* gnus-sum.el (gnus-adjust-marked-articles): Fix the record for `seen' if it
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58
59 (defcustom gnus-kill-summary-on-exit t
60   "*If non-nil, kill the summary buffer when you exit from it.
61 If nil, the summary will become a \"*Dead Summary*\" buffer, and
62 it will be killed sometime later."
63   :group 'gnus-summary-exit
64   :type 'boolean)
65
66 (defcustom gnus-fetch-old-headers nil
67   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
68 If an unread article in the group refers to an older, already read (or
69 just marked as read) article, the old article will not normally be
70 displayed in the Summary buffer.  If this variable is non-nil, Gnus
71 will attempt to grab the headers to the old articles, and thereby
72 build complete threads.  If it has the value `some', only enough
73 headers to connect otherwise loose threads will be displayed.  This
74 variable can also be a number.  In that case, no more than that number
75 of old headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work."
79   :group 'gnus-thread
80   :type '(choice (const :tag "off" nil)
81                  (const some)
82                  number
83                  (sexp :menu-tag "other" t)))
84
85 (defcustom gnus-refer-thread-limit 200
86   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
87 If t, fetch all the available old headers."
88   :group 'gnus-thread
89   :type '(choice number
90                  (sexp :menu-tag "other" t)))
91
92 (defcustom gnus-summary-make-false-root 'adopt
93   "*nil means that Gnus won't gather loose threads.
94 If the root of a thread has expired or been read in a previous
95 session, the information necessary to build a complete thread has been
96 lost.  Instead of having many small sub-threads from this original thread
97 scattered all over the summary buffer, Gnus can gather them.
98
99 If non-nil, Gnus will try to gather all loose sub-threads from an
100 original thread into one large thread.
101
102 If this variable is non-nil, it should be one of `none', `adopt',
103 `dummy' or `empty'.
104
105 If this variable is `none', Gnus will not make a false root, but just
106 present the sub-threads after another.
107 If this variable is `dummy', Gnus will create a dummy root that will
108 have all the sub-threads as children.
109 If this variable is `adopt', Gnus will make one of the \"children\"
110 the parent and mark all the step-children as such.
111 If this variable is `empty', the \"children\" are printed with empty
112 subject fields.  (Or rather, they will be printed with a string
113 given by the `gnus-summary-same-subject' variable.)"
114   :group 'gnus-thread
115   :type '(choice (const :tag "off" nil)
116                  (const none)
117                  (const dummy)
118                  (const adopt)
119                  (const empty)))
120
121 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
122   "*A regexp to match subjects to be excluded from loose thread gathering.
123 As loose thread gathering is done on subjects only, that means that
124 there can be many false gatherings performed.  By rooting out certain
125 common subjects, gathering might become saner."
126   :group 'gnus-thread
127   :type 'regexp)
128
129 (defcustom gnus-summary-gather-subject-limit nil
130   "*Maximum length of subject comparisons when gathering loose threads.
131 Use nil to compare full subjects.  Setting this variable to a low
132 number will help gather threads that have been corrupted by
133 newsreaders chopping off subject lines, but it might also mean that
134 unrelated articles that have subject that happen to begin with the
135 same few characters will be incorrectly gathered.
136
137 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
138 comparing subjects."
139   :group 'gnus-thread
140   :type '(choice (const :tag "off" nil)
141                  (const fuzzy)
142                  (sexp :menu-tag "on" t)))
143
144 (defcustom gnus-simplify-subject-functions nil
145   "List of functions taking a string argument that simplify subjects.
146 The functions are applied recursively.
147
148 Useful functions to put in this list include: `gnus-simplify-subject-re',
149 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
150   :group 'gnus-thread
151   :type '(repeat function))
152
153 (defcustom gnus-simplify-ignored-prefixes nil
154   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
155   :group 'gnus-thread
156   :type '(choice (const :tag "off" nil)
157                  regexp))
158
159 (defcustom gnus-build-sparse-threads nil
160   "*If non-nil, fill in the gaps in threads.
161 If `some', only fill in the gaps that are needed to tie loose threads
162 together.  If `more', fill in all leaf nodes that Gnus can find.  If
163 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
164   :group 'gnus-thread
165   :type '(choice (const :tag "off" nil)
166                  (const some)
167                  (const more)
168                  (sexp :menu-tag "all" t)))
169
170 (defcustom gnus-summary-thread-gathering-function
171   'gnus-gather-threads-by-subject
172   "*Function used for gathering loose threads.
173 There are two pre-defined functions: `gnus-gather-threads-by-subject',
174 which only takes Subjects into consideration; and
175 `gnus-gather-threads-by-references', which compared the References
176 headers of the articles to find matches."
177   :group 'gnus-thread
178   :type '(radio (function-item gnus-gather-threads-by-subject)
179                 (function-item gnus-gather-threads-by-references)
180                 (function :tag "other")))
181
182 (defcustom gnus-summary-same-subject ""
183   "*String indicating that the current article has the same subject as the previous.
184 This variable will only be used if the value of
185 `gnus-summary-make-false-root' is `empty'."
186   :group 'gnus-summary-format
187   :type 'string)
188
189 (defcustom gnus-summary-goto-unread t
190   "*If t, many commands will go to the next unread article.
191 This applies to marking commands as well as other commands that
192 \"naturally\" select the next article, like, for instance, `SPC' at
193 the end of an article.
194
195 If nil, the marking commands do NOT go to the next unread article
196 (they go to the next article instead).  If `never', commands that
197 usually go to the next unread article, will go to the next article,
198 whether it is read or not."
199   :group 'gnus-summary-marks
200   :link '(custom-manual "(gnus)Setting Marks")
201   :type '(choice (const :tag "off" nil)
202                  (const never)
203                  (sexp :menu-tag "on" t)))
204
205 (defcustom gnus-summary-default-score 0
206   "*Default article score level.
207 All scores generated by the score files will be added to this score.
208 If this variable is nil, scoring will be disabled."
209   :group 'gnus-score-default
210   :type '(choice (const :tag "disable")
211                  integer))
212
213 (defcustom gnus-summary-default-high-score 0
214   "*Default threshold for a high scored article.
215 An article will be highlighted as high scored if its score is greater
216 than this score."
217   :group 'gnus-score-default
218   :type 'integer)
219
220 (defcustom gnus-summary-default-low-score 0
221   "*Default threshold for a low scored article.
222 An article will be highlighted as low scored if its score is smaller
223 than this score."
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-zcore-fuzz 0
228   "*Fuzziness factor for the zcore in the summary buffer.
229 Articles with scores closer than this to `gnus-summary-default-score'
230 will not be marked."
231   :group 'gnus-summary-format
232   :type 'integer)
233
234 (defcustom gnus-simplify-subject-fuzzy-regexp nil
235   "*Strings to be removed when doing fuzzy matches.
236 This can either be a regular expression or list of regular expressions
237 that will be removed from subject strings if fuzzy subject
238 simplification is selected."
239   :group 'gnus-thread
240   :type '(repeat regexp))
241
242 (defcustom gnus-show-threads t
243   "*If non-nil, display threads in summary mode."
244   :group 'gnus-thread
245   :type 'boolean)
246
247 (defcustom gnus-thread-hide-subtree nil
248   "*If non-nil, hide all threads initially.
249 If threads are hidden, you have to run the command
250 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
251 to expose hidden threads."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-killed t
256   "*If non-nil, hide killed threads automatically."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-ignore-subject t
261   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
262 If nil, articles that have different subjects from their parents will
263 start separate threads."
264   :group 'gnus-thread
265   :type 'boolean)
266
267 (defcustom gnus-thread-operation-ignore-subject t
268   "*If non-nil, subjects will be ignored when doing thread commands.
269 This affects commands like `gnus-summary-kill-thread' and
270 `gnus-summary-lower-thread'.
271
272 If this variable is nil, articles in the same thread with different
273 subjects will not be included in the operation in question.  If this
274 variable is `fuzzy', only articles that have subjects that are fuzzily
275 equal will be included."
276   :group 'gnus-thread
277   :type '(choice (const :tag "off" nil)
278                  (const fuzzy)
279                  (sexp :tag "on" t)))
280
281 (defcustom gnus-thread-indent-level 4
282   "*Number that says how much each sub-thread should be indented."
283   :group 'gnus-thread
284   :type 'integer)
285
286 (defcustom gnus-auto-extend-newsgroup t
287   "*If non-nil, extend newsgroup forward and backward when requested."
288   :group 'gnus-summary-choose
289   :type 'boolean)
290
291 (defcustom gnus-auto-select-first t
292   "*If non-nil, select the article under point.
293 Which article this is is controlled by the `gnus-auto-select-subject'
294 variable.
295
296 If you want to prevent automatic selection of articles in some
297 newsgroups, set the variable to nil in `gnus-select-group-hook'."
298   :group 'gnus-group-select
299   :type '(choice (const :tag "none" nil)
300                  (sexp :menu-tag "first" t)))
301
302 (defcustom gnus-auto-select-subject 'unread
303   "*Says what subject to place under point when entering a group.
304
305 This variable can either be the symbols `first' (place point on the
306 first subject), `unread' (place point on the subject line of the first
307 unread article), `best' (place point on the subject line of the
308 higest-scored article), `unseen' (place point on the subject line of
309 the first unseen article), or a function to be called to place point on
310 some subject line.."
311   :group 'gnus-group-select
312   :type '(choice (const best)
313                  (const unread)
314                  (const first)
315                  (const unseen)))
316
317 (defcustom gnus-dont-select-after-jump-to-other-group nil
318   "If non-nil, don't select the first unread article after entering the
319 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
320 it is depend on the value of `gnus-auto-select-first' whether to select
321 or not."
322   :group 'gnus-group-select
323   :type 'boolean)
324
325 (defcustom gnus-auto-select-next t
326   "*If non-nil, offer to go to the next group from the end of the previous.
327 If the value is t and the next newsgroup is empty, Gnus will exit
328 summary mode and go back to group mode.  If the value is neither nil
329 nor t, Gnus will select the following unread newsgroup.  In
330 particular, if the value is the symbol `quietly', the next unread
331 newsgroup will be selected without any confirmation, and if it is
332 `almost-quietly', the next group will be selected without any
333 confirmation if you are located on the last article in the group.
334 Finally, if this variable is `slightly-quietly', the `Z n' command
335 will go to the next group without confirmation."
336   :group 'gnus-summary-maneuvering
337   :type '(choice (const :tag "off" nil)
338                  (const quietly)
339                  (const almost-quietly)
340                  (const slightly-quietly)
341                  (sexp :menu-tag "on" t)))
342
343 (defcustom gnus-auto-select-same nil
344   "*If non-nil, select the next article with the same subject.
345 If there are no more articles with the same subject, go to
346 the first unread article."
347   :group 'gnus-summary-maneuvering
348   :type 'boolean)
349
350 (defcustom gnus-summary-check-current nil
351   "*If non-nil, consider the current article when moving.
352 The \"unread\" movement commands will stay on the same line if the
353 current article is unread."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-auto-center-summary t
358   "*If non-nil, always center the current summary buffer.
359 In particular, if `vertical' do only vertical recentering.  If non-nil
360 and non-`vertical', do both horizontal and vertical recentering."
361   :group 'gnus-summary-maneuvering
362   :type '(choice (const :tag "none" nil)
363                  (const vertical)
364                  (integer :tag "height")
365                  (sexp :menu-tag "both" t)))
366
367 (defcustom gnus-show-all-headers nil
368   "*If non-nil, don't hide any headers."
369   :group 'gnus-article-hiding
370   :group 'gnus-article-headers
371   :type 'boolean)
372
373 (defcustom gnus-summary-ignore-duplicates nil
374   "*If non-nil, ignore articles with identical Message-ID headers."
375   :group 'gnus-summary
376   :type 'boolean)
377
378 (defcustom gnus-single-article-buffer t
379   "*If non-nil, display all articles in the same buffer.
380 If nil, each group will get its own article buffer."
381   :group 'gnus-article-various
382   :type 'boolean)
383
384 (defcustom gnus-break-pages t
385   "*If non-nil, do page breaking on articles.
386 The page delimiter is specified by the `gnus-page-delimiter'
387 variable."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-show-mime t
392   "*If non-nil, do mime processing of articles.
393 The articles will simply be fed to the function given by
394 `gnus-article-display-method-for-mime'."
395   :group 'gnus-article-mime
396   :type 'boolean)
397
398 (defcustom gnus-move-split-methods nil
399   "*Variable used to suggest where articles are to be moved to.
400 It uses the same syntax as the `gnus-split-methods' variable.
401 However, whereas `gnus-split-methods' specifies file names as targets,
402 this variable specifies group names."
403   :group 'gnus-summary-mail
404   :type '(repeat (choice (list :value (fun) function)
405                          (cons :value ("" "") regexp (repeat string))
406                          (sexp :value nil))))
407
408 (defcustom gnus-unread-mark ?\ ;;;Whitespace
409   "*Mark used for unread articles."
410   :group 'gnus-summary-marks
411   :type 'character)
412
413 (defcustom gnus-ticked-mark ?!
414   "*Mark used for ticked articles."
415   :group 'gnus-summary-marks
416   :type 'character)
417
418 (defcustom gnus-dormant-mark ??
419   "*Mark used for dormant articles."
420   :group 'gnus-summary-marks
421   :type 'character)
422
423 (defcustom gnus-del-mark ?r
424   "*Mark used for del'd articles."
425   :group 'gnus-summary-marks
426   :type 'character)
427
428 (defcustom gnus-read-mark ?R
429   "*Mark used for read articles."
430   :group 'gnus-summary-marks
431   :type 'character)
432
433 (defcustom gnus-expirable-mark ?E
434   "*Mark used for expirable articles."
435   :group 'gnus-summary-marks
436   :type 'character)
437
438 (defcustom gnus-killed-mark ?K
439   "*Mark used for killed articles."
440   :group 'gnus-summary-marks
441   :type 'character)
442
443 (defcustom gnus-souped-mark ?F
444   "*Mark used for souped articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-kill-file-mark ?X
449   "*Mark used for articles killed by kill files."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-low-score-mark ?Y
454   "*Mark used for articles with a low score."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-catchup-mark ?C
459   "*Mark used for articles that are caught up."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-replied-mark ?A
464   "*Mark used for articles that have been replied to."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-forwarded-mark ?F
469   "*Mark used for articles that have been forwarded."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-recent-mark ?N
474   "*Mark used for articles that are recent."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-cached-mark ?*
479   "*Mark used for articles that are in the cache."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-saved-mark ?S
484   "*Mark used for articles that have been saved."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-unseen-mark ?.
489   "*Mark used for articles that haven't been seen."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-no-mark ?\ ;;;Whitespace
494   "*Mark used for articles that have no other secondary mark."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-ancient-mark ?O
499   "*Mark used for ancient articles."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-sparse-mark ?Q
504   "*Mark used for sparsely reffed articles."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-canceled-mark ?G
509   "*Mark used for canceled articles."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-duplicate-mark ?M
514   "*Mark used for duplicate articles."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-undownloaded-mark ?@
519   "*Mark used for articles that weren't downloaded."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-downloadable-mark ?%
524   "*Mark used for articles that are to be downloaded."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-unsendable-mark ?=
529   "*Mark used for articles that won't be sent."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-score-over-mark ?+
534   "*Score mark used for articles with high scores."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-score-below-mark ?-
539   "*Score mark used for articles with low scores."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
544   "*There is no thread under the article."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-not-empty-thread-mark ?=
549   "*There is a thread under the article."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-view-pseudo-asynchronously nil
554   "*If non-nil, Gnus will view pseudo-articles asynchronously."
555   :group 'gnus-extract-view
556   :type 'boolean)
557
558 (defcustom gnus-auto-expirable-marks
559   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
560         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
561         gnus-souped-mark gnus-duplicate-mark)
562   "*The list of marks converted into expiration if a group is auto-expirable."
563   :version "21.1"
564   :group 'gnus-summary
565   :type '(repeat character))
566
567 (defcustom gnus-inhibit-user-auto-expire t
568   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
569   :version "21.1"
570   :group 'gnus-summary
571   :type 'boolean)
572
573 (defcustom gnus-view-pseudos nil
574   "*If `automatic', pseudo-articles will be viewed automatically.
575 If `not-confirm', pseudos will be viewed automatically, and the user
576 will not be asked to confirm the command."
577   :group 'gnus-extract-view
578   :type '(choice (const :tag "off" nil)
579                  (const automatic)
580                  (const not-confirm)))
581
582 (defcustom gnus-view-pseudos-separately t
583   "*If non-nil, one pseudo-article will be created for each file to be viewed.
584 If nil, all files that use the same viewing command will be given as a
585 list of parameters to that command."
586   :group 'gnus-extract-view
587   :type 'boolean)
588
589 (defcustom gnus-insert-pseudo-articles t
590   "*If non-nil, insert pseudo-articles when decoding articles."
591   :group 'gnus-extract-view
592   :type 'boolean)
593
594 (defcustom gnus-summary-dummy-line-format
595   "  %(:                          :%) %S\n"
596   "*The format specification for the dummy roots in the summary buffer.
597 It works along the same lines as a normal formatting string,
598 with some simple extensions.
599
600 %S  The subject"
601   :group 'gnus-threading
602   :type 'string)
603
604 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
605   "*The format specification for the summary mode line.
606 It works along the same lines as a normal formatting string,
607 with some simple extensions:
608
609 %G  Group name
610 %p  Unprefixed group name
611 %A  Current article number
612 %z  Current article score
613 %V  Gnus version
614 %U  Number of unread articles in the group
615 %e  Number of unselected articles in the group
616 %Z  A string with unread/unselected article counts
617 %g  Shortish group name
618 %S  Subject of the current article
619 %u  User-defined spec
620 %s  Current score file name
621 %d  Number of dormant articles
622 %r  Number of articles that have been marked as read in this session
623 %E  Number of articles expunged by the score files"
624   :group 'gnus-summary-format
625   :type 'string)
626
627 (defcustom gnus-list-identifiers nil
628   "Regexp that matches list identifiers to be removed from subject.
629 This can also be a list of regexps."
630   :version "21.1"
631   :group 'gnus-summary-format
632   :group 'gnus-article-hiding
633   :type '(choice (const :tag "none" nil)
634                  (regexp :value ".*")
635                  (repeat :value (".*") regexp)))
636
637 (defcustom gnus-summary-mark-below 0
638   "*Mark all articles with a score below this variable as read.
639 This variable is local to each summary buffer and usually set by the
640 score file."
641   :group 'gnus-score-default
642   :type 'integer)
643
644 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
645   "*List of functions used for sorting articles in the summary buffer.
646
647 Each function takes two articles and returns non-nil if the first
648 article should be sorted before the other.  If you use more than one
649 function, the primary sort function should be the last.  You should
650 probably always include `gnus-article-sort-by-number' in the list of
651 sorting functions -- preferably first.  Also note that sorting by date
652 is often much slower than sorting by number, and the sorting order is
653 very similar.  (Sorting by date means sorting by the time the message
654 was sent, sorting by number means sorting by arrival time.)
655
656 Ready-made functions include `gnus-article-sort-by-number',
657 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
658 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
659
660 When threading is turned on, the variable `gnus-thread-sort-functions'
661 controls how articles are sorted."
662   :group 'gnus-summary-sort
663   :type '(repeat (choice (function-item gnus-article-sort-by-number)
664                          (function-item gnus-article-sort-by-author)
665                          (function-item gnus-article-sort-by-subject)
666                          (function-item gnus-article-sort-by-date)
667                          (function-item gnus-article-sort-by-score)
668                          (function :tag "other"))))
669
670 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
671   "*List of functions used for sorting threads in the summary buffer.
672 By default, threads are sorted by article number.
673
674 Each function takes two threads and returns non-nil if the first
675 thread should be sorted before the other.  If you use more than one
676 function, the primary sort function should be the last.  You should
677 probably always include `gnus-thread-sort-by-number' in the list of
678 sorting functions -- preferably first.  Also note that sorting by date
679 is often much slower than sorting by number, and the sorting order is
680 very similar.  (Sorting by date means sorting by the time the message
681 was sent, sorting by number means sorting by arrival time.)
682
683 Ready-made functions include `gnus-thread-sort-by-number',
684 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
685 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
686 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
687
688 When threading is turned off, the variable
689 `gnus-article-sort-functions' controls how articles are sorted."
690   :group 'gnus-summary-sort
691   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
692                          (function-item gnus-thread-sort-by-author)
693                          (function-item gnus-thread-sort-by-subject)
694                          (function-item gnus-thread-sort-by-date)
695                          (function-item gnus-thread-sort-by-score)
696                          (function-item gnus-thread-sort-by-total-score)
697                          (function :tag "other"))))
698
699 (defcustom gnus-thread-score-function '+
700   "*Function used for calculating the total score of a thread.
701
702 The function is called with the scores of the article and each
703 subthread and should then return the score of the thread.
704
705 Some functions you can use are `+', `max', or `min'."
706   :group 'gnus-summary-sort
707   :type 'function)
708
709 (defcustom gnus-summary-expunge-below nil
710   "All articles that have a score less than this variable will be expunged.
711 This variable is local to the summary buffers."
712   :group 'gnus-score-default
713   :type '(choice (const :tag "off" nil)
714                  integer))
715
716 (defcustom gnus-thread-expunge-below nil
717   "All threads that have a total score less than this variable will be expunged.
718 See `gnus-thread-score-function' for en explanation of what a
719 \"thread score\" is.
720
721 This variable is local to the summary buffers."
722   :group 'gnus-threading
723   :group 'gnus-score-default
724   :type '(choice (const :tag "off" nil)
725                  integer))
726
727 (defcustom gnus-summary-mode-hook nil
728   "*A hook for Gnus summary mode.
729 This hook is run before any variables are set in the summary buffer."
730   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
731   :group 'gnus-summary-various
732   :type 'hook)
733
734 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
735 (when (featurep 'xemacs)
736   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
737   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
738   (add-hook 'gnus-summary-mode-hook
739             'gnus-xmas-switch-horizontal-scrollbar-off))
740
741 (defcustom gnus-summary-menu-hook nil
742   "*Hook run after the creation of the summary mode menu."
743   :group 'gnus-summary-visual
744   :type 'hook)
745
746 (defcustom gnus-summary-exit-hook nil
747   "*A hook called on exit from the summary buffer.
748 It will be called with point in the group buffer."
749   :group 'gnus-summary-exit
750   :type 'hook)
751
752 (defcustom gnus-summary-prepare-hook nil
753   "*A hook called after the summary buffer has been generated.
754 If you want to modify the summary buffer, you can use this hook."
755   :group 'gnus-summary-various
756   :type 'hook)
757
758 (defcustom gnus-summary-prepared-hook nil
759   "*A hook called as the last thing after the summary buffer has been generated."
760   :group 'gnus-summary-various
761   :type 'hook)
762
763 (defcustom gnus-summary-generate-hook nil
764   "*A hook run just before generating the summary buffer.
765 This hook is commonly used to customize threading variables and the
766 like."
767   :group 'gnus-summary-various
768   :type 'hook)
769
770 (defcustom gnus-select-group-hook nil
771   "*A hook called when a newsgroup is selected.
772
773 If you'd like to simplify subjects like the
774 `gnus-summary-next-same-subject' command does, you can use the
775 following hook:
776
777  (setq gnus-select-group-hook
778       (list
779         (lambda ()
780           (mapcar (lambda (header)
781                      (mail-header-set-subject
782                       header
783                       (gnus-simplify-subject
784                        (mail-header-subject header) 're-only)))
785                   gnus-newsgroup-headers))))"
786   :group 'gnus-group-select
787   :type 'hook)
788
789 (defcustom gnus-select-article-hook nil
790   "*A hook called when an article is selected."
791   :group 'gnus-summary-choose
792   :type 'hook)
793
794 (defcustom gnus-visual-mark-article-hook
795   (list 'gnus-highlight-selected-summary)
796   "*Hook run after selecting an article in the summary buffer.
797 It is meant to be used for highlighting the article in some way.  It
798 is not run if `gnus-visual' is nil."
799   :group 'gnus-summary-visual
800   :type 'hook)
801
802 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
803   "*A hook called before parsing the headers."
804   :group 'gnus-various
805   :type 'hook)
806
807 (defcustom gnus-exit-group-hook nil
808   "*A hook called when exiting summary mode.
809 This hook is not called from the non-updating exit commands like `Q'."
810   :group 'gnus-various
811   :type 'hook)
812
813 (defcustom gnus-summary-update-hook
814   (list 'gnus-summary-highlight-line)
815   "*A hook called when a summary line is changed.
816 The hook will not be called if `gnus-visual' is nil.
817
818 The default function `gnus-summary-highlight-line' will
819 highlight the line according to the `gnus-summary-highlight'
820 variable."
821   :group 'gnus-summary-visual
822   :type 'hook)
823
824 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
825   "*A hook called when an article is selected for the first time.
826 The hook is intended to mark an article as read (or unread)
827 automatically when it is selected."
828   :group 'gnus-summary-choose
829   :type 'hook)
830
831 (defcustom gnus-group-no-more-groups-hook nil
832   "*A hook run when returning to group mode having no more (unread) groups."
833   :group 'gnus-group-select
834   :type 'hook)
835
836 (defcustom gnus-ps-print-hook nil
837   "*A hook run before ps-printing something from Gnus."
838   :group 'gnus-summary
839   :type 'hook)
840
841 (defcustom gnus-summary-display-arrow
842   (and (fboundp 'display-graphic-p)
843        (display-graphic-p))
844   "*If non-nil, display an arrow highlighting the current article."
845   :version "21.1"
846   :group 'gnus-summary
847   :type 'boolean)
848
849 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
850   "Face used for highlighting the current article in the summary buffer."
851   :group 'gnus-summary-visual
852   :type 'face)
853
854 (defcustom gnus-summary-highlight
855   '(((= mark gnus-canceled-mark)
856      . gnus-summary-cancelled-face)
857     ((and (> score default-high)
858           (or (= mark gnus-dormant-mark)
859               (= mark gnus-ticked-mark)))
860      . gnus-summary-high-ticked-face)
861     ((and (< score default-low)
862           (or (= mark gnus-dormant-mark)
863               (= mark gnus-ticked-mark)))
864      . gnus-summary-low-ticked-face)
865     ((or (= mark gnus-dormant-mark)
866          (= mark gnus-ticked-mark))
867      . gnus-summary-normal-ticked-face)
868     ((and (> score default-high) (= mark gnus-ancient-mark))
869      . gnus-summary-high-ancient-face)
870     ((and (< score default-low) (= mark gnus-ancient-mark))
871      . gnus-summary-low-ancient-face)
872     ((= mark gnus-ancient-mark)
873      . gnus-summary-normal-ancient-face)
874     ((and (> score default-high) (= mark gnus-unread-mark))
875      . gnus-summary-high-unread-face)
876     ((and (< score default-low) (= mark gnus-unread-mark))
877      . gnus-summary-low-unread-face)
878     ((= mark gnus-unread-mark)
879      . gnus-summary-normal-unread-face)
880     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
881                                                   gnus-undownloaded-mark)))
882      . gnus-summary-high-unread-face)
883     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
884                                                  gnus-undownloaded-mark)))
885      . gnus-summary-low-unread-face)
886     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
887           (memq article gnus-newsgroup-unreads))
888      . gnus-summary-normal-unread-face)
889     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
890      . gnus-summary-normal-read-face)
891     ((> score default-high)
892      . gnus-summary-high-read-face)
893     ((< score default-low)
894      . gnus-summary-low-read-face)
895     (t
896      . gnus-summary-normal-read-face))
897   "*Controls the highlighting of summary buffer lines.
898
899 A list of (FORM . FACE) pairs.  When deciding how a a particular
900 summary line should be displayed, each form is evaluated.  The content
901 of the face field after the first true form is used.  You can change
902 how those summary lines are displayed, by editing the face field.
903
904 You can use the following variables in the FORM field.
905
906 score:        The article's score
907 default:      The default article score.
908 default-high: The default score for high scored articles.
909 default-low:  The default score for low scored articles.
910 below:        The score below which articles are automatically marked as read.
911 mark:         The articles mark."
912   :group 'gnus-summary-visual
913   :type '(repeat (cons (sexp :tag "Form" nil)
914                        face)))
915
916 (defcustom gnus-alter-header-function nil
917   "Function called to allow alteration of article header structures.
918 The function is called with one parameter, the article header vector,
919 which it may alter in any way.")
920
921 (defvar gnus-decode-encoded-word-function
922   (mime-find-field-decoder 'From 'nov)
923   "Variable that says which function should be used to decode a string with encoded words.")
924
925 (defcustom gnus-extra-headers nil
926   "*Extra headers to parse."
927   :version "21.1"
928   :group 'gnus-summary
929   :type '(repeat symbol))
930
931 (defcustom gnus-ignored-from-addresses
932   (and user-mail-address (regexp-quote user-mail-address))
933   "*Regexp of From headers that may be suppressed in favor of To headers."
934   :version "21.1"
935   :group 'gnus-summary
936   :type 'regexp)
937
938 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
939   "List of charsets that should be ignored.
940 When these charsets are used in the \"charset\" parameter, the
941 default charset will be used instead."
942   :version "21.1"
943   :type '(repeat symbol)
944   :group 'gnus-charset)
945
946 (gnus-define-group-parameter
947  ignored-charsets
948  :type list
949  :function-document
950  "Return the ignored charsets of GROUP."
951  :variable gnus-group-ignored-charsets-alist
952  :variable-default
953  '(("alt\\.chinese\\.text" iso-8859-1))
954  :variable-document
955  "Alist of regexps (to match group names) and charsets that should be ignored.
956 When these charsets are used in the \"charset\" parameter, the
957 default charset will be used instead."
958  :variable-group gnus-charset
959  :variable-type '(repeat (cons (regexp :tag "Group")
960                                (repeat symbol)))
961  :parameter-type '(choice :tag "Ignored charsets"
962                           :value nil
963                           (repeat (symbol)))
964  :parameter-document       "\
965 List of charsets that should be ignored.
966
967 When these charsets are used in the \"charset\" parameter, the
968 default charset will be used instead.")
969
970 (defcustom gnus-group-highlight-words-alist nil
971   "Alist of group regexps and highlight regexps.
972 This variable uses the same syntax as `gnus-emphasis-alist'."
973   :version "21.1"
974   :type '(repeat (cons (regexp :tag "Group")
975                        (repeat (list (regexp :tag "Highlight regexp")
976                                      (number :tag "Group for entire word" 0)
977                                      (number :tag "Group for displayed part" 0)
978                                      (symbol :tag "Face"
979                                              gnus-emphasis-highlight-words)))))
980   :group 'gnus-summary-visual)
981
982 (defcustom gnus-use-wheel nil
983   "Use Intelli-mouse on summary movement"
984   :type 'boolean
985   :group 'gnus-summary-maneuvering)
986
987 (defcustom gnus-wheel-scroll-amount '(5 . 1)
988   "Amount to scroll messages by spinning the mouse wheel.
989 This is actually a cons cell, where the first item is the amount to scroll
990 on a normal wheel event, and the second is the amount to scroll when the
991 wheel is moved with the shift key depressed."
992   :type '(cons (integer :tag "Shift") integer)
993   :group 'gnus-summary-maneuvering)
994
995 (defcustom gnus-wheel-edge-resistance 2
996   "How hard it should be to change the current article
997 by moving the mouse over the edge of the article window."
998   :type 'integer
999   :group 'gnus-summary-maneuvering)
1000
1001 (defcustom gnus-summary-show-article-charset-alist
1002   nil
1003   "Alist of number and charset.
1004 The article will be shown with the charset corresponding to the
1005 numbered argument.
1006 For example: ((1 . cn-gb-2312) (2 . big5))."
1007   :version "21.1"
1008   :type '(repeat (cons (number :tag "Argument" 1)
1009                        (symbol :tag "Charset")))
1010   :group 'gnus-charset)
1011
1012 (defcustom gnus-preserve-marks t
1013   "Whether marks are preserved when moving, copying and respooling messages."
1014   :version "21.1"
1015   :type 'boolean
1016   :group 'gnus-summary-marks)
1017
1018 (defcustom gnus-alter-articles-to-read-function nil
1019   "Function to be called to alter the list of articles to be selected."
1020   :type '(choice (const nil) function)
1021   :group 'gnus-summary)
1022
1023 (defcustom gnus-orphan-score nil
1024   "*All orphans get this score added.  Set in the score file."
1025   :group 'gnus-score-default
1026   :type '(choice (const nil)
1027                  integer))
1028
1029 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1030   "*A regexp to match MIME parts when saving multiple parts of a message
1031 with gnus-summary-save-parts (X m). This regexp will be used by default
1032 when prompting the user for which type of files to save."
1033   :group 'gnus-summary
1034   :type 'regexp)
1035
1036
1037 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1038   "*A regexp to match MIME parts when saving multiple parts of a message
1039 with gnus-summary-save-parts (X m). This regexp will be used by default
1040 when prompting the user for which type of files to save."
1041   :group 'gnus-summary
1042   :type 'regexp)
1043
1044 (defcustom gnus-read-all-available-headers nil
1045   "Whether Gnus should parse all headers made available to it.
1046 This is mostly relevant for slow backends where the user may
1047 wish to widen the summary buffer to include all headers
1048 that were fetched.  Say, for nnultimate groups."
1049   :group 'gnus-summary
1050   :type '(choice boolean regexp))
1051
1052 (defcustom gnus-summary-muttprint-program "muttprint"
1053   "Command (and optional arguments) used to run Muttprint."
1054   :group 'gnus-summary
1055   :type 'string)
1056
1057 ;;; Internal variables
1058
1059 (defvar gnus-summary-display-cache nil)
1060 (defvar gnus-article-mime-handles nil)
1061 (defvar gnus-article-decoded-p nil)
1062 (defvar gnus-article-charset nil)
1063 (defvar gnus-article-ignored-charsets nil)
1064 (defvar gnus-scores-exclude-files nil)
1065 (defvar gnus-page-broken nil)
1066 (defvar gnus-inhibit-mime-unbuttonizing nil)
1067
1068 (defvar gnus-original-article nil)
1069 (defvar gnus-article-internal-prepare-hook nil)
1070 (defvar gnus-newsgroup-process-stack nil)
1071
1072 (defvar gnus-thread-indent-array nil)
1073 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1074 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1075   "Function called to sort the articles within a thread after it has been gathered together.")
1076
1077 (defvar gnus-summary-save-parts-type-history nil)
1078 (defvar gnus-summary-save-parts-last-directory nil)
1079
1080 (defvar gnus-summary-save-parts-type-history nil)
1081 (defvar gnus-summary-save-parts-last-directory nil)
1082
1083 ;; Avoid highlighting in kill files.
1084 (defvar gnus-summary-inhibit-highlight nil)
1085 (defvar gnus-newsgroup-selected-overlay nil)
1086 (defvar gnus-inhibit-limiting nil)
1087 (defvar gnus-newsgroup-adaptive-score-file nil)
1088 (defvar gnus-current-score-file nil)
1089 (defvar gnus-current-move-group nil)
1090 (defvar gnus-current-copy-group nil)
1091 (defvar gnus-current-crosspost-group nil)
1092 (defvar gnus-newsgroup-display nil)
1093
1094 (defvar gnus-newsgroup-dependencies nil)
1095 (defvar gnus-newsgroup-adaptive nil)
1096 (defvar gnus-summary-display-article-function nil)
1097 (defvar gnus-summary-highlight-line-function nil
1098   "Function called after highlighting a summary line.")
1099
1100 (defvar gnus-summary-line-format-alist
1101   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1102     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1103     (?s gnus-tmp-subject-or-nil ?s)
1104     (?n gnus-tmp-name ?s)
1105     (?A (std11-address-string
1106          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1107     (?a (or (std11-full-name-string
1108              (car (mime-entity-read-field gnus-tmp-header 'From)))
1109             gnus-tmp-from) ?s)
1110     (?F gnus-tmp-from ?s)
1111     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1112     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1113     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1114     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1115     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1116     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1117     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1118     (?L gnus-tmp-lines ?s)
1119     (?I gnus-tmp-indentation ?s)
1120     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1121     (?R gnus-tmp-replied ?c)
1122     (?\[ gnus-tmp-opening-bracket ?c)
1123     (?\] gnus-tmp-closing-bracket ?c)
1124     (?\> (make-string gnus-tmp-level ? ) ?s)
1125     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1126     (?i gnus-tmp-score ?d)
1127     (?z gnus-tmp-score-char ?c)
1128     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1129     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1130     (?U gnus-tmp-unread ?c)
1131     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1132         ?s)
1133     (?t (gnus-summary-number-of-articles-in-thread
1134          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1135         ?d)
1136     (?e (gnus-summary-number-of-articles-in-thread
1137          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1138         ?c)
1139     (?u gnus-tmp-user-defined ?s)
1140     (?P (gnus-pick-line-number) ?d)
1141     (?B gnus-tmp-thread-tree-header-string ?s)
1142     (user-date (gnus-user-date
1143                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1144   "An alist of format specifications that can appear in summary lines.
1145 These are paired with what variables they correspond with, along with
1146 the type of the variable (string, integer, character, etc).")
1147
1148 (defvar gnus-summary-dummy-line-format-alist
1149   `((?S gnus-tmp-subject ?s)
1150     (?N gnus-tmp-number ?d)
1151     (?u gnus-tmp-user-defined ?s)))
1152
1153 (defvar gnus-summary-mode-line-format-alist
1154   `((?G gnus-tmp-group-name ?s)
1155     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1156     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1157     (?A gnus-tmp-article-number ?d)
1158     (?Z gnus-tmp-unread-and-unselected ?s)
1159     (?V gnus-version ?s)
1160     (?U gnus-tmp-unread-and-unticked ?d)
1161     (?S gnus-tmp-subject ?s)
1162     (?e gnus-tmp-unselected ?d)
1163     (?u gnus-tmp-user-defined ?s)
1164     (?d (length gnus-newsgroup-dormant) ?d)
1165     (?t (length gnus-newsgroup-marked) ?d)
1166     (?r (length gnus-newsgroup-reads) ?d)
1167     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1168     (?E gnus-newsgroup-expunged-tally ?d)
1169     (?s (gnus-current-score-file-nondirectory) ?s)))
1170
1171 (defvar gnus-last-search-regexp nil
1172   "Default regexp for article search command.")
1173
1174 (defvar gnus-summary-search-article-matched-data nil
1175   "Last matched data of article search command.  It is the local variable
1176 in `gnus-article-buffer' which consists of the list of start position,
1177 end position and text.")
1178
1179 (defvar gnus-last-shell-command nil
1180   "Default shell command on article.")
1181
1182 (defvar gnus-newsgroup-begin nil)
1183 (defvar gnus-newsgroup-end nil)
1184 (defvar gnus-newsgroup-last-rmail nil)
1185 (defvar gnus-newsgroup-last-mail nil)
1186 (defvar gnus-newsgroup-last-folder nil)
1187 (defvar gnus-newsgroup-last-file nil)
1188 (defvar gnus-newsgroup-auto-expire nil)
1189 (defvar gnus-newsgroup-active nil)
1190
1191 (defvar gnus-newsgroup-data nil)
1192 (defvar gnus-newsgroup-data-reverse nil)
1193 (defvar gnus-newsgroup-limit nil)
1194 (defvar gnus-newsgroup-limits nil)
1195
1196 (defvar gnus-newsgroup-unreads nil
1197   "List of unread articles in the current newsgroup.")
1198
1199 (defvar gnus-newsgroup-unselected nil
1200   "List of unselected unread articles in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-reads nil
1203   "Alist of read articles and article marks in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-expunged-tally nil)
1206
1207 (defvar gnus-newsgroup-marked nil
1208   "List of ticked articles in the current newsgroup (a subset of unread art).")
1209
1210 (defvar gnus-newsgroup-killed nil
1211   "List of ranges of articles that have been through the scoring process.")
1212
1213 (defvar gnus-newsgroup-cached nil
1214   "List of articles that come from the article cache.")
1215
1216 (defvar gnus-newsgroup-saved nil
1217   "List of articles that have been saved.")
1218
1219 (defvar gnus-newsgroup-kill-headers nil)
1220
1221 (defvar gnus-newsgroup-replied nil
1222   "List of articles that have been replied to in the current newsgroup.")
1223
1224 (defvar gnus-newsgroup-forwarded nil
1225   "List of articles that have been forwarded in the current newsgroup.")
1226
1227 (defvar gnus-newsgroup-recent nil
1228   "List of articles that have are recent in the current newsgroup.")
1229
1230 (defvar gnus-newsgroup-expirable nil
1231   "List of articles in the current newsgroup that can be expired.")
1232
1233 (defvar gnus-newsgroup-processable nil
1234   "List of articles in the current newsgroup that can be processed.")
1235
1236 (defvar gnus-newsgroup-downloadable nil
1237   "List of articles in the current newsgroup that can be processed.")
1238
1239 (defvar gnus-newsgroup-undownloaded nil
1240   "List of articles in the current newsgroup that haven't been downloaded..")
1241
1242 (defvar gnus-newsgroup-unsendable nil
1243   "List of articles in the current newsgroup that won't be sent.")
1244
1245 (defvar gnus-newsgroup-bookmarks nil
1246   "List of articles in the current newsgroup that have bookmarks.")
1247
1248 (defvar gnus-newsgroup-dormant nil
1249   "List of dormant articles in the current newsgroup.")
1250
1251 (defvar gnus-newsgroup-unseen nil
1252   "List of unseen articles in the current newsgroup.")
1253
1254 (defvar gnus-newsgroup-seen nil
1255   "Range of seen articles in the current newsgroup.")
1256
1257 (defvar gnus-newsgroup-articles nil
1258   "List of articles in the current newsgroup.")
1259
1260 (defvar gnus-newsgroup-scored nil
1261   "List of scored articles in the current newsgroup.")
1262
1263 (defvar gnus-newsgroup-incorporated nil
1264   "List of incorporated articles in the current newsgroup.")
1265
1266 (defvar gnus-newsgroup-headers nil
1267   "List of article headers in the current newsgroup.")
1268
1269 (defvar gnus-newsgroup-threads nil)
1270
1271 (defvar gnus-newsgroup-prepared nil
1272   "Whether the current group has been prepared properly.")
1273
1274 (defvar gnus-newsgroup-ancient nil
1275   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-sparse nil)
1278
1279 (defvar gnus-current-article nil)
1280 (defvar gnus-article-current nil)
1281 (defvar gnus-current-headers nil)
1282 (defvar gnus-have-all-headers nil)
1283 (defvar gnus-last-article nil)
1284 (defvar gnus-newsgroup-history nil)
1285 (defvar gnus-newsgroup-charset nil)
1286 (defvar gnus-newsgroup-ephemeral-charset nil)
1287 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1288
1289 (defvar gnus-article-before-search nil)
1290
1291 (defconst gnus-summary-local-variables
1292   '(gnus-newsgroup-name
1293     gnus-newsgroup-begin gnus-newsgroup-end
1294     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1295     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1296     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1297     gnus-newsgroup-unselected gnus-newsgroup-marked
1298     gnus-newsgroup-reads gnus-newsgroup-saved
1299     gnus-newsgroup-replied gnus-newsgroup-forwarded
1300     gnus-newsgroup-recent
1301     gnus-newsgroup-expirable
1302     gnus-newsgroup-processable gnus-newsgroup-killed
1303     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1304     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1305     gnus-newsgroup-seen gnus-newsgroup-articles
1306     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1307     gnus-newsgroup-headers gnus-newsgroup-threads
1308     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1309     gnus-current-article gnus-current-headers gnus-have-all-headers
1310     gnus-last-article gnus-article-internal-prepare-hook
1311     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1312     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1313     gnus-thread-expunge-below
1314     gnus-score-alist gnus-current-score-file
1315     (gnus-summary-expunge-below . global)
1316     (gnus-summary-mark-below . global)
1317     (gnus-orphan-score . global)
1318     gnus-newsgroup-active gnus-scores-exclude-files
1319     gnus-newsgroup-history gnus-newsgroup-ancient
1320     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1321     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1322     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1323     (gnus-newsgroup-expunged-tally . 0)
1324     gnus-cache-removable-articles gnus-newsgroup-cached
1325     gnus-newsgroup-data gnus-newsgroup-data-reverse
1326     gnus-newsgroup-limit gnus-newsgroup-limits
1327     gnus-newsgroup-charset gnus-newsgroup-display
1328     gnus-newsgroup-incorporated)
1329   "Variables that are buffer-local to the summary buffers.")
1330
1331 (defvar gnus-newsgroup-variables nil
1332   "A list of variables that have separate values in different newsgroups.
1333 A list of newsgroup (summary buffer) local variables, or cons of
1334 variables and their default values (when the default values are not
1335 nil), that should be made global while the summary buffer is active.
1336 These variables can be used to set variables in the group parameters
1337 while still allowing them to affect operations done in other
1338 buffers. For example:
1339
1340 \(setq gnus-newsgroup-variables
1341      '(message-use-followup-to
1342        (gnus-visible-headers .
1343          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1344 ")
1345
1346 ;; Byte-compiler warning.
1347 (eval-when-compile (defvar gnus-article-mode-map))
1348
1349 ;; Subject simplification.
1350
1351 (defun gnus-simplify-whitespace (str)
1352   "Remove excessive whitespace from STR."
1353   (let ((mystr str))
1354     ;; Multiple spaces.
1355     (while (string-match "[ \t][ \t]+" mystr)
1356       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1357                           " "
1358                           (substring mystr (match-end 0)))))
1359     ;; Leading spaces.
1360     (when (string-match "^[ \t]+" mystr)
1361       (setq mystr (substring mystr (match-end 0))))
1362     ;; Trailing spaces.
1363     (when (string-match "[ \t]+$" mystr)
1364       (setq mystr (substring mystr 0 (match-beginning 0))))
1365     mystr))
1366
1367 (defsubst gnus-simplify-subject-re (subject)
1368   "Remove \"Re:\" from subject lines."
1369   (if (string-match message-subject-re-regexp subject)
1370       (substring subject (match-end 0))
1371     subject))
1372
1373 (defun gnus-simplify-subject (subject &optional re-only)
1374   "Remove `Re:' and words in parentheses.
1375 If RE-ONLY is non-nil, strip leading `Re:'s only."
1376   (let ((case-fold-search t))           ;Ignore case.
1377     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1378     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1379       (setq subject (substring subject (match-end 0))))
1380     ;; Remove uninteresting prefixes.
1381     (when (and (not re-only)
1382                gnus-simplify-ignored-prefixes
1383                (string-match gnus-simplify-ignored-prefixes subject))
1384       (setq subject (substring subject (match-end 0))))
1385     ;; Remove words in parentheses from end.
1386     (unless re-only
1387       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1388         (setq subject (substring subject 0 (match-beginning 0)))))
1389     ;; Return subject string.
1390     subject))
1391
1392 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1393 ;; all whitespace.
1394 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1395   (goto-char (point-min))
1396   (while (re-search-forward regexp nil t)
1397     (replace-match (or newtext ""))))
1398
1399 (defun gnus-simplify-buffer-fuzzy ()
1400   "Simplify string in the buffer fuzzily.
1401 The string in the accessible portion of the current buffer is simplified.
1402 It is assumed to be a single-line subject.
1403 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1404 matter is removed.  Additional things can be deleted by setting
1405 `gnus-simplify-subject-fuzzy-regexp'."
1406   (let ((case-fold-search t)
1407         (modified-tick))
1408     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1409
1410     (while (not (eq modified-tick (buffer-modified-tick)))
1411       (setq modified-tick (buffer-modified-tick))
1412       (cond
1413        ((listp gnus-simplify-subject-fuzzy-regexp)
1414         (mapcar 'gnus-simplify-buffer-fuzzy-step
1415                 gnus-simplify-subject-fuzzy-regexp))
1416        (gnus-simplify-subject-fuzzy-regexp
1417         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1418       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1419       (gnus-simplify-buffer-fuzzy-step
1420        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1421       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1422
1423     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1424     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1425     (gnus-simplify-buffer-fuzzy-step " $")
1426     (gnus-simplify-buffer-fuzzy-step "^ +")))
1427
1428 (defun gnus-simplify-subject-fuzzy (subject)
1429   "Simplify a subject string fuzzily.
1430 See `gnus-simplify-buffer-fuzzy' for details."
1431   (save-excursion
1432     (gnus-set-work-buffer)
1433     (let ((case-fold-search t))
1434       ;; Remove uninteresting prefixes.
1435       (when (and gnus-simplify-ignored-prefixes
1436                  (string-match gnus-simplify-ignored-prefixes subject))
1437         (setq subject (substring subject (match-end 0))))
1438       (insert subject)
1439       (inline (gnus-simplify-buffer-fuzzy))
1440       (buffer-string))))
1441
1442 (defsubst gnus-simplify-subject-fully (subject)
1443   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1444   (cond
1445    (gnus-simplify-subject-functions
1446     (gnus-map-function gnus-simplify-subject-functions subject))
1447    ((null gnus-summary-gather-subject-limit)
1448     (gnus-simplify-subject-re subject))
1449    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1450     (gnus-simplify-subject-fuzzy subject))
1451    ((numberp gnus-summary-gather-subject-limit)
1452     (gnus-limit-string (gnus-simplify-subject-re subject)
1453                        gnus-summary-gather-subject-limit))
1454    (t
1455     subject)))
1456
1457 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1458   "Check whether two subjects are equal.
1459 If optional argument simple-first is t, first argument is already
1460 simplified."
1461   (cond
1462    ((null simple-first)
1463     (equal (gnus-simplify-subject-fully s1)
1464            (gnus-simplify-subject-fully s2)))
1465    (t
1466     (equal s1
1467            (gnus-simplify-subject-fully s2)))))
1468
1469 (defun gnus-summary-bubble-group ()
1470   "Increase the score of the current group.
1471 This is a handy function to add to `gnus-summary-exit-hook' to
1472 increase the score of each group you read."
1473   (gnus-group-add-score gnus-newsgroup-name))
1474
1475 \f
1476 ;;;
1477 ;;; Gnus summary mode
1478 ;;;
1479
1480 (put 'gnus-summary-mode 'mode-class 'special)
1481
1482 (defvar gnus-article-commands-menu)
1483
1484 (when t
1485   ;; Non-orthogonal keys
1486
1487   (gnus-define-keys gnus-summary-mode-map
1488     " " gnus-summary-next-page
1489     "\177" gnus-summary-prev-page
1490     [delete] gnus-summary-prev-page
1491     [backspace] gnus-summary-prev-page
1492     "\r" gnus-summary-scroll-up
1493     "\M-\r" gnus-summary-scroll-down
1494     "n" gnus-summary-next-unread-article
1495     "p" gnus-summary-prev-unread-article
1496     "N" gnus-summary-next-article
1497     "P" gnus-summary-prev-article
1498     "\M-\C-n" gnus-summary-next-same-subject
1499     "\M-\C-p" gnus-summary-prev-same-subject
1500     "\M-n" gnus-summary-next-unread-subject
1501     "\M-p" gnus-summary-prev-unread-subject
1502     "." gnus-summary-first-unread-article
1503     "," gnus-summary-best-unread-article
1504     "\M-s" gnus-summary-search-article-forward
1505     "\M-r" gnus-summary-search-article-backward
1506     "<" gnus-summary-beginning-of-article
1507     ">" gnus-summary-end-of-article
1508     "j" gnus-summary-goto-article
1509     "^" gnus-summary-refer-parent-article
1510     "\M-^" gnus-summary-refer-article
1511     "u" gnus-summary-tick-article-forward
1512     "!" gnus-summary-tick-article-forward
1513     "U" gnus-summary-tick-article-backward
1514     "d" gnus-summary-mark-as-read-forward
1515     "D" gnus-summary-mark-as-read-backward
1516     "E" gnus-summary-mark-as-expirable
1517     "\M-u" gnus-summary-clear-mark-forward
1518     "\M-U" gnus-summary-clear-mark-backward
1519     "k" gnus-summary-kill-same-subject-and-select
1520     "\C-k" gnus-summary-kill-same-subject
1521     "\M-\C-k" gnus-summary-kill-thread
1522     "\M-\C-l" gnus-summary-lower-thread
1523     "e" gnus-summary-edit-article
1524     "#" gnus-summary-mark-as-processable
1525     "\M-#" gnus-summary-unmark-as-processable
1526     "\M-\C-t" gnus-summary-toggle-threads
1527     "\M-\C-s" gnus-summary-show-thread
1528     "\M-\C-h" gnus-summary-hide-thread
1529     "\M-\C-f" gnus-summary-next-thread
1530     "\M-\C-b" gnus-summary-prev-thread
1531     [(meta down)] gnus-summary-next-thread
1532     [(meta up)] gnus-summary-prev-thread
1533     "\M-\C-u" gnus-summary-up-thread
1534     "\M-\C-d" gnus-summary-down-thread
1535     "&" gnus-summary-execute-command
1536     "c" gnus-summary-catchup-and-exit
1537     "\C-w" gnus-summary-mark-region-as-read
1538     "\C-t" gnus-summary-toggle-truncation
1539     "?" gnus-summary-mark-as-dormant
1540     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1541     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1542     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1543     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1544     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1545     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1546     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1547     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1548     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1549     "=" gnus-summary-expand-window
1550     "\C-x\C-s" gnus-summary-reselect-current-group
1551     "\M-g" gnus-summary-rescan-group
1552     "w" gnus-summary-stop-page-breaking
1553     "\C-c\C-r" gnus-summary-caesar-message
1554     "\M-t" gnus-summary-toggle-mime
1555     "f" gnus-summary-followup
1556     "F" gnus-summary-followup-with-original
1557     "C" gnus-summary-cancel-article
1558     "r" gnus-summary-reply
1559     "R" gnus-summary-reply-with-original
1560     "\C-c\C-f" gnus-summary-mail-forward
1561     "o" gnus-summary-save-article
1562     "\C-o" gnus-summary-save-article-mail
1563     "|" gnus-summary-pipe-output
1564     "\M-k" gnus-summary-edit-local-kill
1565     "\M-K" gnus-summary-edit-global-kill
1566     ;; "V" gnus-version
1567     "\C-c\C-d" gnus-summary-describe-group
1568     "q" gnus-summary-exit
1569     "Q" gnus-summary-exit-no-update
1570     "\C-c\C-i" gnus-info-find-node
1571     gnus-mouse-2 gnus-mouse-pick-article
1572     "m" gnus-summary-mail-other-window
1573     "a" gnus-summary-post-news
1574     "i" gnus-summary-news-other-window
1575     "x" gnus-summary-limit-to-unread
1576     "s" gnus-summary-isearch-article
1577     "t" gnus-article-toggle-headers
1578     "g" gnus-summary-show-article
1579     "l" gnus-summary-goto-last-article
1580     "v" gnus-summary-preview-mime-message
1581     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1582     "\C-d" gnus-summary-enter-digest-group
1583     "\M-\C-d" gnus-summary-read-document
1584     "\M-\C-e" gnus-summary-edit-parameters
1585     "\M-\C-a" gnus-summary-customize-parameters
1586     "\C-c\C-b" gnus-bug
1587     "\C-c\C-n" gnus-namazu-search
1588     "*" gnus-cache-enter-article
1589     "\M-*" gnus-cache-remove-article
1590     "\M-&" gnus-summary-universal-argument
1591     "\C-l" gnus-recenter
1592     "I" gnus-summary-increase-score
1593     "L" gnus-summary-lower-score
1594     "\M-i" gnus-symbolic-argument
1595     "h" gnus-summary-select-article-buffer
1596
1597     "V" gnus-summary-score-map
1598     "X" gnus-uu-extract-map
1599     "S" gnus-summary-send-map)
1600
1601   ;; Sort of orthogonal keymap
1602   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1603     "t" gnus-summary-tick-article-forward
1604     "!" gnus-summary-tick-article-forward
1605     "d" gnus-summary-mark-as-read-forward
1606     "r" gnus-summary-mark-as-read-forward
1607     "c" gnus-summary-clear-mark-forward
1608     " " gnus-summary-clear-mark-forward
1609     "e" gnus-summary-mark-as-expirable
1610     "x" gnus-summary-mark-as-expirable
1611     "?" gnus-summary-mark-as-dormant
1612     "b" gnus-summary-set-bookmark
1613     "B" gnus-summary-remove-bookmark
1614     "#" gnus-summary-mark-as-processable
1615     "\M-#" gnus-summary-unmark-as-processable
1616     "S" gnus-summary-limit-include-expunged
1617     "C" gnus-summary-catchup
1618     "H" gnus-summary-catchup-to-here
1619     "h" gnus-summary-catchup-from-here
1620     "\C-c" gnus-summary-catchup-all
1621     "k" gnus-summary-kill-same-subject-and-select
1622     "K" gnus-summary-kill-same-subject
1623     "P" gnus-uu-mark-map)
1624
1625   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1626     "c" gnus-summary-clear-above
1627     "u" gnus-summary-tick-above
1628     "m" gnus-summary-mark-above
1629     "k" gnus-summary-kill-below)
1630
1631   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1632     "/" gnus-summary-limit-to-subject
1633     "n" gnus-summary-limit-to-articles
1634     "w" gnus-summary-pop-limit
1635     "s" gnus-summary-limit-to-subject
1636     "a" gnus-summary-limit-to-author
1637     "u" gnus-summary-limit-to-unread
1638     "m" gnus-summary-limit-to-marks
1639     "M" gnus-summary-limit-exclude-marks
1640     "v" gnus-summary-limit-to-score
1641     "*" gnus-summary-limit-include-cached
1642     "D" gnus-summary-limit-include-dormant
1643     "T" gnus-summary-limit-include-thread
1644     "d" gnus-summary-limit-exclude-dormant
1645     "t" gnus-summary-limit-to-age
1646     "x" gnus-summary-limit-to-extra
1647     "p" gnus-summary-limit-to-display-predicate
1648     "E" gnus-summary-limit-include-expunged
1649     "c" gnus-summary-limit-exclude-childless-dormant
1650     "C" gnus-summary-limit-mark-excluded-as-read
1651     "o" gnus-summary-insert-old-articles
1652     "N" gnus-summary-insert-new-articles)
1653
1654   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1655     "n" gnus-summary-next-unread-article
1656     "p" gnus-summary-prev-unread-article
1657     "N" gnus-summary-next-article
1658     "P" gnus-summary-prev-article
1659     "\C-n" gnus-summary-next-same-subject
1660     "\C-p" gnus-summary-prev-same-subject
1661     "\M-n" gnus-summary-next-unread-subject
1662     "\M-p" gnus-summary-prev-unread-subject
1663     "f" gnus-summary-first-unread-article
1664     "b" gnus-summary-best-unread-article
1665     "j" gnus-summary-goto-article
1666     "g" gnus-summary-goto-subject
1667     "l" gnus-summary-goto-last-article
1668     "o" gnus-summary-pop-article)
1669
1670   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1671     "k" gnus-summary-kill-thread
1672     "l" gnus-summary-lower-thread
1673     "i" gnus-summary-raise-thread
1674     "T" gnus-summary-toggle-threads
1675     "t" gnus-summary-rethread-current
1676     "^" gnus-summary-reparent-thread
1677     "s" gnus-summary-show-thread
1678     "S" gnus-summary-show-all-threads
1679     "h" gnus-summary-hide-thread
1680     "H" gnus-summary-hide-all-threads
1681     "n" gnus-summary-next-thread
1682     "p" gnus-summary-prev-thread
1683     "u" gnus-summary-up-thread
1684     "o" gnus-summary-top-thread
1685     "d" gnus-summary-down-thread
1686     "#" gnus-uu-mark-thread
1687     "\M-#" gnus-uu-unmark-thread)
1688
1689   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1690     "g" gnus-summary-prepare
1691     "c" gnus-summary-insert-cached-articles)
1692
1693   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1694     "c" gnus-summary-catchup-and-exit
1695     "C" gnus-summary-catchup-all-and-exit
1696     "E" gnus-summary-exit-no-update
1697     "J" gnus-summary-jump-to-other-group
1698     "Q" gnus-summary-exit
1699     "Z" gnus-summary-exit
1700     "n" gnus-summary-catchup-and-goto-next-group
1701     "R" gnus-summary-reselect-current-group
1702     "G" gnus-summary-rescan-group
1703     "N" gnus-summary-next-group
1704     "s" gnus-summary-save-newsrc
1705     "P" gnus-summary-prev-group)
1706
1707   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1708     " " gnus-summary-next-page
1709     "n" gnus-summary-next-page
1710     "\177" gnus-summary-prev-page
1711     [delete] gnus-summary-prev-page
1712     "p" gnus-summary-prev-page
1713     "\r" gnus-summary-scroll-up
1714     "\M-\r" gnus-summary-scroll-down
1715     "<" gnus-summary-beginning-of-article
1716     ">" gnus-summary-end-of-article
1717     "b" gnus-summary-beginning-of-article
1718     "e" gnus-summary-end-of-article
1719     "^" gnus-summary-refer-parent-article
1720     "r" gnus-summary-refer-parent-article
1721     "D" gnus-summary-enter-digest-group
1722     "R" gnus-summary-refer-references
1723     "T" gnus-summary-refer-thread
1724     "g" gnus-summary-show-article
1725     "s" gnus-summary-isearch-article
1726     "P" gnus-summary-print-article
1727     "M" gnus-mailing-list-insinuate
1728     "t" gnus-article-babel)
1729
1730   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1731     "b" gnus-article-add-buttons
1732     "B" gnus-article-add-buttons-to-head
1733     "o" gnus-article-treat-overstrike
1734     "e" gnus-article-emphasize
1735     "w" gnus-article-fill-cited-article
1736     "Q" gnus-article-fill-long-lines
1737     "C" gnus-article-capitalize-sentences
1738     "c" gnus-article-remove-cr
1739     "Z" gnus-article-decode-HZ
1740     "f" gnus-article-display-x-face
1741     "l" gnus-summary-stop-page-breaking
1742     "r" gnus-summary-caesar-message
1743     "t" gnus-article-toggle-headers
1744     "g" gnus-summary-toggle-smiley
1745     "u" gnus-article-treat-unfold-headers
1746     "n" gnus-article-treat-fold-newsgroups
1747     "v" gnus-summary-verbose-headers
1748     "m" gnus-summary-toggle-mime
1749     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1750     "p" gnus-article-verify-x-pgp-sig
1751     "d" gnus-article-treat-dumbquotes)
1752
1753   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1754     "a" gnus-article-hide
1755     "h" gnus-article-toggle-headers
1756     "b" gnus-article-hide-boring-headers
1757     "s" gnus-article-hide-signature
1758     "c" gnus-article-hide-citation
1759     "C" gnus-article-hide-citation-in-followups
1760     "l" gnus-article-hide-list-identifiers
1761     "p" gnus-article-hide-pgp
1762     "B" gnus-article-strip-banner
1763     "P" gnus-article-hide-pem
1764     "\C-c" gnus-article-hide-citation-maybe)
1765
1766   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1767     "a" gnus-article-highlight
1768     "h" gnus-article-highlight-headers
1769     "c" gnus-article-highlight-citation
1770     "s" gnus-article-highlight-signature)
1771
1772   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1773     "x" gnus-article-display-x-face
1774     "s" gnus-summary-toggle-smiley
1775     "f" gnus-treat-from-picon
1776     "m" gnus-treat-mail-picon
1777     "n" gnus-treat-newsgroups-picon)
1778
1779   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1780     "z" gnus-article-date-ut
1781     "u" gnus-article-date-ut
1782     "l" gnus-article-date-local
1783     "p" gnus-article-date-english
1784     "e" gnus-article-date-lapsed
1785     "o" gnus-article-date-original
1786     "i" gnus-article-date-iso8601
1787     "s" gnus-article-date-user)
1788
1789   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1790     "t" gnus-article-remove-trailing-blank-lines
1791     "l" gnus-article-strip-leading-blank-lines
1792     "m" gnus-article-strip-multiple-blank-lines
1793     "a" gnus-article-strip-blank-lines
1794     "A" gnus-article-strip-all-blank-lines
1795     "s" gnus-article-strip-leading-space
1796     "e" gnus-article-strip-trailing-space
1797     "w" gnus-article-remove-leading-whitespace)
1798
1799   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1800     "v" gnus-version
1801     "f" gnus-summary-fetch-faq
1802     "d" gnus-summary-describe-group
1803     "h" gnus-summary-describe-briefly
1804     "i" gnus-info-find-node)
1805
1806   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1807     "e" gnus-summary-expire-articles
1808     "\M-\C-e" gnus-summary-expire-articles-now
1809     "\177" gnus-summary-delete-article
1810     [delete] gnus-summary-delete-article
1811     [backspace] gnus-summary-delete-article
1812     "m" gnus-summary-move-article
1813     "r" gnus-summary-respool-article
1814     "w" gnus-summary-edit-article
1815     "c" gnus-summary-copy-article
1816     "B" gnus-summary-crosspost-article
1817     "q" gnus-summary-respool-query
1818     "t" gnus-summary-respool-trace
1819     "i" gnus-summary-import-article
1820     "I" gnus-summary-create-article
1821     "p" gnus-summary-article-posted-p)
1822
1823   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1824     "o" gnus-summary-save-article
1825     "m" gnus-summary-save-article-mail
1826     "F" gnus-summary-write-article-file
1827     "r" gnus-summary-save-article-rmail
1828     "f" gnus-summary-save-article-file
1829     "b" gnus-summary-save-article-body-file
1830     "h" gnus-summary-save-article-folder
1831     "v" gnus-summary-save-article-vm
1832     "p" gnus-summary-pipe-output
1833     "P" gnus-summary-muttprint
1834     "s" gnus-soup-add-article)
1835
1836   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1837     "b" gnus-summary-display-buttonized
1838     "m" gnus-summary-repair-multipart
1839     "v" gnus-article-view-part
1840     "o" gnus-article-save-part
1841     "c" gnus-article-copy-part
1842     "C" gnus-article-view-part-as-charset
1843     "e" gnus-article-externalize-part
1844     "E" gnus-article-encrypt-body
1845     "i" gnus-article-inline-part
1846     "|" gnus-article-pipe-part))
1847
1848 (defvar gnus-article-post-menu nil)
1849
1850 (defun gnus-summary-make-menu-bar ()
1851   (gnus-turn-off-edit-menu 'summary)
1852
1853   (unless (boundp 'gnus-summary-misc-menu)
1854
1855     (easy-menu-define
1856      gnus-summary-kill-menu gnus-summary-mode-map ""
1857      (cons
1858       "Score"
1859       (nconc
1860        (list
1861         ["Customize" gnus-score-customize t])
1862        (gnus-make-score-map 'increase)
1863        (gnus-make-score-map 'lower)
1864        '(("Mark"
1865           ["Kill below" gnus-summary-kill-below t]
1866           ["Mark above" gnus-summary-mark-above t]
1867           ["Tick above" gnus-summary-tick-above t]
1868           ["Clear above" gnus-summary-clear-above t])
1869          ["Current score" gnus-summary-current-score t]
1870          ["Set score" gnus-summary-set-score t]
1871          ["Switch current score file..." gnus-score-change-score-file t]
1872          ["Set mark below..." gnus-score-set-mark-below t]
1873          ["Set expunge below..." gnus-score-set-expunge-below t]
1874          ["Edit current score file" gnus-score-edit-current-scores t]
1875          ["Edit score file" gnus-score-edit-file t]
1876          ["Trace score" gnus-score-find-trace t]
1877          ["Find words" gnus-score-find-favourite-words t]
1878          ["Rescore buffer" gnus-summary-rescore t]
1879          ["Increase score..." gnus-summary-increase-score t]
1880          ["Lower score..." gnus-summary-lower-score t]))))
1881
1882     ;; Define both the Article menu in the summary buffer and the
1883     ;; equivalent Commands menu in the article buffer here for
1884     ;; consistency.
1885     (let ((innards
1886            `(("Hide"
1887               ["All" gnus-article-hide t]
1888               ["Headers" gnus-article-toggle-headers t]
1889               ["Signature" gnus-article-hide-signature t]
1890               ["Citation" gnus-article-hide-citation t]
1891               ["List identifiers" gnus-article-hide-list-identifiers t]
1892               ["PGP" gnus-article-hide-pgp t]
1893               ["Banner" gnus-article-strip-banner t]
1894               ["Boring headers" gnus-article-hide-boring-headers t])
1895              ("Highlight"
1896               ["All" gnus-article-highlight t]
1897               ["Headers" gnus-article-highlight-headers t]
1898               ["Signature" gnus-article-highlight-signature t]
1899               ["Citation" gnus-article-highlight-citation t])
1900              ("Date"
1901               ["Local" gnus-article-date-local t]
1902               ["ISO8601" gnus-article-date-iso8601 t]
1903               ["UT" gnus-article-date-ut t]
1904               ["Original" gnus-article-date-original t]
1905               ["Lapsed" gnus-article-date-lapsed t]
1906               ["User-defined" gnus-article-date-user t])
1907              ("Display"
1908               ["Toggle smiley" gnus-summary-toggle-smiley t]
1909               ["Show X-Face" gnus-article-display-x-face t]
1910               ["Show picons in From" gnus-treat-from-picon t]
1911               ["Show picons in mail headers" gnus-treat-mail-picon t]
1912               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1913              ("Washing"
1914               ("Remove Blanks"
1915                ["Leading" gnus-article-strip-leading-blank-lines t]
1916                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1917                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1918                ["All of the above" gnus-article-strip-blank-lines t]
1919                ["All" gnus-article-strip-all-blank-lines t]
1920                ["Leading space" gnus-article-strip-leading-space t]
1921                ["Trailing space" gnus-article-strip-trailing-space t]
1922                ["Leading space in headers"
1923                 gnus-article-remove-leading-whitespace t])
1924               ["Overstrike" gnus-article-treat-overstrike t]
1925               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1926               ["Emphasis" gnus-article-emphasize t]
1927               ["Word wrap" gnus-article-fill-cited-article t]
1928               ["Fill long lines" gnus-article-fill-long-lines t]
1929               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1930               ["CR" gnus-article-remove-cr t]
1931               ["Rot 13" gnus-summary-caesar-message
1932                ,@(if (featurep 'xemacs) '(t)
1933                    '(:help "\"Caesar rotate\" article by 13"))]
1934               ["Unix pipe" gnus-summary-pipe-message t]
1935               ["Add buttons" gnus-article-add-buttons t]
1936               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1937               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1938               ["Toggle MIME" gnus-summary-toggle-mime t]
1939               ["Verbose header" gnus-summary-verbose-headers t]
1940               ["Toggle header" gnus-summary-toggle-header t]
1941               ["Unfold headers" gnus-article-treat-unfold-headers t]
1942               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1943               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1944               ["HZ" gnus-article-decode-HZ t])
1945              ("Output"
1946               ["Save in default format" gnus-summary-save-article
1947                ,@(if (featurep 'xemacs) '(t)
1948                    '(:help "Save article using default method"))]
1949               ["Save in file" gnus-summary-save-article-file
1950                ,@(if (featurep 'xemacs) '(t)
1951                    '(:help "Save article in file"))]
1952               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1953               ["Save in MH folder" gnus-summary-save-article-folder t]
1954               ["Save in VM folder" gnus-summary-save-article-vm t]
1955               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1956               ["Save body in file" gnus-summary-save-article-body-file t]
1957               ["Pipe through a filter" gnus-summary-pipe-output t]
1958               ["Add to SOUP packet" gnus-soup-add-article t]
1959               ["Print with Muttprint" gnus-summary-muttprint t]
1960               ["Print" gnus-summary-print-article t])
1961              ("Backend"
1962               ["Respool article..." gnus-summary-respool-article t]
1963               ["Move article..." gnus-summary-move-article
1964                (gnus-check-backend-function
1965                 'request-move-article gnus-newsgroup-name)]
1966               ["Copy article..." gnus-summary-copy-article t]
1967               ["Crosspost article..." gnus-summary-crosspost-article
1968                (gnus-check-backend-function
1969                 'request-replace-article gnus-newsgroup-name)]
1970               ["Import file..." gnus-summary-import-article t]
1971               ["Create article..." gnus-summary-create-article t]
1972               ["Check if posted" gnus-summary-article-posted-p t]
1973               ["Edit article" gnus-summary-edit-article
1974                (not (gnus-group-read-only-p))]
1975               ["Delete article" gnus-summary-delete-article
1976                (gnus-check-backend-function
1977                 'request-expire-articles gnus-newsgroup-name)]
1978               ["Query respool" gnus-summary-respool-query t]
1979               ["Trace respool" gnus-summary-respool-trace t]
1980               ["Delete expirable articles" gnus-summary-expire-articles-now
1981                (gnus-check-backend-function
1982                 'request-expire-articles gnus-newsgroup-name)])
1983              ("Extract"
1984               ["Uudecode" gnus-uu-decode-uu
1985                ,@(if (featurep 'xemacs) '(t)
1986                    '(:help "Decode uuencoded article(s)"))]
1987               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1988               ["Unshar" gnus-uu-decode-unshar t]
1989               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1990               ["Save" gnus-uu-decode-save t]
1991               ["Binhex" gnus-uu-decode-binhex t]
1992               ["Postscript" gnus-uu-decode-postscript t])
1993              ("Cache"
1994               ["Enter article" gnus-cache-enter-article t]
1995               ["Remove article" gnus-cache-remove-article t])
1996              ["Translate" gnus-article-babel t]
1997              ["Select article buffer" gnus-summary-select-article-buffer t]
1998              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1999              ["Isearch article..." gnus-summary-isearch-article t]
2000              ["Beginning of the article" gnus-summary-beginning-of-article t]
2001              ["End of the article" gnus-summary-end-of-article t]
2002              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2003              ["Fetch referenced articles" gnus-summary-refer-references t]
2004              ["Fetch current thread" gnus-summary-refer-thread t]
2005              ["Fetch article with id..." gnus-summary-refer-article t]
2006              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2007              ["Redisplay" gnus-summary-show-article t]
2008              ["Raw article" gnus-summary-show-raw-article t])))
2009       (easy-menu-define
2010        gnus-summary-article-menu gnus-summary-mode-map ""
2011        (cons "Article" innards))
2012
2013       (if (not (keymapp gnus-summary-article-menu))
2014           (easy-menu-define
2015            gnus-article-commands-menu gnus-article-mode-map ""
2016            (cons "Commands" innards))
2017         ;; in Emacs, don't share menu.
2018         (setq gnus-article-commands-menu
2019               (copy-keymap gnus-summary-article-menu))
2020         (define-key gnus-article-mode-map [menu-bar commands]
2021           (cons "Commands" gnus-article-commands-menu))))
2022
2023     (easy-menu-define
2024      gnus-summary-thread-menu gnus-summary-mode-map ""
2025      '("Threads"
2026        ["Toggle threading" gnus-summary-toggle-threads t]
2027        ["Hide threads" gnus-summary-hide-all-threads t]
2028        ["Show threads" gnus-summary-show-all-threads t]
2029        ["Hide thread" gnus-summary-hide-thread t]
2030        ["Show thread" gnus-summary-show-thread t]
2031        ["Go to next thread" gnus-summary-next-thread t]
2032        ["Go to previous thread" gnus-summary-prev-thread t]
2033        ["Go down thread" gnus-summary-down-thread t]
2034        ["Go up thread" gnus-summary-up-thread t]
2035        ["Top of thread" gnus-summary-top-thread t]
2036        ["Mark thread as read" gnus-summary-kill-thread t]
2037        ["Lower thread score" gnus-summary-lower-thread t]
2038        ["Raise thread score" gnus-summary-raise-thread t]
2039        ["Rethread current" gnus-summary-rethread-current t]))
2040
2041     (easy-menu-define
2042      gnus-summary-post-menu gnus-summary-mode-map ""
2043      `("Post"
2044        ["Send a message (mail or news)" gnus-summary-post-news
2045         ,@(if (featurep 'xemacs) '(t)
2046             '(:help "Post an article"))]
2047        ["Followup" gnus-summary-followup
2048         ,@(if (featurep 'xemacs) '(t)
2049             '(:help "Post followup to this article"))]
2050        ["Followup and yank" gnus-summary-followup-with-original
2051         ,@(if (featurep 'xemacs) '(t)
2052             '(:help "Post followup to this article, quoting its contents"))]
2053        ["Supersede article" gnus-summary-supersede-article t]
2054        ["Cancel article" gnus-summary-cancel-article
2055         ,@(if (featurep 'xemacs) '(t)
2056             '(:help "Cancel an article you posted"))]
2057        ["Reply" gnus-summary-reply t]
2058        ["Reply and yank" gnus-summary-reply-with-original t]
2059        ["Wide reply" gnus-summary-wide-reply t]
2060        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2061         ,@(if (featurep 'xemacs) '(t)
2062             '(:help "Mail a reply, quoting this article"))]
2063        ["Mail forward" gnus-summary-mail-forward t]
2064        ["Post forward" gnus-summary-post-forward t]
2065        ["Digest and mail" gnus-summary-digest-mail-forward t]
2066        ["Digest and post" gnus-summary-digest-post-forward t]
2067        ["Resend message" gnus-summary-resend-message t]
2068        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2069        ["Send a mail" gnus-summary-mail-other-window t]
2070        ["Create a local message" gnus-summary-news-other-window t]
2071        ["Uuencode and post" gnus-uu-post-news
2072         ,@(if (featurep 'xemacs) '(t)
2073             '(:help "Post a uuencoded article"))]
2074        ["Followup via news" gnus-summary-followup-to-mail t]
2075        ["Followup via news and yank"
2076         gnus-summary-followup-to-mail-with-original t]
2077        ;;("Draft"
2078        ;;["Send" gnus-summary-send-draft t]
2079        ;;["Send bounced" gnus-resend-bounced-mail t])
2080        ))
2081
2082     (cond
2083      ((not (keymapp gnus-summary-post-menu))
2084       (setq gnus-article-post-menu gnus-summary-post-menu))
2085      ((not gnus-article-post-menu)
2086       ;; Don't share post menu.
2087       (setq gnus-article-post-menu
2088             (copy-keymap gnus-summary-post-menu))))
2089     (define-key gnus-article-mode-map [menu-bar post]
2090       (cons "Post" gnus-article-post-menu))
2091
2092     (easy-menu-define
2093      gnus-summary-misc-menu gnus-summary-mode-map ""
2094      `("Gnus"
2095        ("Mark Read"
2096         ["Mark as read" gnus-summary-mark-as-read-forward t]
2097         ["Mark same subject and select"
2098          gnus-summary-kill-same-subject-and-select t]
2099         ["Mark same subject" gnus-summary-kill-same-subject t]
2100         ["Catchup" gnus-summary-catchup
2101          ,@(if (featurep 'xemacs) '(t)
2102              '(:help "Mark unread articles in this group as read"))]
2103         ["Catchup all" gnus-summary-catchup-all t]
2104         ["Catchup to here" gnus-summary-catchup-to-here t]
2105         ["Catchup from here" gnus-summary-catchup-from-here t]
2106         ["Catchup region" gnus-summary-mark-region-as-read t]
2107         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2108        ("Mark Various"
2109         ["Tick" gnus-summary-tick-article-forward t]
2110         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2111         ["Remove marks" gnus-summary-clear-mark-forward t]
2112         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2113         ["Set bookmark" gnus-summary-set-bookmark t]
2114         ["Remove bookmark" gnus-summary-remove-bookmark t])
2115        ("Limit to"
2116         ["Marks..." gnus-summary-limit-to-marks t]
2117         ["Subject..." gnus-summary-limit-to-subject t]
2118         ["Author..." gnus-summary-limit-to-author t]
2119         ["Age..." gnus-summary-limit-to-age t]
2120         ["Extra..." gnus-summary-limit-to-extra t]
2121         ["Score" gnus-summary-limit-to-score t]
2122         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2123         ["Unread" gnus-summary-limit-to-unread t]
2124         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2125         ["Articles" gnus-summary-limit-to-articles t]
2126         ["Pop limit" gnus-summary-pop-limit t]
2127         ["Show dormant" gnus-summary-limit-include-dormant t]
2128         ["Hide childless dormant"
2129          gnus-summary-limit-exclude-childless-dormant t]
2130         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2131         ["Hide marked" gnus-summary-limit-exclude-marks t]
2132         ["Show expunged" gnus-summary-limit-include-expunged t])
2133        ("Process Mark"
2134         ["Set mark" gnus-summary-mark-as-processable t]
2135         ["Remove mark" gnus-summary-unmark-as-processable t]
2136         ["Remove all marks" gnus-summary-unmark-all-processable t]
2137         ["Mark above" gnus-uu-mark-over t]
2138         ["Mark series" gnus-uu-mark-series t]
2139         ["Mark region" gnus-uu-mark-region t]
2140         ["Unmark region" gnus-uu-unmark-region t]
2141         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2142         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2143         ["Mark all" gnus-uu-mark-all t]
2144         ["Mark buffer" gnus-uu-mark-buffer t]
2145         ["Mark sparse" gnus-uu-mark-sparse t]
2146         ["Mark thread" gnus-uu-mark-thread t]
2147         ["Unmark thread" gnus-uu-unmark-thread t]
2148         ("Process Mark Sets"
2149          ["Kill" gnus-summary-kill-process-mark t]
2150          ["Yank" gnus-summary-yank-process-mark
2151           gnus-newsgroup-process-stack]
2152          ["Save" gnus-summary-save-process-mark t]))
2153        ("Scroll article"
2154         ["Page forward" gnus-summary-next-page
2155          ,@(if (featurep 'xemacs) '(t)
2156              '(:help "Show next page of article"))]
2157         ["Page backward" gnus-summary-prev-page
2158          ,@(if (featurep 'xemacs) '(t)
2159              '(:help "Show previous page of article"))]
2160         ["Line forward" gnus-summary-scroll-up t])
2161        ("Move"
2162         ["Next unread article" gnus-summary-next-unread-article t]
2163         ["Previous unread article" gnus-summary-prev-unread-article t]
2164         ["Next article" gnus-summary-next-article t]
2165         ["Previous article" gnus-summary-prev-article t]
2166         ["Next unread subject" gnus-summary-next-unread-subject t]
2167         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2168         ["Next article same subject" gnus-summary-next-same-subject t]
2169         ["Previous article same subject" gnus-summary-prev-same-subject t]
2170         ["First unread article" gnus-summary-first-unread-article t]
2171         ["Best unread article" gnus-summary-best-unread-article t]
2172         ["Go to subject number..." gnus-summary-goto-subject t]
2173         ["Go to article number..." gnus-summary-goto-article t]
2174         ["Go to the last article" gnus-summary-goto-last-article t]
2175         ["Pop article off history" gnus-summary-pop-article t])
2176        ("Sort"
2177         ["Sort by number" gnus-summary-sort-by-number t]
2178         ["Sort by author" gnus-summary-sort-by-author t]
2179         ["Sort by subject" gnus-summary-sort-by-subject t]
2180         ["Sort by date" gnus-summary-sort-by-date t]
2181         ["Sort by score" gnus-summary-sort-by-score t]
2182         ["Sort by lines" gnus-summary-sort-by-lines t]
2183         ["Sort by characters" gnus-summary-sort-by-chars t]
2184         ["Original sort" gnus-summary-sort-by-original t])
2185        ("Help"
2186         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2187         ["Describe group" gnus-summary-describe-group t]
2188         ["Read manual" gnus-info-find-node t])
2189        ("Modes"
2190         ["Pick and read" gnus-pick-mode t]
2191         ["Binary" gnus-binary-mode t])
2192        ("Regeneration"
2193         ["Regenerate" gnus-summary-prepare t]
2194         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2195         ["Toggle threading" gnus-summary-toggle-threads t])
2196        ["See old articles" gnus-summary-insert-old-articles t]
2197        ["See new articles" gnus-summary-insert-new-articles t]
2198        ["Filter articles..." gnus-summary-execute-command t]
2199        ["Run command on subjects..." gnus-summary-universal-argument t]
2200        ["Search articles forward..." gnus-summary-search-article-forward t]
2201        ["Search articles backward..." gnus-summary-search-article-backward t]
2202        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2203        ["Expand window" gnus-summary-expand-window t]
2204        ["Expire expirable articles" gnus-summary-expire-articles
2205         (gnus-check-backend-function
2206          'request-expire-articles gnus-newsgroup-name)]
2207        ["Edit local kill file" gnus-summary-edit-local-kill t]
2208        ["Edit main kill file" gnus-summary-edit-global-kill t]
2209        ["Edit group parameters" gnus-summary-edit-parameters t]
2210        ["Customize group parameters" gnus-summary-customize-parameters t]
2211        ["Send a bug report" gnus-bug t]
2212        ("Exit"
2213         ["Catchup and exit" gnus-summary-catchup-and-exit
2214          ,@(if (featurep 'xemacs) '(t)
2215              '(:help "Mark unread articles in this group as read, then exit"))]
2216         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2217         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2218         ["Exit group" gnus-summary-exit
2219          ,@(if (featurep 'xemacs) '(t)
2220              '(:help "Exit current group, return to group selection mode"))]
2221         ["Exit group without updating" gnus-summary-exit-no-update t]
2222         ["Exit and goto next group" gnus-summary-next-group t]
2223         ["Exit and goto prev group" gnus-summary-prev-group t]
2224         ["Reselect group" gnus-summary-reselect-current-group t]
2225         ["Rescan group" gnus-summary-rescan-group t]
2226         ["Update dribble" gnus-summary-save-newsrc t])))
2227
2228     (gnus-run-hooks 'gnus-summary-menu-hook)))
2229
2230 (defvar gnus-summary-tool-bar-map nil)
2231
2232 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2233 (defun gnus-summary-make-tool-bar ()
2234   (if (and (fboundp 'tool-bar-add-item-from-menu)
2235            (default-value 'tool-bar-mode)
2236            (not gnus-summary-tool-bar-map))
2237       (setq gnus-summary-tool-bar-map
2238             (let ((tool-bar-map (make-sparse-keymap))
2239                   (load-path (mm-image-load-path)))
2240               (tool-bar-add-item-from-menu
2241                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2242               (tool-bar-add-item-from-menu
2243                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2244               (tool-bar-add-item-from-menu
2245                'gnus-summary-post-news "post" gnus-summary-mode-map)
2246               (tool-bar-add-item-from-menu
2247                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2248               (tool-bar-add-item-from-menu
2249                'gnus-summary-followup "followup" gnus-summary-mode-map)
2250               (tool-bar-add-item-from-menu
2251                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2252               (tool-bar-add-item-from-menu
2253                'gnus-summary-reply "reply" gnus-summary-mode-map)
2254               (tool-bar-add-item-from-menu
2255                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2256               (tool-bar-add-item-from-menu
2257                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2258               (tool-bar-add-item-from-menu
2259                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2260               (tool-bar-add-item-from-menu
2261                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2262               (tool-bar-add-item-from-menu
2263                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2264               (tool-bar-add-item-from-menu
2265                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2266               (tool-bar-add-item-from-menu
2267                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2268               (tool-bar-add-item-from-menu
2269                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2270               tool-bar-map)))
2271   (if gnus-summary-tool-bar-map
2272       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2273
2274 (defun gnus-score-set-default (var value)
2275   "A version of set that updates the GNU Emacs menu-bar."
2276   (set var value)
2277   ;; It is the message that forces the active status to be updated.
2278   (message ""))
2279
2280 (defun gnus-make-score-map (type)
2281   "Make a summary score map of type TYPE."
2282   (if t
2283       nil
2284     (let ((headers '(("author" "from" string)
2285                      ("subject" "subject" string)
2286                      ("article body" "body" string)
2287                      ("article head" "head" string)
2288                      ("xref" "xref" string)
2289                      ("extra header" "extra" string)
2290                      ("lines" "lines" number)
2291                      ("followups to author" "followup" string)))
2292           (types '((number ("less than" <)
2293                            ("greater than" >)
2294                            ("equal" =))
2295                    (string ("substring" s)
2296                            ("exact string" e)
2297                            ("fuzzy string" f)
2298                            ("regexp" r))))
2299           (perms '(("temporary" (current-time-string))
2300                    ("permanent" nil)
2301                    ("immediate" now)))
2302           header)
2303       (list
2304        (apply
2305         'nconc
2306         (list
2307          (if (eq type 'lower)
2308              "Lower score"
2309            "Increase score"))
2310         (let (outh)
2311           (while headers
2312             (setq header (car headers))
2313             (setq outh
2314                   (cons
2315                    (apply
2316                     'nconc
2317                     (list (car header))
2318                     (let ((ts (cdr (assoc (nth 2 header) types)))
2319                           outt)
2320                       (while ts
2321                         (setq outt
2322                               (cons
2323                                (apply
2324                                 'nconc
2325                                 (list (caar ts))
2326                                 (let ((ps perms)
2327                                       outp)
2328                                   (while ps
2329                                     (setq outp
2330                                           (cons
2331                                            (vector
2332                                             (caar ps)
2333                                             (list
2334                                              'gnus-summary-score-entry
2335                                              (nth 1 header)
2336                                              (if (or (string= (nth 1 header)
2337                                                               "head")
2338                                                      (string= (nth 1 header)
2339                                                               "body"))
2340                                                  ""
2341                                                (list 'gnus-summary-header
2342                                                      (nth 1 header)))
2343                                              (list 'quote (nth 1 (car ts)))
2344                                              (list 'gnus-score-delta-default
2345                                                    nil)
2346                                              (nth 1 (car ps))
2347                                              t)
2348                                             t)
2349                                            outp))
2350                                     (setq ps (cdr ps)))
2351                                   (list (nreverse outp))))
2352                                outt))
2353                         (setq ts (cdr ts)))
2354                       (list (nreverse outt))))
2355                    outh))
2356             (setq headers (cdr headers)))
2357           (list (nreverse outh))))))))
2358
2359 \f
2360
2361 (defun gnus-summary-mode (&optional group)
2362   "Major mode for reading articles.
2363
2364 All normal editing commands are switched off.
2365 \\<gnus-summary-mode-map>
2366 Each line in this buffer represents one article.  To read an
2367 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2368 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2369 respectively.
2370
2371 You can also post articles and send mail from this buffer.  To
2372 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2373 of an article, type `\\[gnus-summary-reply]'.
2374
2375 There are approx. one gazillion commands you can execute in this
2376 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2377
2378 The following commands are available:
2379
2380 \\{gnus-summary-mode-map}"
2381   (interactive)
2382   (kill-all-local-variables)
2383   (when (gnus-visual-p 'summary-menu 'menu)
2384     (gnus-summary-make-menu-bar)
2385     (gnus-summary-make-tool-bar))
2386   (gnus-summary-make-local-variables)
2387   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2388     (gnus-summary-make-local-variables))
2389   (gnus-make-thread-indent-array)
2390   (gnus-simplify-mode-line)
2391   (setq major-mode 'gnus-summary-mode)
2392   (setq mode-name "Summary")
2393   (make-local-variable 'minor-mode-alist)
2394   (use-local-map gnus-summary-mode-map)
2395   (buffer-disable-undo)
2396   (setq buffer-read-only t)             ;Disable modification
2397   (setq truncate-lines t)
2398   (setq selective-display t)
2399   (setq selective-display-ellipses t)   ;Display `...'
2400   (gnus-summary-set-display-table)
2401   (gnus-set-default-directory)
2402   (setq gnus-newsgroup-name group)
2403   (unless (gnus-news-group-p group)
2404     (setq gnus-newsgroup-incorporated
2405           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2406   (make-local-variable 'gnus-summary-line-format)
2407   (make-local-variable 'gnus-summary-line-format-spec)
2408   (make-local-variable 'gnus-summary-dummy-line-format)
2409   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2410   (make-local-variable 'gnus-summary-mark-positions)
2411   (make-local-hook 'pre-command-hook)
2412   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2413   (gnus-run-hooks 'gnus-summary-mode-hook)
2414   (turn-on-gnus-mailing-list-mode)
2415   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2416   (gnus-update-summary-mark-positions))
2417
2418 (defun gnus-summary-make-local-variables ()
2419   "Make all the local summary buffer variables."
2420   (let (global)
2421     (dolist (local gnus-summary-local-variables)
2422       (if (consp local)
2423           (progn
2424             (if (eq (cdr local) 'global)
2425                 ;; Copy the global value of the variable.
2426                 (setq global (symbol-value (car local)))
2427               ;; Use the value from the list.
2428               (setq global (eval (cdr local))))
2429             (set (make-local-variable (car local)) global))
2430         ;; Simple nil-valued local variable.
2431         (set (make-local-variable local) nil)))))
2432
2433 (defun gnus-summary-clear-local-variables ()
2434   (let ((locals gnus-summary-local-variables))
2435     (while locals
2436       (if (consp (car locals))
2437           (and (vectorp (caar locals))
2438                (set (caar locals) nil))
2439         (and (vectorp (car locals))
2440              (set (car locals) nil)))
2441       (setq locals (cdr locals)))))
2442
2443 ;; Summary data functions.
2444
2445 (defmacro gnus-data-number (data)
2446   `(car ,data))
2447
2448 (defmacro gnus-data-set-number (data number)
2449   `(setcar ,data ,number))
2450
2451 (defmacro gnus-data-mark (data)
2452   `(nth 1 ,data))
2453
2454 (defmacro gnus-data-set-mark (data mark)
2455   `(setcar (nthcdr 1 ,data) ,mark))
2456
2457 (defmacro gnus-data-pos (data)
2458   `(nth 2 ,data))
2459
2460 (defmacro gnus-data-set-pos (data pos)
2461   `(setcar (nthcdr 2 ,data) ,pos))
2462
2463 (defmacro gnus-data-header (data)
2464   `(nth 3 ,data))
2465
2466 (defmacro gnus-data-set-header (data header)
2467   `(setcar (nthcdr 3 ,data) ,header))
2468
2469 (defmacro gnus-data-level (data)
2470   `(nth 4 ,data))
2471
2472 (defmacro gnus-data-unread-p (data)
2473   `(= (nth 1 ,data) gnus-unread-mark))
2474
2475 (defmacro gnus-data-read-p (data)
2476   `(/= (nth 1 ,data) gnus-unread-mark))
2477
2478 (defmacro gnus-data-pseudo-p (data)
2479   `(consp (nth 3 ,data)))
2480
2481 (defmacro gnus-data-find (number)
2482   `(assq ,number gnus-newsgroup-data))
2483
2484 (defmacro gnus-data-find-list (number &optional data)
2485   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2486      (memq (assq ,number bdata)
2487            bdata)))
2488
2489 (defmacro gnus-data-make (number mark pos header level)
2490   `(list ,number ,mark ,pos ,header ,level))
2491
2492 (defun gnus-data-enter (after-article number mark pos header level offset)
2493   (let ((data (gnus-data-find-list after-article)))
2494     (unless data
2495       (error "No such article: %d" after-article))
2496     (setcdr data (cons (gnus-data-make number mark pos header level)
2497                        (cdr data)))
2498     (setq gnus-newsgroup-data-reverse nil)
2499     (gnus-data-update-list (cddr data) offset)))
2500
2501 (defun gnus-data-enter-list (after-article list &optional offset)
2502   (when list
2503     (let ((data (and after-article (gnus-data-find-list after-article)))
2504           (ilist list))
2505       (if (not (or data
2506                    after-article))
2507           (let ((odata gnus-newsgroup-data))
2508             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2509             (when offset
2510               (gnus-data-update-list odata offset)))
2511         ;; Find the last element in the list to be spliced into the main
2512         ;; list.
2513         (while (cdr list)
2514           (setq list (cdr list)))
2515         (if (not data)
2516             (progn
2517               (setcdr list gnus-newsgroup-data)
2518               (setq gnus-newsgroup-data ilist)
2519               (when offset
2520                 (gnus-data-update-list (cdr list) offset)))
2521           (setcdr list (cdr data))
2522           (setcdr data ilist)
2523           (when offset
2524             (gnus-data-update-list (cdr list) offset))))
2525       (setq gnus-newsgroup-data-reverse nil))))
2526
2527 (defun gnus-data-remove (article &optional offset)
2528   (let ((data gnus-newsgroup-data))
2529     (if (= (gnus-data-number (car data)) article)
2530         (progn
2531           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2532                 gnus-newsgroup-data-reverse nil)
2533           (when offset
2534             (gnus-data-update-list gnus-newsgroup-data offset)))
2535       (while (cdr data)
2536         (when (= (gnus-data-number (cadr data)) article)
2537           (setcdr data (cddr data))
2538           (when offset
2539             (gnus-data-update-list (cdr data) offset))
2540           (setq data nil
2541                 gnus-newsgroup-data-reverse nil))
2542         (setq data (cdr data))))))
2543
2544 (defmacro gnus-data-list (backward)
2545   `(if ,backward
2546        (or gnus-newsgroup-data-reverse
2547            (setq gnus-newsgroup-data-reverse
2548                  (reverse gnus-newsgroup-data)))
2549      gnus-newsgroup-data))
2550
2551 (defun gnus-data-update-list (data offset)
2552   "Add OFFSET to the POS of all data entries in DATA."
2553   (setq gnus-newsgroup-data-reverse nil)
2554   (while data
2555     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2556     (setq data (cdr data))))
2557
2558 (defun gnus-summary-article-pseudo-p (article)
2559   "Say whether this article is a pseudo article or not."
2560   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2561
2562 (defmacro gnus-summary-article-sparse-p (article)
2563   "Say whether this article is a sparse article or not."
2564   `(memq ,article gnus-newsgroup-sparse))
2565
2566 (defmacro gnus-summary-article-ancient-p (article)
2567   "Say whether this article is a sparse article or not."
2568   `(memq ,article gnus-newsgroup-ancient))
2569
2570 (defun gnus-article-parent-p (number)
2571   "Say whether this article is a parent or not."
2572   (let ((data (gnus-data-find-list number)))
2573     (and (cdr data)                     ; There has to be an article after...
2574          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2575             (gnus-data-level (nth 1 data))))))
2576
2577 (defun gnus-article-children (number)
2578   "Return a list of all children to NUMBER."
2579   (let* ((data (gnus-data-find-list number))
2580          (level (gnus-data-level (car data)))
2581          children)
2582     (setq data (cdr data))
2583     (while (and data
2584                 (= (gnus-data-level (car data)) (1+ level)))
2585       (push (gnus-data-number (car data)) children)
2586       (setq data (cdr data)))
2587     children))
2588
2589 (defmacro gnus-summary-skip-intangible ()
2590   "If the current article is intangible, then jump to a different article."
2591   '(let ((to (get-text-property (point) 'gnus-intangible)))
2592      (and to (gnus-summary-goto-subject to))))
2593
2594 (defmacro gnus-summary-article-intangible-p ()
2595   "Say whether this article is intangible or not."
2596   '(get-text-property (point) 'gnus-intangible))
2597
2598 (defun gnus-article-read-p (article)
2599   "Say whether ARTICLE is read or not."
2600   (not (or (memq article gnus-newsgroup-marked)
2601            (memq article gnus-newsgroup-unreads)
2602            (memq article gnus-newsgroup-unselected)
2603            (memq article gnus-newsgroup-dormant))))
2604
2605 ;; Some summary mode macros.
2606
2607 (defmacro gnus-summary-article-number ()
2608   "The article number of the article on the current line.
2609 If there isn's an article number here, then we return the current
2610 article number."
2611   '(progn
2612      (gnus-summary-skip-intangible)
2613      (or (get-text-property (point) 'gnus-number)
2614          (gnus-summary-last-subject))))
2615
2616 (defmacro gnus-summary-article-header (&optional number)
2617   "Return the header of article NUMBER."
2618   `(gnus-data-header (gnus-data-find
2619                       ,(or number '(gnus-summary-article-number)))))
2620
2621 (defmacro gnus-summary-thread-level (&optional number)
2622   "Return the level of thread that starts with article NUMBER."
2623   `(if (and (eq gnus-summary-make-false-root 'dummy)
2624             (get-text-property (point) 'gnus-intangible))
2625        0
2626      (gnus-data-level (gnus-data-find
2627                        ,(or number '(gnus-summary-article-number))))))
2628
2629 (defmacro gnus-summary-article-mark (&optional number)
2630   "Return the mark of article NUMBER."
2631   `(gnus-data-mark (gnus-data-find
2632                     ,(or number '(gnus-summary-article-number)))))
2633
2634 (defmacro gnus-summary-article-pos (&optional number)
2635   "Return the position of the line of article NUMBER."
2636   `(gnus-data-pos (gnus-data-find
2637                    ,(or number '(gnus-summary-article-number)))))
2638
2639 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2640 (defmacro gnus-summary-article-subject (&optional number)
2641   "Return current subject string or nil if nothing."
2642   `(let ((headers
2643           ,(if number
2644                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2645              '(gnus-data-header (assq (gnus-summary-article-number)
2646                                       gnus-newsgroup-data)))))
2647      (and headers
2648           (vectorp headers)
2649           (mail-header-subject headers))))
2650
2651 (defmacro gnus-summary-article-score (&optional number)
2652   "Return current article score."
2653   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2654                   gnus-newsgroup-scored))
2655        gnus-summary-default-score 0))
2656
2657 (defun gnus-summary-article-children (&optional number)
2658   "Return a list of article numbers that are children of article NUMBER."
2659   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2660          (level (gnus-data-level (car data)))
2661          l children)
2662     (while (and (setq data (cdr data))
2663                 (> (setq l (gnus-data-level (car data))) level))
2664       (and (= (1+ level) l)
2665            (push (gnus-data-number (car data))
2666                  children)))
2667     (nreverse children)))
2668
2669 (defun gnus-summary-article-parent (&optional number)
2670   "Return the article number of the parent of article NUMBER."
2671   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2672                                     (gnus-data-list t)))
2673          (level (gnus-data-level (car data))))
2674     (if (zerop level)
2675         ()                              ; This is a root.
2676       ;; We search until we find an article with a level less than
2677       ;; this one.  That function has to be the parent.
2678       (while (and (setq data (cdr data))
2679                   (not (< (gnus-data-level (car data)) level))))
2680       (and data (gnus-data-number (car data))))))
2681
2682 (defun gnus-unread-mark-p (mark)
2683   "Say whether MARK is the unread mark."
2684   (= mark gnus-unread-mark))
2685
2686 (defun gnus-read-mark-p (mark)
2687   "Say whether MARK is one of the marks that mark as read.
2688 This is all marks except unread, ticked, dormant, and expirable."
2689   (not (or (= mark gnus-unread-mark)
2690            (= mark gnus-ticked-mark)
2691            (= mark gnus-dormant-mark)
2692            (= mark gnus-expirable-mark))))
2693
2694 (defmacro gnus-article-mark (number)
2695   "Return the MARK of article NUMBER.
2696 This macro should only be used when computing the mark the \"first\"
2697 time; i.e., when generating the summary lines.  After that,
2698 `gnus-summary-article-mark' should be used to examine the
2699 marks of articles."
2700   `(cond
2701     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2702     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2703     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2704     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2705     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2706     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2707     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2708     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2709            gnus-ancient-mark))))
2710
2711 ;; Saving hidden threads.
2712
2713 (defmacro gnus-save-hidden-threads (&rest forms)
2714   "Save hidden threads, eval FORMS, and restore the hidden threads."
2715   (let ((config (make-symbol "config")))
2716     `(let ((,config (gnus-hidden-threads-configuration)))
2717        (unwind-protect
2718            (save-excursion
2719              ,@forms)
2720          (gnus-restore-hidden-threads-configuration ,config)))))
2721 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2722 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2723
2724 (defun gnus-data-compute-positions ()
2725   "Compute the positions of all articles."
2726   (setq gnus-newsgroup-data-reverse nil)
2727   (let ((data gnus-newsgroup-data))
2728     (save-excursion
2729       (gnus-save-hidden-threads
2730         (gnus-summary-show-all-threads)
2731         (goto-char (point-min))
2732         (while data
2733           (while (get-text-property (point) 'gnus-intangible)
2734             (forward-line 1))
2735           (gnus-data-set-pos (car data) (+ (point) 3))
2736           (setq data (cdr data))
2737           (forward-line 1))))))
2738
2739 (defun gnus-hidden-threads-configuration ()
2740   "Return the current hidden threads configuration."
2741   (save-excursion
2742     (let (config)
2743       (goto-char (point-min))
2744       (while (search-forward "\r" nil t)
2745         (push (1- (point)) config))
2746       config)))
2747
2748 (defun gnus-restore-hidden-threads-configuration (config)
2749   "Restore hidden threads configuration from CONFIG."
2750   (save-excursion
2751     (let (point buffer-read-only)
2752       (while (setq point (pop config))
2753         (when (and (< point (point-max))
2754                    (goto-char point)
2755                    (eq (char-after) ?\n))
2756           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2757
2758 ;; Various summary mode internalish functions.
2759
2760 (defun gnus-mouse-pick-article (e)
2761   (interactive "e")
2762   (mouse-set-point e)
2763   (gnus-summary-next-page nil t))
2764
2765 (defun gnus-summary-set-display-table ()
2766   "Change the display table.
2767 Odd characters have a tendency to mess
2768 up nicely formatted displays - we make all possible glyphs
2769 display only a single character."
2770
2771   ;; We start from the standard display table, if any.
2772   (let ((table (or (copy-sequence standard-display-table)
2773                    (make-display-table)))
2774         (i 32))
2775     ;; Nix out all the control chars...
2776     (while (>= (setq i (1- i)) 0)
2777       (aset table i [??]))
2778     ;; ... but not newline and cr, of course.  (cr is necessary for the
2779     ;; selective display).
2780     (aset table ?\n nil)
2781     (aset table ?\r nil)
2782     ;; We keep TAB as well.
2783     (aset table ?\t nil)
2784     ;; We nix out any glyphs over 126 that are not set already.
2785     (let ((i 256))
2786       (while (>= (setq i (1- i)) 127)
2787         ;; Only modify if the entry is nil.
2788         (unless (aref table i)
2789           (aset table i [??]))))
2790     (setq buffer-display-table table)))
2791
2792 (defun gnus-summary-set-article-display-arrow (pos)
2793   "Update the overlay arrow to point to line at position POS."
2794   (when (and gnus-summary-display-arrow
2795              (boundp 'overlay-arrow-position)
2796              (boundp 'overlay-arrow-string))
2797     (save-excursion
2798       (goto-char pos)
2799       (beginning-of-line)
2800       (unless overlay-arrow-position
2801         (setq overlay-arrow-position (make-marker)))
2802       (setq overlay-arrow-string "=>"
2803             overlay-arrow-position (set-marker overlay-arrow-position
2804                                                (point)
2805                                                (current-buffer))))))
2806
2807 (defun gnus-summary-buffer-name (group)
2808   "Return the summary buffer name of GROUP."
2809   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2810
2811 (defun gnus-summary-setup-buffer (group)
2812   "Initialize summary buffer."
2813   (let ((buffer (gnus-summary-buffer-name group)))
2814     (if (get-buffer buffer)
2815         (progn
2816           (set-buffer buffer)
2817           (setq gnus-summary-buffer (current-buffer))
2818           (not gnus-newsgroup-prepared))
2819       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2820       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2821       (gnus-summary-mode group)
2822       (when gnus-carpal
2823         (gnus-carpal-setup-buffer 'summary))
2824       (unless gnus-single-article-buffer
2825         (make-local-variable 'gnus-article-buffer)
2826         (make-local-variable 'gnus-article-current)
2827         (make-local-variable 'gnus-original-article-buffer))
2828       (setq gnus-newsgroup-name group)
2829       ;; Set any local variables in the group parameters.
2830       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2831       t)))
2832
2833 (defun gnus-set-global-variables ()
2834   "Set the global equivalents of the buffer-local variables.
2835 They are set to the latest values they had.  These reflect the summary
2836 buffer that was in action when the last article was fetched."
2837   (when (eq major-mode 'gnus-summary-mode)
2838     (setq gnus-summary-buffer (current-buffer))
2839     (let ((name gnus-newsgroup-name)
2840           (marked gnus-newsgroup-marked)
2841           (unread gnus-newsgroup-unreads)
2842           (headers gnus-current-headers)
2843           (data gnus-newsgroup-data)
2844           (summary gnus-summary-buffer)
2845           (article-buffer gnus-article-buffer)
2846           (original gnus-original-article-buffer)
2847           (gac gnus-article-current)
2848           (reffed gnus-reffed-article-number)
2849           (score-file gnus-current-score-file)
2850           (default-charset gnus-newsgroup-charset)
2851           vlist)
2852       (let ((locals gnus-newsgroup-variables))
2853         (while locals
2854           (if (consp (car locals))
2855               (push (eval (caar locals)) vlist)
2856             (push (eval (car locals)) vlist))
2857           (setq locals (cdr locals)))
2858         (setq vlist (nreverse vlist)))
2859       (save-excursion
2860         (set-buffer gnus-group-buffer)
2861         (setq gnus-newsgroup-name name
2862               gnus-newsgroup-marked marked
2863               gnus-newsgroup-unreads unread
2864               gnus-current-headers headers
2865               gnus-newsgroup-data data
2866               gnus-article-current gac
2867               gnus-summary-buffer summary
2868               gnus-article-buffer article-buffer
2869               gnus-original-article-buffer original
2870               gnus-reffed-article-number reffed
2871               gnus-current-score-file score-file
2872               gnus-newsgroup-charset default-charset)
2873         (let ((locals gnus-newsgroup-variables))
2874           (while locals
2875             (if (consp (car locals))
2876                 (set (caar locals) (pop vlist))
2877               (set (car locals) (pop vlist)))
2878             (setq locals (cdr locals))))
2879         ;; The article buffer also has local variables.
2880         (when (gnus-buffer-live-p gnus-article-buffer)
2881           (set-buffer gnus-article-buffer)
2882           (setq gnus-summary-buffer summary))))))
2883
2884 (defun gnus-summary-article-unread-p (article)
2885   "Say whether ARTICLE is unread or not."
2886   (memq article gnus-newsgroup-unreads))
2887
2888 (defun gnus-summary-first-article-p (&optional article)
2889   "Return whether ARTICLE is the first article in the buffer."
2890   (if (not (setq article (or article (gnus-summary-article-number))))
2891       nil
2892     (eq article (caar gnus-newsgroup-data))))
2893
2894 (defun gnus-summary-last-article-p (&optional article)
2895   "Return whether ARTICLE is the last article in the buffer."
2896   (if (not (setq article (or article (gnus-summary-article-number))))
2897       ;; All non-existent numbers are the last article.  :-)
2898       t
2899     (not (cdr (gnus-data-find-list article)))))
2900
2901 (defun gnus-make-thread-indent-array ()
2902   (let ((n 200))
2903     (unless (and gnus-thread-indent-array
2904                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2905       (setq gnus-thread-indent-array (make-vector 201 "")
2906             gnus-thread-indent-array-level gnus-thread-indent-level)
2907       (while (>= n 0)
2908         (aset gnus-thread-indent-array n
2909               (make-string (* n gnus-thread-indent-level) ? ))
2910         (setq n (1- n))))))
2911
2912 (defun gnus-update-summary-mark-positions ()
2913   "Compute where the summary marks are to go."
2914   (save-excursion
2915     (when (gnus-buffer-exists-p gnus-summary-buffer)
2916       (set-buffer gnus-summary-buffer))
2917     (let ((gnus-replied-mark 129)
2918           (gnus-score-below-mark 130)
2919           (gnus-score-over-mark 130)
2920           (gnus-download-mark 131)
2921           (spec gnus-summary-line-format-spec)
2922           gnus-visual pos)
2923       (save-excursion
2924         (gnus-set-work-buffer)
2925         (let ((gnus-summary-line-format-spec spec)
2926               (gnus-newsgroup-downloadable '((0 . t))))
2927           (gnus-summary-insert-line
2928            (make-full-mail-header 0 "" "nobody"
2929                                   "05 Apr 2001 23:33:09 +0400"
2930                                   "" "" 0 0 "" nil)
2931            0 nil 128 t nil "" nil 1)
2932           (goto-char (point-min))
2933           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2934                                              (- (point) 2)))))
2935           (goto-char (point-min))
2936           (push (cons 'replied (and (search-forward "\201" nil t)
2937                                     (- (point) 2)))
2938                 pos)
2939           (goto-char (point-min))
2940           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2941                 pos)
2942           (goto-char (point-min))
2943           (push (cons 'download
2944                       (and (search-forward "\203" nil t) (- (point) 2)))
2945                 pos)))
2946       (setq gnus-summary-mark-positions pos))))
2947
2948 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2949   "Insert a dummy root in the summary buffer."
2950   (beginning-of-line)
2951   (gnus-add-text-properties
2952    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2953    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2954
2955 (defun gnus-summary-extract-address-component (from)
2956   (or (car (funcall gnus-extract-address-components from))
2957       from))
2958
2959 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2960   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
2961                                 default-mime-charset)))
2962     ;; Is it really necessary to do this next part for each summary line?
2963     ;; Luckily, doesn't seem to slow things down much.
2964     (or
2965      (and gnus-ignored-from-addresses
2966           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2967           (let ((extra-headers (mail-header-extra header))
2968                 to
2969                 newsgroups)
2970             (cond
2971              ((setq to (cdr (assq 'To extra-headers)))
2972               (concat "-> "
2973                       (gnus-summary-extract-address-component
2974                        (funcall gnus-decode-encoded-word-function to))))
2975              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2976               (concat "=> " newsgroups)))))
2977      (gnus-summary-extract-address-component gnus-tmp-from))))
2978
2979 (defun gnus-summary-insert-line (gnus-tmp-header
2980                                  gnus-tmp-level gnus-tmp-current
2981                                  gnus-tmp-unread gnus-tmp-replied
2982                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2983                                  &optional gnus-tmp-dummy gnus-tmp-score
2984                                  gnus-tmp-process)
2985   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2986          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2987          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2988          (gnus-tmp-score-char
2989           (if (or (null gnus-summary-default-score)
2990                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2991                       gnus-summary-zcore-fuzz))
2992               ?\ ;;;Whitespace
2993             (if (< gnus-tmp-score gnus-summary-default-score)
2994                 gnus-score-below-mark gnus-score-over-mark)))
2995          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2996          (gnus-tmp-replied
2997           (cond (gnus-tmp-process gnus-process-mark)
2998                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2999                  gnus-cached-mark)
3000                 (gnus-tmp-replied gnus-replied-mark)
3001                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3002                  gnus-forwarded-mark)
3003                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3004                  gnus-saved-mark)
3005                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3006                  gnus-recent-mark)
3007                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3008                  gnus-unseen-mark)
3009                 (t gnus-no-mark)))
3010          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3011          (gnus-tmp-name
3012           (cond
3013            ((string-match "<[^>]+> *$" gnus-tmp-from)
3014             (let ((beg (match-beginning 0)))
3015               (or (and (string-match "^\".+\"" gnus-tmp-from)
3016                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3017                   (substring gnus-tmp-from 0 beg))))
3018            ((string-match "(.+)" gnus-tmp-from)
3019             (substring gnus-tmp-from
3020                        (1+ (match-beginning 0)) (1- (match-end 0))))
3021            (t gnus-tmp-from)))
3022          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3023          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3024          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3025          (buffer-read-only nil))
3026     (when (string= gnus-tmp-name "")
3027       (setq gnus-tmp-name gnus-tmp-from))
3028     (unless (numberp gnus-tmp-lines)
3029       (setq gnus-tmp-lines -1))
3030     (if (= gnus-tmp-lines -1)
3031         (setq gnus-tmp-lines "?")
3032       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3033     (gnus-put-text-property-excluding-characters-with-faces
3034      (point)
3035      (progn (eval gnus-summary-line-format-spec) (point))
3036      'gnus-number gnus-tmp-number)
3037     (when (gnus-visual-p 'summary-highlight 'highlight)
3038       (forward-line -1)
3039       (gnus-run-hooks 'gnus-summary-update-hook)
3040       (forward-line 1))))
3041
3042 (defun gnus-summary-update-line (&optional dont-update)
3043   "Update summary line after change."
3044   (when (and gnus-summary-default-score
3045              (not gnus-summary-inhibit-highlight))
3046     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3047            (article (gnus-summary-article-number))
3048            (score (gnus-summary-article-score article)))
3049       (unless dont-update
3050         (if (and gnus-summary-mark-below
3051                  (< (gnus-summary-article-score)
3052                     gnus-summary-mark-below))
3053             ;; This article has a low score, so we mark it as read.
3054             (when (memq article gnus-newsgroup-unreads)
3055               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3056           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3057             ;; This article was previously marked as read on account
3058             ;; of a low score, but now it has risen, so we mark it as
3059             ;; unread.
3060             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3061         (gnus-summary-update-mark
3062          (if (or (null gnus-summary-default-score)
3063                  (<= (abs (- score gnus-summary-default-score))
3064                      gnus-summary-zcore-fuzz))
3065              ?\ ;;;Whitespace
3066            (if (< score gnus-summary-default-score)
3067                gnus-score-below-mark gnus-score-over-mark))
3068          'score))
3069       ;; Do visual highlighting.
3070       (when (gnus-visual-p 'summary-highlight 'highlight)
3071         (gnus-run-hooks 'gnus-summary-update-hook)))))
3072
3073 (defvar gnus-tmp-new-adopts nil)
3074
3075 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3076   "Return the number of articles in THREAD.
3077 This may be 0 in some cases -- if none of the articles in
3078 the thread are to be displayed."
3079   (let* ((number
3080           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3081           (cond
3082            ((not (listp thread))
3083             1)
3084            ((and (consp thread) (cdr thread))
3085             (apply
3086              '+ 1 (mapcar
3087                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3088            ((null thread)
3089             1)
3090            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3091             1)
3092            (t 0))))
3093     (when (and level (zerop level) gnus-tmp-new-adopts)
3094       (incf number
3095             (apply '+ (mapcar
3096                        'gnus-summary-number-of-articles-in-thread
3097                        gnus-tmp-new-adopts))))
3098     (if char
3099         (if (> number 1) gnus-not-empty-thread-mark
3100           gnus-empty-thread-mark)
3101       number)))
3102
3103 (defun gnus-summary-set-local-parameters (group)
3104   "Go through the local params of GROUP and set all variable specs in that list."
3105   (let ((params (gnus-group-find-parameter group))
3106         (vars '(quit-config))           ; Ignore quit-config.
3107         elem)
3108     (while params
3109       (setq elem (car params)
3110             params (cdr params))
3111       (and (consp elem)                 ; Has to be a cons.
3112            (consp (cdr elem))           ; The cdr has to be a list.
3113            (symbolp (car elem))         ; Has to be a symbol in there.
3114            (not (memq (car elem) vars))
3115            (ignore-errors               ; So we set it.
3116              (push (car elem) vars)
3117              (make-local-variable (car elem))
3118              (set (car elem) (eval (nth 1 elem))))))))
3119
3120 (defun gnus-summary-read-group (group &optional show-all no-article
3121                                       kill-buffer no-display backward
3122                                       select-articles)
3123   "Start reading news in newsgroup GROUP.
3124 If SHOW-ALL is non-nil, already read articles are also listed.
3125 If NO-ARTICLE is non-nil, no article is selected initially.
3126 If NO-DISPLAY, don't generate a summary buffer."
3127   (let (result)
3128     (while (and group
3129                 (null (setq result
3130                             (let ((gnus-auto-select-next nil))
3131                               (or (gnus-summary-read-group-1
3132                                    group show-all no-article
3133                                    kill-buffer no-display
3134                                    select-articles)
3135                                   (setq show-all nil
3136                                         select-articles nil)))))
3137                 (eq gnus-auto-select-next 'quietly))
3138       (set-buffer gnus-group-buffer)
3139       ;; The entry function called above goes to the next
3140       ;; group automatically, so we go two groups back
3141       ;; if we are searching for the previous group.
3142       (when backward
3143         (gnus-group-prev-unread-group 2))
3144       (if (not (equal group (gnus-group-group-name)))
3145           (setq group (gnus-group-group-name))
3146         (setq group nil)))
3147     result))
3148
3149 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3150   "Directly jump to the other GROUP from summary buffer.
3151 If SHOW-ALL is non-nil, already read articles are also listed."
3152   (interactive
3153    (if (eq gnus-summary-buffer (current-buffer))
3154        (list (completing-read
3155               "Group: " gnus-active-hashtb nil t
3156               (when (and gnus-newsgroup-name
3157                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3158                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3159               'gnus-group-history)
3160              current-prefix-arg)
3161      (error "%s must be invoked from a gnus summary buffer." this-command)))
3162   (unless (or (zerop (length group))
3163               (and gnus-newsgroup-name
3164                    (string-equal gnus-newsgroup-name group)))
3165     (gnus-summary-exit)
3166     (gnus-summary-read-group group show-all
3167                              gnus-dont-select-after-jump-to-other-group)))
3168
3169 (defun gnus-summary-read-group-1 (group show-all no-article
3170                                         kill-buffer no-display
3171                                         &optional select-articles)
3172   ;; Killed foreign groups can't be entered.
3173   ;;  (when (and (not (gnus-group-native-p group))
3174   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3175   ;;    (error "Dead non-native groups can't be entered"))
3176   (gnus-message 5 "Retrieving newsgroup: %s..."
3177                 (gnus-group-decoded-name group))
3178   (let* ((new-group (gnus-summary-setup-buffer group))
3179          (quit-config (gnus-group-quit-config group))
3180          (did-select (and new-group (gnus-select-newsgroup
3181                                      group show-all select-articles))))
3182     (cond
3183      ;; This summary buffer exists already, so we just select it.
3184      ((not new-group)
3185       (gnus-set-global-variables)
3186       (when kill-buffer
3187         (gnus-kill-or-deaden-summary kill-buffer))
3188       (gnus-configure-windows 'summary 'force)
3189       (gnus-set-mode-line 'summary)
3190       (gnus-summary-position-point)
3191       (message "")
3192       t)
3193      ;; We couldn't select this group.
3194      ((null did-select)
3195       (when (and (eq major-mode 'gnus-summary-mode)
3196                  (not (equal (current-buffer) kill-buffer)))
3197         (kill-buffer (current-buffer))
3198         (if (not quit-config)
3199             (progn
3200               ;; Update the info -- marks might need to be removed,
3201               ;; for instance.
3202               (gnus-summary-update-info)
3203               (set-buffer gnus-group-buffer)
3204               (gnus-group-jump-to-group group)
3205               (gnus-group-next-unread-group 1))
3206           (gnus-handle-ephemeral-exit quit-config)))
3207       (let ((grpinfo (gnus-get-info group)))
3208         (if (null (gnus-info-read grpinfo))
3209             (gnus-message 3 "Group %s contains no messages"
3210                           (gnus-group-decoded-name group))
3211           (gnus-message 3 "Can't select group")))
3212       nil)
3213      ;; The user did a `C-g' while prompting for number of articles,
3214      ;; so we exit this group.
3215      ((eq did-select 'quit)
3216       (and (eq major-mode 'gnus-summary-mode)
3217            (not (equal (current-buffer) kill-buffer))
3218            (kill-buffer (current-buffer)))
3219       (when kill-buffer
3220         (gnus-kill-or-deaden-summary kill-buffer))
3221       (if (not quit-config)
3222           (progn
3223             (set-buffer gnus-group-buffer)
3224             (gnus-group-jump-to-group group)
3225             (gnus-group-next-unread-group 1)
3226             (gnus-configure-windows 'group 'force))
3227         (gnus-handle-ephemeral-exit quit-config))
3228       ;; Finally signal the quit.
3229       (signal 'quit nil))
3230      ;; The group was successfully selected.
3231      (t
3232       (gnus-set-global-variables)
3233       ;; Save the active value in effect when the group was entered.
3234       (setq gnus-newsgroup-active
3235             (gnus-copy-sequence
3236              (gnus-active gnus-newsgroup-name)))
3237       ;; You can change the summary buffer in some way with this hook.
3238       (gnus-run-hooks 'gnus-select-group-hook)
3239       (gnus-update-format-specifications
3240        nil 'summary 'summary-mode 'summary-dummy)
3241       (gnus-update-summary-mark-positions)
3242       ;; Do score processing.
3243       (when gnus-use-scoring
3244         (gnus-possibly-score-headers))
3245       ;; Check whether to fill in the gaps in the threads.
3246       (when gnus-build-sparse-threads
3247         (gnus-build-sparse-threads))
3248       ;; Find the initial limit.
3249       (if gnus-show-threads
3250           (if show-all
3251               (let ((gnus-newsgroup-dormant nil))
3252                 (gnus-summary-initial-limit show-all))
3253             (gnus-summary-initial-limit show-all))
3254         ;; When untreaded, all articles are always shown.
3255         (setq gnus-newsgroup-limit
3256               (mapcar
3257                (lambda (header) (mail-header-number header))
3258                gnus-newsgroup-headers)))
3259       ;; Generate the summary buffer.
3260       (unless no-display
3261         (gnus-summary-prepare))
3262       (when gnus-use-trees
3263         (gnus-tree-open group)
3264         (setq gnus-summary-highlight-line-function
3265               'gnus-tree-highlight-article))
3266       ;; If the summary buffer is empty, but there are some low-scored
3267       ;; articles or some excluded dormants, we include these in the
3268       ;; buffer.
3269       (when (and (zerop (buffer-size))
3270                  (not no-display))
3271         (cond (gnus-newsgroup-dormant
3272                (gnus-summary-limit-include-dormant))
3273               ((and gnus-newsgroup-scored show-all)
3274                (gnus-summary-limit-include-expunged t))))
3275       ;; Function `gnus-apply-kill-file' must be called in this hook.
3276       (gnus-run-hooks 'gnus-apply-kill-hook)
3277       (if (and (zerop (buffer-size))
3278                (not no-display))
3279           (progn
3280             ;; This newsgroup is empty.
3281             (gnus-summary-catchup-and-exit nil t)
3282             (gnus-message 6 "No unread news")
3283             (when kill-buffer
3284               (gnus-kill-or-deaden-summary kill-buffer))
3285             ;; Return nil from this function.
3286             nil)
3287         ;; Hide conversation thread subtrees.  We cannot do this in
3288         ;; gnus-summary-prepare-hook since kill processing may not
3289         ;; work with hidden articles.
3290         (and gnus-show-threads
3291              gnus-thread-hide-subtree
3292              (gnus-summary-hide-all-threads))
3293         (when kill-buffer
3294           (gnus-kill-or-deaden-summary kill-buffer))
3295         (gnus-summary-auto-select-subject)
3296         ;; Show first unread article if requested.
3297         (if (and (not no-article)
3298                  (not no-display)
3299                  gnus-newsgroup-unreads
3300                  gnus-auto-select-first)
3301             (progn
3302               (gnus-configure-windows 'summary)
3303               (gnus-summary-goto-article (gnus-summary-article-number)))
3304           ;; Don't select any articles.
3305           (gnus-summary-position-point)
3306           (gnus-configure-windows 'summary 'force)
3307           (gnus-set-mode-line 'summary))
3308         (when (get-buffer-window gnus-group-buffer t)
3309           ;; Gotta use windows, because recenter does weird stuff if
3310           ;; the current buffer ain't the displayed window.
3311           (let ((owin (selected-window)))
3312             (select-window (get-buffer-window gnus-group-buffer t))
3313             (when (gnus-group-goto-group group)
3314               (recenter))
3315             (select-window owin)))
3316         ;; Mark this buffer as "prepared".
3317         (setq gnus-newsgroup-prepared t)
3318         (gnus-run-hooks 'gnus-summary-prepared-hook)
3319         t)))))
3320
3321 (defun gnus-summary-auto-select-subject ()
3322   "Select the subject line on initial group entry."
3323   (goto-char (point-min))
3324   (cond
3325    ((eq gnus-auto-select-subject 'best)
3326     (gnus-summary-best-unread-subject))
3327    ((eq gnus-auto-select-subject 'unread)
3328     (gnus-summary-first-unread-subject))
3329    ((eq gnus-auto-select-subject 'unseen)
3330     (gnus-summary-first-unseen-subject))
3331    ((eq gnus-auto-select-subject 'first)
3332     ;; Do nothing.
3333     )
3334    ((gnus-functionp gnus-auto-select-subject)
3335     (funcall gnus-auto-select-subject))))
3336
3337 (defun gnus-summary-prepare ()
3338   "Generate the summary buffer."
3339   (interactive)
3340   (let ((buffer-read-only nil))
3341     (erase-buffer)
3342     (setq gnus-newsgroup-data nil
3343           gnus-newsgroup-data-reverse nil)
3344     (gnus-run-hooks 'gnus-summary-generate-hook)
3345     ;; Generate the buffer, either with threads or without.
3346     (when gnus-newsgroup-headers
3347       (gnus-summary-prepare-threads
3348        (if gnus-show-threads
3349            (gnus-sort-gathered-threads
3350             (funcall gnus-summary-thread-gathering-function
3351                      (gnus-sort-threads
3352                       (gnus-cut-threads (gnus-make-threads)))))
3353          ;; Unthreaded display.
3354          (gnus-sort-articles gnus-newsgroup-headers))))
3355     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3356     ;; Call hooks for modifying summary buffer.
3357     (goto-char (point-min))
3358     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3359
3360 (defsubst gnus-general-simplify-subject (subject)
3361   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3362   (setq subject
3363         (cond
3364          ;; Truncate the subject.
3365          (gnus-simplify-subject-functions
3366           (gnus-map-function gnus-simplify-subject-functions subject))
3367          ((numberp gnus-summary-gather-subject-limit)
3368           (setq subject (gnus-simplify-subject-re subject))
3369           (if (> (length subject) gnus-summary-gather-subject-limit)
3370               (substring subject 0 gnus-summary-gather-subject-limit)
3371             subject))
3372          ;; Fuzzily simplify it.
3373          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3374           (gnus-simplify-subject-fuzzy subject))
3375          ;; Just remove the leading "Re:".
3376          (t
3377           (gnus-simplify-subject-re subject))))
3378
3379   (if (and gnus-summary-gather-exclude-subject
3380            (string-match gnus-summary-gather-exclude-subject subject))
3381       nil                               ; This article shouldn't be gathered
3382     subject))
3383
3384 (defun gnus-summary-simplify-subject-query ()
3385   "Query where the respool algorithm would put this article."
3386   (interactive)
3387   (gnus-summary-select-article)
3388   (message "%s"
3389            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3390
3391 (defun gnus-gather-threads-by-subject (threads)
3392   "Gather threads by looking at Subject headers."
3393   (if (not gnus-summary-make-false-root)
3394       threads
3395     (let ((hashtb (gnus-make-hashtable 1024))
3396           (prev threads)
3397           (result threads)
3398           subject hthread whole-subject)
3399       (while threads
3400         (setq subject (gnus-general-simplify-subject
3401                        (setq whole-subject (mail-header-subject
3402                                             (caar threads)))))
3403         (when subject
3404           (if (setq hthread (gnus-gethash subject hashtb))
3405               (progn
3406                 ;; We enter a dummy root into the thread, if we
3407                 ;; haven't done that already.
3408                 (unless (stringp (caar hthread))
3409                   (setcar hthread (list whole-subject (car hthread))))
3410                 ;; We add this new gathered thread to this gathered
3411                 ;; thread.
3412                 (setcdr (car hthread)
3413                         (nconc (cdar hthread) (list (car threads))))
3414                 ;; Remove it from the list of threads.
3415                 (setcdr prev (cdr threads))
3416                 (setq threads prev))
3417             ;; Enter this thread into the hash table.
3418             (gnus-sethash subject threads hashtb)))
3419         (setq prev threads)
3420         (setq threads (cdr threads)))
3421       result)))
3422
3423 (defun gnus-gather-threads-by-references (threads)
3424   "Gather threads by looking at References headers."
3425   (let ((idhashtb (gnus-make-hashtable 1024))
3426         (thhashtb (gnus-make-hashtable 1024))
3427         (prev threads)
3428         (result threads)
3429         ids references id gthread gid entered ref)
3430     (while threads
3431       (when (setq references (mail-header-references (caar threads)))
3432         (setq id (mail-header-id (caar threads))
3433               ids (gnus-split-references references)
3434               entered nil)
3435         (while (setq ref (pop ids))
3436           (setq ids (delete ref ids))
3437           (if (not (setq gid (gnus-gethash ref idhashtb)))
3438               (progn
3439                 (gnus-sethash ref id idhashtb)
3440                 (gnus-sethash id threads thhashtb))
3441             (setq gthread (gnus-gethash gid thhashtb))
3442             (unless entered
3443               ;; We enter a dummy root into the thread, if we
3444               ;; haven't done that already.
3445               (unless (stringp (caar gthread))
3446                 (setcar gthread (list (mail-header-subject (caar gthread))
3447                                       (car gthread))))
3448               ;; We add this new gathered thread to this gathered
3449               ;; thread.
3450               (setcdr (car gthread)
3451                       (nconc (cdar gthread) (list (car threads)))))
3452             ;; Add it into the thread hash table.
3453             (gnus-sethash id gthread thhashtb)
3454             (setq entered t)
3455             ;; Remove it from the list of threads.
3456             (setcdr prev (cdr threads))
3457             (setq threads prev))))
3458       (setq prev threads)
3459       (setq threads (cdr threads)))
3460     result))
3461
3462 (defun gnus-sort-gathered-threads (threads)
3463   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3464   (let ((result threads))
3465     (while threads
3466       (when (stringp (caar threads))
3467         (setcdr (car threads)
3468                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3469       (setq threads (cdr threads)))
3470     result))
3471
3472 (defun gnus-thread-loop-p (root thread)
3473   "Say whether ROOT is in THREAD."
3474   (let ((stack (list thread))
3475         (infloop 0)
3476         th)
3477     (while (setq thread (pop stack))
3478       (setq th (cdr thread))
3479       (while (and th
3480                   (not (eq (caar th) root)))
3481         (pop th))
3482       (if th
3483           ;; We have found a loop.
3484           (let (ref-dep)
3485             (setcdr thread (delq (car th) (cdr thread)))
3486             (if (boundp (setq ref-dep (intern "none"
3487                                               gnus-newsgroup-dependencies)))
3488                 (setcdr (symbol-value ref-dep)
3489                         (nconc (cdr (symbol-value ref-dep))
3490                                (list (car th))))
3491               (set ref-dep (list nil (car th))))
3492             (setq infloop 1
3493                   stack nil))
3494         ;; Push all the subthreads onto the stack.
3495         (push (cdr thread) stack)))
3496     infloop))
3497
3498 (defun gnus-make-threads ()
3499   "Go through the dependency hashtb and find the roots.  Return all threads."
3500   (let (threads)
3501     (while (catch 'infloop
3502              (mapatoms
3503               (lambda (refs)
3504                 ;; Deal with self-referencing References loops.
3505                 (when (and (car (symbol-value refs))
3506                            (not (zerop
3507                                  (apply
3508                                   '+
3509                                   (mapcar
3510                                    (lambda (thread)
3511                                      (gnus-thread-loop-p
3512                                       (car (symbol-value refs)) thread))
3513                                    (cdr (symbol-value refs)))))))
3514                   (setq threads nil)
3515                   (throw 'infloop t))
3516                 (unless (car (symbol-value refs))
3517                   ;; These threads do not refer back to any other articles,
3518                   ;; so they're roots.
3519                   (setq threads (append (cdr (symbol-value refs)) threads))))
3520               gnus-newsgroup-dependencies)))
3521     threads))
3522
3523 ;; Build the thread tree.
3524 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3525   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3526
3527 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3528 if it was already present.
3529
3530 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3531 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3532 Message-IDs will be renamed be renamed to a unique Message-ID before
3533 being entered.
3534
3535 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3536   (let* ((id (mail-header-id header))
3537          (id-dep (and id (intern id dependencies)))
3538          ref ref-dep ref-header)
3539     ;; Enter this `header' in the `dependencies' table.
3540     (cond
3541      ((not id-dep)
3542       (setq header nil))
3543      ;; The first two cases do the normal part: enter a new `header'
3544      ;; in the `dependencies' table.
3545      ((not (boundp id-dep))
3546       (set id-dep (list header)))
3547      ((null (car (symbol-value id-dep)))
3548       (setcar (symbol-value id-dep) header))
3549
3550      ;; From here the `header' was already present in the
3551      ;; `dependencies' table.
3552      (force-new
3553       ;; Overrides an existing entry;
3554       ;; just set the header part of the entry.
3555       (setcar (symbol-value id-dep) header))
3556
3557      ;; Renames the existing `header' to a unique Message-ID.
3558      ((not gnus-summary-ignore-duplicates)
3559       ;; An article with this Message-ID has already been seen.
3560       ;; We rename the Message-ID.
3561       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3562            (list header))
3563       (mail-header-set-id header id))
3564
3565      ;; The last case ignores an existing entry, except it adds any
3566      ;; additional Xrefs (in case the two articles came from different
3567      ;; servers.
3568      ;; Also sets `header' to `nil' meaning that the `dependencies'
3569      ;; table was *not* modified.
3570      (t
3571       (mail-header-set-xref
3572        (car (symbol-value id-dep))
3573        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3574                    "")
3575                (or (mail-header-xref header) "")))
3576       (setq header nil)))
3577
3578     (when header
3579       ;; First check if that we are not creating a References loop.
3580       (setq ref (gnus-parent-id (mail-header-references header)))
3581       (while (and ref
3582                   (setq ref-dep (intern-soft ref dependencies))
3583                   (boundp ref-dep)
3584                   (setq ref-header (car (symbol-value ref-dep))))
3585         (if (string= id ref)
3586             ;; Yuk!  This is a reference loop.  Make the article be a
3587             ;; root article.
3588             (progn
3589               (mail-header-set-references (car (symbol-value id-dep)) "none")
3590               (setq ref nil))
3591           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3592       (setq ref (gnus-parent-id (mail-header-references header)))
3593       (setq ref-dep (intern (or ref "none") dependencies))
3594       (if (boundp ref-dep)
3595           (setcdr (symbol-value ref-dep)
3596                   (nconc (cdr (symbol-value ref-dep))
3597                          (list (symbol-value id-dep))))
3598         (set ref-dep (list nil (symbol-value id-dep)))))
3599     header))
3600
3601 (defun gnus-build-sparse-threads ()
3602   (let ((headers gnus-newsgroup-headers)
3603         (mail-parse-charset gnus-newsgroup-charset)
3604         (gnus-summary-ignore-duplicates t)
3605         header references generation relations
3606         subject child end new-child date)
3607     ;; First we create an alist of generations/relations, where
3608     ;; generations is how much we trust the relation, and the relation
3609     ;; is parent/child.
3610     (gnus-message 7 "Making sparse threads...")
3611     (save-excursion
3612       (nnheader-set-temp-buffer " *gnus sparse threads*")
3613       (while (setq header (pop headers))
3614         (when (and (setq references (mail-header-references header))
3615                    (not (string= references "")))
3616           (insert references)
3617           (setq child (mail-header-id header)
3618                 subject (mail-header-subject header)
3619                 date (mail-header-date header)
3620                 generation 0)
3621           (while (search-backward ">" nil t)
3622             (setq end (1+ (point)))
3623             (when (search-backward "<" nil t)
3624               (setq new-child (buffer-substring (point) end))
3625               (push (list (incf generation)
3626                           child (setq child new-child)
3627                           subject date)
3628                     relations)))
3629           (when child
3630             (push (list (1+ generation) child nil subject) relations))
3631           (erase-buffer)))
3632       (kill-buffer (current-buffer)))
3633     ;; Sort over trustworthiness.
3634     (mapcar
3635      (lambda (relation)
3636        (when (gnus-dependencies-add-header
3637               (make-full-mail-header-from-decoded-header
3638                gnus-reffed-article-number
3639                (nth 3 relation) "" (or (nth 4 relation) "")
3640                (nth 1 relation)
3641                (or (nth 2 relation) "") 0 0 "")
3642               gnus-newsgroup-dependencies nil)
3643          (push gnus-reffed-article-number gnus-newsgroup-limit)
3644          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3645          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3646                gnus-newsgroup-reads)
3647          (decf gnus-reffed-article-number)))
3648      (sort relations 'car-less-than-car))
3649     (gnus-message 7 "Making sparse threads...done")))
3650
3651 (defun gnus-build-old-threads ()
3652   ;; Look at all the articles that refer back to old articles, and
3653   ;; fetch the headers for the articles that aren't there.  This will
3654   ;; build complete threads - if the roots haven't been expired by the
3655   ;; server, that is.
3656   (let ((mail-parse-charset gnus-newsgroup-charset)
3657         id heads)
3658     (mapatoms
3659      (lambda (refs)
3660        (when (not (car (symbol-value refs)))
3661          (setq heads (cdr (symbol-value refs)))
3662          (while heads
3663            (if (memq (mail-header-number (caar heads))
3664                      gnus-newsgroup-dormant)
3665                (setq heads (cdr heads))
3666              (setq id (symbol-name refs))
3667              (while (and (setq id (gnus-build-get-header id))
3668                          (not (car (gnus-id-to-thread id)))))
3669              (setq heads nil)))))
3670      gnus-newsgroup-dependencies)))
3671
3672 ;; This function has to be called with point after the article number
3673 ;; on the beginning of the line.
3674 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3675   (let ((eol (gnus-point-at-eol))
3676         (buffer (current-buffer))
3677         header)
3678
3679     ;; overview: [num subject from date id refs chars lines misc]
3680     (unwind-protect
3681         (progn
3682           (narrow-to-region (point) eol)
3683           (unless (eobp)
3684             (forward-char))
3685
3686           (setq header
3687                 (make-full-mail-header
3688                  number                         ; number
3689                  (nnheader-nov-field)           ; subject
3690                  (nnheader-nov-field)           ; from
3691                  (nnheader-nov-field)           ; date
3692                  (nnheader-nov-read-message-id) ; id
3693                  (nnheader-nov-field)           ; refs
3694                  (nnheader-nov-read-integer)    ; chars
3695                  (nnheader-nov-read-integer)    ; lines
3696                  (unless (eobp)
3697                    (if (looking-at "Xref: ")
3698                        (goto-char (match-end 0)))
3699                    (nnheader-nov-field))        ; Xref
3700                  (nnheader-nov-parse-extra))))  ; extra
3701
3702       (widen))
3703
3704     (when gnus-alter-header-function
3705       (funcall gnus-alter-header-function header))
3706     (gnus-dependencies-add-header header dependencies force-new)))
3707
3708 (defun gnus-build-get-header (id)
3709   "Look through the buffer of NOV lines and find the header to ID.
3710 Enter this line into the dependencies hash table, and return
3711 the id of the parent article (if any)."
3712   (let ((deps gnus-newsgroup-dependencies)
3713         found header)
3714     (prog1
3715         (save-excursion
3716           (set-buffer nntp-server-buffer)
3717           (let ((case-fold-search nil))
3718             (goto-char (point-min))
3719             (while (and (not found)
3720                         (search-forward id nil t))
3721               (beginning-of-line)
3722               (setq found (looking-at
3723                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3724                                    (regexp-quote id))))
3725               (or found (beginning-of-line 2)))
3726             (when found
3727               (beginning-of-line)
3728               (and
3729                (setq header (gnus-nov-parse-line
3730                              (read (current-buffer)) deps))
3731                (gnus-parent-id (mail-header-references header))))))
3732       (when header
3733         (let ((number (mail-header-number header)))
3734           (push number gnus-newsgroup-limit)
3735           (push header gnus-newsgroup-headers)
3736           (if (memq number gnus-newsgroup-unselected)
3737               (progn
3738                 (push number gnus-newsgroup-unreads)
3739                 (setq gnus-newsgroup-unselected
3740                       (delq number gnus-newsgroup-unselected)))
3741             (push number gnus-newsgroup-ancient)))))))
3742
3743 (defun gnus-build-all-threads ()
3744   "Read all the headers."
3745   (let ((gnus-summary-ignore-duplicates t)
3746         (mail-parse-charset gnus-newsgroup-charset)
3747         (dependencies gnus-newsgroup-dependencies)
3748         header article)
3749     (save-excursion
3750       (set-buffer nntp-server-buffer)
3751       (let ((case-fold-search nil))
3752         (goto-char (point-min))
3753         (while (not (eobp))
3754           (ignore-errors
3755             (setq article (read (current-buffer))
3756                   header (gnus-nov-parse-line article dependencies)))
3757           (when header
3758             (save-excursion
3759               (set-buffer gnus-summary-buffer)
3760               (push header gnus-newsgroup-headers)
3761               (if (memq (setq article (mail-header-number header))
3762                         gnus-newsgroup-unselected)
3763                   (progn
3764                     (push article gnus-newsgroup-unreads)
3765                     (setq gnus-newsgroup-unselected
3766                           (delq article gnus-newsgroup-unselected)))
3767                 (push article gnus-newsgroup-ancient)))
3768             (forward-line 1)))))))
3769
3770 (defun gnus-summary-update-article-line (article header)
3771   "Update the line for ARTICLE using HEADERS."
3772   (let* ((id (mail-header-id header))
3773          (thread (gnus-id-to-thread id)))
3774     (unless thread
3775       (error "Article in no thread"))
3776     ;; Update the thread.
3777     (setcar thread header)
3778     (gnus-summary-goto-subject article)
3779     (let* ((datal (gnus-data-find-list article))
3780            (data (car datal))
3781            (length (when (cdr datal)
3782                      (- (gnus-data-pos data)
3783                         (gnus-data-pos (cadr datal)))))
3784            (buffer-read-only nil)
3785            (level (gnus-summary-thread-level)))
3786       (gnus-delete-line)
3787       (gnus-summary-insert-line
3788        header level nil (gnus-article-mark article)
3789        (memq article gnus-newsgroup-replied)
3790        (memq article gnus-newsgroup-expirable)
3791        ;; Only insert the Subject string when it's different
3792        ;; from the previous Subject string.
3793        (if (and
3794             gnus-show-threads
3795             (gnus-subject-equal
3796              (condition-case ()
3797                  (mail-header-subject
3798                   (gnus-data-header
3799                    (cadr
3800                     (gnus-data-find-list
3801                      article
3802                      (gnus-data-list t)))))
3803                ;; Error on the side of excessive subjects.
3804                (error ""))
3805              (mail-header-subject header)))
3806            ""
3807          (mail-header-subject header))
3808        nil (cdr (assq article gnus-newsgroup-scored))
3809        (memq article gnus-newsgroup-processable))
3810       (when length
3811         (gnus-data-update-list
3812          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3813
3814 (defun gnus-summary-update-article (article &optional iheader)
3815   "Update ARTICLE in the summary buffer."
3816   (set-buffer gnus-summary-buffer)
3817   (let* ((header (gnus-summary-article-header article))
3818          (id (mail-header-id header))
3819          (data (gnus-data-find article))
3820          (thread (gnus-id-to-thread id))
3821          (references (mail-header-references header))
3822          (parent
3823           (gnus-id-to-thread
3824            (or (gnus-parent-id
3825                 (when (and references
3826                            (not (equal "" references)))
3827                   references))
3828                "none")))
3829          (buffer-read-only nil)
3830          (old (car thread)))
3831     (when thread
3832       (unless iheader
3833         (setcar thread nil)
3834         (when parent
3835           (delq thread parent)))
3836       (if (gnus-summary-insert-subject id header)
3837           ;; Set the (possibly) new article number in the data structure.
3838           (gnus-data-set-number data (gnus-id-to-article id))
3839         (setcar thread old)
3840         nil))))
3841
3842 (defun gnus-rebuild-thread (id &optional line)
3843   "Rebuild the thread containing ID.
3844 If LINE, insert the rebuilt thread starting on line LINE."
3845   (let ((buffer-read-only nil)
3846         old-pos current thread data)
3847     (if (not gnus-show-threads)
3848         (setq thread (list (car (gnus-id-to-thread id))))
3849       ;; Get the thread this article is part of.
3850       (setq thread (gnus-remove-thread id)))
3851     (setq old-pos (gnus-point-at-bol))
3852     (setq current (save-excursion
3853                     (and (re-search-backward "[\r\n]" nil t)
3854                          (gnus-summary-article-number))))
3855     ;; If this is a gathered thread, we have to go some re-gathering.
3856     (when (stringp (car thread))
3857       (let ((subject (car thread))
3858             roots thr)
3859         (setq thread (cdr thread))
3860         (while thread
3861           (unless (memq (setq thr (gnus-id-to-thread
3862                                    (gnus-root-id
3863                                     (mail-header-id (caar thread)))))
3864                         roots)
3865             (push thr roots))
3866           (setq thread (cdr thread)))
3867         ;; We now have all (unique) roots.
3868         (if (= (length roots) 1)
3869             ;; All the loose roots are now one solid root.
3870             (setq thread (car roots))
3871           (setq thread (cons subject (gnus-sort-threads roots))))))
3872     (let (threads)
3873       ;; We then insert this thread into the summary buffer.
3874       (when line
3875         (goto-char (point-min))
3876         (forward-line (1- line)))
3877       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3878         (if gnus-show-threads
3879             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3880           (gnus-summary-prepare-unthreaded thread))
3881         (setq data (nreverse gnus-newsgroup-data))
3882         (setq threads gnus-newsgroup-threads))
3883       ;; We splice the new data into the data structure.
3884       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3885       ;;!!! then we want to insert at the beginning of the buffer.
3886       ;;!!! That happens to be true with Gnus now, but that may
3887       ;;!!! change in the future.  Perhaps.
3888       (gnus-data-enter-list
3889        (if line nil current) data (- (point) old-pos))
3890       (setq gnus-newsgroup-threads
3891             (nconc threads gnus-newsgroup-threads))
3892       (gnus-data-compute-positions))))
3893
3894 (defun gnus-number-to-header (number)
3895   "Return the header for article NUMBER."
3896   (let ((headers gnus-newsgroup-headers))
3897     (while (and headers
3898                 (not (= number (mail-header-number (car headers)))))
3899       (pop headers))
3900     (when headers
3901       (car headers))))
3902
3903 (defun gnus-parent-headers (in-headers &optional generation)
3904   "Return the headers of the GENERATIONeth parent of HEADERS."
3905   (unless generation
3906     (setq generation 1))
3907   (let ((parent t)
3908         (headers in-headers)
3909         references)
3910     (while (and parent
3911                 (not (zerop generation))
3912                 (setq references (mail-header-references headers)))
3913       (setq headers (if (and references
3914                              (setq parent (gnus-parent-id references)))
3915                         (car (gnus-id-to-thread parent))
3916                       nil))
3917       (decf generation))
3918     (and (not (eq headers in-headers))
3919          headers)))
3920
3921 (defun gnus-id-to-thread (id)
3922   "Return the (sub-)thread where ID appears."
3923   (gnus-gethash id gnus-newsgroup-dependencies))
3924
3925 (defun gnus-id-to-article (id)
3926   "Return the article number of ID."
3927   (let ((thread (gnus-id-to-thread id)))
3928     (when (and thread
3929                (car thread))
3930       (mail-header-number (car thread)))))
3931
3932 (defun gnus-id-to-header (id)
3933   "Return the article headers of ID."
3934   (car (gnus-id-to-thread id)))
3935
3936 (defun gnus-article-displayed-root-p (article)
3937   "Say whether ARTICLE is a root(ish) article."
3938   (let ((level (gnus-summary-thread-level article))
3939         (refs (mail-header-references  (gnus-summary-article-header article)))
3940         particle)
3941     (cond
3942      ((null level) nil)
3943      ((zerop level) t)
3944      ((null refs) t)
3945      ((null (gnus-parent-id refs)) t)
3946      ((and (= 1 level)
3947            (null (setq particle (gnus-id-to-article
3948                                  (gnus-parent-id refs))))
3949            (null (gnus-summary-thread-level particle)))))))
3950
3951 (defun gnus-root-id (id)
3952   "Return the id of the root of the thread where ID appears."
3953   (let (last-id prev)
3954     (while (and id (setq prev (car (gnus-id-to-thread id))))
3955       (setq last-id id
3956             id (gnus-parent-id (mail-header-references prev))))
3957     last-id))
3958
3959 (defun gnus-articles-in-thread (thread)
3960   "Return the list of articles in THREAD."
3961   (cons (mail-header-number (car thread))
3962         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3963
3964 (defun gnus-remove-thread (id &optional dont-remove)
3965   "Remove the thread that has ID in it."
3966   (let (headers thread last-id)
3967     ;; First go up in this thread until we find the root.
3968     (setq last-id (gnus-root-id id)
3969           headers (message-flatten-list (gnus-id-to-thread last-id)))
3970     ;; We have now found the real root of this thread.  It might have
3971     ;; been gathered into some loose thread, so we have to search
3972     ;; through the threads to find the thread we wanted.
3973     (let ((threads gnus-newsgroup-threads)
3974           sub)
3975       (while threads
3976         (setq sub (car threads))
3977         (if (stringp (car sub))
3978             ;; This is a gathered thread, so we look at the roots
3979             ;; below it to find whether this article is in this
3980             ;; gathered root.
3981             (progn
3982               (setq sub (cdr sub))
3983               (while sub
3984                 (when (member (caar sub) headers)
3985                   (setq thread (car threads)
3986                         threads nil
3987                         sub nil))
3988                 (setq sub (cdr sub))))
3989           ;; It's an ordinary thread, so we check it.
3990           (when (eq (car sub) (car headers))
3991             (setq thread sub
3992                   threads nil)))
3993         (setq threads (cdr threads)))
3994       ;; If this article is in no thread, then it's a root.
3995       (if thread
3996           (unless dont-remove
3997             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3998         (setq thread (gnus-id-to-thread last-id)))
3999       (when thread
4000         (prog1
4001             thread                      ; We return this thread.
4002           (unless dont-remove
4003             (if (stringp (car thread))
4004                 (progn
4005                   ;; If we use dummy roots, then we have to remove the
4006                   ;; dummy root as well.
4007                   (when (eq gnus-summary-make-false-root 'dummy)
4008                     ;; We go to the dummy root by going to
4009                     ;; the first sub-"thread", and then one line up.
4010                     (gnus-summary-goto-article
4011                      (mail-header-number (caadr thread)))
4012                     (forward-line -1)
4013                     (gnus-delete-line)
4014                     (gnus-data-compute-positions))
4015                   (setq thread (cdr thread))
4016                   (while thread
4017                     (gnus-remove-thread-1 (car thread))
4018                     (setq thread (cdr thread))))
4019               (gnus-remove-thread-1 thread))))))))
4020
4021 (defun gnus-remove-thread-1 (thread)
4022   "Remove the thread THREAD recursively."
4023   (let ((number (mail-header-number (pop thread)))
4024         d)
4025     (setq thread (reverse thread))
4026     (while thread
4027       (gnus-remove-thread-1 (pop thread)))
4028     (when (setq d (gnus-data-find number))
4029       (goto-char (gnus-data-pos d))
4030       (gnus-summary-show-thread)
4031       (gnus-data-remove
4032        number
4033        (- (gnus-point-at-bol)
4034           (prog1
4035               (1+ (gnus-point-at-eol))
4036             (gnus-delete-line)))))))
4037
4038 (defun gnus-sort-threads-1 (threads func)
4039   (sort (mapcar (lambda (thread)
4040                   (cons (car thread)
4041                         (and (cdr thread)
4042                              (gnus-sort-threads-1 (cdr thread) func))))
4043                 threads) func))
4044
4045 (defun gnus-sort-threads (threads)
4046   "Sort THREADS."
4047   (if (not gnus-thread-sort-functions)
4048       threads
4049     (gnus-message 8 "Sorting threads...")
4050     (prog1
4051         (gnus-sort-threads-1
4052          threads
4053          (gnus-make-sort-function gnus-thread-sort-functions))
4054       (gnus-message 8 "Sorting threads...done"))))
4055
4056 (defun gnus-sort-articles (articles)
4057   "Sort ARTICLES."
4058   (when gnus-article-sort-functions
4059     (gnus-message 7 "Sorting articles...")
4060     (prog1
4061         (setq gnus-newsgroup-headers
4062               (sort articles (gnus-make-sort-function
4063                               gnus-article-sort-functions)))
4064       (gnus-message 7 "Sorting articles...done"))))
4065
4066 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4067 (defmacro gnus-thread-header (thread)
4068   "Return header of first article in THREAD.
4069 Note that THREAD must never, ever be anything else than a variable -
4070 using some other form will lead to serious barfage."
4071   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4072   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4073   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4074         (vector thread) 2))
4075
4076 (defsubst gnus-article-sort-by-number (h1 h2)
4077   "Sort articles by article number."
4078   (< (mail-header-number h1)
4079      (mail-header-number h2)))
4080
4081 (defun gnus-thread-sort-by-number (h1 h2)
4082   "Sort threads by root article number."
4083   (gnus-article-sort-by-number
4084    (gnus-thread-header h1) (gnus-thread-header h2)))
4085
4086 (defsubst gnus-article-sort-by-lines (h1 h2)
4087   "Sort articles by article Lines header."
4088   (< (mail-header-lines h1)
4089      (mail-header-lines h2)))
4090
4091 (defun gnus-thread-sort-by-lines (h1 h2)
4092   "Sort threads by root article Lines header."
4093   (gnus-article-sort-by-lines
4094    (gnus-thread-header h1) (gnus-thread-header h2)))
4095
4096 (defsubst gnus-article-sort-by-chars (h1 h2)
4097   "Sort articles by octet length."
4098   (< (mail-header-chars h1)
4099      (mail-header-chars h2)))
4100
4101 (defun gnus-thread-sort-by-chars (h1 h2)
4102   "Sort threads by root article octet length."
4103   (gnus-article-sort-by-chars
4104    (gnus-thread-header h1) (gnus-thread-header h2)))
4105
4106 (defsubst gnus-article-sort-by-author (h1 h2)
4107   "Sort articles by root author."
4108   (string-lessp
4109    (let ((addr (car (mime-entity-read-field h1 'From))))
4110      (or (std11-full-name-string addr)
4111          (std11-address-string addr)
4112          ""))
4113    (let ((addr (car (mime-entity-read-field h2 'From))))
4114      (or (std11-full-name-string addr)
4115          (std11-address-string addr)
4116          ""))
4117    ))
4118
4119 (defun gnus-thread-sort-by-author (h1 h2)
4120   "Sort threads by root author."
4121   (gnus-article-sort-by-author
4122    (gnus-thread-header h1)  (gnus-thread-header h2)))
4123
4124 (defsubst gnus-article-sort-by-subject (h1 h2)
4125   "Sort articles by root subject."
4126   (string-lessp
4127    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4128    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4129
4130 (defun gnus-thread-sort-by-subject (h1 h2)
4131   "Sort threads by root subject."
4132   (gnus-article-sort-by-subject
4133    (gnus-thread-header h1) (gnus-thread-header h2)))
4134
4135 (defsubst gnus-article-sort-by-date (h1 h2)
4136   "Sort articles by root article date."
4137   (time-less-p
4138    (gnus-date-get-time (mail-header-date h1))
4139    (gnus-date-get-time (mail-header-date h2))))
4140
4141 (defun gnus-thread-sort-by-date (h1 h2)
4142   "Sort threads by root article date."
4143   (gnus-article-sort-by-date
4144    (gnus-thread-header h1) (gnus-thread-header h2)))
4145
4146 (defsubst gnus-article-sort-by-score (h1 h2)
4147   "Sort articles by root article score.
4148 Unscored articles will be counted as having a score of zero."
4149   (> (or (cdr (assq (mail-header-number h1)
4150                     gnus-newsgroup-scored))
4151          gnus-summary-default-score 0)
4152      (or (cdr (assq (mail-header-number h2)
4153                     gnus-newsgroup-scored))
4154          gnus-summary-default-score 0)))
4155
4156 (defun gnus-thread-sort-by-score (h1 h2)
4157   "Sort threads by root article score."
4158   (gnus-article-sort-by-score
4159    (gnus-thread-header h1) (gnus-thread-header h2)))
4160
4161 (defun gnus-thread-sort-by-total-score (h1 h2)
4162   "Sort threads by the sum of all scores in the thread.
4163 Unscored articles will be counted as having a score of zero."
4164   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4165
4166 (defun gnus-thread-total-score (thread)
4167   ;; This function find the total score of THREAD.
4168   (cond ((null thread)
4169          0)
4170         ((consp thread)
4171          (if (stringp (car thread))
4172              (apply gnus-thread-score-function 0
4173                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4174            (gnus-thread-total-score-1 thread)))
4175         (t
4176          (gnus-thread-total-score-1 (list thread)))))
4177
4178 (defun gnus-thread-total-score-1 (root)
4179   ;; This function find the total score of the thread below ROOT.
4180   (setq root (car root))
4181   (apply gnus-thread-score-function
4182          (or (append
4183               (mapcar 'gnus-thread-total-score
4184                       (cdr (gnus-id-to-thread (mail-header-id root))))
4185               (when (> (mail-header-number root) 0)
4186                 (list (or (cdr (assq (mail-header-number root)
4187                                      gnus-newsgroup-scored))
4188                           gnus-summary-default-score 0))))
4189              (list gnus-summary-default-score)
4190              '(0))))
4191
4192 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4193 (defvar gnus-tmp-prev-subject nil)
4194 (defvar gnus-tmp-false-parent nil)
4195 (defvar gnus-tmp-root-expunged nil)
4196 (defvar gnus-tmp-dummy-line nil)
4197
4198 (eval-when-compile (defvar gnus-tmp-header))
4199 (defun gnus-extra-header (type &optional header)
4200   "Return the extra header of TYPE."
4201   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4202       ""))
4203
4204 (defvar gnus-tmp-thread-tree-header-string "")
4205
4206 (defvar gnus-sum-thread-tree-root "> "
4207   "With %B spec, used for the root of a thread.
4208 If nil, use subject instead.")
4209 (defvar gnus-sum-thread-tree-single-indent ""
4210   "With %B spec, used for a thread with just one message.
4211 If nil, use subject instead.")
4212 (defvar gnus-sum-thread-tree-vertical "| "
4213   "With %B spec, used for drawing a vertical line.")
4214 (defvar gnus-sum-thread-tree-indent "  "
4215   "With %B spec, used for indenting.")
4216 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4217   "With %B spec, used for a leaf with brothers.")
4218 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4219   "With %B spec, used for a leaf without brothers.")
4220
4221 (defun gnus-summary-prepare-threads (threads)
4222   "Prepare summary buffer from THREADS and indentation LEVEL.
4223 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4224 or a straight list of headers."
4225   (gnus-message 7 "Generating summary...")
4226
4227   (setq gnus-newsgroup-threads threads)
4228   (beginning-of-line)
4229
4230   (let ((gnus-tmp-level 0)
4231         (default-score (or gnus-summary-default-score 0))
4232         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4233         thread number subject stack state gnus-tmp-gathered beg-match
4234         new-roots gnus-tmp-new-adopts thread-end
4235         gnus-tmp-header gnus-tmp-unread
4236         gnus-tmp-replied gnus-tmp-subject-or-nil
4237         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4238         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4239         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4240         tree-stack)
4241
4242     (setq gnus-tmp-prev-subject nil)
4243
4244     (if (vectorp (car threads))
4245         ;; If this is a straight (sic) list of headers, then a
4246         ;; threaded summary display isn't required, so we just create
4247         ;; an unthreaded one.
4248         (gnus-summary-prepare-unthreaded threads)
4249
4250       ;; Do the threaded display.
4251
4252       (while (or threads stack gnus-tmp-new-adopts new-roots)
4253
4254         (if (and (= gnus-tmp-level 0)
4255                  (or (not stack)
4256                      (= (caar stack) 0))
4257                  (not gnus-tmp-false-parent)
4258                  (or gnus-tmp-new-adopts new-roots))
4259             (if gnus-tmp-new-adopts
4260                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4261                       thread (list (car gnus-tmp-new-adopts))
4262                       gnus-tmp-header (caar thread)
4263                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4264               (when new-roots
4265                 (setq thread (list (car new-roots))
4266                       gnus-tmp-header (caar thread)
4267                       new-roots (cdr new-roots))))
4268
4269           (if threads
4270               ;; If there are some threads, we do them before the
4271               ;; threads on the stack.
4272               (setq thread threads
4273                     gnus-tmp-header (caar thread))
4274             ;; There were no current threads, so we pop something off
4275             ;; the stack.
4276             (setq state (car stack)
4277                   gnus-tmp-level (car state)
4278                   tree-stack (cadr state)
4279                   thread (caddr state)
4280                   stack (cdr stack)
4281                   gnus-tmp-header (caar thread))))
4282
4283         (setq gnus-tmp-false-parent nil)
4284         (setq gnus-tmp-root-expunged nil)
4285         (setq thread-end nil)
4286
4287         (if (stringp gnus-tmp-header)
4288             ;; The header is a dummy root.
4289             (cond
4290              ((eq gnus-summary-make-false-root 'adopt)
4291               ;; We let the first article adopt the rest.
4292               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4293                                                (cddar thread)))
4294               (setq gnus-tmp-gathered
4295                     (nconc (mapcar
4296                             (lambda (h) (mail-header-number (car h)))
4297                             (cddar thread))
4298                            gnus-tmp-gathered))
4299               (setq thread (cons (list (caar thread)
4300                                        (cadar thread))
4301                                  (cdr thread)))
4302               (setq gnus-tmp-level -1
4303                     gnus-tmp-false-parent t))
4304              ((eq gnus-summary-make-false-root 'empty)
4305               ;; We print adopted articles with empty subject fields.
4306               (setq gnus-tmp-gathered
4307                     (nconc (mapcar
4308                             (lambda (h) (mail-header-number (car h)))
4309                             (cddar thread))
4310                            gnus-tmp-gathered))
4311               (setq gnus-tmp-level -1))
4312              ((eq gnus-summary-make-false-root 'dummy)
4313               ;; We remember that we probably want to output a dummy
4314               ;; root.
4315               (setq gnus-tmp-dummy-line gnus-tmp-header)
4316               (setq gnus-tmp-prev-subject gnus-tmp-header))
4317              (t
4318               ;; We do not make a root for the gathered
4319               ;; sub-threads at all.
4320               (setq gnus-tmp-level -1)))
4321
4322           (setq number (mail-header-number gnus-tmp-header)
4323                 subject (mail-header-subject gnus-tmp-header))
4324
4325           (cond
4326            ;; If the thread has changed subject, we might want to make
4327            ;; this subthread into a root.
4328            ((and (null gnus-thread-ignore-subject)
4329                  (not (zerop gnus-tmp-level))
4330                  gnus-tmp-prev-subject
4331                  (not (inline
4332                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4333             (setq new-roots (nconc new-roots (list (car thread)))
4334                   thread-end t
4335                   gnus-tmp-header nil))
4336            ;; If the article lies outside the current limit,
4337            ;; then we do not display it.
4338            ((not (memq number gnus-newsgroup-limit))
4339             (setq gnus-tmp-gathered
4340                   (nconc (mapcar
4341                           (lambda (h) (mail-header-number (car h)))
4342                           (cdar thread))
4343                          gnus-tmp-gathered))
4344             (setq gnus-tmp-new-adopts (if (cdar thread)
4345                                           (append gnus-tmp-new-adopts
4346                                                   (cdar thread))
4347                                         gnus-tmp-new-adopts)
4348                   thread-end t
4349                   gnus-tmp-header nil)
4350             (when (zerop gnus-tmp-level)
4351               (setq gnus-tmp-root-expunged t)))
4352            ;; Perhaps this article is to be marked as read?
4353            ((and gnus-summary-mark-below
4354                  (< (or (cdr (assq number gnus-newsgroup-scored))
4355                         default-score)
4356                     gnus-summary-mark-below)
4357                  ;; Don't touch sparse articles.
4358                  (not (gnus-summary-article-sparse-p number))
4359                  (not (gnus-summary-article-ancient-p number)))
4360             (setq gnus-newsgroup-unreads
4361                   (delq number gnus-newsgroup-unreads))
4362             (if gnus-newsgroup-auto-expire
4363                 (push number gnus-newsgroup-expirable)
4364               (push (cons number gnus-low-score-mark)
4365                     gnus-newsgroup-reads))))
4366
4367           (when gnus-tmp-header
4368             ;; We may have an old dummy line to output before this
4369             ;; article.
4370             (when (and gnus-tmp-dummy-line
4371                        (gnus-subject-equal
4372                         gnus-tmp-dummy-line
4373                         (mail-header-subject gnus-tmp-header)))
4374               (gnus-summary-insert-dummy-line
4375                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4376               (setq gnus-tmp-dummy-line nil))
4377
4378             ;; Compute the mark.
4379             (setq gnus-tmp-unread (gnus-article-mark number))
4380
4381             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4382                                   gnus-tmp-header gnus-tmp-level)
4383                   gnus-newsgroup-data)
4384
4385             ;; Actually insert the line.
4386             (setq
4387              gnus-tmp-subject-or-nil
4388              (cond
4389               ((and gnus-thread-ignore-subject
4390                     gnus-tmp-prev-subject
4391                     (not (inline (gnus-subject-equal
4392                                   gnus-tmp-prev-subject subject))))
4393                subject)
4394               ((zerop gnus-tmp-level)
4395                (if (and (eq gnus-summary-make-false-root 'empty)
4396                         (memq number gnus-tmp-gathered)
4397                         gnus-tmp-prev-subject
4398                         (inline (gnus-subject-equal
4399                                  gnus-tmp-prev-subject subject)))
4400                    gnus-summary-same-subject
4401                  subject))
4402               (t gnus-summary-same-subject)))
4403             (if (and (eq gnus-summary-make-false-root 'adopt)
4404                      (= gnus-tmp-level 1)
4405                      (memq number gnus-tmp-gathered))
4406                 (setq gnus-tmp-opening-bracket ?\<
4407                       gnus-tmp-closing-bracket ?\>)
4408               (setq gnus-tmp-opening-bracket ?\[
4409                     gnus-tmp-closing-bracket ?\]))
4410             (setq
4411              gnus-tmp-indentation
4412              (aref gnus-thread-indent-array gnus-tmp-level)
4413              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4414              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4415                                 gnus-summary-default-score 0)
4416              gnus-tmp-score-char
4417              (if (or (null gnus-summary-default-score)
4418                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4419                          gnus-summary-zcore-fuzz))
4420                  ?\ ;;;Whitespace
4421                (if (< gnus-tmp-score gnus-summary-default-score)
4422                    gnus-score-below-mark gnus-score-over-mark))
4423              gnus-tmp-replied
4424              (cond ((memq number gnus-newsgroup-processable)
4425                     gnus-process-mark)
4426                    ((memq number gnus-newsgroup-cached)
4427                     gnus-cached-mark)
4428                    ((memq number gnus-newsgroup-replied)
4429                     gnus-replied-mark)
4430                    ((memq number gnus-newsgroup-forwarded)
4431                     gnus-forwarded-mark)
4432                    ((memq number gnus-newsgroup-saved)
4433                     gnus-saved-mark)
4434                    ((memq number gnus-newsgroup-recent)
4435                     gnus-recent-mark)
4436                    ((memq number gnus-newsgroup-unseen)
4437                     gnus-unseen-mark)
4438                    (t gnus-no-mark))
4439              gnus-tmp-from (mail-header-from gnus-tmp-header)
4440              gnus-tmp-name
4441              (cond
4442               ((string-match "<[^>]+> *$" gnus-tmp-from)
4443                (setq beg-match (match-beginning 0))
4444                (or (and (string-match "^\".+\"" gnus-tmp-from)
4445                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4446                    (substring gnus-tmp-from 0 beg-match)))
4447               ((string-match "(.+)" gnus-tmp-from)
4448                (substring gnus-tmp-from
4449                           (1+ (match-beginning 0)) (1- (match-end 0))))
4450               (t gnus-tmp-from))
4451              gnus-tmp-thread-tree-header-string
4452              (cond
4453               ((not gnus-show-threads) "")
4454               ((zerop gnus-tmp-level)
4455                (if (cdar thread)
4456                    (or gnus-sum-thread-tree-root subject)
4457                  (or gnus-sum-thread-tree-single-indent subject)))
4458               (t
4459                (concat (apply 'concat
4460                               (mapcar (lambda (item)
4461                                         (if (= item 1)
4462                                             gnus-sum-thread-tree-vertical
4463                                           gnus-sum-thread-tree-indent))
4464                                       (cdr (reverse tree-stack))))
4465                        (if (nth 1 thread)
4466                            gnus-sum-thread-tree-leaf-with-other
4467                          gnus-sum-thread-tree-single-leaf)))))
4468             (when (string= gnus-tmp-name "")
4469               (setq gnus-tmp-name gnus-tmp-from))
4470             (unless (numberp gnus-tmp-lines)
4471               (setq gnus-tmp-lines -1))
4472             (if (= gnus-tmp-lines -1)
4473                 (setq gnus-tmp-lines "?")
4474               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4475             (gnus-put-text-property
4476              (point)
4477              (progn (eval gnus-summary-line-format-spec) (point))
4478              'gnus-number number)
4479             (when gnus-visual-p
4480               (forward-line -1)
4481               (gnus-run-hooks 'gnus-summary-update-hook)
4482               (forward-line 1))
4483
4484             (setq gnus-tmp-prev-subject subject)))
4485
4486         (when (nth 1 thread)
4487           (push (list (max 0 gnus-tmp-level)
4488                       (copy-list tree-stack)
4489                       (nthcdr 1 thread))
4490                 stack))
4491         (push (if (nth 1 thread) 1 0) tree-stack)
4492         (incf gnus-tmp-level)
4493         (setq threads (if thread-end nil (cdar thread)))
4494         (unless threads
4495           (setq gnus-tmp-level 0)))))
4496   (gnus-message 7 "Generating summary...done"))
4497
4498 (defun gnus-summary-prepare-unthreaded (headers)
4499   "Generate an unthreaded summary buffer based on HEADERS."
4500   (let (header number mark)
4501
4502     (beginning-of-line)
4503
4504     (while headers
4505       ;; We may have to root out some bad articles...
4506       (when (memq (setq number (mail-header-number
4507                                 (setq header (pop headers))))
4508                   gnus-newsgroup-limit)
4509         ;; Mark article as read when it has a low score.
4510         (when (and gnus-summary-mark-below
4511                    (< (or (cdr (assq number gnus-newsgroup-scored))
4512                           gnus-summary-default-score 0)
4513                       gnus-summary-mark-below)
4514                    (not (gnus-summary-article-ancient-p number)))
4515           (setq gnus-newsgroup-unreads
4516                 (delq number gnus-newsgroup-unreads))
4517           (if gnus-newsgroup-auto-expire
4518               (push number gnus-newsgroup-expirable)
4519             (push (cons number gnus-low-score-mark)
4520                   gnus-newsgroup-reads)))
4521
4522         (setq mark (gnus-article-mark number))
4523         (push (gnus-data-make number mark (1+ (point)) header 0)
4524               gnus-newsgroup-data)
4525         (gnus-summary-insert-line
4526          header 0 number
4527          mark (memq number gnus-newsgroup-replied)
4528          (memq number gnus-newsgroup-expirable)
4529          (mail-header-subject header) nil
4530          (cdr (assq number gnus-newsgroup-scored))
4531          (memq number gnus-newsgroup-processable))))))
4532
4533 (defun gnus-summary-remove-list-identifiers ()
4534   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4535   (let ((regexp (if (consp gnus-list-identifiers)
4536                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4537                   gnus-list-identifiers))
4538         changed subject)
4539     (when regexp
4540       (dolist (header gnus-newsgroup-headers)
4541         (setq subject (mail-header-subject header)
4542               changed nil)
4543         (while (string-match
4544                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4545                 subject)
4546           (setq subject
4547                 (concat (substring subject 0 (match-beginning 2))
4548                         (substring subject (match-end 0)))
4549                 changed t))
4550         (when (and changed
4551                    (string-match
4552                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4553           (setq subject
4554                 (concat (substring subject 0 (match-beginning 1))
4555                         (substring subject (match-end 1)))))
4556         (when changed
4557           (mail-header-set-subject header subject))))))
4558
4559 (defun gnus-fetch-headers (articles)
4560   "Fetch headers of ARTICLES."
4561   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4562     (gnus-message 5 "Fetching headers for %s..." name)
4563     (prog1
4564         (if (eq 'nov
4565                 (setq gnus-headers-retrieved-by
4566                       (gnus-retrieve-headers
4567                        articles gnus-newsgroup-name
4568                        ;; We might want to fetch old headers, but
4569                        ;; not if there is only 1 article.
4570                        (and (or (and
4571                                  (not (eq gnus-fetch-old-headers 'some))
4572                                  (not (numberp gnus-fetch-old-headers)))
4573                                 (> (length articles) 1))
4574                             gnus-fetch-old-headers))))
4575             (gnus-get-newsgroup-headers-xover
4576              articles nil nil gnus-newsgroup-name t)
4577           (gnus-get-newsgroup-headers))
4578       (gnus-message 5 "Fetching headers for %s...done" name))))
4579
4580 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4581   "Select newsgroup GROUP.
4582 If READ-ALL is non-nil, all articles in the group are selected.
4583 If SELECT-ARTICLES, only select those articles from GROUP."
4584   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4585          ;;!!! Dirty hack; should be removed.
4586          (gnus-summary-ignore-duplicates
4587           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4588               t
4589             gnus-summary-ignore-duplicates))
4590          (info (nth 2 entry))
4591          articles fetched-articles cached)
4592
4593     (unless (gnus-check-server
4594              (set (make-local-variable 'gnus-current-select-method)
4595                   (gnus-find-method-for-group group)))
4596       (error "Couldn't open server"))
4597
4598     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4599         (gnus-activate-group group)     ; Or we can activate it...
4600         (progn                          ; Or we bug out.
4601           (when (equal major-mode 'gnus-summary-mode)
4602             (kill-buffer (current-buffer)))
4603           (error "Couldn't activate group %s: %s"
4604                  group (gnus-status-message group))))
4605
4606     (unless (gnus-request-group group t)
4607       (when (equal major-mode 'gnus-summary-mode)
4608         (kill-buffer (current-buffer)))
4609       (error "Couldn't request group %s: %s"
4610              group (gnus-status-message group)))
4611
4612     (setq gnus-newsgroup-name group
4613           gnus-newsgroup-unselected nil
4614           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4615
4616     (let ((display (gnus-group-find-parameter group 'display)))
4617       (setq gnus-newsgroup-display
4618             (cond
4619              ((not (zerop (or (car-safe read-all) 0)))
4620               ;; The user entered the group with C-u SPC/RET, let's show
4621               ;; all articles.
4622               'gnus-not-ignore)
4623              ((eq display 'all)
4624               'gnus-not-ignore)
4625              ((arrayp display)
4626               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4627              ((numberp display)
4628               ;; The following is probably the "correct" solution, but
4629               ;; it makes Gnus fetch all headers and then limit the
4630               ;; articles (which is slow), so instead we hack the
4631               ;; select-articles parameter instead. -- Simon Josefsson
4632               ;; <jas@kth.se>
4633               ;;
4634               ;; (gnus-byte-compile
4635               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4636               ;;                         display)))))
4637               (setq select-articles
4638                     (gnus-uncompress-range
4639                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4640                              (if (> tmp 0)
4641                                  tmp
4642                                1))
4643                            (cdr (gnus-active group)))))
4644               nil)
4645              (t
4646               nil))))
4647
4648     (gnus-summary-setup-default-charset)
4649
4650     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4651     (when (gnus-virtual-group-p group)
4652       (setq cached gnus-newsgroup-cached))
4653
4654     (setq gnus-newsgroup-unreads
4655           (gnus-set-difference
4656            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4657            gnus-newsgroup-dormant))
4658
4659     (setq gnus-newsgroup-processable nil)
4660
4661     (gnus-update-read-articles group gnus-newsgroup-unreads)
4662
4663     ;; Adjust and set lists of article marks.
4664     (when info
4665       (gnus-adjust-marked-articles info))
4666
4667     (if (setq articles select-articles)
4668         (setq gnus-newsgroup-unselected
4669               (gnus-sorted-intersection
4670                gnus-newsgroup-unreads
4671                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4672       (setq articles (gnus-articles-to-read group read-all)))
4673
4674     (cond
4675      ((null articles)
4676       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4677       'quit)
4678      ((eq articles 0) nil)
4679      (t
4680       ;; Init the dependencies hash table.
4681       (setq gnus-newsgroup-dependencies
4682             (gnus-make-hashtable (length articles)))
4683       (gnus-set-global-variables)
4684       ;; Retrieve the headers and read them in.
4685       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4686
4687       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4688       (when cached
4689         (setq gnus-newsgroup-cached cached))
4690
4691       ;; Suppress duplicates?
4692       (when gnus-suppress-duplicates
4693         (gnus-dup-suppress-articles))
4694
4695       ;; Set the initial limit.
4696       (setq gnus-newsgroup-limit (copy-sequence articles))
4697       ;; Remove canceled articles from the list of unread articles.
4698       (setq fetched-articles
4699             (mapcar (lambda (headers) (mail-header-number headers))
4700                     gnus-newsgroup-headers))
4701       (setq gnus-newsgroup-articles fetched-articles)
4702       (setq gnus-newsgroup-unreads
4703             (gnus-set-sorted-intersection
4704              gnus-newsgroup-unreads fetched-articles))
4705
4706       ;; The `seen' marks are treated specially.
4707       (if (not gnus-newsgroup-seen)
4708           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4709         (dolist (article gnus-newsgroup-articles)
4710           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4711             (push article gnus-newsgroup-unseen)))
4712         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4713
4714       ;; Removed marked articles that do not exist.
4715       (gnus-update-missing-marks
4716        (gnus-sorted-complement fetched-articles articles))
4717       ;; We might want to build some more threads first.
4718       (when (and gnus-fetch-old-headers
4719                  (eq gnus-headers-retrieved-by 'nov))
4720         (if (eq gnus-fetch-old-headers 'invisible)
4721             (gnus-build-all-threads)
4722           (gnus-build-old-threads)))
4723       ;; Let the Gnus agent mark articles as read.
4724       (when gnus-agent
4725         (gnus-agent-get-undownloaded-list))
4726       ;; Remove list identifiers from subject
4727       (when gnus-list-identifiers
4728         (gnus-summary-remove-list-identifiers))
4729       ;; Check whether auto-expire is to be done in this group.
4730       (setq gnus-newsgroup-auto-expire
4731             (gnus-group-auto-expirable-p group))
4732       ;; Set up the article buffer now, if necessary.
4733       (unless gnus-single-article-buffer
4734         (gnus-article-setup-buffer))
4735       ;; First and last article in this newsgroup.
4736       (when gnus-newsgroup-headers
4737         (setq gnus-newsgroup-begin
4738               (mail-header-number (car gnus-newsgroup-headers))
4739               gnus-newsgroup-end
4740               (mail-header-number
4741                (gnus-last-element gnus-newsgroup-headers))))
4742       ;; GROUP is successfully selected.
4743       (or gnus-newsgroup-headers t)))))
4744
4745 (defun gnus-summary-display-make-predicate (display)
4746   (require 'gnus-agent)
4747   (when (= (length display) 1)
4748     (setq display (car display)))
4749   (unless gnus-summary-display-cache
4750     (dolist (elem (append (list (cons 'read 'read)
4751                                 (cons 'unseen 'unseen))
4752                           gnus-article-mark-lists))
4753       (push (cons (cdr elem)
4754                   (gnus-byte-compile
4755                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4756             gnus-summary-display-cache)))
4757   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4758     (gnus-get-predicate display)))
4759
4760 ;; Uses the dynamically bound `number' variable.
4761 (defvar number)
4762 (defun gnus-article-marked-p (type &optional article)
4763   (let ((article (or article number)))
4764     (cond
4765      ((eq type 'tick)
4766       (memq article gnus-newsgroup-marked))
4767      ((eq type 'unsend)
4768       (memq article gnus-newsgroup-unsendable))
4769      ((eq type 'undownload)
4770       (memq article gnus-newsgroup-undownloaded))
4771      ((eq type 'download)
4772       (memq article gnus-newsgroup-downloadable))
4773      ((eq type 'unread)
4774       (memq article gnus-newsgroup-unreads))
4775      ((eq type 'read)
4776       (memq article gnus-newsgroup-reads))
4777      ((eq type 'dormant)
4778       (memq article gnus-newsgroup-dormant) )
4779      ((eq type 'expire)
4780       (memq article gnus-newsgroup-expirable))
4781      ((eq type 'reply)
4782       (memq article gnus-newsgroup-replied))
4783      ((eq type 'killed)
4784       (memq article gnus-newsgroup-killed))
4785      ((eq type 'bookmark)
4786       (assq article gnus-newsgroup-bookmarks))
4787      ((eq type 'score)
4788       (assq article gnus-newsgroup-scored))
4789      ((eq type 'save)
4790       (memq article gnus-newsgroup-saved))
4791      ((eq type 'cache)
4792       (memq article gnus-newsgroup-cached))
4793      ((eq type 'forward)
4794       (memq article gnus-newsgroup-forwarded))
4795      ((eq type 'seen)
4796       (not (memq article gnus-newsgroup-unseen)))
4797      ((eq type 'recent)
4798       (memq article gnus-newsgroup-recent))
4799      (t t))))
4800
4801 (defun gnus-articles-to-read (group &optional read-all)
4802   "Find out what articles the user wants to read."
4803   (let* ((articles
4804           ;; Select all articles if `read-all' is non-nil, or if there
4805           ;; are no unread articles.
4806           (if (or read-all
4807                   (and (zerop (length gnus-newsgroup-marked))
4808                        (zerop (length gnus-newsgroup-unreads)))
4809                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4810               ;; We want to select the headers for all the articles in
4811               ;; the group, so we select either all the active
4812               ;; articles in the group, or (if that's nil), the
4813               ;; articles in the cache.
4814               (or
4815                (gnus-uncompress-range (gnus-active group))
4816                (gnus-cache-articles-in-group group))
4817             ;; Select only the "normal" subset of articles.
4818             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4819                           (copy-sequence gnus-newsgroup-unreads))
4820                   '<)))
4821          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4822          (scored (length scored-list))
4823          (number (length articles))
4824          (marked (+ (length gnus-newsgroup-marked)
4825                     (length gnus-newsgroup-dormant)))
4826          (select
4827           (cond
4828            ((numberp read-all)
4829             read-all)
4830            (t
4831             (condition-case ()
4832                 (cond
4833                  ((and (or (<= scored marked) (= scored number))
4834                        (natnump gnus-large-newsgroup)
4835                        (> number gnus-large-newsgroup))
4836                   (let* ((cursor-in-echo-area nil)
4837                          (input
4838                           (read-from-minibuffer
4839                            (format
4840                             "How many articles from %s (max %d): "
4841                             (gnus-limit-string
4842                              (gnus-group-decoded-name gnus-newsgroup-name)
4843                              35)
4844                             number)
4845                            (cons (number-to-string gnus-large-newsgroup)
4846                                  0))))
4847                     (if (string-match "^[ \t]*$" input)
4848                         number
4849                       input)))
4850                  ((and (> scored marked) (< scored number)
4851                        (> (- scored number) 20))
4852                   (let ((input
4853                          (read-string
4854                           (format "%s %s (%d scored, %d total): "
4855                                   "How many articles from"
4856                                   (gnus-group-decoded-name group)
4857                                   scored number))))
4858                     (if (string-match "^[ \t]*$" input)
4859                         number input)))
4860                  (t number))
4861               (quit
4862                (message "Quit getting the articles to read")
4863                nil))))))
4864     (setq select (if (stringp select) (string-to-number select) select))
4865     (if (or (null select) (zerop select))
4866         select
4867       (if (and (not (zerop scored)) (<= (abs select) scored))
4868           (progn
4869             (setq articles (sort scored-list '<))
4870             (setq number (length articles)))
4871         (setq articles (copy-sequence articles)))
4872
4873       (when (< (abs select) number)
4874         (if (< select 0)
4875             ;; Select the N oldest articles.
4876             (setcdr (nthcdr (1- (abs select)) articles) nil)
4877           ;; Select the N most recent articles.
4878           (setq articles (nthcdr (- number select) articles))))
4879       (setq gnus-newsgroup-unselected
4880             (gnus-sorted-intersection
4881              gnus-newsgroup-unreads
4882              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4883       (when gnus-alter-articles-to-read-function
4884         (setq gnus-newsgroup-unreads
4885               (sort
4886                (funcall gnus-alter-articles-to-read-function
4887                         gnus-newsgroup-name gnus-newsgroup-unreads)
4888                '<)))
4889       articles)))
4890
4891 (defun gnus-killed-articles (killed articles)
4892   (let (out)
4893     (while articles
4894       (when (inline (gnus-member-of-range (car articles) killed))
4895         (push (car articles) out))
4896       (setq articles (cdr articles)))
4897     out))
4898
4899 (defun gnus-uncompress-marks (marks)
4900   "Uncompress the mark ranges in MARKS."
4901   (let ((uncompressed '(score bookmark))
4902         out)
4903     (while marks
4904       (if (memq (caar marks) uncompressed)
4905           (push (car marks) out)
4906         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4907       (setq marks (cdr marks)))
4908     out))
4909
4910 (defun gnus-article-mark-to-type (mark)
4911   "Return the type of MARK."
4912   (or (cadr (assq mark gnus-article-special-mark-lists))
4913       'list))
4914
4915 (defun gnus-article-unpropagatable-p (mark)
4916   "Return whether MARK should be propagated to backend."
4917   (memq mark gnus-article-unpropagated-mark-lists))
4918
4919 (defun gnus-adjust-marked-articles (info)
4920   "Set all article lists and remove all marks that are no longer valid."
4921   (let* ((marked-lists (gnus-info-marks info))
4922          (active (gnus-active (gnus-info-group info)))
4923          (min (car active))
4924          (max (cdr active))
4925          (types gnus-article-mark-lists)
4926          marks var articles article mark mark-type)
4927
4928     (dolist (marks marked-lists)
4929       (setq mark (car marks)
4930             mark-type (gnus-article-mark-to-type mark)
4931             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4932
4933       ;; We set the variable according to the type of the marks list,
4934       ;; and then adjust the marks to a subset of the active articles.
4935       (cond
4936        ;; Adjust "simple" lists.
4937        ((eq mark-type 'list)
4938         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4939         (when (memq mark '(tick dormant expire reply save))
4940           (while articles
4941             (when (or (< (setq article (pop articles)) min) (> article max))
4942               (set var (delq article (symbol-value var)))))))
4943        ;; Adjust assocs.
4944        ((eq mark-type 'tuple)
4945         (set var (setq articles (cdr marks)))
4946         (when (not (listp (cdr (symbol-value var))))
4947           (set var (list (symbol-value var))))
4948         (when (not (listp (cdr articles)))
4949           (setq articles (list articles)))
4950         (while articles
4951           (when (or (not (consp (setq article (pop articles))))
4952                     (< (car article) min)
4953                     (> (car article) max))
4954             (set var (delq article (symbol-value var))))))
4955        ;; Adjust ranges (sloppily).
4956        ((eq mark-type 'range)
4957         (cond
4958          ((eq mark 'seen)
4959           ;; T-gnus change: Fix the record for `seen' if it looks like
4960           ;; (seen NUM1 . NUM2).  It should be (seen (NUM1 . NUM2)).
4961           (when (numberp (cddr marks))
4962             (setcdr marks (list (cdr marks))))
4963           (setq articles (cdr marks))
4964           (while (and articles
4965                       (or (and (consp (car articles))
4966                                (> min (cdar articles)))
4967                           (and (numberp (car articles))
4968                                (> min (car articles)))))
4969             (pop articles))
4970           (set var articles))))))))
4971
4972 (defun gnus-update-missing-marks (missing)
4973   "Go through the list of MISSING articles and remove them from the mark lists."
4974   (when missing
4975     (let (var m)
4976       ;; Go through all types.
4977       (dolist (elem gnus-article-mark-lists)
4978         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4979           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4980           (when (symbol-value var)
4981             ;; This list has articles.  So we delete all missing
4982             ;; articles from it.
4983             (setq m missing)
4984             (while m
4985               (set var (delq (pop m) (symbol-value var))))))))))
4986
4987 (defun gnus-update-marks ()
4988   "Enter the various lists of marked articles into the newsgroup info list."
4989   (let ((types gnus-article-mark-lists)
4990         (info (gnus-get-info gnus-newsgroup-name))
4991         type list newmarked symbol delta-marks)
4992     (when info
4993       ;; Add all marks lists to the list of marks lists.
4994       (while (setq type (pop types))
4995         (setq list (symbol-value
4996                     (setq symbol
4997                           (intern (format "gnus-newsgroup-%s" (car type))))))
4998
4999         (when list
5000           ;; Get rid of the entries of the articles that have the
5001           ;; default score.
5002           (when (and (eq (cdr type) 'score)
5003                      gnus-save-score
5004                      list)
5005             (let* ((arts list)
5006                    (prev (cons nil list))
5007                    (all prev))
5008               (while arts
5009                 (if (or (not (consp (car arts)))
5010                         (= (cdar arts) gnus-summary-default-score))
5011                     (setcdr prev (cdr arts))
5012                   (setq prev arts))
5013                 (setq arts (cdr arts)))
5014               (setq list (cdr all)))))
5015
5016         (when (eq (cdr type) 'seen)
5017           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5018
5019         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5020           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5021
5022         (when (and (gnus-check-backend-function
5023                     'request-set-mark gnus-newsgroup-name)
5024                    (not (gnus-article-unpropagatable-p (cdr type))))
5025           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5026                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5027                  (add (gnus-remove-from-range
5028                        (gnus-copy-sequence list) old)))
5029             (when add
5030               (push (list add 'add (list (cdr type))) delta-marks))
5031             (when del
5032               (push (list del 'del (list (cdr type))) delta-marks))))
5033
5034         (when list
5035           (push (cons (cdr type) list) newmarked)))
5036
5037       (when delta-marks
5038         (unless (gnus-check-group gnus-newsgroup-name)
5039           (error "Can't open server for %s" gnus-newsgroup-name))
5040         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5041
5042       ;; Enter these new marks into the info of the group.
5043       (if (nthcdr 3 info)
5044           (setcar (nthcdr 3 info) newmarked)
5045         ;; Add the marks lists to the end of the info.
5046         (when newmarked
5047           (setcdr (nthcdr 2 info) (list newmarked))))
5048
5049       ;; Cut off the end of the info if there's nothing else there.
5050       (let ((i 5))
5051         (while (and (> i 2)
5052                     (not (nth i info)))
5053           (when (nthcdr (decf i) info)
5054             (setcdr (nthcdr i info) nil)))))))
5055
5056 (defun gnus-set-mode-line (where)
5057   "Set the mode line of the article or summary buffers.
5058 If WHERE is `summary', the summary mode line format will be used."
5059   ;; Is this mode line one we keep updated?
5060   (when (and (memq where gnus-updated-mode-lines)
5061              (symbol-value
5062               (intern (format "gnus-%s-mode-line-format-spec" where))))
5063     (let (mode-string)
5064       (save-excursion
5065         ;; We evaluate this in the summary buffer since these
5066         ;; variables are buffer-local to that buffer.
5067         (set-buffer gnus-summary-buffer)
5068         ;; We bind all these variables that are used in the `eval' form
5069         ;; below.
5070         (let* ((mformat (symbol-value
5071                          (intern
5072                           (format "gnus-%s-mode-line-format-spec" where))))
5073                (gnus-tmp-group-name (gnus-group-decoded-name
5074                                      gnus-newsgroup-name))
5075                (gnus-tmp-article-number (or gnus-current-article 0))
5076                (gnus-tmp-unread gnus-newsgroup-unreads)
5077                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5078                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5079                (gnus-tmp-unread-and-unselected
5080                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5081                             (zerop gnus-tmp-unselected))
5082                        "")
5083                       ((zerop gnus-tmp-unselected)
5084                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5085                       (t (format "{%d(+%d) more}"
5086                                  gnus-tmp-unread-and-unticked
5087                                  gnus-tmp-unselected))))
5088                (gnus-tmp-subject
5089                 (if (and gnus-current-headers
5090                          (vectorp gnus-current-headers))
5091                     (gnus-mode-string-quote
5092                      (mail-header-subject gnus-current-headers))
5093                   ""))
5094                bufname-length max-len
5095                gnus-tmp-header);; passed as argument to any user-format-funcs
5096           (setq mode-string (eval mformat))
5097           (setq bufname-length (if (string-match "%b" mode-string)
5098                                    (- (length
5099                                        (buffer-name
5100                                         (if (eq where 'summary)
5101                                             nil
5102                                           (get-buffer gnus-article-buffer))))
5103                                       2)
5104                                  0))
5105           (setq max-len (max 4 (if gnus-mode-non-string-length
5106                                    (- (window-width)
5107                                       gnus-mode-non-string-length
5108                                       bufname-length)
5109                                  (length mode-string))))
5110           ;; We might have to chop a bit of the string off...
5111           (when (> (length mode-string) max-len)
5112             (setq mode-string
5113                   (concat (gnus-truncate-string mode-string (- max-len 3))
5114                           "...")))
5115           ;; Pad the mode string a bit.
5116           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5117       ;; Update the mode line.
5118       (setq mode-line-buffer-identification
5119             (gnus-mode-line-buffer-identification (list mode-string)))
5120       (set-buffer-modified-p t))))
5121
5122 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5123   "Go through the HEADERS list and add all Xrefs to a hash table.
5124 The resulting hash table is returned, or nil if no Xrefs were found."
5125   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5126          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5127          (xref-hashtb (gnus-make-hashtable))
5128          start group entry number xrefs header)
5129     (while headers
5130       (setq header (pop headers))
5131       (when (and (setq xrefs (mail-header-xref header))
5132                  (not (memq (setq number (mail-header-number header))
5133                             unreads)))
5134         (setq start 0)
5135         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5136           (setq start (match-end 0))
5137           (setq group (if prefix
5138                           (concat prefix (substring xrefs (match-beginning 1)
5139                                                     (match-end 1)))
5140                         (substring xrefs (match-beginning 1) (match-end 1))))
5141           (setq number
5142                 (string-to-int (substring xrefs (match-beginning 2)
5143                                           (match-end 2))))
5144           (if (setq entry (gnus-gethash group xref-hashtb))
5145               (setcdr entry (cons number (cdr entry)))
5146             (gnus-sethash group (cons number nil) xref-hashtb)))))
5147     (and start xref-hashtb)))
5148
5149 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5150   "Look through all the headers and mark the Xrefs as read."
5151   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5152         name entry info xref-hashtb idlist method nth4)
5153     (save-excursion
5154       (set-buffer gnus-group-buffer)
5155       (when (setq xref-hashtb
5156                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5157         (mapatoms
5158          (lambda (group)
5159            (unless (string= from-newsgroup (setq name (symbol-name group)))
5160              (setq idlist (symbol-value group))
5161              ;; Dead groups are not updated.
5162              (and (prog1
5163                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5164                             info (nth 2 entry))
5165                     (when (stringp (setq nth4 (gnus-info-method info)))
5166                       (setq nth4 (gnus-server-to-method nth4))))
5167                   ;; Only do the xrefs if the group has the same
5168                   ;; select method as the group we have just read.
5169                   (or (gnus-methods-equal-p
5170                        nth4 (gnus-find-method-for-group from-newsgroup))
5171                       virtual
5172                       (equal nth4 (setq method (gnus-find-method-for-group
5173                                                 from-newsgroup)))
5174                       (and (equal (car nth4) (car method))
5175                            (equal (nth 1 nth4) (nth 1 method))))
5176                   gnus-use-cross-reference
5177                   (or (not (eq gnus-use-cross-reference t))
5178                       virtual
5179                       ;; Only do cross-references on subscribed
5180                       ;; groups, if that is what is wanted.
5181                       (<= (gnus-info-level info) gnus-level-subscribed))
5182                   (gnus-group-make-articles-read name idlist))))
5183          xref-hashtb)))))
5184
5185 (defun gnus-compute-read-articles (group articles)
5186   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5187          (info (nth 2 entry))
5188          (active (gnus-active group))
5189          ninfo)
5190     (when entry
5191       ;; First peel off all invalid article numbers.
5192       (when active
5193         (let ((ids articles)
5194               id first)
5195           (while (setq id (pop ids))
5196             (when (and first (> id (cdr active)))
5197               ;; We'll end up in this situation in one particular
5198               ;; obscure situation.  If you re-scan a group and get
5199               ;; a new article that is cross-posted to a different
5200               ;; group that has not been re-scanned, you might get
5201               ;; crossposted article that has a higher number than
5202               ;; Gnus believes possible.  So we re-activate this
5203               ;; group as well.  This might mean doing the
5204               ;; crossposting thingy will *increase* the number
5205               ;; of articles in some groups.  Tsk, tsk.
5206               (setq active (or (gnus-activate-group group) active)))
5207             (when (or (> id (cdr active))
5208                       (< id (car active)))
5209               (setq articles (delq id articles))))))
5210       ;; If the read list is nil, we init it.
5211       (if (and active
5212                (null (gnus-info-read info))
5213                (> (car active) 1))
5214           (setq ninfo (cons 1 (1- (car active))))
5215         (setq ninfo (gnus-info-read info)))
5216       ;; Then we add the read articles to the range.
5217       (gnus-add-to-range
5218        ninfo (setq articles (sort articles '<))))))
5219
5220 (defun gnus-group-make-articles-read (group articles)
5221   "Update the info of GROUP to say that ARTICLES are read."
5222   (let* ((num 0)
5223          (entry (gnus-gethash group gnus-newsrc-hashtb))
5224          (info (nth 2 entry))
5225          (active (gnus-active group))
5226          range)
5227     (when entry
5228       (setq range (gnus-compute-read-articles group articles))
5229       (save-excursion
5230         (set-buffer gnus-group-buffer)
5231         (gnus-undo-register
5232           `(progn
5233              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5234              (gnus-info-set-read ',info ',(gnus-info-read info))
5235              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5236              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5237              (gnus-group-update-group ,group t))))
5238       ;; Add the read articles to the range.
5239       (gnus-info-set-read info range)
5240       (gnus-request-set-mark group (list (list range 'add '(read))))
5241       ;; Then we have to re-compute how many unread
5242       ;; articles there are in this group.
5243       (when active
5244         (cond
5245          ((not range)
5246           (setq num (- (1+ (cdr active)) (car active))))
5247          ((not (listp (cdr range)))
5248           (setq num (- (cdr active) (- (1+ (cdr range))
5249                                        (car range)))))
5250          (t
5251           (while range
5252             (if (numberp (car range))
5253                 (setq num (1+ num))
5254               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5255             (setq range (cdr range)))
5256           (setq num (- (cdr active) num))))
5257         ;; Update the number of unread articles.
5258         (setcar entry num)
5259         ;; Update the group buffer.
5260         (gnus-group-update-group group t)))))
5261
5262 (defvar gnus-newsgroup-none-id 0)
5263
5264 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5265   (let ((cur nntp-server-buffer)
5266         (dependencies
5267          (or dependencies
5268              (save-excursion (set-buffer gnus-summary-buffer)
5269                              gnus-newsgroup-dependencies)))
5270         headers id end ref
5271         (mail-parse-charset gnus-newsgroup-charset)
5272         (mail-parse-ignored-charsets
5273          (save-excursion (condition-case nil
5274                              (set-buffer gnus-summary-buffer)
5275                            (error))
5276                          gnus-newsgroup-ignored-charsets)))
5277     (save-excursion
5278       (set-buffer nntp-server-buffer)
5279       ;; Translate all TAB characters into SPACE characters.
5280       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5281       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5282       (gnus-run-hooks 'gnus-parse-headers-hook)
5283       (let ((case-fold-search t)
5284             in-reply-to header p lines chars ctype)
5285         (goto-char (point-min))
5286         ;; Search to the beginning of the next header.  Error messages
5287         ;; do not begin with 2 or 3.
5288         (while (re-search-forward "^[23][0-9]+ " nil t)
5289           (setq id nil
5290                 ref nil)
5291           ;; This implementation of this function, with nine
5292           ;; search-forwards instead of the one re-search-forward and
5293           ;; a case (which basically was the old function) is actually
5294           ;; about twice as fast, even though it looks messier.  You
5295           ;; can't have everything, I guess.  Speed and elegance
5296           ;; doesn't always go hand in hand.
5297           (setq
5298            header
5299            (make-full-mail-header
5300             ;; Number.
5301             (prog1
5302                 (read cur)
5303               (end-of-line)
5304               (setq p (point))
5305               (narrow-to-region (point)
5306                                 (or (and (search-forward "\n.\n" nil t)
5307                                          (- (point) 2))
5308                                     (point))))
5309             ;; Subject.
5310             (progn
5311               (goto-char p)
5312               (if (search-forward "\nsubject:" nil t)
5313                   (nnheader-header-value)
5314                 "(none)"))
5315             ;; From.
5316             (progn
5317               (goto-char p)
5318               (if (search-forward "\nfrom:" nil t)
5319                   (nnheader-header-value)
5320                 "(nobody)"))
5321             ;; Date.
5322             (progn
5323               (goto-char p)
5324               (if (search-forward "\ndate:" nil t)
5325                   (nnheader-header-value) ""))
5326             ;; Message-ID.
5327             (progn
5328               (goto-char p)
5329               (setq id (if (re-search-forward
5330                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5331                            ;; We do it this way to make sure the Message-ID
5332                            ;; is (somewhat) syntactically valid.
5333                            (buffer-substring (match-beginning 1)
5334                                              (match-end 1))
5335                          ;; If there was no message-id, we just fake one
5336                          ;; to make subsequent routines simpler.
5337                          (nnheader-generate-fake-message-id))))
5338             ;; References.
5339             (progn
5340               (goto-char p)
5341               (if (search-forward "\nreferences:" nil t)
5342                   (progn
5343                     (setq end (point))
5344                     (prog1
5345                         (nnheader-header-value)
5346                       (setq ref
5347                             (buffer-substring
5348                              (progn
5349                                ;; (end-of-line)
5350                                (search-backward ">" end t)
5351                                (1+ (point)))
5352                              (progn
5353                                (search-backward "<" end t)
5354                                (point))))))
5355                 ;; Get the references from the in-reply-to header if there
5356                 ;; were no references and the in-reply-to header looks
5357                 ;; promising.
5358                 (if (and (search-forward "\nin-reply-to:" nil t)
5359                          (setq in-reply-to (nnheader-header-value))
5360                          (string-match "<[^>]+>" in-reply-to))
5361                     (let (ref2)
5362                       (setq ref (substring in-reply-to (match-beginning 0)
5363                                            (match-end 0)))
5364                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5365                         (setq ref2 (substring in-reply-to (match-beginning 0)
5366                                               (match-end 0)))
5367                         (when (> (length ref2) (length ref))
5368                           (setq ref ref2)))
5369                       ref)
5370                   (setq ref nil))))
5371             ;; Chars.
5372             (progn
5373               (goto-char p)
5374               (if (search-forward "\nchars: " nil t)
5375                   (if (numberp (setq chars (ignore-errors (read cur))))
5376                       chars -1)
5377                 -1))
5378             ;; Lines.
5379             (progn
5380               (goto-char p)
5381               (if (search-forward "\nlines: " nil t)
5382                   (if (numberp (setq lines (ignore-errors (read cur))))
5383                       lines -1)
5384                 -1))
5385             ;; Xref.
5386             (progn
5387               (goto-char p)
5388               (and (search-forward "\nxref:" nil t)
5389                    (nnheader-header-value)))
5390             ;; Extra.
5391             (when gnus-extra-headers
5392               (let ((extra gnus-extra-headers)
5393                     out)
5394                 (while extra
5395                   (goto-char p)
5396                   (when (search-forward
5397                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5398                     (push (cons (car extra) (nnheader-header-value)) out))
5399                   (pop extra))
5400                 out))))
5401           (goto-char p)
5402           (if (and (search-forward "\ncontent-type: " nil t)
5403                    (setq ctype (nnheader-header-value)))
5404               (mime-entity-set-content-type-internal
5405                header (mime-parse-Content-Type ctype)))
5406           (when (equal id ref)
5407             (setq ref nil))
5408
5409           (when gnus-alter-header-function
5410             (funcall gnus-alter-header-function header)
5411             (setq id (mail-header-id header)
5412                   ref (gnus-parent-id (mail-header-references header))))
5413
5414           (when (setq header
5415                       (gnus-dependencies-add-header
5416                        header dependencies force-new))
5417             (push header headers))
5418           (goto-char (point-max))
5419           (widen))
5420         (nreverse headers)))))
5421
5422 ;; Goes through the xover lines and returns a list of vectors
5423 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5424                                                   force-new dependencies
5425                                                   group also-fetch-heads)
5426   "Parse the news overview data in the server buffer.
5427 Return a list of headers that match SEQUENCE (see
5428 `nntp-retrieve-headers')."
5429   ;; Get the Xref when the users reads the articles since most/some
5430   ;; NNTP servers do not include Xrefs when using XOVER.
5431   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5432   (let ((mail-parse-charset gnus-newsgroup-charset)
5433         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5434         (cur nntp-server-buffer)
5435         (dependencies (or dependencies gnus-newsgroup-dependencies))
5436         (allp (cond
5437                ((eq gnus-read-all-available-headers t)
5438                 t)
5439                ((stringp gnus-read-all-available-headers)
5440                 (string-match gnus-read-all-available-headers group))
5441                (t
5442                 nil)))
5443         number headers header)
5444     (save-excursion
5445       (set-buffer nntp-server-buffer)
5446       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5447       ;; Allow the user to mangle the headers before parsing them.
5448       (gnus-run-hooks 'gnus-parse-headers-hook)
5449       (goto-char (point-min))
5450       (while (not (eobp))
5451         (condition-case ()
5452             (while (and (or sequence allp)
5453                         (not (eobp)))
5454               (setq number (read cur))
5455               (when (not allp)
5456                 (while (and sequence
5457                             (< (car sequence) number))
5458                   (setq sequence (cdr sequence))))
5459               (when (and (or allp
5460                              (and sequence
5461                                   (eq number (car sequence))))
5462                          (progn
5463                            (setq sequence (cdr sequence))
5464                            (setq header (inline
5465                                           (gnus-nov-parse-line
5466                                            number dependencies force-new)))))
5467                 (push header headers))
5468               (forward-line 1))
5469           (error
5470            (gnus-error 4 "Strange nov line (%d)"
5471                        (count-lines (point-min) (point)))))
5472         (forward-line 1))
5473       ;; A common bug in inn is that if you have posted an article and
5474       ;; then retrieves the active file, it will answer correctly --
5475       ;; the new article is included.  However, a NOV entry for the
5476       ;; article may not have been generated yet, so this may fail.
5477       ;; We work around this problem by retrieving the last few
5478       ;; headers using HEAD.
5479       (if (or (not also-fetch-heads)
5480               (not sequence))
5481           ;; We (probably) got all the headers.
5482           (nreverse headers)
5483         (let ((gnus-nov-is-evil t))
5484           (nconc
5485            (nreverse headers)
5486            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5487              (gnus-get-newsgroup-headers))))))))
5488
5489 (defun gnus-article-get-xrefs ()
5490   "Fill in the Xref value in `gnus-current-headers', if necessary.
5491 This is meant to be called in `gnus-article-internal-prepare-hook'."
5492   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5493                                  gnus-current-headers)))
5494     (or (not gnus-use-cross-reference)
5495         (not headers)
5496         (and (mail-header-xref headers)
5497              (not (string= (mail-header-xref headers) "")))
5498         (let ((case-fold-search t)
5499               xref)
5500           (save-restriction
5501             (nnheader-narrow-to-headers)
5502             (goto-char (point-min))
5503             (when (or (and (not (eobp))
5504                            (eq (downcase (char-after)) ?x)
5505                            (looking-at "Xref:"))
5506                       (search-forward "\nXref:" nil t))
5507               (goto-char (1+ (match-end 0)))
5508               (setq xref (buffer-substring (point)
5509                                            (progn (end-of-line) (point))))
5510               (mail-header-set-xref headers xref)))))))
5511
5512 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5513   "Find article ID and insert the summary line for that article.
5514 OLD-HEADER can either be a header or a line number to insert
5515 the subject line on."
5516   (let* ((line (and (numberp old-header) old-header))
5517          (old-header (and (vectorp old-header) old-header))
5518          (header (cond ((and old-header use-old-header)
5519                         old-header)
5520                        ((and (numberp id)
5521                              (gnus-number-to-header id))
5522                         (gnus-number-to-header id))
5523                        (t
5524                         (gnus-read-header id))))
5525          (number (and (numberp id) id))
5526          d)
5527     (when header
5528       ;; Rebuild the thread that this article is part of and go to the
5529       ;; article we have fetched.
5530       (when (and (not gnus-show-threads)
5531                  old-header)
5532         (when (and number
5533                    (setq d (gnus-data-find (mail-header-number old-header))))
5534           (goto-char (gnus-data-pos d))
5535           (gnus-data-remove
5536            number
5537            (- (gnus-point-at-bol)
5538               (prog1
5539                   (1+ (gnus-point-at-eol))
5540                 (gnus-delete-line))))))
5541       (when old-header
5542         (mail-header-set-number header (mail-header-number old-header)))
5543       (setq gnus-newsgroup-sparse
5544             (delq (setq number (mail-header-number header))
5545                   gnus-newsgroup-sparse))
5546       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5547       (push number gnus-newsgroup-limit)
5548       (gnus-rebuild-thread (mail-header-id header) line)
5549       (gnus-summary-goto-subject number nil t))
5550     (when (and (numberp number)
5551                (> number 0))
5552       ;; We have to update the boundaries even if we can't fetch the
5553       ;; article if ID is a number -- so that the next `P' or `N'
5554       ;; command will fetch the previous (or next) article even
5555       ;; if the one we tried to fetch this time has been canceled.
5556       (when (> number gnus-newsgroup-end)
5557         (setq gnus-newsgroup-end number))
5558       (when (< number gnus-newsgroup-begin)
5559         (setq gnus-newsgroup-begin number))
5560       (setq gnus-newsgroup-unselected
5561             (delq number gnus-newsgroup-unselected)))
5562     ;; Report back a success?
5563     (and header (mail-header-number header))))
5564
5565 ;;; Process/prefix in the summary buffer
5566
5567 (defun gnus-summary-work-articles (n)
5568   "Return a list of articles to be worked upon.
5569 The prefix argument, the list of process marked articles, and the
5570 current article will be taken into consideration."
5571   (save-excursion
5572     (set-buffer gnus-summary-buffer)
5573     (cond
5574      (n
5575       ;; A numerical prefix has been given.
5576       (setq n (prefix-numeric-value n))
5577       (let ((backward (< n 0))
5578             (n (abs (prefix-numeric-value n)))
5579             articles article)
5580         (save-excursion
5581           (while
5582               (and (> n 0)
5583                    (push (setq article (gnus-summary-article-number))
5584                          articles)
5585                    (if backward
5586                        (gnus-summary-find-prev nil article)
5587                      (gnus-summary-find-next nil article)))
5588             (decf n)))
5589         (nreverse articles)))
5590      ((and (gnus-region-active-p) (mark))
5591       (message "region active")
5592       ;; Work on the region between point and mark.
5593       (let ((max (max (point) (mark)))
5594             articles article)
5595         (save-excursion
5596           (goto-char (min (point) (mark)))
5597           (while
5598               (and
5599                (push (setq article (gnus-summary-article-number)) articles)
5600                (gnus-summary-find-next nil article)
5601                (< (point) max)))
5602           (nreverse articles))))
5603      (gnus-newsgroup-processable
5604       ;; There are process-marked articles present.
5605       ;; Save current state.
5606       (gnus-summary-save-process-mark)
5607       ;; Return the list.
5608       (reverse gnus-newsgroup-processable))
5609      (t
5610       ;; Just return the current article.
5611       (list (gnus-summary-article-number))))))
5612
5613 (defmacro gnus-summary-iterate (arg &rest forms)
5614   "Iterate over the process/prefixed articles and do FORMS.
5615 ARG is the interactive prefix given to the command.  FORMS will be
5616 executed with point over the summary line of the articles."
5617   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5618     `(let ((,articles (gnus-summary-work-articles ,arg)))
5619        (while ,articles
5620          (gnus-summary-goto-subject (car ,articles))
5621          ,@forms
5622          (pop ,articles)))))
5623
5624 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5625 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5626
5627 (defun gnus-summary-save-process-mark ()
5628   "Push the current set of process marked articles on the stack."
5629   (interactive)
5630   (push (copy-sequence gnus-newsgroup-processable)
5631         gnus-newsgroup-process-stack))
5632
5633 (defun gnus-summary-kill-process-mark ()
5634   "Push the current set of process marked articles on the stack and unmark."
5635   (interactive)
5636   (gnus-summary-save-process-mark)
5637   (gnus-summary-unmark-all-processable))
5638
5639 (defun gnus-summary-yank-process-mark ()
5640   "Pop the last process mark state off the stack and restore it."
5641   (interactive)
5642   (unless gnus-newsgroup-process-stack
5643     (error "Empty mark stack"))
5644   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5645
5646 (defun gnus-summary-process-mark-set (set)
5647   "Make SET into the current process marked articles."
5648   (gnus-summary-unmark-all-processable)
5649   (while set
5650     (gnus-summary-set-process-mark (pop set))))
5651
5652 ;;; Searching and stuff
5653
5654 (defun gnus-summary-search-group (&optional backward use-level)
5655   "Search for next unread newsgroup.
5656 If optional argument BACKWARD is non-nil, search backward instead."
5657   (save-excursion
5658     (set-buffer gnus-group-buffer)
5659     (when (gnus-group-search-forward
5660            backward nil (if use-level (gnus-group-group-level) nil))
5661       (gnus-group-group-name))))
5662
5663 (defun gnus-summary-best-group (&optional exclude-group)
5664   "Find the name of the best unread group.
5665 If EXCLUDE-GROUP, do not go to this group."
5666   (save-excursion
5667     (set-buffer gnus-group-buffer)
5668     (save-excursion
5669       (gnus-group-best-unread-group exclude-group))))
5670
5671 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5672   (if backward (gnus-summary-find-prev)
5673     (let* ((dummy (gnus-summary-article-intangible-p))
5674            (article (or article (gnus-summary-article-number)))
5675            (arts (gnus-data-find-list article))
5676            result)
5677       (when (and (not dummy)
5678                  (or (not gnus-summary-check-current)
5679                      (not unread)
5680                      (not (gnus-data-unread-p (car arts)))))
5681         (setq arts (cdr arts)))
5682       (when (setq result
5683                   (if unread
5684                       (progn
5685                         (while arts
5686                           (when (or (and undownloaded
5687                                          (eq gnus-undownloaded-mark
5688                                              (gnus-data-mark (car arts))))
5689                                     (gnus-data-unread-p (car arts)))
5690                             (setq result (car arts)
5691                                   arts nil))
5692                           (setq arts (cdr arts)))
5693                         result)
5694                     (car arts)))
5695         (goto-char (gnus-data-pos result))
5696         (gnus-data-number result)))))
5697
5698 (defun gnus-summary-find-prev (&optional unread article)
5699   (let* ((eobp (eobp))
5700          (article (or article (gnus-summary-article-number)))
5701          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5702          result)
5703     (when (and (not eobp)
5704                (or (not gnus-summary-check-current)
5705                    (not unread)
5706                    (not (gnus-data-unread-p (car arts)))))
5707       (setq arts (cdr arts)))
5708     (when (setq result
5709                 (if unread
5710                     (progn
5711                       (while arts
5712                         (when (gnus-data-unread-p (car arts))
5713                           (setq result (car arts)
5714                                 arts nil))
5715                         (setq arts (cdr arts)))
5716                       result)
5717                   (car arts)))
5718       (goto-char (gnus-data-pos result))
5719       (gnus-data-number result))))
5720
5721 (defun gnus-summary-find-subject (subject &optional unread backward article)
5722   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5723          (article (or article (gnus-summary-article-number)))
5724          (articles (gnus-data-list backward))
5725          (arts (gnus-data-find-list article articles))
5726          result)
5727     (when (or (not gnus-summary-check-current)
5728               (not unread)
5729               (not (gnus-data-unread-p (car arts))))
5730       (setq arts (cdr arts)))
5731     (while arts
5732       (and (or (not unread)
5733                (gnus-data-unread-p (car arts)))
5734            (vectorp (gnus-data-header (car arts)))
5735            (gnus-subject-equal
5736             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5737            (setq result (car arts)
5738                  arts nil))
5739       (setq arts (cdr arts)))
5740     (and result
5741          (goto-char (gnus-data-pos result))
5742          (gnus-data-number result))))
5743
5744 (defun gnus-summary-search-forward (&optional unread subject backward)
5745   "Search forward for an article.
5746 If UNREAD, look for unread articles.  If SUBJECT, look for
5747 articles with that subject.  If BACKWARD, search backward instead."
5748   (cond (subject (gnus-summary-find-subject subject unread backward))
5749         (backward (gnus-summary-find-prev unread))
5750         (t (gnus-summary-find-next unread))))
5751
5752 (defun gnus-recenter (&optional n)
5753   "Center point in window and redisplay frame.
5754 Also do horizontal recentering."
5755   (interactive "P")
5756   (when (and gnus-auto-center-summary
5757              (not (eq gnus-auto-center-summary 'vertical)))
5758     (gnus-horizontal-recenter))
5759   (recenter n))
5760
5761 (defun gnus-summary-recenter ()
5762   "Center point in the summary window.
5763 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5764 displayed, no centering will be performed."
5765   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5766   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5767   (interactive)
5768   (let* ((top (cond ((< (window-height) 4) 0)
5769                     ((< (window-height) 7) 1)
5770                     (t (if (numberp gnus-auto-center-summary)
5771                            gnus-auto-center-summary
5772                          2))))
5773          (height (1- (window-height)))
5774          (bottom (save-excursion (goto-char (point-max))
5775                                  (forward-line (- height))
5776                                  (point)))
5777          (window (get-buffer-window (current-buffer))))
5778     ;; The user has to want it.
5779     (when gnus-auto-center-summary
5780       (when (get-buffer-window gnus-article-buffer)
5781         ;; Only do recentering when the article buffer is displayed,
5782         ;; Set the window start to either `bottom', which is the biggest
5783         ;; possible valid number, or the second line from the top,
5784         ;; whichever is the least.
5785         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5786           (if (> bottom top-pos)
5787               ;; Keep the second line from the top visible
5788               (set-window-start window top-pos t)
5789             ;; Try to keep the bottom line visible; if it's partially
5790             ;; obscured, either scroll one more line to make it fully
5791             ;; visible, or revert to using TOP-POS.
5792             (save-excursion
5793               (goto-char (point-max))
5794               (forward-line -1)
5795               (let ((last-line-start (point)))
5796                 (goto-char bottom)
5797                 (set-window-start window (point) t)
5798                 (when (not (pos-visible-in-window-p last-line-start window))
5799                   (forward-line 1)
5800                   (set-window-start window (min (point) top-pos) t)))))))
5801       ;; Do horizontal recentering while we're at it.
5802       (when (and (get-buffer-window (current-buffer) t)
5803                  (not (eq gnus-auto-center-summary 'vertical)))
5804         (let ((selected (selected-window)))
5805           (select-window (get-buffer-window (current-buffer) t))
5806           (gnus-summary-position-point)
5807           (gnus-horizontal-recenter)
5808           (select-window selected))))))
5809
5810 (defun gnus-summary-jump-to-group (newsgroup)
5811   "Move point to NEWSGROUP in group mode buffer."
5812   ;; Keep update point of group mode buffer if visible.
5813   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5814       (save-window-excursion
5815         ;; Take care of tree window mode.
5816         (when (get-buffer-window gnus-group-buffer)
5817           (pop-to-buffer gnus-group-buffer))
5818         (gnus-group-jump-to-group newsgroup))
5819     (save-excursion
5820       ;; Take care of tree window mode.
5821       (if (get-buffer-window gnus-group-buffer)
5822           (pop-to-buffer gnus-group-buffer)
5823         (set-buffer gnus-group-buffer))
5824       (gnus-group-jump-to-group newsgroup))))
5825
5826 ;; This function returns a list of article numbers based on the
5827 ;; difference between the ranges of read articles in this group and
5828 ;; the range of active articles.
5829 (defun gnus-list-of-unread-articles (group)
5830   (let* ((read (gnus-info-read (gnus-get-info group)))
5831          (active (or (gnus-active group) (gnus-activate-group group)))
5832          (last (cdr active))
5833          first nlast unread)
5834     ;; If none are read, then all are unread.
5835     (if (not read)
5836         (setq first (car active))
5837       ;; If the range of read articles is a single range, then the
5838       ;; first unread article is the article after the last read
5839       ;; article.  Sounds logical, doesn't it?
5840       (if (and (not (listp (cdr read)))
5841                (or (< (car read) (car active))
5842                    (progn (setq read (list read))
5843                           nil)))
5844           (setq first (max (car active) (1+ (cdr read))))
5845         ;; `read' is a list of ranges.
5846         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5847                                   (caar read)))
5848                   1)
5849           (setq first (car active)))
5850         (while read
5851           (when first
5852             (while (< first nlast)
5853               (push first unread)
5854               (setq first (1+ first))))
5855           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5856           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5857           (setq read (cdr read)))))
5858     ;; And add the last unread articles.
5859     (while (<= first last)
5860       (push first unread)
5861       (setq first (1+ first)))
5862     ;; Return the list of unread articles.
5863     (delq 0 (nreverse unread))))
5864
5865 (defun gnus-list-of-read-articles (group)
5866   "Return a list of unread, unticked and non-dormant articles."
5867   (let* ((info (gnus-get-info group))
5868          (marked (gnus-info-marks info))
5869          (active (gnus-active group)))
5870     (and info active
5871          (gnus-set-difference
5872           (gnus-sorted-complement
5873            (gnus-uncompress-range active)
5874            (gnus-list-of-unread-articles group))
5875           (append
5876            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5877            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5878
5879 ;; Various summary commands
5880
5881 (defun gnus-summary-select-article-buffer ()
5882   "Reconfigure windows to show article buffer."
5883   (interactive)
5884   (if (not (gnus-buffer-live-p gnus-article-buffer))
5885       (error "There is no article buffer for this summary buffer")
5886     (gnus-configure-windows 'article)
5887     (select-window (get-buffer-window gnus-article-buffer))))
5888
5889 (defun gnus-summary-universal-argument (arg)
5890   "Perform any operation on all articles that are process/prefixed."
5891   (interactive "P")
5892   (let ((articles (gnus-summary-work-articles arg))
5893         func article)
5894     (if (eq
5895          (setq
5896           func
5897           (key-binding
5898            (read-key-sequence
5899             (substitute-command-keys
5900              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5901          'undefined)
5902         (gnus-error 1 "Undefined key")
5903       (save-excursion
5904         (while articles
5905           (gnus-summary-goto-subject (setq article (pop articles)))
5906           (let (gnus-newsgroup-processable)
5907             (command-execute func))
5908           (gnus-summary-remove-process-mark article)))))
5909   (gnus-summary-position-point))
5910
5911 (defun gnus-summary-toggle-truncation (&optional arg)
5912   "Toggle truncation of summary lines.
5913 With arg, turn line truncation on iff arg is positive."
5914   (interactive "P")
5915   (setq truncate-lines
5916         (if (null arg) (not truncate-lines)
5917           (> (prefix-numeric-value arg) 0)))
5918   (redraw-display))
5919
5920 (defun gnus-summary-reselect-current-group (&optional all rescan)
5921   "Exit and then reselect the current newsgroup.
5922 The prefix argument ALL means to select all articles."
5923   (interactive "P")
5924   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5925     (error "Ephemeral groups can't be reselected"))
5926   (let ((current-subject (gnus-summary-article-number))
5927         (group gnus-newsgroup-name))
5928     (setq gnus-newsgroup-begin nil)
5929     (gnus-summary-exit)
5930     ;; We have to adjust the point of group mode buffer because
5931     ;; point was moved to the next unread newsgroup by exiting.
5932     (gnus-summary-jump-to-group group)
5933     (when rescan
5934       (save-excursion
5935         (save-window-excursion
5936           ;; Don't show group contents.
5937           (set-window-start (selected-window) (point-max))
5938           (gnus-group-get-new-news-this-group 1))))
5939     (gnus-group-read-group all t)
5940     (gnus-summary-goto-subject current-subject nil t)))
5941
5942 (defun gnus-summary-rescan-group (&optional all)
5943   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5944   (interactive "P")
5945   (gnus-summary-reselect-current-group all t))
5946
5947 (defun gnus-summary-update-info (&optional non-destructive)
5948   (save-excursion
5949     (let ((group gnus-newsgroup-name))
5950       (when group
5951         (when gnus-newsgroup-kill-headers
5952           (setq gnus-newsgroup-killed
5953                 (gnus-compress-sequence
5954                  (nconc
5955                   (gnus-set-sorted-intersection
5956                    (gnus-uncompress-range gnus-newsgroup-killed)
5957                    (setq gnus-newsgroup-unselected
5958                          (sort gnus-newsgroup-unselected '<)))
5959                   (setq gnus-newsgroup-unreads
5960                         (sort gnus-newsgroup-unreads '<)))
5961                  t)))
5962         (unless (listp (cdr gnus-newsgroup-killed))
5963           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5964         (let ((headers gnus-newsgroup-headers))
5965           ;; Set the new ranges of read articles.
5966           (save-excursion
5967             (set-buffer gnus-group-buffer)
5968             (gnus-undo-force-boundary))
5969           (gnus-update-read-articles
5970            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5971           ;; Set the current article marks.
5972           (let ((gnus-newsgroup-scored
5973                  (if (and (not gnus-save-score)
5974                           (not non-destructive))
5975                      nil
5976                    gnus-newsgroup-scored)))
5977             (save-excursion
5978               (gnus-update-marks)))
5979           ;; Do the cross-ref thing.
5980           (when gnus-use-cross-reference
5981             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5982           ;; Do not switch windows but change the buffer to work.
5983           (set-buffer gnus-group-buffer)
5984           (unless (gnus-ephemeral-group-p group)
5985             (gnus-group-update-group group)))))))
5986
5987 (defun gnus-summary-save-newsrc (&optional force)
5988   "Save the current number of read/marked articles in the dribble buffer.
5989 The dribble buffer will then be saved.
5990 If FORCE (the prefix), also save the .newsrc file(s)."
5991   (interactive "P")
5992   (gnus-summary-update-info t)
5993   (if force
5994       (gnus-save-newsrc-file)
5995     (gnus-dribble-save)))
5996
5997 (defun gnus-summary-exit (&optional temporary)
5998   "Exit reading current newsgroup, and then return to group selection mode.
5999 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6000   (interactive)
6001   (gnus-set-global-variables)
6002   (gnus-kill-save-kill-buffer)
6003   (gnus-async-halt-prefetch)
6004   (let* ((group gnus-newsgroup-name)
6005          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6006          (mode major-mode)
6007          (group-point nil)
6008          (buf (current-buffer)))
6009     (unless quit-config
6010       ;; Do adaptive scoring, and possibly save score files.
6011       (when gnus-newsgroup-adaptive
6012         (gnus-score-adaptive))
6013       (when gnus-use-scoring
6014         (gnus-score-save)))
6015     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6016     ;; If we have several article buffers, we kill them at exit.
6017     (unless gnus-single-article-buffer
6018       (gnus-kill-buffer gnus-original-article-buffer)
6019       (setq gnus-article-current nil))
6020     (when gnus-use-cache
6021       (gnus-cache-possibly-remove-articles)
6022       (gnus-cache-save-buffers))
6023     (gnus-async-prefetch-remove-group group)
6024     (when gnus-suppress-duplicates
6025       (gnus-dup-enter-articles))
6026     (when gnus-use-trees
6027       (gnus-tree-close group))
6028     (when gnus-use-cache
6029       (gnus-cache-write-active))
6030     ;; Remove entries for this group.
6031     (nnmail-purge-split-history (gnus-group-real-name group))
6032     ;; Make all changes in this group permanent.
6033     (unless quit-config
6034       (gnus-run-hooks 'gnus-exit-group-hook)
6035       (gnus-summary-update-info))
6036     (gnus-close-group group)
6037     ;; Make sure where we were, and go to next newsgroup.
6038     (set-buffer gnus-group-buffer)
6039     (unless quit-config
6040       (gnus-group-jump-to-group group))
6041     (gnus-run-hooks 'gnus-summary-exit-hook)
6042     (unless (or quit-config
6043                 ;; If this group has disappeared from the summary
6044                 ;; buffer, don't skip forwards.
6045                 (not (string= group (gnus-group-group-name))))
6046       (gnus-group-next-unread-group 1))
6047     (setq group-point (point))
6048     (if temporary
6049         nil                             ;Nothing to do.
6050       ;; If we have several article buffers, we kill them at exit.
6051       (unless gnus-single-article-buffer
6052         (gnus-kill-buffer gnus-article-buffer)
6053         (gnus-kill-buffer gnus-original-article-buffer)
6054         (setq gnus-article-current nil))
6055       (set-buffer buf)
6056       (if (not gnus-kill-summary-on-exit)
6057           (progn
6058             (gnus-deaden-summary)
6059             (setq mode nil))
6060         ;; We set all buffer-local variables to nil.  It is unclear why
6061         ;; this is needed, but if we don't, buffer-local variables are
6062         ;; not garbage-collected, it seems.  This would the lead to en
6063         ;; ever-growing Emacs.
6064         (gnus-summary-clear-local-variables)
6065         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6066           (gnus-summary-clear-local-variables))
6067         (when (get-buffer gnus-article-buffer)
6068           (bury-buffer gnus-article-buffer))
6069         ;; We clear the global counterparts of the buffer-local
6070         ;; variables as well, just to be on the safe side.
6071         (set-buffer gnus-group-buffer)
6072         (gnus-summary-clear-local-variables)
6073         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6074           (gnus-summary-clear-local-variables)))
6075       (setq gnus-current-select-method gnus-select-method)
6076       (pop-to-buffer gnus-group-buffer)
6077       (if (not quit-config)
6078           (progn
6079             (goto-char group-point)
6080             (gnus-configure-windows 'group 'force)
6081             (unless (pos-visible-in-window-p)
6082               (forward-line (/ (static-if (featurep 'xemacs)
6083                                    (window-displayed-height)
6084                                  (1- (window-height)))
6085                                -2))
6086               (set-window-start (selected-window) (point))
6087               (goto-char group-point)))
6088         (gnus-handle-ephemeral-exit quit-config))
6089       ;; Return to group mode buffer.
6090       (when (eq mode 'gnus-summary-mode)
6091         (gnus-kill-buffer buf))
6092       ;; Clear the current group name.
6093       (unless quit-config
6094         (setq gnus-newsgroup-name nil)))))
6095
6096 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6097 (defun gnus-summary-exit-no-update (&optional no-questions)
6098   "Quit reading current newsgroup without updating read article info."
6099   (interactive)
6100   (let* ((group gnus-newsgroup-name)
6101          (quit-config (gnus-group-quit-config group)))
6102     (when (or no-questions
6103               gnus-expert-user
6104               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6105       (gnus-async-halt-prefetch)
6106       (mapcar 'funcall
6107               (delq 'gnus-summary-expire-articles
6108                     (copy-sequence gnus-summary-prepare-exit-hook)))
6109       ;; If we have several article buffers, we kill them at exit.
6110       (unless gnus-single-article-buffer
6111         (gnus-kill-buffer gnus-article-buffer)
6112         (gnus-kill-buffer gnus-original-article-buffer)
6113         (setq gnus-article-current nil))
6114       (if (not gnus-kill-summary-on-exit)
6115           (gnus-deaden-summary)
6116         (gnus-close-group group)
6117         (gnus-summary-clear-local-variables)
6118         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6119           (gnus-summary-clear-local-variables))
6120         (set-buffer gnus-group-buffer)
6121         (gnus-summary-clear-local-variables)
6122         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6123           (gnus-summary-clear-local-variables))
6124         (when (get-buffer gnus-summary-buffer)
6125           (kill-buffer gnus-summary-buffer)))
6126       (unless gnus-single-article-buffer
6127         (setq gnus-article-current nil))
6128       (when gnus-use-trees
6129         (gnus-tree-close group))
6130       (gnus-async-prefetch-remove-group group)
6131       (when (get-buffer gnus-article-buffer)
6132         (bury-buffer gnus-article-buffer))
6133       ;; Return to the group buffer.
6134       (gnus-configure-windows 'group 'force)
6135       ;; Clear the current group name.
6136       (setq gnus-newsgroup-name nil)
6137       (when (equal (gnus-group-group-name) group)
6138         (gnus-group-next-unread-group 1))
6139       (when quit-config
6140         (gnus-handle-ephemeral-exit quit-config)))))
6141
6142 (defun gnus-handle-ephemeral-exit (quit-config)
6143   "Handle movement when leaving an ephemeral group.
6144 The state which existed when entering the ephemeral is reset."
6145   (if (not (buffer-name (car quit-config)))
6146       (gnus-configure-windows 'group 'force)
6147     (set-buffer (car quit-config))
6148     (cond ((eq major-mode 'gnus-summary-mode)
6149            (gnus-set-global-variables))
6150           ((eq major-mode 'gnus-article-mode)
6151            (save-excursion
6152              ;; The `gnus-summary-buffer' variable may point
6153              ;; to the old summary buffer when using a single
6154              ;; article buffer.
6155              (unless (gnus-buffer-live-p gnus-summary-buffer)
6156                (set-buffer gnus-group-buffer))
6157              (set-buffer gnus-summary-buffer)
6158              (gnus-set-global-variables))))
6159     (if (or (eq (cdr quit-config) 'article)
6160             (eq (cdr quit-config) 'pick))
6161         (progn
6162           ;; The current article may be from the ephemeral group
6163           ;; thus it is best that we reload this article
6164           (gnus-summary-show-article)
6165           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6166               (gnus-configure-windows 'pick 'force)
6167             (gnus-configure-windows (cdr quit-config) 'force)))
6168       (gnus-configure-windows (cdr quit-config) 'force))
6169     (when (eq major-mode 'gnus-summary-mode)
6170       (gnus-summary-next-subject 1 nil t)
6171       (gnus-summary-recenter)
6172       (gnus-summary-position-point))))
6173
6174 (defun gnus-summary-preview-mime-message ()
6175   "MIME decode and play this message."
6176   (interactive)
6177   (let ((gnus-break-pages nil)
6178         (gnus-show-mime t))
6179     (gnus-summary-select-article gnus-show-all-headers t))
6180   (select-window (get-buffer-window gnus-article-buffer)))
6181
6182 ;;; Dead summaries.
6183
6184 (defvar gnus-dead-summary-mode-map nil)
6185
6186 (unless gnus-dead-summary-mode-map
6187   (setq gnus-dead-summary-mode-map (make-keymap))
6188   (suppress-keymap gnus-dead-summary-mode-map)
6189   (substitute-key-definition
6190    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6191   (let ((keys '("\C-d" "\r" "\177" [delete])))
6192     (while keys
6193       (define-key gnus-dead-summary-mode-map
6194         (pop keys) 'gnus-summary-wake-up-the-dead))))
6195
6196 (defvar gnus-dead-summary-mode nil
6197   "Minor mode for Gnus summary buffers.")
6198
6199 (defun gnus-dead-summary-mode (&optional arg)
6200   "Minor mode for Gnus summary buffers."
6201   (interactive "P")
6202   (when (eq major-mode 'gnus-summary-mode)
6203     (make-local-variable 'gnus-dead-summary-mode)
6204     (setq gnus-dead-summary-mode
6205           (if (null arg) (not gnus-dead-summary-mode)
6206             (> (prefix-numeric-value arg) 0)))
6207     (when gnus-dead-summary-mode
6208       (gnus-add-minor-mode
6209        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6210
6211 (defun gnus-deaden-summary ()
6212   "Make the current summary buffer into a dead summary buffer."
6213   ;; Kill any previous dead summary buffer.
6214   (when (and gnus-dead-summary
6215              (buffer-name gnus-dead-summary))
6216     (save-excursion
6217       (set-buffer gnus-dead-summary)
6218       (when gnus-dead-summary-mode
6219         (kill-buffer (current-buffer)))))
6220   ;; Make this the current dead summary.
6221   (setq gnus-dead-summary (current-buffer))
6222   (gnus-dead-summary-mode 1)
6223   (let ((name (buffer-name)))
6224     (when (string-match "Summary" name)
6225       (rename-buffer
6226        (concat (substring name 0 (match-beginning 0)) "Dead "
6227                (substring name (match-beginning 0)))
6228        t)
6229       (bury-buffer))))
6230
6231 (defun gnus-kill-or-deaden-summary (buffer)
6232   "Kill or deaden the summary BUFFER."
6233   (save-excursion
6234     (when (and (buffer-name buffer)
6235                (not gnus-single-article-buffer))
6236       (save-excursion
6237         (set-buffer buffer)
6238         (gnus-kill-buffer gnus-article-buffer)
6239         (gnus-kill-buffer gnus-original-article-buffer)))
6240     (cond (gnus-kill-summary-on-exit
6241            (when (and gnus-use-trees
6242                       (gnus-buffer-exists-p buffer))
6243              (save-excursion
6244                (set-buffer buffer)
6245                (gnus-tree-close gnus-newsgroup-name)))
6246            (gnus-kill-buffer buffer))
6247           ((gnus-buffer-exists-p buffer)
6248            (save-excursion
6249              (set-buffer buffer)
6250              (gnus-deaden-summary))))))
6251
6252 (defun gnus-summary-wake-up-the-dead (&rest args)
6253   "Wake up the dead summary buffer."
6254   (interactive)
6255   (gnus-dead-summary-mode -1)
6256   (let ((name (buffer-name)))
6257     (when (string-match "Dead " name)
6258       (rename-buffer
6259        (concat (substring name 0 (match-beginning 0))
6260                (substring name (match-end 0)))
6261        t)))
6262   (gnus-message 3 "This dead summary is now alive again"))
6263
6264 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6265 (defun gnus-summary-fetch-faq (&optional faq-dir)
6266   "Fetch the FAQ for the current group.
6267 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6268 in."
6269   (interactive
6270    (list
6271     (when current-prefix-arg
6272       (completing-read
6273        "Faq dir: " (and (listp gnus-group-faq-directory)
6274                         (mapcar (lambda (file) (list file))
6275                                 gnus-group-faq-directory))))))
6276   (let (gnus-faq-buffer)
6277     (when (setq gnus-faq-buffer
6278                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6279       (gnus-configure-windows 'summary-faq))))
6280
6281 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6282 (defun gnus-summary-describe-group (&optional force)
6283   "Describe the current newsgroup."
6284   (interactive "P")
6285   (gnus-group-describe-group force gnus-newsgroup-name))
6286
6287 (defun gnus-summary-describe-briefly ()
6288   "Describe summary mode commands briefly."
6289   (interactive)
6290   (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")))
6291
6292 ;; Walking around group mode buffer from summary mode.
6293
6294 (defun gnus-summary-next-group (&optional no-article target-group backward)
6295   "Exit current newsgroup and then select next unread newsgroup.
6296 If prefix argument NO-ARTICLE is non-nil, no article is selected
6297 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6298 previous group instead."
6299   (interactive "P")
6300   ;; Stop pre-fetching.
6301   (gnus-async-halt-prefetch)
6302   (let ((current-group gnus-newsgroup-name)
6303         (current-buffer (current-buffer))
6304         entered)
6305     ;; First we semi-exit this group to update Xrefs and all variables.
6306     ;; We can't do a real exit, because the window conf must remain
6307     ;; the same in case the user is prompted for info, and we don't
6308     ;; want the window conf to change before that...
6309     (gnus-summary-exit t)
6310     (while (not entered)
6311       ;; Then we find what group we are supposed to enter.
6312       (set-buffer gnus-group-buffer)
6313       (gnus-group-jump-to-group current-group)
6314       (setq target-group
6315             (or target-group
6316                 (if (eq gnus-keep-same-level 'best)
6317                     (gnus-summary-best-group gnus-newsgroup-name)
6318                   (gnus-summary-search-group backward gnus-keep-same-level))))
6319       (if (not target-group)
6320           ;; There are no further groups, so we return to the group
6321           ;; buffer.
6322           (progn
6323             (gnus-message 5 "Returning to the group buffer")
6324             (setq entered t)
6325             (when (gnus-buffer-live-p current-buffer)
6326               (set-buffer current-buffer)
6327               (gnus-summary-exit))
6328             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6329         ;; We try to enter the target group.
6330         (gnus-group-jump-to-group target-group)
6331         (let ((unreads (gnus-group-group-unread)))
6332           (if (and (or (eq t unreads)
6333                        (and unreads (not (zerop unreads))))
6334                    (gnus-summary-read-group
6335                     target-group nil no-article
6336                     (and (buffer-name current-buffer) current-buffer)
6337                     nil backward))
6338               (setq entered t)
6339             (setq current-group target-group
6340                   target-group nil)))))))
6341
6342 (defun gnus-summary-prev-group (&optional no-article)
6343   "Exit current newsgroup and then select previous unread newsgroup.
6344 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6345   (interactive "P")
6346   (gnus-summary-next-group no-article nil t))
6347
6348 ;; Walking around summary lines.
6349
6350 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6351   "Go to the first unread subject.
6352 If UNREAD is non-nil, go to the first unread article.
6353 Returns the article selected or nil if there are no unread articles."
6354   (interactive "P")
6355   (prog1
6356       (cond
6357        ;; Empty summary.
6358        ((null gnus-newsgroup-data)
6359         (gnus-message 3 "No articles in the group")
6360         nil)
6361        ;; Pick the first article.
6362        ((not unread)
6363         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6364         (gnus-data-number (car gnus-newsgroup-data)))
6365        ;; No unread articles.
6366        ((null gnus-newsgroup-unreads)
6367         (gnus-message 3 "No more unread articles")
6368         nil)
6369        ;; Find the first unread article.
6370        (t
6371         (let ((data gnus-newsgroup-data))
6372           (while (and data
6373                       (and (not (and undownloaded
6374                                      (eq gnus-undownloaded-mark
6375                                          (gnus-data-mark (car data)))))
6376                            (not (and unseen
6377                                      (memq (car data) gnus-newsgroup-unseen)))
6378                            (not (gnus-data-unread-p (car data)))))
6379             (setq data (cdr data)))
6380           (when data
6381             (goto-char (gnus-data-pos (car data)))
6382             (gnus-data-number (car data))))))
6383     (gnus-summary-position-point)))
6384
6385 (defun gnus-summary-next-subject (n &optional unread dont-display)
6386   "Go to next N'th summary line.
6387 If N is negative, go to the previous N'th subject line.
6388 If UNREAD is non-nil, only unread articles are selected.
6389 The difference between N and the actual number of steps taken is
6390 returned."
6391   (interactive "p")
6392   (let ((backward (< n 0))
6393         (n (abs n)))
6394     (while (and (> n 0)
6395                 (if backward
6396                     (gnus-summary-find-prev unread)
6397                   (gnus-summary-find-next unread)))
6398       (unless (zerop (setq n (1- n)))
6399         (gnus-summary-show-thread)))
6400     (when (/= 0 n)
6401       (gnus-message 7 "No more%s articles"
6402                     (if unread " unread" "")))
6403     (unless dont-display
6404       (gnus-summary-recenter)
6405       (gnus-summary-position-point))
6406     n))
6407
6408 (defun gnus-summary-next-unread-subject (n)
6409   "Go to next N'th unread summary line."
6410   (interactive "p")
6411   (gnus-summary-next-subject n t))
6412
6413 (defun gnus-summary-prev-subject (n &optional unread)
6414   "Go to previous N'th summary line.
6415 If optional argument UNREAD is non-nil, only unread article is selected."
6416   (interactive "p")
6417   (gnus-summary-next-subject (- n) unread))
6418
6419 (defun gnus-summary-prev-unread-subject (n)
6420   "Go to previous N'th unread summary line."
6421   (interactive "p")
6422   (gnus-summary-next-subject (- n) t))
6423
6424 (defun gnus-summary-goto-subject (article &optional force silent)
6425   "Go the subject line of ARTICLE.
6426 If FORCE, also allow jumping to articles not currently shown."
6427   (interactive "nArticle number: ")
6428   (let ((b (point))
6429         (data (gnus-data-find article)))
6430     ;; We read in the article if we have to.
6431     (and (not data)
6432          force
6433          (gnus-summary-insert-subject
6434           article
6435           (if (or (numberp force) (vectorp force)) force)
6436           t)
6437          (setq data (gnus-data-find article)))
6438     (goto-char b)
6439     (if (not data)
6440         (progn
6441           (unless silent
6442             (gnus-message 3 "Can't find article %d" article))
6443           nil)
6444       (let ((pt (gnus-data-pos data)))
6445         (goto-char pt)
6446         (gnus-summary-set-article-display-arrow pt))
6447       (gnus-summary-position-point)
6448       article)))
6449
6450 ;; Walking around summary lines with displaying articles.
6451
6452 (defun gnus-summary-expand-window (&optional arg)
6453   "Make the summary buffer take up the entire Emacs frame.
6454 Given a prefix, will force an `article' buffer configuration."
6455   (interactive "P")
6456   (if arg
6457       (gnus-configure-windows 'article 'force)
6458     (gnus-configure-windows 'summary 'force)))
6459
6460 (defun gnus-summary-display-article (article &optional all-header)
6461   "Display ARTICLE in article buffer."
6462   (when (gnus-buffer-live-p gnus-article-buffer)
6463     (with-current-buffer gnus-article-buffer
6464       (set-buffer-multibyte t)))
6465   (gnus-set-global-variables)
6466   (when (gnus-buffer-live-p gnus-article-buffer)
6467     (with-current-buffer gnus-article-buffer
6468       (setq gnus-article-charset gnus-newsgroup-charset)
6469       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6470   (if (null article)
6471       nil
6472     (prog1
6473         (if gnus-summary-display-article-function
6474             (funcall gnus-summary-display-article-function article all-header)
6475           (gnus-article-prepare article all-header))
6476       (with-current-buffer gnus-article-buffer
6477         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6478              nil))
6479       (gnus-run-hooks 'gnus-select-article-hook)
6480       (when (and gnus-current-article
6481                  (not (zerop gnus-current-article)))
6482         (gnus-summary-goto-subject gnus-current-article))
6483       (gnus-summary-recenter)
6484       (when (and gnus-use-trees gnus-show-threads)
6485         (gnus-possibly-generate-tree article)
6486         (gnus-highlight-selected-tree article))
6487       ;; Successfully display article.
6488       (gnus-article-set-window-start
6489        (cdr (assq article gnus-newsgroup-bookmarks))))))
6490
6491 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6492   "Select the current article.
6493 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6494 non-nil, the article will be re-fetched even if it already present in
6495 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6496 be displayed."
6497   ;; Make sure we are in the summary buffer to work around bbdb bug.
6498   (unless (eq major-mode 'gnus-summary-mode)
6499     (set-buffer gnus-summary-buffer))
6500   (let ((article (or article (gnus-summary-article-number)))
6501         (all-headers (not (not all-headers))) ;Must be T or NIL.
6502         gnus-summary-display-article-function)
6503     (and (not pseudo)
6504          (gnus-summary-article-pseudo-p article)
6505          (error "This is a pseudo-article"))
6506     (save-excursion
6507       (set-buffer gnus-summary-buffer)
6508       (if (or (and gnus-single-article-buffer
6509                    (or (null gnus-current-article)
6510                        (null gnus-article-current)
6511                        (null (get-buffer gnus-article-buffer))
6512                        (not (eq article (cdr gnus-article-current)))
6513                        (not (equal (car gnus-article-current)
6514                                    gnus-newsgroup-name))))
6515               (and (not gnus-single-article-buffer)
6516                    (or (null gnus-current-article)
6517                        (not (eq gnus-current-article article))))
6518               force)
6519           ;; The requested article is different from the current article.
6520           (progn
6521             (gnus-summary-display-article article all-headers)
6522             (when (or all-headers gnus-show-all-headers)
6523               (gnus-article-show-all-headers))
6524             (gnus-article-set-window-start
6525              (cdr (assq article gnus-newsgroup-bookmarks)))
6526             article)
6527         (when (or all-headers gnus-show-all-headers)
6528           (gnus-article-show-all-headers))
6529         'old))))
6530
6531 (defun gnus-summary-force-verify-and-decrypt ()
6532   (interactive)
6533   (let ((mm-verify-option 'known)
6534         (mm-decrypt-option 'known))
6535     (gnus-summary-select-article nil 'force)))
6536
6537 (defun gnus-summary-set-current-mark (&optional current-mark)
6538   "Obsolete function."
6539   nil)
6540
6541 (defun gnus-summary-next-article (&optional unread subject backward push)
6542   "Select the next article.
6543 If UNREAD, only unread articles are selected.
6544 If SUBJECT, only articles with SUBJECT are selected.
6545 If BACKWARD, the previous article is selected instead of the next."
6546   (interactive "P")
6547   (cond
6548    ;; Is there such an article?
6549    ((and (gnus-summary-search-forward unread subject backward)
6550          (or (gnus-summary-display-article (gnus-summary-article-number))
6551              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6552     (gnus-summary-position-point))
6553    ;; If not, we try the first unread, if that is wanted.
6554    ((and subject
6555          gnus-auto-select-same
6556          (gnus-summary-first-unread-article))
6557     (gnus-summary-position-point)
6558     (gnus-message 6 "Wrapped"))
6559    ;; Try to get next/previous article not displayed in this group.
6560    ((and gnus-auto-extend-newsgroup
6561          (not unread) (not subject))
6562     (gnus-summary-goto-article
6563      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6564      nil (count-lines (point-min) (point))))
6565    ;; Go to next/previous group.
6566    (t
6567     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6568       (gnus-summary-jump-to-group gnus-newsgroup-name))
6569     (let ((cmd last-command-char)
6570           (point
6571            (save-excursion
6572              (set-buffer gnus-group-buffer)
6573              (point)))
6574           (group
6575            (if (eq gnus-keep-same-level 'best)
6576                (gnus-summary-best-group gnus-newsgroup-name)
6577              (gnus-summary-search-group backward gnus-keep-same-level))))
6578       ;; For some reason, the group window gets selected.  We change
6579       ;; it back.
6580       (select-window (get-buffer-window (current-buffer)))
6581       ;; Select next unread newsgroup automagically.
6582       (cond
6583        ((or (not gnus-auto-select-next)
6584             (not cmd))
6585         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6586        ((or (eq gnus-auto-select-next 'quietly)
6587             (and (eq gnus-auto-select-next 'slightly-quietly)
6588                  push)
6589             (and (eq gnus-auto-select-next 'almost-quietly)
6590                  (gnus-summary-last-article-p)))
6591         ;; Select quietly.
6592         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6593             (gnus-summary-exit)
6594           (gnus-message 7 "No more%s articles (%s)..."
6595                         (if unread " unread" "")
6596                         (if group (concat "selecting " group)
6597                           "exiting"))
6598           (gnus-summary-next-group nil group backward)))
6599        (t
6600         (when (gnus-key-press-event-p last-input-event)
6601           (gnus-summary-walk-group-buffer
6602            gnus-newsgroup-name cmd unread backward point))))))))
6603
6604 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6605   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6606                       (?\C-p (gnus-group-prev-unread-group 1))))
6607         (cursor-in-echo-area t)
6608         keve key group ended)
6609     (save-excursion
6610       (set-buffer gnus-group-buffer)
6611       (goto-char start)
6612       (setq group
6613             (if (eq gnus-keep-same-level 'best)
6614                 (gnus-summary-best-group gnus-newsgroup-name)
6615               (gnus-summary-search-group backward gnus-keep-same-level))))
6616     (while (not ended)
6617       (gnus-message
6618        5 "No more%s articles%s" (if unread " unread" "")
6619        (if (and group
6620                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6621            (format " (Type %s for %s [%s])"
6622                    (single-key-description cmd) group
6623                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6624          (format " (Type %s to exit %s)"
6625                  (single-key-description cmd)
6626                  gnus-newsgroup-name)))
6627       ;; Confirm auto selection.
6628       (setq key (car (setq keve (gnus-read-event-char))))
6629       (setq ended t)
6630       (cond
6631        ((assq key keystrokes)
6632         (let ((obuf (current-buffer)))
6633           (switch-to-buffer gnus-group-buffer)
6634           (when group
6635             (gnus-group-jump-to-group group))
6636           (eval (cadr (assq key keystrokes)))
6637           (setq group (gnus-group-group-name))
6638           (switch-to-buffer obuf))
6639         (setq ended nil))
6640        ((equal key cmd)
6641         (if (or (not group)
6642                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6643             (gnus-summary-exit)
6644           (gnus-summary-next-group nil group backward)))
6645        (t
6646         (push (cdr keve) unread-command-events))))))
6647
6648 (defun gnus-summary-next-unread-article ()
6649   "Select unread article after current one."
6650   (interactive)
6651   (gnus-summary-next-article
6652    (or (not (eq gnus-summary-goto-unread 'never))
6653        (gnus-summary-last-article-p (gnus-summary-article-number)))
6654    (and gnus-auto-select-same
6655         (gnus-summary-article-subject))))
6656
6657 (defun gnus-summary-prev-article (&optional unread subject)
6658   "Select the article after the current one.
6659 If UNREAD is non-nil, only unread articles are selected."
6660   (interactive "P")
6661   (gnus-summary-next-article unread subject t))
6662
6663 (defun gnus-summary-prev-unread-article ()
6664   "Select unread article before current one."
6665   (interactive)
6666   (gnus-summary-prev-article
6667    (or (not (eq gnus-summary-goto-unread 'never))
6668        (gnus-summary-first-article-p (gnus-summary-article-number)))
6669    (and gnus-auto-select-same
6670         (gnus-summary-article-subject))))
6671
6672 (defun gnus-summary-next-page (&optional lines circular)
6673   "Show next page of the selected article.
6674 If at the end of the current article, select the next article.
6675 LINES says how many lines should be scrolled up.
6676
6677 If CIRCULAR is non-nil, go to the start of the article instead of
6678 selecting the next article when reaching the end of the current
6679 article."
6680   (interactive "P")
6681   (setq gnus-summary-buffer (current-buffer))
6682   (gnus-set-global-variables)
6683   (let ((article (gnus-summary-article-number))
6684         (article-window (get-buffer-window gnus-article-buffer t))
6685         endp)
6686     ;; If the buffer is empty, we have no article.
6687     (unless article
6688       (error "No article to select"))
6689     (gnus-configure-windows 'article)
6690     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6691         (if (and (eq gnus-summary-goto-unread 'never)
6692                  (not (gnus-summary-last-article-p article)))
6693             (gnus-summary-next-article)
6694           (gnus-summary-next-unread-article))
6695       (if (or (null gnus-current-article)
6696               (null gnus-article-current)
6697               (/= article (cdr gnus-article-current))
6698               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6699           ;; Selected subject is different from current article's.
6700           (gnus-summary-display-article article)
6701         (when article-window
6702           (gnus-eval-in-buffer-window gnus-article-buffer
6703             (setq endp (gnus-article-next-page lines)))
6704           (when endp
6705             (cond (circular
6706                    (gnus-summary-beginning-of-article))
6707                   (lines
6708                    (gnus-message 3 "End of message"))
6709                   ((null lines)
6710                    (if (and (eq gnus-summary-goto-unread 'never)
6711                             (not (gnus-summary-last-article-p article)))
6712                        (gnus-summary-next-article)
6713                      (gnus-summary-next-unread-article))))))))
6714     (gnus-summary-recenter)
6715     (gnus-summary-position-point)))
6716
6717 (defun gnus-summary-prev-page (&optional lines move)
6718   "Show previous page of selected article.
6719 Argument LINES specifies lines to be scrolled down.
6720 If MOVE, move to the previous unread article if point is at
6721 the beginning of the buffer."
6722   (interactive "P")
6723   (let ((article (gnus-summary-article-number))
6724         (article-window (get-buffer-window gnus-article-buffer t))
6725         endp)
6726     (gnus-configure-windows 'article)
6727     (if (or (null gnus-current-article)
6728             (null gnus-article-current)
6729             (/= article (cdr gnus-article-current))
6730             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6731         ;; Selected subject is different from current article's.
6732         (gnus-summary-display-article article)
6733       (gnus-summary-recenter)
6734       (when article-window
6735         (gnus-eval-in-buffer-window gnus-article-buffer
6736           (setq endp (gnus-article-prev-page lines)))
6737         (when (and move endp)
6738           (cond (lines
6739                  (gnus-message 3 "Beginning of message"))
6740                 ((null lines)
6741                  (if (and (eq gnus-summary-goto-unread 'never)
6742                           (not (gnus-summary-first-article-p article)))
6743                      (gnus-summary-prev-article)
6744                    (gnus-summary-prev-unread-article))))))))
6745   (gnus-summary-position-point))
6746
6747 (defun gnus-summary-prev-page-or-article (&optional lines)
6748   "Show previous page of selected article.
6749 Argument LINES specifies lines to be scrolled down.
6750 If at the beginning of the article, go to the next article."
6751   (interactive "P")
6752   (gnus-summary-prev-page lines t))
6753
6754 (defun gnus-summary-scroll-up (lines)
6755   "Scroll up (or down) one line current article.
6756 Argument LINES specifies lines to be scrolled up (or down if negative)."
6757   (interactive "p")
6758   (gnus-configure-windows 'article)
6759   (gnus-summary-show-thread)
6760   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6761     (gnus-eval-in-buffer-window gnus-article-buffer
6762       (cond ((> lines 0)
6763              (when (gnus-article-next-page lines)
6764                (gnus-message 3 "End of message")))
6765             ((< lines 0)
6766              (gnus-article-prev-page (- lines))))))
6767   (gnus-summary-recenter)
6768   (gnus-summary-position-point))
6769
6770 (defun gnus-summary-scroll-down (lines)
6771   "Scroll down (or up) one line current article.
6772 Argument LINES specifies lines to be scrolled down (or up if negative)."
6773   (interactive "p")
6774   (gnus-summary-scroll-up (- lines)))
6775
6776 (defun gnus-summary-next-same-subject ()
6777   "Select next article which has the same subject as current one."
6778   (interactive)
6779   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6780
6781 (defun gnus-summary-prev-same-subject ()
6782   "Select previous article which has the same subject as current one."
6783   (interactive)
6784   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6785
6786 (defun gnus-summary-next-unread-same-subject ()
6787   "Select next unread article which has the same subject as current one."
6788   (interactive)
6789   (gnus-summary-next-article t (gnus-summary-article-subject)))
6790
6791 (defun gnus-summary-prev-unread-same-subject ()
6792   "Select previous unread article which has the same subject as current one."
6793   (interactive)
6794   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6795
6796 (defun gnus-summary-first-unread-article ()
6797   "Select the first unread article.
6798 Return nil if there are no unread articles."
6799   (interactive)
6800   (prog1
6801       (when (gnus-summary-first-subject t)
6802         (gnus-summary-show-thread)
6803         (gnus-summary-first-subject t)
6804         (gnus-summary-display-article (gnus-summary-article-number)))
6805     (gnus-summary-position-point)))
6806
6807 (defun gnus-summary-first-unread-subject ()
6808   "Place the point on the subject line of the first unread article.
6809 Return nil if there are no unread articles."
6810   (interactive)
6811   (prog1
6812       (when (gnus-summary-first-subject t)
6813         (gnus-summary-show-thread)
6814         (gnus-summary-first-subject t))
6815     (gnus-summary-position-point)))
6816
6817 (defun gnus-summary-first-unseen-subject ()
6818   "Place the point on the subject line of the first unseen article.
6819 Return nil if there are no unseen articles."
6820   (interactive)
6821   (prog1
6822       (when (gnus-summary-first-subject t t t)
6823         (gnus-summary-show-thread)
6824         (gnus-summary-first-subject t t t))
6825     (gnus-summary-position-point)))
6826
6827 (defun gnus-summary-first-article ()
6828   "Select the first article.
6829 Return nil if there are no articles."
6830   (interactive)
6831   (prog1
6832       (when (gnus-summary-first-subject)
6833         (gnus-summary-show-thread)
6834         (gnus-summary-first-subject)
6835         (gnus-summary-display-article (gnus-summary-article-number)))
6836     (gnus-summary-position-point)))
6837
6838 (defun gnus-summary-best-unread-article (&optional arg)
6839   "Select the unread article with the highest score.
6840 If given a prefix argument, select the next unread article that has a
6841 score higher than the default score."
6842   (interactive "P")
6843   (let ((article (if arg
6844                      (gnus-summary-better-unread-subject)
6845                    (gnus-summary-best-unread-subject))))
6846     (if article
6847         (gnus-summary-goto-article article)
6848       (error "No unread articles"))))
6849
6850 (defun gnus-summary-best-unread-subject ()
6851   "Select the unread subject with the highest score."
6852   (interactive)
6853   (let ((best -1000000)
6854         (data gnus-newsgroup-data)
6855         article score)
6856     (while data
6857       (and (gnus-data-unread-p (car data))
6858            (> (setq score
6859                     (gnus-summary-article-score (gnus-data-number (car data))))
6860               best)
6861            (setq best score
6862                  article (gnus-data-number (car data))))
6863       (setq data (cdr data)))
6864     (when article
6865       (gnus-summary-goto-subject article))
6866     (gnus-summary-position-point)
6867     article))
6868
6869 (defun gnus-summary-better-unread-subject ()
6870   "Select the first unread subject that has a score over the default score."
6871   (interactive)
6872   (let ((data gnus-newsgroup-data)
6873         article score)
6874     (while (and (setq article (gnus-data-number (car data)))
6875                 (or (gnus-data-read-p (car data))
6876                     (not (> (gnus-summary-article-score article)
6877                             gnus-summary-default-score))))
6878       (setq data (cdr data)))
6879     (when article
6880       (gnus-summary-goto-subject article))
6881     (gnus-summary-position-point)
6882     article))
6883
6884 (defun gnus-summary-last-subject ()
6885   "Go to the last displayed subject line in the group."
6886   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6887     (when article
6888       (gnus-summary-goto-subject article))))
6889
6890 (defun gnus-summary-goto-article (article &optional all-headers force)
6891   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6892 If ALL-HEADERS is non-nil, no header lines are hidden.
6893 If FORCE, go to the article even if it isn't displayed.  If FORCE
6894 is a number, it is the line the article is to be displayed on."
6895   (interactive
6896    (list
6897     (completing-read
6898      "Article number or Message-ID: "
6899      (mapcar (lambda (number) (list (int-to-string number)))
6900              gnus-newsgroup-limit))
6901     current-prefix-arg
6902     t))
6903   (prog1
6904       (if (and (stringp article)
6905                (string-match "@" article))
6906           (gnus-summary-refer-article article)
6907         (when (stringp article)
6908           (setq article (string-to-number article)))
6909         (if (gnus-summary-goto-subject article force)
6910             (gnus-summary-display-article article all-headers)
6911           (gnus-message 4 "Couldn't go to article %s" article) nil))
6912     (gnus-summary-position-point)))
6913
6914 (defun gnus-summary-goto-last-article ()
6915   "Go to the previously read article."
6916   (interactive)
6917   (prog1
6918       (when gnus-last-article
6919         (gnus-summary-goto-article gnus-last-article nil t))
6920     (gnus-summary-position-point)))
6921
6922 (defun gnus-summary-pop-article (number)
6923   "Pop one article off the history and go to the previous.
6924 NUMBER articles will be popped off."
6925   (interactive "p")
6926   (let (to)
6927     (setq gnus-newsgroup-history
6928           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6929     (if to
6930         (gnus-summary-goto-article (car to) nil t)
6931       (error "Article history empty")))
6932   (gnus-summary-position-point))
6933
6934 ;; Summary commands and functions for limiting the summary buffer.
6935
6936 (defun gnus-summary-limit-to-articles (n)
6937   "Limit the summary buffer to the next N articles.
6938 If not given a prefix, use the process marked articles instead."
6939   (interactive "P")
6940   (prog1
6941       (let ((articles (gnus-summary-work-articles n)))
6942         (setq gnus-newsgroup-processable nil)
6943         (gnus-summary-limit articles))
6944     (gnus-summary-position-point)))
6945
6946 (defun gnus-summary-pop-limit (&optional total)
6947   "Restore the previous limit.
6948 If given a prefix, remove all limits."
6949   (interactive "P")
6950   (when total
6951     (setq gnus-newsgroup-limits
6952           (list (mapcar (lambda (h) (mail-header-number h))
6953                         gnus-newsgroup-headers))))
6954   (unless gnus-newsgroup-limits
6955     (error "No limit to pop"))
6956   (prog1
6957       (gnus-summary-limit nil 'pop)
6958     (gnus-summary-position-point)))
6959
6960 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6961   "Limit the summary buffer to articles that have subjects that match a regexp.
6962 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6963   (interactive
6964    (list (read-string (if current-prefix-arg
6965                           "Exclude subject (regexp): "
6966                         "Limit to subject (regexp): "))
6967          nil current-prefix-arg))
6968   (unless header
6969     (setq header "subject"))
6970   (when (not (equal "" subject))
6971     (prog1
6972         (let ((articles (gnus-summary-find-matching
6973                          (or header "subject") subject 'all nil nil
6974                          not-matching)))
6975           (unless articles
6976             (error "Found no matches for \"%s\"" subject))
6977           (gnus-summary-limit articles))
6978       (gnus-summary-position-point))))
6979
6980 (defun gnus-summary-limit-to-author (from &optional not-matching)
6981   "Limit the summary buffer to articles that have authors that match a regexp.
6982 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6983   (interactive
6984    (list (read-string (if current-prefix-arg
6985                           "Exclude author (regexp): "
6986                         "Limit to author (regexp): "))
6987          current-prefix-arg))
6988   (gnus-summary-limit-to-subject from "from" not-matching))
6989
6990 (defun gnus-summary-limit-to-age (age &optional younger-p)
6991   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6992 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6993 articles that are younger than AGE days."
6994   (interactive
6995    (let ((younger current-prefix-arg)
6996          (days-got nil)
6997          days)
6998      (while (not days-got)
6999        (setq days (if younger
7000                       (read-string "Limit to articles within (in days): ")
7001                     (read-string "Limit to articles older than (in days): ")))
7002        (when (> (length days) 0)
7003          (setq days (read days)))
7004        (if (numberp days)
7005            (progn
7006              (setq days-got t)
7007              (if (< days 0)
7008                  (progn
7009                    (setq younger (not younger))
7010                    (setq days (* days -1)))))
7011          (message "Please enter a number.")
7012          (sleep-for 1)))
7013      (list days younger)))
7014   (prog1
7015       (let ((data gnus-newsgroup-data)
7016             (cutoff (days-to-time age))
7017             articles d date is-younger)
7018         (while (setq d (pop data))
7019           (when (and (vectorp (gnus-data-header d))
7020                      (setq date (mail-header-date (gnus-data-header d))))
7021             (setq is-younger (time-less-p
7022                               (time-since (condition-case ()
7023                                               (date-to-time date)
7024                                             (error '(0 0))))
7025                               cutoff))
7026             (when (if younger-p
7027                       is-younger
7028                     (not is-younger))
7029               (push (gnus-data-number d) articles))))
7030         (gnus-summary-limit (nreverse articles)))
7031     (gnus-summary-position-point)))
7032
7033 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7034   "Limit the summary buffer to articles that match an 'extra' header."
7035   (interactive
7036    (let ((header
7037           (intern
7038            (gnus-completing-read
7039             (symbol-name (car gnus-extra-headers))
7040             (if current-prefix-arg
7041                 "Exclude extra header:"
7042               "Limit extra header:")
7043             (mapcar (lambda (x)
7044                       (cons (symbol-name x) x))
7045                     gnus-extra-headers)
7046             nil
7047             t))))
7048      (list header
7049            (read-string (format "%s header %s (regexp): "
7050                                 (if current-prefix-arg "Exclude" "Limit to")
7051                                 header))
7052            current-prefix-arg)))
7053   (when (not (equal "" regexp))
7054     (prog1
7055         (let ((articles (gnus-summary-find-matching
7056                          (cons 'extra header) regexp 'all nil nil
7057                          not-matching)))
7058           (unless articles
7059             (error "Found no matches for \"%s\"" regexp))
7060           (gnus-summary-limit articles))
7061       (gnus-summary-position-point))))
7062
7063 (defun gnus-summary-limit-to-display-predicate ()
7064   "Limit the summary buffer to the predicated in the `display' group parameter."
7065   (interactive)
7066   (unless gnus-newsgroup-display
7067     (error "There is no `display' group parameter"))
7068   (let (articles)
7069     (dolist (number gnus-newsgroup-articles)
7070       (when (funcall gnus-newsgroup-display)
7071         (push number articles)))
7072     (gnus-summary-limit articles))
7073   (gnus-summary-position-point))
7074
7075 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7076 (make-obsolete
7077  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7078
7079 (defun gnus-summary-limit-to-unread (&optional all)
7080   "Limit the summary buffer to articles that are not marked as read.
7081 If ALL is non-nil, limit strictly to unread articles."
7082   (interactive "P")
7083   (if all
7084       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7085     (gnus-summary-limit-to-marks
7086      ;; Concat all the marks that say that an article is read and have
7087      ;; those removed.
7088      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7089            gnus-killed-mark gnus-kill-file-mark
7090            gnus-low-score-mark gnus-expirable-mark
7091            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7092            gnus-duplicate-mark gnus-souped-mark)
7093      'reverse)))
7094
7095 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7096 (make-obsolete 'gnus-summary-delete-marked-with
7097                'gnus-summary-limit-exlude-marks)
7098
7099 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7100   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7101 If REVERSE, limit the summary buffer to articles that are marked
7102 with MARKS.  MARKS can either be a string of marks or a list of marks.
7103 Returns how many articles were removed."
7104   (interactive "sMarks: ")
7105   (gnus-summary-limit-to-marks marks t))
7106
7107 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7108   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7109 If REVERSE (the prefix), limit the summary buffer to articles that are
7110 not marked with MARKS.  MARKS can either be a string of marks or a
7111 list of marks.
7112 Returns how many articles were removed."
7113   (interactive "sMarks: \nP")
7114   (prog1
7115       (let ((data gnus-newsgroup-data)
7116             (marks (if (listp marks) marks
7117                      (append marks nil))) ; Transform to list.
7118             articles)
7119         (while data
7120           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7121                   (memq (gnus-data-mark (car data)) marks))
7122             (push (gnus-data-number (car data)) articles))
7123           (setq data (cdr data)))
7124         (gnus-summary-limit articles))
7125     (gnus-summary-position-point)))
7126
7127 (defun gnus-summary-limit-to-score (score)
7128   "Limit to articles with score at or above SCORE."
7129   (interactive "NLimit to articles with score of at least: ")
7130   (let ((data gnus-newsgroup-data)
7131         articles)
7132     (while data
7133       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7134                 score)
7135         (push (gnus-data-number (car data)) articles))
7136       (setq data (cdr data)))
7137     (prog1
7138         (gnus-summary-limit articles)
7139       (gnus-summary-position-point))))
7140
7141 (defun gnus-summary-limit-include-thread (id)
7142   "Display all the hidden articles that is in the thread with ID in it.
7143 When called interactively, ID is the Message-ID of the current
7144 article."
7145   (interactive (list (mail-header-id (gnus-summary-article-header))))
7146   (let ((articles (gnus-articles-in-thread
7147                    (gnus-id-to-thread (gnus-root-id id)))))
7148     (prog1
7149         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7150       (gnus-summary-limit-include-matching-articles
7151        "subject"
7152        (regexp-quote (gnus-simplify-subject-re
7153                       (mail-header-subject (gnus-id-to-header id)))))
7154       (gnus-summary-position-point))))
7155
7156 (defun gnus-summary-limit-include-matching-articles (header regexp)
7157   "Display all the hidden articles that have HEADERs that match REGEXP."
7158   (interactive (list (read-string "Match on header: ")
7159                      (read-string "Regexp: ")))
7160   (let ((articles (gnus-find-matching-articles header regexp)))
7161     (prog1
7162         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7163       (gnus-summary-position-point))))
7164
7165 (defun gnus-summary-limit-include-dormant ()
7166   "Display all the hidden articles that are marked as dormant.
7167 Note that this command only works on a subset of the articles currently
7168 fetched for this group."
7169   (interactive)
7170   (unless gnus-newsgroup-dormant
7171     (error "There are no dormant articles in this group"))
7172   (prog1
7173       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7174     (gnus-summary-position-point)))
7175
7176 (defun gnus-summary-limit-exclude-dormant ()
7177   "Hide all dormant articles."
7178   (interactive)
7179   (prog1
7180       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7181     (gnus-summary-position-point)))
7182
7183 (defun gnus-summary-limit-exclude-childless-dormant ()
7184   "Hide all dormant articles that have no children."
7185   (interactive)
7186   (let ((data (gnus-data-list t))
7187         articles d children)
7188     ;; Find all articles that are either not dormant or have
7189     ;; children.
7190     (while (setq d (pop data))
7191       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7192                 (and (setq children
7193                            (gnus-article-children (gnus-data-number d)))
7194                      (let (found)
7195                        (while children
7196                          (when (memq (car children) articles)
7197                            (setq children nil
7198                                  found t))
7199                          (pop children))
7200                        found)))
7201         (push (gnus-data-number d) articles)))
7202     ;; Do the limiting.
7203     (prog1
7204         (gnus-summary-limit articles)
7205       (gnus-summary-position-point))))
7206
7207 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7208   "Mark all unread excluded articles as read.
7209 If ALL, mark even excluded ticked and dormants as read."
7210   (interactive "P")
7211   (let ((articles (gnus-sorted-complement
7212                    (sort
7213                     (mapcar (lambda (h) (mail-header-number h))
7214                             gnus-newsgroup-headers)
7215                     '<)
7216                    (sort gnus-newsgroup-limit '<)))
7217         article)
7218     (setq gnus-newsgroup-unreads
7219           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7220     (if all
7221         (setq gnus-newsgroup-dormant nil
7222               gnus-newsgroup-marked nil
7223               gnus-newsgroup-reads
7224               (nconc
7225                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7226                gnus-newsgroup-reads))
7227       (while (setq article (pop articles))
7228         (unless (or (memq article gnus-newsgroup-dormant)
7229                     (memq article gnus-newsgroup-marked))
7230           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7231
7232 (defun gnus-summary-limit (articles &optional pop)
7233   (if pop
7234       ;; We pop the previous limit off the stack and use that.
7235       (setq articles (car gnus-newsgroup-limits)
7236             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7237     ;; We use the new limit, so we push the old limit on the stack.
7238     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7239   ;; Set the limit.
7240   (setq gnus-newsgroup-limit articles)
7241   (let ((total (length gnus-newsgroup-data))
7242         (data (gnus-data-find-list (gnus-summary-article-number)))
7243         (gnus-summary-mark-below nil)   ; Inhibit this.
7244         found)
7245     ;; This will do all the work of generating the new summary buffer
7246     ;; according to the new limit.
7247     (gnus-summary-prepare)
7248     ;; Hide any threads, possibly.
7249     (and gnus-show-threads
7250          gnus-thread-hide-subtree
7251          (gnus-summary-hide-all-threads))
7252     ;; Try to return to the article you were at, or one in the
7253     ;; neighborhood.
7254     (when data
7255       ;; We try to find some article after the current one.
7256       (while data
7257         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7258           (setq data nil
7259                 found t))
7260         (setq data (cdr data))))
7261     (unless found
7262       ;; If there is no data, that means that we were after the last
7263       ;; article.  The same goes when we can't find any articles
7264       ;; after the current one.
7265       (goto-char (point-max))
7266       (gnus-summary-find-prev))
7267     (gnus-set-mode-line 'summary)
7268     ;; We return how many articles were removed from the summary
7269     ;; buffer as a result of the new limit.
7270     (- total (length gnus-newsgroup-data))))
7271
7272 (defsubst gnus-invisible-cut-children (threads)
7273   (let ((num 0))
7274     (while threads
7275       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7276         (incf num))
7277       (pop threads))
7278     (< num 2)))
7279
7280 (defsubst gnus-cut-thread (thread)
7281   "Go forwards in the thread until we find an article that we want to display."
7282   (when (or (eq gnus-fetch-old-headers 'some)
7283             (eq gnus-fetch-old-headers 'invisible)
7284             (numberp gnus-fetch-old-headers)
7285             (eq gnus-build-sparse-threads 'some)
7286             (eq gnus-build-sparse-threads 'more))
7287     ;; Deal with old-fetched headers and sparse threads.
7288     (while (and
7289             thread
7290             (or
7291              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7292              (gnus-summary-article-ancient-p
7293               (mail-header-number (car thread))))
7294             (if (or (<= (length (cdr thread)) 1)
7295                     (eq gnus-fetch-old-headers 'invisible))
7296                 (setq gnus-newsgroup-limit
7297                       (delq (mail-header-number (car thread))
7298                             gnus-newsgroup-limit)
7299                       thread (cadr thread))
7300               (when (gnus-invisible-cut-children (cdr thread))
7301                 (let ((th (cdr thread)))
7302                   (while th
7303                     (if (memq (mail-header-number (caar th))
7304                               gnus-newsgroup-limit)
7305                         (setq thread (car th)
7306                               th nil)
7307                       (setq th (cdr th))))))))))
7308   thread)
7309
7310 (defun gnus-cut-threads (threads)
7311   "Cut off all uninteresting articles from the beginning of threads."
7312   (when (or (eq gnus-fetch-old-headers 'some)
7313             (eq gnus-fetch-old-headers 'invisible)
7314             (numberp gnus-fetch-old-headers)
7315             (eq gnus-build-sparse-threads 'some)
7316             (eq gnus-build-sparse-threads 'more))
7317     (let ((th threads))
7318       (while th
7319         (setcar th (gnus-cut-thread (car th)))
7320         (setq th (cdr th)))))
7321   ;; Remove nixed out threads.
7322   (delq nil threads))
7323
7324 (defun gnus-summary-initial-limit (&optional show-if-empty)
7325   "Figure out what the initial limit is supposed to be on group entry.
7326 This entails weeding out unwanted dormants, low-scored articles,
7327 fetch-old-headers verbiage, and so on."
7328   ;; Most groups have nothing to remove.
7329   (if (or gnus-inhibit-limiting
7330           (and (null gnus-newsgroup-dormant)
7331                (eq gnus-newsgroup-display 'gnus-not-ignore)
7332                (not (eq gnus-fetch-old-headers 'some))
7333                (not (numberp gnus-fetch-old-headers))
7334                (not (eq gnus-fetch-old-headers 'invisible))
7335                (null gnus-summary-expunge-below)
7336                (not (eq gnus-build-sparse-threads 'some))
7337                (not (eq gnus-build-sparse-threads 'more))
7338                (null gnus-thread-expunge-below)
7339                (not gnus-use-nocem)))
7340       ()                                ; Do nothing.
7341     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7342     (setq gnus-newsgroup-limit nil)
7343     (mapatoms
7344      (lambda (node)
7345        (unless (car (symbol-value node))
7346          ;; These threads have no parents -- they are roots.
7347          (let ((nodes (cdr (symbol-value node)))
7348                thread)
7349            (while nodes
7350              (if (and gnus-thread-expunge-below
7351                       (< (gnus-thread-total-score (car nodes))
7352                          gnus-thread-expunge-below))
7353                  (gnus-expunge-thread (pop nodes))
7354                (setq thread (pop nodes))
7355                (gnus-summary-limit-children thread))))))
7356      gnus-newsgroup-dependencies)
7357     ;; If this limitation resulted in an empty group, we might
7358     ;; pop the previous limit and use it instead.
7359     (when (and (not gnus-newsgroup-limit)
7360                show-if-empty)
7361       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7362     gnus-newsgroup-limit))
7363
7364 (defun gnus-summary-limit-children (thread)
7365   "Return 1 if this subthread is visible and 0 if it is not."
7366   ;; First we get the number of visible children to this thread.  This
7367   ;; is done by recursing down the thread using this function, so this
7368   ;; will really go down to a leaf article first, before slowly
7369   ;; working its way up towards the root.
7370   (when thread
7371     (let ((children
7372            (if (cdr thread)
7373                (apply '+ (mapcar 'gnus-summary-limit-children
7374                                  (cdr thread)))
7375              0))
7376           (number (mail-header-number (car thread)))
7377           score)
7378       (if (and
7379            (not (memq number gnus-newsgroup-marked))
7380            (or
7381             ;; If this article is dormant and has absolutely no visible
7382             ;; children, then this article isn't visible.
7383             (and (memq number gnus-newsgroup-dormant)
7384                  (zerop children))
7385             ;; If this is "fetch-old-headered" and there is no
7386             ;; visible children, then we don't want this article.
7387             (and (or (eq gnus-fetch-old-headers 'some)
7388                      (numberp gnus-fetch-old-headers))
7389                  (gnus-summary-article-ancient-p number)
7390                  (zerop children))
7391             ;; If this is "fetch-old-headered" and `invisible', then
7392             ;; we don't want this article.
7393             (and (eq gnus-fetch-old-headers 'invisible)
7394                  (gnus-summary-article-ancient-p number))
7395             ;; If this is a sparsely inserted article with no children,
7396             ;; we don't want it.
7397             (and (eq gnus-build-sparse-threads 'some)
7398                  (gnus-summary-article-sparse-p number)
7399                  (zerop children))
7400             ;; If we use expunging, and this article is really
7401             ;; low-scored, then we don't want this article.
7402             (when (and gnus-summary-expunge-below
7403                        (< (setq score
7404                                 (or (cdr (assq number gnus-newsgroup-scored))
7405                                     gnus-summary-default-score))
7406                           gnus-summary-expunge-below))
7407               ;; We increase the expunge-tally here, but that has
7408               ;; nothing to do with the limits, really.
7409               (incf gnus-newsgroup-expunged-tally)
7410               ;; We also mark as read here, if that's wanted.
7411               (when (and gnus-summary-mark-below
7412                          (< score gnus-summary-mark-below))
7413                 (setq gnus-newsgroup-unreads
7414                       (delq number gnus-newsgroup-unreads))
7415                 (if gnus-newsgroup-auto-expire
7416                     (push number gnus-newsgroup-expirable)
7417                   (push (cons number gnus-low-score-mark)
7418                         gnus-newsgroup-reads)))
7419               t)
7420             ;; Do the `display' group parameter.
7421             (and gnus-newsgroup-display
7422                  (not (funcall gnus-newsgroup-display)))
7423             ;; Check NoCeM things.
7424             (if (and gnus-use-nocem
7425                      (gnus-nocem-unwanted-article-p
7426                       (mail-header-id (car thread))))
7427                 (progn
7428                   (setq gnus-newsgroup-unreads
7429                         (delq number gnus-newsgroup-unreads))
7430                   t))))
7431           ;; Nope, invisible article.
7432           0
7433         ;; Ok, this article is to be visible, so we add it to the limit
7434         ;; and return 1.
7435         (push number gnus-newsgroup-limit)
7436         1))))
7437
7438 (defun gnus-expunge-thread (thread)
7439   "Mark all articles in THREAD as read."
7440   (let* ((number (mail-header-number (car thread))))
7441     (incf gnus-newsgroup-expunged-tally)
7442     ;; We also mark as read here, if that's wanted.
7443     (setq gnus-newsgroup-unreads
7444           (delq number gnus-newsgroup-unreads))
7445     (if gnus-newsgroup-auto-expire
7446         (push number gnus-newsgroup-expirable)
7447       (push (cons number gnus-low-score-mark)
7448             gnus-newsgroup-reads)))
7449   ;; Go recursively through all subthreads.
7450   (mapcar 'gnus-expunge-thread (cdr thread)))
7451
7452 ;; Summary article oriented commands
7453
7454 (defun gnus-summary-refer-parent-article (n)
7455   "Refer parent article N times.
7456 If N is negative, go to ancestor -N instead.
7457 The difference between N and the number of articles fetched is returned."
7458   (interactive "p")
7459   (let ((skip 1)
7460         error header ref)
7461     (when (not (natnump n))
7462       (setq skip (abs n)
7463             n 1))
7464     (while (and (> n 0)
7465                 (not error))
7466       (setq header (gnus-summary-article-header))
7467       (if (and (eq (mail-header-number header)
7468                    (cdr gnus-article-current))
7469                (equal gnus-newsgroup-name
7470                       (car gnus-article-current)))
7471           ;; If we try to find the parent of the currently
7472           ;; displayed article, then we take a look at the actual
7473           ;; References header, since this is slightly more
7474           ;; reliable than the References field we got from the
7475           ;; server.
7476           (save-excursion
7477             (set-buffer gnus-original-article-buffer)
7478             (nnheader-narrow-to-headers)
7479             (unless (setq ref (message-fetch-field "references"))
7480               (setq ref (message-fetch-field "in-reply-to")))
7481             (widen))
7482         (setq ref
7483               ;; It's not the current article, so we take a bet on
7484               ;; the value we got from the server.
7485               (mail-header-references header)))
7486       (if (and ref
7487                (not (equal ref "")))
7488           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7489             (gnus-message 1 "Couldn't find parent"))
7490         (gnus-message 1 "No references in article %d"
7491                       (gnus-summary-article-number))
7492         (setq error t))
7493       (decf n))
7494     (gnus-summary-position-point)
7495     n))
7496
7497 (defun gnus-summary-refer-references ()
7498   "Fetch all articles mentioned in the References header.
7499 Return the number of articles fetched."
7500   (interactive)
7501   (let ((ref (mail-header-references (gnus-summary-article-header)))
7502         (current (gnus-summary-article-number))
7503         (n 0))
7504     (if (or (not ref)
7505             (equal ref ""))
7506         (error "No References in the current article")
7507       ;; For each Message-ID in the References header...
7508       (while (string-match "<[^>]*>" ref)
7509         (incf n)
7510         ;; ... fetch that article.
7511         (gnus-summary-refer-article
7512          (prog1 (match-string 0 ref)
7513            (setq ref (substring ref (match-end 0))))))
7514       (gnus-summary-goto-subject current)
7515       (gnus-summary-position-point)
7516       n)))
7517
7518 (defun gnus-summary-refer-thread (&optional limit)
7519   "Fetch all articles in the current thread.
7520 If LIMIT (the numerical prefix), fetch that many old headers instead
7521 of what's specified by the `gnus-refer-thread-limit' variable."
7522   (interactive "P")
7523   (let ((id (mail-header-id (gnus-summary-article-header)))
7524         (limit (if limit (prefix-numeric-value limit)
7525                  gnus-refer-thread-limit)))
7526     ;; We want to fetch LIMIT *old* headers, but we also have to
7527     ;; re-fetch all the headers in the current buffer, because many of
7528     ;; them may be undisplayed.  So we adjust LIMIT.
7529     (when (numberp limit)
7530       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7531     (unless (eq gnus-fetch-old-headers 'invisible)
7532       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7533       ;; Retrieve the headers and read them in.
7534       (if (eq (gnus-retrieve-headers
7535                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7536               'nov)
7537           (gnus-build-all-threads)
7538         (error "Can't fetch thread from backends that don't support NOV"))
7539       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7540     (gnus-summary-limit-include-thread id)))
7541
7542 (defun gnus-summary-refer-article (message-id)
7543   "Fetch an article specified by MESSAGE-ID."
7544   (interactive "sMessage-ID: ")
7545   (when (and (stringp message-id)
7546              (not (zerop (length message-id))))
7547     ;; Construct the correct Message-ID if necessary.
7548     ;; Suggested by tale@pawl.rpi.edu.
7549     (unless (string-match "^<" message-id)
7550       (setq message-id (concat "<" message-id)))
7551     (unless (string-match ">$" message-id)
7552       (setq message-id (concat message-id ">")))
7553     (let* ((header (gnus-id-to-header message-id))
7554            (sparse (and header
7555                         (gnus-summary-article-sparse-p
7556                          (mail-header-number header))
7557                         (memq (mail-header-number header)
7558                               gnus-newsgroup-limit)))
7559            number)
7560       (cond
7561        ;; If the article is present in the buffer we just go to it.
7562        ((and header
7563              (or (not (gnus-summary-article-sparse-p
7564                        (mail-header-number header)))
7565                  sparse))
7566         (prog1
7567             (gnus-summary-goto-article
7568              (mail-header-number header) nil t)
7569           (when sparse
7570             (gnus-summary-update-article (mail-header-number header)))))
7571        (t
7572         ;; We fetch the article.
7573         (catch 'found
7574           (dolist (gnus-override-method (gnus-refer-article-methods))
7575             (gnus-check-server gnus-override-method)
7576             ;; Fetch the header, and display the article.
7577             (when (setq number (gnus-summary-insert-subject message-id))
7578               (gnus-summary-select-article nil nil nil number)
7579               (throw 'found t)))
7580           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7581
7582 (defun gnus-refer-article-methods ()
7583   "Return a list of referrable methods."
7584   (cond
7585    ;; No method, so we default to current and native.
7586    ((null gnus-refer-article-method)
7587     (list gnus-current-select-method gnus-select-method))
7588    ;; Current.
7589    ((eq 'current gnus-refer-article-method)
7590     (list gnus-current-select-method))
7591    ;; List of select methods.
7592    ((not (and (symbolp (car gnus-refer-article-method))
7593               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7594     (let (out)
7595       (dolist (method gnus-refer-article-method)
7596         (push (if (eq 'current method)
7597                   gnus-current-select-method
7598                 method)
7599               out))
7600       (nreverse out)))
7601    ;; One single select method.
7602    (t
7603     (list gnus-refer-article-method))))
7604
7605 (defun gnus-summary-edit-parameters ()
7606   "Edit the group parameters of the current group."
7607   (interactive)
7608   (gnus-group-edit-group gnus-newsgroup-name 'params))
7609
7610 (defun gnus-summary-customize-parameters ()
7611   "Customize the group parameters of the current group."
7612   (interactive)
7613   (gnus-group-customize gnus-newsgroup-name))
7614
7615 (defun gnus-summary-enter-digest-group (&optional force)
7616   "Enter an nndoc group based on the current article.
7617 If FORCE, force a digest interpretation.  If not, try
7618 to guess what the document format is."
7619   (interactive "P")
7620   (let ((conf gnus-current-window-configuration))
7621     (save-excursion
7622       (gnus-summary-select-article))
7623     (setq gnus-current-window-configuration conf)
7624     (let* ((name (format "%s-%d"
7625                          (gnus-group-prefixed-name
7626                           gnus-newsgroup-name (list 'nndoc ""))
7627                          (save-excursion
7628                            (set-buffer gnus-summary-buffer)
7629                            gnus-current-article)))
7630            (ogroup gnus-newsgroup-name)
7631            (params (append (gnus-info-params (gnus-get-info ogroup))
7632                            (list (cons 'to-group ogroup))
7633                            (list (cons 'save-article-group ogroup))))
7634            (case-fold-search t)
7635            (buf (current-buffer))
7636            dig to-address)
7637       (save-excursion
7638         (set-buffer gnus-original-article-buffer)
7639         ;; Have the digest group inherit the main mail address of
7640         ;; the parent article.
7641         (when (setq to-address (or (message-fetch-field "reply-to")
7642                                    (message-fetch-field "from")))
7643           (setq params (append
7644                         (list (cons 'to-address
7645                                     (funcall gnus-decode-encoded-word-function
7646                                              to-address))))))
7647         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7648         (insert-buffer-substring gnus-original-article-buffer)
7649         ;; Remove lines that may lead nndoc to misinterpret the
7650         ;; document type.
7651         (narrow-to-region
7652          (goto-char (point-min))
7653          (or (search-forward "\n\n" nil t) (point)))
7654         (goto-char (point-min))
7655         (delete-matching-lines "^Path:\\|^From ")
7656         (widen))
7657       (unwind-protect
7658           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7659                     (gnus-newsgroup-ephemeral-ignored-charsets
7660                      gnus-newsgroup-ignored-charsets))
7661                 (gnus-group-read-ephemeral-group
7662                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7663                               (nndoc-article-type
7664                                ,(if force 'mbox 'guess))) t))
7665               ;; Make all postings to this group go to the parent group.
7666               (nconc (gnus-info-params (gnus-get-info name))
7667                      params)
7668             ;; Couldn't select this doc group.
7669             (switch-to-buffer buf)
7670             (gnus-set-global-variables)
7671             (gnus-configure-windows 'summary)
7672             (gnus-message 3 "Article couldn't be entered?"))
7673         (kill-buffer dig)))))
7674
7675 (defun gnus-summary-read-document (n)
7676   "Open a new group based on the current article(s).
7677 This will allow you to read digests and other similar
7678 documents as newsgroups.
7679 Obeys the standard process/prefix convention."
7680   (interactive "P")
7681   (let* ((articles (gnus-summary-work-articles n))
7682          (ogroup gnus-newsgroup-name)
7683          (params (append (gnus-info-params (gnus-get-info ogroup))
7684                          (list (cons 'to-group ogroup))))
7685          article group egroup groups vgroup)
7686     (while (setq article (pop articles))
7687       (setq group (format "%s-%d" gnus-newsgroup-name article))
7688       (gnus-summary-remove-process-mark article)
7689       (when (gnus-summary-display-article article)
7690         (save-excursion
7691           (with-temp-buffer
7692             (insert-buffer-substring gnus-original-article-buffer)
7693             ;; Remove some headers that may lead nndoc to make
7694             ;; the wrong guess.
7695             (message-narrow-to-head)
7696             (goto-char (point-min))
7697             (delete-matching-lines "^\\(Path\\):\\|^From ")
7698             (widen)
7699             (if (setq egroup
7700                       (gnus-group-read-ephemeral-group
7701                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7702                                      (nndoc-article-type guess))
7703                        t nil t))
7704                 (progn
7705                   ;; Make all postings to this group go to the parent group.
7706                   (nconc (gnus-info-params (gnus-get-info egroup))
7707                          params)
7708                   (push egroup groups))
7709               ;; Couldn't select this doc group.
7710               (gnus-error 3 "Article couldn't be entered"))))))
7711     ;; Now we have selected all the documents.
7712     (cond
7713      ((not groups)
7714       (error "None of the articles could be interpreted as documents"))
7715      ((gnus-group-read-ephemeral-group
7716        (setq vgroup (format
7717                      "nnvirtual:%s-%s" gnus-newsgroup-name
7718                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7719        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7720        t
7721        (cons (current-buffer) 'summary)))
7722      (t
7723       (error "Couldn't select virtual nndoc group")))))
7724
7725 (defun gnus-summary-isearch-article (&optional regexp-p)
7726   "Do incremental search forward on the current article.
7727 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7728   (interactive "P")
7729   (let* ((gnus-inhibit-treatment t)
7730          (old (gnus-summary-select-article)))
7731     (gnus-configure-windows 'article)
7732     (gnus-eval-in-buffer-window gnus-article-buffer
7733       (save-restriction
7734         (widen)
7735         (when (eq 'old old)
7736           (gnus-article-show-all-headers))
7737         (goto-char (point-min))
7738         (isearch-forward regexp-p)))))
7739
7740 (defun gnus-summary-search-article-forward (regexp &optional backward)
7741   "Search for an article containing REGEXP forward.
7742 If BACKWARD, search backward instead."
7743   (interactive
7744    (list (read-string
7745           (format "Search article %s (regexp%s): "
7746                   (if current-prefix-arg "backward" "forward")
7747                   (if gnus-last-search-regexp
7748                       (concat ", default " gnus-last-search-regexp)
7749                     "")))
7750          current-prefix-arg))
7751   (if (string-equal regexp "")
7752       (setq regexp (or gnus-last-search-regexp ""))
7753     (setq gnus-last-search-regexp regexp)
7754     (setq gnus-article-before-search gnus-current-article))
7755   ;; Intentionally set gnus-last-article.
7756   (setq gnus-last-article gnus-article-before-search)
7757   (let ((gnus-last-article gnus-last-article))
7758     (if (gnus-summary-search-article regexp backward)
7759         (gnus-summary-show-thread)
7760       (error "Search failed: \"%s\"" regexp))))
7761
7762 (defun gnus-summary-search-article-backward (regexp)
7763   "Search for an article containing REGEXP backward."
7764   (interactive
7765    (list (read-string
7766           (format "Search article backward (regexp%s): "
7767                   (if gnus-last-search-regexp
7768                       (concat ", default " gnus-last-search-regexp)
7769                     "")))))
7770   (gnus-summary-search-article-forward regexp 'backward))
7771
7772 (eval-when-compile
7773   (defmacro gnus-summary-search-article-position-point (regexp backward)
7774     "Dehighlight the last matched text and goto the beginning position."
7775     (` (if (and gnus-summary-search-article-matched-data
7776                 (let ((text (caddr gnus-summary-search-article-matched-data))
7777                       (inhibit-read-only t)
7778                       buffer-read-only)
7779                   (delete-region
7780                    (goto-char (car gnus-summary-search-article-matched-data))
7781                    (cadr gnus-summary-search-article-matched-data))
7782                   (insert text)
7783                   (string-match (, regexp) text)))
7784            (if (, backward) (beginning-of-line) (end-of-line))
7785          (goto-char (if (, backward) (point-max) (point-min))))))
7786
7787   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7788     "Place point where X-Face image is displayed."
7789     (if (featurep 'xemacs)
7790         (` (let ((end (if (search-forward "\n\n" nil t)
7791                           (goto-char (1- (point)))
7792                         (point-min)))
7793                  extent)
7794              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7795              (unless (and (re-search-forward "^From:" end t)
7796                           (setq extent (extent-at (point)))
7797                           (extent-begin-glyph extent))
7798                (goto-char (, opoint)))))
7799       (` (let ((end (if (search-forward "\n\n" nil t)
7800                         (goto-char (1- (point)))
7801                       (point-min)))
7802                (start (or (search-backward "\n\n" nil t) (point-min))))
7803            (goto-char
7804             (or (text-property-any start end 'x-face-image t);; x-face-e21
7805                 (text-property-any start end 'x-face-mule-bitmap-image t)
7806                 (, opoint)))))))
7807
7808   (defmacro gnus-summary-search-article-highlight-matched-text
7809     (backward treated x-face)
7810     "Highlight matched text in the function `gnus-summary-search-article'."
7811     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7812              (end (set-marker (make-marker) (match-end 0)))
7813              (inhibit-read-only t)
7814              buffer-read-only)
7815          (unless treated
7816            (let ((,@
7817                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7818                     (mapcar
7819                      (lambda (item) (setq items (delq item items)))
7820                      '(gnus-treat-buttonize
7821                        gnus-treat-fill-article
7822                        gnus-treat-fill-long-lines
7823                        gnus-treat-emphasize
7824                        gnus-treat-highlight-headers
7825                        gnus-treat-highlight-citation
7826                        gnus-treat-highlight-signature
7827                        gnus-treat-overstrike
7828                        gnus-treat-display-xface
7829                        gnus-treat-buttonize-head
7830                        gnus-treat-decode-article-as-default-mime-charset))
7831                     (static-if (featurep 'xemacs)
7832                         items
7833                       (cons '(x-face-mule-delete-x-face-field
7834                               (quote never))
7835                             items))))
7836                  (gnus-treat-display-xface
7837                   (when (, x-face) gnus-treat-display-xface)))
7838              (gnus-article-prepare-mime-display)))
7839          (goto-char (if (, backward) start end))
7840          (when (, x-face)
7841            (gnus-summary-search-article-highlight-goto-x-face (point)))
7842          (setq gnus-summary-search-article-matched-data
7843                (list start end (buffer-substring start end)))
7844          (unless (eq start end);; matched text has been deleted. :-<
7845            (put-text-property start end 'face
7846                               (or (find-face 'isearch)
7847                                   'secondary-selection))))))
7848   )
7849
7850 (defun gnus-summary-search-article (regexp &optional backward)
7851   "Search for an article containing REGEXP.
7852 Optional argument BACKWARD means do search for backward.
7853 `gnus-select-article-hook' is not called during the search."
7854   ;; We have to require this here to make sure that the following
7855   ;; dynamic binding isn't shadowed by autoloading.
7856   (require 'gnus-async)
7857   (require 'gnus-art)
7858   (let ((gnus-select-article-hook nil)  ;Disable hook.
7859         (gnus-article-prepare-hook nil)
7860         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7861         (gnus-use-article-prefetch nil)
7862         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7863         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7864         (sum (current-buffer))
7865         (found nil)
7866         point treated)
7867     (gnus-save-hidden-threads
7868       (static-if (featurep 'xemacs)
7869           (let ((gnus-inhibit-treatment t))
7870             (setq treated (eq 'old (gnus-summary-select-article)))
7871             (when (and treated
7872                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7873                                  (window-live-p (get-buffer-window
7874                                                  gnus-article-buffer t)))))
7875               (gnus-summary-select-article nil t)
7876               (setq treated nil)))
7877         (let ((gnus-inhibit-treatment t)
7878               (x-face-mule-delete-x-face-field 'never))
7879           (setq treated (eq 'old (gnus-summary-select-article)))
7880           (when (and treated
7881                      (not
7882                       (and (gnus-buffer-live-p gnus-article-buffer)
7883                            (window-live-p (get-buffer-window
7884                                            gnus-article-buffer t))
7885                            (or (not (string-match "^\\^X-Face:" regexp))
7886                                (with-current-buffer gnus-article-buffer
7887                                  gnus-summary-search-article-matched-data)))))
7888             (gnus-summary-select-article nil t)
7889             (setq treated nil))))
7890       (set-buffer gnus-article-buffer)
7891       (widen)
7892       (if treated
7893           (progn
7894             (gnus-article-show-all-headers)
7895             (gnus-summary-search-article-position-point regexp backward))
7896         (goto-char (if backward (point-max) (point-min))))
7897       (while (not found)
7898         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7899         (if (if backward
7900                 (re-search-backward regexp nil t)
7901               (re-search-forward regexp nil t))
7902             ;; We found the regexp.
7903             (progn
7904               (gnus-summary-search-article-highlight-matched-text
7905                backward treated (string-match "^\\^X-Face:" regexp))
7906               (setq found 'found)
7907               (forward-line
7908                (/ (- 2 (window-height
7909                         (get-buffer-window gnus-article-buffer t)))
7910                   2))
7911               (set-window-start
7912                (get-buffer-window (current-buffer))
7913                (point))
7914               (set-buffer sum)
7915               (setq point (point)))
7916           ;; We didn't find it, so we go to the next article.
7917           (set-buffer sum)
7918           (setq found 'not)
7919           (while (eq found 'not)
7920             (if (not (if backward (gnus-summary-find-prev)
7921                        (gnus-summary-find-next)))
7922                 ;; No more articles.
7923                 (setq found t)
7924               ;; Select the next article and adjust point.
7925               (unless (gnus-summary-article-sparse-p
7926                        (gnus-summary-article-number))
7927                 (setq found nil)
7928                 (let ((gnus-inhibit-treatment t))
7929                   (gnus-summary-select-article))
7930                 (setq treated nil)
7931                 (set-buffer gnus-article-buffer)
7932                 (widen)
7933                 (goto-char (if backward (point-max) (point-min))))))))
7934       (gnus-message 7 ""))
7935     ;; Return whether we found the regexp.
7936     (when (eq found 'found)
7937       (goto-char point)
7938       (gnus-summary-show-thread)
7939       (gnus-summary-goto-subject gnus-current-article)
7940       (gnus-summary-position-point)
7941       t)))
7942
7943 (defun gnus-find-matching-articles (header regexp)
7944   "Return a list of all articles that match REGEXP on HEADER.
7945 This search includes all articles in the current group that Gnus has
7946 fetched headers for, whether they are displayed or not."
7947   (let ((articles nil)
7948         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7949         (case-fold-search t))
7950     (dolist (header gnus-newsgroup-headers)
7951       (when (string-match regexp (funcall func header))
7952         (push (mail-header-number header) articles)))
7953     (nreverse articles)))
7954
7955 (defun gnus-summary-find-matching (header regexp &optional backward unread
7956                                           not-case-fold not-matching)
7957   "Return a list of all articles that match REGEXP on HEADER.
7958 The search stars on the current article and goes forwards unless
7959 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7960 If UNREAD is non-nil, only unread articles will
7961 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7962 in the comparisons. If NOT-MATCHING, return a list of all articles that
7963 not match REGEXP on HEADER."
7964   (let ((case-fold-search (not not-case-fold))
7965         articles d func)
7966     (if (consp header)
7967         (if (eq (car header) 'extra)
7968             (setq func
7969                   `(lambda (h)
7970                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7971                          "")))
7972           (error "%s is an invalid header" header))
7973       (unless (fboundp (intern (concat "mail-header-" header)))
7974         (error "%s is not a valid header" header))
7975       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7976     (dolist (d (if (eq backward 'all)
7977                    gnus-newsgroup-data
7978                  (gnus-data-find-list
7979                   (gnus-summary-article-number)
7980                   (gnus-data-list backward))))
7981       (when (and (or (not unread)       ; We want all articles...
7982                      (gnus-data-unread-p d)) ; Or just unreads.
7983                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7984                  (if not-matching
7985                      (not (string-match
7986                            regexp
7987                            (funcall func (gnus-data-header d))))
7988                    (string-match regexp
7989                                  (funcall func (gnus-data-header d)))))
7990         (push (gnus-data-number d) articles))) ; Success!
7991     (nreverse articles)))
7992
7993 (defun gnus-summary-execute-command (header regexp command &optional backward)
7994   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7995 If HEADER is an empty string (or nil), the match is done on the entire
7996 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7997   (interactive
7998    (list (let ((completion-ignore-case t))
7999            (completing-read
8000             "Header name: "
8001             (mapcar (lambda (header) (list (format "%s" header)))
8002                     (append
8003                      '("Number" "Subject" "From" "Lines" "Date"
8004                        "Message-ID" "Xref" "References" "Body")
8005                      gnus-extra-headers))
8006             nil 'require-match))
8007          (read-string "Regexp: ")
8008          (read-key-sequence "Command: ")
8009          current-prefix-arg))
8010   (when (equal header "Body")
8011     (setq header ""))
8012   ;; Hidden thread subtrees must be searched as well.
8013   (gnus-summary-show-all-threads)
8014   ;; We don't want to change current point nor window configuration.
8015   (save-excursion
8016     (save-window-excursion
8017       (gnus-message 6 "Executing %s..." (key-description command))
8018       ;; We'd like to execute COMMAND interactively so as to give arguments.
8019       (gnus-execute header regexp
8020                     `(call-interactively ',(key-binding command))
8021                     backward)
8022       (gnus-message 6 "Executing %s...done" (key-description command)))))
8023
8024 (defun gnus-summary-beginning-of-article ()
8025   "Scroll the article back to the beginning."
8026   (interactive)
8027   (gnus-summary-select-article)
8028   (gnus-configure-windows 'article)
8029   (gnus-eval-in-buffer-window gnus-article-buffer
8030     (widen)
8031     (goto-char (point-min))
8032     (when gnus-page-broken
8033       (gnus-narrow-to-page))))
8034
8035 (defun gnus-summary-end-of-article ()
8036   "Scroll to the end of the article."
8037   (interactive)
8038   (gnus-summary-select-article)
8039   (gnus-configure-windows 'article)
8040   (gnus-eval-in-buffer-window gnus-article-buffer
8041     (widen)
8042     (goto-char (point-max))
8043     (recenter -3)
8044     (when gnus-page-broken
8045       (gnus-narrow-to-page))))
8046
8047 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8048   "Truncate to LEN and quote all \"(\"'s in STRING."
8049   (gnus-replace-in-string (if (and len (> (length string) len))
8050                               (substring string 0 len)
8051                             string)
8052                           "[()]" "\\\\\\&"))
8053
8054 (defun gnus-summary-print-article (&optional filename n)
8055   "Generate and print a PostScript image of the N next (mail) articles.
8056
8057 If N is negative, print the N previous articles.  If N is nil and articles
8058 have been marked with the process mark, print these instead.
8059
8060 If the optional first argument FILENAME is nil, send the image to the
8061 printer.  If FILENAME is a string, save the PostScript image in a file with
8062 that name.  If FILENAME is a number, prompt the user for the name of the file
8063 to save in."
8064   (interactive (list (ps-print-preprint current-prefix-arg)))
8065   (dolist (article (gnus-summary-work-articles n))
8066     (gnus-summary-select-article nil nil 'pseudo article)
8067     (gnus-eval-in-buffer-window gnus-article-buffer
8068       (gnus-print-buffer))
8069     (gnus-summary-remove-process-mark article))
8070   (ps-despool filename))
8071
8072 (defun gnus-print-buffer ()
8073   (let ((buffer (generate-new-buffer " *print*")))
8074     (unwind-protect
8075         (progn
8076           (copy-to-buffer buffer (point-min) (point-max))
8077           (set-buffer buffer)
8078           (gnus-article-delete-invisible-text)
8079           (when (gnus-visual-p 'article-highlight 'highlight)
8080             ;; Copy-to-buffer doesn't copy overlay.  So redo
8081             ;; highlight.
8082             (let ((gnus-article-buffer buffer))
8083               (gnus-article-highlight-citation t)
8084               (gnus-article-highlight-signature)))
8085           (let ((ps-left-header
8086                  (list
8087                   (concat "("
8088                           (gnus-summary-print-truncate-and-quote
8089                            (mail-header-subject gnus-current-headers)
8090                            66) ")")
8091                   (concat "("
8092                           (gnus-summary-print-truncate-and-quote
8093                            (mail-header-from gnus-current-headers)
8094                            45) ")")))
8095                 (ps-right-header
8096                  (list
8097                   "/pagenumberstring load"
8098                   (concat "("
8099                           (mail-header-date gnus-current-headers) ")"))))
8100             (gnus-run-hooks 'gnus-ps-print-hook)
8101             (save-excursion
8102               (if window-system
8103                   (ps-spool-buffer-with-faces)
8104                 (ps-spool-buffer)))))
8105       (kill-buffer buffer))))
8106
8107 (defun gnus-summary-show-article (&optional arg)
8108   "Force redisplaying of the current article.
8109 If ARG (the prefix) is a number, show the article with the charset
8110 defined in `gnus-summary-show-article-charset-alist', or the charset
8111 input.
8112 If ARG (the prefix) is non-nil and not a number, show the raw article
8113 without any article massaging functions being run.  Normally, the key strokes
8114 are `C-u g'."
8115   (interactive "P")
8116   (cond
8117    ((numberp arg)
8118     (gnus-summary-show-article t)
8119     (let ((gnus-newsgroup-charset
8120            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8121                (mm-read-coding-system
8122                 "View as charset: "
8123                 (save-excursion
8124                   (set-buffer gnus-article-buffer)
8125                   (let ((coding-systems
8126                          (detect-coding-region (point) (point-max))))
8127                     (or (car-safe coding-systems)
8128                         coding-systems))))))
8129           (gnus-newsgroup-ignored-charsets 'gnus-all))
8130       (gnus-summary-select-article nil 'force)
8131       (let ((deps gnus-newsgroup-dependencies)
8132             head header lines)
8133         (save-excursion
8134           (set-buffer gnus-original-article-buffer)
8135           (save-restriction
8136             (message-narrow-to-head)
8137             (setq head (buffer-string))
8138             (goto-char (point-min))
8139             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8140               (goto-char (point-max))
8141               (widen)
8142               (setq lines (1- (count-lines (point) (point-max))))))
8143           (with-temp-buffer
8144             (insert (format "211 %d Article retrieved.\n"
8145                             (cdr gnus-article-current)))
8146             (insert head)
8147             (if lines (insert (format "Lines: %d\n" lines)))
8148             (insert ".\n")
8149             (let ((nntp-server-buffer (current-buffer)))
8150               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8151         (gnus-data-set-header
8152          (gnus-data-find (cdr gnus-article-current))
8153          header)
8154         (gnus-summary-update-article-line
8155          (cdr gnus-article-current) header)
8156         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8157           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8158    ((not arg)
8159     ;; Select the article the normal way.
8160     (gnus-summary-select-article nil 'force))
8161    (t
8162     ;; We have to require this here to make sure that the following
8163     ;; dynamic binding isn't shadowed by autoloading.
8164     (require 'gnus-async)
8165     (require 'gnus-art)
8166     ;; Bind the article treatment functions to nil.
8167     (let ((gnus-have-all-headers t)
8168           gnus-article-prepare-hook
8169           gnus-article-decode-hook
8170           gnus-break-pages
8171           gnus-show-mime
8172           (gnus-inhibit-treatment t))
8173       (gnus-summary-select-article nil 'force))))
8174   (gnus-summary-goto-subject gnus-current-article)
8175   (gnus-summary-position-point))
8176
8177 (defun gnus-summary-show-raw-article ()
8178   "Show the raw article without any article massaging functions being run."
8179   (interactive)
8180   (gnus-summary-show-article t))
8181
8182 (defun gnus-summary-verbose-headers (&optional arg)
8183   "Toggle permanent full header display.
8184 If ARG is a positive number, turn header display on.
8185 If ARG is a negative number, turn header display off."
8186   (interactive "P")
8187   (setq gnus-show-all-headers
8188         (cond ((or (not (numberp arg))
8189                    (zerop arg))
8190                (not gnus-show-all-headers))
8191               ((natnump arg)
8192                t)))
8193   (gnus-summary-show-article))
8194
8195 (defun gnus-summary-toggle-header (&optional arg)
8196   "Show the headers if they are hidden, or hide them if they are shown.
8197 If ARG is a positive number, show the entire header.
8198 If ARG is a negative number, hide the unwanted header lines."
8199   (interactive "P")
8200   (save-excursion
8201     (set-buffer gnus-article-buffer)
8202     (save-restriction
8203       (let* ((buffer-read-only nil)
8204              (inhibit-point-motion-hooks t)
8205              hidden e)
8206         (setq hidden
8207               (if (numberp arg)
8208                   (>= arg 0)
8209                 (save-restriction
8210                   (article-narrow-to-head)
8211                   (gnus-article-hidden-text-p 'headers))))
8212         (goto-char (point-min))
8213         (when (search-forward "\n\n" nil t)
8214           (delete-region (point-min) (1- (point))))
8215         (goto-char (point-min))
8216         (save-excursion
8217           (set-buffer gnus-original-article-buffer)
8218           (goto-char (point-min))
8219           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8220         (insert-buffer-substring gnus-original-article-buffer 1 e)
8221         (save-restriction
8222           (narrow-to-region (point-min) (point))
8223           (article-decode-encoded-words)
8224           (if  hidden
8225               (let ((gnus-treat-hide-headers nil)
8226                     (gnus-treat-hide-boring-headers nil))
8227                 (gnus-delete-wash-type 'headers)
8228                 (gnus-treat-article 'head))
8229             (gnus-treat-article 'head)))
8230         (gnus-set-mode-line 'article)))))
8231
8232 (defun gnus-summary-show-all-headers ()
8233   "Make all header lines visible."
8234   (interactive)
8235   (gnus-summary-toggle-header 1))
8236
8237 (defun gnus-summary-toggle-mime (&optional arg)
8238   "Toggle MIME processing.
8239 If ARG is a positive number, turn MIME processing on."
8240   (interactive "P")
8241   (setq gnus-show-mime
8242         (if (null arg)
8243             (not gnus-show-mime)
8244           (> (prefix-numeric-value arg) 0)))
8245   (gnus-summary-select-article t 'force))
8246
8247 (defun gnus-summary-caesar-message (&optional arg)
8248   "Caesar rotate the current article by 13.
8249 The numerical prefix specifies how many places to rotate each letter
8250 forward."
8251   (interactive "P")
8252   (gnus-summary-select-article)
8253   (let ((mail-header-separator ""))
8254     (gnus-eval-in-buffer-window gnus-article-buffer
8255       (save-restriction
8256         (widen)
8257         (let ((start (window-start))
8258               buffer-read-only)
8259           (message-caesar-buffer-body arg)
8260           (set-window-start (get-buffer-window (current-buffer)) start))))))
8261
8262 (defun gnus-summary-stop-page-breaking ()
8263   "Stop page breaking in the current article."
8264   (interactive)
8265   (gnus-summary-select-article)
8266   (gnus-eval-in-buffer-window gnus-article-buffer
8267     (widen)
8268     (when (gnus-visual-p 'page-marker)
8269       (let ((buffer-read-only nil))
8270         (gnus-remove-text-with-property 'gnus-prev)
8271         (gnus-remove-text-with-property 'gnus-next))
8272       (setq gnus-page-broken nil))))
8273
8274 (defun gnus-summary-move-article (&optional n to-newsgroup
8275                                             select-method action)
8276   "Move the current article to a different newsgroup.
8277 If N is a positive number, move the N next articles.
8278 If N is a negative number, move the N previous articles.
8279 If N is nil and any articles have been marked with the process mark,
8280 move those articles instead.
8281 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8282 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8283 re-spool using this method.
8284
8285 For this function to work, both the current newsgroup and the
8286 newsgroup that you want to move to have to support the `request-move'
8287 and `request-accept' functions.
8288
8289 ACTION can be either `move' (the default), `crosspost' or `copy'."
8290   (interactive "P")
8291   (unless action
8292     (setq action 'move))
8293   ;; Check whether the source group supports the required functions.
8294   (cond ((and (eq action 'move)
8295               (not (gnus-check-backend-function
8296                     'request-move-article gnus-newsgroup-name)))
8297          (error "The current group does not support article moving"))
8298         ((and (eq action 'crosspost)
8299               (not (gnus-check-backend-function
8300                     'request-replace-article gnus-newsgroup-name)))
8301          (error "The current group does not support article editing")))
8302   (let ((articles (gnus-summary-work-articles n))
8303         (prefix (if (gnus-check-backend-function
8304                      'request-move-article gnus-newsgroup-name)
8305                     (gnus-group-real-prefix gnus-newsgroup-name)
8306                   ""))
8307         (names '((move "Move" "Moving")
8308                  (copy "Copy" "Copying")
8309                  (crosspost "Crosspost" "Crossposting")))
8310         (copy-buf (save-excursion
8311                     (nnheader-set-temp-buffer " *copy article*")))
8312         (default-marks gnus-article-mark-lists)
8313         (no-expire-marks (delete '(expirable . expire)
8314                                  (copy-sequence gnus-article-mark-lists)))
8315         art-group to-method new-xref article to-groups)
8316     (unless (assq action names)
8317       (error "Unknown action %s" action))
8318     ;; We have to select an article to give
8319     ;; `gnus-read-move-group-name' an opportunity to suggest an
8320     ;; appropriate default.
8321     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8322       (gnus-summary-select-article nil nil nil (car articles)))
8323     ;; Read the newsgroup name.
8324     (when (and (not to-newsgroup)
8325                (not select-method))
8326       (setq to-newsgroup
8327             (gnus-read-move-group-name
8328              (cadr (assq action names))
8329              (symbol-value (intern (format "gnus-current-%s-group" action)))
8330              articles prefix))
8331       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8332     (setq to-method (or select-method
8333                         (gnus-server-to-method
8334                          (gnus-group-method to-newsgroup))))
8335     ;; Check the method we are to move this article to...
8336     (unless (gnus-check-backend-function
8337              'request-accept-article (car to-method))
8338       (error "%s does not support article copying" (car to-method)))
8339     (unless (gnus-check-server to-method)
8340       (error "Can't open server %s" (car to-method)))
8341     (gnus-message 6 "%s to %s: %s..."
8342                   (caddr (assq action names))
8343                   (or (car select-method) to-newsgroup) articles)
8344     (while articles
8345       (setq article (pop articles))
8346       (setq
8347        art-group
8348        (cond
8349         ;; Move the article.
8350         ((eq action 'move)
8351          ;; Remove this article from future suppression.
8352          (gnus-dup-unsuppress-article article)
8353          (gnus-request-move-article
8354           article                       ; Article to move
8355           gnus-newsgroup-name           ; From newsgroup
8356           (nth 1 (gnus-find-method-for-group
8357                   gnus-newsgroup-name)) ; Server
8358           (list 'gnus-request-accept-article
8359                 to-newsgroup (list 'quote select-method)
8360                 (not articles) t)       ; Accept form
8361           (not articles)))              ; Only save nov last time
8362         ;; Copy the article.
8363         ((eq action 'copy)
8364          (save-excursion
8365            (set-buffer copy-buf)
8366            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8367              (gnus-request-accept-article
8368               to-newsgroup select-method (not articles) t))))
8369         ;; Crosspost the article.
8370         ((eq action 'crosspost)
8371          (let ((xref (message-tokenize-header
8372                       (mail-header-xref (gnus-summary-article-header article))
8373                       " ")))
8374            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8375                                   ":" (number-to-string article)))
8376            (unless xref
8377              (setq xref (list (system-name))))
8378            (setq new-xref
8379                  (concat
8380                   (mapconcat 'identity
8381                              (delete "Xref:" (delete new-xref xref))
8382                              " ")
8383                   " " new-xref))
8384            (save-excursion
8385              (set-buffer copy-buf)
8386              ;; First put the article in the destination group.
8387              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8388              (when (consp (setq art-group
8389                                 (gnus-request-accept-article
8390                                  to-newsgroup select-method (not articles))))
8391                (setq new-xref (concat new-xref " " (car art-group)
8392                                       ":"
8393                                       (number-to-string (cdr art-group))))
8394                ;; Now we have the new Xrefs header, so we insert
8395                ;; it and replace the new article.
8396                (nnheader-replace-header "Xref" new-xref)
8397                (gnus-request-replace-article
8398                 (cdr art-group) to-newsgroup (current-buffer))
8399                art-group))))))
8400       (cond
8401        ((not art-group)
8402         (gnus-message 1 "Couldn't %s article %s: %s"
8403                       (cadr (assq action names)) article
8404                       (nnheader-get-report (car to-method))))
8405        ((eq art-group 'junk)
8406         (when (eq action 'move)
8407           (gnus-summary-mark-article article gnus-canceled-mark)
8408           (gnus-message 4 "Deleted article %s" article)))
8409        (t
8410         (let* ((pto-group (gnus-group-prefixed-name
8411                            (car art-group) to-method))
8412                (entry
8413                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8414                (info (nth 2 entry))
8415                (to-group (gnus-info-group info))
8416                to-marks)
8417           ;; Update the group that has been moved to.
8418           (when (and info
8419                      (memq action '(move copy)))
8420             (unless (member to-group to-groups)
8421               (push to-group to-groups))
8422
8423             (unless (memq article gnus-newsgroup-unreads)
8424               (push 'read to-marks)
8425               (gnus-info-set-read
8426                info (gnus-add-to-range (gnus-info-read info)
8427                                        (list (cdr art-group)))))
8428
8429             ;; See whether the article is to be put in the cache.
8430             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8431                              default-marks
8432                            no-expire-marks))
8433                   (to-article (cdr art-group)))
8434
8435               ;; Enter the article into the cache in the new group,
8436               ;; if that is required.
8437               (when gnus-use-cache
8438                 (gnus-cache-possibly-enter-article
8439                  to-group to-article
8440                  (let ((header (copy-sequence
8441                                 (gnus-summary-article-header article))))
8442                    (mail-header-set-number header to-article)
8443                    header)
8444                  (memq article gnus-newsgroup-marked)
8445                  (memq article gnus-newsgroup-dormant)
8446                  (memq article gnus-newsgroup-unreads)))
8447
8448               (when gnus-preserve-marks
8449                 ;; Copy any marks over to the new group.
8450                 (when (and (equal to-group gnus-newsgroup-name)
8451                            (not (memq article gnus-newsgroup-unreads)))
8452                   ;; Mark this article as read in this group.
8453                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8454                   (setcdr (gnus-active to-group) to-article)
8455                   (setcdr gnus-newsgroup-active to-article))
8456
8457                 (while marks
8458                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8459                     (when (memq article (symbol-value
8460                                          (intern (format "gnus-newsgroup-%s"
8461                                                          (caar marks)))))
8462                       (push (cdar marks) to-marks)
8463                       ;; If the other group is the same as this group,
8464                       ;; then we have to add the mark to the list.
8465                       (when (equal to-group gnus-newsgroup-name)
8466                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8467                              (cons to-article
8468                                    (symbol-value
8469                                     (intern (format "gnus-newsgroup-%s"
8470                                                     (caar marks)))))))
8471                       ;; Copy the marks to other group.
8472                       (gnus-add-marked-articles
8473                        to-group (cdar marks) (list to-article) info)))
8474                   (setq marks (cdr marks)))
8475
8476                 (gnus-request-set-mark to-group (list (list (list to-article)
8477                                                             'add
8478                                                             to-marks))))
8479
8480               (gnus-dribble-enter
8481                (concat "(gnus-group-set-info '"
8482                        (gnus-prin1-to-string (gnus-get-info to-group))
8483                        ")"))))
8484
8485           ;; Update the Xref header in this article to point to
8486           ;; the new crossposted article we have just created.
8487           (when (eq action 'crosspost)
8488             (save-excursion
8489               (set-buffer copy-buf)
8490               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8491               (nnheader-replace-header "Xref" new-xref)
8492               (gnus-request-replace-article
8493                article gnus-newsgroup-name (current-buffer)))))
8494
8495         ;;;!!!Why is this necessary?
8496         (set-buffer gnus-summary-buffer)
8497
8498         (gnus-summary-goto-subject article)
8499         (when (eq action 'move)
8500           (gnus-summary-mark-article article gnus-canceled-mark))))
8501       (gnus-summary-remove-process-mark article))
8502     ;; Re-activate all groups that have been moved to.
8503     (save-excursion
8504       (set-buffer gnus-group-buffer)
8505       (let ((gnus-group-marked to-groups))
8506         (gnus-group-get-new-news-this-group nil t)))
8507
8508     (gnus-kill-buffer copy-buf)
8509     (gnus-summary-position-point)
8510     (gnus-set-mode-line 'summary)))
8511
8512 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8513   "Move the current article to a different newsgroup.
8514 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8515 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8516 re-spool using this method."
8517   (interactive "P")
8518   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8519
8520 (defun gnus-summary-crosspost-article (&optional n)
8521   "Crosspost the current article to some other group."
8522   (interactive "P")
8523   (gnus-summary-move-article n nil nil 'crosspost))
8524
8525 (defcustom gnus-summary-respool-default-method nil
8526   "Default method type for respooling an article.
8527 If nil, use to the current newsgroup method."
8528   :type 'symbol
8529   :group 'gnus-summary-mail)
8530
8531 (defun gnus-summary-respool-article (&optional n method)
8532   "Respool the current article.
8533 The article will be squeezed through the mail spooling process again,
8534 which means that it will be put in some mail newsgroup or other
8535 depending on `nnmail-split-methods'.
8536 If N is a positive number, respool the N next articles.
8537 If N is a negative number, respool the N previous articles.
8538 If N is nil and any articles have been marked with the process mark,
8539 respool those articles instead.
8540
8541 Respooling can be done both from mail groups and \"real\" newsgroups.
8542 In the former case, the articles in question will be moved from the
8543 current group into whatever groups they are destined to.  In the
8544 latter case, they will be copied into the relevant groups."
8545   (interactive
8546    (list current-prefix-arg
8547          (let* ((methods (gnus-methods-using 'respool))
8548                 (methname
8549                  (symbol-name (or gnus-summary-respool-default-method
8550                                   (car (gnus-find-method-for-group
8551                                         gnus-newsgroup-name)))))
8552                 (method
8553                  (gnus-completing-read
8554                   methname "What backend do you want to use when respooling?"
8555                   methods nil t nil 'gnus-mail-method-history))
8556                 ms)
8557            (cond
8558             ((zerop (length (setq ms (gnus-servers-using-backend
8559                                       (intern method)))))
8560              (list (intern method) ""))
8561             ((= 1 (length ms))
8562              (car ms))
8563             (t
8564              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8565                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8566                            ms-alist))))))))
8567   (unless method
8568     (error "No method given for respooling"))
8569   (if (assoc (symbol-name
8570               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8571              (gnus-methods-using 'respool))
8572       (gnus-summary-move-article n nil method)
8573     (gnus-summary-copy-article n nil method)))
8574
8575 (defun gnus-summary-import-article (file &optional edit)
8576   "Import an arbitrary file into a mail newsgroup."
8577   (interactive "fImport file: \nP")
8578   (let ((group gnus-newsgroup-name)
8579         (now (current-time))
8580         atts lines group-art)
8581     (unless (gnus-check-backend-function 'request-accept-article group)
8582       (error "%s does not support article importing" group))
8583     (or (file-readable-p file)
8584         (not (file-regular-p file))
8585         (error "Can't read %s" file))
8586     (save-excursion
8587       (set-buffer (gnus-get-buffer-create " *import file*"))
8588       (erase-buffer)
8589       (nnheader-insert-file-contents file)
8590       (goto-char (point-min))
8591       (if (nnheader-article-p)
8592           (save-restriction
8593             (goto-char (point-min))
8594             (search-forward "\n\n" nil t)
8595             (narrow-to-region (point-min) (1- (point)))
8596             (goto-char (point-min))
8597             (unless (re-search-forward "^date:" nil t)
8598               (goto-char (point-max))
8599               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8600         ;; This doesn't look like an article, so we fudge some headers.
8601         (setq atts (file-attributes file)
8602               lines (count-lines (point-min) (point-max)))
8603         (insert "From: " (read-string "From: ") "\n"
8604                 "Subject: " (read-string "Subject: ") "\n"
8605                 "Date: " (message-make-date (nth 5 atts)) "\n"
8606                 "Message-ID: " (message-make-message-id) "\n"
8607                 "Lines: " (int-to-string lines) "\n"
8608                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8609       (setq group-art (gnus-request-accept-article group nil t))
8610       (kill-buffer (current-buffer)))
8611     (setq gnus-newsgroup-active (gnus-activate-group group))
8612     (forward-line 1)
8613     (gnus-summary-goto-article (cdr group-art) nil t)
8614     (when edit
8615       (gnus-summary-edit-article))))
8616
8617 (defun gnus-summary-create-article ()
8618   "Create an article in a mail newsgroup."
8619   (interactive)
8620   (let ((group gnus-newsgroup-name)
8621         (now (current-time))
8622         group-art)
8623     (unless (gnus-check-backend-function 'request-accept-article group)
8624       (error "%s does not support article importing" group))
8625     (save-excursion
8626       (set-buffer (gnus-get-buffer-create " *import file*"))
8627       (erase-buffer)
8628       (goto-char (point-min))
8629       ;; This doesn't look like an article, so we fudge some headers.
8630       (insert "From: " (read-string "From: ") "\n"
8631               "Subject: " (read-string "Subject: ") "\n"
8632               "Date: " (message-make-date now) "\n"
8633               "Message-ID: " (message-make-message-id) "\n")
8634       (setq group-art (gnus-request-accept-article group nil t))
8635       (kill-buffer (current-buffer)))
8636     (setq gnus-newsgroup-active (gnus-activate-group group))
8637     (forward-line 1)
8638     (gnus-summary-goto-article (cdr group-art) nil t)
8639     (gnus-summary-edit-article)))
8640
8641 (defun gnus-summary-article-posted-p ()
8642   "Say whether the current (mail) article is available from news as well.
8643 This will be the case if the article has both been mailed and posted."
8644   (interactive)
8645   (let ((id (mail-header-references (gnus-summary-article-header)))
8646         (gnus-override-method (car (gnus-refer-article-methods))))
8647     (if (gnus-request-head id "")
8648         (gnus-message 2 "The current message was found on %s"
8649                       gnus-override-method)
8650       (gnus-message 2 "The current message couldn't be found on %s"
8651                     gnus-override-method)
8652       nil)))
8653
8654 (defun gnus-summary-expire-articles (&optional now)
8655   "Expire all articles that are marked as expirable in the current group."
8656   (interactive)
8657   (when (gnus-check-backend-function
8658          'request-expire-articles gnus-newsgroup-name)
8659     ;; This backend supports expiry.
8660     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8661            (expirable (if total
8662                           (progn
8663                             ;; We need to update the info for
8664                             ;; this group for `gnus-list-of-read-articles'
8665                             ;; to give us the right answer.
8666                             (gnus-run-hooks 'gnus-exit-group-hook)
8667                             (gnus-summary-update-info)
8668                             (gnus-list-of-read-articles gnus-newsgroup-name))
8669                         (setq gnus-newsgroup-expirable
8670                               (sort gnus-newsgroup-expirable '<))))
8671            (expiry-wait (if now 'immediate
8672                           (gnus-group-find-parameter
8673                            gnus-newsgroup-name 'expiry-wait)))
8674            (nnmail-expiry-target
8675             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8676                 nnmail-expiry-target))
8677            es)
8678       (when expirable
8679         ;; There are expirable articles in this group, so we run them
8680         ;; through the expiry process.
8681         (gnus-message 6 "Expiring articles...")
8682         (unless (gnus-check-group gnus-newsgroup-name)
8683           (error "Can't open server for %s" gnus-newsgroup-name))
8684         ;; The list of articles that weren't expired is returned.
8685         (save-excursion
8686           (if expiry-wait
8687               (let ((nnmail-expiry-wait-function nil)
8688                     (nnmail-expiry-wait expiry-wait))
8689                 (setq es (gnus-request-expire-articles
8690                           expirable gnus-newsgroup-name)))
8691             (setq es (gnus-request-expire-articles
8692                       expirable gnus-newsgroup-name)))
8693           (unless total
8694             (setq gnus-newsgroup-expirable es))
8695           ;; We go through the old list of expirable, and mark all
8696           ;; really expired articles as nonexistent.
8697           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8698             (let ((gnus-use-cache nil))
8699               (while expirable
8700                 (unless (memq (car expirable) es)
8701                   (when (gnus-data-find (car expirable))
8702                     (gnus-summary-mark-article
8703                      (car expirable) gnus-canceled-mark)))
8704                 (setq expirable (cdr expirable))))))
8705         (gnus-message 6 "Expiring articles...done")))))
8706
8707 (defun gnus-summary-expire-articles-now ()
8708   "Expunge all expirable articles in the current group.
8709 This means that *all* articles that are marked as expirable will be
8710 deleted forever, right now."
8711   (interactive)
8712   (or gnus-expert-user
8713       (gnus-yes-or-no-p
8714        "Are you really, really, really sure you want to delete all these messages? ")
8715       (error "Phew!"))
8716   (gnus-summary-expire-articles t))
8717
8718 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8719 (defun gnus-summary-delete-article (&optional n)
8720   "Delete the N next (mail) articles.
8721 This command actually deletes articles.  This is not a marking
8722 command.  The article will disappear forever from your life, never to
8723 return.
8724 If N is negative, delete backwards.
8725 If N is nil and articles have been marked with the process mark,
8726 delete these instead."
8727   (interactive "P")
8728   (unless (gnus-check-backend-function 'request-expire-articles
8729                                        gnus-newsgroup-name)
8730     (error "The current newsgroup does not support article deletion"))
8731   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8732     (error "Couldn't open server"))
8733   ;; Compute the list of articles to delete.
8734   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8735         not-deleted)
8736     (if (and gnus-novice-user
8737              (not (gnus-yes-or-no-p
8738                    (format "Do you really want to delete %s forever? "
8739                            (if (> (length articles) 1)
8740                                (format "these %s articles" (length articles))
8741                              "this article")))))
8742         ()
8743       ;; Delete the articles.
8744       (setq not-deleted (gnus-request-expire-articles
8745                          articles gnus-newsgroup-name 'force))
8746       (while articles
8747         (gnus-summary-remove-process-mark (car articles))
8748         ;; The backend might not have been able to delete the article
8749         ;; after all.
8750         (unless (memq (car articles) not-deleted)
8751           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8752         (setq articles (cdr articles)))
8753       (when not-deleted
8754         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8755     (gnus-summary-position-point)
8756     (gnus-set-mode-line 'summary)
8757     not-deleted))
8758
8759 (defun gnus-summary-edit-article (&optional force)
8760   "Edit the current article.
8761 This will have permanent effect only in mail groups.
8762 If FORCE is non-nil, allow editing of articles even in read-only
8763 groups."
8764   (interactive "P")
8765   (save-excursion
8766     (set-buffer gnus-summary-buffer)
8767     (let ((mail-parse-charset gnus-newsgroup-charset)
8768           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8769       (gnus-set-global-variables)
8770       (when (and (not force)
8771                  (gnus-group-read-only-p))
8772         (error "The current newsgroup does not support article editing"))
8773       (gnus-summary-show-article t)
8774       (gnus-article-edit-article
8775        'ignore
8776        `(lambda (no-highlight)
8777           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8778                 (message-options message-options)
8779                 (message-options-set-recipient)
8780                 (mail-parse-ignored-charsets
8781                  ',gnus-newsgroup-ignored-charsets))
8782             (gnus-summary-edit-article-done
8783              ,(or (mail-header-references gnus-current-headers) "")
8784              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8785
8786 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8787
8788 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8789                                                  no-highlight)
8790   "Make edits to the current article permanent."
8791   (interactive)
8792   (save-excursion
8793     ;; The buffer restriction contains the entire article if it exists.
8794     (when (article-goto-body)
8795       (let ((lines (count-lines (point) (point-max)))
8796             (length (- (point-max) (point)))
8797             (case-fold-search t)
8798             (body (copy-marker (point))))
8799         (goto-char (point-min))
8800         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8801           (delete-region (match-beginning 1) (match-end 1))
8802           (insert (number-to-string length)))
8803         (goto-char (point-min))
8804         (when (re-search-forward
8805                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8806           (delete-region (match-beginning 1) (match-end 1))
8807           (insert (number-to-string length)))
8808         (goto-char (point-min))
8809         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8810           (delete-region (match-beginning 1) (match-end 1))
8811           (insert (number-to-string lines))))))
8812   ;; Replace the article.
8813   (let ((buf (current-buffer)))
8814     (with-temp-buffer
8815       (insert-buffer-substring buf)
8816
8817       (if (and (not read-only)
8818                (not (gnus-request-replace-article
8819                      (cdr gnus-article-current) (car gnus-article-current)
8820                      (current-buffer) t)))
8821           (error "Couldn't replace article")
8822         ;; Update the summary buffer.
8823         (if (and references
8824                  (equal (message-tokenize-header references " ")
8825                         (message-tokenize-header
8826                          (or (message-fetch-field "references") "") " ")))
8827             ;; We only have to update this line.
8828             (save-excursion
8829               (save-restriction
8830                 (message-narrow-to-head)
8831                 (let ((head (buffer-string))
8832                       header)
8833                   (with-temp-buffer
8834                     (insert (format "211 %d Article retrieved.\n"
8835                                     (cdr gnus-article-current)))
8836                     (insert head)
8837                     (insert ".\n")
8838                     (let ((nntp-server-buffer (current-buffer)))
8839                       (setq header (car (gnus-get-newsgroup-headers
8840                                          (save-excursion
8841                                            (set-buffer gnus-summary-buffer)
8842                                            gnus-newsgroup-dependencies)
8843                                          t))))
8844                     (save-excursion
8845                       (set-buffer gnus-summary-buffer)
8846                       (gnus-data-set-header
8847                        (gnus-data-find (cdr gnus-article-current))
8848                        header)
8849                       (gnus-summary-update-article-line
8850                        (cdr gnus-article-current) header)
8851                       (if (gnus-summary-goto-subject
8852                            (cdr gnus-article-current) nil t)
8853                           (gnus-summary-update-secondary-mark
8854                            (cdr gnus-article-current))))))))
8855           ;; Update threads.
8856           (set-buffer (or buffer gnus-summary-buffer))
8857           (gnus-summary-update-article (cdr gnus-article-current))
8858           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8859               (gnus-summary-update-secondary-mark
8860                (cdr gnus-article-current))))
8861         ;; Prettify the article buffer again.
8862         (unless no-highlight
8863           (save-excursion
8864             (set-buffer gnus-article-buffer)
8865             ;;;!!! Fix this -- article should be rehighlighted.
8866             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8867             (set-buffer gnus-original-article-buffer)
8868             (gnus-request-article
8869              (cdr gnus-article-current)
8870              (car gnus-article-current) (current-buffer))))
8871         ;; Prettify the summary buffer line.
8872         (when (gnus-visual-p 'summary-highlight 'highlight)
8873           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8874
8875 (defun gnus-summary-edit-wash (key)
8876   "Perform editing command KEY in the article buffer."
8877   (interactive
8878    (list
8879     (progn
8880       (message "%s" (concat (this-command-keys) "- "))
8881       (read-char))))
8882   (message "")
8883   (gnus-summary-edit-article)
8884   (execute-kbd-macro (concat (this-command-keys) key))
8885   (gnus-article-edit-done))
8886
8887 (defun gnus-summary-toggle-smiley (&optional arg)
8888   "Toggle the display of smilies as small graphical icons."
8889   (interactive "P")
8890   (save-excursion
8891     (set-buffer gnus-article-buffer)
8892     (gnus-article-smiley-display arg)))
8893
8894 ;;; Respooling
8895
8896 (defun gnus-summary-respool-query (&optional silent trace)
8897   "Query where the respool algorithm would put this article."
8898   (interactive)
8899   (let (gnus-mark-article-hook)
8900     (gnus-summary-select-article)
8901     (save-excursion
8902       (set-buffer gnus-original-article-buffer)
8903       (save-restriction
8904         (message-narrow-to-head)
8905         (let ((groups (nnmail-article-group 'identity trace)))
8906           (unless silent
8907             (if groups
8908                 (message "This message would go to %s"
8909                          (mapconcat 'car groups ", "))
8910               (message "This message would go to no groups"))
8911             groups))))))
8912
8913 (defun gnus-summary-respool-trace ()
8914   "Trace where the respool algorithm would put this article.
8915 Display a buffer showing all fancy splitting patterns which matched."
8916   (interactive)
8917   (gnus-summary-respool-query nil t))
8918
8919 ;; Summary marking commands.
8920
8921 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8922   "Mark articles which has the same subject as read, and then select the next.
8923 If UNMARK is positive, remove any kind of mark.
8924 If UNMARK is negative, tick articles."
8925   (interactive "P")
8926   (when unmark
8927     (setq unmark (prefix-numeric-value unmark)))
8928   (let ((count
8929          (gnus-summary-mark-same-subject
8930           (gnus-summary-article-subject) unmark)))
8931     ;; Select next unread article.  If auto-select-same mode, should
8932     ;; select the first unread article.
8933     (gnus-summary-next-article t (and gnus-auto-select-same
8934                                       (gnus-summary-article-subject)))
8935     (gnus-message 7 "%d article%s marked as %s"
8936                   count (if (= count 1) " is" "s are")
8937                   (if unmark "unread" "read"))))
8938
8939 (defun gnus-summary-kill-same-subject (&optional unmark)
8940   "Mark articles which has the same subject as read.
8941 If UNMARK is positive, remove any kind of mark.
8942 If UNMARK is negative, tick articles."
8943   (interactive "P")
8944   (when unmark
8945     (setq unmark (prefix-numeric-value unmark)))
8946   (let ((count
8947          (gnus-summary-mark-same-subject
8948           (gnus-summary-article-subject) unmark)))
8949     ;; If marked as read, go to next unread subject.
8950     (when (null unmark)
8951       ;; Go to next unread subject.
8952       (gnus-summary-next-subject 1 t))
8953     (gnus-message 7 "%d articles are marked as %s"
8954                   count (if unmark "unread" "read"))))
8955
8956 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8957   "Mark articles with same SUBJECT as read, and return marked number.
8958 If optional argument UNMARK is positive, remove any kinds of marks.
8959 If optional argument UNMARK is negative, mark articles as unread instead."
8960   (let ((count 1))
8961     (save-excursion
8962       (cond
8963        ((null unmark)                   ; Mark as read.
8964         (while (and
8965                 (progn
8966                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8967                   (gnus-summary-show-thread) t)
8968                 (gnus-summary-find-subject subject))
8969           (setq count (1+ count))))
8970        ((> unmark 0)                    ; Tick.
8971         (while (and
8972                 (progn
8973                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8974                   (gnus-summary-show-thread) t)
8975                 (gnus-summary-find-subject subject))
8976           (setq count (1+ count))))
8977        (t                               ; Mark as unread.
8978         (while (and
8979                 (progn
8980                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8981                   (gnus-summary-show-thread) t)
8982                 (gnus-summary-find-subject subject))
8983           (setq count (1+ count)))))
8984       (gnus-set-mode-line 'summary)
8985       ;; Return the number of marked articles.
8986       count)))
8987
8988 (defun gnus-summary-mark-as-processable (n &optional unmark)
8989   "Set the process mark on the next N articles.
8990 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8991 the process mark instead.  The difference between N and the actual
8992 number of articles marked is returned."
8993   (interactive "P")
8994   (if (and (null n) (gnus-region-active-p))
8995       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8996     (setq n (prefix-numeric-value n))
8997     (let ((backward (< n 0))
8998           (n (abs n)))
8999       (while (and
9000               (> n 0)
9001               (if unmark
9002                   (gnus-summary-remove-process-mark
9003                    (gnus-summary-article-number))
9004                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9005               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9006         (setq n (1- n)))
9007       (when (/= 0 n)
9008         (gnus-message 7 "No more articles"))
9009       (gnus-summary-recenter)
9010       (gnus-summary-position-point)
9011       n)))
9012
9013 (defun gnus-summary-unmark-as-processable (n)
9014   "Remove the process mark from the next N articles.
9015 If N is negative, unmark backward instead.  The difference between N and
9016 the actual number of articles unmarked is returned."
9017   (interactive "P")
9018   (gnus-summary-mark-as-processable n t))
9019
9020 (defun gnus-summary-unmark-all-processable ()
9021   "Remove the process mark from all articles."
9022   (interactive)
9023   (save-excursion
9024     (while gnus-newsgroup-processable
9025       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9026   (gnus-summary-position-point))
9027
9028 (defun gnus-summary-add-mark (article type)
9029   "Mark ARTICLE with a mark of TYPE."
9030   (let ((vtype (car (assq type gnus-article-mark-lists)))
9031         var)
9032     (if (not vtype)
9033         (error "No such mark type: %s" type)
9034       (setq var (intern (format "gnus-newsgroup-%s" type)))
9035       (set var (cons article (symbol-value var)))
9036       (if (memq type '(processable cached replied forwarded recent saved))
9037           (gnus-summary-update-secondary-mark article)
9038         ;;; !!! This is bogus.  We should find out what primary
9039         ;;; !!! mark we want to set.
9040         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9041
9042 (defun gnus-summary-mark-as-expirable (n)
9043   "Mark N articles forward as expirable.
9044 If N is negative, mark backward instead.  The difference between N and
9045 the actual number of articles marked is returned."
9046   (interactive "p")
9047   (gnus-summary-mark-forward n gnus-expirable-mark))
9048
9049 (defun gnus-summary-mark-article-as-replied (article)
9050   "Mark ARTICLE as replied to and update the summary line.
9051 ARTICLE can also be a list of articles."
9052   (interactive (list (gnus-summary-article-number)))
9053   (let ((articles (if (listp article) article (list article))))
9054     (dolist (article articles)
9055       (push article gnus-newsgroup-replied)
9056       (let ((buffer-read-only nil))
9057         (when (gnus-summary-goto-subject article nil t)
9058           (gnus-summary-update-secondary-mark article))))))
9059
9060 (defun gnus-summary-mark-article-as-forwarded (article)
9061   "Mark ARTICLE as forwarded and update the summary line.
9062 ARTICLE can also be a list of articles."
9063   (let ((articles (if (listp article) article (list article))))
9064     (dolist (article articles)
9065       (push article gnus-newsgroup-forwarded)
9066       (let ((buffer-read-only nil))
9067         (when (gnus-summary-goto-subject article nil t)
9068           (gnus-summary-update-secondary-mark article))))))
9069
9070 (defun gnus-summary-set-bookmark (article)
9071   "Set a bookmark in current article."
9072   (interactive (list (gnus-summary-article-number)))
9073   (when (or (not (get-buffer gnus-article-buffer))
9074             (not gnus-current-article)
9075             (not gnus-article-current)
9076             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9077     (error "No current article selected"))
9078   ;; Remove old bookmark, if one exists.
9079   (let ((old (assq article gnus-newsgroup-bookmarks)))
9080     (when old
9081       (setq gnus-newsgroup-bookmarks
9082             (delq old gnus-newsgroup-bookmarks))))
9083   ;; Set the new bookmark, which is on the form
9084   ;; (article-number . line-number-in-body).
9085   (push
9086    (cons article
9087          (save-excursion
9088            (set-buffer gnus-article-buffer)
9089            (count-lines
9090             (min (point)
9091                  (save-excursion
9092                    (goto-char (point-min))
9093                    (search-forward "\n\n" nil t)
9094                    (point)))
9095             (point))))
9096    gnus-newsgroup-bookmarks)
9097   (gnus-message 6 "A bookmark has been added to the current article."))
9098
9099 (defun gnus-summary-remove-bookmark (article)
9100   "Remove the bookmark from the current article."
9101   (interactive (list (gnus-summary-article-number)))
9102   ;; Remove old bookmark, if one exists.
9103   (let ((old (assq article gnus-newsgroup-bookmarks)))
9104     (if old
9105         (progn
9106           (setq gnus-newsgroup-bookmarks
9107                 (delq old gnus-newsgroup-bookmarks))
9108           (gnus-message 6 "Removed bookmark."))
9109       (gnus-message 6 "No bookmark in current article."))))
9110
9111 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9112 (defun gnus-summary-mark-as-dormant (n)
9113   "Mark N articles forward as dormant.
9114 If N is negative, mark backward instead.  The difference between N and
9115 the actual number of articles marked is returned."
9116   (interactive "p")
9117   (gnus-summary-mark-forward n gnus-dormant-mark))
9118
9119 (defun gnus-summary-set-process-mark (article)
9120   "Set the process mark on ARTICLE and update the summary line."
9121   (setq gnus-newsgroup-processable
9122         (cons article
9123               (delq article gnus-newsgroup-processable)))
9124   (when (gnus-summary-goto-subject article)
9125     (gnus-summary-show-thread)
9126     (gnus-summary-goto-subject article)
9127     (gnus-summary-update-secondary-mark article)))
9128
9129 (defun gnus-summary-remove-process-mark (article)
9130   "Remove the process mark from ARTICLE and update the summary line."
9131   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9132   (when (gnus-summary-goto-subject article)
9133     (gnus-summary-show-thread)
9134     (gnus-summary-goto-subject article)
9135     (gnus-summary-update-secondary-mark article)))
9136
9137 (defun gnus-summary-set-saved-mark (article)
9138   "Set the process mark on ARTICLE and update the summary line."
9139   (push article gnus-newsgroup-saved)
9140   (when (gnus-summary-goto-subject article)
9141     (gnus-summary-update-secondary-mark article)))
9142
9143 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9144   "Mark N articles as read forwards.
9145 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9146 The difference between N and the actual number of articles marked is
9147 returned.
9148 Iff NO-EXPIRE, auto-expiry will be inhibited."
9149   (interactive "p")
9150   (gnus-summary-show-thread)
9151   (let ((backward (< n 0))
9152         (gnus-summary-goto-unread
9153          (and gnus-summary-goto-unread
9154               (not (eq gnus-summary-goto-unread 'never))
9155               (not (memq mark (list gnus-unread-mark
9156                                     gnus-ticked-mark gnus-dormant-mark)))))
9157         (n (abs n))
9158         (mark (or mark gnus-del-mark)))
9159     (while (and (> n 0)
9160                 (gnus-summary-mark-article nil mark no-expire)
9161                 (zerop (gnus-summary-next-subject
9162                         (if backward -1 1)
9163                         (and gnus-summary-goto-unread
9164                              (not (eq gnus-summary-goto-unread 'never)))
9165                         t)))
9166       (setq n (1- n)))
9167     (when (/= 0 n)
9168       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9169     (gnus-summary-recenter)
9170     (gnus-summary-position-point)
9171     (gnus-set-mode-line 'summary)
9172     n))
9173
9174 (defun gnus-summary-mark-article-as-read (mark)
9175   "Mark the current article quickly as read with MARK."
9176   (let ((article (gnus-summary-article-number)))
9177     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9178     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9179     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9180     (push (cons article mark) gnus-newsgroup-reads)
9181     ;; Possibly remove from cache, if that is used.
9182     (when gnus-use-cache
9183       (gnus-cache-enter-remove-article article))
9184     ;; Allow the backend to change the mark.
9185     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9186     ;; Check for auto-expiry.
9187     (when (and gnus-newsgroup-auto-expire
9188                (memq mark gnus-auto-expirable-marks))
9189       (setq mark gnus-expirable-mark)
9190       ;; Let the backend know about the mark change.
9191       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9192       (push article gnus-newsgroup-expirable))
9193     ;; Set the mark in the buffer.
9194     (gnus-summary-update-mark mark 'unread)
9195     t))
9196
9197 (defun gnus-summary-mark-article-as-unread (mark)
9198   "Mark the current article quickly as unread with MARK."
9199   (let* ((article (gnus-summary-article-number))
9200          (old-mark (gnus-summary-article-mark article)))
9201     ;; Allow the backend to change the mark.
9202     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9203     (if (eq mark old-mark)
9204         t
9205       (if (<= article 0)
9206           (progn
9207             (gnus-error 1 "Can't mark negative article numbers")
9208             nil)
9209         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9210         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9211         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9212         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9213         (cond ((= mark gnus-ticked-mark)
9214                (push article gnus-newsgroup-marked))
9215               ((= mark gnus-dormant-mark)
9216                (push article gnus-newsgroup-dormant))
9217               (t
9218                (push article gnus-newsgroup-unreads)))
9219         (gnus-pull article gnus-newsgroup-reads)
9220
9221         ;; See whether the article is to be put in the cache.
9222         (and gnus-use-cache
9223              (vectorp (gnus-summary-article-header article))
9224              (save-excursion
9225                (gnus-cache-possibly-enter-article
9226                 gnus-newsgroup-name article
9227                 (gnus-summary-article-header article)
9228                 (= mark gnus-ticked-mark)
9229                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9230
9231         ;; Fix the mark.
9232         (gnus-summary-update-mark mark 'unread)
9233         t))))
9234
9235 (defun gnus-summary-mark-article (&optional article mark no-expire)
9236   "Mark ARTICLE with MARK.  MARK can be any character.
9237 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9238 `??' (dormant) and `?E' (expirable).
9239 If MARK is nil, then the default character `?r' is used.
9240 If ARTICLE is nil, then the article on the current line will be
9241 marked.
9242 Iff NO-EXPIRE, auto-expiry will be inhibited."
9243   ;; The mark might be a string.
9244   (when (stringp mark)
9245     (setq mark (aref mark 0)))
9246   ;; If no mark is given, then we check auto-expiring.
9247   (when (null mark)
9248     (setq mark gnus-del-mark))
9249   (when (and (not no-expire)
9250              gnus-newsgroup-auto-expire
9251              (memq mark gnus-auto-expirable-marks))
9252     (setq mark gnus-expirable-mark))
9253   (let ((article (or article (gnus-summary-article-number)))
9254         (old-mark (gnus-summary-article-mark article)))
9255     ;; Allow the backend to change the mark.
9256     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9257     (if (eq mark old-mark)
9258         t
9259       (unless article
9260         (error "No article on current line"))
9261       (if (not (if (or (= mark gnus-unread-mark)
9262                        (= mark gnus-ticked-mark)
9263                        (= mark gnus-dormant-mark))
9264                    (gnus-mark-article-as-unread article mark)
9265                  (gnus-mark-article-as-read article mark)))
9266           t
9267         ;; See whether the article is to be put in the cache.
9268         (and gnus-use-cache
9269              (not (= mark gnus-canceled-mark))
9270              (vectorp (gnus-summary-article-header article))
9271              (save-excursion
9272                (gnus-cache-possibly-enter-article
9273                 gnus-newsgroup-name article
9274                 (gnus-summary-article-header article)
9275                 (= mark gnus-ticked-mark)
9276                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9277
9278         (when (gnus-summary-goto-subject article nil t)
9279           (let ((buffer-read-only nil))
9280             (gnus-summary-show-thread)
9281             ;; Fix the mark.
9282             (gnus-summary-update-mark mark 'unread)
9283             t))))))
9284
9285 (defun gnus-summary-update-secondary-mark (article)
9286   "Update the secondary (read, process, cache) mark."
9287   (gnus-summary-update-mark
9288    (cond ((memq article gnus-newsgroup-processable)
9289           gnus-process-mark)
9290          ((memq article gnus-newsgroup-cached)
9291           gnus-cached-mark)
9292          ((memq article gnus-newsgroup-replied)
9293           gnus-replied-mark)
9294          ((memq article gnus-newsgroup-forwarded)
9295           gnus-forwarded-mark)
9296          ((memq article gnus-newsgroup-saved)
9297           gnus-saved-mark)
9298          ((memq article gnus-newsgroup-recent)
9299           gnus-recent-mark)
9300          ((memq article gnus-newsgroup-unseen)
9301           gnus-unseen-mark)
9302          (t gnus-no-mark))
9303    'replied)
9304   (when (gnus-visual-p 'summary-highlight 'highlight)
9305     (gnus-run-hooks 'gnus-summary-update-hook))
9306   t)
9307
9308 (defun gnus-summary-update-mark (mark type)
9309   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9310         (buffer-read-only nil))
9311     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9312     (when forward
9313       (when (looking-at "\r")
9314         (incf forward))
9315       (when (<= (+ forward (point)) (point-max))
9316         ;; Go to the right position on the line.
9317         (goto-char (+ forward (point)))
9318         ;; Replace the old mark with the new mark.
9319         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9320         ;; Optionally update the marks by some user rule.
9321         (when (eq type 'unread)
9322           (gnus-data-set-mark
9323            (gnus-data-find (gnus-summary-article-number)) mark)
9324           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9325
9326 (defun gnus-mark-article-as-read (article &optional mark)
9327   "Enter ARTICLE in the pertinent lists and remove it from others."
9328   ;; Make the article expirable.
9329   (let ((mark (or mark gnus-del-mark)))
9330     (if (= mark gnus-expirable-mark)
9331         (push article gnus-newsgroup-expirable)
9332       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9333     ;; Remove from unread and marked lists.
9334     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9335     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9336     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9337     (push (cons article mark) gnus-newsgroup-reads)
9338     ;; Possibly remove from cache, if that is used.
9339     (when gnus-use-cache
9340       (gnus-cache-enter-remove-article article))
9341     t))
9342
9343 (defun gnus-mark-article-as-unread (article &optional mark)
9344   "Enter ARTICLE in the pertinent lists and remove it from others."
9345   (let ((mark (or mark gnus-ticked-mark)))
9346     (if (<= article 0)
9347         (progn
9348           (gnus-error 1 "Can't mark negative article numbers")
9349           nil)
9350       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9351             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9352             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9353             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9354
9355       ;; Unsuppress duplicates?
9356       (when gnus-suppress-duplicates
9357         (gnus-dup-unsuppress-article article))
9358
9359       (cond ((= mark gnus-ticked-mark)
9360              (push article gnus-newsgroup-marked))
9361             ((= mark gnus-dormant-mark)
9362              (push article gnus-newsgroup-dormant))
9363             (t
9364              (push article gnus-newsgroup-unreads)))
9365       (gnus-pull article gnus-newsgroup-reads)
9366       t)))
9367
9368 (defalias 'gnus-summary-mark-as-unread-forward
9369   'gnus-summary-tick-article-forward)
9370 (make-obsolete 'gnus-summary-mark-as-unread-forward
9371                'gnus-summary-tick-article-forward)
9372 (defun gnus-summary-tick-article-forward (n)
9373   "Tick N articles forwards.
9374 If N is negative, tick backwards instead.
9375 The difference between N and the number of articles ticked is returned."
9376   (interactive "p")
9377   (gnus-summary-mark-forward n gnus-ticked-mark))
9378
9379 (defalias 'gnus-summary-mark-as-unread-backward
9380   'gnus-summary-tick-article-backward)
9381 (make-obsolete 'gnus-summary-mark-as-unread-backward
9382                'gnus-summary-tick-article-backward)
9383 (defun gnus-summary-tick-article-backward (n)
9384   "Tick N articles backwards.
9385 The difference between N and the number of articles ticked is returned."
9386   (interactive "p")
9387   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9388
9389 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9390 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9391 (defun gnus-summary-tick-article (&optional article clear-mark)
9392   "Mark current article as unread.
9393 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9394 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9395   (interactive)
9396   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9397                                        gnus-ticked-mark)))
9398
9399 (defun gnus-summary-mark-as-read-forward (n)
9400   "Mark N articles as read forwards.
9401 If N is negative, mark backwards instead.
9402 The difference between N and the actual number of articles marked is
9403 returned."
9404   (interactive "p")
9405   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9406
9407 (defun gnus-summary-mark-as-read-backward (n)
9408   "Mark the N articles as read backwards.
9409 The difference between N and the actual number of articles marked is
9410 returned."
9411   (interactive "p")
9412   (gnus-summary-mark-forward
9413    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9414
9415 (defun gnus-summary-mark-as-read (&optional article mark)
9416   "Mark current article as read.
9417 ARTICLE specifies the article to be marked as read.
9418 MARK specifies a string to be inserted at the beginning of the line."
9419   (gnus-summary-mark-article article mark))
9420
9421 (defun gnus-summary-clear-mark-forward (n)
9422   "Clear marks from N articles forward.
9423 If N is negative, clear backward instead.
9424 The difference between N and the number of marks cleared is returned."
9425   (interactive "p")
9426   (gnus-summary-mark-forward n gnus-unread-mark))
9427
9428 (defun gnus-summary-clear-mark-backward (n)
9429   "Clear marks from N articles backward.
9430 The difference between N and the number of marks cleared is returned."
9431   (interactive "p")
9432   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9433
9434 (defun gnus-summary-mark-unread-as-read ()
9435   "Intended to be used by `gnus-summary-mark-article-hook'."
9436   (when (memq gnus-current-article gnus-newsgroup-unreads)
9437     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9438
9439 (defun gnus-summary-mark-read-and-unread-as-read ()
9440   "Intended to be used by `gnus-summary-mark-article-hook'."
9441   (let ((mark (gnus-summary-article-mark)))
9442     (when (or (gnus-unread-mark-p mark)
9443               (gnus-read-mark-p mark))
9444       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9445
9446 (defun gnus-summary-mark-unread-as-ticked ()
9447   "Intended to be used by `gnus-summary-mark-article-hook'."
9448   (when (memq gnus-current-article gnus-newsgroup-unreads)
9449     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9450
9451 (defun gnus-summary-mark-region-as-read (point mark all)
9452   "Mark all unread articles between point and mark as read.
9453 If given a prefix, mark all articles between point and mark as read,
9454 even ticked and dormant ones."
9455   (interactive "r\nP")
9456   (save-excursion
9457     (let (article)
9458       (goto-char point)
9459       (beginning-of-line)
9460       (while (and
9461               (< (point) mark)
9462               (progn
9463                 (when (or all
9464                           (memq (setq article (gnus-summary-article-number))
9465                                 gnus-newsgroup-unreads))
9466                   (gnus-summary-mark-article article gnus-del-mark))
9467                 t)
9468               (gnus-summary-find-next))))))
9469
9470 (defun gnus-summary-mark-below (score mark)
9471   "Mark articles with score less than SCORE with MARK."
9472   (interactive "P\ncMark: ")
9473   (setq score (if score
9474                   (prefix-numeric-value score)
9475                 (or gnus-summary-default-score 0)))
9476   (save-excursion
9477     (set-buffer gnus-summary-buffer)
9478     (goto-char (point-min))
9479     (while
9480         (progn
9481           (and (< (gnus-summary-article-score) score)
9482                (gnus-summary-mark-article nil mark))
9483           (gnus-summary-find-next)))))
9484
9485 (defun gnus-summary-kill-below (&optional score)
9486   "Mark articles with score below SCORE as read."
9487   (interactive "P")
9488   (gnus-summary-mark-below score gnus-killed-mark))
9489
9490 (defun gnus-summary-clear-above (&optional score)
9491   "Clear all marks from articles with score above SCORE."
9492   (interactive "P")
9493   (gnus-summary-mark-above score gnus-unread-mark))
9494
9495 (defun gnus-summary-tick-above (&optional score)
9496   "Tick all articles with score above SCORE."
9497   (interactive "P")
9498   (gnus-summary-mark-above score gnus-ticked-mark))
9499
9500 (defun gnus-summary-mark-above (score mark)
9501   "Mark articles with score over SCORE with MARK."
9502   (interactive "P\ncMark: ")
9503   (setq score (if score
9504                   (prefix-numeric-value score)
9505                 (or gnus-summary-default-score 0)))
9506   (save-excursion
9507     (set-buffer gnus-summary-buffer)
9508     (goto-char (point-min))
9509     (while (and (progn
9510                   (when (> (gnus-summary-article-score) score)
9511                     (gnus-summary-mark-article nil mark))
9512                   t)
9513                 (gnus-summary-find-next)))))
9514
9515 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9516 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9517 (defun gnus-summary-limit-include-expunged (&optional no-error)
9518   "Display all the hidden articles that were expunged for low scores."
9519   (interactive)
9520   (let ((buffer-read-only nil))
9521     (let ((scored gnus-newsgroup-scored)
9522           headers h)
9523       (while scored
9524         (unless (gnus-summary-article-header (caar scored))
9525           (and (setq h (gnus-number-to-header (caar scored)))
9526                (< (cdar scored) gnus-summary-expunge-below)
9527                (push h headers)))
9528         (setq scored (cdr scored)))
9529       (if (not headers)
9530           (when (not no-error)
9531             (error "No expunged articles hidden"))
9532         (goto-char (point-min))
9533         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9534         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9535         (mapcar (lambda (x) (push (mail-header-number x)
9536                                   gnus-newsgroup-limit))
9537                 headers)
9538         (gnus-summary-prepare-unthreaded (nreverse headers))
9539         (goto-char (point-min))
9540         (gnus-summary-position-point)
9541         t))))
9542
9543 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9544   "Mark all unread articles in this newsgroup as read.
9545 If prefix argument ALL is non-nil, ticked and dormant articles will
9546 also be marked as read.
9547 If QUIETLY is non-nil, no questions will be asked.
9548 If TO-HERE is non-nil, it should be a point in the buffer.  All
9549 articles before (after, if REVERSE is set) this point will be marked as read.
9550 Note that this function will only catch up the unread article
9551 in the current summary buffer limitation.
9552 The number of articles marked as read is returned."
9553   (interactive "P")
9554   (prog1
9555       (save-excursion
9556         (when (or quietly
9557                   (not gnus-interactive-catchup) ;Without confirmation?
9558                   gnus-expert-user
9559                   (gnus-y-or-n-p
9560                    (if all
9561                        "Mark absolutely all articles as read? "
9562                      "Mark all unread articles as read? ")))
9563           (if (and not-mark
9564                    (not gnus-newsgroup-adaptive)
9565                    (not gnus-newsgroup-auto-expire)
9566                    (not gnus-suppress-duplicates)
9567                    (or (not gnus-use-cache)
9568                        (eq gnus-use-cache 'passive)))
9569               (progn
9570                 (when all
9571                   (setq gnus-newsgroup-marked nil
9572                         gnus-newsgroup-dormant nil))
9573                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9574             ;; We actually mark all articles as canceled, which we
9575             ;; have to do when using auto-expiry or adaptive scoring.
9576             (gnus-summary-show-all-threads)
9577             (if (and to-here reverse)
9578                 (progn
9579                   (goto-char to-here)
9580                   (while (and
9581                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9582                           (gnus-summary-find-next (not all) nil nil t))))
9583               (when (gnus-summary-first-subject (not all) t)
9584                 (while (and
9585                         (if to-here (< (point) to-here) t)
9586                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9587                         (gnus-summary-find-next (not all) nil nil t)))))
9588             (gnus-set-mode-line 'summary))
9589           t))
9590     (gnus-summary-position-point)))
9591
9592 (defun gnus-summary-catchup-to-here (&optional all)
9593   "Mark all unticked articles before the current one as read.
9594 If ALL is non-nil, also mark ticked and dormant articles as read."
9595   (interactive "P")
9596   (save-excursion
9597     (gnus-save-hidden-threads
9598       (let ((beg (point)))
9599         ;; We check that there are unread articles.
9600         (when (or all (gnus-summary-find-prev))
9601           (gnus-summary-catchup all t beg)))))
9602   (gnus-summary-position-point))
9603
9604 (defun gnus-summary-catchup-from-here (&optional all)
9605   "Mark all unticked articles after the current one as read.
9606 If ALL is non-nil, also mark ticked and dormant articles as read."
9607   (interactive "P")
9608   (save-excursion
9609     (gnus-save-hidden-threads
9610       (let ((beg (point)))
9611         ;; We check that there are unread articles.
9612         (when (or all (gnus-summary-find-next))
9613           (gnus-summary-catchup all t beg nil t)))))
9614   (gnus-summary-position-point))
9615
9616 (defun gnus-summary-catchup-all (&optional quietly)
9617   "Mark all articles in this newsgroup as read."
9618   (interactive "P")
9619   (gnus-summary-catchup t quietly))
9620
9621 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9622   "Mark all unread articles in this group as read, then exit.
9623 If prefix argument ALL is non-nil, all articles are marked as read.
9624 If QUIETLY is non-nil, no questions will be asked."
9625   (interactive "P")
9626   (when (gnus-summary-catchup all quietly nil 'fast)
9627     ;; Select next newsgroup or exit.
9628     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9629              (eq gnus-auto-select-next 'quietly))
9630         (gnus-summary-next-group nil)
9631       (gnus-summary-exit))))
9632
9633 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9634   "Mark all articles in this newsgroup as read, and then exit."
9635   (interactive "P")
9636   (gnus-summary-catchup-and-exit t quietly))
9637
9638 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9639   "Mark all articles in this group as read and select the next group.
9640 If given a prefix, mark all articles, unread as well as ticked, as
9641 read."
9642   (interactive "P")
9643   (save-excursion
9644     (gnus-summary-catchup all))
9645   (gnus-summary-next-group))
9646
9647 ;;;
9648 ;;; with article
9649 ;;;
9650
9651 (defmacro gnus-with-article (article &rest forms)
9652   "Select ARTICLE and perform FORMS in the original article buffer.
9653 Then replace the article with the result."
9654   `(progn
9655      ;; We don't want the article to be marked as read.
9656      (let (gnus-mark-article-hook)
9657        (gnus-summary-select-article t t nil ,article))
9658      (set-buffer gnus-original-article-buffer)
9659      ,@forms
9660      (if (not (gnus-check-backend-function
9661                'request-replace-article (car gnus-article-current)))
9662          (gnus-message 5 "Read-only group; not replacing")
9663        (unless (gnus-request-replace-article
9664                 ,article (car gnus-article-current)
9665                 (current-buffer) t)
9666          (error "Couldn't replace article")))
9667      ;; The cache and backlog have to be flushed somewhat.
9668      (when gnus-keep-backlog
9669        (gnus-backlog-remove-article
9670         (car gnus-article-current) (cdr gnus-article-current)))
9671      (when gnus-use-cache
9672        (gnus-cache-update-article
9673         (car gnus-article-current) (cdr gnus-article-current)))))
9674
9675 (put 'gnus-with-article 'lisp-indent-function 1)
9676 (put 'gnus-with-article 'edebug-form-spec '(form body))
9677
9678 ;; Thread-based commands.
9679
9680 (defun gnus-summary-articles-in-thread (&optional article)
9681   "Return a list of all articles in the current thread.
9682 If ARTICLE is non-nil, return all articles in the thread that starts
9683 with that article."
9684   (let* ((article (or article (gnus-summary-article-number)))
9685          (data (gnus-data-find-list article))
9686          (top-level (gnus-data-level (car data)))
9687          (top-subject
9688           (cond ((null gnus-thread-operation-ignore-subject)
9689                  (gnus-simplify-subject-re
9690                   (mail-header-subject (gnus-data-header (car data)))))
9691                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9692                  (gnus-simplify-subject-fuzzy
9693                   (mail-header-subject (gnus-data-header (car data)))))
9694                 (t nil)))
9695          (end-point (save-excursion
9696                       (if (gnus-summary-go-to-next-thread)
9697                           (point) (point-max))))
9698          articles)
9699     (while (and data
9700                 (< (gnus-data-pos (car data)) end-point))
9701       (when (or (not top-subject)
9702                 (string= top-subject
9703                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9704                              (gnus-simplify-subject-fuzzy
9705                               (mail-header-subject
9706                                (gnus-data-header (car data))))
9707                            (gnus-simplify-subject-re
9708                             (mail-header-subject
9709                              (gnus-data-header (car data)))))))
9710         (push (gnus-data-number (car data)) articles))
9711       (unless (and (setq data (cdr data))
9712                    (> (gnus-data-level (car data)) top-level))
9713         (setq data nil)))
9714     ;; Return the list of articles.
9715     (nreverse articles)))
9716
9717 (defun gnus-summary-rethread-current ()
9718   "Rethread the thread the current article is part of."
9719   (interactive)
9720   (let* ((gnus-show-threads t)
9721          (article (gnus-summary-article-number))
9722          (id (mail-header-id (gnus-summary-article-header)))
9723          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9724     (unless id
9725       (error "No article on the current line"))
9726     (gnus-rebuild-thread id)
9727     (gnus-summary-goto-subject article)))
9728
9729 (defun gnus-summary-reparent-thread ()
9730   "Make the current article child of the marked (or previous) article.
9731
9732 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9733 is non-nil or the Subject: of both articles are the same."
9734   (interactive)
9735   (unless (not (gnus-group-read-only-p))
9736     (error "The current newsgroup does not support article editing"))
9737   (unless (<= (length gnus-newsgroup-processable) 1)
9738     (error "No more than one article may be marked"))
9739   (save-window-excursion
9740     (let ((gnus-article-buffer " *reparent*")
9741           (current-article (gnus-summary-article-number))
9742           ;; First grab the marked article, otherwise one line up.
9743           (parent-article (if (not (null gnus-newsgroup-processable))
9744                               (car gnus-newsgroup-processable)
9745                             (save-excursion
9746                               (if (eq (forward-line -1) 0)
9747                                   (gnus-summary-article-number)
9748                                 (error "Beginning of summary buffer"))))))
9749       (unless (not (eq current-article parent-article))
9750         (error "An article may not be self-referential"))
9751       (let ((message-id (mail-header-id
9752                          (gnus-summary-article-header parent-article))))
9753         (unless (and message-id (not (equal message-id "")))
9754           (error "No message-id in desired parent"))
9755         (gnus-with-article current-article
9756           (save-restriction
9757             (goto-char (point-min))
9758             (message-narrow-to-head)
9759             (if (re-search-forward "^References: " nil t)
9760                 (progn
9761                   (re-search-forward "^[^ \t]" nil t)
9762                   (forward-line -1)
9763                   (end-of-line)
9764                   (insert " " message-id))
9765               (insert "References: " message-id "\n"))))
9766         (set-buffer gnus-summary-buffer)
9767         (gnus-summary-unmark-all-processable)
9768         (gnus-summary-update-article current-article)
9769         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9770             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9771         (gnus-summary-rethread-current)
9772         (gnus-message 3 "Article %d is now the child of article %d"
9773                       current-article parent-article)))))
9774
9775 (defun gnus-summary-toggle-threads (&optional arg)
9776   "Toggle showing conversation threads.
9777 If ARG is positive number, turn showing conversation threads on."
9778   (interactive "P")
9779   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9780     (setq gnus-show-threads
9781           (if (null arg) (not gnus-show-threads)
9782             (> (prefix-numeric-value arg) 0)))
9783     (gnus-summary-prepare)
9784     (gnus-summary-goto-subject current)
9785     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9786     (gnus-summary-position-point)))
9787
9788 (defun gnus-summary-show-all-threads ()
9789   "Show all threads."
9790   (interactive)
9791   (save-excursion
9792     (let ((buffer-read-only nil))
9793       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9794   (gnus-summary-position-point))
9795
9796 (defun gnus-summary-show-thread ()
9797   "Show thread subtrees.
9798 Returns nil if no thread was there to be shown."
9799   (interactive)
9800   (let ((buffer-read-only nil)
9801         (orig (point))
9802         ;; first goto end then to beg, to have point at beg after let
9803         (end (progn (end-of-line) (point)))
9804         (beg (progn (beginning-of-line) (point))))
9805     (prog1
9806         ;; Any hidden lines here?
9807         (search-forward "\r" end t)
9808       (subst-char-in-region beg end ?\^M ?\n t)
9809       (goto-char orig)
9810       (gnus-summary-position-point))))
9811
9812 (defun gnus-summary-hide-all-threads ()
9813   "Hide all thread subtrees."
9814   (interactive)
9815   (save-excursion
9816     (goto-char (point-min))
9817     (gnus-summary-hide-thread)
9818     (while (zerop (gnus-summary-next-thread 1 t))
9819       (gnus-summary-hide-thread)))
9820   (gnus-summary-position-point))
9821
9822 (defun gnus-summary-hide-thread ()
9823   "Hide thread subtrees.
9824 Returns nil if no threads were there to be hidden."
9825   (interactive)
9826   (let ((buffer-read-only nil)
9827         (start (point))
9828         (article (gnus-summary-article-number)))
9829     (goto-char start)
9830     ;; Go forward until either the buffer ends or the subthread
9831     ;; ends.
9832     (when (and (not (eobp))
9833                (or (zerop (gnus-summary-next-thread 1 t))
9834                    (goto-char (point-max))))
9835       (prog1
9836           (if (and (> (point) start)
9837                    (search-backward "\n" start t))
9838               (progn
9839                 (subst-char-in-region start (point) ?\n ?\^M)
9840                 (gnus-summary-goto-subject article))
9841             (goto-char start)
9842             nil)))))
9843
9844 (defun gnus-summary-go-to-next-thread (&optional previous)
9845   "Go to the same level (or less) next thread.
9846 If PREVIOUS is non-nil, go to previous thread instead.
9847 Return the article number moved to, or nil if moving was impossible."
9848   (let ((level (gnus-summary-thread-level))
9849         (way (if previous -1 1))
9850         (beg (point)))
9851     (forward-line way)
9852     (while (and (not (eobp))
9853                 (< level (gnus-summary-thread-level)))
9854       (forward-line way))
9855     (if (eobp)
9856         (progn
9857           (goto-char beg)
9858           nil)
9859       (setq beg (point))
9860       (prog1
9861           (gnus-summary-article-number)
9862         (goto-char beg)))))
9863
9864 (defun gnus-summary-next-thread (n &optional silent)
9865   "Go to the same level next N'th thread.
9866 If N is negative, search backward instead.
9867 Returns the difference between N and the number of skips actually
9868 done.
9869
9870 If SILENT, don't output messages."
9871   (interactive "p")
9872   (let ((backward (< n 0))
9873         (n (abs n)))
9874     (while (and (> n 0)
9875                 (gnus-summary-go-to-next-thread backward))
9876       (decf n))
9877     (unless silent
9878       (gnus-summary-position-point))
9879     (when (and (not silent) (/= 0 n))
9880       (gnus-message 7 "No more threads"))
9881     n))
9882
9883 (defun gnus-summary-prev-thread (n)
9884   "Go to the same level previous N'th thread.
9885 Returns the difference between N and the number of skips actually
9886 done."
9887   (interactive "p")
9888   (gnus-summary-next-thread (- n)))
9889
9890 (defun gnus-summary-go-down-thread ()
9891   "Go down one level in the current thread."
9892   (let ((children (gnus-summary-article-children)))
9893     (when children
9894       (gnus-summary-goto-subject (car children)))))
9895
9896 (defun gnus-summary-go-up-thread ()
9897   "Go up one level in the current thread."
9898   (let ((parent (gnus-summary-article-parent)))
9899     (when parent
9900       (gnus-summary-goto-subject parent))))
9901
9902 (defun gnus-summary-down-thread (n)
9903   "Go down thread N steps.
9904 If N is negative, go up instead.
9905 Returns the difference between N and how many steps down that were
9906 taken."
9907   (interactive "p")
9908   (let ((up (< n 0))
9909         (n (abs n)))
9910     (while (and (> n 0)
9911                 (if up (gnus-summary-go-up-thread)
9912                   (gnus-summary-go-down-thread)))
9913       (setq n (1- n)))
9914     (gnus-summary-position-point)
9915     (when (/= 0 n)
9916       (gnus-message 7 "Can't go further"))
9917     n))
9918
9919 (defun gnus-summary-up-thread (n)
9920   "Go up thread N steps.
9921 If N is negative, go down instead.
9922 Returns the difference between N and how many steps down that were
9923 taken."
9924   (interactive "p")
9925   (gnus-summary-down-thread (- n)))
9926
9927 (defun gnus-summary-top-thread ()
9928   "Go to the top of the thread."
9929   (interactive)
9930   (while (gnus-summary-go-up-thread))
9931   (gnus-summary-article-number))
9932
9933 (defun gnus-summary-kill-thread (&optional unmark)
9934   "Mark articles under current thread as read.
9935 If the prefix argument is positive, remove any kinds of marks.
9936 If the prefix argument is negative, tick articles instead."
9937   (interactive "P")
9938   (when unmark
9939     (setq unmark (prefix-numeric-value unmark)))
9940   (let ((articles (gnus-summary-articles-in-thread)))
9941     (save-excursion
9942       ;; Expand the thread.
9943       (gnus-summary-show-thread)
9944       ;; Mark all the articles.
9945       (while articles
9946         (gnus-summary-goto-subject (car articles))
9947         (cond ((null unmark)
9948                (gnus-summary-mark-article-as-read gnus-killed-mark))
9949               ((> unmark 0)
9950                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9951               (t
9952                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9953         (setq articles (cdr articles))))
9954     ;; Hide killed subtrees.
9955     (and (null unmark)
9956          gnus-thread-hide-killed
9957          (gnus-summary-hide-thread))
9958     ;; If marked as read, go to next unread subject.
9959     (when (null unmark)
9960       ;; Go to next unread subject.
9961       (gnus-summary-next-subject 1 t)))
9962   (gnus-set-mode-line 'summary))
9963
9964 ;; Summary sorting commands
9965
9966 (defun gnus-summary-sort-by-number (&optional reverse)
9967   "Sort the summary buffer by article number.
9968 Argument REVERSE means reverse order."
9969   (interactive "P")
9970   (gnus-summary-sort 'number reverse))
9971
9972 (defun gnus-summary-sort-by-author (&optional reverse)
9973   "Sort the summary buffer by author name alphabetically.
9974 If `case-fold-search' is non-nil, case of letters is ignored.
9975 Argument REVERSE means reverse order."
9976   (interactive "P")
9977   (gnus-summary-sort 'author reverse))
9978
9979 (defun gnus-summary-sort-by-subject (&optional reverse)
9980   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9981 If `case-fold-search' is non-nil, case of letters is ignored.
9982 Argument REVERSE means reverse order."
9983   (interactive "P")
9984   (gnus-summary-sort 'subject reverse))
9985
9986 (defun gnus-summary-sort-by-date (&optional reverse)
9987   "Sort the summary buffer by date.
9988 Argument REVERSE means reverse order."
9989   (interactive "P")
9990   (gnus-summary-sort 'date reverse))
9991
9992 (defun gnus-summary-sort-by-score (&optional reverse)
9993   "Sort the summary buffer by score.
9994 Argument REVERSE means reverse order."
9995   (interactive "P")
9996   (gnus-summary-sort 'score reverse))
9997
9998 (defun gnus-summary-sort-by-lines (&optional reverse)
9999   "Sort the summary buffer by the number of lines.
10000 Argument REVERSE means reverse order."
10001   (interactive "P")
10002   (gnus-summary-sort 'lines reverse))
10003
10004 (defun gnus-summary-sort-by-chars (&optional reverse)
10005   "Sort the summary buffer by article length.
10006 Argument REVERSE means reverse order."
10007   (interactive "P")
10008   (gnus-summary-sort 'chars reverse))
10009
10010 (defun gnus-summary-sort-by-original (&optional reverse)
10011   "Sort the summary buffer using the default sorting method.
10012 Argument REVERSE means reverse order."
10013   (interactive "P")
10014   (let* ((buffer-read-only)
10015          (gnus-summary-prepare-hook nil))
10016     ;; We do the sorting by regenerating the threads.
10017     (gnus-summary-prepare)
10018     ;; Hide subthreads if needed.
10019     (when (and gnus-show-threads gnus-thread-hide-subtree)
10020       (gnus-summary-hide-all-threads))))
10021
10022 (defun gnus-summary-sort (predicate reverse)
10023   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10024   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10025          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10026          (gnus-thread-sort-functions
10027           (if (not reverse)
10028               thread
10029             `(lambda (t1 t2)
10030                (,thread t2 t1))))
10031          (gnus-sort-gathered-threads-function
10032           gnus-thread-sort-functions)
10033          (gnus-article-sort-functions
10034           (if (not reverse)
10035               article
10036             `(lambda (t1 t2)
10037                (,article t2 t1))))
10038          (buffer-read-only)
10039          (gnus-summary-prepare-hook nil))
10040     ;; We do the sorting by regenerating the threads.
10041     (gnus-summary-prepare)
10042     ;; Hide subthreads if needed.
10043     (when (and gnus-show-threads gnus-thread-hide-subtree)
10044       (gnus-summary-hide-all-threads))))
10045
10046 ;; Summary saving commands.
10047
10048 (defun gnus-summary-save-article (&optional n not-saved)
10049   "Save the current article using the default saver function.
10050 If N is a positive number, save the N next articles.
10051 If N is a negative number, save the N previous articles.
10052 If N is nil and any articles have been marked with the process mark,
10053 save those articles instead.
10054 The variable `gnus-default-article-saver' specifies the saver function."
10055   (interactive "P")
10056   (let* ((articles (gnus-summary-work-articles n))
10057          (save-buffer (save-excursion
10058                         (nnheader-set-temp-buffer " *Gnus Save*")))
10059          (num (length articles))
10060          header file)
10061     (dolist (article articles)
10062       (setq header (gnus-summary-article-header article))
10063       (if (not (vectorp header))
10064           ;; This is a pseudo-article.
10065           (if (assq 'name header)
10066               (gnus-copy-file (cdr (assq 'name header)))
10067             (gnus-message 1 "Article %d is unsaveable" article))
10068         ;; This is a real article.
10069         (save-window-excursion
10070           (let ((gnus-display-mime-function nil)
10071                 (gnus-article-prepare-hook nil))
10072             (gnus-summary-select-article t nil nil article)))
10073         (save-excursion
10074           (set-buffer save-buffer)
10075           (erase-buffer)
10076           (insert-buffer-substring gnus-original-article-buffer))
10077         (setq file (gnus-article-save save-buffer file num))
10078         (gnus-summary-remove-process-mark article)
10079         (unless not-saved
10080           (gnus-summary-set-saved-mark article))))
10081     (gnus-kill-buffer save-buffer)
10082     (gnus-summary-position-point)
10083     (gnus-set-mode-line 'summary)
10084     n))
10085
10086 (defun gnus-summary-pipe-output (&optional arg)
10087   "Pipe the current article to a subprocess.
10088 If N is a positive number, pipe the N next articles.
10089 If N is a negative number, pipe the N previous articles.
10090 If N is nil and any articles have been marked with the process mark,
10091 pipe those articles instead."
10092   (interactive "P")
10093   (require 'gnus-art)
10094   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10095     (gnus-summary-save-article arg t))
10096   (let ((buffer (get-buffer "*Shell Command Output*")))
10097     (if (and buffer
10098              (with-current-buffer buffer (> (point-max) (point-min))))
10099         (gnus-configure-windows 'pipe))))
10100
10101 (defun gnus-summary-save-article-mail (&optional arg)
10102   "Append the current article to an mail file.
10103 If N is a positive number, save the N next articles.
10104 If N is a negative number, save the N previous articles.
10105 If N is nil and any articles have been marked with the process mark,
10106 save those articles instead."
10107   (interactive "P")
10108   (require 'gnus-art)
10109   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10110     (gnus-summary-save-article arg)))
10111
10112 (defun gnus-summary-save-article-rmail (&optional arg)
10113   "Append the current article to an rmail file.
10114 If N is a positive number, save the N next articles.
10115 If N is a negative number, save the N previous articles.
10116 If N is nil and any articles have been marked with the process mark,
10117 save those articles instead."
10118   (interactive "P")
10119   (require 'gnus-art)
10120   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10121     (gnus-summary-save-article arg)))
10122
10123 (defun gnus-summary-save-article-file (&optional arg)
10124   "Append the current article to a file.
10125 If N is a positive number, save the N next articles.
10126 If N is a negative number, save the N previous articles.
10127 If N is nil and any articles have been marked with the process mark,
10128 save those articles instead."
10129   (interactive "P")
10130   (require 'gnus-art)
10131   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10132     (gnus-summary-save-article arg)))
10133
10134 (defun gnus-summary-write-article-file (&optional arg)
10135   "Write the current article to a file, deleting the previous file.
10136 If N is a positive number, save the N next articles.
10137 If N is a negative number, save the N previous articles.
10138 If N is nil and any articles have been marked with the process mark,
10139 save those articles instead."
10140   (interactive "P")
10141   (require 'gnus-art)
10142   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10143     (gnus-summary-save-article arg)))
10144
10145 (defun gnus-summary-save-article-body-file (&optional arg)
10146   "Append the current article body to a file.
10147 If N is a positive number, save the N next articles.
10148 If N is a negative number, save the N previous articles.
10149 If N is nil and any articles have been marked with the process mark,
10150 save those articles instead."
10151   (interactive "P")
10152   (require 'gnus-art)
10153   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10154     (gnus-summary-save-article arg)))
10155
10156 (defun gnus-summary-muttprint (&optional arg)
10157   "Print the current article using Muttprint.
10158 If N is a positive number, save the N next articles.
10159 If N is a negative number, save the N previous articles.
10160 If N is nil and any articles have been marked with the process mark,
10161 save those articles instead."
10162   (interactive "P")
10163   (require 'gnus-art)
10164   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10165     (gnus-summary-save-article arg t)))
10166
10167 (defun gnus-summary-pipe-message (program)
10168   "Pipe the current article through PROGRAM."
10169   (interactive "sProgram: ")
10170   (gnus-summary-select-article)
10171   (let ((mail-header-separator ""))
10172     (gnus-eval-in-buffer-window gnus-article-buffer
10173       (save-restriction
10174         (widen)
10175         (let ((start (window-start))
10176               buffer-read-only)
10177           (message-pipe-buffer-body program)
10178           (set-window-start (get-buffer-window (current-buffer)) start))))))
10179
10180 (defun gnus-get-split-value (methods)
10181   "Return a value based on the split METHODS."
10182   (let (split-name method result match)
10183     (when methods
10184       (save-excursion
10185         (set-buffer gnus-original-article-buffer)
10186         (save-restriction
10187           (nnheader-narrow-to-headers)
10188           (while (and methods (not split-name))
10189             (goto-char (point-min))
10190             (setq method (pop methods))
10191             (setq match (car method))
10192             (when (cond
10193                    ((stringp match)
10194                     ;; Regular expression.
10195                     (ignore-errors
10196                       (re-search-forward match nil t)))
10197                    ((gnus-functionp match)
10198                     ;; Function.
10199                     (save-restriction
10200                       (widen)
10201                       (setq result (funcall match gnus-newsgroup-name))))
10202                    ((consp match)
10203                     ;; Form.
10204                     (save-restriction
10205                       (widen)
10206                       (setq result (eval match)))))
10207               (setq split-name (cdr method))
10208               (cond ((stringp result)
10209                      (push (expand-file-name
10210                             result gnus-article-save-directory)
10211                            split-name))
10212                     ((consp result)
10213                      (setq split-name (append result split-name)))))))))
10214     (nreverse split-name)))
10215
10216 (defun gnus-valid-move-group-p (group)
10217   (and (boundp group)
10218        (symbol-name group)
10219        (symbol-value group)
10220        (gnus-get-function (gnus-find-method-for-group
10221                            (symbol-name group)) 'request-accept-article t)))
10222
10223 (defun gnus-read-move-group-name (prompt default articles prefix)
10224   "Read a group name."
10225   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10226          (minibuffer-confirm-incomplete nil) ; XEmacs
10227          (prom
10228           (format "%s %s to:"
10229                   prompt
10230                   (if (> (length articles) 1)
10231                       (format "these %d articles" (length articles))
10232                     "this article")))
10233          (to-newsgroup
10234           (cond
10235            ((null split-name)
10236             (gnus-completing-read default prom
10237                                   gnus-active-hashtb
10238                                   'gnus-valid-move-group-p
10239                                   nil prefix
10240                                   'gnus-group-history))
10241            ((= 1 (length split-name))
10242             (gnus-completing-read (car split-name) prom
10243                                   gnus-active-hashtb
10244                                   'gnus-valid-move-group-p
10245                                   nil nil
10246                                   'gnus-group-history))
10247            (t
10248             (gnus-completing-read nil prom
10249                                   (mapcar (lambda (el) (list el))
10250                                           (nreverse split-name))
10251                                   nil nil nil
10252                                   'gnus-group-history))))
10253          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10254     (when to-newsgroup
10255       (if (or (string= to-newsgroup "")
10256               (string= to-newsgroup prefix))
10257           (setq to-newsgroup default))
10258       (unless to-newsgroup
10259         (error "No group name entered"))
10260       (or (gnus-active to-newsgroup)
10261           (gnus-activate-group to-newsgroup nil nil to-method)
10262           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10263                                      to-newsgroup))
10264               (or (and (gnus-request-create-group to-newsgroup to-method)
10265                        (gnus-activate-group
10266                         to-newsgroup nil nil to-method)
10267                        (gnus-subscribe-group to-newsgroup))
10268                   (error "Couldn't create group %s" to-newsgroup)))
10269           (error "No such group: %s" to-newsgroup)))
10270     to-newsgroup))
10271
10272 (defun gnus-summary-save-parts (type dir n &optional reverse)
10273   "Save parts matching TYPE to DIR.
10274 If REVERSE, save parts that do not match TYPE."
10275   (interactive
10276    (list (read-string "Save parts of type: "
10277                       (or (car gnus-summary-save-parts-type-history)
10278                           gnus-summary-save-parts-default-mime)
10279                       'gnus-summary-save-parts-type-history)
10280          (setq gnus-summary-save-parts-last-directory
10281                (read-file-name "Save to directory: "
10282                                gnus-summary-save-parts-last-directory
10283                                nil t))
10284          current-prefix-arg))
10285   (gnus-summary-iterate n
10286     (let ((gnus-display-mime-function nil)
10287           (gnus-inhibit-treatment t))
10288       (gnus-summary-select-article))
10289     (save-excursion
10290       (set-buffer gnus-article-buffer)
10291       (let ((handles (or gnus-article-mime-handles
10292                          (mm-dissect-buffer) (mm-uu-dissect))))
10293         (when handles
10294           (gnus-summary-save-parts-1 type dir handles reverse)
10295           (unless gnus-article-mime-handles ;; Don't destroy this case.
10296             (mm-destroy-parts handles)))))))
10297
10298 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10299   (if (stringp (car handle))
10300       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10301               (cdr handle))
10302     (when (if reverse
10303               (not (string-match type (mm-handle-media-type handle)))
10304             (string-match type (mm-handle-media-type handle)))
10305       (let ((file (expand-file-name
10306                    (file-name-nondirectory
10307                     (or
10308                      (mail-content-type-get
10309                       (mm-handle-disposition handle) 'filename)
10310                      (concat gnus-newsgroup-name
10311                              "." (number-to-string
10312                                   (cdr gnus-article-current)))))
10313                    dir)))
10314         (unless (file-exists-p file)
10315           (mm-save-part-to-file handle file))))))
10316
10317 ;; Summary extract commands
10318
10319 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10320   (let ((buffer-read-only nil)
10321         (article (gnus-summary-article-number))
10322         after-article b e)
10323     (unless (gnus-summary-goto-subject article)
10324       (error "No such article: %d" article))
10325     (gnus-summary-position-point)
10326     ;; If all commands are to be bunched up on one line, we collect
10327     ;; them here.
10328     (unless gnus-view-pseudos-separately
10329       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10330             files action)
10331         (while ps
10332           (setq action (cdr (assq 'action (car ps))))
10333           (setq files (list (cdr (assq 'name (car ps)))))
10334           (while (and ps (cdr ps)
10335                       (string= (or action "1")
10336                                (or (cdr (assq 'action (cadr ps))) "2")))
10337             (push (cdr (assq 'name (cadr ps))) files)
10338             (setcdr ps (cddr ps)))
10339           (when files
10340             (when (not (string-match "%s" action))
10341               (push " " files))
10342             (push " " files)
10343             (when (assq 'execute (car ps))
10344               (setcdr (assq 'execute (car ps))
10345                       (funcall (if (string-match "%s" action)
10346                                    'format 'concat)
10347                                action
10348                                (mapconcat
10349                                 (lambda (f)
10350                                   (if (equal f " ")
10351                                       f
10352                                     (gnus-quote-arg-for-sh-or-csh f)))
10353                                 files " ")))))
10354           (setq ps (cdr ps)))))
10355     (if (and gnus-view-pseudos (not not-view))
10356         (while pslist
10357           (when (assq 'execute (car pslist))
10358             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10359                                   (eq gnus-view-pseudos 'not-confirm)))
10360           (setq pslist (cdr pslist)))
10361       (save-excursion
10362         (while pslist
10363           (setq after-article (or (cdr (assq 'article (car pslist)))
10364                                   (gnus-summary-article-number)))
10365           (gnus-summary-goto-subject after-article)
10366           (forward-line 1)
10367           (setq b (point))
10368           (insert "    " (file-name-nondirectory
10369                           (cdr (assq 'name (car pslist))))
10370                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10371           (setq e (point))
10372           (forward-line -1)             ; back to `b'
10373           (gnus-add-text-properties
10374            b (1- e) (list 'gnus-number gnus-reffed-article-number
10375                           gnus-mouse-face-prop gnus-mouse-face))
10376           (gnus-data-enter
10377            after-article gnus-reffed-article-number
10378            gnus-unread-mark b (car pslist) 0 (- e b))
10379           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10380           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10381           (setq pslist (cdr pslist)))))))
10382
10383 (defun gnus-pseudos< (p1 p2)
10384   (let ((c1 (cdr (assq 'action p1)))
10385         (c2 (cdr (assq 'action p2))))
10386     (and c1 c2 (string< c1 c2))))
10387
10388 (defun gnus-request-pseudo-article (props)
10389   (cond ((assq 'execute props)
10390          (gnus-execute-command (cdr (assq 'execute props)))))
10391   (let ((gnus-current-article (gnus-summary-article-number)))
10392     (gnus-run-hooks 'gnus-mark-article-hook)))
10393
10394 (defun gnus-execute-command (command &optional automatic)
10395   (save-excursion
10396     (gnus-article-setup-buffer)
10397     (set-buffer gnus-article-buffer)
10398     (setq buffer-read-only nil)
10399     (let ((command (if automatic command
10400                      (read-string "Command: " (cons command 0)))))
10401       (erase-buffer)
10402       (insert "$ " command "\n\n")
10403       (if gnus-view-pseudo-asynchronously
10404           (start-process "gnus-execute" (current-buffer) shell-file-name
10405                          shell-command-switch command)
10406         (call-process shell-file-name nil t nil
10407                       shell-command-switch command)))))
10408
10409 ;; Summary kill commands.
10410
10411 (defun gnus-summary-edit-global-kill (article)
10412   "Edit the \"global\" kill file."
10413   (interactive (list (gnus-summary-article-number)))
10414   (gnus-group-edit-global-kill article))
10415
10416 (defun gnus-summary-edit-local-kill ()
10417   "Edit a local kill file applied to the current newsgroup."
10418   (interactive)
10419   (setq gnus-current-headers (gnus-summary-article-header))
10420   (gnus-group-edit-local-kill
10421    (gnus-summary-article-number) gnus-newsgroup-name))
10422
10423 ;;; Header reading.
10424
10425 (defun gnus-read-header (id &optional header)
10426   "Read the headers of article ID and enter them into the Gnus system."
10427   (let ((group gnus-newsgroup-name)
10428         (gnus-override-method
10429          (or
10430           gnus-override-method
10431           (and (gnus-news-group-p gnus-newsgroup-name)
10432                (car (gnus-refer-article-methods)))))
10433         where)
10434     ;; First we check to see whether the header in question is already
10435     ;; fetched.
10436     (if (stringp id)
10437         ;; This is a Message-ID.
10438         (setq header (or header (gnus-id-to-header id)))
10439       ;; This is an article number.
10440       (setq header (or header (gnus-summary-article-header id))))
10441     (if (and header
10442              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10443         ;; We have found the header.
10444         header
10445       ;; If this is a sparse article, we have to nix out its
10446       ;; previous entry in the thread hashtb.
10447       (when (and header
10448                  (gnus-summary-article-sparse-p (mail-header-number header)))
10449         (let* ((parent (gnus-parent-id (mail-header-references header)))
10450                (thread (and parent (gnus-id-to-thread parent))))
10451           (when thread
10452             (delq (assq header thread) thread))))
10453       ;; We have to really fetch the header to this article.
10454       (save-excursion
10455         (set-buffer nntp-server-buffer)
10456         (when (setq where (gnus-request-head id group))
10457           (nnheader-fold-continuation-lines)
10458           (goto-char (point-max))
10459           (insert ".\n")
10460           (goto-char (point-min))
10461           (insert "211 ")
10462           (princ (cond
10463                   ((numberp id) id)
10464                   ((cdr where) (cdr where))
10465                   (header (mail-header-number header))
10466                   (t gnus-reffed-article-number))
10467                  (current-buffer))
10468           (insert " Article retrieved.\n"))
10469         (if (or (not where)
10470                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10471             ()                          ; Malformed head.
10472           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10473             (when (and (stringp id)
10474                        (not (string= (gnus-group-real-name group)
10475                                      (car where))))
10476               ;; If we fetched by Message-ID and the article came
10477               ;; from a different group, we fudge some bogus article
10478               ;; numbers for this article.
10479               (mail-header-set-number header gnus-reffed-article-number))
10480             (save-excursion
10481               (set-buffer gnus-summary-buffer)
10482               (decf gnus-reffed-article-number)
10483               (gnus-remove-header (mail-header-number header))
10484               (push header gnus-newsgroup-headers)
10485               (setq gnus-current-headers header)
10486               (push (mail-header-number header) gnus-newsgroup-limit)))
10487           header)))))
10488
10489 (defun gnus-remove-header (number)
10490   "Remove header NUMBER from `gnus-newsgroup-headers'."
10491   (if (and gnus-newsgroup-headers
10492            (= number (mail-header-number (car gnus-newsgroup-headers))))
10493       (pop gnus-newsgroup-headers)
10494     (let ((headers gnus-newsgroup-headers))
10495       (while (and (cdr headers)
10496                   (not (= number (mail-header-number (cadr headers)))))
10497         (pop headers))
10498       (when (cdr headers)
10499         (setcdr headers (cddr headers))))))
10500
10501 ;;;
10502 ;;; summary highlights
10503 ;;;
10504
10505 (defun gnus-highlight-selected-summary ()
10506   "Highlight selected article in summary buffer."
10507   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10508   (when gnus-summary-selected-face
10509     (save-excursion
10510       (let* ((beg (progn (beginning-of-line) (point)))
10511              (end (progn (end-of-line) (point)))
10512              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10513              (from (if (get-text-property beg gnus-mouse-face-prop)
10514                        beg
10515                      (or (next-single-property-change
10516                           beg gnus-mouse-face-prop nil end)
10517                          beg)))
10518              (to
10519               (if (= from end)
10520                   (- from 2)
10521                 (or (next-single-property-change
10522                      from gnus-mouse-face-prop nil end)
10523                     end))))
10524         ;; If no mouse-face prop on line we will have to = from = end,
10525         ;; so we highlight the entire line instead.
10526         (when (= (+ to 2) from)
10527           (setq from beg)
10528           (setq to end))
10529         (if gnus-newsgroup-selected-overlay
10530             ;; Move old overlay.
10531             (gnus-move-overlay
10532              gnus-newsgroup-selected-overlay from to (current-buffer))
10533           ;; Create new overlay.
10534           (gnus-overlay-put
10535            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10536            'face gnus-summary-selected-face))))))
10537
10538 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10539 (defun gnus-summary-highlight-line ()
10540   "Highlight current line according to `gnus-summary-highlight'."
10541   (let* ((list gnus-summary-highlight)
10542          (p (point))
10543          (end (progn (end-of-line) (point)))
10544          ;; now find out where the line starts and leave point there.
10545          (beg (progn (beginning-of-line) (point)))
10546          (article (gnus-summary-article-number))
10547          (score (or (cdr (assq (or article gnus-current-article)
10548                                gnus-newsgroup-scored))
10549                     gnus-summary-default-score 0))
10550          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10551          (inhibit-read-only t))
10552     ;; Eval the cars of the lists until we find a match.
10553     (let ((default gnus-summary-default-score)
10554           (default-high gnus-summary-default-high-score)
10555           (default-low gnus-summary-default-low-score))
10556       (while (and list
10557                   (not (eval (caar list))))
10558         (setq list (cdr list))))
10559     (let ((face (cdar list)))
10560       (unless (eq face (get-text-property beg 'face))
10561         (gnus-put-text-property-excluding-characters-with-faces
10562          beg end 'face
10563          (setq face (if (boundp face) (symbol-value face) face)))
10564         (when gnus-summary-highlight-line-function
10565           (funcall gnus-summary-highlight-line-function article face))))
10566     (goto-char p)))
10567
10568 (defun gnus-update-read-articles (group unread &optional compute)
10569   "Update the list of read articles in GROUP."
10570   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10571          (entry (gnus-gethash group gnus-newsrc-hashtb))
10572          (info (nth 2 entry))
10573          (prev 1)
10574          (unread (sort (copy-sequence unread) '<))
10575          read)
10576     (if (or (not info) (not active))
10577         ;; There is no info on this group if it was, in fact,
10578         ;; killed.  Gnus stores no information on killed groups, so
10579         ;; there's nothing to be done.
10580         ;; One could store the information somewhere temporarily,
10581         ;; perhaps...  Hmmm...
10582         ()
10583       ;; Remove any negative articles numbers.
10584       (while (and unread (< (car unread) 0))
10585         (setq unread (cdr unread)))
10586       ;; Remove any expired article numbers
10587       (while (and unread (< (car unread) (car active)))
10588         (setq unread (cdr unread)))
10589       ;; Compute the ranges of read articles by looking at the list of
10590       ;; unread articles.
10591       (while unread
10592         (when (/= (car unread) prev)
10593           (push (if (= prev (1- (car unread))) prev
10594                   (cons prev (1- (car unread))))
10595                 read))
10596         (setq prev (1+ (car unread)))
10597         (setq unread (cdr unread)))
10598       (when (<= prev (cdr active))
10599         (push (cons prev (cdr active)) read))
10600       (setq read (if (> (length read) 1) (nreverse read) read))
10601       (if compute
10602           read
10603         (save-excursion
10604           (let (setmarkundo)
10605             ;; Propagate the read marks to the backend.
10606             (when (gnus-check-backend-function 'request-set-mark group)
10607               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10608                     (add (gnus-remove-from-range read (gnus-info-read info))))
10609                 (when (or add del)
10610                   (unless (gnus-check-group group)
10611                     (error "Can't open server for %s" group))
10612                   (gnus-request-set-mark
10613                    group (delq nil (list (if add (list add 'add '(read)))
10614                                          (if del (list del 'del '(read))))))
10615                   (setq setmarkundo
10616                         `(gnus-request-set-mark
10617                           ,group
10618                           ',(delq nil (list
10619                                        (if del (list del 'add '(read)))
10620                                        (if add (list add 'del '(read))))))))))
10621             (set-buffer gnus-group-buffer)
10622             (gnus-undo-register
10623               `(progn
10624                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10625                  (gnus-info-set-read ',info ',(gnus-info-read info))
10626                  (gnus-get-unread-articles-in-group ',info
10627                                                     (gnus-active ,group))
10628                  (gnus-group-update-group ,group t)
10629                  ,setmarkundo))))
10630         ;; Enter this list into the group info.
10631         (gnus-info-set-read info read)
10632         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10633         (gnus-get-unread-articles-in-group info (gnus-active group))
10634         t))))
10635
10636 (defun gnus-offer-save-summaries ()
10637   "Offer to save all active summary buffers."
10638   (let (buffers)
10639     ;; Go through all buffers and find all summaries.
10640     (dolist (buffer (buffer-list))
10641       (when (and (setq buffer (buffer-name buffer))
10642                  (string-match "Summary" buffer)
10643                  (save-excursion
10644                    (set-buffer buffer)
10645                    ;; We check that this is, indeed, a summary buffer.
10646                    (and (eq major-mode 'gnus-summary-mode)
10647                         ;; Also make sure this isn't bogus.
10648                         gnus-newsgroup-prepared
10649                         ;; Also make sure that this isn't a
10650                         ;; dead summary buffer.
10651                         (not gnus-dead-summary-mode))))
10652         (push buffer buffers)))
10653     ;; Go through all these summary buffers and offer to save them.
10654     (when buffers
10655       (save-excursion
10656         (map-y-or-n-p
10657          "Update summary buffer %s? "
10658          (lambda (buf)
10659            (switch-to-buffer buf)
10660            (gnus-summary-exit))
10661          buffers)))))
10662
10663
10664 ;;; @ for mime-partial
10665 ;;;
10666
10667 (defun gnus-request-partial-message ()
10668   (save-excursion
10669     (let ((number (gnus-summary-article-number))
10670           (group gnus-newsgroup-name)
10671           (mother gnus-article-buffer))
10672       (set-buffer (get-buffer-create " *Partial Article*"))
10673       (erase-buffer)
10674       (setq mime-preview-buffer mother)
10675       (gnus-request-article-this-buffer number group)
10676       (mime-parse-buffer)
10677       )))
10678
10679 (autoload 'mime-combine-message/partial-pieces-automatically
10680   "mime-partial"
10681   "Internal method to combine message/partial messages automatically.")
10682
10683 (mime-add-condition
10684  'action '((type . message)(subtype . partial)
10685            (major-mode . gnus-original-article-mode)
10686            (method . mime-combine-message/partial-pieces-automatically)
10687            (summary-buffer-exp . gnus-summary-buffer)
10688            (request-partial-message-method . gnus-request-partial-message)
10689            ))
10690
10691
10692 ;;; @ for message/rfc822
10693 ;;;
10694
10695 (defun gnus-mime-extract-message/rfc822 (entity situation)
10696   (let (group article num cwin swin cur)
10697     (with-temp-buffer
10698       (mime-insert-entity-content entity)
10699       (setq group (or (cdr (assq 'group situation))
10700                       (completing-read "Group: "
10701                                        gnus-active-hashtb
10702                                        nil
10703                                        (gnus-read-active-file-p)
10704                                        gnus-newsgroup-name))
10705             article (gnus-request-accept-article group)))
10706     (when (and (consp article)
10707                (numberp (setq article (cdr article))))
10708       (setq num (1+ (or (cdr (assq 'number situation)) 0))
10709             cwin (get-buffer-window (current-buffer) t))
10710       (save-window-excursion
10711         (if (setq swin (get-buffer-window gnus-summary-buffer t))
10712             (select-window swin)
10713           (set-buffer gnus-summary-buffer))
10714         (setq cur gnus-current-article)
10715         (forward-line num)
10716         (let (gnus-show-threads)
10717           (gnus-summary-goto-subject article t))
10718         (gnus-summary-clear-mark-forward 1)
10719         (gnus-summary-goto-subject cur))
10720       (when (and cwin (window-frame cwin))
10721         (select-frame (window-frame cwin)))
10722       (when (boundp 'mime-acting-situation-to-override)
10723         (set-alist 'mime-acting-situation-to-override
10724                    'group
10725                    group)
10726         (set-alist 'mime-acting-situation-to-override
10727                    'after-method
10728                    `(progn
10729                       (save-current-buffer
10730                         (set-buffer gnus-group-buffer)
10731                         (gnus-activate-group ,group))
10732                       (gnus-summary-goto-article ,cur
10733                                                  gnus-show-all-headers)))
10734         (set-alist 'mime-acting-situation-to-override
10735                    'number num)))))
10736
10737 (mime-add-condition
10738  'action '((type . message)(subtype . rfc822)
10739            (major-mode . gnus-original-article-mode)
10740            (method . gnus-mime-extract-message/rfc822)
10741            (mode . "extract")
10742            ))
10743
10744 (mime-add-condition
10745  'action '((type . message)(subtype . news)
10746            (major-mode . gnus-original-article-mode)
10747            (method . gnus-mime-extract-message/rfc822)
10748            (mode . "extract")
10749            ))
10750
10751 (defun gnus-mime-extract-multipart (entity situation)
10752   (let ((children (mime-entity-children entity))
10753         mime-acting-situation-to-override
10754         f)
10755     (while children
10756       (mime-play-entity (car children)
10757                         (cons (assq 'mode situation)
10758                               mime-acting-situation-to-override))
10759       (setq children (cdr children)))
10760     (if (setq f (cdr (assq 'after-method
10761                            mime-acting-situation-to-override)))
10762         (eval f)
10763       )))
10764
10765 (mime-add-condition
10766  'action '((type . multipart)
10767            (method . gnus-mime-extract-multipart)
10768            (mode . "extract")
10769            )
10770  'with-default)
10771
10772
10773 ;;; @ end
10774 ;;;
10775
10776 (defun gnus-summary-setup-default-charset ()
10777   "Setup newsgroup default charset."
10778   (if (equal gnus-newsgroup-name "nndraft:drafts")
10779       (setq gnus-newsgroup-charset nil)
10780     (let* ((ignored-charsets
10781             (or gnus-newsgroup-ephemeral-ignored-charsets
10782                 (append
10783                  (and gnus-newsgroup-name
10784                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10785                  gnus-newsgroup-ignored-charsets))))
10786       (setq gnus-newsgroup-charset
10787             (or gnus-newsgroup-ephemeral-charset
10788                 (and gnus-newsgroup-name
10789                      (gnus-parameter-charset gnus-newsgroup-name))
10790                 gnus-default-charset))
10791       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10792            ignored-charsets))))
10793
10794 ;;;
10795 ;;; Mime Commands
10796 ;;;
10797
10798 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10799   "Display the current article buffer fully MIME-buttonized.
10800 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10801 treated as multipart/mixed."
10802   (interactive "P")
10803   (require 'gnus-art)
10804   (let ((gnus-unbuttonized-mime-types nil)
10805         (gnus-mime-display-multipart-as-mixed show-all-parts))
10806     (gnus-summary-show-article)))
10807
10808 (defun gnus-summary-repair-multipart (article)
10809   "Add a Content-Type header to a multipart article without one."
10810   (interactive (list (gnus-summary-article-number)))
10811   (gnus-with-article article
10812     (message-narrow-to-head)
10813     (message-remove-header "Mime-Version")
10814     (goto-char (point-max))
10815     (insert "Mime-Version: 1.0\n")
10816     (widen)
10817     (when (search-forward "\n--" nil t)
10818       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10819         (message-narrow-to-head)
10820         (message-remove-header "Content-Type")
10821         (goto-char (point-max))
10822         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10823                         separator))
10824         (widen))))
10825   (let (gnus-mark-article-hook)
10826     (gnus-summary-select-article t t nil article)))
10827
10828 (defun gnus-summary-toggle-display-buttonized ()
10829   "Toggle the buttonizing of the article buffer."
10830   (interactive)
10831   (require 'gnus-art)
10832   (if (setq gnus-inhibit-mime-unbuttonizing
10833             (not gnus-inhibit-mime-unbuttonizing))
10834       (let ((gnus-unbuttonized-mime-types nil))
10835         (gnus-summary-show-article))
10836     (gnus-summary-show-article)))
10837
10838 ;;;
10839 ;;; Intelli-mouse commmands
10840 ;;;
10841
10842 (defun gnus-wheel-summary-scroll (event)
10843   (interactive "e")
10844   (let ((amount (if (memq 'shift (event-modifiers event))
10845                     (car gnus-wheel-scroll-amount)
10846                   (cdr gnus-wheel-scroll-amount)))
10847         (direction (- (* (static-if (featurep 'xemacs)
10848                              (event-button event)
10849                            (cond ((eq 'mouse-4 (event-basic-type event))
10850                                   4)
10851                                  ((eq 'mouse-5 (event-basic-type event))
10852                                   5)))
10853                          2) 9))
10854         edge)
10855     (gnus-summary-scroll-up (* amount direction))
10856     (when (gnus-eval-in-buffer-window gnus-article-buffer
10857             (save-restriction
10858               (widen)
10859               (and (if (< 0 direction)
10860                        (gnus-article-next-page 0)
10861                      (gnus-article-prev-page 0)
10862                      (bobp))
10863                    (if (setq edge (get-text-property
10864                                    (point-min) 'gnus-wheel-edge))
10865                        (setq edge (* edge direction))
10866                      (setq edge -1))
10867                    (or (plusp edge)
10868                        (let ((buffer-read-only nil)
10869                              (inhibit-read-only t))
10870                          (put-text-property (point-min) (point-max)
10871                                             'gnus-wheel-edge direction)
10872                          nil))
10873                    (or (> edge gnus-wheel-edge-resistance)
10874                        (let ((buffer-read-only nil)
10875                              (inhibit-read-only t))
10876                          (put-text-property (point-min) (point-max)
10877                                             'gnus-wheel-edge
10878                                             (* (1+ edge) direction))
10879                          nil))
10880                    (eq last-command 'gnus-wheel-summary-scroll))))
10881       (gnus-summary-next-article nil nil (minusp direction)))))
10882
10883 (defun gnus-wheel-install ()
10884   "Enable mouse wheel support on summary window."
10885   (when gnus-use-wheel
10886     (let ((keys
10887            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10888       (dolist (key keys)
10889         (define-key gnus-summary-mode-map key
10890           'gnus-wheel-summary-scroll)))))
10891
10892 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10893
10894 ;;;
10895 ;;; Traditional PGP commmands
10896 ;;;
10897
10898 (defun gnus-summary-decrypt-article (&optional force)
10899   "Decrypt the current article in traditional PGP way.
10900 This will have permanent effect only in mail groups.
10901 If FORCE is non-nil, allow editing of articles even in read-only
10902 groups."
10903   (interactive "P")
10904   (gnus-summary-select-article t)
10905   (gnus-eval-in-buffer-window gnus-article-buffer
10906     (save-excursion
10907       (save-restriction
10908         (widen)
10909         (goto-char (point-min))
10910         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10911           (error "Not a traditional PGP message!"))
10912         (let ((armor-start (match-beginning 0)))
10913           (if (and (pgg-decrypt-region armor-start (point-max))
10914                    (or force (not (gnus-group-read-only-p))))
10915               (let ((inhibit-read-only t)
10916                     buffer-read-only)
10917                 (delete-region armor-start
10918                                (progn
10919                                  (re-search-forward "^-+END PGP" nil t)
10920                                  (beginning-of-line 2)
10921                                  (point)))
10922                 (insert-buffer-substring pgg-output-buffer))))))))
10923
10924 (defun gnus-summary-verify-article ()
10925   "Verify the current article in traditional PGP way."
10926   (interactive)
10927   (save-excursion
10928     (set-buffer gnus-original-article-buffer)
10929     (goto-char (point-min))
10930     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10931       (error "Not a traditional PGP message!"))
10932     (re-search-forward "^-+END PGP" nil t)
10933     (beginning-of-line 2)
10934     (call-interactively (function pgg-verify-region))))
10935
10936 ;;;
10937 ;;; Generic summary marking commands
10938 ;;;
10939
10940 (defvar gnus-summary-marking-alist
10941   '((read gnus-del-mark "d")
10942     (unread gnus-unread-mark "u")
10943     (ticked gnus-ticked-mark "!")
10944     (dormant gnus-dormant-mark "?")
10945     (expirable gnus-expirable-mark "e"))
10946   "An alist of names/marks/keystrokes.")
10947
10948 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10949 (defvar gnus-summary-mark-map)
10950
10951 (defun gnus-summary-make-all-marking-commands ()
10952   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10953   (dolist (elem gnus-summary-marking-alist)
10954     (apply 'gnus-summary-make-marking-command elem)))
10955
10956 (defun gnus-summary-make-marking-command (name mark keystroke)
10957   (let ((map (make-sparse-keymap)))
10958     (define-key gnus-summary-generic-mark-map keystroke map)
10959     (dolist (lway `((next "next" next nil "n")
10960                     (next-unread "next unread" next t "N")
10961                     (prev "previous" prev nil "p")
10962                     (prev-unread "previous unread" prev t "P")
10963                     (nomove "" nil nil ,keystroke)))
10964       (let ((func (gnus-summary-make-marking-command-1
10965                    mark (car lway) lway name)))
10966         (setq func (eval func))
10967         (define-key map (nth 4 lway) func)))))
10968
10969 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10970   `(defun ,(intern
10971             (format "gnus-summary-put-mark-as-%s%s"
10972                     name (if (eq way 'nomove)
10973                              ""
10974                            (concat "-" (symbol-name way)))))
10975      (n)
10976      ,(format
10977        "Mark the current article as %s%s.
10978 If N, the prefix, then repeat N times.
10979 If N is negative, move in reverse order.
10980 The difference between N and the actual number of articles marked is
10981 returned."
10982        name (car (cdr lway)))
10983      (interactive "p")
10984      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10985
10986 (defun gnus-summary-generic-mark (n mark move unread)
10987   "Mark N articles with MARK."
10988   (unless (eq major-mode 'gnus-summary-mode)
10989     (error "This command can only be used in the summary buffer"))
10990   (gnus-summary-show-thread)
10991   (let ((nummove
10992          (cond
10993           ((eq move 'next) 1)
10994           ((eq move 'prev) -1)
10995           (t 0))))
10996     (if (zerop nummove)
10997         (setq n 1)
10998       (when (< n 0)
10999         (setq n (abs n)
11000               nummove (* -1 nummove))))
11001     (while (and (> n 0)
11002                 (gnus-summary-mark-article nil mark)
11003                 (zerop (gnus-summary-next-subject nummove unread t)))
11004       (setq n (1- n)))
11005     (when (/= 0 n)
11006       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11007     (gnus-summary-recenter)
11008     (gnus-summary-position-point)
11009     (gnus-set-mode-line 'summary)
11010     n))
11011
11012 (defun gnus-summary-insert-articles (articles)
11013   (when (setq articles
11014               (gnus-set-difference articles
11015                                    (mapcar (lambda (h) (mail-header-number h))
11016                                            gnus-newsgroup-headers)))
11017     (setq gnus-newsgroup-headers
11018           (merge 'list
11019                  gnus-newsgroup-headers
11020                  (gnus-fetch-headers articles)
11021                  'gnus-article-sort-by-number))
11022     ;; Suppress duplicates?
11023     (when gnus-suppress-duplicates
11024       (gnus-dup-suppress-articles))
11025
11026     ;; We might want to build some more threads first.
11027     (when (and gnus-fetch-old-headers
11028                (eq gnus-headers-retrieved-by 'nov))
11029       (if (eq gnus-fetch-old-headers 'invisible)
11030           (gnus-build-all-threads)
11031         (gnus-build-old-threads)))
11032     ;; Let the Gnus agent mark articles as read.
11033     (when gnus-agent
11034       (gnus-agent-get-undownloaded-list))
11035     ;; Remove list identifiers from subject
11036     (when gnus-list-identifiers
11037       (gnus-summary-remove-list-identifiers))
11038     ;; First and last article in this newsgroup.
11039     (when gnus-newsgroup-headers
11040       (setq gnus-newsgroup-begin
11041             (mail-header-number (car gnus-newsgroup-headers))
11042             gnus-newsgroup-end
11043             (mail-header-number
11044              (gnus-last-element gnus-newsgroup-headers))))
11045     (when gnus-use-scoring
11046       (gnus-possibly-score-headers))))
11047
11048 (defun gnus-summary-insert-old-articles (&optional all)
11049   "Insert all old articles in this group.
11050 If ALL is non-nil, already read articles become readable.
11051 If ALL is a number, fetch this number of articles."
11052   (interactive "P")
11053   (prog1
11054       (let ((old (mapcar 'car gnus-newsgroup-data))
11055             (i (car gnus-newsgroup-active))
11056             older len)
11057         (while (<= i (cdr gnus-newsgroup-active))
11058           (or (memq i old) (push i older))
11059           (incf i))
11060         (setq len (length older))
11061         (cond
11062          ((null older) nil)
11063          ((numberp all)
11064           (if (< all len)
11065               (setq older (subseq older 0 all))))
11066          (all nil)
11067          (t
11068           (if (and (numberp gnus-large-newsgroup)
11069                    (> len gnus-large-newsgroup))
11070               (let ((input
11071                      (read-string
11072                       (format
11073                        "How many articles from %s (default %d): "
11074                        (gnus-limit-string
11075                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
11076                        len))))
11077                 (unless (string-match "^[ \t]*$" input)
11078                   (setq all (string-to-number input))
11079                   (if (< all len)
11080                       (setq older (subseq older 0 all))))))))
11081         (if (not older)
11082             (message "No old news.")
11083           (gnus-summary-insert-articles older)
11084           (gnus-summary-limit (gnus-union older old))))
11085     (gnus-summary-position-point)))
11086
11087 (defun gnus-summary-insert-new-articles ()
11088   "Insert all new articles in this group."
11089   (interactive)
11090   (prog1
11091       (let ((old (mapcar 'car gnus-newsgroup-data))
11092             (old-active gnus-newsgroup-active)
11093             (nnmail-fetched-sources (list t))
11094             i new)
11095         (setq gnus-newsgroup-active
11096               (gnus-activate-group gnus-newsgroup-name 'scan))
11097         (setq i (1+ (cdr old-active)))
11098         (while (<= i (cdr gnus-newsgroup-active))
11099           (push i new)
11100           (incf i))
11101         (if (not new)
11102             (message "No gnus is bad news.")
11103           (setq new (nreverse new))
11104           (gnus-summary-insert-articles new)
11105           (setq gnus-newsgroup-unreads
11106                 (append gnus-newsgroup-unreads new))
11107           (gnus-summary-limit (gnus-union old new))))
11108     (gnus-summary-position-point)))
11109
11110 (gnus-summary-make-all-marking-commands)
11111
11112 (gnus-ems-redefine)
11113
11114 (provide 'gnus-sum)
11115
11116 (run-hooks 'gnus-sum-load-hook)
11117
11118 ;;; gnus-sum.el ends here