Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58
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 This can be a predicate specifier which says which threads to hide.
250 If threads are hidden, you have to run the command
251 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
252 to expose hidden threads."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-hide-killed t
257   "*If non-nil, hide killed threads automatically."
258   :group 'gnus-thread
259   :type 'boolean)
260
261 (defcustom gnus-thread-ignore-subject t
262   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
263 If nil, articles that have different subjects from their parents will
264 start separate threads."
265   :group 'gnus-thread
266   :type 'boolean)
267
268 (defcustom gnus-thread-operation-ignore-subject t
269   "*If non-nil, subjects will be ignored when doing thread commands.
270 This affects commands like `gnus-summary-kill-thread' and
271 `gnus-summary-lower-thread'.
272
273 If this variable is nil, articles in the same thread with different
274 subjects will not be included in the operation in question.  If this
275 variable is `fuzzy', only articles that have subjects that are fuzzily
276 equal will be included."
277   :group 'gnus-thread
278   :type '(choice (const :tag "off" nil)
279                  (const fuzzy)
280                  (sexp :tag "on" t)))
281
282 (defcustom gnus-thread-indent-level 4
283   "*Number that says how much each sub-thread should be indented."
284   :group 'gnus-thread
285   :type 'integer)
286
287 (defcustom gnus-auto-extend-newsgroup t
288   "*If non-nil, extend newsgroup forward and backward when requested."
289   :group 'gnus-summary-choose
290   :type 'boolean)
291
292 (defcustom gnus-auto-select-first t
293   "*If non-nil, select the article under point.
294 Which article this is is controlled by the `gnus-auto-select-subject'
295 variable.
296
297 If you want to prevent automatic selection of articles in some
298 newsgroups, set the variable to nil in `gnus-select-group-hook'."
299   :group 'gnus-group-select
300   :type '(choice (const :tag "none" nil)
301                  (sexp :menu-tag "first" t)))
302
303 (defcustom gnus-auto-select-subject 'unread
304   "*Says what subject to place under point when entering a group.
305
306 This variable can either be the symbols `first' (place point on the
307 first subject), `unread' (place point on the subject line of the first
308 unread article), `best' (place point on the subject line of the
309 higest-scored article), `unseen' (place point on the subject line of
310 the first unseen article), 'unseen-or-unread' (place point on the subject
311 line of the first unseen article or, if all article have been seen, on the
312 subject line of the first unread article), or a function to be called to
313 place point on some subject line.."
314   :group 'gnus-group-select
315   :type '(choice (const best)
316                  (const unread)
317                  (const first)
318                  (const unseen)
319                  (const unseen-or-unread)))
320
321 (defcustom gnus-dont-select-after-jump-to-other-group nil
322   "If non-nil, don't select the first unread article after entering the
323 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
324 it is depend on the value of `gnus-auto-select-first' whether to select
325 or not."
326   :group 'gnus-group-select
327   :type 'boolean)
328
329 (defcustom gnus-auto-select-next t
330   "*If non-nil, offer to go to the next group from the end of the previous.
331 If the value is t and the next newsgroup is empty, Gnus will exit
332 summary mode and go back to group mode.  If the value is neither nil
333 nor t, Gnus will select the following unread newsgroup.  In
334 particular, if the value is the symbol `quietly', the next unread
335 newsgroup will be selected without any confirmation, and if it is
336 `almost-quietly', the next group will be selected without any
337 confirmation if you are located on the last article in the group.
338 Finally, if this variable is `slightly-quietly', the `Z n' command
339 will go to the next group without confirmation."
340   :group 'gnus-summary-maneuvering
341   :type '(choice (const :tag "off" nil)
342                  (const quietly)
343                  (const almost-quietly)
344                  (const slightly-quietly)
345                  (sexp :menu-tag "on" t)))
346
347 (defcustom gnus-auto-select-same nil
348   "*If non-nil, select the next article with the same subject.
349 If there are no more articles with the same subject, go to
350 the first unread article."
351   :group 'gnus-summary-maneuvering
352   :type 'boolean)
353
354 (defcustom gnus-summary-check-current nil
355   "*If non-nil, consider the current article when moving.
356 The \"unread\" movement commands will stay on the same line if the
357 current article is unread."
358   :group 'gnus-summary-maneuvering
359   :type 'boolean)
360
361 (defcustom gnus-auto-center-summary t
362   "*If non-nil, always center the current summary buffer.
363 In particular, if `vertical' do only vertical recentering.  If non-nil
364 and non-`vertical', do both horizontal and vertical recentering."
365   :group 'gnus-summary-maneuvering
366   :type '(choice (const :tag "none" nil)
367                  (const vertical)
368                  (integer :tag "height")
369                  (sexp :menu-tag "both" t)))
370
371 (defcustom gnus-show-all-headers nil
372   "*If non-nil, don't hide any headers."
373   :group 'gnus-article-hiding
374   :group 'gnus-article-headers
375   :type 'boolean)
376
377 (defcustom gnus-summary-ignore-duplicates nil
378   "*If non-nil, ignore articles with identical Message-ID headers."
379   :group 'gnus-summary
380   :type 'boolean)
381
382 (defcustom gnus-single-article-buffer t
383   "*If non-nil, display all articles in the same buffer.
384 If nil, each group will get its own article buffer."
385   :group 'gnus-article-various
386   :type 'boolean)
387
388 (defcustom gnus-break-pages t
389   "*If non-nil, do page breaking on articles.
390 The page delimiter is specified by the `gnus-page-delimiter'
391 variable."
392   :group 'gnus-article-various
393   :type 'boolean)
394
395 (defcustom gnus-show-mime t
396   "*If non-nil, do mime processing of articles.
397 The articles will simply be fed to the function given by
398 `gnus-article-display-method-for-mime'."
399   :group 'gnus-article-mime
400   :type 'boolean)
401
402 (defcustom gnus-move-split-methods nil
403   "*Variable used to suggest where articles are to be moved to.
404 It uses the same syntax as the `gnus-split-methods' variable.
405 However, whereas `gnus-split-methods' specifies file names as targets,
406 this variable specifies group names."
407   :group 'gnus-summary-mail
408   :type '(repeat (choice (list :value (fun) function)
409                          (cons :value ("" "") regexp (repeat string))
410                          (sexp :value nil))))
411
412 (defcustom gnus-unread-mark ?\ ;;;Whitespace
413   "*Mark used for unread articles."
414   :group 'gnus-summary-marks
415   :type 'character)
416
417 (defcustom gnus-ticked-mark ?!
418   "*Mark used for ticked articles."
419   :group 'gnus-summary-marks
420   :type 'character)
421
422 (defcustom gnus-dormant-mark ??
423   "*Mark used for dormant articles."
424   :group 'gnus-summary-marks
425   :type 'character)
426
427 (defcustom gnus-del-mark ?r
428   "*Mark used for del'd articles."
429   :group 'gnus-summary-marks
430   :type 'character)
431
432 (defcustom gnus-read-mark ?R
433   "*Mark used for read articles."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-expirable-mark ?E
438   "*Mark used for expirable articles."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-killed-mark ?K
443   "*Mark used for killed articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-souped-mark ?F
448   "*Mark used for souped articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-kill-file-mark ?X
453   "*Mark used for articles killed by kill files."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-low-score-mark ?Y
458   "*Mark used for articles with a low score."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-catchup-mark ?C
463   "*Mark used for articles that are caught up."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-replied-mark ?A
468   "*Mark used for articles that have been replied to."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-forwarded-mark ?F
473   "*Mark used for articles that have been forwarded."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-recent-mark ?N
478   "*Mark used for articles that are recent."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-cached-mark ?*
483   "*Mark used for articles that are in the cache."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-saved-mark ?S
488   "*Mark used for articles that have been saved."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-unseen-mark ?.
493   "*Mark used for articles that haven't been seen."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-no-mark ?\ ;;;Whitespace
498   "*Mark used for articles that have no other secondary mark."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-ancient-mark ?O
503   "*Mark used for ancient articles."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-sparse-mark ?Q
508   "*Mark used for sparsely reffed articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-canceled-mark ?G
513   "*Mark used for canceled articles."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-duplicate-mark ?M
518   "*Mark used for duplicate articles."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-undownloaded-mark ?@
523   "*Mark used for articles that weren't downloaded."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-downloadable-mark ?%
528   "*Mark used for articles that are to be downloaded."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-unsendable-mark ?=
533   "*Mark used for articles that won't be sent."
534   :group 'gnus-summary-marks
535   :type 'character)
536
537 (defcustom gnus-score-over-mark ?+
538   "*Score mark used for articles with high scores."
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-score-below-mark ?-
543   "*Score mark used for articles with low scores."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
548   "*There is no thread under the article."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-not-empty-thread-mark ?=
553   "*There is a thread under the article."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-view-pseudo-asynchronously nil
558   "*If non-nil, Gnus will view pseudo-articles asynchronously."
559   :group 'gnus-extract-view
560   :type 'boolean)
561
562 (defcustom gnus-auto-expirable-marks
563   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
564         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
565         gnus-souped-mark gnus-duplicate-mark)
566   "*The list of marks converted into expiration if a group is auto-expirable."
567   :version "21.1"
568   :group 'gnus-summary
569   :type '(repeat character))
570
571 (defcustom gnus-inhibit-user-auto-expire t
572   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
573   :version "21.1"
574   :group 'gnus-summary
575   :type 'boolean)
576
577 (defcustom gnus-view-pseudos nil
578   "*If `automatic', pseudo-articles will be viewed automatically.
579 If `not-confirm', pseudos will be viewed automatically, and the user
580 will not be asked to confirm the command."
581   :group 'gnus-extract-view
582   :type '(choice (const :tag "off" nil)
583                  (const automatic)
584                  (const not-confirm)))
585
586 (defcustom gnus-view-pseudos-separately t
587   "*If non-nil, one pseudo-article will be created for each file to be viewed.
588 If nil, all files that use the same viewing command will be given as a
589 list of parameters to that command."
590   :group 'gnus-extract-view
591   :type 'boolean)
592
593 (defcustom gnus-insert-pseudo-articles t
594   "*If non-nil, insert pseudo-articles when decoding articles."
595   :group 'gnus-extract-view
596   :type 'boolean)
597
598 (defcustom gnus-summary-dummy-line-format
599   "  %(:                          :%) %S\n"
600   "*The format specification for the dummy roots in the summary buffer.
601 It works along the same lines as a normal formatting string,
602 with some simple extensions.
603
604 %S  The subject
605
606 General format specifiers can also be used.
607 See (gnus)Formatting Variables."
608   :link '(custom-manual "(gnus)Formatting Variables")
609   :group 'gnus-threading
610   :type 'string)
611
612 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
613   "*The format specification for the summary mode line.
614 It works along the same lines as a normal formatting string,
615 with some simple extensions:
616
617 %G  Group name
618 %p  Unprefixed group name
619 %A  Current article number
620 %z  Current article score
621 %V  Gnus version
622 %U  Number of unread articles in the group
623 %e  Number of unselected articles in the group
624 %Z  A string with unread/unselected article counts
625 %g  Shortish group name
626 %S  Subject of the current article
627 %u  User-defined spec
628 %s  Current score file name
629 %d  Number of dormant articles
630 %r  Number of articles that have been marked as read in this session
631 %E  Number of articles expunged by the score files"
632   :group 'gnus-summary-format
633   :type 'string)
634
635 (defcustom gnus-list-identifiers nil
636   "Regexp that matches list identifiers to be removed from subject.
637 This can also be a list of regexps."
638   :version "21.1"
639   :group 'gnus-summary-format
640   :group 'gnus-article-hiding
641   :type '(choice (const :tag "none" nil)
642                  (regexp :value ".*")
643                  (repeat :value (".*") regexp)))
644
645 (defcustom gnus-summary-mark-below 0
646   "*Mark all articles with a score below this variable as read.
647 This variable is local to each summary buffer and usually set by the
648 score file."
649   :group 'gnus-score-default
650   :type 'integer)
651
652 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
653   "*List of functions used for sorting articles in the summary buffer.
654
655 Each function takes two articles and returns non-nil if the first
656 article should be sorted before the other.  If you use more than one
657 function, the primary sort function should be the last.  You should
658 probably always include `gnus-article-sort-by-number' in the list of
659 sorting functions -- preferably first.  Also note that sorting by date
660 is often much slower than sorting by number, and the sorting order is
661 very similar.  (Sorting by date means sorting by the time the message
662 was sent, sorting by number means sorting by arrival time.)
663
664 Ready-made functions include `gnus-article-sort-by-number',
665 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
666 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
667
668 When threading is turned on, the variable `gnus-thread-sort-functions'
669 controls how articles are sorted."
670   :group 'gnus-summary-sort
671   :type '(repeat (choice (function-item gnus-article-sort-by-number)
672                          (function-item gnus-article-sort-by-author)
673                          (function-item gnus-article-sort-by-subject)
674                          (function-item gnus-article-sort-by-date)
675                          (function-item gnus-article-sort-by-score)
676                          (function :tag "other"))))
677
678 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
679   "*List of functions used for sorting threads in the summary buffer.
680 By default, threads are sorted by article number.
681
682 Each function takes two threads and returns non-nil if the first
683 thread should be sorted before the other.  If you use more than one
684 function, the primary sort function should be the last.  You should
685 probably always include `gnus-thread-sort-by-number' in the list of
686 sorting functions -- preferably first.  Also note that sorting by date
687 is often much slower than sorting by number, and the sorting order is
688 very similar.  (Sorting by date means sorting by the time the message
689 was sent, sorting by number means sorting by arrival time.)
690
691 Ready-made functions include `gnus-thread-sort-by-number',
692 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
693 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
694 `gnus-thread-sort-by-most-recent-number',
695 `gnus-thread-sort-by-most-recent-date', and
696 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
697
698 When threading is turned off, the variable
699 `gnus-article-sort-functions' controls how articles are sorted."
700   :group 'gnus-summary-sort
701   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
702                          (function-item gnus-thread-sort-by-author)
703                          (function-item gnus-thread-sort-by-subject)
704                          (function-item gnus-thread-sort-by-date)
705                          (function-item gnus-thread-sort-by-score)
706                          (function-item gnus-thread-sort-by-total-score)
707                          (function :tag "other"))))
708
709 (defcustom gnus-thread-score-function '+
710   "*Function used for calculating the total score of a thread.
711
712 The function is called with the scores of the article and each
713 subthread and should then return the score of the thread.
714
715 Some functions you can use are `+', `max', or `min'."
716   :group 'gnus-summary-sort
717   :type 'function)
718
719 (defcustom gnus-summary-expunge-below nil
720   "All articles that have a score less than this variable will be expunged.
721 This variable is local to the summary buffers."
722   :group 'gnus-score-default
723   :type '(choice (const :tag "off" nil)
724                  integer))
725
726 (defcustom gnus-thread-expunge-below nil
727   "All threads that have a total score less than this variable will be expunged.
728 See `gnus-thread-score-function' for en explanation of what a
729 \"thread score\" is.
730
731 This variable is local to the summary buffers."
732   :group 'gnus-threading
733   :group 'gnus-score-default
734   :type '(choice (const :tag "off" nil)
735                  integer))
736
737 (defcustom gnus-summary-mode-hook nil
738   "*A hook for Gnus summary mode.
739 This hook is run before any variables are set in the summary buffer."
740   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
741   :group 'gnus-summary-various
742   :type 'hook)
743
744 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
745 (when (featurep 'xemacs)
746   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
747   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
748   (add-hook 'gnus-summary-mode-hook
749             'gnus-xmas-switch-horizontal-scrollbar-off))
750
751 (defcustom gnus-summary-menu-hook nil
752   "*Hook run after the creation of the summary mode menu."
753   :group 'gnus-summary-visual
754   :type 'hook)
755
756 (defcustom gnus-summary-exit-hook nil
757   "*A hook called on exit from the summary buffer.
758 It will be called with point in the group buffer."
759   :group 'gnus-summary-exit
760   :type 'hook)
761
762 (defcustom gnus-summary-prepare-hook nil
763   "*A hook called after the summary buffer has been generated.
764 If you want to modify the summary buffer, you can use this hook."
765   :group 'gnus-summary-various
766   :type 'hook)
767
768 (defcustom gnus-summary-prepared-hook nil
769   "*A hook called as the last thing after the summary buffer has been generated."
770   :group 'gnus-summary-various
771   :type 'hook)
772
773 (defcustom gnus-summary-generate-hook nil
774   "*A hook run just before generating the summary buffer.
775 This hook is commonly used to customize threading variables and the
776 like."
777   :group 'gnus-summary-various
778   :type 'hook)
779
780 (defcustom gnus-select-group-hook nil
781   "*A hook called when a newsgroup is selected.
782
783 If you'd like to simplify subjects like the
784 `gnus-summary-next-same-subject' command does, you can use the
785 following hook:
786
787  (add-hook gnus-select-group-hook
788            (lambda ()
789              (mapcar (lambda (header)
790                        (mail-header-set-subject
791                         header
792                         (gnus-simplify-subject
793                          (mail-header-subject header) 're-only)))
794                      gnus-newsgroup-headers)))"
795   :group 'gnus-group-select
796   :type 'hook)
797
798 (defcustom gnus-select-article-hook nil
799   "*A hook called when an article is selected."
800   :group 'gnus-summary-choose
801   :type 'hook)
802
803 (defcustom gnus-visual-mark-article-hook
804   (list 'gnus-highlight-selected-summary)
805   "*Hook run after selecting an article in the summary buffer.
806 It is meant to be used for highlighting the article in some way.  It
807 is not run if `gnus-visual' is nil."
808   :group 'gnus-summary-visual
809   :type 'hook)
810
811 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
812   "*A hook called before parsing the headers."
813   :group 'gnus-various
814   :type 'hook)
815
816 (defcustom gnus-exit-group-hook nil
817   "*A hook called when exiting summary mode.
818 This hook is not called from the non-updating exit commands like `Q'."
819   :group 'gnus-various
820   :type 'hook)
821
822 (defcustom gnus-summary-update-hook
823   (list 'gnus-summary-highlight-line)
824   "*A hook called when a summary line is changed.
825 The hook will not be called if `gnus-visual' is nil.
826
827 The default function `gnus-summary-highlight-line' will
828 highlight the line according to the `gnus-summary-highlight'
829 variable."
830   :group 'gnus-summary-visual
831   :type 'hook)
832
833 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
834   "*A hook called when an article is selected for the first time.
835 The hook is intended to mark an article as read (or unread)
836 automatically when it is selected."
837   :group 'gnus-summary-choose
838   :type 'hook)
839
840 (defcustom gnus-group-no-more-groups-hook nil
841   "*A hook run when returning to group mode having no more (unread) groups."
842   :group 'gnus-group-select
843   :type 'hook)
844
845 (defcustom gnus-ps-print-hook nil
846   "*A hook run before ps-printing something from Gnus."
847   :group 'gnus-summary
848   :type 'hook)
849
850 (defcustom gnus-summary-display-arrow
851   (and (fboundp 'display-graphic-p)
852        (display-graphic-p))
853   "*If non-nil, display an arrow highlighting the current article."
854   :version "21.1"
855   :group 'gnus-summary
856   :type 'boolean)
857
858 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
859   "Face used for highlighting the current article in the summary buffer."
860   :group 'gnus-summary-visual
861   :type 'face)
862
863 (defcustom gnus-summary-highlight
864   '(((= mark gnus-canceled-mark)
865      . gnus-summary-cancelled-face)
866     ((and (> score default-high)
867           (or (= mark gnus-dormant-mark)
868               (= mark gnus-ticked-mark)))
869      . gnus-summary-high-ticked-face)
870     ((and (< score default-low)
871           (or (= mark gnus-dormant-mark)
872               (= mark gnus-ticked-mark)))
873      . gnus-summary-low-ticked-face)
874     ((or (= mark gnus-dormant-mark)
875          (= mark gnus-ticked-mark))
876      . gnus-summary-normal-ticked-face)
877     ((and (> score default-high) (= mark gnus-ancient-mark))
878      . gnus-summary-high-ancient-face)
879     ((and (< score default-low) (= mark gnus-ancient-mark))
880      . gnus-summary-low-ancient-face)
881     ((= mark gnus-ancient-mark)
882      . gnus-summary-normal-ancient-face)
883     ((and (> score default-high) (= mark gnus-unread-mark))
884      . gnus-summary-high-unread-face)
885     ((and (< score default-low) (= mark gnus-unread-mark))
886      . gnus-summary-low-unread-face)
887     ((= mark gnus-unread-mark)
888      . gnus-summary-normal-unread-face)
889     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
890                                                   gnus-undownloaded-mark)))
891      . gnus-summary-high-unread-face)
892     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
893                                                  gnus-undownloaded-mark)))
894      . gnus-summary-low-unread-face)
895     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
896           (memq article gnus-newsgroup-unreads))
897      . gnus-summary-normal-unread-face)
898     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
899      . gnus-summary-normal-read-face)
900     ((> score default-high)
901      . gnus-summary-high-read-face)
902     ((< score default-low)
903      . gnus-summary-low-read-face)
904     (t
905      . gnus-summary-normal-read-face))
906   "*Controls the highlighting of summary buffer lines.
907
908 A list of (FORM . FACE) pairs.  When deciding how a a particular
909 summary line should be displayed, each form is evaluated.  The content
910 of the face field after the first true form is used.  You can change
911 how those summary lines are displayed, by editing the face field.
912
913 You can use the following variables in the FORM field.
914
915 score:        The article's score
916 default:      The default article score.
917 default-high: The default score for high scored articles.
918 default-low:  The default score for low scored articles.
919 below:        The score below which articles are automatically marked as read.
920 mark:         The articles mark."
921   :group 'gnus-summary-visual
922   :type '(repeat (cons (sexp :tag "Form" nil)
923                        face)))
924
925 (defcustom gnus-alter-header-function nil
926   "Function called to allow alteration of article header structures.
927 The function is called with one parameter, the article header vector,
928 which it may alter in any way.")
929
930 (defvar gnus-decode-encoded-word-function
931   (mime-find-field-decoder 'From 'nov)
932   "Variable that says which function should be used to decode a string with encoded words.")
933
934 (defcustom gnus-extra-headers '(To Newsgroups)
935   "*Extra headers to parse."
936   :version "21.1"
937   :group 'gnus-summary
938   :type '(repeat symbol))
939
940 (defcustom gnus-ignored-from-addresses
941   (and user-mail-address (regexp-quote user-mail-address))
942   "*Regexp of From headers that may be suppressed in favor of To headers."
943   :version "21.1"
944   :group 'gnus-summary
945   :type 'regexp)
946
947 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
948   "List of charsets that should be ignored.
949 When these charsets are used in the \"charset\" parameter, the
950 default charset will be used instead."
951   :version "21.1"
952   :type '(repeat symbol)
953   :group 'gnus-charset)
954
955 (gnus-define-group-parameter
956  ignored-charsets
957  :type list
958  :function-document
959  "Return the ignored charsets of GROUP."
960  :variable gnus-group-ignored-charsets-alist
961  :variable-default
962  '(("alt\\.chinese\\.text" iso-8859-1))
963  :variable-document
964  "Alist of regexps (to match group names) and charsets that should be ignored.
965 When these charsets are used in the \"charset\" parameter, the
966 default charset will be used instead."
967  :variable-group gnus-charset
968  :variable-type '(repeat (cons (regexp :tag "Group")
969                                (repeat symbol)))
970  :parameter-type '(choice :tag "Ignored charsets"
971                           :value nil
972                           (repeat (symbol)))
973  :parameter-document       "\
974 List of charsets that should be ignored.
975
976 When these charsets are used in the \"charset\" parameter, the
977 default charset will be used instead.")
978
979 (defcustom gnus-group-highlight-words-alist nil
980   "Alist of group regexps and highlight regexps.
981 This variable uses the same syntax as `gnus-emphasis-alist'."
982   :version "21.1"
983   :type '(repeat (cons (regexp :tag "Group")
984                        (repeat (list (regexp :tag "Highlight regexp")
985                                      (number :tag "Group for entire word" 0)
986                                      (number :tag "Group for displayed part" 0)
987                                      (symbol :tag "Face"
988                                              gnus-emphasis-highlight-words)))))
989   :group 'gnus-summary-visual)
990
991 (defcustom gnus-use-wheel nil
992   "Use Intelli-mouse on summary movement"
993   :type 'boolean
994   :group 'gnus-summary-maneuvering)
995
996 (defcustom gnus-wheel-scroll-amount '(5 . 1)
997   "Amount to scroll messages by spinning the mouse wheel.
998 This is actually a cons cell, where the first item is the amount to scroll
999 on a normal wheel event, and the second is the amount to scroll when the
1000 wheel is moved with the shift key depressed."
1001   :type '(cons (integer :tag "Shift") integer)
1002   :group 'gnus-summary-maneuvering)
1003
1004 (defcustom gnus-wheel-edge-resistance 2
1005   "How hard it should be to change the current article
1006 by moving the mouse over the edge of the article window."
1007   :type 'integer
1008   :group 'gnus-summary-maneuvering)
1009
1010 (defcustom gnus-summary-show-article-charset-alist
1011   nil
1012   "Alist of number and charset.
1013 The article will be shown with the charset corresponding to the
1014 numbered argument.
1015 For example: ((1 . cn-gb-2312) (2 . big5))."
1016   :version "21.1"
1017   :type '(repeat (cons (number :tag "Argument" 1)
1018                        (symbol :tag "Charset")))
1019   :group 'gnus-charset)
1020
1021 (defcustom gnus-preserve-marks t
1022   "Whether marks are preserved when moving, copying and respooling messages."
1023   :version "21.1"
1024   :type 'boolean
1025   :group 'gnus-summary-marks)
1026
1027 (defcustom gnus-alter-articles-to-read-function nil
1028   "Function to be called to alter the list of articles to be selected."
1029   :type '(choice (const nil) function)
1030   :group 'gnus-summary)
1031
1032 (defcustom gnus-orphan-score nil
1033   "*All orphans get this score added.  Set in the score file."
1034   :group 'gnus-score-default
1035   :type '(choice (const nil)
1036                  integer))
1037
1038 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1039   "*A regexp to match MIME parts when saving multiple parts of a message
1040 with gnus-summary-save-parts (X m). This regexp will be used by default
1041 when prompting the user for which type of files to save."
1042   :group 'gnus-summary
1043   :type 'regexp)
1044
1045
1046 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1047   "*A regexp to match MIME parts when saving multiple parts of a message
1048 with gnus-summary-save-parts (X m). This regexp will be used by default
1049 when prompting the user for which type of files to save."
1050   :group 'gnus-summary
1051   :type 'regexp)
1052
1053 (defcustom gnus-read-all-available-headers nil
1054   "Whether Gnus should parse all headers made available to it.
1055 This is mostly relevant for slow backends where the user may
1056 wish to widen the summary buffer to include all headers
1057 that were fetched.  Say, for nnultimate groups."
1058   :group 'gnus-summary
1059   :type '(choice boolean regexp))
1060
1061 (defcustom gnus-summary-muttprint-program "muttprint"
1062   "Command (and optional arguments) used to run Muttprint."
1063   :version "21.3"
1064   :group 'gnus-summary
1065   :type 'string)
1066
1067 (defcustom gnus-article-no-strict-mime nil
1068   "If non-nil, don't require strict MIME.
1069 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1070 supply the MIME-Version header or deliberately strip it From the mail.
1071 Set it to non-nil, Gnus will treat some articles as MIME even if
1072 the MIME-Version header is missed."
1073   :version "21.3"
1074   :type 'boolean
1075   :group 'gnus-article)
1076
1077 ;;; Internal variables
1078
1079 (defvar gnus-summary-display-cache nil)
1080 (defvar gnus-article-mime-handles nil)
1081 (defvar gnus-article-decoded-p nil)
1082 (defvar gnus-article-charset nil)
1083 (defvar gnus-article-ignored-charsets nil)
1084 (defvar gnus-scores-exclude-files nil)
1085 (defvar gnus-page-broken nil)
1086 (defvar gnus-inhibit-mime-unbuttonizing nil)
1087
1088 (defvar gnus-original-article nil)
1089 (defvar gnus-article-internal-prepare-hook nil)
1090 (defvar gnus-newsgroup-process-stack nil)
1091
1092 (defvar gnus-thread-indent-array nil)
1093 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1094 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1095   "Function called to sort the articles within a thread after it has been gathered together.")
1096
1097 (defvar gnus-summary-save-parts-type-history nil)
1098 (defvar gnus-summary-save-parts-last-directory nil)
1099
1100 (defvar gnus-summary-save-parts-type-history nil)
1101 (defvar gnus-summary-save-parts-last-directory nil)
1102
1103 ;; Avoid highlighting in kill files.
1104 (defvar gnus-summary-inhibit-highlight nil)
1105 (defvar gnus-newsgroup-selected-overlay nil)
1106 (defvar gnus-inhibit-limiting nil)
1107 (defvar gnus-newsgroup-adaptive-score-file nil)
1108 (defvar gnus-current-score-file nil)
1109 (defvar gnus-current-move-group nil)
1110 (defvar gnus-current-copy-group nil)
1111 (defvar gnus-current-crosspost-group nil)
1112 (defvar gnus-newsgroup-display nil)
1113
1114 (defvar gnus-newsgroup-dependencies nil)
1115 (defvar gnus-newsgroup-adaptive nil)
1116 (defvar gnus-summary-display-article-function nil)
1117 (defvar gnus-summary-highlight-line-function nil
1118   "Function called after highlighting a summary line.")
1119
1120 (defvar gnus-summary-line-format-alist
1121   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1122     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1123     (?s gnus-tmp-subject-or-nil ?s)
1124     (?n gnus-tmp-name ?s)
1125     (?A (std11-address-string
1126          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1127     (?a (or (std11-full-name-string
1128              (car (mime-entity-read-field gnus-tmp-header 'From)))
1129             gnus-tmp-from) ?s)
1130     (?F gnus-tmp-from ?s)
1131     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1132     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1133     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1134     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1135     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1136     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1137     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1138     (?L gnus-tmp-lines ?s)
1139     (?I gnus-tmp-indentation ?s)
1140     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1141     (?R gnus-tmp-replied ?c)
1142     (?\[ gnus-tmp-opening-bracket ?c)
1143     (?\] gnus-tmp-closing-bracket ?c)
1144     (?\> (make-string gnus-tmp-level ? ) ?s)
1145     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1146     (?i gnus-tmp-score ?d)
1147     (?z gnus-tmp-score-char ?c)
1148     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1149     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1150     (?U gnus-tmp-unread ?c)
1151     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1152         ?s)
1153     (?t (gnus-summary-number-of-articles-in-thread
1154          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1155         ?d)
1156     (?e (gnus-summary-number-of-articles-in-thread
1157          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1158         ?c)
1159     (?u gnus-tmp-user-defined ?s)
1160     (?P (gnus-pick-line-number) ?d)
1161     (?B gnus-tmp-thread-tree-header-string ?s)
1162     (user-date (gnus-user-date
1163                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1164   "An alist of format specifications that can appear in summary lines.
1165 These are paired with what variables they correspond with, along with
1166 the type of the variable (string, integer, character, etc).")
1167
1168 (defvar gnus-summary-dummy-line-format-alist
1169   `((?S gnus-tmp-subject ?s)
1170     (?N gnus-tmp-number ?d)
1171     (?u gnus-tmp-user-defined ?s)))
1172
1173 (defvar gnus-summary-mode-line-format-alist
1174   `((?G gnus-tmp-group-name ?s)
1175     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1176     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1177     (?A gnus-tmp-article-number ?d)
1178     (?Z gnus-tmp-unread-and-unselected ?s)
1179     (?V gnus-version ?s)
1180     (?U gnus-tmp-unread-and-unticked ?d)
1181     (?S gnus-tmp-subject ?s)
1182     (?e gnus-tmp-unselected ?d)
1183     (?u gnus-tmp-user-defined ?s)
1184     (?d (length gnus-newsgroup-dormant) ?d)
1185     (?t (length gnus-newsgroup-marked) ?d)
1186     (?r (length gnus-newsgroup-reads) ?d)
1187     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1188     (?E gnus-newsgroup-expunged-tally ?d)
1189     (?s (gnus-current-score-file-nondirectory) ?s)))
1190
1191 (defvar gnus-last-search-regexp nil
1192   "Default regexp for article search command.")
1193
1194 (defvar gnus-summary-search-article-matched-data nil
1195   "Last matched data of article search command.  It is the local variable
1196 in `gnus-article-buffer' which consists of the list of start position,
1197 end position and text.")
1198
1199 (defvar gnus-last-shell-command nil
1200   "Default shell command on article.")
1201
1202 (defvar gnus-newsgroup-begin nil)
1203 (defvar gnus-newsgroup-end nil)
1204 (defvar gnus-newsgroup-last-rmail nil)
1205 (defvar gnus-newsgroup-last-mail nil)
1206 (defvar gnus-newsgroup-last-folder nil)
1207 (defvar gnus-newsgroup-last-file nil)
1208 (defvar gnus-newsgroup-auto-expire nil)
1209 (defvar gnus-newsgroup-active nil)
1210
1211 (defvar gnus-newsgroup-data nil)
1212 (defvar gnus-newsgroup-data-reverse nil)
1213 (defvar gnus-newsgroup-limit nil)
1214 (defvar gnus-newsgroup-limits nil)
1215
1216 (defvar gnus-newsgroup-unreads nil
1217   "Sorted list of unread articles in the current newsgroup.")
1218
1219 (defvar gnus-newsgroup-unselected nil
1220   "Sorted list of unselected unread articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-reads nil
1223   "Alist of read articles and article marks in the current newsgroup.")
1224
1225 (defvar gnus-newsgroup-expunged-tally nil)
1226
1227 (defvar gnus-newsgroup-marked nil
1228   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1229
1230 (defvar gnus-newsgroup-killed nil
1231   "List of ranges of articles that have been through the scoring process.")
1232
1233 (defvar gnus-newsgroup-cached nil
1234   "Sorted list of articles that come from the article cache.")
1235
1236 (defvar gnus-newsgroup-saved nil
1237   "List of articles that have been saved.")
1238
1239 (defvar gnus-newsgroup-kill-headers nil)
1240
1241 (defvar gnus-newsgroup-replied nil
1242   "List of articles that have been replied to in the current newsgroup.")
1243
1244 (defvar gnus-newsgroup-forwarded nil
1245   "List of articles that have been forwarded in the current newsgroup.")
1246
1247 (defvar gnus-newsgroup-recent nil
1248   "List of articles that have are recent in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-expirable nil
1251   "Sorted list of articles in the current newsgroup that can be expired.")
1252
1253 (defvar gnus-newsgroup-processable nil
1254   "List of articles in the current newsgroup that can be processed.")
1255
1256 (defvar gnus-newsgroup-downloadable nil
1257   "Sorted list of articles in the current newsgroup that can be processed.")
1258
1259 (defvar gnus-newsgroup-undownloaded nil
1260   "List of articles in the current newsgroup that haven't been downloaded..")
1261
1262 (defvar gnus-newsgroup-unsendable nil
1263   "List of articles in the current newsgroup that won't be sent.")
1264
1265 (defvar gnus-newsgroup-bookmarks nil
1266   "List of articles in the current newsgroup that have bookmarks.")
1267
1268 (defvar gnus-newsgroup-dormant nil
1269   "Sorted list of dormant articles in the current newsgroup.")
1270
1271 (defvar gnus-newsgroup-unseen nil
1272   "List of unseen articles in the current newsgroup.")
1273
1274 (defvar gnus-newsgroup-seen nil
1275   "Range of seen articles in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-articles nil
1278   "List of articles in the current newsgroup.")
1279
1280 (defvar gnus-newsgroup-scored nil
1281   "List of scored articles in the current newsgroup.")
1282
1283 (defvar gnus-newsgroup-incorporated nil
1284   "List of incorporated articles in the current newsgroup.")
1285
1286 (defvar gnus-newsgroup-headers nil
1287   "List of article headers in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-threads nil)
1290
1291 (defvar gnus-newsgroup-prepared nil
1292   "Whether the current group has been prepared properly.")
1293
1294 (defvar gnus-newsgroup-ancient nil
1295   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1296
1297 (defvar gnus-newsgroup-sparse nil)
1298
1299 (defvar gnus-current-article nil)
1300 (defvar gnus-article-current nil)
1301 (defvar gnus-current-headers nil)
1302 (defvar gnus-have-all-headers nil)
1303 (defvar gnus-last-article nil)
1304 (defvar gnus-newsgroup-history nil)
1305 (defvar gnus-newsgroup-charset nil)
1306 (defvar gnus-newsgroup-ephemeral-charset nil)
1307 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1308
1309 (defvar gnus-article-before-search nil)
1310
1311 (defconst gnus-summary-local-variables
1312   '(gnus-newsgroup-name
1313     gnus-newsgroup-begin gnus-newsgroup-end
1314     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1315     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1316     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1317     gnus-newsgroup-unselected gnus-newsgroup-marked
1318     gnus-newsgroup-reads gnus-newsgroup-saved
1319     gnus-newsgroup-replied gnus-newsgroup-forwarded
1320     gnus-newsgroup-recent
1321     gnus-newsgroup-expirable
1322     gnus-newsgroup-processable gnus-newsgroup-killed
1323     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1324     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1325     gnus-newsgroup-seen gnus-newsgroup-articles
1326     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1327     gnus-newsgroup-headers gnus-newsgroup-threads
1328     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1329     gnus-current-article gnus-current-headers gnus-have-all-headers
1330     gnus-last-article gnus-article-internal-prepare-hook
1331     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1332     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1333     gnus-thread-expunge-below
1334     gnus-score-alist gnus-current-score-file
1335     (gnus-summary-expunge-below . global)
1336     (gnus-summary-mark-below . global)
1337     (gnus-orphan-score . global)
1338     gnus-newsgroup-active gnus-scores-exclude-files
1339     gnus-newsgroup-history gnus-newsgroup-ancient
1340     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1341     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1342     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1343     (gnus-newsgroup-expunged-tally . 0)
1344     gnus-cache-removable-articles gnus-newsgroup-cached
1345     gnus-newsgroup-data gnus-newsgroup-data-reverse
1346     gnus-newsgroup-limit gnus-newsgroup-limits
1347     gnus-newsgroup-charset gnus-newsgroup-display
1348     gnus-newsgroup-incorporated)
1349   "Variables that are buffer-local to the summary buffers.")
1350
1351 (defvar gnus-newsgroup-variables nil
1352   "A list of variables that have separate values in different newsgroups.
1353 A list of newsgroup (summary buffer) local variables, or cons of
1354 variables and their default values (when the default values are not
1355 nil), that should be made global while the summary buffer is active.
1356 These variables can be used to set variables in the group parameters
1357 while still allowing them to affect operations done in other
1358 buffers. For example:
1359
1360 \(setq gnus-newsgroup-variables
1361      '(message-use-followup-to
1362        (gnus-visible-headers .
1363          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1364 ")
1365
1366 ;; Byte-compiler warning.
1367 (eval-when-compile (defvar gnus-article-mode-map))
1368
1369 ;; Subject simplification.
1370
1371 (defun gnus-simplify-whitespace (str)
1372   "Remove excessive whitespace from STR."
1373   (let ((mystr str))
1374     ;; Multiple spaces.
1375     (while (string-match "[ \t][ \t]+" mystr)
1376       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1377                           " "
1378                           (substring mystr (match-end 0)))))
1379     ;; Leading spaces.
1380     (when (string-match "^[ \t]+" mystr)
1381       (setq mystr (substring mystr (match-end 0))))
1382     ;; Trailing spaces.
1383     (when (string-match "[ \t]+$" mystr)
1384       (setq mystr (substring mystr 0 (match-beginning 0))))
1385     mystr))
1386
1387 (defsubst gnus-simplify-subject-re (subject)
1388   "Remove \"Re:\" from subject lines."
1389   (if (string-match message-subject-re-regexp subject)
1390       (substring subject (match-end 0))
1391     subject))
1392
1393 (defun gnus-simplify-subject (subject &optional re-only)
1394   "Remove `Re:' and words in parentheses.
1395 If RE-ONLY is non-nil, strip leading `Re:'s only."
1396   (let ((case-fold-search t))           ;Ignore case.
1397     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1398     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1399       (setq subject (substring subject (match-end 0))))
1400     ;; Remove uninteresting prefixes.
1401     (when (and (not re-only)
1402                gnus-simplify-ignored-prefixes
1403                (string-match gnus-simplify-ignored-prefixes subject))
1404       (setq subject (substring subject (match-end 0))))
1405     ;; Remove words in parentheses from end.
1406     (unless re-only
1407       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1408         (setq subject (substring subject 0 (match-beginning 0)))))
1409     ;; Return subject string.
1410     subject))
1411
1412 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1413 ;; all whitespace.
1414 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1415   (goto-char (point-min))
1416   (while (re-search-forward regexp nil t)
1417     (replace-match (or newtext ""))))
1418
1419 (defun gnus-simplify-buffer-fuzzy ()
1420   "Simplify string in the buffer fuzzily.
1421 The string in the accessible portion of the current buffer is simplified.
1422 It is assumed to be a single-line subject.
1423 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1424 matter is removed.  Additional things can be deleted by setting
1425 `gnus-simplify-subject-fuzzy-regexp'."
1426   (let ((case-fold-search t)
1427         (modified-tick))
1428     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1429
1430     (while (not (eq modified-tick (buffer-modified-tick)))
1431       (setq modified-tick (buffer-modified-tick))
1432       (cond
1433        ((listp gnus-simplify-subject-fuzzy-regexp)
1434         (mapcar 'gnus-simplify-buffer-fuzzy-step
1435                 gnus-simplify-subject-fuzzy-regexp))
1436        (gnus-simplify-subject-fuzzy-regexp
1437         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1438       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1439       (gnus-simplify-buffer-fuzzy-step
1440        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1441       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1442
1443     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1444     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1445     (gnus-simplify-buffer-fuzzy-step " $")
1446     (gnus-simplify-buffer-fuzzy-step "^ +")))
1447
1448 (defun gnus-simplify-subject-fuzzy (subject)
1449   "Simplify a subject string fuzzily.
1450 See `gnus-simplify-buffer-fuzzy' for details."
1451   (save-excursion
1452     (gnus-set-work-buffer)
1453     (let ((case-fold-search t))
1454       ;; Remove uninteresting prefixes.
1455       (when (and gnus-simplify-ignored-prefixes
1456                  (string-match gnus-simplify-ignored-prefixes subject))
1457         (setq subject (substring subject (match-end 0))))
1458       (insert subject)
1459       (inline (gnus-simplify-buffer-fuzzy))
1460       (buffer-string))))
1461
1462 (defsubst gnus-simplify-subject-fully (subject)
1463   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1464   (cond
1465    (gnus-simplify-subject-functions
1466     (gnus-map-function gnus-simplify-subject-functions subject))
1467    ((null gnus-summary-gather-subject-limit)
1468     (gnus-simplify-subject-re subject))
1469    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1470     (gnus-simplify-subject-fuzzy subject))
1471    ((numberp gnus-summary-gather-subject-limit)
1472     (gnus-limit-string (gnus-simplify-subject-re subject)
1473                        gnus-summary-gather-subject-limit))
1474    (t
1475     subject)))
1476
1477 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1478   "Check whether two subjects are equal.
1479 If optional argument simple-first is t, first argument is already
1480 simplified."
1481   (cond
1482    ((null simple-first)
1483     (equal (gnus-simplify-subject-fully s1)
1484            (gnus-simplify-subject-fully s2)))
1485    (t
1486     (equal s1
1487            (gnus-simplify-subject-fully s2)))))
1488
1489 (defun gnus-summary-bubble-group ()
1490   "Increase the score of the current group.
1491 This is a handy function to add to `gnus-summary-exit-hook' to
1492 increase the score of each group you read."
1493   (gnus-group-add-score gnus-newsgroup-name))
1494
1495 \f
1496 ;;;
1497 ;;; Gnus summary mode
1498 ;;;
1499
1500 (put 'gnus-summary-mode 'mode-class 'special)
1501
1502 (defvar gnus-article-commands-menu)
1503
1504 (when t
1505   ;; Non-orthogonal keys
1506
1507   (gnus-define-keys gnus-summary-mode-map
1508     " " gnus-summary-next-page
1509     "\177" gnus-summary-prev-page
1510     [delete] gnus-summary-prev-page
1511     [backspace] gnus-summary-prev-page
1512     "\r" gnus-summary-scroll-up
1513     "\M-\r" gnus-summary-scroll-down
1514     "n" gnus-summary-next-unread-article
1515     "p" gnus-summary-prev-unread-article
1516     "N" gnus-summary-next-article
1517     "P" gnus-summary-prev-article
1518     "\M-\C-n" gnus-summary-next-same-subject
1519     "\M-\C-p" gnus-summary-prev-same-subject
1520     "\M-n" gnus-summary-next-unread-subject
1521     "\M-p" gnus-summary-prev-unread-subject
1522     "." gnus-summary-first-unread-article
1523     "," gnus-summary-best-unread-article
1524     "\M-s" gnus-summary-search-article-forward
1525     "\M-r" gnus-summary-search-article-backward
1526     "<" gnus-summary-beginning-of-article
1527     ">" gnus-summary-end-of-article
1528     "j" gnus-summary-goto-article
1529     "^" gnus-summary-refer-parent-article
1530     "\M-^" gnus-summary-refer-article
1531     "u" gnus-summary-tick-article-forward
1532     "!" gnus-summary-tick-article-forward
1533     "U" gnus-summary-tick-article-backward
1534     "d" gnus-summary-mark-as-read-forward
1535     "D" gnus-summary-mark-as-read-backward
1536     "E" gnus-summary-mark-as-expirable
1537     "\M-u" gnus-summary-clear-mark-forward
1538     "\M-U" gnus-summary-clear-mark-backward
1539     "k" gnus-summary-kill-same-subject-and-select
1540     "\C-k" gnus-summary-kill-same-subject
1541     "\M-\C-k" gnus-summary-kill-thread
1542     "\M-\C-l" gnus-summary-lower-thread
1543     "e" gnus-summary-edit-article
1544     "#" gnus-summary-mark-as-processable
1545     "\M-#" gnus-summary-unmark-as-processable
1546     "\M-\C-t" gnus-summary-toggle-threads
1547     "\M-\C-s" gnus-summary-show-thread
1548     "\M-\C-h" gnus-summary-hide-thread
1549     "\M-\C-f" gnus-summary-next-thread
1550     "\M-\C-b" gnus-summary-prev-thread
1551     [(meta down)] gnus-summary-next-thread
1552     [(meta up)] gnus-summary-prev-thread
1553     "\M-\C-u" gnus-summary-up-thread
1554     "\M-\C-d" gnus-summary-down-thread
1555     "&" gnus-summary-execute-command
1556     "c" gnus-summary-catchup-and-exit
1557     "\C-w" gnus-summary-mark-region-as-read
1558     "\C-t" gnus-summary-toggle-truncation
1559     "?" gnus-summary-mark-as-dormant
1560     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1561     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1562     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1563     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1564     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1565     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1566     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1567     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1568     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1569     "=" gnus-summary-expand-window
1570     "\C-x\C-s" gnus-summary-reselect-current-group
1571     "\M-g" gnus-summary-rescan-group
1572     "w" gnus-summary-stop-page-breaking
1573     "\C-c\C-r" gnus-summary-caesar-message
1574     "\M-t" gnus-summary-toggle-mime
1575     "f" gnus-summary-followup
1576     "F" gnus-summary-followup-with-original
1577     "C" gnus-summary-cancel-article
1578     "r" gnus-summary-reply
1579     "R" gnus-summary-reply-with-original
1580     "\C-c\C-f" gnus-summary-mail-forward
1581     "o" gnus-summary-save-article
1582     "\C-o" gnus-summary-save-article-mail
1583     "|" gnus-summary-pipe-output
1584     "\M-k" gnus-summary-edit-local-kill
1585     "\M-K" gnus-summary-edit-global-kill
1586     ;; "V" gnus-version
1587     "\C-c\C-d" gnus-summary-describe-group
1588     "q" gnus-summary-exit
1589     "Q" gnus-summary-exit-no-update
1590     "\C-c\C-i" gnus-info-find-node
1591     gnus-mouse-2 gnus-mouse-pick-article
1592     "m" gnus-summary-mail-other-window
1593     "a" gnus-summary-post-news
1594     "i" gnus-summary-news-other-window
1595     "x" gnus-summary-limit-to-unread
1596     "s" gnus-summary-isearch-article
1597     "t" gnus-article-toggle-headers
1598     "g" gnus-summary-show-article
1599     "l" gnus-summary-goto-last-article
1600     "v" gnus-summary-preview-mime-message
1601     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1602     "\C-d" gnus-summary-enter-digest-group
1603     "\M-\C-d" gnus-summary-read-document
1604     "\M-\C-e" gnus-summary-edit-parameters
1605     "\M-\C-a" gnus-summary-customize-parameters
1606     "\C-c\C-b" gnus-bug
1607     "\C-c\C-n" gnus-namazu-search
1608     "*" gnus-cache-enter-article
1609     "\M-*" gnus-cache-remove-article
1610     "\M-&" gnus-summary-universal-argument
1611     "\C-l" gnus-recenter
1612     "I" gnus-summary-increase-score
1613     "L" gnus-summary-lower-score
1614     "\M-i" gnus-symbolic-argument
1615     "h" gnus-summary-select-article-buffer
1616
1617     "V" gnus-summary-score-map
1618     "X" gnus-uu-extract-map
1619     "S" gnus-summary-send-map)
1620
1621   ;; Sort of orthogonal keymap
1622   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1623     "t" gnus-summary-tick-article-forward
1624     "!" gnus-summary-tick-article-forward
1625     "d" gnus-summary-mark-as-read-forward
1626     "r" gnus-summary-mark-as-read-forward
1627     "c" gnus-summary-clear-mark-forward
1628     " " gnus-summary-clear-mark-forward
1629     "e" gnus-summary-mark-as-expirable
1630     "x" gnus-summary-mark-as-expirable
1631     "?" gnus-summary-mark-as-dormant
1632     "b" gnus-summary-set-bookmark
1633     "B" gnus-summary-remove-bookmark
1634     "#" gnus-summary-mark-as-processable
1635     "\M-#" gnus-summary-unmark-as-processable
1636     "S" gnus-summary-limit-include-expunged
1637     "C" gnus-summary-catchup
1638     "H" gnus-summary-catchup-to-here
1639     "h" gnus-summary-catchup-from-here
1640     "\C-c" gnus-summary-catchup-all
1641     "k" gnus-summary-kill-same-subject-and-select
1642     "K" gnus-summary-kill-same-subject
1643     "P" gnus-uu-mark-map)
1644
1645   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1646     "c" gnus-summary-clear-above
1647     "u" gnus-summary-tick-above
1648     "m" gnus-summary-mark-above
1649     "k" gnus-summary-kill-below)
1650
1651   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1652     "/" gnus-summary-limit-to-subject
1653     "n" gnus-summary-limit-to-articles
1654     "w" gnus-summary-pop-limit
1655     "s" gnus-summary-limit-to-subject
1656     "a" gnus-summary-limit-to-author
1657     "u" gnus-summary-limit-to-unread
1658     "m" gnus-summary-limit-to-marks
1659     "M" gnus-summary-limit-exclude-marks
1660     "v" gnus-summary-limit-to-score
1661     "*" gnus-summary-limit-include-cached
1662     "D" gnus-summary-limit-include-dormant
1663     "T" gnus-summary-limit-include-thread
1664     "d" gnus-summary-limit-exclude-dormant
1665     "t" gnus-summary-limit-to-age
1666     "x" gnus-summary-limit-to-extra
1667     "p" gnus-summary-limit-to-display-predicate
1668     "E" gnus-summary-limit-include-expunged
1669     "c" gnus-summary-limit-exclude-childless-dormant
1670     "C" gnus-summary-limit-mark-excluded-as-read
1671     "o" gnus-summary-insert-old-articles
1672     "N" gnus-summary-insert-new-articles)
1673
1674   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1675     "n" gnus-summary-next-unread-article
1676     "p" gnus-summary-prev-unread-article
1677     "N" gnus-summary-next-article
1678     "P" gnus-summary-prev-article
1679     "\C-n" gnus-summary-next-same-subject
1680     "\C-p" gnus-summary-prev-same-subject
1681     "\M-n" gnus-summary-next-unread-subject
1682     "\M-p" gnus-summary-prev-unread-subject
1683     "f" gnus-summary-first-unread-article
1684     "b" gnus-summary-best-unread-article
1685     "j" gnus-summary-goto-article
1686     "g" gnus-summary-goto-subject
1687     "l" gnus-summary-goto-last-article
1688     "o" gnus-summary-pop-article)
1689
1690   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1691     "k" gnus-summary-kill-thread
1692     "l" gnus-summary-lower-thread
1693     "i" gnus-summary-raise-thread
1694     "T" gnus-summary-toggle-threads
1695     "t" gnus-summary-rethread-current
1696     "^" gnus-summary-reparent-thread
1697     "s" gnus-summary-show-thread
1698     "S" gnus-summary-show-all-threads
1699     "h" gnus-summary-hide-thread
1700     "H" gnus-summary-hide-all-threads
1701     "n" gnus-summary-next-thread
1702     "p" gnus-summary-prev-thread
1703     "u" gnus-summary-up-thread
1704     "o" gnus-summary-top-thread
1705     "d" gnus-summary-down-thread
1706     "#" gnus-uu-mark-thread
1707     "\M-#" gnus-uu-unmark-thread)
1708
1709   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1710     "g" gnus-summary-prepare
1711     "c" gnus-summary-insert-cached-articles)
1712
1713   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1714     "c" gnus-summary-catchup-and-exit
1715     "C" gnus-summary-catchup-all-and-exit
1716     "E" gnus-summary-exit-no-update
1717     "J" gnus-summary-jump-to-other-group
1718     "Q" gnus-summary-exit
1719     "Z" gnus-summary-exit
1720     "n" gnus-summary-catchup-and-goto-next-group
1721     "R" gnus-summary-reselect-current-group
1722     "G" gnus-summary-rescan-group
1723     "N" gnus-summary-next-group
1724     "s" gnus-summary-save-newsrc
1725     "P" gnus-summary-prev-group)
1726
1727   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1728     " " gnus-summary-next-page
1729     "n" gnus-summary-next-page
1730     "\177" gnus-summary-prev-page
1731     [delete] gnus-summary-prev-page
1732     "p" gnus-summary-prev-page
1733     "\r" gnus-summary-scroll-up
1734     "\M-\r" gnus-summary-scroll-down
1735     "<" gnus-summary-beginning-of-article
1736     ">" gnus-summary-end-of-article
1737     "b" gnus-summary-beginning-of-article
1738     "e" gnus-summary-end-of-article
1739     "^" gnus-summary-refer-parent-article
1740     "r" gnus-summary-refer-parent-article
1741     "D" gnus-summary-enter-digest-group
1742     "R" gnus-summary-refer-references
1743     "T" gnus-summary-refer-thread
1744     "g" gnus-summary-show-article
1745     "s" gnus-summary-isearch-article
1746     "P" gnus-summary-print-article
1747     "M" gnus-mailing-list-insinuate
1748     "t" gnus-article-babel)
1749
1750   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1751     "b" gnus-article-add-buttons
1752     "B" gnus-article-add-buttons-to-head
1753     "o" gnus-article-treat-overstrike
1754     "e" gnus-article-emphasize
1755     "w" gnus-article-fill-cited-article
1756     "Q" gnus-article-fill-long-lines
1757     "C" gnus-article-capitalize-sentences
1758     "c" gnus-article-remove-cr
1759     "Z" gnus-article-decode-HZ
1760     "h" gnus-article-wash-html
1761     "f" gnus-article-display-x-face
1762     "l" gnus-summary-stop-page-breaking
1763     "r" gnus-summary-caesar-message
1764     "t" gnus-article-toggle-headers
1765     "g" gnus-treat-smiley
1766     "v" gnus-summary-verbose-headers
1767     "m" gnus-summary-toggle-mime
1768     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1769     "p" gnus-article-verify-x-pgp-sig
1770     "d" gnus-article-treat-dumbquotes)
1771
1772   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1773     "a" gnus-article-hide
1774     "h" gnus-article-toggle-headers
1775     "b" gnus-article-hide-boring-headers
1776     "s" gnus-article-hide-signature
1777     "c" gnus-article-hide-citation
1778     "C" gnus-article-hide-citation-in-followups
1779     "l" gnus-article-hide-list-identifiers
1780     "p" gnus-article-hide-pgp
1781     "B" gnus-article-strip-banner
1782     "P" gnus-article-hide-pem
1783     "\C-c" gnus-article-hide-citation-maybe)
1784
1785   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1786     "a" gnus-article-highlight
1787     "h" gnus-article-highlight-headers
1788     "c" gnus-article-highlight-citation
1789     "s" gnus-article-highlight-signature)
1790
1791   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1792     "f" gnus-article-treat-fold-headers
1793     "u" gnus-article-treat-unfold-headers
1794     "n" gnus-article-treat-fold-newsgroups)
1795
1796   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1797     "x" gnus-article-display-x-face
1798     "s" gnus-treat-smiley
1799     "D" gnus-article-remove-images
1800     "f" gnus-treat-from-picon
1801     "m" gnus-treat-mail-picon
1802     "n" gnus-treat-newsgroups-picon)
1803
1804   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1805     "z" gnus-article-date-ut
1806     "u" gnus-article-date-ut
1807     "l" gnus-article-date-local
1808     "p" gnus-article-date-english
1809     "e" gnus-article-date-lapsed
1810     "o" gnus-article-date-original
1811     "i" gnus-article-date-iso8601
1812     "s" gnus-article-date-user)
1813
1814   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1815     "t" gnus-article-remove-trailing-blank-lines
1816     "l" gnus-article-strip-leading-blank-lines
1817     "m" gnus-article-strip-multiple-blank-lines
1818     "a" gnus-article-strip-blank-lines
1819     "A" gnus-article-strip-all-blank-lines
1820     "s" gnus-article-strip-leading-space
1821     "e" gnus-article-strip-trailing-space
1822     "w" gnus-article-remove-leading-whitespace)
1823
1824   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1825     "v" gnus-version
1826     "f" gnus-summary-fetch-faq
1827     "d" gnus-summary-describe-group
1828     "h" gnus-summary-describe-briefly
1829     "i" gnus-info-find-node)
1830
1831   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1832     "e" gnus-summary-expire-articles
1833     "\M-\C-e" gnus-summary-expire-articles-now
1834     "\177" gnus-summary-delete-article
1835     [delete] gnus-summary-delete-article
1836     [backspace] gnus-summary-delete-article
1837     "m" gnus-summary-move-article
1838     "r" gnus-summary-respool-article
1839     "w" gnus-summary-edit-article
1840     "c" gnus-summary-copy-article
1841     "B" gnus-summary-crosspost-article
1842     "q" gnus-summary-respool-query
1843     "t" gnus-summary-respool-trace
1844     "i" gnus-summary-import-article
1845     "I" gnus-summary-create-article
1846     "p" gnus-summary-article-posted-p)
1847
1848   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1849     "o" gnus-summary-save-article
1850     "m" gnus-summary-save-article-mail
1851     "F" gnus-summary-write-article-file
1852     "r" gnus-summary-save-article-rmail
1853     "f" gnus-summary-save-article-file
1854     "b" gnus-summary-save-article-body-file
1855     "h" gnus-summary-save-article-folder
1856     "v" gnus-summary-save-article-vm
1857     "p" gnus-summary-pipe-output
1858     "P" gnus-summary-muttprint
1859     "s" gnus-soup-add-article)
1860
1861   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1862     "b" gnus-summary-display-buttonized
1863     "m" gnus-summary-repair-multipart
1864     "v" gnus-article-view-part
1865     "o" gnus-article-save-part
1866     "c" gnus-article-copy-part
1867     "C" gnus-article-view-part-as-charset
1868     "e" gnus-article-externalize-part
1869     "E" gnus-article-encrypt-body
1870     "i" gnus-article-inline-part
1871     "|" gnus-article-pipe-part))
1872
1873 (defvar gnus-article-post-menu nil)
1874
1875 (defun gnus-summary-make-menu-bar ()
1876   (gnus-turn-off-edit-menu 'summary)
1877
1878   (unless (boundp 'gnus-summary-misc-menu)
1879
1880     (easy-menu-define
1881      gnus-summary-kill-menu gnus-summary-mode-map ""
1882      (cons
1883       "Score"
1884       (nconc
1885        (list
1886         ["Customize" gnus-score-customize t])
1887        (gnus-make-score-map 'increase)
1888        (gnus-make-score-map 'lower)
1889        '(("Mark"
1890           ["Kill below" gnus-summary-kill-below t]
1891           ["Mark above" gnus-summary-mark-above t]
1892           ["Tick above" gnus-summary-tick-above t]
1893           ["Clear above" gnus-summary-clear-above t])
1894          ["Current score" gnus-summary-current-score t]
1895          ["Set score" gnus-summary-set-score t]
1896          ["Switch current score file..." gnus-score-change-score-file t]
1897          ["Set mark below..." gnus-score-set-mark-below t]
1898          ["Set expunge below..." gnus-score-set-expunge-below t]
1899          ["Edit current score file" gnus-score-edit-current-scores t]
1900          ["Edit score file" gnus-score-edit-file t]
1901          ["Trace score" gnus-score-find-trace t]
1902          ["Find words" gnus-score-find-favourite-words t]
1903          ["Rescore buffer" gnus-summary-rescore t]
1904          ["Increase score..." gnus-summary-increase-score t]
1905          ["Lower score..." gnus-summary-lower-score t]))))
1906
1907     ;; Define both the Article menu in the summary buffer and the
1908     ;; equivalent Commands menu in the article buffer here for
1909     ;; consistency.
1910     (let ((innards
1911            `(("Hide"
1912               ["All" gnus-article-hide t]
1913               ["Headers" gnus-article-toggle-headers t]
1914               ["Signature" gnus-article-hide-signature t]
1915               ["Citation" gnus-article-hide-citation t]
1916               ["List identifiers" gnus-article-hide-list-identifiers t]
1917               ["PGP" gnus-article-hide-pgp t]
1918               ["Banner" gnus-article-strip-banner t]
1919               ["Boring headers" gnus-article-hide-boring-headers t])
1920              ("Highlight"
1921               ["All" gnus-article-highlight t]
1922               ["Headers" gnus-article-highlight-headers t]
1923               ["Signature" gnus-article-highlight-signature t]
1924               ["Citation" gnus-article-highlight-citation t])
1925              ("Date"
1926               ["Local" gnus-article-date-local t]
1927               ["ISO8601" gnus-article-date-iso8601 t]
1928               ["UT" gnus-article-date-ut t]
1929               ["Original" gnus-article-date-original t]
1930               ["Lapsed" gnus-article-date-lapsed t]
1931               ["User-defined" gnus-article-date-user t])
1932              ("Display"
1933               ["Remove images" gnus-article-remove-images t]
1934               ["Toggle smiley" gnus-treat-smiley t]
1935               ["Show X-Face" gnus-article-display-x-face t]
1936               ["Show picons in From" gnus-treat-from-picon t]
1937               ["Show picons in mail headers" gnus-treat-mail-picon t]
1938               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1939              ("Washing"
1940               ("Remove Blanks"
1941                ["Leading" gnus-article-strip-leading-blank-lines t]
1942                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1943                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1944                ["All of the above" gnus-article-strip-blank-lines t]
1945                ["All" gnus-article-strip-all-blank-lines t]
1946                ["Leading space" gnus-article-strip-leading-space t]
1947                ["Trailing space" gnus-article-strip-trailing-space t]
1948                ["Leading space in headers"
1949                 gnus-article-remove-leading-whitespace t])
1950               ["Overstrike" gnus-article-treat-overstrike t]
1951               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1952               ["Emphasis" gnus-article-emphasize t]
1953               ["Word wrap" gnus-article-fill-cited-article t]
1954               ["Fill long lines" gnus-article-fill-long-lines t]
1955               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1956               ["CR" gnus-article-remove-cr t]
1957               ["Rot 13" gnus-summary-caesar-message
1958                ,@(if (featurep 'xemacs) '(t)
1959                    '(:help "\"Caesar rotate\" article by 13"))]
1960               ["Unix pipe" gnus-summary-pipe-message t]
1961               ["Add buttons" gnus-article-add-buttons t]
1962               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1963               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1964               ["Toggle MIME" gnus-summary-toggle-mime t]
1965               ["Verbose header" gnus-summary-verbose-headers t]
1966               ["Toggle header" gnus-summary-toggle-header t]
1967               ["Unfold headers" gnus-article-treat-unfold-headers t]
1968               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1969               ["Html" gnus-article-wash-html t]
1970               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1971               ["HZ" gnus-article-decode-HZ t])
1972              ("Output"
1973               ["Save in default format" gnus-summary-save-article
1974                ,@(if (featurep 'xemacs) '(t)
1975                    '(:help "Save article using default method"))]
1976               ["Save in file" gnus-summary-save-article-file
1977                ,@(if (featurep 'xemacs) '(t)
1978                    '(:help "Save article in file"))]
1979               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1980               ["Save in MH folder" gnus-summary-save-article-folder t]
1981               ["Save in VM folder" gnus-summary-save-article-vm t]
1982               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1983               ["Save body in file" gnus-summary-save-article-body-file t]
1984               ["Pipe through a filter" gnus-summary-pipe-output t]
1985               ["Add to SOUP packet" gnus-soup-add-article t]
1986               ["Print with Muttprint" gnus-summary-muttprint t]
1987               ["Print" gnus-summary-print-article t])
1988              ("Backend"
1989               ["Respool article..." gnus-summary-respool-article t]
1990               ["Move article..." gnus-summary-move-article
1991                (gnus-check-backend-function
1992                 'request-move-article gnus-newsgroup-name)]
1993               ["Copy article..." gnus-summary-copy-article t]
1994               ["Crosspost article..." gnus-summary-crosspost-article
1995                (gnus-check-backend-function
1996                 'request-replace-article gnus-newsgroup-name)]
1997               ["Import file..." gnus-summary-import-article t]
1998               ["Create article..." gnus-summary-create-article t]
1999               ["Check if posted" gnus-summary-article-posted-p t]
2000               ["Edit article" gnus-summary-edit-article
2001                (not (gnus-group-read-only-p))]
2002               ["Delete article" gnus-summary-delete-article
2003                (gnus-check-backend-function
2004                 'request-expire-articles gnus-newsgroup-name)]
2005               ["Query respool" gnus-summary-respool-query t]
2006               ["Trace respool" gnus-summary-respool-trace t]
2007               ["Delete expirable articles" gnus-summary-expire-articles-now
2008                (gnus-check-backend-function
2009                 'request-expire-articles gnus-newsgroup-name)])
2010              ("Extract"
2011               ["Uudecode" gnus-uu-decode-uu
2012                ,@(if (featurep 'xemacs) '(t)
2013                    '(:help "Decode uuencoded article(s)"))]
2014               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2015               ["Unshar" gnus-uu-decode-unshar t]
2016               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2017               ["Save" gnus-uu-decode-save t]
2018               ["Binhex" gnus-uu-decode-binhex t]
2019               ["Postscript" gnus-uu-decode-postscript t])
2020              ("Cache"
2021               ["Enter article" gnus-cache-enter-article t]
2022               ["Remove article" gnus-cache-remove-article t])
2023              ["Translate" gnus-article-babel t]
2024              ["Select article buffer" gnus-summary-select-article-buffer t]
2025              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2026              ["Isearch article..." gnus-summary-isearch-article t]
2027              ["Beginning of the article" gnus-summary-beginning-of-article t]
2028              ["End of the article" gnus-summary-end-of-article t]
2029              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2030              ["Fetch referenced articles" gnus-summary-refer-references t]
2031              ["Fetch current thread" gnus-summary-refer-thread t]
2032              ["Fetch article with id..." gnus-summary-refer-article t]
2033              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2034              ["Redisplay" gnus-summary-show-article t]
2035              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2036       (easy-menu-define
2037        gnus-summary-article-menu gnus-summary-mode-map ""
2038        (cons "Article" innards))
2039
2040       (if (not (keymapp gnus-summary-article-menu))
2041           (easy-menu-define
2042            gnus-article-commands-menu gnus-article-mode-map ""
2043            (cons "Commands" innards))
2044         ;; in Emacs, don't share menu.
2045         (setq gnus-article-commands-menu
2046               (copy-keymap gnus-summary-article-menu))
2047         (define-key gnus-article-mode-map [menu-bar commands]
2048           (cons "Commands" gnus-article-commands-menu))))
2049
2050     (easy-menu-define
2051      gnus-summary-thread-menu gnus-summary-mode-map ""
2052      '("Threads"
2053        ["Toggle threading" gnus-summary-toggle-threads t]
2054        ["Hide threads" gnus-summary-hide-all-threads t]
2055        ["Show threads" gnus-summary-show-all-threads t]
2056        ["Hide thread" gnus-summary-hide-thread t]
2057        ["Show thread" gnus-summary-show-thread t]
2058        ["Go to next thread" gnus-summary-next-thread t]
2059        ["Go to previous thread" gnus-summary-prev-thread t]
2060        ["Go down thread" gnus-summary-down-thread t]
2061        ["Go up thread" gnus-summary-up-thread t]
2062        ["Top of thread" gnus-summary-top-thread t]
2063        ["Mark thread as read" gnus-summary-kill-thread t]
2064        ["Lower thread score" gnus-summary-lower-thread t]
2065        ["Raise thread score" gnus-summary-raise-thread t]
2066        ["Rethread current" gnus-summary-rethread-current t]))
2067
2068     (easy-menu-define
2069      gnus-summary-post-menu gnus-summary-mode-map ""
2070      `("Post"
2071        ["Send a message (mail or news)" gnus-summary-post-news
2072         ,@(if (featurep 'xemacs) '(t)
2073             '(:help "Post an article"))]
2074        ["Followup" gnus-summary-followup
2075         ,@(if (featurep 'xemacs) '(t)
2076             '(:help "Post followup to this article"))]
2077        ["Followup and yank" gnus-summary-followup-with-original
2078         ,@(if (featurep 'xemacs) '(t)
2079             '(:help "Post followup to this article, quoting its contents"))]
2080        ["Supersede article" gnus-summary-supersede-article t]
2081        ["Cancel article" gnus-summary-cancel-article
2082         ,@(if (featurep 'xemacs) '(t)
2083             '(:help "Cancel an article you posted"))]
2084        ["Reply" gnus-summary-reply t]
2085        ["Reply and yank" gnus-summary-reply-with-original t]
2086        ["Wide reply" gnus-summary-wide-reply t]
2087        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2088         ,@(if (featurep 'xemacs) '(t)
2089             '(:help "Mail a reply, quoting this article"))]
2090        ["Very wide reply" gnus-summary-very-wide-reply t]
2091        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2092         ,@(if (featurep 'xemacs) '(t)
2093             '(:help "Mail a very wide reply, quoting this article"))]
2094        ["Mail forward" gnus-summary-mail-forward t]
2095        ["Post forward" gnus-summary-post-forward t]
2096        ["Digest and mail" gnus-summary-digest-mail-forward t]
2097        ["Digest and post" gnus-summary-digest-post-forward t]
2098        ["Resend message" gnus-summary-resend-message t]
2099        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2100        ["Send a mail" gnus-summary-mail-other-window t]
2101        ["Create a local message" gnus-summary-news-other-window t]
2102        ["Uuencode and post" gnus-uu-post-news
2103         ,@(if (featurep 'xemacs) '(t)
2104             '(:help "Post a uuencoded article"))]
2105        ["Followup via news" gnus-summary-followup-to-mail t]
2106        ["Followup via news and yank"
2107         gnus-summary-followup-to-mail-with-original t]
2108        ;;("Draft"
2109        ;;["Send" gnus-summary-send-draft t]
2110        ;;["Send bounced" gnus-resend-bounced-mail t])
2111        ))
2112
2113     (cond
2114      ((not (keymapp gnus-summary-post-menu))
2115       (setq gnus-article-post-menu gnus-summary-post-menu))
2116      ((not gnus-article-post-menu)
2117       ;; Don't share post menu.
2118       (setq gnus-article-post-menu
2119             (copy-keymap gnus-summary-post-menu))))
2120     (define-key gnus-article-mode-map [menu-bar post]
2121       (cons "Post" gnus-article-post-menu))
2122
2123     (easy-menu-define
2124      gnus-summary-misc-menu gnus-summary-mode-map ""
2125      `("Gnus"
2126        ("Mark Read"
2127         ["Mark as read" gnus-summary-mark-as-read-forward t]
2128         ["Mark same subject and select"
2129          gnus-summary-kill-same-subject-and-select t]
2130         ["Mark same subject" gnus-summary-kill-same-subject t]
2131         ["Catchup" gnus-summary-catchup
2132          ,@(if (featurep 'xemacs) '(t)
2133              '(:help "Mark unread articles in this group as read"))]
2134         ["Catchup all" gnus-summary-catchup-all t]
2135         ["Catchup to here" gnus-summary-catchup-to-here t]
2136         ["Catchup from here" gnus-summary-catchup-from-here t]
2137         ["Catchup region" gnus-summary-mark-region-as-read t]
2138         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2139        ("Mark Various"
2140         ["Tick" gnus-summary-tick-article-forward t]
2141         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2142         ["Remove marks" gnus-summary-clear-mark-forward t]
2143         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2144         ["Set bookmark" gnus-summary-set-bookmark t]
2145         ["Remove bookmark" gnus-summary-remove-bookmark t])
2146        ("Limit to"
2147         ["Marks..." gnus-summary-limit-to-marks t]
2148         ["Subject..." gnus-summary-limit-to-subject t]
2149         ["Author..." gnus-summary-limit-to-author t]
2150         ["Age..." gnus-summary-limit-to-age t]
2151         ["Extra..." gnus-summary-limit-to-extra t]
2152         ["Score" gnus-summary-limit-to-score t]
2153         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2154         ["Unread" gnus-summary-limit-to-unread t]
2155         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2156         ["Articles" gnus-summary-limit-to-articles t]
2157         ["Pop limit" gnus-summary-pop-limit t]
2158         ["Show dormant" gnus-summary-limit-include-dormant t]
2159         ["Hide childless dormant"
2160          gnus-summary-limit-exclude-childless-dormant t]
2161         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2162         ["Hide marked" gnus-summary-limit-exclude-marks t]
2163         ["Show expunged" gnus-summary-limit-include-expunged t])
2164        ("Process Mark"
2165         ["Set mark" gnus-summary-mark-as-processable t]
2166         ["Remove mark" gnus-summary-unmark-as-processable t]
2167         ["Remove all marks" gnus-summary-unmark-all-processable t]
2168         ["Mark above" gnus-uu-mark-over t]
2169         ["Mark series" gnus-uu-mark-series t]
2170         ["Mark region" gnus-uu-mark-region t]
2171         ["Unmark region" gnus-uu-unmark-region t]
2172         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2173         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2174         ["Mark all" gnus-uu-mark-all t]
2175         ["Mark buffer" gnus-uu-mark-buffer t]
2176         ["Mark sparse" gnus-uu-mark-sparse t]
2177         ["Mark thread" gnus-uu-mark-thread t]
2178         ["Unmark thread" gnus-uu-unmark-thread t]
2179         ("Process Mark Sets"
2180          ["Kill" gnus-summary-kill-process-mark t]
2181          ["Yank" gnus-summary-yank-process-mark
2182           gnus-newsgroup-process-stack]
2183          ["Save" gnus-summary-save-process-mark t]))
2184        ("Scroll article"
2185         ["Page forward" gnus-summary-next-page
2186          ,@(if (featurep 'xemacs) '(t)
2187              '(:help "Show next page of article"))]
2188         ["Page backward" gnus-summary-prev-page
2189          ,@(if (featurep 'xemacs) '(t)
2190              '(:help "Show previous page of article"))]
2191         ["Line forward" gnus-summary-scroll-up t])
2192        ("Move"
2193         ["Next unread article" gnus-summary-next-unread-article t]
2194         ["Previous unread article" gnus-summary-prev-unread-article t]
2195         ["Next article" gnus-summary-next-article t]
2196         ["Previous article" gnus-summary-prev-article t]
2197         ["Next unread subject" gnus-summary-next-unread-subject t]
2198         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2199         ["Next article same subject" gnus-summary-next-same-subject t]
2200         ["Previous article same subject" gnus-summary-prev-same-subject t]
2201         ["First unread article" gnus-summary-first-unread-article t]
2202         ["Best unread article" gnus-summary-best-unread-article t]
2203         ["Go to subject number..." gnus-summary-goto-subject t]
2204         ["Go to article number..." gnus-summary-goto-article t]
2205         ["Go to the last article" gnus-summary-goto-last-article t]
2206         ["Pop article off history" gnus-summary-pop-article t])
2207        ("Sort"
2208         ["Sort by number" gnus-summary-sort-by-number t]
2209         ["Sort by author" gnus-summary-sort-by-author t]
2210         ["Sort by subject" gnus-summary-sort-by-subject t]
2211         ["Sort by date" gnus-summary-sort-by-date t]
2212         ["Sort by score" gnus-summary-sort-by-score t]
2213         ["Sort by lines" gnus-summary-sort-by-lines t]
2214         ["Sort by characters" gnus-summary-sort-by-chars t]
2215         ["Original sort" gnus-summary-sort-by-original t])
2216        ("Help"
2217         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2218         ["Describe group" gnus-summary-describe-group t]
2219         ["Read manual" gnus-info-find-node t])
2220        ("Modes"
2221         ["Pick and read" gnus-pick-mode t]
2222         ["Binary" gnus-binary-mode t])
2223        ("Regeneration"
2224         ["Regenerate" gnus-summary-prepare t]
2225         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2226         ["Toggle threading" gnus-summary-toggle-threads t])
2227        ["See old articles" gnus-summary-insert-old-articles t]
2228        ["See new articles" gnus-summary-insert-new-articles t]
2229        ["Filter articles..." gnus-summary-execute-command t]
2230        ["Run command on subjects..." gnus-summary-universal-argument t]
2231        ["Search articles forward..." gnus-summary-search-article-forward t]
2232        ["Search articles backward..." gnus-summary-search-article-backward t]
2233        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2234        ["Expand window" gnus-summary-expand-window t]
2235        ["Expire expirable articles" gnus-summary-expire-articles
2236         (gnus-check-backend-function
2237          'request-expire-articles gnus-newsgroup-name)]
2238        ["Edit local kill file" gnus-summary-edit-local-kill t]
2239        ["Edit main kill file" gnus-summary-edit-global-kill t]
2240        ["Edit group parameters" gnus-summary-edit-parameters t]
2241        ["Customize group parameters" gnus-summary-customize-parameters t]
2242        ["Send a bug report" gnus-bug t]
2243        ("Exit"
2244         ["Catchup and exit" gnus-summary-catchup-and-exit
2245          ,@(if (featurep 'xemacs) '(t)
2246              '(:help "Mark unread articles in this group as read, then exit"))]
2247         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2248         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2249         ["Exit group" gnus-summary-exit
2250          ,@(if (featurep 'xemacs) '(t)
2251              '(:help "Exit current group, return to group selection mode"))]
2252         ["Exit group without updating" gnus-summary-exit-no-update t]
2253         ["Exit and goto next group" gnus-summary-next-group t]
2254         ["Exit and goto prev group" gnus-summary-prev-group t]
2255         ["Reselect group" gnus-summary-reselect-current-group t]
2256         ["Rescan group" gnus-summary-rescan-group t]
2257         ["Update dribble" gnus-summary-save-newsrc t])))
2258
2259     (gnus-run-hooks 'gnus-summary-menu-hook)))
2260
2261 (defvar gnus-summary-tool-bar-map nil)
2262
2263 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2264 (defun gnus-summary-make-tool-bar ()
2265   (if (and (fboundp 'tool-bar-add-item-from-menu)
2266            (default-value 'tool-bar-mode)
2267            (not gnus-summary-tool-bar-map))
2268       (setq gnus-summary-tool-bar-map
2269             (let ((tool-bar-map (make-sparse-keymap))
2270                   (load-path (mm-image-load-path)))
2271               (tool-bar-add-item-from-menu
2272                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2273               (tool-bar-add-item-from-menu
2274                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2275               (tool-bar-add-item-from-menu
2276                'gnus-summary-post-news "post" gnus-summary-mode-map)
2277               (tool-bar-add-item-from-menu
2278                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2279               (tool-bar-add-item-from-menu
2280                'gnus-summary-followup "followup" gnus-summary-mode-map)
2281               (tool-bar-add-item-from-menu
2282                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2283               (tool-bar-add-item-from-menu
2284                'gnus-summary-reply "reply" gnus-summary-mode-map)
2285               (tool-bar-add-item-from-menu
2286                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2287               (tool-bar-add-item-from-menu
2288                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2289               (tool-bar-add-item-from-menu
2290                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2291               (tool-bar-add-item-from-menu
2292                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2293               (tool-bar-add-item-from-menu
2294                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2295               (tool-bar-add-item-from-menu
2296                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2297               (tool-bar-add-item-from-menu
2298                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2299               (tool-bar-add-item-from-menu
2300                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2301               tool-bar-map)))
2302   (if gnus-summary-tool-bar-map
2303       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2304
2305 (defun gnus-score-set-default (var value)
2306   "A version of set that updates the GNU Emacs menu-bar."
2307   (set var value)
2308   ;; It is the message that forces the active status to be updated.
2309   (message ""))
2310
2311 (defun gnus-make-score-map (type)
2312   "Make a summary score map of type TYPE."
2313   (if t
2314       nil
2315     (let ((headers '(("author" "from" string)
2316                      ("subject" "subject" string)
2317                      ("article body" "body" string)
2318                      ("article head" "head" string)
2319                      ("xref" "xref" string)
2320                      ("extra header" "extra" string)
2321                      ("lines" "lines" number)
2322                      ("followups to author" "followup" string)))
2323           (types '((number ("less than" <)
2324                            ("greater than" >)
2325                            ("equal" =))
2326                    (string ("substring" s)
2327                            ("exact string" e)
2328                            ("fuzzy string" f)
2329                            ("regexp" r))))
2330           (perms '(("temporary" (current-time-string))
2331                    ("permanent" nil)
2332                    ("immediate" now)))
2333           header)
2334       (list
2335        (apply
2336         'nconc
2337         (list
2338          (if (eq type 'lower)
2339              "Lower score"
2340            "Increase score"))
2341         (let (outh)
2342           (while headers
2343             (setq header (car headers))
2344             (setq outh
2345                   (cons
2346                    (apply
2347                     'nconc
2348                     (list (car header))
2349                     (let ((ts (cdr (assoc (nth 2 header) types)))
2350                           outt)
2351                       (while ts
2352                         (setq outt
2353                               (cons
2354                                (apply
2355                                 'nconc
2356                                 (list (caar ts))
2357                                 (let ((ps perms)
2358                                       outp)
2359                                   (while ps
2360                                     (setq outp
2361                                           (cons
2362                                            (vector
2363                                             (caar ps)
2364                                             (list
2365                                              'gnus-summary-score-entry
2366                                              (nth 1 header)
2367                                              (if (or (string= (nth 1 header)
2368                                                               "head")
2369                                                      (string= (nth 1 header)
2370                                                               "body"))
2371                                                  ""
2372                                                (list 'gnus-summary-header
2373                                                      (nth 1 header)))
2374                                              (list 'quote (nth 1 (car ts)))
2375                                              (list 'gnus-score-delta-default
2376                                                    nil)
2377                                              (nth 1 (car ps))
2378                                              t)
2379                                             t)
2380                                            outp))
2381                                     (setq ps (cdr ps)))
2382                                   (list (nreverse outp))))
2383                                outt))
2384                         (setq ts (cdr ts)))
2385                       (list (nreverse outt))))
2386                    outh))
2387             (setq headers (cdr headers)))
2388           (list (nreverse outh))))))))
2389
2390 \f
2391
2392 (defun gnus-summary-mode (&optional group)
2393   "Major mode for reading articles.
2394
2395 All normal editing commands are switched off.
2396 \\<gnus-summary-mode-map>
2397 Each line in this buffer represents one article.  To read an
2398 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2399 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2400 respectively.
2401
2402 You can also post articles and send mail from this buffer.  To
2403 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2404 of an article, type `\\[gnus-summary-reply]'.
2405
2406 There are approx. one gazillion commands you can execute in this
2407 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2408
2409 The following commands are available:
2410
2411 \\{gnus-summary-mode-map}"
2412   (interactive)
2413   (kill-all-local-variables)
2414   (when (gnus-visual-p 'summary-menu 'menu)
2415     (gnus-summary-make-menu-bar)
2416     (gnus-summary-make-tool-bar))
2417   (gnus-summary-make-local-variables)
2418   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2419     (gnus-summary-make-local-variables))
2420   (gnus-make-thread-indent-array)
2421   (gnus-simplify-mode-line)
2422   (setq major-mode 'gnus-summary-mode)
2423   (setq mode-name "Summary")
2424   (make-local-variable 'minor-mode-alist)
2425   (use-local-map gnus-summary-mode-map)
2426   (buffer-disable-undo)
2427   (setq buffer-read-only t)             ;Disable modification
2428   (setq truncate-lines t)
2429   (setq selective-display t)
2430   (setq selective-display-ellipses t)   ;Display `...'
2431   (gnus-summary-set-display-table)
2432   (gnus-set-default-directory)
2433   (setq gnus-newsgroup-name group)
2434   (unless (gnus-news-group-p group)
2435     (setq gnus-newsgroup-incorporated
2436           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2437   (make-local-variable 'gnus-summary-line-format)
2438   (make-local-variable 'gnus-summary-line-format-spec)
2439   (make-local-variable 'gnus-summary-dummy-line-format)
2440   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2441   (make-local-variable 'gnus-summary-mark-positions)
2442   (make-local-hook 'pre-command-hook)
2443   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2444   (gnus-run-hooks 'gnus-summary-mode-hook)
2445   (turn-on-gnus-mailing-list-mode)
2446   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2447   (gnus-update-summary-mark-positions))
2448
2449 (defun gnus-summary-make-local-variables ()
2450   "Make all the local summary buffer variables."
2451   (let (global)
2452     (dolist (local gnus-summary-local-variables)
2453       (if (consp local)
2454           (progn
2455             (if (eq (cdr local) 'global)
2456                 ;; Copy the global value of the variable.
2457                 (setq global (symbol-value (car local)))
2458               ;; Use the value from the list.
2459               (setq global (eval (cdr local))))
2460             (set (make-local-variable (car local)) global))
2461         ;; Simple nil-valued local variable.
2462         (set (make-local-variable local) nil)))))
2463
2464 (defun gnus-summary-clear-local-variables ()
2465   (let ((locals gnus-summary-local-variables))
2466     (while locals
2467       (if (consp (car locals))
2468           (and (vectorp (caar locals))
2469                (set (caar locals) nil))
2470         (and (vectorp (car locals))
2471              (set (car locals) nil)))
2472       (setq locals (cdr locals)))))
2473
2474 ;; Summary data functions.
2475
2476 (defmacro gnus-data-number (data)
2477   `(car ,data))
2478
2479 (defmacro gnus-data-set-number (data number)
2480   `(setcar ,data ,number))
2481
2482 (defmacro gnus-data-mark (data)
2483   `(nth 1 ,data))
2484
2485 (defmacro gnus-data-set-mark (data mark)
2486   `(setcar (nthcdr 1 ,data) ,mark))
2487
2488 (defmacro gnus-data-pos (data)
2489   `(nth 2 ,data))
2490
2491 (defmacro gnus-data-set-pos (data pos)
2492   `(setcar (nthcdr 2 ,data) ,pos))
2493
2494 (defmacro gnus-data-header (data)
2495   `(nth 3 ,data))
2496
2497 (defmacro gnus-data-set-header (data header)
2498   `(setcar (nthcdr 3 ,data) ,header))
2499
2500 (defmacro gnus-data-level (data)
2501   `(nth 4 ,data))
2502
2503 (defmacro gnus-data-unread-p (data)
2504   `(= (nth 1 ,data) gnus-unread-mark))
2505
2506 (defmacro gnus-data-read-p (data)
2507   `(/= (nth 1 ,data) gnus-unread-mark))
2508
2509 (defmacro gnus-data-pseudo-p (data)
2510   `(consp (nth 3 ,data)))
2511
2512 (defmacro gnus-data-find (number)
2513   `(assq ,number gnus-newsgroup-data))
2514
2515 (defmacro gnus-data-find-list (number &optional data)
2516   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2517      (memq (assq ,number bdata)
2518            bdata)))
2519
2520 (defmacro gnus-data-make (number mark pos header level)
2521   `(list ,number ,mark ,pos ,header ,level))
2522
2523 (defun gnus-data-enter (after-article number mark pos header level offset)
2524   (let ((data (gnus-data-find-list after-article)))
2525     (unless data
2526       (error "No such article: %d" after-article))
2527     (setcdr data (cons (gnus-data-make number mark pos header level)
2528                        (cdr data)))
2529     (setq gnus-newsgroup-data-reverse nil)
2530     (gnus-data-update-list (cddr data) offset)))
2531
2532 (defun gnus-data-enter-list (after-article list &optional offset)
2533   (when list
2534     (let ((data (and after-article (gnus-data-find-list after-article)))
2535           (ilist list))
2536       (if (not (or data
2537                    after-article))
2538           (let ((odata gnus-newsgroup-data))
2539             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2540             (when offset
2541               (gnus-data-update-list odata offset)))
2542         ;; Find the last element in the list to be spliced into the main
2543         ;; list.
2544         (while (cdr list)
2545           (setq list (cdr list)))
2546         (if (not data)
2547             (progn
2548               (setcdr list gnus-newsgroup-data)
2549               (setq gnus-newsgroup-data ilist)
2550               (when offset
2551                 (gnus-data-update-list (cdr list) offset)))
2552           (setcdr list (cdr data))
2553           (setcdr data ilist)
2554           (when offset
2555             (gnus-data-update-list (cdr list) offset))))
2556       (setq gnus-newsgroup-data-reverse nil))))
2557
2558 (defun gnus-data-remove (article &optional offset)
2559   (let ((data gnus-newsgroup-data))
2560     (if (= (gnus-data-number (car data)) article)
2561         (progn
2562           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2563                 gnus-newsgroup-data-reverse nil)
2564           (when offset
2565             (gnus-data-update-list gnus-newsgroup-data offset)))
2566       (while (cdr data)
2567         (when (= (gnus-data-number (cadr data)) article)
2568           (setcdr data (cddr data))
2569           (when offset
2570             (gnus-data-update-list (cdr data) offset))
2571           (setq data nil
2572                 gnus-newsgroup-data-reverse nil))
2573         (setq data (cdr data))))))
2574
2575 (defmacro gnus-data-list (backward)
2576   `(if ,backward
2577        (or gnus-newsgroup-data-reverse
2578            (setq gnus-newsgroup-data-reverse
2579                  (reverse gnus-newsgroup-data)))
2580      gnus-newsgroup-data))
2581
2582 (defun gnus-data-update-list (data offset)
2583   "Add OFFSET to the POS of all data entries in DATA."
2584   (setq gnus-newsgroup-data-reverse nil)
2585   (while data
2586     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2587     (setq data (cdr data))))
2588
2589 (defun gnus-summary-article-pseudo-p (article)
2590   "Say whether this article is a pseudo article or not."
2591   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2592
2593 (defmacro gnus-summary-article-sparse-p (article)
2594   "Say whether this article is a sparse article or not."
2595   `(memq ,article gnus-newsgroup-sparse))
2596
2597 (defmacro gnus-summary-article-ancient-p (article)
2598   "Say whether this article is a sparse article or not."
2599   `(memq ,article gnus-newsgroup-ancient))
2600
2601 (defun gnus-article-parent-p (number)
2602   "Say whether this article is a parent or not."
2603   (let ((data (gnus-data-find-list number)))
2604     (and (cdr data)                     ; There has to be an article after...
2605          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2606             (gnus-data-level (nth 1 data))))))
2607
2608 (defun gnus-article-children (number)
2609   "Return a list of all children to NUMBER."
2610   (let* ((data (gnus-data-find-list number))
2611          (level (gnus-data-level (car data)))
2612          children)
2613     (setq data (cdr data))
2614     (while (and data
2615                 (= (gnus-data-level (car data)) (1+ level)))
2616       (push (gnus-data-number (car data)) children)
2617       (setq data (cdr data)))
2618     children))
2619
2620 (defmacro gnus-summary-skip-intangible ()
2621   "If the current article is intangible, then jump to a different article."
2622   '(let ((to (get-text-property (point) 'gnus-intangible)))
2623      (and to (gnus-summary-goto-subject to))))
2624
2625 (defmacro gnus-summary-article-intangible-p ()
2626   "Say whether this article is intangible or not."
2627   '(get-text-property (point) 'gnus-intangible))
2628
2629 (defun gnus-article-read-p (article)
2630   "Say whether ARTICLE is read or not."
2631   (not (or (memq article gnus-newsgroup-marked)
2632            (memq article gnus-newsgroup-unreads)
2633            (memq article gnus-newsgroup-unselected)
2634            (memq article gnus-newsgroup-dormant))))
2635
2636 ;; Some summary mode macros.
2637
2638 (defmacro gnus-summary-article-number ()
2639   "The article number of the article on the current line.
2640 If there isn's an article number here, then we return the current
2641 article number."
2642   '(progn
2643      (gnus-summary-skip-intangible)
2644      (or (get-text-property (point) 'gnus-number)
2645          (gnus-summary-last-subject))))
2646
2647 (defmacro gnus-summary-article-header (&optional number)
2648   "Return the header of article NUMBER."
2649   `(gnus-data-header (gnus-data-find
2650                       ,(or number '(gnus-summary-article-number)))))
2651
2652 (defmacro gnus-summary-thread-level (&optional number)
2653   "Return the level of thread that starts with article NUMBER."
2654   `(if (and (eq gnus-summary-make-false-root 'dummy)
2655             (get-text-property (point) 'gnus-intangible))
2656        0
2657      (gnus-data-level (gnus-data-find
2658                        ,(or number '(gnus-summary-article-number))))))
2659
2660 (defmacro gnus-summary-article-mark (&optional number)
2661   "Return the mark of article NUMBER."
2662   `(gnus-data-mark (gnus-data-find
2663                     ,(or number '(gnus-summary-article-number)))))
2664
2665 (defmacro gnus-summary-article-pos (&optional number)
2666   "Return the position of the line of article NUMBER."
2667   `(gnus-data-pos (gnus-data-find
2668                    ,(or number '(gnus-summary-article-number)))))
2669
2670 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2671 (defmacro gnus-summary-article-subject (&optional number)
2672   "Return current subject string or nil if nothing."
2673   `(let ((headers
2674           ,(if number
2675                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2676              '(gnus-data-header (assq (gnus-summary-article-number)
2677                                       gnus-newsgroup-data)))))
2678      (and headers
2679           (vectorp headers)
2680           (mail-header-subject headers))))
2681
2682 (defmacro gnus-summary-article-score (&optional number)
2683   "Return current article score."
2684   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2685                   gnus-newsgroup-scored))
2686        gnus-summary-default-score 0))
2687
2688 (defun gnus-summary-article-children (&optional number)
2689   "Return a list of article numbers that are children of article NUMBER."
2690   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2691          (level (gnus-data-level (car data)))
2692          l children)
2693     (while (and (setq data (cdr data))
2694                 (> (setq l (gnus-data-level (car data))) level))
2695       (and (= (1+ level) l)
2696            (push (gnus-data-number (car data))
2697                  children)))
2698     (nreverse children)))
2699
2700 (defun gnus-summary-article-parent (&optional number)
2701   "Return the article number of the parent of article NUMBER."
2702   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2703                                     (gnus-data-list t)))
2704          (level (gnus-data-level (car data))))
2705     (if (zerop level)
2706         ()                              ; This is a root.
2707       ;; We search until we find an article with a level less than
2708       ;; this one.  That function has to be the parent.
2709       (while (and (setq data (cdr data))
2710                   (not (< (gnus-data-level (car data)) level))))
2711       (and data (gnus-data-number (car data))))))
2712
2713 (defun gnus-unread-mark-p (mark)
2714   "Say whether MARK is the unread mark."
2715   (= mark gnus-unread-mark))
2716
2717 (defun gnus-read-mark-p (mark)
2718   "Say whether MARK is one of the marks that mark as read.
2719 This is all marks except unread, ticked, dormant, and expirable."
2720   (not (or (= mark gnus-unread-mark)
2721            (= mark gnus-ticked-mark)
2722            (= mark gnus-dormant-mark)
2723            (= mark gnus-expirable-mark))))
2724
2725 (defmacro gnus-article-mark (number)
2726   "Return the MARK of article NUMBER.
2727 This macro should only be used when computing the mark the \"first\"
2728 time; i.e., when generating the summary lines.  After that,
2729 `gnus-summary-article-mark' should be used to examine the
2730 marks of articles."
2731   `(cond
2732     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2733     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2734     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2735     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2736     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2737     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2738     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2739     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2740            gnus-ancient-mark))))
2741
2742 ;; Saving hidden threads.
2743
2744 (defmacro gnus-save-hidden-threads (&rest forms)
2745   "Save hidden threads, eval FORMS, and restore the hidden threads."
2746   (let ((config (make-symbol "config")))
2747     `(let ((,config (gnus-hidden-threads-configuration)))
2748        (unwind-protect
2749            (save-excursion
2750              ,@forms)
2751          (gnus-restore-hidden-threads-configuration ,config)))))
2752 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2753 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2754
2755 (defun gnus-data-compute-positions ()
2756   "Compute the positions of all articles."
2757   (setq gnus-newsgroup-data-reverse nil)
2758   (let ((data gnus-newsgroup-data))
2759     (save-excursion
2760       (gnus-save-hidden-threads
2761         (gnus-summary-show-all-threads)
2762         (goto-char (point-min))
2763         (while data
2764           (while (get-text-property (point) 'gnus-intangible)
2765             (forward-line 1))
2766           (gnus-data-set-pos (car data) (+ (point) 3))
2767           (setq data (cdr data))
2768           (forward-line 1))))))
2769
2770 (defun gnus-hidden-threads-configuration ()
2771   "Return the current hidden threads configuration."
2772   (save-excursion
2773     (let (config)
2774       (goto-char (point-min))
2775       (while (search-forward "\r" nil t)
2776         (push (1- (point)) config))
2777       config)))
2778
2779 (defun gnus-restore-hidden-threads-configuration (config)
2780   "Restore hidden threads configuration from CONFIG."
2781   (save-excursion
2782     (let (point buffer-read-only)
2783       (while (setq point (pop config))
2784         (when (and (< point (point-max))
2785                    (goto-char point)
2786                    (eq (char-after) ?\n))
2787           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2788
2789 ;; Various summary mode internalish functions.
2790
2791 (defun gnus-mouse-pick-article (e)
2792   (interactive "e")
2793   (mouse-set-point e)
2794   (gnus-summary-next-page nil t))
2795
2796 (defun gnus-summary-set-display-table ()
2797   "Change the display table.
2798 Odd characters have a tendency to mess
2799 up nicely formatted displays - we make all possible glyphs
2800 display only a single character."
2801
2802   ;; We start from the standard display table, if any.
2803   (let ((table (or (copy-sequence standard-display-table)
2804                    (make-display-table)))
2805         (i 32))
2806     ;; Nix out all the control chars...
2807     (while (>= (setq i (1- i)) 0)
2808       (aset table i [??]))
2809     ;; ... but not newline and cr, of course.  (cr is necessary for the
2810     ;; selective display).
2811     (aset table ?\n nil)
2812     (aset table ?\r nil)
2813     ;; We keep TAB as well.
2814     (aset table ?\t nil)
2815     ;; We nix out any glyphs over 126 that are not set already.
2816     (let ((i 256))
2817       (while (>= (setq i (1- i)) 127)
2818         ;; Only modify if the entry is nil.
2819         (unless (aref table i)
2820           (aset table i [??]))))
2821     (setq buffer-display-table table)))
2822
2823 (defun gnus-summary-set-article-display-arrow (pos)
2824   "Update the overlay arrow to point to line at position POS."
2825   (when (and gnus-summary-display-arrow
2826              (boundp 'overlay-arrow-position)
2827              (boundp 'overlay-arrow-string))
2828     (save-excursion
2829       (goto-char pos)
2830       (beginning-of-line)
2831       (unless overlay-arrow-position
2832         (setq overlay-arrow-position (make-marker)))
2833       (setq overlay-arrow-string "=>"
2834             overlay-arrow-position (set-marker overlay-arrow-position
2835                                                (point)
2836                                                (current-buffer))))))
2837
2838 (defun gnus-summary-buffer-name (group)
2839   "Return the summary buffer name of GROUP."
2840   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2841
2842 (defun gnus-summary-setup-buffer (group)
2843   "Initialize summary buffer."
2844   (let ((buffer (gnus-summary-buffer-name group))
2845         (dead-name (concat "*Dead Summary "
2846                            (gnus-group-decoded-name group) "*")))
2847     ;; If a dead summary buffer exists, we kill it.
2848     (when (gnus-buffer-live-p dead-name)
2849       (gnus-kill-buffer dead-name))
2850     (if (get-buffer buffer)
2851         (progn
2852           (set-buffer buffer)
2853           (setq gnus-summary-buffer (current-buffer))
2854           (not gnus-newsgroup-prepared))
2855       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2856       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2857       (gnus-summary-mode group)
2858       (when gnus-carpal
2859         (gnus-carpal-setup-buffer 'summary))
2860       (unless gnus-single-article-buffer
2861         (make-local-variable 'gnus-article-buffer)
2862         (make-local-variable 'gnus-article-current)
2863         (make-local-variable 'gnus-original-article-buffer))
2864       (setq gnus-newsgroup-name group)
2865       ;; Set any local variables in the group parameters.
2866       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2867       t)))
2868
2869 (defun gnus-set-global-variables ()
2870   "Set the global equivalents of the buffer-local variables.
2871 They are set to the latest values they had.  These reflect the summary
2872 buffer that was in action when the last article was fetched."
2873   (when (eq major-mode 'gnus-summary-mode)
2874     (setq gnus-summary-buffer (current-buffer))
2875     (let ((name gnus-newsgroup-name)
2876           (marked gnus-newsgroup-marked)
2877           (unread gnus-newsgroup-unreads)
2878           (headers gnus-current-headers)
2879           (data gnus-newsgroup-data)
2880           (summary gnus-summary-buffer)
2881           (article-buffer gnus-article-buffer)
2882           (original gnus-original-article-buffer)
2883           (gac gnus-article-current)
2884           (reffed gnus-reffed-article-number)
2885           (score-file gnus-current-score-file)
2886           (default-charset gnus-newsgroup-charset)
2887           vlist)
2888       (let ((locals gnus-newsgroup-variables))
2889         (while locals
2890           (if (consp (car locals))
2891               (push (eval (caar locals)) vlist)
2892             (push (eval (car locals)) vlist))
2893           (setq locals (cdr locals)))
2894         (setq vlist (nreverse vlist)))
2895       (save-excursion
2896         (set-buffer gnus-group-buffer)
2897         (setq gnus-newsgroup-name name
2898               gnus-newsgroup-marked marked
2899               gnus-newsgroup-unreads unread
2900               gnus-current-headers headers
2901               gnus-newsgroup-data data
2902               gnus-article-current gac
2903               gnus-summary-buffer summary
2904               gnus-article-buffer article-buffer
2905               gnus-original-article-buffer original
2906               gnus-reffed-article-number reffed
2907               gnus-current-score-file score-file
2908               gnus-newsgroup-charset default-charset)
2909         (let ((locals gnus-newsgroup-variables))
2910           (while locals
2911             (if (consp (car locals))
2912                 (set (caar locals) (pop vlist))
2913               (set (car locals) (pop vlist)))
2914             (setq locals (cdr locals))))
2915         ;; The article buffer also has local variables.
2916         (when (gnus-buffer-live-p gnus-article-buffer)
2917           (set-buffer gnus-article-buffer)
2918           (setq gnus-summary-buffer summary))))))
2919
2920 (defun gnus-summary-article-unread-p (article)
2921   "Say whether ARTICLE is unread or not."
2922   (memq article gnus-newsgroup-unreads))
2923
2924 (defun gnus-summary-first-article-p (&optional article)
2925   "Return whether ARTICLE is the first article in the buffer."
2926   (if (not (setq article (or article (gnus-summary-article-number))))
2927       nil
2928     (eq article (caar gnus-newsgroup-data))))
2929
2930 (defun gnus-summary-last-article-p (&optional article)
2931   "Return whether ARTICLE is the last article in the buffer."
2932   (if (not (setq article (or article (gnus-summary-article-number))))
2933       ;; All non-existent numbers are the last article.  :-)
2934       t
2935     (not (cdr (gnus-data-find-list article)))))
2936
2937 (defun gnus-make-thread-indent-array ()
2938   (let ((n 200))
2939     (unless (and gnus-thread-indent-array
2940                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2941       (setq gnus-thread-indent-array (make-vector 201 "")
2942             gnus-thread-indent-array-level gnus-thread-indent-level)
2943       (while (>= n 0)
2944         (aset gnus-thread-indent-array n
2945               (make-string (* n gnus-thread-indent-level) ? ))
2946         (setq n (1- n))))))
2947
2948 (defun gnus-update-summary-mark-positions ()
2949   "Compute where the summary marks are to go."
2950   (save-excursion
2951     (when (gnus-buffer-exists-p gnus-summary-buffer)
2952       (set-buffer gnus-summary-buffer))
2953     (let ((gnus-replied-mark 129)
2954           (gnus-score-below-mark 130)
2955           (gnus-score-over-mark 130)
2956           (gnus-download-mark 131)
2957           (spec gnus-summary-line-format-spec)
2958           gnus-visual pos)
2959       (save-excursion
2960         (gnus-set-work-buffer)
2961         (let ((gnus-summary-line-format-spec spec)
2962               (gnus-newsgroup-downloadable '((0 . t))))
2963           (gnus-summary-insert-line
2964            (make-full-mail-header 0 "" "nobody"
2965                                   "05 Apr 2001 23:33:09 +0400"
2966                                   "" "" 0 0 "" nil)
2967            0 nil 128 t nil "" nil 1)
2968           (goto-char (point-min))
2969           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2970                                              (- (point) 2)))))
2971           (goto-char (point-min))
2972           (push (cons 'replied (and (search-forward "\201" nil t)
2973                                     (- (point) 2)))
2974                 pos)
2975           (goto-char (point-min))
2976           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2977                 pos)
2978           (goto-char (point-min))
2979           (push (cons 'download
2980                       (and (search-forward "\203" nil t) (- (point) 2)))
2981                 pos)))
2982       (setq gnus-summary-mark-positions pos))))
2983
2984 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2985   "Insert a dummy root in the summary buffer."
2986   (beginning-of-line)
2987   (gnus-add-text-properties
2988    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2989    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2990
2991 (defun gnus-summary-extract-address-component (from)
2992   (or (car (funcall gnus-extract-address-components from))
2993       from))
2994
2995 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2996   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
2997                                 default-mime-charset)))
2998     ;; Is it really necessary to do this next part for each summary line?
2999     ;; Luckily, doesn't seem to slow things down much.
3000     (or
3001      (and gnus-ignored-from-addresses
3002           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3003           (let ((extra-headers (mail-header-extra header))
3004                 to
3005                 newsgroups)
3006             (cond
3007              ((setq to (cdr (assq 'To extra-headers)))
3008               (concat "-> "
3009                       (inline
3010                         (gnus-summary-extract-address-component
3011                          (funcall gnus-decode-encoded-word-function to)))))
3012              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3013               (concat "=> " newsgroups)))))
3014      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3015
3016 (defun gnus-summary-insert-line (gnus-tmp-header
3017                                  gnus-tmp-level gnus-tmp-current
3018                                  gnus-tmp-unread gnus-tmp-replied
3019                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3020                                  &optional gnus-tmp-dummy gnus-tmp-score
3021                                  gnus-tmp-process)
3022   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3023          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3024          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3025          (gnus-tmp-score-char
3026           (if (or (null gnus-summary-default-score)
3027                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3028                       gnus-summary-zcore-fuzz))
3029               ?\ ;;;Whitespace
3030             (if (< gnus-tmp-score gnus-summary-default-score)
3031                 gnus-score-below-mark gnus-score-over-mark)))
3032          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3033          (gnus-tmp-replied
3034           (cond (gnus-tmp-process gnus-process-mark)
3035                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3036                  gnus-cached-mark)
3037                 (gnus-tmp-replied gnus-replied-mark)
3038                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3039                  gnus-forwarded-mark)
3040                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3041                  gnus-saved-mark)
3042                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3043                  gnus-recent-mark)
3044                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3045                  gnus-unseen-mark)
3046                 (t gnus-no-mark)))
3047          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3048          (gnus-tmp-name
3049           (cond
3050            ((string-match "<[^>]+> *$" gnus-tmp-from)
3051             (let ((beg (match-beginning 0)))
3052               (or (and (string-match "^\".+\"" gnus-tmp-from)
3053                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3054                   (substring gnus-tmp-from 0 beg))))
3055            ((string-match "(.+)" gnus-tmp-from)
3056             (substring gnus-tmp-from
3057                        (1+ (match-beginning 0)) (1- (match-end 0))))
3058            (t gnus-tmp-from)))
3059          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3060          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3061          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3062          (buffer-read-only nil))
3063     (when (string= gnus-tmp-name "")
3064       (setq gnus-tmp-name gnus-tmp-from))
3065     (unless (numberp gnus-tmp-lines)
3066       (setq gnus-tmp-lines -1))
3067     (if (= gnus-tmp-lines -1)
3068         (setq gnus-tmp-lines "?")
3069       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3070     (gnus-put-text-property-excluding-characters-with-faces
3071      (point)
3072      (progn (eval gnus-summary-line-format-spec) (point))
3073      'gnus-number gnus-tmp-number)
3074     (when (gnus-visual-p 'summary-highlight 'highlight)
3075       (forward-line -1)
3076       (gnus-run-hooks 'gnus-summary-update-hook)
3077       (forward-line 1))))
3078
3079 (defun gnus-summary-update-line (&optional dont-update)
3080   "Update summary line after change."
3081   (when (and gnus-summary-default-score
3082              (not gnus-summary-inhibit-highlight))
3083     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3084            (article (gnus-summary-article-number))
3085            (score (gnus-summary-article-score article)))
3086       (unless dont-update
3087         (if (and gnus-summary-mark-below
3088                  (< (gnus-summary-article-score)
3089                     gnus-summary-mark-below))
3090             ;; This article has a low score, so we mark it as read.
3091             (when (memq article gnus-newsgroup-unreads)
3092               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3093           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3094             ;; This article was previously marked as read on account
3095             ;; of a low score, but now it has risen, so we mark it as
3096             ;; unread.
3097             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3098         (gnus-summary-update-mark
3099          (if (or (null gnus-summary-default-score)
3100                  (<= (abs (- score gnus-summary-default-score))
3101                      gnus-summary-zcore-fuzz))
3102              ?\ ;;;Whitespace
3103            (if (< score gnus-summary-default-score)
3104                gnus-score-below-mark gnus-score-over-mark))
3105          'score))
3106       ;; Do visual highlighting.
3107       (when (gnus-visual-p 'summary-highlight 'highlight)
3108         (gnus-run-hooks 'gnus-summary-update-hook)))))
3109
3110 (defvar gnus-tmp-new-adopts nil)
3111
3112 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3113   "Return the number of articles in THREAD.
3114 This may be 0 in some cases -- if none of the articles in
3115 the thread are to be displayed."
3116   (let* ((number
3117           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3118           (cond
3119            ((not (listp thread))
3120             1)
3121            ((and (consp thread) (cdr thread))
3122             (apply
3123              '+ 1 (mapcar
3124                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3125            ((null thread)
3126             1)
3127            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3128             1)
3129            (t 0))))
3130     (when (and level (zerop level) gnus-tmp-new-adopts)
3131       (incf number
3132             (apply '+ (mapcar
3133                        'gnus-summary-number-of-articles-in-thread
3134                        gnus-tmp-new-adopts))))
3135     (if char
3136         (if (> number 1) gnus-not-empty-thread-mark
3137           gnus-empty-thread-mark)
3138       number)))
3139
3140 (defun gnus-summary-set-local-parameters (group)
3141   "Go through the local params of GROUP and set all variable specs in that list."
3142   (let ((params (gnus-group-find-parameter group))
3143         (vars '(quit-config))           ; Ignore quit-config.
3144         elem)
3145     (while params
3146       (setq elem (car params)
3147             params (cdr params))
3148       (and (consp elem)                 ; Has to be a cons.
3149            (consp (cdr elem))           ; The cdr has to be a list.
3150            (symbolp (car elem))         ; Has to be a symbol in there.
3151            (not (memq (car elem) vars))
3152            (ignore-errors               ; So we set it.
3153              (push (car elem) vars)
3154              (make-local-variable (car elem))
3155              (set (car elem) (eval (nth 1 elem))))))))
3156
3157 (defun gnus-summary-read-group (group &optional show-all no-article
3158                                       kill-buffer no-display backward
3159                                       select-articles)
3160   "Start reading news in newsgroup GROUP.
3161 If SHOW-ALL is non-nil, already read articles are also listed.
3162 If NO-ARTICLE is non-nil, no article is selected initially.
3163 If NO-DISPLAY, don't generate a summary buffer."
3164   (let (result)
3165     (while (and group
3166                 (null (setq result
3167                             (let ((gnus-auto-select-next nil))
3168                               (or (gnus-summary-read-group-1
3169                                    group show-all no-article
3170                                    kill-buffer no-display
3171                                    select-articles)
3172                                   (setq show-all nil
3173                                         select-articles nil)))))
3174                 (eq gnus-auto-select-next 'quietly))
3175       (set-buffer gnus-group-buffer)
3176       ;; The entry function called above goes to the next
3177       ;; group automatically, so we go two groups back
3178       ;; if we are searching for the previous group.
3179       (when backward
3180         (gnus-group-prev-unread-group 2))
3181       (if (not (equal group (gnus-group-group-name)))
3182           (setq group (gnus-group-group-name))
3183         (setq group nil)))
3184     result))
3185
3186 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3187   "Directly jump to the other GROUP from summary buffer.
3188 If SHOW-ALL is non-nil, already read articles are also listed."
3189   (interactive
3190    (if (eq gnus-summary-buffer (current-buffer))
3191        (list (completing-read
3192               "Group: " gnus-active-hashtb nil t
3193               (when (and gnus-newsgroup-name
3194                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3195                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3196               'gnus-group-history)
3197              current-prefix-arg)
3198      (error "%s must be invoked from a gnus summary buffer." this-command)))
3199   (unless (or (zerop (length group))
3200               (and gnus-newsgroup-name
3201                    (string-equal gnus-newsgroup-name group)))
3202     (gnus-summary-exit)
3203     (gnus-summary-read-group group show-all
3204                              gnus-dont-select-after-jump-to-other-group)))
3205
3206 (defun gnus-summary-read-group-1 (group show-all no-article
3207                                         kill-buffer no-display
3208                                         &optional select-articles)
3209   ;; Killed foreign groups can't be entered.
3210   ;;  (when (and (not (gnus-group-native-p group))
3211   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3212   ;;    (error "Dead non-native groups can't be entered"))
3213   (gnus-message 5 "Retrieving newsgroup: %s..."
3214                 (gnus-group-decoded-name group))
3215   (let* ((new-group (gnus-summary-setup-buffer group))
3216          (quit-config (gnus-group-quit-config group))
3217          (did-select (and new-group (gnus-select-newsgroup
3218                                      group show-all select-articles))))
3219     (cond
3220      ;; This summary buffer exists already, so we just select it.
3221      ((not new-group)
3222       (gnus-set-global-variables)
3223       (when kill-buffer
3224         (gnus-kill-or-deaden-summary kill-buffer))
3225       (gnus-configure-windows 'summary 'force)
3226       (gnus-set-mode-line 'summary)
3227       (gnus-summary-position-point)
3228       (message "")
3229       t)
3230      ;; We couldn't select this group.
3231      ((null did-select)
3232       (when (and (eq major-mode 'gnus-summary-mode)
3233                  (not (equal (current-buffer) kill-buffer)))
3234         (kill-buffer (current-buffer))
3235         (if (not quit-config)
3236             (progn
3237               ;; Update the info -- marks might need to be removed,
3238               ;; for instance.
3239               (gnus-summary-update-info)
3240               (set-buffer gnus-group-buffer)
3241               (gnus-group-jump-to-group group)
3242               (gnus-group-next-unread-group 1))
3243           (gnus-handle-ephemeral-exit quit-config)))
3244       (let ((grpinfo (gnus-get-info group)))
3245         (if (null (gnus-info-read grpinfo))
3246             (gnus-message 3 "Group %s contains no messages"
3247                           (gnus-group-decoded-name group))
3248           (gnus-message 3 "Can't select group")))
3249       nil)
3250      ;; The user did a `C-g' while prompting for number of articles,
3251      ;; so we exit this group.
3252      ((eq did-select 'quit)
3253       (and (eq major-mode 'gnus-summary-mode)
3254            (not (equal (current-buffer) kill-buffer))
3255            (kill-buffer (current-buffer)))
3256       (when kill-buffer
3257         (gnus-kill-or-deaden-summary kill-buffer))
3258       (if (not quit-config)
3259           (progn
3260             (set-buffer gnus-group-buffer)
3261             (gnus-group-jump-to-group group)
3262             (gnus-group-next-unread-group 1)
3263             (gnus-configure-windows 'group 'force))
3264         (gnus-handle-ephemeral-exit quit-config))
3265       ;; Finally signal the quit.
3266       (signal 'quit nil))
3267      ;; The group was successfully selected.
3268      (t
3269       (gnus-set-global-variables)
3270       ;; Save the active value in effect when the group was entered.
3271       (setq gnus-newsgroup-active
3272             (gnus-copy-sequence
3273              (gnus-active gnus-newsgroup-name)))
3274       ;; You can change the summary buffer in some way with this hook.
3275       (gnus-run-hooks 'gnus-select-group-hook)
3276       (gnus-update-format-specifications
3277        nil 'summary 'summary-mode 'summary-dummy)
3278       (gnus-update-summary-mark-positions)
3279       ;; Do score processing.
3280       (when gnus-use-scoring
3281         (gnus-possibly-score-headers))
3282       ;; Check whether to fill in the gaps in the threads.
3283       (when gnus-build-sparse-threads
3284         (gnus-build-sparse-threads))
3285       ;; Find the initial limit.
3286       (if gnus-show-threads
3287           (if show-all
3288               (let ((gnus-newsgroup-dormant nil))
3289                 (gnus-summary-initial-limit show-all))
3290             (gnus-summary-initial-limit show-all))
3291         ;; When untreaded, all articles are always shown.
3292         (setq gnus-newsgroup-limit
3293               (mapcar
3294                (lambda (header) (mail-header-number header))
3295                gnus-newsgroup-headers)))
3296       ;; Generate the summary buffer.
3297       (unless no-display
3298         (gnus-summary-prepare))
3299       (when gnus-use-trees
3300         (gnus-tree-open group)
3301         (setq gnus-summary-highlight-line-function
3302               'gnus-tree-highlight-article))
3303       ;; If the summary buffer is empty, but there are some low-scored
3304       ;; articles or some excluded dormants, we include these in the
3305       ;; buffer.
3306       (when (and (zerop (buffer-size))
3307                  (not no-display))
3308         (cond (gnus-newsgroup-dormant
3309                (gnus-summary-limit-include-dormant))
3310               ((and gnus-newsgroup-scored show-all)
3311                (gnus-summary-limit-include-expunged t))))
3312       ;; Function `gnus-apply-kill-file' must be called in this hook.
3313       (gnus-run-hooks 'gnus-apply-kill-hook)
3314       (if (and (zerop (buffer-size))
3315                (not no-display))
3316           (progn
3317             ;; This newsgroup is empty.
3318             (gnus-summary-catchup-and-exit nil t)
3319             (gnus-message 6 "No unread news")
3320             (when kill-buffer
3321               (gnus-kill-or-deaden-summary kill-buffer))
3322             ;; Return nil from this function.
3323             nil)
3324         ;; Hide conversation thread subtrees.  We cannot do this in
3325         ;; gnus-summary-prepare-hook since kill processing may not
3326         ;; work with hidden articles.
3327         (gnus-summary-maybe-hide-threads)
3328         (when kill-buffer
3329           (gnus-kill-or-deaden-summary kill-buffer))
3330         (gnus-summary-auto-select-subject)
3331         ;; Show first unread article if requested.
3332         (if (and (not no-article)
3333                  (not no-display)
3334                  gnus-newsgroup-unreads
3335                  gnus-auto-select-first)
3336             (progn
3337               (gnus-configure-windows 'summary)
3338               (let ((art (gnus-summary-article-number)))
3339                 (unless (or (memq art gnus-newsgroup-undownloaded)
3340                             (memq art gnus-newsgroup-downloadable))
3341                   (gnus-summary-goto-article art))))
3342           ;; Don't select any articles.
3343           (gnus-summary-position-point)
3344           (gnus-configure-windows 'summary 'force)
3345           (gnus-set-mode-line 'summary))
3346         (when (get-buffer-window gnus-group-buffer t)
3347           ;; Gotta use windows, because recenter does weird stuff if
3348           ;; the current buffer ain't the displayed window.
3349           (let ((owin (selected-window)))
3350             (select-window (get-buffer-window gnus-group-buffer t))
3351             (when (gnus-group-goto-group group)
3352               (recenter))
3353             (select-window owin)))
3354         ;; Mark this buffer as "prepared".
3355         (setq gnus-newsgroup-prepared t)
3356         (gnus-run-hooks 'gnus-summary-prepared-hook)
3357         t)))))
3358
3359 (defun gnus-summary-auto-select-subject ()
3360   "Select the subject line on initial group entry."
3361   (goto-char (point-min))
3362   (cond
3363    ((eq gnus-auto-select-subject 'best)
3364     (gnus-summary-best-unread-subject))
3365    ((eq gnus-auto-select-subject 'unread)
3366     (gnus-summary-first-unread-subject))
3367    ((eq gnus-auto-select-subject 'unseen)
3368     (gnus-summary-first-unseen-subject))
3369    ((eq gnus-auto-select-subject 'unseen-or-unread)
3370     (gnus-summary-first-unseen-or-unread-subject))
3371    ((eq gnus-auto-select-subject 'first)
3372     ;; Do nothing.
3373     )
3374    ((gnus-functionp gnus-auto-select-subject)
3375     (funcall gnus-auto-select-subject))))
3376
3377 (defun gnus-summary-prepare ()
3378   "Generate the summary buffer."
3379   (interactive)
3380   (let ((buffer-read-only nil))
3381     (erase-buffer)
3382     (setq gnus-newsgroup-data nil
3383           gnus-newsgroup-data-reverse nil)
3384     (gnus-run-hooks 'gnus-summary-generate-hook)
3385     ;; Generate the buffer, either with threads or without.
3386     (when gnus-newsgroup-headers
3387       (gnus-summary-prepare-threads
3388        (if gnus-show-threads
3389            (gnus-sort-gathered-threads
3390             (funcall gnus-summary-thread-gathering-function
3391                      (gnus-sort-threads
3392                       (gnus-cut-threads (gnus-make-threads)))))
3393          ;; Unthreaded display.
3394          (gnus-sort-articles gnus-newsgroup-headers))))
3395     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3396     ;; Call hooks for modifying summary buffer.
3397     (goto-char (point-min))
3398     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3399
3400 (defsubst gnus-general-simplify-subject (subject)
3401   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3402   (setq subject
3403         (cond
3404          ;; Truncate the subject.
3405          (gnus-simplify-subject-functions
3406           (gnus-map-function gnus-simplify-subject-functions subject))
3407          ((numberp gnus-summary-gather-subject-limit)
3408           (setq subject (gnus-simplify-subject-re subject))
3409           (if (> (length subject) gnus-summary-gather-subject-limit)
3410               (substring subject 0 gnus-summary-gather-subject-limit)
3411             subject))
3412          ;; Fuzzily simplify it.
3413          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3414           (gnus-simplify-subject-fuzzy subject))
3415          ;; Just remove the leading "Re:".
3416          (t
3417           (gnus-simplify-subject-re subject))))
3418
3419   (if (and gnus-summary-gather-exclude-subject
3420            (string-match gnus-summary-gather-exclude-subject subject))
3421       nil                               ; This article shouldn't be gathered
3422     subject))
3423
3424 (defun gnus-summary-simplify-subject-query ()
3425   "Query where the respool algorithm would put this article."
3426   (interactive)
3427   (gnus-summary-select-article)
3428   (message "%s"
3429            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3430
3431 (defun gnus-gather-threads-by-subject (threads)
3432   "Gather threads by looking at Subject headers."
3433   (if (not gnus-summary-make-false-root)
3434       threads
3435     (let ((hashtb (gnus-make-hashtable 1024))
3436           (prev threads)
3437           (result threads)
3438           subject hthread whole-subject)
3439       (while threads
3440         (setq subject (gnus-general-simplify-subject
3441                        (setq whole-subject (mail-header-subject
3442                                             (caar threads)))))
3443         (when subject
3444           (if (setq hthread (gnus-gethash subject hashtb))
3445               (progn
3446                 ;; We enter a dummy root into the thread, if we
3447                 ;; haven't done that already.
3448                 (unless (stringp (caar hthread))
3449                   (setcar hthread (list whole-subject (car hthread))))
3450                 ;; We add this new gathered thread to this gathered
3451                 ;; thread.
3452                 (setcdr (car hthread)
3453                         (nconc (cdar hthread) (list (car threads))))
3454                 ;; Remove it from the list of threads.
3455                 (setcdr prev (cdr threads))
3456                 (setq threads prev))
3457             ;; Enter this thread into the hash table.
3458             (gnus-sethash subject threads hashtb)))
3459         (setq prev threads)
3460         (setq threads (cdr threads)))
3461       result)))
3462
3463 (defun gnus-gather-threads-by-references (threads)
3464   "Gather threads by looking at References headers."
3465   (let ((idhashtb (gnus-make-hashtable 1024))
3466         (thhashtb (gnus-make-hashtable 1024))
3467         (prev threads)
3468         (result threads)
3469         ids references id gthread gid entered ref)
3470     (while threads
3471       (when (setq references (mail-header-references (caar threads)))
3472         (setq id (mail-header-id (caar threads))
3473               ids (inline (gnus-split-references references))
3474               entered nil)
3475         (while (setq ref (pop ids))
3476           (setq ids (delete ref ids))
3477           (if (not (setq gid (gnus-gethash ref idhashtb)))
3478               (progn
3479                 (gnus-sethash ref id idhashtb)
3480                 (gnus-sethash id threads thhashtb))
3481             (setq gthread (gnus-gethash gid thhashtb))
3482             (unless entered
3483               ;; We enter a dummy root into the thread, if we
3484               ;; haven't done that already.
3485               (unless (stringp (caar gthread))
3486                 (setcar gthread (list (mail-header-subject (caar gthread))
3487                                       (car gthread))))
3488               ;; We add this new gathered thread to this gathered
3489               ;; thread.
3490               (setcdr (car gthread)
3491                       (nconc (cdar gthread) (list (car threads)))))
3492             ;; Add it into the thread hash table.
3493             (gnus-sethash id gthread thhashtb)
3494             (setq entered t)
3495             ;; Remove it from the list of threads.
3496             (setcdr prev (cdr threads))
3497             (setq threads prev))))
3498       (setq prev threads)
3499       (setq threads (cdr threads)))
3500     result))
3501
3502 (defun gnus-sort-gathered-threads (threads)
3503   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3504   (let ((result threads))
3505     (while threads
3506       (when (stringp (caar threads))
3507         (setcdr (car threads)
3508                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3509       (setq threads (cdr threads)))
3510     result))
3511
3512 (defun gnus-thread-loop-p (root thread)
3513   "Say whether ROOT is in THREAD."
3514   (let ((stack (list thread))
3515         (infloop 0)
3516         th)
3517     (while (setq thread (pop stack))
3518       (setq th (cdr thread))
3519       (while (and th
3520                   (not (eq (caar th) root)))
3521         (pop th))
3522       (if th
3523           ;; We have found a loop.
3524           (let (ref-dep)
3525             (setcdr thread (delq (car th) (cdr thread)))
3526             (if (boundp (setq ref-dep (intern "none"
3527                                               gnus-newsgroup-dependencies)))
3528                 (setcdr (symbol-value ref-dep)
3529                         (nconc (cdr (symbol-value ref-dep))
3530                                (list (car th))))
3531               (set ref-dep (list nil (car th))))
3532             (setq infloop 1
3533                   stack nil))
3534         ;; Push all the subthreads onto the stack.
3535         (push (cdr thread) stack)))
3536     infloop))
3537
3538 (defun gnus-make-threads ()
3539   "Go through the dependency hashtb and find the roots.  Return all threads."
3540   (let (threads)
3541     (while (catch 'infloop
3542              (mapatoms
3543               (lambda (refs)
3544                 ;; Deal with self-referencing References loops.
3545                 (when (and (car (symbol-value refs))
3546                            (not (zerop
3547                                  (apply
3548                                   '+
3549                                   (mapcar
3550                                    (lambda (thread)
3551                                      (gnus-thread-loop-p
3552                                       (car (symbol-value refs)) thread))
3553                                    (cdr (symbol-value refs)))))))
3554                   (setq threads nil)
3555                   (throw 'infloop t))
3556                 (unless (car (symbol-value refs))
3557                   ;; These threads do not refer back to any other articles,
3558                   ;; so they're roots.
3559                   (setq threads (append (cdr (symbol-value refs)) threads))))
3560               gnus-newsgroup-dependencies)))
3561     threads))
3562
3563 ;; Build the thread tree.
3564 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3565   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3566
3567 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3568 if it was already present.
3569
3570 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3571 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3572 Message-IDs will be renamed to a unique Message-ID before being
3573 entered.
3574
3575 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3576   (let* ((id (mail-header-id header))
3577          (id-dep (and id (intern id dependencies)))
3578          ref ref-dep ref-header)
3579     ;; Enter this `header' in the `dependencies' table.
3580     (cond
3581      ((not id-dep)
3582       (setq header nil))
3583      ;; The first two cases do the normal part: enter a new `header'
3584      ;; in the `dependencies' table.
3585      ((not (boundp id-dep))
3586       (set id-dep (list header)))
3587      ((null (car (symbol-value id-dep)))
3588       (setcar (symbol-value id-dep) header))
3589
3590      ;; From here the `header' was already present in the
3591      ;; `dependencies' table.
3592      (force-new
3593       ;; Overrides an existing entry;
3594       ;; just set the header part of the entry.
3595       (setcar (symbol-value id-dep) header))
3596
3597      ;; Renames the existing `header' to a unique Message-ID.
3598      ((not gnus-summary-ignore-duplicates)
3599       ;; An article with this Message-ID has already been seen.
3600       ;; We rename the Message-ID.
3601       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3602            (list header))
3603       (mail-header-set-id header id))
3604
3605      ;; The last case ignores an existing entry, except it adds any
3606      ;; additional Xrefs (in case the two articles came from different
3607      ;; servers.
3608      ;; Also sets `header' to `nil' meaning that the `dependencies'
3609      ;; table was *not* modified.
3610      (t
3611       (mail-header-set-xref
3612        (car (symbol-value id-dep))
3613        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3614                    "")
3615                (or (mail-header-xref header) "")))
3616       (setq header nil)))
3617
3618     (when header
3619       ;; First check that we are not creating a References loop.
3620       (setq ref (gnus-parent-id (mail-header-references header)))
3621       (while (and ref
3622                   (setq ref-dep (intern-soft ref dependencies))
3623                   (boundp ref-dep)
3624                   (setq ref-header (car (symbol-value ref-dep))))
3625         (if (string= id ref)
3626             ;; Yuk!  This is a reference loop.  Make the article be a
3627             ;; root article.
3628             (progn
3629               (mail-header-set-references (car (symbol-value id-dep)) "none")
3630               (setq ref nil))
3631           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3632       (setq ref (gnus-parent-id (mail-header-references header)))
3633       (setq ref-dep (intern (or ref "none") dependencies))
3634       (if (boundp ref-dep)
3635           (setcdr (symbol-value ref-dep)
3636                   (nconc (cdr (symbol-value ref-dep))
3637                          (list (symbol-value id-dep))))
3638         (set ref-dep (list nil (symbol-value id-dep)))))
3639     header))
3640
3641 (defun gnus-extract-message-id-from-in-reply-to (string)
3642   (if (string-match "<[^>]+>" string)
3643       (substring string (match-beginning 0) (match-end 0))
3644     nil))
3645
3646 (defun gnus-build-sparse-threads ()
3647   (let ((headers gnus-newsgroup-headers)
3648         (mail-parse-charset gnus-newsgroup-charset)
3649         (gnus-summary-ignore-duplicates t)
3650         header references generation relations
3651         subject child end new-child date)
3652     ;; First we create an alist of generations/relations, where
3653     ;; generations is how much we trust the relation, and the relation
3654     ;; is parent/child.
3655     (gnus-message 7 "Making sparse threads...")
3656     (save-excursion
3657       (nnheader-set-temp-buffer " *gnus sparse threads*")
3658       (while (setq header (pop headers))
3659         (when (and (setq references (mail-header-references header))
3660                    (not (string= references "")))
3661           (insert references)
3662           (setq child (mail-header-id header)
3663                 subject (mail-header-subject header)
3664                 date (mail-header-date header)
3665                 generation 0)
3666           (while (search-backward ">" nil t)
3667             (setq end (1+ (point)))
3668             (when (search-backward "<" nil t)
3669               (setq new-child (buffer-substring (point) end))
3670               (push (list (incf generation)
3671                           child (setq child new-child)
3672                           subject date)
3673                     relations)))
3674           (when child
3675             (push (list (1+ generation) child nil subject) relations))
3676           (erase-buffer)))
3677       (kill-buffer (current-buffer)))
3678     ;; Sort over trustworthiness.
3679     (mapcar
3680      (lambda (relation)
3681        (when (gnus-dependencies-add-header
3682               (make-full-mail-header-from-decoded-header
3683                gnus-reffed-article-number
3684                (nth 3 relation) "" (or (nth 4 relation) "")
3685                (nth 1 relation)
3686                (or (nth 2 relation) "") 0 0 "")
3687               gnus-newsgroup-dependencies nil)
3688          (push gnus-reffed-article-number gnus-newsgroup-limit)
3689          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3690          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3691                gnus-newsgroup-reads)
3692          (decf gnus-reffed-article-number)))
3693      (sort relations 'car-less-than-car))
3694     (gnus-message 7 "Making sparse threads...done")))
3695
3696 (defun gnus-build-old-threads ()
3697   ;; Look at all the articles that refer back to old articles, and
3698   ;; fetch the headers for the articles that aren't there.  This will
3699   ;; build complete threads - if the roots haven't been expired by the
3700   ;; server, that is.
3701   (let ((mail-parse-charset gnus-newsgroup-charset)
3702         id heads)
3703     (mapatoms
3704      (lambda (refs)
3705        (when (not (car (symbol-value refs)))
3706          (setq heads (cdr (symbol-value refs)))
3707          (while heads
3708            (if (memq (mail-header-number (caar heads))
3709                      gnus-newsgroup-dormant)
3710                (setq heads (cdr heads))
3711              (setq id (symbol-name refs))
3712              (while (and (setq id (gnus-build-get-header id))
3713                          (not (car (gnus-id-to-thread id)))))
3714              (setq heads nil)))))
3715      gnus-newsgroup-dependencies)))
3716
3717 ;; This function has to be called with point after the article number
3718 ;; on the beginning of the line.
3719 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3720   (let ((eol (gnus-point-at-eol))
3721         (buffer (current-buffer))
3722         header references in-reply-to)
3723
3724     ;; overview: [num subject from date id refs chars lines misc]
3725     (unwind-protect
3726         (progn
3727           (narrow-to-region (point) eol)
3728           (unless (eobp)
3729             (forward-char))
3730
3731           (setq header
3732                 (make-full-mail-header
3733                  number                         ; number
3734                  (nnheader-nov-field)           ; subject
3735                  (nnheader-nov-field)           ; from
3736                  (nnheader-nov-field)           ; date
3737                  (nnheader-nov-read-message-id) ; id
3738                  (nnheader-nov-field)           ; refs
3739                  (nnheader-nov-read-integer)    ; chars
3740                  (nnheader-nov-read-integer)    ; lines
3741                  (unless (eobp)
3742                    (if (looking-at "Xref: ")
3743                        (goto-char (match-end 0)))
3744                    (nnheader-nov-field))        ; Xref
3745                  (nnheader-nov-parse-extra))))  ; extra
3746
3747       (widen))
3748
3749     (when (and (string= references "")
3750                (setq in-reply-to (mail-header-extra header))
3751                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3752       (mail-header-set-references
3753        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3754
3755     (when gnus-alter-header-function
3756       (funcall gnus-alter-header-function header))
3757     (gnus-dependencies-add-header header dependencies force-new)))
3758
3759 (defun gnus-build-get-header (id)
3760   "Look through the buffer of NOV lines and find the header to ID.
3761 Enter this line into the dependencies hash table, and return
3762 the id of the parent article (if any)."
3763   (let ((deps gnus-newsgroup-dependencies)
3764         found header)
3765     (prog1
3766         (save-excursion
3767           (set-buffer nntp-server-buffer)
3768           (let ((case-fold-search nil))
3769             (goto-char (point-min))
3770             (while (and (not found)
3771                         (search-forward id nil t))
3772               (beginning-of-line)
3773               (setq found (looking-at
3774                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3775                                    (regexp-quote id))))
3776               (or found (beginning-of-line 2)))
3777             (when found
3778               (beginning-of-line)
3779               (and
3780                (setq header (gnus-nov-parse-line
3781                              (read (current-buffer)) deps))
3782                (gnus-parent-id (mail-header-references header))))))
3783       (when header
3784         (let ((number (mail-header-number header)))
3785           (push number gnus-newsgroup-limit)
3786           (push header gnus-newsgroup-headers)
3787           (if (memq number gnus-newsgroup-unselected)
3788               (progn
3789                 (setq gnus-newsgroup-unreads
3790                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3791                                                number))
3792                 (setq gnus-newsgroup-unselected
3793                       (delq number gnus-newsgroup-unselected)))
3794             (push number gnus-newsgroup-ancient)))))))
3795
3796 (defun gnus-build-all-threads ()
3797   "Read all the headers."
3798   (let ((gnus-summary-ignore-duplicates t)
3799         (mail-parse-charset gnus-newsgroup-charset)
3800         (dependencies gnus-newsgroup-dependencies)
3801         header article)
3802     (save-excursion
3803       (set-buffer nntp-server-buffer)
3804       (let ((case-fold-search nil))
3805         (goto-char (point-min))
3806         (while (not (eobp))
3807           (ignore-errors
3808             (setq article (read (current-buffer))
3809                   header (gnus-nov-parse-line article dependencies)))
3810           (when header
3811             (save-excursion
3812               (set-buffer gnus-summary-buffer)
3813               (push header gnus-newsgroup-headers)
3814               (if (memq (setq article (mail-header-number header))
3815                         gnus-newsgroup-unselected)
3816                   (progn
3817                     (setq gnus-newsgroup-unreads
3818                           (gnus-add-to-sorted-list
3819                            gnus-newsgroup-unreads article))
3820                     (setq gnus-newsgroup-unselected
3821                           (delq article gnus-newsgroup-unselected)))
3822                 (push article gnus-newsgroup-ancient)))
3823             (forward-line 1)))))))
3824
3825 (defun gnus-summary-update-article-line (article header)
3826   "Update the line for ARTICLE using HEADERS."
3827   (let* ((id (mail-header-id header))
3828          (thread (gnus-id-to-thread id)))
3829     (unless thread
3830       (error "Article in no thread"))
3831     ;; Update the thread.
3832     (setcar thread header)
3833     (gnus-summary-goto-subject article)
3834     (let* ((datal (gnus-data-find-list article))
3835            (data (car datal))
3836            (length (when (cdr datal)
3837                      (- (gnus-data-pos data)
3838                         (gnus-data-pos (cadr datal)))))
3839            (buffer-read-only nil)
3840            (level (gnus-summary-thread-level)))
3841       (gnus-delete-line)
3842       (gnus-summary-insert-line
3843        header level nil (gnus-article-mark article)
3844        (memq article gnus-newsgroup-replied)
3845        (memq article gnus-newsgroup-expirable)
3846        ;; Only insert the Subject string when it's different
3847        ;; from the previous Subject string.
3848        (if (and
3849             gnus-show-threads
3850             (gnus-subject-equal
3851              (condition-case ()
3852                  (mail-header-subject
3853                   (gnus-data-header
3854                    (cadr
3855                     (gnus-data-find-list
3856                      article
3857                      (gnus-data-list t)))))
3858                ;; Error on the side of excessive subjects.
3859                (error ""))
3860              (mail-header-subject header)))
3861            ""
3862          (mail-header-subject header))
3863        nil (cdr (assq article gnus-newsgroup-scored))
3864        (memq article gnus-newsgroup-processable))
3865       (when length
3866         (gnus-data-update-list
3867          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3868
3869 (defun gnus-summary-update-article (article &optional iheader)
3870   "Update ARTICLE in the summary buffer."
3871   (set-buffer gnus-summary-buffer)
3872   (let* ((header (gnus-summary-article-header article))
3873          (id (mail-header-id header))
3874          (data (gnus-data-find article))
3875          (thread (gnus-id-to-thread id))
3876          (references (mail-header-references header))
3877          (parent
3878           (gnus-id-to-thread
3879            (or (gnus-parent-id
3880                 (when (and references
3881                            (not (equal "" references)))
3882                   references))
3883                "none")))
3884          (buffer-read-only nil)
3885          (old (car thread)))
3886     (when thread
3887       (unless iheader
3888         (setcar thread nil)
3889         (when parent
3890           (delq thread parent)))
3891       (if (gnus-summary-insert-subject id header)
3892           ;; Set the (possibly) new article number in the data structure.
3893           (gnus-data-set-number data (gnus-id-to-article id))
3894         (setcar thread old)
3895         nil))))
3896
3897 (defun gnus-rebuild-thread (id &optional line)
3898   "Rebuild the thread containing ID.
3899 If LINE, insert the rebuilt thread starting on line LINE."
3900   (let ((buffer-read-only nil)
3901         old-pos current thread data)
3902     (if (not gnus-show-threads)
3903         (setq thread (list (car (gnus-id-to-thread id))))
3904       ;; Get the thread this article is part of.
3905       (setq thread (gnus-remove-thread id)))
3906     (setq old-pos (gnus-point-at-bol))
3907     (setq current (save-excursion
3908                     (and (re-search-backward "[\r\n]" nil t)
3909                          (gnus-summary-article-number))))
3910     ;; If this is a gathered thread, we have to go some re-gathering.
3911     (when (stringp (car thread))
3912       (let ((subject (car thread))
3913             roots thr)
3914         (setq thread (cdr thread))
3915         (while thread
3916           (unless (memq (setq thr (gnus-id-to-thread
3917                                    (gnus-root-id
3918                                     (mail-header-id (caar thread)))))
3919                         roots)
3920             (push thr roots))
3921           (setq thread (cdr thread)))
3922         ;; We now have all (unique) roots.
3923         (if (= (length roots) 1)
3924             ;; All the loose roots are now one solid root.
3925             (setq thread (car roots))
3926           (setq thread (cons subject (gnus-sort-threads roots))))))
3927     (let (threads)
3928       ;; We then insert this thread into the summary buffer.
3929       (when line
3930         (goto-char (point-min))
3931         (forward-line (1- line)))
3932       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3933         (if gnus-show-threads
3934             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3935           (gnus-summary-prepare-unthreaded thread))
3936         (setq data (nreverse gnus-newsgroup-data))
3937         (setq threads gnus-newsgroup-threads))
3938       ;; We splice the new data into the data structure.
3939       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3940       ;;!!! then we want to insert at the beginning of the buffer.
3941       ;;!!! That happens to be true with Gnus now, but that may
3942       ;;!!! change in the future.  Perhaps.
3943       (gnus-data-enter-list
3944        (if line nil current) data (- (point) old-pos))
3945       (setq gnus-newsgroup-threads
3946             (nconc threads gnus-newsgroup-threads))
3947       (gnus-data-compute-positions))))
3948
3949 (defun gnus-number-to-header (number)
3950   "Return the header for article NUMBER."
3951   (let ((headers gnus-newsgroup-headers))
3952     (while (and headers
3953                 (not (= number (mail-header-number (car headers)))))
3954       (pop headers))
3955     (when headers
3956       (car headers))))
3957
3958 (defun gnus-parent-headers (in-headers &optional generation)
3959   "Return the headers of the GENERATIONeth parent of HEADERS."
3960   (unless generation
3961     (setq generation 1))
3962   (let ((parent t)
3963         (headers in-headers)
3964         references)
3965     (while (and parent
3966                 (not (zerop generation))
3967                 (setq references (mail-header-references headers)))
3968       (setq headers (if (and references
3969                              (setq parent (gnus-parent-id references)))
3970                         (car (gnus-id-to-thread parent))
3971                       nil))
3972       (decf generation))
3973     (and (not (eq headers in-headers))
3974          headers)))
3975
3976 (defun gnus-id-to-thread (id)
3977   "Return the (sub-)thread where ID appears."
3978   (gnus-gethash id gnus-newsgroup-dependencies))
3979
3980 (defun gnus-id-to-article (id)
3981   "Return the article number of ID."
3982   (let ((thread (gnus-id-to-thread id)))
3983     (when (and thread
3984                (car thread))
3985       (mail-header-number (car thread)))))
3986
3987 (defun gnus-id-to-header (id)
3988   "Return the article headers of ID."
3989   (car (gnus-id-to-thread id)))
3990
3991 (defun gnus-article-displayed-root-p (article)
3992   "Say whether ARTICLE is a root(ish) article."
3993   (let ((level (gnus-summary-thread-level article))
3994         (refs (mail-header-references  (gnus-summary-article-header article)))
3995         particle)
3996     (cond
3997      ((null level) nil)
3998      ((zerop level) t)
3999      ((null refs) t)
4000      ((null (gnus-parent-id refs)) t)
4001      ((and (= 1 level)
4002            (null (setq particle (gnus-id-to-article
4003                                  (gnus-parent-id refs))))
4004            (null (gnus-summary-thread-level particle)))))))
4005
4006 (defun gnus-root-id (id)
4007   "Return the id of the root of the thread where ID appears."
4008   (let (last-id prev)
4009     (while (and id (setq prev (car (gnus-id-to-thread id))))
4010       (setq last-id id
4011             id (gnus-parent-id (mail-header-references prev))))
4012     last-id))
4013
4014 (defun gnus-articles-in-thread (thread)
4015   "Return the list of articles in THREAD."
4016   (cons (mail-header-number (car thread))
4017         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4018
4019 (defun gnus-remove-thread (id &optional dont-remove)
4020   "Remove the thread that has ID in it."
4021   (let (headers thread last-id)
4022     ;; First go up in this thread until we find the root.
4023     (setq last-id (gnus-root-id id)
4024           headers (message-flatten-list (gnus-id-to-thread last-id)))
4025     ;; We have now found the real root of this thread.  It might have
4026     ;; been gathered into some loose thread, so we have to search
4027     ;; through the threads to find the thread we wanted.
4028     (let ((threads gnus-newsgroup-threads)
4029           sub)
4030       (while threads
4031         (setq sub (car threads))
4032         (if (stringp (car sub))
4033             ;; This is a gathered thread, so we look at the roots
4034             ;; below it to find whether this article is in this
4035             ;; gathered root.
4036             (progn
4037               (setq sub (cdr sub))
4038               (while sub
4039                 (when (member (caar sub) headers)
4040                   (setq thread (car threads)
4041                         threads nil
4042                         sub nil))
4043                 (setq sub (cdr sub))))
4044           ;; It's an ordinary thread, so we check it.
4045           (when (eq (car sub) (car headers))
4046             (setq thread sub
4047                   threads nil)))
4048         (setq threads (cdr threads)))
4049       ;; If this article is in no thread, then it's a root.
4050       (if thread
4051           (unless dont-remove
4052             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4053         (setq thread (gnus-id-to-thread last-id)))
4054       (when thread
4055         (prog1
4056             thread                      ; We return this thread.
4057           (unless dont-remove
4058             (if (stringp (car thread))
4059                 (progn
4060                   ;; If we use dummy roots, then we have to remove the
4061                   ;; dummy root as well.
4062                   (when (eq gnus-summary-make-false-root 'dummy)
4063                     ;; We go to the dummy root by going to
4064                     ;; the first sub-"thread", and then one line up.
4065                     (gnus-summary-goto-article
4066                      (mail-header-number (caadr thread)))
4067                     (forward-line -1)
4068                     (gnus-delete-line)
4069                     (gnus-data-compute-positions))
4070                   (setq thread (cdr thread))
4071                   (while thread
4072                     (gnus-remove-thread-1 (car thread))
4073                     (setq thread (cdr thread))))
4074               (gnus-remove-thread-1 thread))))))))
4075
4076 (defun gnus-remove-thread-1 (thread)
4077   "Remove the thread THREAD recursively."
4078   (let ((number (mail-header-number (pop thread)))
4079         d)
4080     (setq thread (reverse thread))
4081     (while thread
4082       (gnus-remove-thread-1 (pop thread)))
4083     (when (setq d (gnus-data-find number))
4084       (goto-char (gnus-data-pos d))
4085       (gnus-summary-show-thread)
4086       (gnus-data-remove
4087        number
4088        (- (gnus-point-at-bol)
4089           (prog1
4090               (1+ (gnus-point-at-eol))
4091             (gnus-delete-line)))))))
4092
4093 (defun gnus-sort-threads-1 (threads func)
4094   (sort (mapcar (lambda (thread)
4095                   (cons (car thread)
4096                         (and (cdr thread)
4097                              (gnus-sort-threads-1 (cdr thread) func))))
4098                 threads) func))
4099
4100 (defun gnus-sort-threads (threads)
4101   "Sort THREADS."
4102   (if (not gnus-thread-sort-functions)
4103       threads
4104     (gnus-message 8 "Sorting threads...")
4105     (prog1
4106         (gnus-sort-threads-1
4107          threads
4108          (gnus-make-sort-function gnus-thread-sort-functions))
4109       (gnus-message 8 "Sorting threads...done"))))
4110
4111 (defun gnus-sort-articles (articles)
4112   "Sort ARTICLES."
4113   (when gnus-article-sort-functions
4114     (gnus-message 7 "Sorting articles...")
4115     (prog1
4116         (setq gnus-newsgroup-headers
4117               (sort articles (gnus-make-sort-function
4118                               gnus-article-sort-functions)))
4119       (gnus-message 7 "Sorting articles...done"))))
4120
4121 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4122 (defmacro gnus-thread-header (thread)
4123   "Return header of first article in THREAD.
4124 Note that THREAD must never, ever be anything else than a variable -
4125 using some other form will lead to serious barfage."
4126   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4127   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4128   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4129         (vector thread) 2))
4130
4131 (defsubst gnus-article-sort-by-number (h1 h2)
4132   "Sort articles by article number."
4133   (< (mail-header-number h1)
4134      (mail-header-number h2)))
4135
4136 (defun gnus-thread-sort-by-number (h1 h2)
4137   "Sort threads by root article number."
4138   (gnus-article-sort-by-number
4139    (gnus-thread-header h1) (gnus-thread-header h2)))
4140
4141 (defsubst gnus-article-sort-by-lines (h1 h2)
4142   "Sort articles by article Lines header."
4143   (< (mail-header-lines h1)
4144      (mail-header-lines h2)))
4145
4146 (defun gnus-thread-sort-by-lines (h1 h2)
4147   "Sort threads by root article Lines header."
4148   (gnus-article-sort-by-lines
4149    (gnus-thread-header h1) (gnus-thread-header h2)))
4150
4151 (defsubst gnus-article-sort-by-chars (h1 h2)
4152   "Sort articles by octet length."
4153   (< (mail-header-chars h1)
4154      (mail-header-chars h2)))
4155
4156 (defun gnus-thread-sort-by-chars (h1 h2)
4157   "Sort threads by root article octet length."
4158   (gnus-article-sort-by-chars
4159    (gnus-thread-header h1) (gnus-thread-header h2)))
4160
4161 (defsubst gnus-article-sort-by-author (h1 h2)
4162   "Sort articles by root author."
4163   (string-lessp
4164    (let ((addr (car (mime-entity-read-field h1 'From))))
4165      (or (std11-full-name-string addr)
4166          (std11-address-string addr)
4167          ""))
4168    (let ((addr (car (mime-entity-read-field h2 'From))))
4169      (or (std11-full-name-string addr)
4170          (std11-address-string addr)
4171          ""))
4172    ))
4173
4174 (defun gnus-thread-sort-by-author (h1 h2)
4175   "Sort threads by root author."
4176   (gnus-article-sort-by-author
4177    (gnus-thread-header h1)  (gnus-thread-header h2)))
4178
4179 (defsubst gnus-article-sort-by-subject (h1 h2)
4180   "Sort articles by root subject."
4181   (string-lessp
4182    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4183    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4184
4185 (defun gnus-thread-sort-by-subject (h1 h2)
4186   "Sort threads by root subject."
4187   (gnus-article-sort-by-subject
4188    (gnus-thread-header h1) (gnus-thread-header h2)))
4189
4190 (defsubst gnus-article-sort-by-date (h1 h2)
4191   "Sort articles by root article date."
4192   (time-less-p
4193    (gnus-date-get-time (mail-header-date h1))
4194    (gnus-date-get-time (mail-header-date h2))))
4195
4196 (defun gnus-thread-sort-by-date (h1 h2)
4197   "Sort threads by root article date."
4198   (gnus-article-sort-by-date
4199    (gnus-thread-header h1) (gnus-thread-header h2)))
4200
4201 (defsubst gnus-article-sort-by-score (h1 h2)
4202   "Sort articles by root article score.
4203 Unscored articles will be counted as having a score of zero."
4204   (> (or (cdr (assq (mail-header-number h1)
4205                     gnus-newsgroup-scored))
4206          gnus-summary-default-score 0)
4207      (or (cdr (assq (mail-header-number h2)
4208                     gnus-newsgroup-scored))
4209          gnus-summary-default-score 0)))
4210
4211 (defun gnus-thread-sort-by-score (h1 h2)
4212   "Sort threads by root article score."
4213   (gnus-article-sort-by-score
4214    (gnus-thread-header h1) (gnus-thread-header h2)))
4215
4216 (defun gnus-thread-sort-by-total-score (h1 h2)
4217   "Sort threads by the sum of all scores in the thread.
4218 Unscored articles will be counted as having a score of zero."
4219   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4220
4221 (defun gnus-thread-total-score (thread)
4222   ;; This function find the total score of THREAD.
4223   (cond
4224    ((null thread)
4225     0)
4226    ((consp thread)
4227     (if (stringp (car thread))
4228         (apply gnus-thread-score-function 0
4229                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4230       (gnus-thread-total-score-1 thread)))
4231    (t
4232     (gnus-thread-total-score-1 (list thread)))))
4233
4234 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4235   "Sort threads such that the thread with the most recently arrived article comes first."
4236   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4237
4238 (defun gnus-thread-highest-number (thread)
4239   "Return the highest article number in THREAD."
4240   (apply 'max (mapcar (lambda (header)
4241                         (mail-header-number header))
4242                       (message-flatten-list thread))))
4243
4244 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4245   "Sort threads such that the thread with the most recently dated article comes first."
4246   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4247
4248 (defun gnus-thread-latest-date (thread)
4249   "Return the highest article date in THREAD."
4250   (let ((previous-time 0))
4251     (apply 'max (mapcar
4252                  (lambda (header)
4253                    (setq previous-time
4254                          (time-to-seconds
4255                           (mail-header-parse-date
4256                            (condition-case ()
4257                                (mail-header-date header)
4258                              (error previous-time))))))
4259                  (sort
4260                   (message-flatten-list thread)
4261                   (lambda (h1 h2)
4262                     (< (mail-header-number h1)
4263                        (mail-header-number h2))))))))
4264
4265 (defun gnus-thread-total-score-1 (root)
4266   ;; This function find the total score of the thread below ROOT.
4267   (setq root (car root))
4268   (apply gnus-thread-score-function
4269          (or (append
4270               (mapcar 'gnus-thread-total-score
4271                       (cdr (gnus-id-to-thread (mail-header-id root))))
4272               (when (> (mail-header-number root) 0)
4273                 (list (or (cdr (assq (mail-header-number root)
4274                                      gnus-newsgroup-scored))
4275                           gnus-summary-default-score 0))))
4276              (list gnus-summary-default-score)
4277              '(0))))
4278
4279 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4280 (defvar gnus-tmp-prev-subject nil)
4281 (defvar gnus-tmp-false-parent nil)
4282 (defvar gnus-tmp-root-expunged nil)
4283 (defvar gnus-tmp-dummy-line nil)
4284
4285 (eval-when-compile (defvar gnus-tmp-header))
4286 (defun gnus-extra-header (type &optional header)
4287   "Return the extra header of TYPE."
4288   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4289       ""))
4290
4291 (defvar gnus-tmp-thread-tree-header-string "")
4292
4293 (defvar gnus-sum-thread-tree-root "> "
4294   "With %B spec, used for the root of a thread.
4295 If nil, use subject instead.")
4296 (defvar gnus-sum-thread-tree-single-indent ""
4297   "With %B spec, used for a thread with just one message.
4298 If nil, use subject instead.")
4299 (defvar gnus-sum-thread-tree-vertical "| "
4300   "With %B spec, used for drawing a vertical line.")
4301 (defvar gnus-sum-thread-tree-indent "  "
4302   "With %B spec, used for indenting.")
4303 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4304   "With %B spec, used for a leaf with brothers.")
4305 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4306   "With %B spec, used for a leaf without brothers.")
4307
4308 (defun gnus-summary-prepare-threads (threads)
4309   "Prepare summary buffer from THREADS and indentation LEVEL.
4310 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4311 or a straight list of headers."
4312   (gnus-message 7 "Generating summary...")
4313
4314   (setq gnus-newsgroup-threads threads)
4315   (beginning-of-line)
4316
4317   (let ((gnus-tmp-level 0)
4318         (default-score (or gnus-summary-default-score 0))
4319         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4320         thread number subject stack state gnus-tmp-gathered beg-match
4321         new-roots gnus-tmp-new-adopts thread-end
4322         gnus-tmp-header gnus-tmp-unread
4323         gnus-tmp-replied gnus-tmp-subject-or-nil
4324         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4325         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4326         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4327         tree-stack)
4328
4329     (setq gnus-tmp-prev-subject nil)
4330
4331     (if (vectorp (car threads))
4332         ;; If this is a straight (sic) list of headers, then a
4333         ;; threaded summary display isn't required, so we just create
4334         ;; an unthreaded one.
4335         (gnus-summary-prepare-unthreaded threads)
4336
4337       ;; Do the threaded display.
4338
4339       (while (or threads stack gnus-tmp-new-adopts new-roots)
4340
4341         (if (and (= gnus-tmp-level 0)
4342                  (or (not stack)
4343                      (= (caar stack) 0))
4344                  (not gnus-tmp-false-parent)
4345                  (or gnus-tmp-new-adopts new-roots))
4346             (if gnus-tmp-new-adopts
4347                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4348                       thread (list (car gnus-tmp-new-adopts))
4349                       gnus-tmp-header (caar thread)
4350                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4351               (when new-roots
4352                 (setq thread (list (car new-roots))
4353                       gnus-tmp-header (caar thread)
4354                       new-roots (cdr new-roots))))
4355
4356           (if threads
4357               ;; If there are some threads, we do them before the
4358               ;; threads on the stack.
4359               (setq thread threads
4360                     gnus-tmp-header (caar thread))
4361             ;; There were no current threads, so we pop something off
4362             ;; the stack.
4363             (setq state (car stack)
4364                   gnus-tmp-level (car state)
4365                   tree-stack (cadr state)
4366                   thread (caddr state)
4367                   stack (cdr stack)
4368                   gnus-tmp-header (caar thread))))
4369
4370         (setq gnus-tmp-false-parent nil)
4371         (setq gnus-tmp-root-expunged nil)
4372         (setq thread-end nil)
4373
4374         (if (stringp gnus-tmp-header)
4375             ;; The header is a dummy root.
4376             (cond
4377              ((eq gnus-summary-make-false-root 'adopt)
4378               ;; We let the first article adopt the rest.
4379               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4380                                                (cddar thread)))
4381               (setq gnus-tmp-gathered
4382                     (nconc (mapcar
4383                             (lambda (h) (mail-header-number (car h)))
4384                             (cddar thread))
4385                            gnus-tmp-gathered))
4386               (setq thread (cons (list (caar thread)
4387                                        (cadar thread))
4388                                  (cdr thread)))
4389               (setq gnus-tmp-level -1
4390                     gnus-tmp-false-parent t))
4391              ((eq gnus-summary-make-false-root 'empty)
4392               ;; We print adopted articles with empty subject fields.
4393               (setq gnus-tmp-gathered
4394                     (nconc (mapcar
4395                             (lambda (h) (mail-header-number (car h)))
4396                             (cddar thread))
4397                            gnus-tmp-gathered))
4398               (setq gnus-tmp-level -1))
4399              ((eq gnus-summary-make-false-root 'dummy)
4400               ;; We remember that we probably want to output a dummy
4401               ;; root.
4402               (setq gnus-tmp-dummy-line gnus-tmp-header)
4403               (setq gnus-tmp-prev-subject gnus-tmp-header))
4404              (t
4405               ;; We do not make a root for the gathered
4406               ;; sub-threads at all.
4407               (setq gnus-tmp-level -1)))
4408
4409           (setq number (mail-header-number gnus-tmp-header)
4410                 subject (mail-header-subject gnus-tmp-header))
4411
4412           (cond
4413            ;; If the thread has changed subject, we might want to make
4414            ;; this subthread into a root.
4415            ((and (null gnus-thread-ignore-subject)
4416                  (not (zerop gnus-tmp-level))
4417                  gnus-tmp-prev-subject
4418                  (not (inline
4419                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4420             (setq new-roots (nconc new-roots (list (car thread)))
4421                   thread-end t
4422                   gnus-tmp-header nil))
4423            ;; If the article lies outside the current limit,
4424            ;; then we do not display it.
4425            ((not (memq number gnus-newsgroup-limit))
4426             (setq gnus-tmp-gathered
4427                   (nconc (mapcar
4428                           (lambda (h) (mail-header-number (car h)))
4429                           (cdar thread))
4430                          gnus-tmp-gathered))
4431             (setq gnus-tmp-new-adopts (if (cdar thread)
4432                                           (append gnus-tmp-new-adopts
4433                                                   (cdar thread))
4434                                         gnus-tmp-new-adopts)
4435                   thread-end t
4436                   gnus-tmp-header nil)
4437             (when (zerop gnus-tmp-level)
4438               (setq gnus-tmp-root-expunged t)))
4439            ;; Perhaps this article is to be marked as read?
4440            ((and gnus-summary-mark-below
4441                  (< (or (cdr (assq number gnus-newsgroup-scored))
4442                         default-score)
4443                     gnus-summary-mark-below)
4444                  ;; Don't touch sparse articles.
4445                  (not (gnus-summary-article-sparse-p number))
4446                  (not (gnus-summary-article-ancient-p number)))
4447             (setq gnus-newsgroup-unreads
4448                   (delq number gnus-newsgroup-unreads))
4449             (if gnus-newsgroup-auto-expire
4450                 (setq gnus-newsgroup-expirable
4451                       (gnus-add-to-sorted-list
4452                        gnus-newsgroup-expirable number))
4453               (push (cons number gnus-low-score-mark)
4454                     gnus-newsgroup-reads))))
4455
4456           (when gnus-tmp-header
4457             ;; We may have an old dummy line to output before this
4458             ;; article.
4459             (when (and gnus-tmp-dummy-line
4460                        (gnus-subject-equal
4461                         gnus-tmp-dummy-line
4462                         (mail-header-subject gnus-tmp-header)))
4463               (gnus-summary-insert-dummy-line
4464                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4465               (setq gnus-tmp-dummy-line nil))
4466
4467             ;; Compute the mark.
4468             (setq gnus-tmp-unread (gnus-article-mark number))
4469
4470             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4471                                   gnus-tmp-header gnus-tmp-level)
4472                   gnus-newsgroup-data)
4473
4474             ;; Actually insert the line.
4475             (setq
4476              gnus-tmp-subject-or-nil
4477              (cond
4478               ((and gnus-thread-ignore-subject
4479                     gnus-tmp-prev-subject
4480                     (not (inline (gnus-subject-equal
4481                                   gnus-tmp-prev-subject subject))))
4482                subject)
4483               ((zerop gnus-tmp-level)
4484                (if (and (eq gnus-summary-make-false-root 'empty)
4485                         (memq number gnus-tmp-gathered)
4486                         gnus-tmp-prev-subject
4487                         (inline (gnus-subject-equal
4488                                  gnus-tmp-prev-subject subject)))
4489                    gnus-summary-same-subject
4490                  subject))
4491               (t gnus-summary-same-subject)))
4492             (if (and (eq gnus-summary-make-false-root 'adopt)
4493                      (= gnus-tmp-level 1)
4494                      (memq number gnus-tmp-gathered))
4495                 (setq gnus-tmp-opening-bracket ?\<
4496                       gnus-tmp-closing-bracket ?\>)
4497               (setq gnus-tmp-opening-bracket ?\[
4498                     gnus-tmp-closing-bracket ?\]))
4499             (setq
4500              gnus-tmp-indentation
4501              (aref gnus-thread-indent-array gnus-tmp-level)
4502              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4503              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4504                                 gnus-summary-default-score 0)
4505              gnus-tmp-score-char
4506              (if (or (null gnus-summary-default-score)
4507                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4508                          gnus-summary-zcore-fuzz))
4509                  ?\ ;;;Whitespace
4510                (if (< gnus-tmp-score gnus-summary-default-score)
4511                    gnus-score-below-mark gnus-score-over-mark))
4512              gnus-tmp-replied
4513              (cond ((memq number gnus-newsgroup-processable)
4514                     gnus-process-mark)
4515                    ((memq number gnus-newsgroup-cached)
4516                     gnus-cached-mark)
4517                    ((memq number gnus-newsgroup-replied)
4518                     gnus-replied-mark)
4519                    ((memq number gnus-newsgroup-forwarded)
4520                     gnus-forwarded-mark)
4521                    ((memq number gnus-newsgroup-saved)
4522                     gnus-saved-mark)
4523                    ((memq number gnus-newsgroup-recent)
4524                     gnus-recent-mark)
4525                    ((memq number gnus-newsgroup-unseen)
4526                     gnus-unseen-mark)
4527                    (t gnus-no-mark))
4528              gnus-tmp-from (mail-header-from gnus-tmp-header)
4529              gnus-tmp-name
4530              (cond
4531               ((string-match "<[^>]+> *$" gnus-tmp-from)
4532                (setq beg-match (match-beginning 0))
4533                (or (and (string-match "^\".+\"" gnus-tmp-from)
4534                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4535                    (substring gnus-tmp-from 0 beg-match)))
4536               ((string-match "(.+)" gnus-tmp-from)
4537                (substring gnus-tmp-from
4538                           (1+ (match-beginning 0)) (1- (match-end 0))))
4539               (t gnus-tmp-from))
4540              gnus-tmp-thread-tree-header-string
4541              (cond
4542               ((not gnus-show-threads) "")
4543               ((zerop gnus-tmp-level)
4544                (if (cdar thread)
4545                    (or gnus-sum-thread-tree-root subject)
4546                  (or gnus-sum-thread-tree-single-indent subject)))
4547               (t
4548                (concat (apply 'concat
4549                               (mapcar (lambda (item)
4550                                         (if (= item 1)
4551                                             gnus-sum-thread-tree-vertical
4552                                           gnus-sum-thread-tree-indent))
4553                                       (cdr (reverse tree-stack))))
4554                        (if (nth 1 thread)
4555                            gnus-sum-thread-tree-leaf-with-other
4556                          gnus-sum-thread-tree-single-leaf)))))
4557             (when (string= gnus-tmp-name "")
4558               (setq gnus-tmp-name gnus-tmp-from))
4559             (unless (numberp gnus-tmp-lines)
4560               (setq gnus-tmp-lines -1))
4561             (if (= gnus-tmp-lines -1)
4562                 (setq gnus-tmp-lines "?")
4563               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4564             (gnus-put-text-property
4565              (point)
4566              (progn (eval gnus-summary-line-format-spec) (point))
4567              'gnus-number number)
4568             (when gnus-visual-p
4569               (forward-line -1)
4570               (gnus-run-hooks 'gnus-summary-update-hook)
4571               (forward-line 1))
4572
4573             (setq gnus-tmp-prev-subject subject)))
4574
4575         (when (nth 1 thread)
4576           (push (list (max 0 gnus-tmp-level)
4577                       (copy-list tree-stack)
4578                       (nthcdr 1 thread))
4579                 stack))
4580         (push (if (nth 1 thread) 1 0) tree-stack)
4581         (incf gnus-tmp-level)
4582         (setq threads (if thread-end nil (cdar thread)))
4583         (unless threads
4584           (setq gnus-tmp-level 0)))))
4585   (gnus-message 7 "Generating summary...done"))
4586
4587 (defun gnus-summary-prepare-unthreaded (headers)
4588   "Generate an unthreaded summary buffer based on HEADERS."
4589   (let (header number mark)
4590
4591     (beginning-of-line)
4592
4593     (while headers
4594       ;; We may have to root out some bad articles...
4595       (when (memq (setq number (mail-header-number
4596                                 (setq header (pop headers))))
4597                   gnus-newsgroup-limit)
4598         ;; Mark article as read when it has a low score.
4599         (when (and gnus-summary-mark-below
4600                    (< (or (cdr (assq number gnus-newsgroup-scored))
4601                           gnus-summary-default-score 0)
4602                       gnus-summary-mark-below)
4603                    (not (gnus-summary-article-ancient-p number)))
4604           (setq gnus-newsgroup-unreads
4605                 (delq number gnus-newsgroup-unreads))
4606           (if gnus-newsgroup-auto-expire
4607               (push number gnus-newsgroup-expirable)
4608             (push (cons number gnus-low-score-mark)
4609                   gnus-newsgroup-reads)))
4610
4611         (setq mark (gnus-article-mark number))
4612         (push (gnus-data-make number mark (1+ (point)) header 0)
4613               gnus-newsgroup-data)
4614         (gnus-summary-insert-line
4615          header 0 number
4616          mark (memq number gnus-newsgroup-replied)
4617          (memq number gnus-newsgroup-expirable)
4618          (mail-header-subject header) nil
4619          (cdr (assq number gnus-newsgroup-scored))
4620          (memq number gnus-newsgroup-processable))))))
4621
4622 (defun gnus-summary-remove-list-identifiers ()
4623   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4624   (let ((regexp (if (consp gnus-list-identifiers)
4625                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4626                   gnus-list-identifiers))
4627         changed subject)
4628     (when regexp
4629       (dolist (header gnus-newsgroup-headers)
4630         (setq subject (mail-header-subject header)
4631               changed nil)
4632         (while (string-match
4633                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4634                 subject)
4635           (setq subject
4636                 (concat (substring subject 0 (match-beginning 2))
4637                         (substring subject (match-end 0)))
4638                 changed t))
4639         (when (and changed
4640                    (string-match
4641                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4642           (setq subject
4643                 (concat (substring subject 0 (match-beginning 1))
4644                         (substring subject (match-end 1)))))
4645         (when changed
4646           (mail-header-set-subject header subject))))))
4647
4648 (defun gnus-fetch-headers (articles)
4649   "Fetch headers of ARTICLES."
4650   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4651     (gnus-message 5 "Fetching headers for %s..." name)
4652     (prog1
4653         (if (eq 'nov
4654                 (setq gnus-headers-retrieved-by
4655                       (gnus-retrieve-headers
4656                        articles gnus-newsgroup-name
4657                        ;; We might want to fetch old headers, but
4658                        ;; not if there is only 1 article.
4659                        (and (or (and
4660                                  (not (eq gnus-fetch-old-headers 'some))
4661                                  (not (numberp gnus-fetch-old-headers)))
4662                                 (> (length articles) 1))
4663                             gnus-fetch-old-headers))))
4664             (gnus-get-newsgroup-headers-xover
4665              articles nil nil gnus-newsgroup-name t)
4666           (gnus-get-newsgroup-headers))
4667       (gnus-message 5 "Fetching headers for %s...done" name))))
4668
4669 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4670   "Select newsgroup GROUP.
4671 If READ-ALL is non-nil, all articles in the group are selected.
4672 If SELECT-ARTICLES, only select those articles from GROUP."
4673   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4674          ;;!!! Dirty hack; should be removed.
4675          (gnus-summary-ignore-duplicates
4676           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4677               t
4678             gnus-summary-ignore-duplicates))
4679          (info (nth 2 entry))
4680          articles fetched-articles cached)
4681
4682     (unless (gnus-check-server
4683              (set (make-local-variable 'gnus-current-select-method)
4684                   (gnus-find-method-for-group group)))
4685       (error "Couldn't open server"))
4686
4687     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4688         (gnus-activate-group group)     ; Or we can activate it...
4689         (progn                          ; Or we bug out.
4690           (when (equal major-mode 'gnus-summary-mode)
4691             (kill-buffer (current-buffer)))
4692           (error "Couldn't activate group %s: %s"
4693                  group (gnus-status-message group))))
4694
4695     (unless (gnus-request-group group t)
4696       (when (equal major-mode 'gnus-summary-mode)
4697         (kill-buffer (current-buffer)))
4698       (error "Couldn't request group %s: %s"
4699              group (gnus-status-message group)))
4700
4701     (setq gnus-newsgroup-name group
4702           gnus-newsgroup-unselected nil
4703           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4704
4705     (let ((display (gnus-group-find-parameter group 'display)))
4706       (setq gnus-newsgroup-display
4707             (cond
4708              ((not (zerop (or (car-safe read-all) 0)))
4709               ;; The user entered the group with C-u SPC/RET, let's show
4710               ;; all articles.
4711               'gnus-not-ignore)
4712              ((eq display 'all)
4713               'gnus-not-ignore)
4714              ((arrayp display)
4715               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4716              ((numberp display)
4717               ;; The following is probably the "correct" solution, but
4718               ;; it makes Gnus fetch all headers and then limit the
4719               ;; articles (which is slow), so instead we hack the
4720               ;; select-articles parameter instead. -- Simon Josefsson
4721               ;; <jas@kth.se>
4722               ;;
4723               ;; (gnus-byte-compile
4724               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4725               ;;                         display)))))
4726               (setq select-articles
4727                     (gnus-uncompress-range
4728                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4729                              (if (> tmp 0)
4730                                  tmp
4731                                1))
4732                            (cdr (gnus-active group)))))
4733               nil)
4734              (t
4735               nil))))
4736
4737     (gnus-summary-setup-default-charset)
4738
4739     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4740     (when (gnus-virtual-group-p group)
4741       (setq cached gnus-newsgroup-cached))
4742
4743     (setq gnus-newsgroup-unreads
4744           (gnus-sorted-ndifference
4745            (gnus-sorted-ndifference gnus-newsgroup-unreads
4746                                     gnus-newsgroup-marked)
4747            gnus-newsgroup-dormant))
4748
4749     (setq gnus-newsgroup-processable nil)
4750
4751     (gnus-update-read-articles group gnus-newsgroup-unreads)
4752
4753     ;; Adjust and set lists of article marks.
4754     (when info
4755       (gnus-adjust-marked-articles info))
4756
4757     (if (setq articles select-articles)
4758         (setq gnus-newsgroup-unselected
4759               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4760       (setq articles (gnus-articles-to-read group read-all)))
4761
4762     (cond
4763      ((null articles)
4764       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4765       'quit)
4766      ((eq articles 0) nil)
4767      (t
4768       ;; Init the dependencies hash table.
4769       (setq gnus-newsgroup-dependencies
4770             (gnus-make-hashtable (length articles)))
4771       (gnus-set-global-variables)
4772       ;; Retrieve the headers and read them in.
4773       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4774
4775       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4776       (when cached
4777         (setq gnus-newsgroup-cached cached))
4778
4779       ;; Suppress duplicates?
4780       (when gnus-suppress-duplicates
4781         (gnus-dup-suppress-articles))
4782
4783       ;; Set the initial limit.
4784       (setq gnus-newsgroup-limit (copy-sequence articles))
4785       ;; Remove canceled articles from the list of unread articles.
4786       (setq fetched-articles
4787             (mapcar (lambda (headers) (mail-header-number headers))
4788                     gnus-newsgroup-headers))
4789       (setq gnus-newsgroup-articles fetched-articles)
4790       (setq gnus-newsgroup-unreads
4791             (gnus-sorted-nintersection
4792              gnus-newsgroup-unreads fetched-articles))
4793       (gnus-compute-unseen-list)
4794
4795       ;; Removed marked articles that do not exist.
4796       (gnus-update-missing-marks
4797        (gnus-sorted-difference articles fetched-articles))
4798       ;; We might want to build some more threads first.
4799       (when (and gnus-fetch-old-headers
4800                  (eq gnus-headers-retrieved-by 'nov))
4801         (if (eq gnus-fetch-old-headers 'invisible)
4802             (gnus-build-all-threads)
4803           (gnus-build-old-threads)))
4804       ;; Let the Gnus agent mark articles as read.
4805       (when gnus-agent
4806         (gnus-agent-get-undownloaded-list))
4807       ;; Remove list identifiers from subject
4808       (when gnus-list-identifiers
4809         (gnus-summary-remove-list-identifiers))
4810       ;; Check whether auto-expire is to be done in this group.
4811       (setq gnus-newsgroup-auto-expire
4812             (gnus-group-auto-expirable-p group))
4813       ;; Set up the article buffer now, if necessary.
4814       (unless gnus-single-article-buffer
4815         (gnus-article-setup-buffer))
4816       ;; First and last article in this newsgroup.
4817       (when gnus-newsgroup-headers
4818         (setq gnus-newsgroup-begin
4819               (mail-header-number (car gnus-newsgroup-headers))
4820               gnus-newsgroup-end
4821               (mail-header-number
4822                (gnus-last-element gnus-newsgroup-headers))))
4823       ;; GROUP is successfully selected.
4824       (or gnus-newsgroup-headers t)))))
4825
4826 (defun gnus-compute-unseen-list ()
4827   ;; The `seen' marks are treated specially.
4828   (if (not gnus-newsgroup-seen)
4829       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4830     (setq gnus-newsgroup-unseen
4831           (gnus-inverse-list-range-intersection
4832            gnus-newsgroup-articles gnus-newsgroup-seen))))
4833
4834 (defun gnus-summary-display-make-predicate (display)
4835   (require 'gnus-agent)
4836   (when (= (length display) 1)
4837     (setq display (car display)))
4838   (unless gnus-summary-display-cache
4839     (dolist (elem (append (list (cons 'read 'read)
4840                                 (cons 'unseen 'unseen))
4841                           gnus-article-mark-lists))
4842       (push (cons (cdr elem)
4843                   (gnus-byte-compile
4844                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4845             gnus-summary-display-cache)))
4846   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4847     (gnus-get-predicate display)))
4848
4849 ;; Uses the dynamically bound `number' variable.
4850 (defvar number)
4851 (defun gnus-article-marked-p (type &optional article)
4852   (let ((article (or article number)))
4853     (cond
4854      ((eq type 'tick)
4855       (memq article gnus-newsgroup-marked))
4856      ((eq type 'unsend)
4857       (memq article gnus-newsgroup-unsendable))
4858      ((eq type 'undownload)
4859       (memq article gnus-newsgroup-undownloaded))
4860      ((eq type 'download)
4861       (memq article gnus-newsgroup-downloadable))
4862      ((eq type 'unread)
4863       (memq article gnus-newsgroup-unreads))
4864      ((eq type 'read)
4865       (memq article gnus-newsgroup-reads))
4866      ((eq type 'dormant)
4867       (memq article gnus-newsgroup-dormant) )
4868      ((eq type 'expire)
4869       (memq article gnus-newsgroup-expirable))
4870      ((eq type 'reply)
4871       (memq article gnus-newsgroup-replied))
4872      ((eq type 'killed)
4873       (memq article gnus-newsgroup-killed))
4874      ((eq type 'bookmark)
4875       (assq article gnus-newsgroup-bookmarks))
4876      ((eq type 'score)
4877       (assq article gnus-newsgroup-scored))
4878      ((eq type 'save)
4879       (memq article gnus-newsgroup-saved))
4880      ((eq type 'cache)
4881       (memq article gnus-newsgroup-cached))
4882      ((eq type 'forward)
4883       (memq article gnus-newsgroup-forwarded))
4884      ((eq type 'seen)
4885       (not (memq article gnus-newsgroup-unseen)))
4886      ((eq type 'recent)
4887       (memq article gnus-newsgroup-recent))
4888      (t t))))
4889
4890 (defun gnus-articles-to-read (group &optional read-all)
4891   "Find out what articles the user wants to read."
4892   (let* ((articles
4893           ;; Select all articles if `read-all' is non-nil, or if there
4894           ;; are no unread articles.
4895           (if (or read-all
4896                   (and (zerop (length gnus-newsgroup-marked))
4897                        (zerop (length gnus-newsgroup-unreads)))
4898                   ;; Fetch all if the predicate is non-nil.
4899                   gnus-newsgroup-display)
4900               ;; We want to select the headers for all the articles in
4901               ;; the group, so we select either all the active
4902               ;; articles in the group, or (if that's nil), the
4903               ;; articles in the cache.
4904               (or
4905                (gnus-uncompress-range (gnus-active group))
4906                (gnus-cache-articles-in-group group))
4907             ;; Select only the "normal" subset of articles.
4908             (gnus-sorted-nunion
4909              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4910              gnus-newsgroup-unreads)))
4911          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4912          (scored (length scored-list))
4913          (number (length articles))
4914          (marked (+ (length gnus-newsgroup-marked)
4915                     (length gnus-newsgroup-dormant)))
4916          (select
4917           (cond
4918            ((numberp read-all)
4919             read-all)
4920            ((numberp gnus-newsgroup-display)
4921             gnus-newsgroup-display)
4922            (t
4923             (condition-case ()
4924                 (cond
4925                  ((and (or (<= scored marked) (= scored number))
4926                        (natnump gnus-large-newsgroup)
4927                        (> number gnus-large-newsgroup))
4928                   (let* ((cursor-in-echo-area nil)
4929                          (input
4930                           (read-from-minibuffer
4931                            (format
4932                             "How many articles from %s (max %d): "
4933                             (gnus-limit-string
4934                              (gnus-group-decoded-name gnus-newsgroup-name)
4935                              35)
4936                             number)
4937                            (cons (number-to-string gnus-large-newsgroup)
4938                                  0))))
4939                     (if (string-match "^[ \t]*$" input)
4940                         number
4941                       input)))
4942                  ((and (> scored marked) (< scored number)
4943                        (> (- scored number) 20))
4944                   (let ((input
4945                          (read-string
4946                           (format "%s %s (%d scored, %d total): "
4947                                   "How many articles from"
4948                                   (gnus-group-decoded-name group)
4949                                   scored number))))
4950                     (if (string-match "^[ \t]*$" input)
4951                         number input)))
4952                  (t number))
4953               (quit
4954                (message "Quit getting the articles to read")
4955                nil))))))
4956     (setq select (if (stringp select) (string-to-number select) select))
4957     (if (or (null select) (zerop select))
4958         select
4959       (if (and (not (zerop scored)) (<= (abs select) scored))
4960           (progn
4961             (setq articles (sort scored-list '<))
4962             (setq number (length articles)))
4963         (setq articles (copy-sequence articles)))
4964
4965       (when (< (abs select) number)
4966         (if (< select 0)
4967             ;; Select the N oldest articles.
4968             (setcdr (nthcdr (1- (abs select)) articles) nil)
4969           ;; Select the N most recent articles.
4970           (setq articles (nthcdr (- number select) articles))))
4971       (setq gnus-newsgroup-unselected
4972             (gnus-sorted-difference gnus-newsgroup-unreads articles))
4973       (when gnus-alter-articles-to-read-function
4974         (setq gnus-newsgroup-unreads
4975               (sort
4976                (funcall gnus-alter-articles-to-read-function
4977                         gnus-newsgroup-name gnus-newsgroup-unreads)
4978                '<)))
4979       articles)))
4980
4981 (defun gnus-killed-articles (killed articles)
4982   (let (out)
4983     (while articles
4984       (when (inline (gnus-member-of-range (car articles) killed))
4985         (push (car articles) out))
4986       (setq articles (cdr articles)))
4987     out))
4988
4989 (defun gnus-uncompress-marks (marks)
4990   "Uncompress the mark ranges in MARKS."
4991   (let ((uncompressed '(score bookmark))
4992         out)
4993     (while marks
4994       (if (memq (caar marks) uncompressed)
4995           (push (car marks) out)
4996         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4997       (setq marks (cdr marks)))
4998     out))
4999
5000 (defun gnus-article-mark-to-type (mark)
5001   "Return the type of MARK."
5002   (or (cadr (assq mark gnus-article-special-mark-lists))
5003       'list))
5004
5005 (defun gnus-article-unpropagatable-p (mark)
5006   "Return whether MARK should be propagated to backend."
5007   (memq mark gnus-article-unpropagated-mark-lists))
5008
5009 (defun gnus-adjust-marked-articles (info)
5010   "Set all article lists and remove all marks that are no longer valid."
5011   (let* ((marked-lists (gnus-info-marks info))
5012          (active (gnus-active (gnus-info-group info)))
5013          (min (car active))
5014          (max (cdr active))
5015          (types gnus-article-mark-lists)
5016          marks var articles article mark mark-type)
5017
5018     (dolist (marks marked-lists)
5019       (setq mark (car marks)
5020             mark-type (gnus-article-mark-to-type mark)
5021             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5022
5023       ;; We set the variable according to the type of the marks list,
5024       ;; and then adjust the marks to a subset of the active articles.
5025       (cond
5026        ;; Adjust "simple" lists.
5027        ((eq mark-type 'list)
5028         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5029         (when (memq mark '(tick dormant expire reply save))
5030           (while articles
5031             (when (or (< (setq article (pop articles)) min) (> article max))
5032               (set var (delq article (symbol-value var)))))))
5033        ;; Adjust assocs.
5034        ((eq mark-type 'tuple)
5035         (set var (setq articles (cdr marks)))
5036         (when (not (listp (cdr (symbol-value var))))
5037           (set var (list (symbol-value var))))
5038         (when (not (listp (cdr articles)))
5039           (setq articles (list articles)))
5040         (while articles
5041           (when (or (not (consp (setq article (pop articles))))
5042                     (< (car article) min)
5043                     (> (car article) max))
5044             (set var (delq article (symbol-value var))))))
5045        ;; Adjust ranges (sloppily).
5046        ((eq mark-type 'range)
5047         (cond
5048          ((eq mark 'seen)
5049           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5050           ;; It should be (seen (NUM1 . NUM2)).
5051           (when (numberp (cddr marks))
5052             (setcdr marks (list (cdr marks))))
5053           (setq articles (cdr marks))
5054           (while (and articles
5055                       (or (and (consp (car articles))
5056                                (> min (cdar articles)))
5057                           (and (numberp (car articles))
5058                                (> min (car articles)))))
5059             (pop articles))
5060           (set var articles))))))))
5061
5062 (defun gnus-update-missing-marks (missing)
5063   "Go through the list of MISSING articles and remove them from the mark lists."
5064   (when missing
5065     (let (var m)
5066       ;; Go through all types.
5067       (dolist (elem gnus-article-mark-lists)
5068         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5069           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5070           (when (symbol-value var)
5071             ;; This list has articles.  So we delete all missing
5072             ;; articles from it.
5073             (setq m missing)
5074             (while m
5075               (set var (delq (pop m) (symbol-value var))))))))))
5076
5077 (defun gnus-update-marks ()
5078   "Enter the various lists of marked articles into the newsgroup info list."
5079   (let ((types gnus-article-mark-lists)
5080         (info (gnus-get-info gnus-newsgroup-name))
5081         type list newmarked symbol delta-marks)
5082     (when info
5083       ;; Add all marks lists to the list of marks lists.
5084       (while (setq type (pop types))
5085         (setq list (symbol-value
5086                     (setq symbol
5087                           (intern (format "gnus-newsgroup-%s" (car type))))))
5088
5089         (when list
5090           ;; Get rid of the entries of the articles that have the
5091           ;; default score.
5092           (when (and (eq (cdr type) 'score)
5093                      gnus-save-score
5094                      list)
5095             (let* ((arts list)
5096                    (prev (cons nil list))
5097                    (all prev))
5098               (while arts
5099                 (if (or (not (consp (car arts)))
5100                         (= (cdar arts) gnus-summary-default-score))
5101                     (setcdr prev (cdr arts))
5102                   (setq prev arts))
5103                 (setq arts (cdr arts)))
5104               (setq list (cdr all)))))
5105
5106         (when (eq (cdr type) 'seen)
5107           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5108
5109         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5110           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5111
5112         (when (and (gnus-check-backend-function
5113                     'request-set-mark gnus-newsgroup-name)
5114                    (not (gnus-article-unpropagatable-p (cdr type))))
5115           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5116                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5117                  (add (gnus-remove-from-range
5118                        (gnus-copy-sequence list) old)))
5119             (when add
5120               (push (list add 'add (list (cdr type))) delta-marks))
5121             (when del
5122               (push (list del 'del (list (cdr type))) delta-marks))))
5123
5124         (when list
5125           (push (cons (cdr type) list) newmarked)))
5126
5127       (when delta-marks
5128         (unless (gnus-check-group gnus-newsgroup-name)
5129           (error "Can't open server for %s" gnus-newsgroup-name))
5130         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5131
5132       ;; Enter these new marks into the info of the group.
5133       (if (nthcdr 3 info)
5134           (setcar (nthcdr 3 info) newmarked)
5135         ;; Add the marks lists to the end of the info.
5136         (when newmarked
5137           (setcdr (nthcdr 2 info) (list newmarked))))
5138
5139       ;; Cut off the end of the info if there's nothing else there.
5140       (let ((i 5))
5141         (while (and (> i 2)
5142                     (not (nth i info)))
5143           (when (nthcdr (decf i) info)
5144             (setcdr (nthcdr i info) nil)))))))
5145
5146 (defun gnus-set-mode-line (where)
5147   "Set the mode line of the article or summary buffers.
5148 If WHERE is `summary', the summary mode line format will be used."
5149   ;; Is this mode line one we keep updated?
5150   (when (and (memq where gnus-updated-mode-lines)
5151              (symbol-value
5152               (intern (format "gnus-%s-mode-line-format-spec" where))))
5153     (let (mode-string)
5154       (save-excursion
5155         ;; We evaluate this in the summary buffer since these
5156         ;; variables are buffer-local to that buffer.
5157         (set-buffer gnus-summary-buffer)
5158         ;; We bind all these variables that are used in the `eval' form
5159         ;; below.
5160         (let* ((mformat (symbol-value
5161                          (intern
5162                           (format "gnus-%s-mode-line-format-spec" where))))
5163                (gnus-tmp-group-name (gnus-group-decoded-name
5164                                      gnus-newsgroup-name))
5165                (gnus-tmp-article-number (or gnus-current-article 0))
5166                (gnus-tmp-unread gnus-newsgroup-unreads)
5167                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5168                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5169                (gnus-tmp-unread-and-unselected
5170                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5171                             (zerop gnus-tmp-unselected))
5172                        "")
5173                       ((zerop gnus-tmp-unselected)
5174                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5175                       (t (format "{%d(+%d) more}"
5176                                  gnus-tmp-unread-and-unticked
5177                                  gnus-tmp-unselected))))
5178                (gnus-tmp-subject
5179                 (if (and gnus-current-headers
5180                          (vectorp gnus-current-headers))
5181                     (gnus-mode-string-quote
5182                      (mail-header-subject gnus-current-headers))
5183                   ""))
5184                bufname-length max-len
5185                gnus-tmp-header);; passed as argument to any user-format-funcs
5186           (setq mode-string (eval mformat))
5187           (setq bufname-length (if (string-match "%b" mode-string)
5188                                    (- (length
5189                                        (buffer-name
5190                                         (if (eq where 'summary)
5191                                             nil
5192                                           (get-buffer gnus-article-buffer))))
5193                                       2)
5194                                  0))
5195           (setq max-len (max 4 (if gnus-mode-non-string-length
5196                                    (- (window-width)
5197                                       gnus-mode-non-string-length
5198                                       bufname-length)
5199                                  (length mode-string))))
5200           ;; We might have to chop a bit of the string off...
5201           (when (> (length mode-string) max-len)
5202             (setq mode-string
5203                   (concat (gnus-truncate-string mode-string (- max-len 3))
5204                           "...")))
5205           ;; Pad the mode string a bit.
5206           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5207       ;; Update the mode line.
5208       (setq mode-line-buffer-identification
5209             (gnus-mode-line-buffer-identification (list mode-string)))
5210       (set-buffer-modified-p t))))
5211
5212 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5213   "Go through the HEADERS list and add all Xrefs to a hash table.
5214 The resulting hash table is returned, or nil if no Xrefs were found."
5215   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5216          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5217          (xref-hashtb (gnus-make-hashtable))
5218          start group entry number xrefs header)
5219     (while headers
5220       (setq header (pop headers))
5221       (when (and (setq xrefs (mail-header-xref header))
5222                  (not (memq (setq number (mail-header-number header))
5223                             unreads)))
5224         (setq start 0)
5225         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5226           (setq start (match-end 0))
5227           (setq group (if prefix
5228                           (concat prefix (substring xrefs (match-beginning 1)
5229                                                     (match-end 1)))
5230                         (substring xrefs (match-beginning 1) (match-end 1))))
5231           (setq number
5232                 (string-to-int (substring xrefs (match-beginning 2)
5233                                           (match-end 2))))
5234           (if (setq entry (gnus-gethash group xref-hashtb))
5235               (setcdr entry (cons number (cdr entry)))
5236             (gnus-sethash group (cons number nil) xref-hashtb)))))
5237     (and start xref-hashtb)))
5238
5239 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5240   "Look through all the headers and mark the Xrefs as read."
5241   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5242         name entry info xref-hashtb idlist method nth4)
5243     (save-excursion
5244       (set-buffer gnus-group-buffer)
5245       (when (setq xref-hashtb
5246                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5247         (mapatoms
5248          (lambda (group)
5249            (unless (string= from-newsgroup (setq name (symbol-name group)))
5250              (setq idlist (symbol-value group))
5251              ;; Dead groups are not updated.
5252              (and (prog1
5253                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5254                             info (nth 2 entry))
5255                     (when (stringp (setq nth4 (gnus-info-method info)))
5256                       (setq nth4 (gnus-server-to-method nth4))))
5257                   ;; Only do the xrefs if the group has the same
5258                   ;; select method as the group we have just read.
5259                   (or (gnus-methods-equal-p
5260                        nth4 (gnus-find-method-for-group from-newsgroup))
5261                       virtual
5262                       (equal nth4 (setq method (gnus-find-method-for-group
5263                                                 from-newsgroup)))
5264                       (and (equal (car nth4) (car method))
5265                            (equal (nth 1 nth4) (nth 1 method))))
5266                   gnus-use-cross-reference
5267                   (or (not (eq gnus-use-cross-reference t))
5268                       virtual
5269                       ;; Only do cross-references on subscribed
5270                       ;; groups, if that is what is wanted.
5271                       (<= (gnus-info-level info) gnus-level-subscribed))
5272                   (gnus-group-make-articles-read name idlist))))
5273          xref-hashtb)))))
5274
5275 (defun gnus-compute-read-articles (group articles)
5276   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5277          (info (nth 2 entry))
5278          (active (gnus-active group))
5279          ninfo)
5280     (when entry
5281       ;; First peel off all invalid article numbers.
5282       (when active
5283         (let ((ids articles)
5284               id first)
5285           (while (setq id (pop ids))
5286             (when (and first (> id (cdr active)))
5287               ;; We'll end up in this situation in one particular
5288               ;; obscure situation.  If you re-scan a group and get
5289               ;; a new article that is cross-posted to a different
5290               ;; group that has not been re-scanned, you might get
5291               ;; crossposted article that has a higher number than
5292               ;; Gnus believes possible.  So we re-activate this
5293               ;; group as well.  This might mean doing the
5294               ;; crossposting thingy will *increase* the number
5295               ;; of articles in some groups.  Tsk, tsk.
5296               (setq active (or (gnus-activate-group group) active)))
5297             (when (or (> id (cdr active))
5298                       (< id (car active)))
5299               (setq articles (delq id articles))))))
5300       ;; If the read list is nil, we init it.
5301       (if (and active
5302                (null (gnus-info-read info))
5303                (> (car active) 1))
5304           (setq ninfo (cons 1 (1- (car active))))
5305         (setq ninfo (gnus-info-read info)))
5306       ;; Then we add the read articles to the range.
5307       (gnus-add-to-range
5308        ninfo (setq articles (sort articles '<))))))
5309
5310 (defun gnus-group-make-articles-read (group articles)
5311   "Update the info of GROUP to say that ARTICLES are read."
5312   (let* ((num 0)
5313          (entry (gnus-gethash group gnus-newsrc-hashtb))
5314          (info (nth 2 entry))
5315          (active (gnus-active group))
5316          range)
5317     (when entry
5318       (setq range (gnus-compute-read-articles group articles))
5319       (save-excursion
5320         (set-buffer gnus-group-buffer)
5321         (gnus-undo-register
5322           `(progn
5323              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5324              (gnus-info-set-read ',info ',(gnus-info-read info))
5325              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5326              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5327              (gnus-group-update-group ,group t))))
5328       ;; Add the read articles to the range.
5329       (gnus-info-set-read info range)
5330       (gnus-request-set-mark group (list (list range 'add '(read))))
5331       ;; Then we have to re-compute how many unread
5332       ;; articles there are in this group.
5333       (when active
5334         (cond
5335          ((not range)
5336           (setq num (- (1+ (cdr active)) (car active))))
5337          ((not (listp (cdr range)))
5338           (setq num (- (cdr active) (- (1+ (cdr range))
5339                                        (car range)))))
5340          (t
5341           (while range
5342             (if (numberp (car range))
5343                 (setq num (1+ num))
5344               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5345             (setq range (cdr range)))
5346           (setq num (- (cdr active) num))))
5347         ;; Update the number of unread articles.
5348         (setcar entry num)
5349         ;; Update the group buffer.
5350         (gnus-group-update-group group t)))))
5351
5352 (defvar gnus-newsgroup-none-id 0)
5353
5354 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5355   (let ((cur nntp-server-buffer)
5356         (dependencies
5357          (or dependencies
5358              (save-excursion (set-buffer gnus-summary-buffer)
5359                              gnus-newsgroup-dependencies)))
5360         headers id end ref
5361         (mail-parse-charset gnus-newsgroup-charset)
5362         (mail-parse-ignored-charsets
5363          (save-excursion (condition-case nil
5364                              (set-buffer gnus-summary-buffer)
5365                            (error))
5366                          gnus-newsgroup-ignored-charsets)))
5367     (save-excursion
5368       (set-buffer nntp-server-buffer)
5369       ;; Translate all TAB characters into SPACE characters.
5370       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5371       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5372       (gnus-run-hooks 'gnus-parse-headers-hook)
5373       (let ((case-fold-search t)
5374             in-reply-to header p lines chars ctype)
5375         (goto-char (point-min))
5376         ;; Search to the beginning of the next header.  Error messages
5377         ;; do not begin with 2 or 3.
5378         (while (re-search-forward "^[23][0-9]+ " nil t)
5379           (setq id nil
5380                 ref nil)
5381           ;; This implementation of this function, with nine
5382           ;; search-forwards instead of the one re-search-forward and
5383           ;; a case (which basically was the old function) is actually
5384           ;; about twice as fast, even though it looks messier.  You
5385           ;; can't have everything, I guess.  Speed and elegance
5386           ;; doesn't always go hand in hand.
5387           (setq
5388            header
5389            (make-full-mail-header
5390             ;; Number.
5391             (prog1
5392                 (read cur)
5393               (end-of-line)
5394               (setq p (point))
5395               (narrow-to-region (point)
5396                                 (or (and (search-forward "\n.\n" nil t)
5397                                          (- (point) 2))
5398                                     (point))))
5399             ;; Subject.
5400             (progn
5401               (goto-char p)
5402               (if (search-forward "\nsubject:" nil t)
5403                   (nnheader-header-value)
5404                 "(none)"))
5405             ;; From.
5406             (progn
5407               (goto-char p)
5408               (if (search-forward "\nfrom:" nil t)
5409                   (nnheader-header-value)
5410                 "(nobody)"))
5411             ;; Date.
5412             (progn
5413               (goto-char p)
5414               (if (search-forward "\ndate:" nil t)
5415                   (nnheader-header-value) ""))
5416             ;; Message-ID.
5417             (progn
5418               (goto-char p)
5419               (setq id (if (re-search-forward
5420                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5421                            ;; We do it this way to make sure the Message-ID
5422                            ;; is (somewhat) syntactically valid.
5423                            (buffer-substring (match-beginning 1)
5424                                              (match-end 1))
5425                          ;; If there was no message-id, we just fake one
5426                          ;; to make subsequent routines simpler.
5427                          (nnheader-generate-fake-message-id))))
5428             ;; References.
5429             (progn
5430               (goto-char p)
5431               (if (search-forward "\nreferences:" nil t)
5432                   (progn
5433                     (setq end (point))
5434                     (prog1
5435                         (nnheader-header-value)
5436                       (setq ref
5437                             (buffer-substring
5438                              (progn
5439                                ;; (end-of-line)
5440                                (search-backward ">" end t)
5441                                (1+ (point)))
5442                              (progn
5443                                (search-backward "<" end t)
5444                                (point))))))
5445                 ;; Get the references from the in-reply-to header if there
5446                 ;; were no references and the in-reply-to header looks
5447                 ;; promising.
5448                 (if (and (search-forward "\nin-reply-to:" nil t)
5449                          (setq in-reply-to (nnheader-header-value))
5450                          (string-match "<[^>]+>" in-reply-to))
5451                     (let (ref2)
5452                       (setq ref (substring in-reply-to (match-beginning 0)
5453                                            (match-end 0)))
5454                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5455                         (setq ref2 (substring in-reply-to (match-beginning 0)
5456                                               (match-end 0)))
5457                         (when (> (length ref2) (length ref))
5458                           (setq ref ref2)))
5459                       ref)
5460                   (setq ref nil))))
5461             ;; Chars.
5462             (progn
5463               (goto-char p)
5464               (if (search-forward "\nchars: " nil t)
5465                   (if (numberp (setq chars (ignore-errors (read cur))))
5466                       chars -1)
5467                 -1))
5468             ;; Lines.
5469             (progn
5470               (goto-char p)
5471               (if (search-forward "\nlines: " nil t)
5472                   (if (numberp (setq lines (ignore-errors (read cur))))
5473                       lines -1)
5474                 -1))
5475             ;; Xref.
5476             (progn
5477               (goto-char p)
5478               (and (search-forward "\nxref:" nil t)
5479                    (nnheader-header-value)))
5480             ;; Extra.
5481             (when gnus-extra-headers
5482               (let ((extra gnus-extra-headers)
5483                     out)
5484                 (while extra
5485                   (goto-char p)
5486                   (when (search-forward
5487                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5488                     (push (cons (car extra) (nnheader-header-value)) out))
5489                   (pop extra))
5490                 out))))
5491           (goto-char p)
5492           (if (and (search-forward "\ncontent-type: " nil t)
5493                    (setq ctype (nnheader-header-value)))
5494               (mime-entity-set-content-type-internal
5495                header (mime-parse-Content-Type ctype)))
5496           (when (equal id ref)
5497             (setq ref nil))
5498
5499           (when gnus-alter-header-function
5500             (funcall gnus-alter-header-function header)
5501             (setq id (mail-header-id header)
5502                   ref (gnus-parent-id (mail-header-references header))))
5503
5504           (when (setq header
5505                       (gnus-dependencies-add-header
5506                        header dependencies force-new))
5507             (push header headers))
5508           (goto-char (point-max))
5509           (widen))
5510         (nreverse headers)))))
5511
5512 ;; Goes through the xover lines and returns a list of vectors
5513 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5514                                                   force-new dependencies
5515                                                   group also-fetch-heads)
5516   "Parse the news overview data in the server buffer.
5517 Return a list of headers that match SEQUENCE (see
5518 `nntp-retrieve-headers')."
5519   ;; Get the Xref when the users reads the articles since most/some
5520   ;; NNTP servers do not include Xrefs when using XOVER.
5521   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5522   (let ((mail-parse-charset gnus-newsgroup-charset)
5523         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5524         (cur nntp-server-buffer)
5525         (dependencies (or dependencies gnus-newsgroup-dependencies))
5526         (allp (cond
5527                ((eq gnus-read-all-available-headers t)
5528                 t)
5529                ((stringp gnus-read-all-available-headers)
5530                 (string-match gnus-read-all-available-headers group))
5531                (t
5532                 nil)))
5533         number headers header)
5534     (save-excursion
5535       (set-buffer nntp-server-buffer)
5536       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5537       ;; Allow the user to mangle the headers before parsing them.
5538       (gnus-run-hooks 'gnus-parse-headers-hook)
5539       (goto-char (point-min))
5540       (gnus-parse-without-error
5541         (while (and (or sequence allp)
5542                     (not (eobp)))
5543           (setq number (read cur))
5544           (when (not allp)
5545             (while (and sequence
5546                         (< (car sequence) number))
5547               (setq sequence (cdr sequence))))
5548           (when (and (or allp
5549                          (and sequence
5550                               (eq number (car sequence))))
5551                      (progn
5552                        (setq sequence (cdr sequence))
5553                        (setq header (inline
5554                                       (gnus-nov-parse-line
5555                                        number dependencies force-new)))))
5556             (push header headers))
5557           (forward-line 1)))
5558       ;; A common bug in inn is that if you have posted an article and
5559       ;; then retrieves the active file, it will answer correctly --
5560       ;; the new article is included.  However, a NOV entry for the
5561       ;; article may not have been generated yet, so this may fail.
5562       ;; We work around this problem by retrieving the last few
5563       ;; headers using HEAD.
5564       (if (or (not also-fetch-heads)
5565               (not sequence))
5566           ;; We (probably) got all the headers.
5567           (nreverse headers)
5568         (let ((gnus-nov-is-evil t))
5569           (nconc
5570            (nreverse headers)
5571            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5572              (gnus-get-newsgroup-headers))))))))
5573
5574 (defun gnus-article-get-xrefs ()
5575   "Fill in the Xref value in `gnus-current-headers', if necessary.
5576 This is meant to be called in `gnus-article-internal-prepare-hook'."
5577   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5578                                  gnus-current-headers)))
5579     (or (not gnus-use-cross-reference)
5580         (not headers)
5581         (and (mail-header-xref headers)
5582              (not (string= (mail-header-xref headers) "")))
5583         (let ((case-fold-search t)
5584               xref)
5585           (save-restriction
5586             (nnheader-narrow-to-headers)
5587             (goto-char (point-min))
5588             (when (or (and (not (eobp))
5589                            (eq (downcase (char-after)) ?x)
5590                            (looking-at "Xref:"))
5591                       (search-forward "\nXref:" nil t))
5592               (goto-char (1+ (match-end 0)))
5593               (setq xref (buffer-substring (point)
5594                                            (progn (end-of-line) (point))))
5595               (mail-header-set-xref headers xref)))))))
5596
5597 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5598   "Find article ID and insert the summary line for that article.
5599 OLD-HEADER can either be a header or a line number to insert
5600 the subject line on."
5601   (let* ((line (and (numberp old-header) old-header))
5602          (old-header (and (vectorp old-header) old-header))
5603          (header (cond ((and old-header use-old-header)
5604                         old-header)
5605                        ((and (numberp id)
5606                              (gnus-number-to-header id))
5607                         (gnus-number-to-header id))
5608                        (t
5609                         (gnus-read-header id))))
5610          (number (and (numberp id) id))
5611          d)
5612     (when header
5613       ;; Rebuild the thread that this article is part of and go to the
5614       ;; article we have fetched.
5615       (when (and (not gnus-show-threads)
5616                  old-header)
5617         (when (and number
5618                    (setq d (gnus-data-find (mail-header-number old-header))))
5619           (goto-char (gnus-data-pos d))
5620           (gnus-data-remove
5621            number
5622            (- (gnus-point-at-bol)
5623               (prog1
5624                   (1+ (gnus-point-at-eol))
5625                 (gnus-delete-line))))))
5626       (when old-header
5627         (mail-header-set-number header (mail-header-number old-header)))
5628       (setq gnus-newsgroup-sparse
5629             (delq (setq number (mail-header-number header))
5630                   gnus-newsgroup-sparse))
5631       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5632       (push number gnus-newsgroup-limit)
5633       (gnus-rebuild-thread (mail-header-id header) line)
5634       (gnus-summary-goto-subject number nil t))
5635     (when (and (numberp number)
5636                (> number 0))
5637       ;; We have to update the boundaries even if we can't fetch the
5638       ;; article if ID is a number -- so that the next `P' or `N'
5639       ;; command will fetch the previous (or next) article even
5640       ;; if the one we tried to fetch this time has been canceled.
5641       (when (> number gnus-newsgroup-end)
5642         (setq gnus-newsgroup-end number))
5643       (when (< number gnus-newsgroup-begin)
5644         (setq gnus-newsgroup-begin number))
5645       (setq gnus-newsgroup-unselected
5646             (delq number gnus-newsgroup-unselected)))
5647     ;; Report back a success?
5648     (and header (mail-header-number header))))
5649
5650 ;;; Process/prefix in the summary buffer
5651
5652 (defun gnus-summary-work-articles (n)
5653   "Return a list of articles to be worked upon.
5654 The prefix argument, the list of process marked articles, and the
5655 current article will be taken into consideration."
5656   (save-excursion
5657     (set-buffer gnus-summary-buffer)
5658     (cond
5659      (n
5660       ;; A numerical prefix has been given.
5661       (setq n (prefix-numeric-value n))
5662       (let ((backward (< n 0))
5663             (n (abs (prefix-numeric-value n)))
5664             articles article)
5665         (save-excursion
5666           (while
5667               (and (> n 0)
5668                    (push (setq article (gnus-summary-article-number))
5669                          articles)
5670                    (if backward
5671                        (gnus-summary-find-prev nil article)
5672                      (gnus-summary-find-next nil article)))
5673             (decf n)))
5674         (nreverse articles)))
5675      ((and (gnus-region-active-p) (mark))
5676       (message "region active")
5677       ;; Work on the region between point and mark.
5678       (let ((max (max (point) (mark)))
5679             articles article)
5680         (save-excursion
5681           (goto-char (min (point) (mark)))
5682           (while
5683               (and
5684                (push (setq article (gnus-summary-article-number)) articles)
5685                (gnus-summary-find-next nil article)
5686                (< (point) max)))
5687           (nreverse articles))))
5688      (gnus-newsgroup-processable
5689       ;; There are process-marked articles present.
5690       ;; Save current state.
5691       (gnus-summary-save-process-mark)
5692       ;; Return the list.
5693       (reverse gnus-newsgroup-processable))
5694      (t
5695       ;; Just return the current article.
5696       (list (gnus-summary-article-number))))))
5697
5698 (defmacro gnus-summary-iterate (arg &rest forms)
5699   "Iterate over the process/prefixed articles and do FORMS.
5700 ARG is the interactive prefix given to the command.  FORMS will be
5701 executed with point over the summary line of the articles."
5702   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5703     `(let ((,articles (gnus-summary-work-articles ,arg)))
5704        (while ,articles
5705          (gnus-summary-goto-subject (car ,articles))
5706          ,@forms
5707          (pop ,articles)))))
5708
5709 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5710 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5711
5712 (defun gnus-summary-save-process-mark ()
5713   "Push the current set of process marked articles on the stack."
5714   (interactive)
5715   (push (copy-sequence gnus-newsgroup-processable)
5716         gnus-newsgroup-process-stack))
5717
5718 (defun gnus-summary-kill-process-mark ()
5719   "Push the current set of process marked articles on the stack and unmark."
5720   (interactive)
5721   (gnus-summary-save-process-mark)
5722   (gnus-summary-unmark-all-processable))
5723
5724 (defun gnus-summary-yank-process-mark ()
5725   "Pop the last process mark state off the stack and restore it."
5726   (interactive)
5727   (unless gnus-newsgroup-process-stack
5728     (error "Empty mark stack"))
5729   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5730
5731 (defun gnus-summary-process-mark-set (set)
5732   "Make SET into the current process marked articles."
5733   (gnus-summary-unmark-all-processable)
5734   (while set
5735     (gnus-summary-set-process-mark (pop set))))
5736
5737 ;;; Searching and stuff
5738
5739 (defun gnus-summary-search-group (&optional backward use-level)
5740   "Search for next unread newsgroup.
5741 If optional argument BACKWARD is non-nil, search backward instead."
5742   (save-excursion
5743     (set-buffer gnus-group-buffer)
5744     (when (gnus-group-search-forward
5745            backward nil (if use-level (gnus-group-group-level) nil))
5746       (gnus-group-group-name))))
5747
5748 (defun gnus-summary-best-group (&optional exclude-group)
5749   "Find the name of the best unread group.
5750 If EXCLUDE-GROUP, do not go to this group."
5751   (save-excursion
5752     (set-buffer gnus-group-buffer)
5753     (save-excursion
5754       (gnus-group-best-unread-group exclude-group))))
5755
5756 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5757   (if backward (gnus-summary-find-prev)
5758     (let* ((dummy (gnus-summary-article-intangible-p))
5759            (article (or article (gnus-summary-article-number)))
5760            (arts (gnus-data-find-list article))
5761            result)
5762       (when (and (not dummy)
5763                  (or (not gnus-summary-check-current)
5764                      (not unread)
5765                      (not (gnus-data-unread-p (car arts)))))
5766         (setq arts (cdr arts)))
5767       (when (setq result
5768                   (if unread
5769                       (progn
5770                         (while arts
5771                           (when (or (and undownloaded
5772                                          (eq gnus-undownloaded-mark
5773                                              (gnus-data-mark (car arts))))
5774                                     (gnus-data-unread-p (car arts)))
5775                             (setq result (car arts)
5776                                   arts nil))
5777                           (setq arts (cdr arts)))
5778                         result)
5779                     (car arts)))
5780         (goto-char (gnus-data-pos result))
5781         (gnus-data-number result)))))
5782
5783 (defun gnus-summary-find-prev (&optional unread article)
5784   (let* ((eobp (eobp))
5785          (article (or article (gnus-summary-article-number)))
5786          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5787          result)
5788     (when (and (not eobp)
5789                (or (not gnus-summary-check-current)
5790                    (not unread)
5791                    (not (gnus-data-unread-p (car arts)))))
5792       (setq arts (cdr arts)))
5793     (when (setq result
5794                 (if unread
5795                     (progn
5796                       (while arts
5797                         (when (gnus-data-unread-p (car arts))
5798                           (setq result (car arts)
5799                                 arts nil))
5800                         (setq arts (cdr arts)))
5801                       result)
5802                   (car arts)))
5803       (goto-char (gnus-data-pos result))
5804       (gnus-data-number result))))
5805
5806 (defun gnus-summary-find-subject (subject &optional unread backward article)
5807   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5808          (article (or article (gnus-summary-article-number)))
5809          (articles (gnus-data-list backward))
5810          (arts (gnus-data-find-list article articles))
5811          result)
5812     (when (or (not gnus-summary-check-current)
5813               (not unread)
5814               (not (gnus-data-unread-p (car arts))))
5815       (setq arts (cdr arts)))
5816     (while arts
5817       (and (or (not unread)
5818                (gnus-data-unread-p (car arts)))
5819            (vectorp (gnus-data-header (car arts)))
5820            (gnus-subject-equal
5821             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5822            (setq result (car arts)
5823                  arts nil))
5824       (setq arts (cdr arts)))
5825     (and result
5826          (goto-char (gnus-data-pos result))
5827          (gnus-data-number result))))
5828
5829 (defun gnus-summary-search-forward (&optional unread subject backward)
5830   "Search forward for an article.
5831 If UNREAD, look for unread articles.  If SUBJECT, look for
5832 articles with that subject.  If BACKWARD, search backward instead."
5833   (cond (subject (gnus-summary-find-subject subject unread backward))
5834         (backward (gnus-summary-find-prev unread))
5835         (t (gnus-summary-find-next unread))))
5836
5837 (defun gnus-recenter (&optional n)
5838   "Center point in window and redisplay frame.
5839 Also do horizontal recentering."
5840   (interactive "P")
5841   (when (and gnus-auto-center-summary
5842              (not (eq gnus-auto-center-summary 'vertical)))
5843     (gnus-horizontal-recenter))
5844   (recenter n))
5845
5846 (defun gnus-summary-recenter ()
5847   "Center point in the summary window.
5848 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5849 displayed, no centering will be performed."
5850   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5851   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5852   (interactive)
5853   (let* ((top (cond ((< (window-height) 4) 0)
5854                     ((< (window-height) 7) 1)
5855                     (t (if (numberp gnus-auto-center-summary)
5856                            gnus-auto-center-summary
5857                          2))))
5858          (height (1- (window-height)))
5859          (bottom (save-excursion (goto-char (point-max))
5860                                  (forward-line (- height))
5861                                  (point)))
5862          (window (get-buffer-window (current-buffer))))
5863     ;; The user has to want it.
5864     (when gnus-auto-center-summary
5865       (when (get-buffer-window gnus-article-buffer)
5866         ;; Only do recentering when the article buffer is displayed,
5867         ;; Set the window start to either `bottom', which is the biggest
5868         ;; possible valid number, or the second line from the top,
5869         ;; whichever is the least.
5870         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5871           (if (> bottom top-pos)
5872               ;; Keep the second line from the top visible
5873               (set-window-start window top-pos t)
5874             ;; Try to keep the bottom line visible; if it's partially
5875             ;; obscured, either scroll one more line to make it fully
5876             ;; visible, or revert to using TOP-POS.
5877             (save-excursion
5878               (goto-char (point-max))
5879               (forward-line -1)
5880               (let ((last-line-start (point)))
5881                 (goto-char bottom)
5882                 (set-window-start window (point) t)
5883                 (when (not (pos-visible-in-window-p last-line-start window))
5884                   (forward-line 1)
5885                   (set-window-start window (min (point) top-pos) t)))))))
5886       ;; Do horizontal recentering while we're at it.
5887       (when (and (get-buffer-window (current-buffer) t)
5888                  (not (eq gnus-auto-center-summary 'vertical)))
5889         (let ((selected (selected-window)))
5890           (select-window (get-buffer-window (current-buffer) t))
5891           (gnus-summary-position-point)
5892           (gnus-horizontal-recenter)
5893           (select-window selected))))))
5894
5895 (defun gnus-summary-jump-to-group (newsgroup)
5896   "Move point to NEWSGROUP in group mode buffer."
5897   ;; Keep update point of group mode buffer if visible.
5898   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5899       (save-window-excursion
5900         ;; Take care of tree window mode.
5901         (when (get-buffer-window gnus-group-buffer)
5902           (pop-to-buffer gnus-group-buffer))
5903         (gnus-group-jump-to-group newsgroup))
5904     (save-excursion
5905       ;; Take care of tree window mode.
5906       (if (get-buffer-window gnus-group-buffer)
5907           (pop-to-buffer gnus-group-buffer)
5908         (set-buffer gnus-group-buffer))
5909       (gnus-group-jump-to-group newsgroup))))
5910
5911 ;; This function returns a list of article numbers based on the
5912 ;; difference between the ranges of read articles in this group and
5913 ;; the range of active articles.
5914 (defun gnus-list-of-unread-articles (group)
5915   (let* ((read (gnus-info-read (gnus-get-info group)))
5916          (active (or (gnus-active group) (gnus-activate-group group)))
5917          (last (cdr active))
5918          first nlast unread)
5919     ;; If none are read, then all are unread.
5920     (if (not read)
5921         (setq first (car active))
5922       ;; If the range of read articles is a single range, then the
5923       ;; first unread article is the article after the last read
5924       ;; article.  Sounds logical, doesn't it?
5925       (if (and (not (listp (cdr read)))
5926                (or (< (car read) (car active))
5927                    (progn (setq read (list read))
5928                           nil)))
5929           (setq first (max (car active) (1+ (cdr read))))
5930         ;; `read' is a list of ranges.
5931         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5932                                   (caar read)))
5933                   1)
5934           (setq first (car active)))
5935         (while read
5936           (when first
5937             (while (< first nlast)
5938               (push first unread)
5939               (setq first (1+ first))))
5940           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5941           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5942           (setq read (cdr read)))))
5943     ;; And add the last unread articles.
5944     (while (<= first last)
5945       (push first unread)
5946       (setq first (1+ first)))
5947     ;; Return the list of unread articles.
5948     (delq 0 (nreverse unread))))
5949
5950 (defun gnus-list-of-read-articles (group)
5951   "Return a list of unread, unticked and non-dormant articles."
5952   (let* ((info (gnus-get-info group))
5953          (marked (gnus-info-marks info))
5954          (active (gnus-active group)))
5955     (and info active
5956          (gnus-list-range-difference
5957           (gnus-list-range-difference
5958            (gnus-sorted-complement
5959             (gnus-uncompress-range active)
5960             (gnus-list-of-unread-articles group))
5961            (cdr (assq 'dormant marked)))
5962           (cdr (assq 'tick marked))))))
5963
5964 ;; Various summary commands
5965
5966 (defun gnus-summary-select-article-buffer ()
5967   "Reconfigure windows to show article buffer."
5968   (interactive)
5969   (if (not (gnus-buffer-live-p gnus-article-buffer))
5970       (error "There is no article buffer for this summary buffer")
5971     (gnus-configure-windows 'article)
5972     (select-window (get-buffer-window gnus-article-buffer))))
5973
5974 (defun gnus-summary-universal-argument (arg)
5975   "Perform any operation on all articles that are process/prefixed."
5976   (interactive "P")
5977   (let ((articles (gnus-summary-work-articles arg))
5978         func article)
5979     (if (eq
5980          (setq
5981           func
5982           (key-binding
5983            (read-key-sequence
5984             (substitute-command-keys
5985              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5986          'undefined)
5987         (gnus-error 1 "Undefined key")
5988       (save-excursion
5989         (while articles
5990           (gnus-summary-goto-subject (setq article (pop articles)))
5991           (let (gnus-newsgroup-processable)
5992             (command-execute func))
5993           (gnus-summary-remove-process-mark article)))))
5994   (gnus-summary-position-point))
5995
5996 (defun gnus-summary-toggle-truncation (&optional arg)
5997   "Toggle truncation of summary lines.
5998 With arg, turn line truncation on iff arg is positive."
5999   (interactive "P")
6000   (setq truncate-lines
6001         (if (null arg) (not truncate-lines)
6002           (> (prefix-numeric-value arg) 0)))
6003   (redraw-display))
6004
6005 (defun gnus-summary-reselect-current-group (&optional all rescan)
6006   "Exit and then reselect the current newsgroup.
6007 The prefix argument ALL means to select all articles."
6008   (interactive "P")
6009   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6010     (error "Ephemeral groups can't be reselected"))
6011   (let ((current-subject (gnus-summary-article-number))
6012         (group gnus-newsgroup-name))
6013     (setq gnus-newsgroup-begin nil)
6014     (gnus-summary-exit)
6015     ;; We have to adjust the point of group mode buffer because
6016     ;; point was moved to the next unread newsgroup by exiting.
6017     (gnus-summary-jump-to-group group)
6018     (when rescan
6019       (save-excursion
6020         (save-window-excursion
6021           ;; Don't show group contents.
6022           (set-window-start (selected-window) (point-max))
6023           (gnus-group-get-new-news-this-group 1))))
6024     (gnus-group-read-group all t)
6025     (gnus-summary-goto-subject current-subject nil t)))
6026
6027 (defun gnus-summary-rescan-group (&optional all)
6028   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6029   (interactive "P")
6030   (gnus-summary-reselect-current-group all t))
6031
6032 (defun gnus-summary-update-info (&optional non-destructive)
6033   (save-excursion
6034     (let ((group gnus-newsgroup-name))
6035       (when group
6036         (when gnus-newsgroup-kill-headers
6037           (setq gnus-newsgroup-killed
6038                 (gnus-compress-sequence
6039                  (gnus-sorted-union
6040                   (gnus-list-range-intersection
6041                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6042                   gnus-newsgroup-unreads)
6043                  t)))
6044         (unless (listp (cdr gnus-newsgroup-killed))
6045           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6046         (let ((headers gnus-newsgroup-headers))
6047           ;; Set the new ranges of read articles.
6048           (save-excursion
6049             (set-buffer gnus-group-buffer)
6050             (gnus-undo-force-boundary))
6051           (gnus-update-read-articles
6052            group (gnus-sorted-union
6053                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6054           ;; Set the current article marks.
6055           (let ((gnus-newsgroup-scored
6056                  (if (and (not gnus-save-score)
6057                           (not non-destructive))
6058                      nil
6059                    gnus-newsgroup-scored)))
6060             (save-excursion
6061               (gnus-update-marks)))
6062           ;; Do the cross-ref thing.
6063           (when gnus-use-cross-reference
6064             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6065           ;; Do not switch windows but change the buffer to work.
6066           (set-buffer gnus-group-buffer)
6067           (unless (gnus-ephemeral-group-p group)
6068             (gnus-group-update-group group)))))))
6069
6070 (defun gnus-summary-save-newsrc (&optional force)
6071   "Save the current number of read/marked articles in the dribble buffer.
6072 The dribble buffer will then be saved.
6073 If FORCE (the prefix), also save the .newsrc file(s)."
6074   (interactive "P")
6075   (gnus-summary-update-info t)
6076   (if force
6077       (gnus-save-newsrc-file)
6078     (gnus-dribble-save)))
6079
6080 (defun gnus-summary-exit (&optional temporary)
6081   "Exit reading current newsgroup, and then return to group selection mode.
6082 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6083   (interactive)
6084   (gnus-set-global-variables)
6085   (gnus-kill-save-kill-buffer)
6086   (gnus-async-halt-prefetch)
6087   (let* ((group gnus-newsgroup-name)
6088          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6089          (mode major-mode)
6090          (group-point nil)
6091          (buf (current-buffer)))
6092     (unless quit-config
6093       ;; Do adaptive scoring, and possibly save score files.
6094       (when gnus-newsgroup-adaptive
6095         (gnus-score-adaptive))
6096       (when gnus-use-scoring
6097         (gnus-score-save)))
6098     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6099     ;; If we have several article buffers, we kill them at exit.
6100     (unless gnus-single-article-buffer
6101       (gnus-kill-buffer gnus-original-article-buffer)
6102       (setq gnus-article-current nil))
6103     (when gnus-use-cache
6104       (gnus-cache-possibly-remove-articles)
6105       (gnus-cache-save-buffers))
6106     (gnus-async-prefetch-remove-group group)
6107     (when gnus-suppress-duplicates
6108       (gnus-dup-enter-articles))
6109     (when gnus-use-trees
6110       (gnus-tree-close group))
6111     (when gnus-use-cache
6112       (gnus-cache-write-active))
6113     ;; Remove entries for this group.
6114     (nnmail-purge-split-history (gnus-group-real-name group))
6115     ;; Make all changes in this group permanent.
6116     (unless quit-config
6117       (gnus-run-hooks 'gnus-exit-group-hook)
6118       (gnus-summary-update-info))
6119     (gnus-close-group group)
6120     ;; Make sure where we were, and go to next newsgroup.
6121     (set-buffer gnus-group-buffer)
6122     (unless quit-config
6123       (gnus-group-jump-to-group group))
6124     (gnus-run-hooks 'gnus-summary-exit-hook)
6125     (unless (or quit-config
6126                 ;; If this group has disappeared from the summary
6127                 ;; buffer, don't skip forwards.
6128                 (not (string= group (gnus-group-group-name))))
6129       (gnus-group-next-unread-group 1))
6130     (setq group-point (point))
6131     (if temporary
6132         nil                             ;Nothing to do.
6133       ;; If we have several article buffers, we kill them at exit.
6134       (unless gnus-single-article-buffer
6135         (gnus-kill-buffer gnus-article-buffer)
6136         (gnus-kill-buffer gnus-original-article-buffer)
6137         (setq gnus-article-current nil))
6138       (set-buffer buf)
6139       (if (not gnus-kill-summary-on-exit)
6140           (progn
6141             (gnus-deaden-summary)
6142             (setq mode nil))
6143         ;; We set all buffer-local variables to nil.  It is unclear why
6144         ;; this is needed, but if we don't, buffer-local variables are
6145         ;; not garbage-collected, it seems.  This would the lead to en
6146         ;; ever-growing Emacs.
6147         (gnus-summary-clear-local-variables)
6148         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6149           (gnus-summary-clear-local-variables))
6150         (when (get-buffer gnus-article-buffer)
6151           (bury-buffer gnus-article-buffer))
6152         ;; We clear the global counterparts of the buffer-local
6153         ;; variables as well, just to be on the safe side.
6154         (set-buffer gnus-group-buffer)
6155         (gnus-summary-clear-local-variables)
6156         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6157           (gnus-summary-clear-local-variables)))
6158       (setq gnus-current-select-method gnus-select-method)
6159       (pop-to-buffer gnus-group-buffer)
6160       (if (not quit-config)
6161           (progn
6162             (goto-char group-point)
6163             (gnus-configure-windows 'group 'force)
6164             (unless (pos-visible-in-window-p)
6165               (forward-line (/ (static-if (featurep 'xemacs)
6166                                    (window-displayed-height)
6167                                  (1- (window-height)))
6168                                -2))
6169               (set-window-start (selected-window) (point))
6170               (goto-char group-point)))
6171         (gnus-handle-ephemeral-exit quit-config))
6172       ;; Return to group mode buffer.
6173       (when (eq mode 'gnus-summary-mode)
6174         (gnus-kill-buffer buf))
6175       ;; Clear the current group name.
6176       (unless quit-config
6177         (setq gnus-newsgroup-name nil)))))
6178
6179 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6180 (defun gnus-summary-exit-no-update (&optional no-questions)
6181   "Quit reading current newsgroup without updating read article info."
6182   (interactive)
6183   (let* ((group gnus-newsgroup-name)
6184          (quit-config (gnus-group-quit-config group)))
6185     (when (or no-questions
6186               gnus-expert-user
6187               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6188       (gnus-async-halt-prefetch)
6189       (mapcar 'funcall
6190               (delq 'gnus-summary-expire-articles
6191                     (copy-sequence gnus-summary-prepare-exit-hook)))
6192       ;; If we have several article buffers, we kill them at exit.
6193       (unless gnus-single-article-buffer
6194         (gnus-kill-buffer gnus-article-buffer)
6195         (gnus-kill-buffer gnus-original-article-buffer)
6196         (setq gnus-article-current nil))
6197       (if (not gnus-kill-summary-on-exit)
6198           (gnus-deaden-summary)
6199         (gnus-close-group group)
6200         (gnus-summary-clear-local-variables)
6201         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6202           (gnus-summary-clear-local-variables))
6203         (set-buffer gnus-group-buffer)
6204         (gnus-summary-clear-local-variables)
6205         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6206           (gnus-summary-clear-local-variables))
6207         (when (get-buffer gnus-summary-buffer)
6208           (kill-buffer gnus-summary-buffer)))
6209       (unless gnus-single-article-buffer
6210         (setq gnus-article-current nil))
6211       (when gnus-use-trees
6212         (gnus-tree-close group))
6213       (gnus-async-prefetch-remove-group group)
6214       (when (get-buffer gnus-article-buffer)
6215         (bury-buffer gnus-article-buffer))
6216       ;; Return to the group buffer.
6217       (gnus-configure-windows 'group 'force)
6218       ;; Clear the current group name.
6219       (setq gnus-newsgroup-name nil)
6220       (when (equal (gnus-group-group-name) group)
6221         (gnus-group-next-unread-group 1))
6222       (when quit-config
6223         (gnus-handle-ephemeral-exit quit-config)))))
6224
6225 (defun gnus-handle-ephemeral-exit (quit-config)
6226   "Handle movement when leaving an ephemeral group.
6227 The state which existed when entering the ephemeral is reset."
6228   (if (not (buffer-name (car quit-config)))
6229       (gnus-configure-windows 'group 'force)
6230     (set-buffer (car quit-config))
6231     (cond ((eq major-mode 'gnus-summary-mode)
6232            (gnus-set-global-variables))
6233           ((eq major-mode 'gnus-article-mode)
6234            (save-excursion
6235              ;; The `gnus-summary-buffer' variable may point
6236              ;; to the old summary buffer when using a single
6237              ;; article buffer.
6238              (unless (gnus-buffer-live-p gnus-summary-buffer)
6239                (set-buffer gnus-group-buffer))
6240              (set-buffer gnus-summary-buffer)
6241              (gnus-set-global-variables))))
6242     (if (or (eq (cdr quit-config) 'article)
6243             (eq (cdr quit-config) 'pick))
6244         (progn
6245           ;; The current article may be from the ephemeral group
6246           ;; thus it is best that we reload this article
6247           (gnus-summary-show-article)
6248           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6249               (gnus-configure-windows 'pick 'force)
6250             (gnus-configure-windows (cdr quit-config) 'force)))
6251       (gnus-configure-windows (cdr quit-config) 'force))
6252     (when (eq major-mode 'gnus-summary-mode)
6253       (gnus-summary-next-subject 1 nil t)
6254       (gnus-summary-recenter)
6255       (gnus-summary-position-point))))
6256
6257 (defun gnus-summary-preview-mime-message ()
6258   "MIME decode and play this message."
6259   (interactive)
6260   (let ((gnus-break-pages nil)
6261         (gnus-show-mime t))
6262     (gnus-summary-select-article gnus-show-all-headers t))
6263   (let ((w (get-buffer-window gnus-article-buffer)))
6264     (when w
6265       (select-window (get-buffer-window gnus-article-buffer)))))
6266
6267 ;;; Dead summaries.
6268
6269 (defvar gnus-dead-summary-mode-map nil)
6270
6271 (unless gnus-dead-summary-mode-map
6272   (setq gnus-dead-summary-mode-map (make-keymap))
6273   (suppress-keymap gnus-dead-summary-mode-map)
6274   (substitute-key-definition
6275    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6276   (dolist (key '("\C-d" "\r" "\177" [delete]))
6277     (define-key gnus-dead-summary-mode-map
6278       key 'gnus-summary-wake-up-the-dead))
6279   (dolist (key '("q" "Q"))
6280     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6281
6282 (defvar gnus-dead-summary-mode nil
6283   "Minor mode for Gnus summary buffers.")
6284
6285 (defun gnus-dead-summary-mode (&optional arg)
6286   "Minor mode for Gnus summary buffers."
6287   (interactive "P")
6288   (when (eq major-mode 'gnus-summary-mode)
6289     (make-local-variable 'gnus-dead-summary-mode)
6290     (setq gnus-dead-summary-mode
6291           (if (null arg) (not gnus-dead-summary-mode)
6292             (> (prefix-numeric-value arg) 0)))
6293     (when gnus-dead-summary-mode
6294       (gnus-add-minor-mode
6295        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6296
6297 (defun gnus-deaden-summary ()
6298   "Make the current summary buffer into a dead summary buffer."
6299   ;; Kill any previous dead summary buffer.
6300   (when (and gnus-dead-summary
6301              (buffer-name gnus-dead-summary))
6302     (save-excursion
6303       (set-buffer gnus-dead-summary)
6304       (when gnus-dead-summary-mode
6305         (kill-buffer (current-buffer)))))
6306   ;; Make this the current dead summary.
6307   (setq gnus-dead-summary (current-buffer))
6308   (gnus-dead-summary-mode 1)
6309   (let ((name (buffer-name)))
6310     (when (string-match "Summary" name)
6311       (rename-buffer
6312        (concat (substring name 0 (match-beginning 0)) "Dead "
6313                (substring name (match-beginning 0)))
6314        t)
6315       (bury-buffer))))
6316
6317 (defun gnus-kill-or-deaden-summary (buffer)
6318   "Kill or deaden the summary BUFFER."
6319   (save-excursion
6320     (when (and (buffer-name buffer)
6321                (not gnus-single-article-buffer))
6322       (save-excursion
6323         (set-buffer buffer)
6324         (gnus-kill-buffer gnus-article-buffer)
6325         (gnus-kill-buffer gnus-original-article-buffer)))
6326     (cond
6327      ;; Kill the buffer.
6328      (gnus-kill-summary-on-exit
6329       (when (and gnus-use-trees
6330                  (gnus-buffer-exists-p buffer))
6331         (save-excursion
6332           (set-buffer buffer)
6333           (gnus-tree-close gnus-newsgroup-name)))
6334       (gnus-kill-buffer buffer))
6335      ;; Deaden the buffer.
6336      ((gnus-buffer-exists-p buffer)
6337       (save-excursion
6338         (set-buffer buffer)
6339         (gnus-deaden-summary))))))
6340
6341 (defun gnus-summary-wake-up-the-dead (&rest args)
6342   "Wake up the dead summary buffer."
6343   (interactive)
6344   (gnus-dead-summary-mode -1)
6345   (let ((name (buffer-name)))
6346     (when (string-match "Dead " name)
6347       (rename-buffer
6348        (concat (substring name 0 (match-beginning 0))
6349                (substring name (match-end 0)))
6350        t)))
6351   (gnus-message 3 "This dead summary is now alive again"))
6352
6353 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6354 (defun gnus-summary-fetch-faq (&optional faq-dir)
6355   "Fetch the FAQ for the current group.
6356 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6357 in."
6358   (interactive
6359    (list
6360     (when current-prefix-arg
6361       (completing-read
6362        "Faq dir: " (and (listp gnus-group-faq-directory)
6363                         (mapcar (lambda (file) (list file))
6364                                 gnus-group-faq-directory))))))
6365   (let (gnus-faq-buffer)
6366     (when (setq gnus-faq-buffer
6367                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6368       (gnus-configure-windows 'summary-faq))))
6369
6370 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6371 (defun gnus-summary-describe-group (&optional force)
6372   "Describe the current newsgroup."
6373   (interactive "P")
6374   (gnus-group-describe-group force gnus-newsgroup-name))
6375
6376 (defun gnus-summary-describe-briefly ()
6377   "Describe summary mode commands briefly."
6378   (interactive)
6379   (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")))
6380
6381 ;; Walking around group mode buffer from summary mode.
6382
6383 (defun gnus-summary-next-group (&optional no-article target-group backward)
6384   "Exit current newsgroup and then select next unread newsgroup.
6385 If prefix argument NO-ARTICLE is non-nil, no article is selected
6386 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6387 previous group instead."
6388   (interactive "P")
6389   ;; Stop pre-fetching.
6390   (gnus-async-halt-prefetch)
6391   (let ((current-group gnus-newsgroup-name)
6392         (current-buffer (current-buffer))
6393         entered)
6394     ;; First we semi-exit this group to update Xrefs and all variables.
6395     ;; We can't do a real exit, because the window conf must remain
6396     ;; the same in case the user is prompted for info, and we don't
6397     ;; want the window conf to change before that...
6398     (gnus-summary-exit t)
6399     (while (not entered)
6400       ;; Then we find what group we are supposed to enter.
6401       (set-buffer gnus-group-buffer)
6402       (gnus-group-jump-to-group current-group)
6403       (setq target-group
6404             (or target-group
6405                 (if (eq gnus-keep-same-level 'best)
6406                     (gnus-summary-best-group gnus-newsgroup-name)
6407                   (gnus-summary-search-group backward gnus-keep-same-level))))
6408       (if (not target-group)
6409           ;; There are no further groups, so we return to the group
6410           ;; buffer.
6411           (progn
6412             (gnus-message 5 "Returning to the group buffer")
6413             (setq entered t)
6414             (when (gnus-buffer-live-p current-buffer)
6415               (set-buffer current-buffer)
6416               (gnus-summary-exit))
6417             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6418         ;; We try to enter the target group.
6419         (gnus-group-jump-to-group target-group)
6420         (let ((unreads (gnus-group-group-unread)))
6421           (if (and (or (eq t unreads)
6422                        (and unreads (not (zerop unreads))))
6423                    (gnus-summary-read-group
6424                     target-group nil no-article
6425                     (and (buffer-name current-buffer) current-buffer)
6426                     nil backward))
6427               (setq entered t)
6428             (setq current-group target-group
6429                   target-group nil)))))))
6430
6431 (defun gnus-summary-prev-group (&optional no-article)
6432   "Exit current newsgroup and then select previous unread newsgroup.
6433 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6434   (interactive "P")
6435   (gnus-summary-next-group no-article nil t))
6436
6437 ;; Walking around summary lines.
6438
6439 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6440   "Go to the first unread subject.
6441 If UNREAD is non-nil, go to the first unread article.
6442 Returns the article selected or nil if there are no unread articles."
6443   (interactive "P")
6444   (prog1
6445       (cond
6446        ;; Empty summary.
6447        ((null gnus-newsgroup-data)
6448         (gnus-message 3 "No articles in the group")
6449         nil)
6450        ;; Pick the first article.
6451        ((not unread)
6452         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6453         (gnus-data-number (car gnus-newsgroup-data)))
6454        ;; No unread articles.
6455        ((null gnus-newsgroup-unreads)
6456         (gnus-message 3 "No more unread articles")
6457         nil)
6458        ;; Find the first unread article.
6459        (t
6460         (let ((data gnus-newsgroup-data))
6461           (while (and data
6462                       (and (not (and undownloaded
6463                                      (eq gnus-undownloaded-mark
6464                                          (gnus-data-mark (car data)))))
6465                            (if unseen
6466                                (or (not (memq
6467                                          (gnus-data-number (car data))
6468                                          gnus-newsgroup-unseen))
6469                                    (not (gnus-data-unread-p (car data))))
6470                              (not (gnus-data-unread-p (car data))))))
6471             (setq data (cdr data)))
6472           (when data
6473             (goto-char (gnus-data-pos (car data)))
6474             (gnus-data-number (car data))))))
6475     (gnus-summary-position-point)))
6476
6477 (defun gnus-summary-next-subject (n &optional unread dont-display)
6478   "Go to next N'th summary line.
6479 If N is negative, go to the previous N'th subject line.
6480 If UNREAD is non-nil, only unread articles are selected.
6481 The difference between N and the actual number of steps taken is
6482 returned."
6483   (interactive "p")
6484   (let ((backward (< n 0))
6485         (n (abs n)))
6486     (while (and (> n 0)
6487                 (if backward
6488                     (gnus-summary-find-prev unread)
6489                   (gnus-summary-find-next unread)))
6490       (unless (zerop (setq n (1- n)))
6491         (gnus-summary-show-thread)))
6492     (when (/= 0 n)
6493       (gnus-message 7 "No more%s articles"
6494                     (if unread " unread" "")))
6495     (unless dont-display
6496       (gnus-summary-recenter)
6497       (gnus-summary-position-point))
6498     n))
6499
6500 (defun gnus-summary-next-unread-subject (n)
6501   "Go to next N'th unread summary line."
6502   (interactive "p")
6503   (gnus-summary-next-subject n t))
6504
6505 (defun gnus-summary-prev-subject (n &optional unread)
6506   "Go to previous N'th summary line.
6507 If optional argument UNREAD is non-nil, only unread article is selected."
6508   (interactive "p")
6509   (gnus-summary-next-subject (- n) unread))
6510
6511 (defun gnus-summary-prev-unread-subject (n)
6512   "Go to previous N'th unread summary line."
6513   (interactive "p")
6514   (gnus-summary-next-subject (- n) t))
6515
6516 (defun gnus-summary-goto-subject (article &optional force silent)
6517   "Go the subject line of ARTICLE.
6518 If FORCE, also allow jumping to articles not currently shown."
6519   (interactive "nArticle number: ")
6520   (unless (numberp article)
6521     (error "Article %s is not a number" article))
6522   (let ((b (point))
6523         (data (gnus-data-find article)))
6524     ;; We read in the article if we have to.
6525     (and (not data)
6526          force
6527          (gnus-summary-insert-subject
6528           article
6529           (if (or (numberp force) (vectorp force)) force)
6530           t)
6531          (setq data (gnus-data-find article)))
6532     (goto-char b)
6533     (if (not data)
6534         (progn
6535           (unless silent
6536             (gnus-message 3 "Can't find article %d" article))
6537           nil)
6538       (let ((pt (gnus-data-pos data)))
6539         (goto-char pt)
6540         (gnus-summary-set-article-display-arrow pt))
6541       (gnus-summary-position-point)
6542       article)))
6543
6544 ;; Walking around summary lines with displaying articles.
6545
6546 (defun gnus-summary-expand-window (&optional arg)
6547   "Make the summary buffer take up the entire Emacs frame.
6548 Given a prefix, will force an `article' buffer configuration."
6549   (interactive "P")
6550   (if arg
6551       (gnus-configure-windows 'article 'force)
6552     (gnus-configure-windows 'summary 'force)))
6553
6554 (defun gnus-summary-display-article (article &optional all-header)
6555   "Display ARTICLE in article buffer."
6556   (when (gnus-buffer-live-p gnus-article-buffer)
6557     (with-current-buffer gnus-article-buffer
6558       (set-buffer-multibyte t)))
6559   (gnus-set-global-variables)
6560   (when (gnus-buffer-live-p gnus-article-buffer)
6561     (with-current-buffer gnus-article-buffer
6562       (setq gnus-article-charset gnus-newsgroup-charset)
6563       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6564       (set-buffer-multibyte t)))
6565   (if (null article)
6566       nil
6567     (prog1
6568         (if gnus-summary-display-article-function
6569             (funcall gnus-summary-display-article-function article all-header)
6570           (gnus-article-prepare article all-header))
6571       (with-current-buffer gnus-article-buffer
6572         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6573              nil))
6574       (gnus-run-hooks 'gnus-select-article-hook)
6575       (when (and gnus-current-article
6576                  (not (zerop gnus-current-article)))
6577         (gnus-summary-goto-subject gnus-current-article))
6578       (gnus-summary-recenter)
6579       (when (and gnus-use-trees gnus-show-threads)
6580         (gnus-possibly-generate-tree article)
6581         (gnus-highlight-selected-tree article))
6582       ;; Successfully display article.
6583       (gnus-article-set-window-start
6584        (cdr (assq article gnus-newsgroup-bookmarks))))))
6585
6586 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6587   "Select the current article.
6588 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6589 non-nil, the article will be re-fetched even if it already present in
6590 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6591 be displayed."
6592   ;; Make sure we are in the summary buffer to work around bbdb bug.
6593   (unless (eq major-mode 'gnus-summary-mode)
6594     (set-buffer gnus-summary-buffer))
6595   (let ((article (or article (gnus-summary-article-number)))
6596         (all-headers (not (not all-headers))) ;Must be T or NIL.
6597         gnus-summary-display-article-function)
6598     (and (not pseudo)
6599          (gnus-summary-article-pseudo-p article)
6600          (error "This is a pseudo-article"))
6601     (save-excursion
6602       (set-buffer gnus-summary-buffer)
6603       (if (or (and gnus-single-article-buffer
6604                    (or (null gnus-current-article)
6605                        (null gnus-article-current)
6606                        (null (get-buffer gnus-article-buffer))
6607                        (not (eq article (cdr gnus-article-current)))
6608                        (not (equal (car gnus-article-current)
6609                                    gnus-newsgroup-name))))
6610               (and (not gnus-single-article-buffer)
6611                    (or (null gnus-current-article)
6612                        (not (eq gnus-current-article article))))
6613               force)
6614           ;; The requested article is different from the current article.
6615           (progn
6616             (gnus-summary-display-article article all-headers)
6617 ;;; Hidden headers are not hidden text any more.
6618 ;;          (when (or all-headers gnus-show-all-headers)
6619 ;;            (gnus-article-show-all-headers))
6620             (gnus-article-set-window-start
6621              (cdr (assq article gnus-newsgroup-bookmarks)))
6622             article)
6623 ;;      (when (or all-headers gnus-show-all-headers)
6624 ;;        (gnus-article-show-all-headers))
6625         'old))))
6626
6627 (defun gnus-summary-force-verify-and-decrypt ()
6628   (interactive)
6629   (let ((mm-verify-option 'known)
6630         (mm-decrypt-option 'known))
6631     (gnus-summary-select-article nil 'force)))
6632
6633 (defun gnus-summary-set-current-mark (&optional current-mark)
6634   "Obsolete function."
6635   nil)
6636
6637 (defun gnus-summary-next-article (&optional unread subject backward push)
6638   "Select the next article.
6639 If UNREAD, only unread articles are selected.
6640 If SUBJECT, only articles with SUBJECT are selected.
6641 If BACKWARD, the previous article is selected instead of the next."
6642   (interactive "P")
6643   (cond
6644    ;; Is there such an article?
6645    ((and (gnus-summary-search-forward unread subject backward)
6646          (or (gnus-summary-display-article (gnus-summary-article-number))
6647              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6648     (gnus-summary-position-point))
6649    ;; If not, we try the first unread, if that is wanted.
6650    ((and subject
6651          gnus-auto-select-same
6652          (gnus-summary-first-unread-article))
6653     (gnus-summary-position-point)
6654     (gnus-message 6 "Wrapped"))
6655    ;; Try to get next/previous article not displayed in this group.
6656    ((and gnus-auto-extend-newsgroup
6657          (not unread) (not subject))
6658     (gnus-summary-goto-article
6659      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6660      nil (count-lines (point-min) (point))))
6661    ;; Go to next/previous group.
6662    (t
6663     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6664       (gnus-summary-jump-to-group gnus-newsgroup-name))
6665     (let ((cmd last-command-char)
6666           (point
6667            (save-excursion
6668              (set-buffer gnus-group-buffer)
6669              (point)))
6670           (group
6671            (if (eq gnus-keep-same-level 'best)
6672                (gnus-summary-best-group gnus-newsgroup-name)
6673              (gnus-summary-search-group backward gnus-keep-same-level))))
6674       ;; For some reason, the group window gets selected.  We change
6675       ;; it back.
6676       (select-window (get-buffer-window (current-buffer)))
6677       ;; Select next unread newsgroup automagically.
6678       (cond
6679        ((or (not gnus-auto-select-next)
6680             (not cmd))
6681         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6682        ((or (eq gnus-auto-select-next 'quietly)
6683             (and (eq gnus-auto-select-next 'slightly-quietly)
6684                  push)
6685             (and (eq gnus-auto-select-next 'almost-quietly)
6686                  (gnus-summary-last-article-p)))
6687         ;; Select quietly.
6688         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6689             (gnus-summary-exit)
6690           (gnus-message 7 "No more%s articles (%s)..."
6691                         (if unread " unread" "")
6692                         (if group (concat "selecting " group)
6693                           "exiting"))
6694           (gnus-summary-next-group nil group backward)))
6695        (t
6696         (when (gnus-key-press-event-p last-input-event)
6697           (gnus-summary-walk-group-buffer
6698            gnus-newsgroup-name cmd unread backward point))))))))
6699
6700 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6701   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6702                       (?\C-p (gnus-group-prev-unread-group 1))))
6703         (cursor-in-echo-area t)
6704         keve key group ended)
6705     (save-excursion
6706       (set-buffer gnus-group-buffer)
6707       (goto-char start)
6708       (setq group
6709             (if (eq gnus-keep-same-level 'best)
6710                 (gnus-summary-best-group gnus-newsgroup-name)
6711               (gnus-summary-search-group backward gnus-keep-same-level))))
6712     (while (not ended)
6713       (gnus-message
6714        5 "No more%s articles%s" (if unread " unread" "")
6715        (if (and group
6716                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6717            (format " (Type %s for %s [%s])"
6718                    (single-key-description cmd) group
6719                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6720          (format " (Type %s to exit %s)"
6721                  (single-key-description cmd)
6722                  gnus-newsgroup-name)))
6723       ;; Confirm auto selection.
6724       (setq key (car (setq keve (gnus-read-event-char))))
6725       (setq ended t)
6726       (cond
6727        ((assq key keystrokes)
6728         (let ((obuf (current-buffer)))
6729           (switch-to-buffer gnus-group-buffer)
6730           (when group
6731             (gnus-group-jump-to-group group))
6732           (eval (cadr (assq key keystrokes)))
6733           (setq group (gnus-group-group-name))
6734           (switch-to-buffer obuf))
6735         (setq ended nil))
6736        ((equal key cmd)
6737         (if (or (not group)
6738                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6739             (gnus-summary-exit)
6740           (gnus-summary-next-group nil group backward)))
6741        (t
6742         (push (cdr keve) unread-command-events))))))
6743
6744 (defun gnus-summary-next-unread-article ()
6745   "Select unread article after current one."
6746   (interactive)
6747   (gnus-summary-next-article
6748    (or (not (eq gnus-summary-goto-unread 'never))
6749        (gnus-summary-last-article-p (gnus-summary-article-number)))
6750    (and gnus-auto-select-same
6751         (gnus-summary-article-subject))))
6752
6753 (defun gnus-summary-prev-article (&optional unread subject)
6754   "Select the article after the current one.
6755 If UNREAD is non-nil, only unread articles are selected."
6756   (interactive "P")
6757   (gnus-summary-next-article unread subject t))
6758
6759 (defun gnus-summary-prev-unread-article ()
6760   "Select unread article before current one."
6761   (interactive)
6762   (gnus-summary-prev-article
6763    (or (not (eq gnus-summary-goto-unread 'never))
6764        (gnus-summary-first-article-p (gnus-summary-article-number)))
6765    (and gnus-auto-select-same
6766         (gnus-summary-article-subject))))
6767
6768 (defun gnus-summary-next-page (&optional lines circular)
6769   "Show next page of the selected article.
6770 If at the end of the current article, select the next article.
6771 LINES says how many lines should be scrolled up.
6772
6773 If CIRCULAR is non-nil, go to the start of the article instead of
6774 selecting the next article when reaching the end of the current
6775 article."
6776   (interactive "P")
6777   (setq gnus-summary-buffer (current-buffer))
6778   (gnus-set-global-variables)
6779   (let ((article (gnus-summary-article-number))
6780         (article-window (get-buffer-window gnus-article-buffer t))
6781         endp)
6782     ;; If the buffer is empty, we have no article.
6783     (unless article
6784       (error "No article to select"))
6785     (gnus-configure-windows 'article)
6786     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6787         (if (and (eq gnus-summary-goto-unread 'never)
6788                  (not (gnus-summary-last-article-p article)))
6789             (gnus-summary-next-article)
6790           (gnus-summary-next-unread-article))
6791       (if (or (null gnus-current-article)
6792               (null gnus-article-current)
6793               (/= article (cdr gnus-article-current))
6794               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6795           ;; Selected subject is different from current article's.
6796           (gnus-summary-display-article article)
6797         (when article-window
6798           (gnus-eval-in-buffer-window gnus-article-buffer
6799             (setq endp (gnus-article-next-page lines)))
6800           (when endp
6801             (cond (circular
6802                    (gnus-summary-beginning-of-article))
6803                   (lines
6804                    (gnus-message 3 "End of message"))
6805                   ((null lines)
6806                    (if (and (eq gnus-summary-goto-unread 'never)
6807                             (not (gnus-summary-last-article-p article)))
6808                        (gnus-summary-next-article)
6809                      (gnus-summary-next-unread-article))))))))
6810     (gnus-summary-recenter)
6811     (gnus-summary-position-point)))
6812
6813 (defun gnus-summary-prev-page (&optional lines move)
6814   "Show previous page of selected article.
6815 Argument LINES specifies lines to be scrolled down.
6816 If MOVE, move to the previous unread article if point is at
6817 the beginning of the buffer."
6818   (interactive "P")
6819   (let ((article (gnus-summary-article-number))
6820         (article-window (get-buffer-window gnus-article-buffer t))
6821         endp)
6822     (gnus-configure-windows 'article)
6823     (if (or (null gnus-current-article)
6824             (null gnus-article-current)
6825             (/= article (cdr gnus-article-current))
6826             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6827         ;; Selected subject is different from current article's.
6828         (gnus-summary-display-article article)
6829       (gnus-summary-recenter)
6830       (when article-window
6831         (gnus-eval-in-buffer-window gnus-article-buffer
6832           (setq endp (gnus-article-prev-page lines)))
6833         (when (and move endp)
6834           (cond (lines
6835                  (gnus-message 3 "Beginning of message"))
6836                 ((null lines)
6837                  (if (and (eq gnus-summary-goto-unread 'never)
6838                           (not (gnus-summary-first-article-p article)))
6839                      (gnus-summary-prev-article)
6840                    (gnus-summary-prev-unread-article))))))))
6841   (gnus-summary-position-point))
6842
6843 (defun gnus-summary-prev-page-or-article (&optional lines)
6844   "Show previous page of selected article.
6845 Argument LINES specifies lines to be scrolled down.
6846 If at the beginning of the article, go to the next article."
6847   (interactive "P")
6848   (gnus-summary-prev-page lines t))
6849
6850 (defun gnus-summary-scroll-up (lines)
6851   "Scroll up (or down) one line current article.
6852 Argument LINES specifies lines to be scrolled up (or down if negative)."
6853   (interactive "p")
6854   (gnus-configure-windows 'article)
6855   (gnus-summary-show-thread)
6856   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6857     (gnus-eval-in-buffer-window gnus-article-buffer
6858       (cond ((> lines 0)
6859              (when (gnus-article-next-page lines)
6860                (gnus-message 3 "End of message")))
6861             ((< lines 0)
6862              (gnus-article-prev-page (- lines))))))
6863   (gnus-summary-recenter)
6864   (gnus-summary-position-point))
6865
6866 (defun gnus-summary-scroll-down (lines)
6867   "Scroll down (or up) one line current article.
6868 Argument LINES specifies lines to be scrolled down (or up if negative)."
6869   (interactive "p")
6870   (gnus-summary-scroll-up (- lines)))
6871
6872 (defun gnus-summary-next-same-subject ()
6873   "Select next article which has the same subject as current one."
6874   (interactive)
6875   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6876
6877 (defun gnus-summary-prev-same-subject ()
6878   "Select previous article which has the same subject as current one."
6879   (interactive)
6880   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6881
6882 (defun gnus-summary-next-unread-same-subject ()
6883   "Select next unread article which has the same subject as current one."
6884   (interactive)
6885   (gnus-summary-next-article t (gnus-summary-article-subject)))
6886
6887 (defun gnus-summary-prev-unread-same-subject ()
6888   "Select previous unread article which has the same subject as current one."
6889   (interactive)
6890   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6891
6892 (defun gnus-summary-first-unread-article ()
6893   "Select the first unread article.
6894 Return nil if there are no unread articles."
6895   (interactive)
6896   (prog1
6897       (when (gnus-summary-first-subject t)
6898         (gnus-summary-show-thread)
6899         (gnus-summary-first-subject t)
6900         (gnus-summary-display-article (gnus-summary-article-number)))
6901     (gnus-summary-position-point)))
6902
6903 (defun gnus-summary-first-unread-subject ()
6904   "Place the point on the subject line of the first unread article.
6905 Return nil if there are no unread articles."
6906   (interactive)
6907   (prog1
6908       (when (gnus-summary-first-subject t)
6909         (gnus-summary-show-thread)
6910         (gnus-summary-first-subject t))
6911     (gnus-summary-position-point)))
6912
6913 (defun gnus-summary-first-unseen-subject ()
6914   "Place the point on the subject line of the first unseen article.
6915 Return nil if there are no unseen articles."
6916   (interactive)
6917   (prog1
6918       (when (gnus-summary-first-subject t t t)
6919         (gnus-summary-show-thread)
6920         (gnus-summary-first-subject t t t))
6921     (gnus-summary-position-point)))
6922
6923 (defun gnus-summary-first-unseen-or-unread-subject ()
6924   "Place the point on the subject line of the first unseen article.
6925 Return nil if there are no unseen articles."
6926   (interactive)
6927   (prog1
6928       (unless (when (gnus-summary-first-subject t t t)
6929                 (gnus-summary-show-thread)
6930                 (gnus-summary-first-subject t t t))
6931         (when (gnus-summary-first-subject t)
6932           (gnus-summary-show-thread)
6933           (gnus-summary-first-subject t)))
6934     (gnus-summary-position-point)))
6935
6936 (defun gnus-summary-first-article ()
6937   "Select the first article.
6938 Return nil if there are no articles."
6939   (interactive)
6940   (prog1
6941       (when (gnus-summary-first-subject)
6942         (gnus-summary-show-thread)
6943         (gnus-summary-first-subject)
6944         (gnus-summary-display-article (gnus-summary-article-number)))
6945     (gnus-summary-position-point)))
6946
6947 (defun gnus-summary-best-unread-article (&optional arg)
6948   "Select the unread article with the highest score.
6949 If given a prefix argument, select the next unread article that has a
6950 score higher than the default score."
6951   (interactive "P")
6952   (let ((article (if arg
6953                      (gnus-summary-better-unread-subject)
6954                    (gnus-summary-best-unread-subject))))
6955     (if article
6956         (gnus-summary-goto-article article)
6957       (error "No unread articles"))))
6958
6959 (defun gnus-summary-best-unread-subject ()
6960   "Select the unread subject with the highest score."
6961   (interactive)
6962   (let ((best -1000000)
6963         (data gnus-newsgroup-data)
6964         article score)
6965     (while data
6966       (and (gnus-data-unread-p (car data))
6967            (> (setq score
6968                     (gnus-summary-article-score (gnus-data-number (car data))))
6969               best)
6970            (setq best score
6971                  article (gnus-data-number (car data))))
6972       (setq data (cdr data)))
6973     (when article
6974       (gnus-summary-goto-subject article))
6975     (gnus-summary-position-point)
6976     article))
6977
6978 (defun gnus-summary-better-unread-subject ()
6979   "Select the first unread subject that has a score over the default score."
6980   (interactive)
6981   (let ((data gnus-newsgroup-data)
6982         article score)
6983     (while (and (setq article (gnus-data-number (car data)))
6984                 (or (gnus-data-read-p (car data))
6985                     (not (> (gnus-summary-article-score article)
6986                             gnus-summary-default-score))))
6987       (setq data (cdr data)))
6988     (when article
6989       (gnus-summary-goto-subject article))
6990     (gnus-summary-position-point)
6991     article))
6992
6993 (defun gnus-summary-last-subject ()
6994   "Go to the last displayed subject line in the group."
6995   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6996     (when article
6997       (gnus-summary-goto-subject article))))
6998
6999 (defun gnus-summary-goto-article (article &optional all-headers force)
7000   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7001 If ALL-HEADERS is non-nil, no header lines are hidden.
7002 If FORCE, go to the article even if it isn't displayed.  If FORCE
7003 is a number, it is the line the article is to be displayed on."
7004   (interactive
7005    (list
7006     (completing-read
7007      "Article number or Message-ID: "
7008      (mapcar (lambda (number) (list (int-to-string number)))
7009              gnus-newsgroup-limit))
7010     current-prefix-arg
7011     t))
7012   (prog1
7013       (if (and (stringp article)
7014                (string-match "@" article))
7015           (gnus-summary-refer-article article)
7016         (when (stringp article)
7017           (setq article (string-to-number article)))
7018         (if (gnus-summary-goto-subject article force)
7019             (gnus-summary-display-article article all-headers)
7020           (gnus-message 4 "Couldn't go to article %s" article) nil))
7021     (gnus-summary-position-point)))
7022
7023 (defun gnus-summary-goto-last-article ()
7024   "Go to the previously read article."
7025   (interactive)
7026   (prog1
7027       (when gnus-last-article
7028         (gnus-summary-goto-article gnus-last-article nil t))
7029     (gnus-summary-position-point)))
7030
7031 (defun gnus-summary-pop-article (number)
7032   "Pop one article off the history and go to the previous.
7033 NUMBER articles will be popped off."
7034   (interactive "p")
7035   (let (to)
7036     (setq gnus-newsgroup-history
7037           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7038     (if to
7039         (gnus-summary-goto-article (car to) nil t)
7040       (error "Article history empty")))
7041   (gnus-summary-position-point))
7042
7043 ;; Summary commands and functions for limiting the summary buffer.
7044
7045 (defun gnus-summary-limit-to-articles (n)
7046   "Limit the summary buffer to the next N articles.
7047 If not given a prefix, use the process marked articles instead."
7048   (interactive "P")
7049   (prog1
7050       (let ((articles (gnus-summary-work-articles n)))
7051         (setq gnus-newsgroup-processable nil)
7052         (gnus-summary-limit articles))
7053     (gnus-summary-position-point)))
7054
7055 (defun gnus-summary-pop-limit (&optional total)
7056   "Restore the previous limit.
7057 If given a prefix, remove all limits."
7058   (interactive "P")
7059   (when total
7060     (setq gnus-newsgroup-limits
7061           (list (mapcar (lambda (h) (mail-header-number h))
7062                         gnus-newsgroup-headers))))
7063   (unless gnus-newsgroup-limits
7064     (error "No limit to pop"))
7065   (prog1
7066       (gnus-summary-limit nil 'pop)
7067     (gnus-summary-position-point)))
7068
7069 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7070   "Limit the summary buffer to articles that have subjects that match a regexp.
7071 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7072   (interactive
7073    (list (read-string (if current-prefix-arg
7074                           "Exclude subject (regexp): "
7075                         "Limit to subject (regexp): "))
7076          nil current-prefix-arg))
7077   (unless header
7078     (setq header "subject"))
7079   (when (not (equal "" subject))
7080     (prog1
7081         (let ((articles (gnus-summary-find-matching
7082                          (or header "subject") subject 'all nil nil
7083                          not-matching)))
7084           (unless articles
7085             (error "Found no matches for \"%s\"" subject))
7086           (gnus-summary-limit articles))
7087       (gnus-summary-position-point))))
7088
7089 (defun gnus-summary-limit-to-author (from &optional not-matching)
7090   "Limit the summary buffer to articles that have authors that match a regexp.
7091 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7092   (interactive
7093    (list (read-string (if current-prefix-arg
7094                           "Exclude author (regexp): "
7095                         "Limit to author (regexp): "))
7096          current-prefix-arg))
7097   (gnus-summary-limit-to-subject from "from" not-matching))
7098
7099 (defun gnus-summary-limit-to-age (age &optional younger-p)
7100   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7101 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7102 articles that are younger than AGE days."
7103   (interactive
7104    (let ((younger current-prefix-arg)
7105          (days-got nil)
7106          days)
7107      (while (not days-got)
7108        (setq days (if younger
7109                       (read-string "Limit to articles within (in days): ")
7110                     (read-string "Limit to articles older than (in days): ")))
7111        (when (> (length days) 0)
7112          (setq days (read days)))
7113        (if (numberp days)
7114            (progn
7115              (setq days-got t)
7116              (if (< days 0)
7117                  (progn
7118                    (setq younger (not younger))
7119                    (setq days (* days -1)))))
7120          (message "Please enter a number.")
7121          (sleep-for 1)))
7122      (list days younger)))
7123   (prog1
7124       (let ((data gnus-newsgroup-data)
7125             (cutoff (days-to-time age))
7126             articles d date is-younger)
7127         (while (setq d (pop data))
7128           (when (and (vectorp (gnus-data-header d))
7129                      (setq date (mail-header-date (gnus-data-header d))))
7130             (setq is-younger (time-less-p
7131                               (time-since (condition-case ()
7132                                               (date-to-time date)
7133                                             (error '(0 0))))
7134                               cutoff))
7135             (when (if younger-p
7136                       is-younger
7137                     (not is-younger))
7138               (push (gnus-data-number d) articles))))
7139         (gnus-summary-limit (nreverse articles)))
7140     (gnus-summary-position-point)))
7141
7142 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7143   "Limit the summary buffer to articles that match an 'extra' header."
7144   (interactive
7145    (let ((header
7146           (intern
7147            (gnus-completing-read-with-default
7148             (symbol-name (car gnus-extra-headers))
7149             (if current-prefix-arg
7150                 "Exclude extra header:"
7151               "Limit extra header:")
7152             (mapcar (lambda (x)
7153                       (cons (symbol-name x) x))
7154                     gnus-extra-headers)
7155             nil
7156             t))))
7157      (list header
7158            (read-string (format "%s header %s (regexp): "
7159                                 (if current-prefix-arg "Exclude" "Limit to")
7160                                 header))
7161            current-prefix-arg)))
7162   (when (not (equal "" regexp))
7163     (prog1
7164         (let ((articles (gnus-summary-find-matching
7165                          (cons 'extra header) regexp 'all nil nil
7166                          not-matching)))
7167           (unless articles
7168             (error "Found no matches for \"%s\"" regexp))
7169           (gnus-summary-limit articles))
7170       (gnus-summary-position-point))))
7171
7172 (defun gnus-summary-limit-to-display-predicate ()
7173   "Limit the summary buffer to the predicated in the `display' group parameter."
7174   (interactive)
7175   (unless gnus-newsgroup-display
7176     (error "There is no `display' group parameter"))
7177   (let (articles)
7178     (dolist (number gnus-newsgroup-articles)
7179       (when (funcall gnus-newsgroup-display)
7180         (push number articles)))
7181     (gnus-summary-limit articles))
7182   (gnus-summary-position-point))
7183
7184 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7185 (make-obsolete
7186  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7187
7188 (defun gnus-summary-limit-to-unread (&optional all)
7189   "Limit the summary buffer to articles that are not marked as read.
7190 If ALL is non-nil, limit strictly to unread articles."
7191   (interactive "P")
7192   (if all
7193       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7194     (gnus-summary-limit-to-marks
7195      ;; Concat all the marks that say that an article is read and have
7196      ;; those removed.
7197      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7198            gnus-killed-mark gnus-kill-file-mark
7199            gnus-low-score-mark gnus-expirable-mark
7200            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7201            gnus-duplicate-mark gnus-souped-mark)
7202      'reverse)))
7203
7204 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7205 (make-obsolete 'gnus-summary-delete-marked-with
7206                'gnus-summary-limit-exlude-marks)
7207
7208 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7209   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7210 If REVERSE, limit the summary buffer to articles that are marked
7211 with MARKS.  MARKS can either be a string of marks or a list of marks.
7212 Returns how many articles were removed."
7213   (interactive "sMarks: ")
7214   (gnus-summary-limit-to-marks marks t))
7215
7216 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7217   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7218 If REVERSE (the prefix), limit the summary buffer to articles that are
7219 not marked with MARKS.  MARKS can either be a string of marks or a
7220 list of marks.
7221 Returns how many articles were removed."
7222   (interactive "sMarks: \nP")
7223   (prog1
7224       (let ((data gnus-newsgroup-data)
7225             (marks (if (listp marks) marks
7226                      (append marks nil))) ; Transform to list.
7227             articles)
7228         (while data
7229           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7230                   (memq (gnus-data-mark (car data)) marks))
7231             (push (gnus-data-number (car data)) articles))
7232           (setq data (cdr data)))
7233         (gnus-summary-limit articles))
7234     (gnus-summary-position-point)))
7235
7236 (defun gnus-summary-limit-to-score (score)
7237   "Limit to articles with score at or above SCORE."
7238   (interactive "NLimit to articles with score of at least: ")
7239   (let ((data gnus-newsgroup-data)
7240         articles)
7241     (while data
7242       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7243                 score)
7244         (push (gnus-data-number (car data)) articles))
7245       (setq data (cdr data)))
7246     (prog1
7247         (gnus-summary-limit articles)
7248       (gnus-summary-position-point))))
7249
7250 (defun gnus-summary-limit-include-thread (id)
7251   "Display all the hidden articles that is in the thread with ID in it.
7252 When called interactively, ID is the Message-ID of the current
7253 article."
7254   (interactive (list (mail-header-id (gnus-summary-article-header))))
7255   (let ((articles (gnus-articles-in-thread
7256                    (gnus-id-to-thread (gnus-root-id id)))))
7257     (prog1
7258         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7259       (gnus-summary-limit-include-matching-articles
7260        "subject"
7261        (regexp-quote (gnus-simplify-subject-re
7262                       (mail-header-subject (gnus-id-to-header id)))))
7263       (gnus-summary-position-point))))
7264
7265 (defun gnus-summary-limit-include-matching-articles (header regexp)
7266   "Display all the hidden articles that have HEADERs that match REGEXP."
7267   (interactive (list (read-string "Match on header: ")
7268                      (read-string "Regexp: ")))
7269   (let ((articles (gnus-find-matching-articles header regexp)))
7270     (prog1
7271         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7272       (gnus-summary-position-point))))
7273
7274 (defun gnus-summary-limit-include-dormant ()
7275   "Display all the hidden articles that are marked as dormant.
7276 Note that this command only works on a subset of the articles currently
7277 fetched for this group."
7278   (interactive)
7279   (unless gnus-newsgroup-dormant
7280     (error "There are no dormant articles in this group"))
7281   (prog1
7282       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7283     (gnus-summary-position-point)))
7284
7285 (defun gnus-summary-limit-exclude-dormant ()
7286   "Hide all dormant articles."
7287   (interactive)
7288   (prog1
7289       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7290     (gnus-summary-position-point)))
7291
7292 (defun gnus-summary-limit-exclude-childless-dormant ()
7293   "Hide all dormant articles that have no children."
7294   (interactive)
7295   (let ((data (gnus-data-list t))
7296         articles d children)
7297     ;; Find all articles that are either not dormant or have
7298     ;; children.
7299     (while (setq d (pop data))
7300       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7301                 (and (setq children
7302                            (gnus-article-children (gnus-data-number d)))
7303                      (let (found)
7304                        (while children
7305                          (when (memq (car children) articles)
7306                            (setq children nil
7307                                  found t))
7308                          (pop children))
7309                        found)))
7310         (push (gnus-data-number d) articles)))
7311     ;; Do the limiting.
7312     (prog1
7313         (gnus-summary-limit articles)
7314       (gnus-summary-position-point))))
7315
7316 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7317   "Mark all unread excluded articles as read.
7318 If ALL, mark even excluded ticked and dormants as read."
7319   (interactive "P")
7320   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7321   (let ((articles (gnus-sorted-ndifference
7322                    (sort
7323                     (mapcar (lambda (h) (mail-header-number h))
7324                             gnus-newsgroup-headers)
7325                     '<)
7326                    gnus-newsgroup-limit))
7327         article)
7328     (setq gnus-newsgroup-unreads
7329           (gnus-sorted-intersection gnus-newsgroup-unreads
7330                                     gnus-newsgroup-limit))
7331     (if all
7332         (setq gnus-newsgroup-dormant nil
7333               gnus-newsgroup-marked nil
7334               gnus-newsgroup-reads
7335               (nconc
7336                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7337                gnus-newsgroup-reads))
7338       (while (setq article (pop articles))
7339         (unless (or (memq article gnus-newsgroup-dormant)
7340                     (memq article gnus-newsgroup-marked))
7341           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7342
7343 (defun gnus-summary-limit (articles &optional pop)
7344   (if pop
7345       ;; We pop the previous limit off the stack and use that.
7346       (setq articles (car gnus-newsgroup-limits)
7347             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7348     ;; We use the new limit, so we push the old limit on the stack.
7349     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7350   ;; Set the limit.
7351   (setq gnus-newsgroup-limit articles)
7352   (let ((total (length gnus-newsgroup-data))
7353         (data (gnus-data-find-list (gnus-summary-article-number)))
7354         (gnus-summary-mark-below nil)   ; Inhibit this.
7355         found)
7356     ;; This will do all the work of generating the new summary buffer
7357     ;; according to the new limit.
7358     (gnus-summary-prepare)
7359     ;; Hide any threads, possibly.
7360     (gnus-summary-maybe-hide-threads)
7361     ;; Try to return to the article you were at, or one in the
7362     ;; neighborhood.
7363     (when data
7364       ;; We try to find some article after the current one.
7365       (while data
7366         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7367           (setq data nil
7368                 found t))
7369         (setq data (cdr data))))
7370     (unless found
7371       ;; If there is no data, that means that we were after the last
7372       ;; article.  The same goes when we can't find any articles
7373       ;; after the current one.
7374       (goto-char (point-max))
7375       (gnus-summary-find-prev))
7376     (gnus-set-mode-line 'summary)
7377     ;; We return how many articles were removed from the summary
7378     ;; buffer as a result of the new limit.
7379     (- total (length gnus-newsgroup-data))))
7380
7381 (defsubst gnus-invisible-cut-children (threads)
7382   (let ((num 0))
7383     (while threads
7384       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7385         (incf num))
7386       (pop threads))
7387     (< num 2)))
7388
7389 (defsubst gnus-cut-thread (thread)
7390   "Go forwards in the thread until we find an article that we want to display."
7391   (when (or (eq gnus-fetch-old-headers 'some)
7392             (eq gnus-fetch-old-headers 'invisible)
7393             (numberp gnus-fetch-old-headers)
7394             (eq gnus-build-sparse-threads 'some)
7395             (eq gnus-build-sparse-threads 'more))
7396     ;; Deal with old-fetched headers and sparse threads.
7397     (while (and
7398             thread
7399             (or
7400              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7401              (gnus-summary-article-ancient-p
7402               (mail-header-number (car thread))))
7403             (if (or (<= (length (cdr thread)) 1)
7404                     (eq gnus-fetch-old-headers 'invisible))
7405                 (setq gnus-newsgroup-limit
7406                       (delq (mail-header-number (car thread))
7407                             gnus-newsgroup-limit)
7408                       thread (cadr thread))
7409               (when (gnus-invisible-cut-children (cdr thread))
7410                 (let ((th (cdr thread)))
7411                   (while th
7412                     (if (memq (mail-header-number (caar th))
7413                               gnus-newsgroup-limit)
7414                         (setq thread (car th)
7415                               th nil)
7416                       (setq th (cdr th))))))))))
7417   thread)
7418
7419 (defun gnus-cut-threads (threads)
7420   "Cut off all uninteresting articles from the beginning of threads."
7421   (when (or (eq gnus-fetch-old-headers 'some)
7422             (eq gnus-fetch-old-headers 'invisible)
7423             (numberp gnus-fetch-old-headers)
7424             (eq gnus-build-sparse-threads 'some)
7425             (eq gnus-build-sparse-threads 'more))
7426     (let ((th threads))
7427       (while th
7428         (setcar th (gnus-cut-thread (car th)))
7429         (setq th (cdr th)))))
7430   ;; Remove nixed out threads.
7431   (delq nil threads))
7432
7433 (defun gnus-summary-initial-limit (&optional show-if-empty)
7434   "Figure out what the initial limit is supposed to be on group entry.
7435 This entails weeding out unwanted dormants, low-scored articles,
7436 fetch-old-headers verbiage, and so on."
7437   ;; Most groups have nothing to remove.
7438   (if (or gnus-inhibit-limiting
7439           (and (null gnus-newsgroup-dormant)
7440                (eq gnus-newsgroup-display 'gnus-not-ignore)
7441                (not (eq gnus-fetch-old-headers 'some))
7442                (not (numberp gnus-fetch-old-headers))
7443                (not (eq gnus-fetch-old-headers 'invisible))
7444                (null gnus-summary-expunge-below)
7445                (not (eq gnus-build-sparse-threads 'some))
7446                (not (eq gnus-build-sparse-threads 'more))
7447                (null gnus-thread-expunge-below)
7448                (not gnus-use-nocem)))
7449       ()                                ; Do nothing.
7450     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7451     (setq gnus-newsgroup-limit nil)
7452     (mapatoms
7453      (lambda (node)
7454        (unless (car (symbol-value node))
7455          ;; These threads have no parents -- they are roots.
7456          (let ((nodes (cdr (symbol-value node)))
7457                thread)
7458            (while nodes
7459              (if (and gnus-thread-expunge-below
7460                       (< (gnus-thread-total-score (car nodes))
7461                          gnus-thread-expunge-below))
7462                  (gnus-expunge-thread (pop nodes))
7463                (setq thread (pop nodes))
7464                (gnus-summary-limit-children thread))))))
7465      gnus-newsgroup-dependencies)
7466     ;; If this limitation resulted in an empty group, we might
7467     ;; pop the previous limit and use it instead.
7468     (when (and (not gnus-newsgroup-limit)
7469                show-if-empty)
7470       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7471     gnus-newsgroup-limit))
7472
7473 (defun gnus-summary-limit-children (thread)
7474   "Return 1 if this subthread is visible and 0 if it is not."
7475   ;; First we get the number of visible children to this thread.  This
7476   ;; is done by recursing down the thread using this function, so this
7477   ;; will really go down to a leaf article first, before slowly
7478   ;; working its way up towards the root.
7479   (when thread
7480     (let ((children
7481            (if (cdr thread)
7482                (apply '+ (mapcar 'gnus-summary-limit-children
7483                                  (cdr thread)))
7484              0))
7485           (number (mail-header-number (car thread)))
7486           score)
7487       (if (and
7488            (not (memq number gnus-newsgroup-marked))
7489            (or
7490             ;; If this article is dormant and has absolutely no visible
7491             ;; children, then this article isn't visible.
7492             (and (memq number gnus-newsgroup-dormant)
7493                  (zerop children))
7494             ;; If this is "fetch-old-headered" and there is no
7495             ;; visible children, then we don't want this article.
7496             (and (or (eq gnus-fetch-old-headers 'some)
7497                      (numberp gnus-fetch-old-headers))
7498                  (gnus-summary-article-ancient-p number)
7499                  (zerop children))
7500             ;; If this is "fetch-old-headered" and `invisible', then
7501             ;; we don't want this article.
7502             (and (eq gnus-fetch-old-headers 'invisible)
7503                  (gnus-summary-article-ancient-p number))
7504             ;; If this is a sparsely inserted article with no children,
7505             ;; we don't want it.
7506             (and (eq gnus-build-sparse-threads 'some)
7507                  (gnus-summary-article-sparse-p number)
7508                  (zerop children))
7509             ;; If we use expunging, and this article is really
7510             ;; low-scored, then we don't want this article.
7511             (when (and gnus-summary-expunge-below
7512                        (< (setq score
7513                                 (or (cdr (assq number gnus-newsgroup-scored))
7514                                     gnus-summary-default-score))
7515                           gnus-summary-expunge-below))
7516               ;; We increase the expunge-tally here, but that has
7517               ;; nothing to do with the limits, really.
7518               (incf gnus-newsgroup-expunged-tally)
7519               ;; We also mark as read here, if that's wanted.
7520               (when (and gnus-summary-mark-below
7521                          (< score gnus-summary-mark-below))
7522                 (setq gnus-newsgroup-unreads
7523                       (delq number gnus-newsgroup-unreads))
7524                 (if gnus-newsgroup-auto-expire
7525                     (push number gnus-newsgroup-expirable)
7526                   (push (cons number gnus-low-score-mark)
7527                         gnus-newsgroup-reads)))
7528               t)
7529             ;; Do the `display' group parameter.
7530             (and gnus-newsgroup-display
7531                  (not (funcall gnus-newsgroup-display)))
7532             ;; Check NoCeM things.
7533             (if (and gnus-use-nocem
7534                      (gnus-nocem-unwanted-article-p
7535                       (mail-header-id (car thread))))
7536                 (progn
7537                   (setq gnus-newsgroup-unreads
7538                         (delq number gnus-newsgroup-unreads))
7539                   t))))
7540           ;; Nope, invisible article.
7541           0
7542         ;; Ok, this article is to be visible, so we add it to the limit
7543         ;; and return 1.
7544         (push number gnus-newsgroup-limit)
7545         1))))
7546
7547 (defun gnus-expunge-thread (thread)
7548   "Mark all articles in THREAD as read."
7549   (let* ((number (mail-header-number (car thread))))
7550     (incf gnus-newsgroup-expunged-tally)
7551     ;; We also mark as read here, if that's wanted.
7552     (setq gnus-newsgroup-unreads
7553           (delq number gnus-newsgroup-unreads))
7554     (if gnus-newsgroup-auto-expire
7555         (push number gnus-newsgroup-expirable)
7556       (push (cons number gnus-low-score-mark)
7557             gnus-newsgroup-reads)))
7558   ;; Go recursively through all subthreads.
7559   (mapcar 'gnus-expunge-thread (cdr thread)))
7560
7561 ;; Summary article oriented commands
7562
7563 (defun gnus-summary-refer-parent-article (n)
7564   "Refer parent article N times.
7565 If N is negative, go to ancestor -N instead.
7566 The difference between N and the number of articles fetched is returned."
7567   (interactive "p")
7568   (let ((skip 1)
7569         error header ref)
7570     (when (not (natnump n))
7571       (setq skip (abs n)
7572             n 1))
7573     (while (and (> n 0)
7574                 (not error))
7575       (setq header (gnus-summary-article-header))
7576       (if (and (eq (mail-header-number header)
7577                    (cdr gnus-article-current))
7578                (equal gnus-newsgroup-name
7579                       (car gnus-article-current)))
7580           ;; If we try to find the parent of the currently
7581           ;; displayed article, then we take a look at the actual
7582           ;; References header, since this is slightly more
7583           ;; reliable than the References field we got from the
7584           ;; server.
7585           (save-excursion
7586             (set-buffer gnus-original-article-buffer)
7587             (nnheader-narrow-to-headers)
7588             (unless (setq ref (message-fetch-field "references"))
7589               (setq ref (message-fetch-field "in-reply-to")))
7590             (widen))
7591         (setq ref
7592               ;; It's not the current article, so we take a bet on
7593               ;; the value we got from the server.
7594               (mail-header-references header)))
7595       (if (and ref
7596                (not (equal ref "")))
7597           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7598             (gnus-message 1 "Couldn't find parent"))
7599         (gnus-message 1 "No references in article %d"
7600                       (gnus-summary-article-number))
7601         (setq error t))
7602       (decf n))
7603     (gnus-summary-position-point)
7604     n))
7605
7606 (defun gnus-summary-refer-references ()
7607   "Fetch all articles mentioned in the References header.
7608 Return the number of articles fetched."
7609   (interactive)
7610   (let ((ref (mail-header-references (gnus-summary-article-header)))
7611         (current (gnus-summary-article-number))
7612         (n 0))
7613     (if (or (not ref)
7614             (equal ref ""))
7615         (error "No References in the current article")
7616       ;; For each Message-ID in the References header...
7617       (while (string-match "<[^>]*>" ref)
7618         (incf n)
7619         ;; ... fetch that article.
7620         (gnus-summary-refer-article
7621          (prog1 (match-string 0 ref)
7622            (setq ref (substring ref (match-end 0))))))
7623       (gnus-summary-goto-subject current)
7624       (gnus-summary-position-point)
7625       n)))
7626
7627 (defun gnus-summary-refer-thread (&optional limit)
7628   "Fetch all articles in the current thread.
7629 If LIMIT (the numerical prefix), fetch that many old headers instead
7630 of what's specified by the `gnus-refer-thread-limit' variable."
7631   (interactive "P")
7632   (let ((id (mail-header-id (gnus-summary-article-header)))
7633         (limit (if limit (prefix-numeric-value limit)
7634                  gnus-refer-thread-limit)))
7635     ;; We want to fetch LIMIT *old* headers, but we also have to
7636     ;; re-fetch all the headers in the current buffer, because many of
7637     ;; them may be undisplayed.  So we adjust LIMIT.
7638     (when (numberp limit)
7639       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7640     (unless (eq gnus-fetch-old-headers 'invisible)
7641       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7642       ;; Retrieve the headers and read them in.
7643       (if (eq (gnus-retrieve-headers
7644                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7645               'nov)
7646           (gnus-build-all-threads)
7647         (error "Can't fetch thread from backends that don't support NOV"))
7648       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7649     (gnus-summary-limit-include-thread id)))
7650
7651 (defun gnus-summary-refer-article (message-id)
7652   "Fetch an article specified by MESSAGE-ID."
7653   (interactive "sMessage-ID: ")
7654   (when (and (stringp message-id)
7655              (not (zerop (length message-id))))
7656     ;; Construct the correct Message-ID if necessary.
7657     ;; Suggested by tale@pawl.rpi.edu.
7658     (unless (string-match "^<" message-id)
7659       (setq message-id (concat "<" message-id)))
7660     (unless (string-match ">$" message-id)
7661       (setq message-id (concat message-id ">")))
7662     (let* ((header (gnus-id-to-header message-id))
7663            (sparse (and header
7664                         (gnus-summary-article-sparse-p
7665                          (mail-header-number header))
7666                         (memq (mail-header-number header)
7667                               gnus-newsgroup-limit)))
7668            number)
7669       (cond
7670        ;; If the article is present in the buffer we just go to it.
7671        ((and header
7672              (or (not (gnus-summary-article-sparse-p
7673                        (mail-header-number header)))
7674                  sparse))
7675         (prog1
7676             (gnus-summary-goto-article
7677              (mail-header-number header) nil t)
7678           (when sparse
7679             (gnus-summary-update-article (mail-header-number header)))))
7680        (t
7681         ;; We fetch the article.
7682         (catch 'found
7683           (dolist (gnus-override-method (gnus-refer-article-methods))
7684             (gnus-check-server gnus-override-method)
7685             ;; Fetch the header, and display the article.
7686             (when (setq number (gnus-summary-insert-subject message-id))
7687               (gnus-summary-select-article nil nil nil number)
7688               (throw 'found t)))
7689           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7690
7691 (defun gnus-refer-article-methods ()
7692   "Return a list of referrable methods."
7693   (cond
7694    ;; No method, so we default to current and native.
7695    ((null gnus-refer-article-method)
7696     (list gnus-current-select-method gnus-select-method))
7697    ;; Current.
7698    ((eq 'current gnus-refer-article-method)
7699     (list gnus-current-select-method))
7700    ;; List of select methods.
7701    ((not (and (symbolp (car gnus-refer-article-method))
7702               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7703     (let (out)
7704       (dolist (method gnus-refer-article-method)
7705         (push (if (eq 'current method)
7706                   gnus-current-select-method
7707                 method)
7708               out))
7709       (nreverse out)))
7710    ;; One single select method.
7711    (t
7712     (list gnus-refer-article-method))))
7713
7714 (defun gnus-summary-edit-parameters ()
7715   "Edit the group parameters of the current group."
7716   (interactive)
7717   (gnus-group-edit-group gnus-newsgroup-name 'params))
7718
7719 (defun gnus-summary-customize-parameters ()
7720   "Customize the group parameters of the current group."
7721   (interactive)
7722   (gnus-group-customize gnus-newsgroup-name))
7723
7724 (defun gnus-summary-enter-digest-group (&optional force)
7725   "Enter an nndoc group based on the current article.
7726 If FORCE, force a digest interpretation.  If not, try
7727 to guess what the document format is."
7728   (interactive "P")
7729   (let ((conf gnus-current-window-configuration))
7730     (save-excursion
7731       (gnus-summary-select-article))
7732     (setq gnus-current-window-configuration conf)
7733     (let* ((name (format "%s-%d"
7734                          (gnus-group-prefixed-name
7735                           gnus-newsgroup-name (list 'nndoc ""))
7736                          (save-excursion
7737                            (set-buffer gnus-summary-buffer)
7738                            gnus-current-article)))
7739            (ogroup gnus-newsgroup-name)
7740            (params (append (gnus-info-params (gnus-get-info ogroup))
7741                            (list (cons 'to-group ogroup))
7742                            (list (cons 'save-article-group ogroup))))
7743            (case-fold-search t)
7744            (buf (current-buffer))
7745            dig to-address)
7746       (save-excursion
7747         (set-buffer gnus-original-article-buffer)
7748         ;; Have the digest group inherit the main mail address of
7749         ;; the parent article.
7750         (when (setq to-address (or (message-fetch-field "reply-to")
7751                                    (message-fetch-field "from")))
7752           (setq params (append
7753                         (list (cons 'to-address
7754                                     (funcall gnus-decode-encoded-word-function
7755                                              to-address))))))
7756         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7757         (insert-buffer-substring gnus-original-article-buffer)
7758         ;; Remove lines that may lead nndoc to misinterpret the
7759         ;; document type.
7760         (narrow-to-region
7761          (goto-char (point-min))
7762          (or (search-forward "\n\n" nil t) (point)))
7763         (goto-char (point-min))
7764         (delete-matching-lines "^Path:\\|^From ")
7765         (widen))
7766       (unwind-protect
7767           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7768                     (gnus-newsgroup-ephemeral-ignored-charsets
7769                      gnus-newsgroup-ignored-charsets))
7770                 (gnus-group-read-ephemeral-group
7771                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7772                               (nndoc-article-type
7773                                ,(if force 'mbox 'guess)))
7774                  t nil nil nil
7775                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7776                                                         "ADAPT")))))
7777               ;; Make all postings to this group go to the parent group.
7778               (nconc (gnus-info-params (gnus-get-info name))
7779                      params)
7780             ;; Couldn't select this doc group.
7781             (switch-to-buffer buf)
7782             (gnus-set-global-variables)
7783             (gnus-configure-windows 'summary)
7784             (gnus-message 3 "Article couldn't be entered?"))
7785         (kill-buffer dig)))))
7786
7787 (defun gnus-summary-read-document (n)
7788   "Open a new group based on the current article(s).
7789 This will allow you to read digests and other similar
7790 documents as newsgroups.
7791 Obeys the standard process/prefix convention."
7792   (interactive "P")
7793   (let* ((articles (gnus-summary-work-articles n))
7794          (ogroup gnus-newsgroup-name)
7795          (params (append (gnus-info-params (gnus-get-info ogroup))
7796                          (list (cons 'to-group ogroup))))
7797          article group egroup groups vgroup)
7798     (while (setq article (pop articles))
7799       (setq group (format "%s-%d" gnus-newsgroup-name article))
7800       (gnus-summary-remove-process-mark article)
7801       (when (gnus-summary-display-article article)
7802         (save-excursion
7803           (with-temp-buffer
7804             (insert-buffer-substring gnus-original-article-buffer)
7805             ;; Remove some headers that may lead nndoc to make
7806             ;; the wrong guess.
7807             (message-narrow-to-head)
7808             (goto-char (point-min))
7809             (delete-matching-lines "^\\(Path\\):\\|^From ")
7810             (widen)
7811             (if (setq egroup
7812                       (gnus-group-read-ephemeral-group
7813                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7814                                      (nndoc-article-type guess))
7815                        t nil t))
7816                 (progn
7817                   ;; Make all postings to this group go to the parent group.
7818                   (nconc (gnus-info-params (gnus-get-info egroup))
7819                          params)
7820                   (push egroup groups))
7821               ;; Couldn't select this doc group.
7822               (gnus-error 3 "Article couldn't be entered"))))))
7823     ;; Now we have selected all the documents.
7824     (cond
7825      ((not groups)
7826       (error "None of the articles could be interpreted as documents"))
7827      ((gnus-group-read-ephemeral-group
7828        (setq vgroup (format
7829                      "nnvirtual:%s-%s" gnus-newsgroup-name
7830                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7831        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7832        t
7833        (cons (current-buffer) 'summary)))
7834      (t
7835       (error "Couldn't select virtual nndoc group")))))
7836
7837 (defun gnus-summary-isearch-article (&optional regexp-p)
7838   "Do incremental search forward on the current article.
7839 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7840   (interactive "P")
7841   (let* ((gnus-inhibit-treatment t)
7842          (old (gnus-summary-select-article)))
7843     (gnus-configure-windows 'article)
7844     (gnus-eval-in-buffer-window gnus-article-buffer
7845       (save-restriction
7846         (widen)
7847         (when (eq 'old old)
7848           (gnus-article-show-all-headers))
7849         (goto-char (point-min))
7850         (isearch-forward regexp-p)))))
7851
7852 (defun gnus-summary-search-article-forward (regexp &optional backward)
7853   "Search for an article containing REGEXP forward.
7854 If BACKWARD, search backward instead."
7855   (interactive
7856    (list (read-string
7857           (format "Search article %s (regexp%s): "
7858                   (if current-prefix-arg "backward" "forward")
7859                   (if gnus-last-search-regexp
7860                       (concat ", default " gnus-last-search-regexp)
7861                     "")))
7862          current-prefix-arg))
7863   (if (string-equal regexp "")
7864       (setq regexp (or gnus-last-search-regexp ""))
7865     (setq gnus-last-search-regexp regexp)
7866     (setq gnus-article-before-search gnus-current-article))
7867   ;; Intentionally set gnus-last-article.
7868   (setq gnus-last-article gnus-article-before-search)
7869   (let ((gnus-last-article gnus-last-article))
7870     (if (gnus-summary-search-article regexp backward)
7871         (gnus-summary-show-thread)
7872       (error "Search failed: \"%s\"" regexp))))
7873
7874 (defun gnus-summary-search-article-backward (regexp)
7875   "Search for an article containing REGEXP backward."
7876   (interactive
7877    (list (read-string
7878           (format "Search article backward (regexp%s): "
7879                   (if gnus-last-search-regexp
7880                       (concat ", default " gnus-last-search-regexp)
7881                     "")))))
7882   (gnus-summary-search-article-forward regexp 'backward))
7883
7884 (eval-when-compile
7885   (defmacro gnus-summary-search-article-position-point (regexp backward)
7886     "Dehighlight the last matched text and goto the beginning position."
7887     (` (if (and gnus-summary-search-article-matched-data
7888                 (let ((text (caddr gnus-summary-search-article-matched-data))
7889                       (inhibit-read-only t)
7890                       buffer-read-only)
7891                   (delete-region
7892                    (goto-char (car gnus-summary-search-article-matched-data))
7893                    (cadr gnus-summary-search-article-matched-data))
7894                   (insert text)
7895                   (string-match (, regexp) text)))
7896            (if (, backward) (beginning-of-line) (end-of-line))
7897          (goto-char (if (, backward) (point-max) (point-min))))))
7898
7899   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7900     "Place point where X-Face image is displayed."
7901     (if (featurep 'xemacs)
7902         (` (let ((end (if (search-forward "\n\n" nil t)
7903                           (goto-char (1- (point)))
7904                         (point-min)))
7905                  extent)
7906              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7907              (unless (and (re-search-forward "^From:" end t)
7908                           (setq extent (extent-at (point)))
7909                           (extent-begin-glyph extent))
7910                (goto-char (, opoint)))))
7911       (` (let ((end (if (search-forward "\n\n" nil t)
7912                         (goto-char (1- (point)))
7913                       (point-min)))
7914                (start (or (search-backward "\n\n" nil t) (point-min))))
7915            (goto-char
7916             (or (text-property-any start end 'x-face-image t);; x-face-e21
7917                 (text-property-any start end 'x-face-mule-bitmap-image t)
7918                 (, opoint)))))))
7919
7920   (defmacro gnus-summary-search-article-highlight-matched-text
7921     (backward treated x-face)
7922     "Highlight matched text in the function `gnus-summary-search-article'."
7923     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7924              (end (set-marker (make-marker) (match-end 0)))
7925              (inhibit-read-only t)
7926              buffer-read-only)
7927          (unless treated
7928            (let ((,@
7929                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7930                     (mapcar
7931                      (lambda (item) (setq items (delq item items)))
7932                      '(gnus-treat-buttonize
7933                        gnus-treat-fill-article
7934                        gnus-treat-fill-long-lines
7935                        gnus-treat-emphasize
7936                        gnus-treat-highlight-headers
7937                        gnus-treat-highlight-citation
7938                        gnus-treat-highlight-signature
7939                        gnus-treat-overstrike
7940                        gnus-treat-display-xface
7941                        gnus-treat-buttonize-head
7942                        gnus-treat-decode-article-as-default-mime-charset))
7943                     (static-if (featurep 'xemacs)
7944                         items
7945                       (cons '(x-face-mule-delete-x-face-field
7946                               (quote never))
7947                             items))))
7948                  (gnus-treat-display-xface
7949                   (when (, x-face) gnus-treat-display-xface)))
7950              (gnus-article-prepare-mime-display)))
7951          (goto-char (if (, backward) start end))
7952          (when (, x-face)
7953            (gnus-summary-search-article-highlight-goto-x-face (point)))
7954          (setq gnus-summary-search-article-matched-data
7955                (list start end (buffer-substring start end)))
7956          (unless (eq start end);; matched text has been deleted. :-<
7957            (put-text-property start end 'face
7958                               (or (find-face 'isearch)
7959                                   'secondary-selection))))))
7960   )
7961
7962 (defun gnus-summary-search-article (regexp &optional backward)
7963   "Search for an article containing REGEXP.
7964 Optional argument BACKWARD means do search for backward.
7965 `gnus-select-article-hook' is not called during the search."
7966   ;; We have to require this here to make sure that the following
7967   ;; dynamic binding isn't shadowed by autoloading.
7968   (require 'gnus-async)
7969   (require 'gnus-art)
7970   (let ((gnus-select-article-hook nil)  ;Disable hook.
7971         (gnus-article-prepare-hook nil)
7972         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7973         (gnus-use-article-prefetch nil)
7974         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7975         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7976         (sum (current-buffer))
7977         (found nil)
7978         point treated)
7979     (gnus-save-hidden-threads
7980       (static-if (featurep 'xemacs)
7981           (let ((gnus-inhibit-treatment t))
7982             (setq treated (eq 'old (gnus-summary-select-article)))
7983             (when (and treated
7984                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7985                                  (window-live-p (get-buffer-window
7986                                                  gnus-article-buffer t)))))
7987               (gnus-summary-select-article nil t)
7988               (setq treated nil)))
7989         (let ((gnus-inhibit-treatment t)
7990               (x-face-mule-delete-x-face-field 'never))
7991           (setq treated (eq 'old (gnus-summary-select-article)))
7992           (when (and treated
7993                      (not
7994                       (and (gnus-buffer-live-p gnus-article-buffer)
7995                            (window-live-p (get-buffer-window
7996                                            gnus-article-buffer t))
7997                            (or (not (string-match "^\\^X-Face:" regexp))
7998                                (with-current-buffer gnus-article-buffer
7999                                  gnus-summary-search-article-matched-data)))))
8000             (gnus-summary-select-article nil t)
8001             (setq treated nil))))
8002       (set-buffer gnus-article-buffer)
8003       (widen)
8004       (if treated
8005           (progn
8006             (gnus-article-show-all-headers)
8007             (gnus-summary-search-article-position-point regexp backward))
8008         (goto-char (if backward (point-max) (point-min))))
8009       (while (not found)
8010         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8011         (if (if backward
8012                 (re-search-backward regexp nil t)
8013               (re-search-forward regexp nil t))
8014             ;; We found the regexp.
8015             (progn
8016               (gnus-summary-search-article-highlight-matched-text
8017                backward treated (string-match "^\\^X-Face:" regexp))
8018               (setq found 'found)
8019               (forward-line
8020                (/ (- 2 (window-height
8021                         (get-buffer-window gnus-article-buffer t)))
8022                   2))
8023               (set-window-start
8024                (get-buffer-window (current-buffer))
8025                (point))
8026               (set-buffer sum)
8027               (setq point (point)))
8028           ;; We didn't find it, so we go to the next article.
8029           (set-buffer sum)
8030           (setq found 'not)
8031           (while (eq found 'not)
8032             (if (not (if backward (gnus-summary-find-prev)
8033                        (gnus-summary-find-next)))
8034                 ;; No more articles.
8035                 (setq found t)
8036               ;; Select the next article and adjust point.
8037               (unless (gnus-summary-article-sparse-p
8038                        (gnus-summary-article-number))
8039                 (setq found nil)
8040                 (let ((gnus-inhibit-treatment t))
8041                   (gnus-summary-select-article))
8042                 (setq treated nil)
8043                 (set-buffer gnus-article-buffer)
8044                 (widen)
8045                 (goto-char (if backward (point-max) (point-min))))))))
8046       (gnus-message 7 ""))
8047     ;; Return whether we found the regexp.
8048     (when (eq found 'found)
8049       (goto-char point)
8050       (gnus-summary-show-thread)
8051       (gnus-summary-goto-subject gnus-current-article)
8052       (gnus-summary-position-point)
8053       t)))
8054
8055 (defun gnus-find-matching-articles (header regexp)
8056   "Return a list of all articles that match REGEXP on HEADER.
8057 This search includes all articles in the current group that Gnus has
8058 fetched headers for, whether they are displayed or not."
8059   (let ((articles nil)
8060         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8061         (case-fold-search t))
8062     (dolist (header gnus-newsgroup-headers)
8063       (when (string-match regexp (funcall func header))
8064         (push (mail-header-number header) articles)))
8065     (nreverse articles)))
8066
8067 (defun gnus-summary-find-matching (header regexp &optional backward unread
8068                                           not-case-fold not-matching)
8069   "Return a list of all articles that match REGEXP on HEADER.
8070 The search stars on the current article and goes forwards unless
8071 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8072 If UNREAD is non-nil, only unread articles will
8073 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8074 in the comparisons. If NOT-MATCHING, return a list of all articles that
8075 not match REGEXP on HEADER."
8076   (let ((case-fold-search (not not-case-fold))
8077         articles d func)
8078     (if (consp header)
8079         (if (eq (car header) 'extra)
8080             (setq func
8081                   `(lambda (h)
8082                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8083                          "")))
8084           (error "%s is an invalid header" header))
8085       (unless (fboundp (intern (concat "mail-header-" header)))
8086         (error "%s is not a valid header" header))
8087       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8088     (dolist (d (if (eq backward 'all)
8089                    gnus-newsgroup-data
8090                  (gnus-data-find-list
8091                   (gnus-summary-article-number)
8092                   (gnus-data-list backward))))
8093       (when (and (or (not unread)       ; We want all articles...
8094                      (gnus-data-unread-p d)) ; Or just unreads.
8095                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8096                  (if not-matching
8097                      (not (string-match
8098                            regexp
8099                            (funcall func (gnus-data-header d))))
8100                    (string-match regexp
8101                                  (funcall func (gnus-data-header d)))))
8102         (push (gnus-data-number d) articles))) ; Success!
8103     (nreverse articles)))
8104
8105 (defun gnus-summary-execute-command (header regexp command &optional backward)
8106   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8107 If HEADER is an empty string (or nil), the match is done on the entire
8108 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8109   (interactive
8110    (list (let ((completion-ignore-case t))
8111            (completing-read
8112             "Header name: "
8113             (mapcar (lambda (header) (list (format "%s" header)))
8114                     (append
8115                      '("Number" "Subject" "From" "Lines" "Date"
8116                        "Message-ID" "Xref" "References" "Body")
8117                      gnus-extra-headers))
8118             nil 'require-match))
8119          (read-string "Regexp: ")
8120          (read-key-sequence "Command: ")
8121          current-prefix-arg))
8122   (when (equal header "Body")
8123     (setq header ""))
8124   ;; Hidden thread subtrees must be searched as well.
8125   (gnus-summary-show-all-threads)
8126   ;; We don't want to change current point nor window configuration.
8127   (save-excursion
8128     (save-window-excursion
8129       (gnus-message 6 "Executing %s..." (key-description command))
8130       ;; We'd like to execute COMMAND interactively so as to give arguments.
8131       (gnus-execute header regexp
8132                     `(call-interactively ',(key-binding command))
8133                     backward)
8134       (gnus-message 6 "Executing %s...done" (key-description command)))))
8135
8136 (defun gnus-summary-beginning-of-article ()
8137   "Scroll the article back to the beginning."
8138   (interactive)
8139   (gnus-summary-select-article)
8140   (gnus-configure-windows 'article)
8141   (gnus-eval-in-buffer-window gnus-article-buffer
8142     (widen)
8143     (goto-char (point-min))
8144     (when gnus-page-broken
8145       (gnus-narrow-to-page))))
8146
8147 (defun gnus-summary-end-of-article ()
8148   "Scroll to the end of the article."
8149   (interactive)
8150   (gnus-summary-select-article)
8151   (gnus-configure-windows 'article)
8152   (gnus-eval-in-buffer-window gnus-article-buffer
8153     (widen)
8154     (goto-char (point-max))
8155     (recenter -3)
8156     (when gnus-page-broken
8157       (gnus-narrow-to-page))))
8158
8159 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8160   "Truncate to LEN and quote all \"(\"'s in STRING."
8161   (gnus-replace-in-string (if (and len (> (length string) len))
8162                               (substring string 0 len)
8163                             string)
8164                           "[()]" "\\\\\\&"))
8165
8166 (defun gnus-summary-print-article (&optional filename n)
8167   "Generate and print a PostScript image of the N next (mail) articles.
8168
8169 If N is negative, print the N previous articles.  If N is nil and articles
8170 have been marked with the process mark, print these instead.
8171
8172 If the optional first argument FILENAME is nil, send the image to the
8173 printer.  If FILENAME is a string, save the PostScript image in a file with
8174 that name.  If FILENAME is a number, prompt the user for the name of the file
8175 to save in."
8176   (interactive (list (ps-print-preprint current-prefix-arg)))
8177   (dolist (article (gnus-summary-work-articles n))
8178     (gnus-summary-select-article nil nil 'pseudo article)
8179     (gnus-eval-in-buffer-window gnus-article-buffer
8180       (gnus-print-buffer))
8181     (gnus-summary-remove-process-mark article))
8182   (ps-despool filename))
8183
8184 (defun gnus-print-buffer ()
8185   (let ((buffer (generate-new-buffer " *print*")))
8186     (unwind-protect
8187         (progn
8188           (copy-to-buffer buffer (point-min) (point-max))
8189           (set-buffer buffer)
8190           (gnus-article-delete-invisible-text)
8191           (when (gnus-visual-p 'article-highlight 'highlight)
8192             ;; Copy-to-buffer doesn't copy overlay.  So redo
8193             ;; highlight.
8194             (let ((gnus-article-buffer buffer))
8195               (gnus-article-highlight-citation t)
8196               (gnus-article-highlight-signature)))
8197           (let ((ps-left-header
8198                  (list
8199                   (concat "("
8200                           (gnus-summary-print-truncate-and-quote
8201                            (mail-header-subject gnus-current-headers)
8202                            66) ")")
8203                   (concat "("
8204                           (gnus-summary-print-truncate-and-quote
8205                            (mail-header-from gnus-current-headers)
8206                            45) ")")))
8207                 (ps-right-header
8208                  (list
8209                   "/pagenumberstring load"
8210                   (concat "("
8211                           (mail-header-date gnus-current-headers) ")"))))
8212             (gnus-run-hooks 'gnus-ps-print-hook)
8213             (save-excursion
8214               (if window-system
8215                   (ps-spool-buffer-with-faces)
8216                 (ps-spool-buffer)))))
8217       (kill-buffer buffer))))
8218
8219 (defun gnus-summary-show-article (&optional arg)
8220   "Force redisplaying of the current article.
8221 If ARG (the prefix) is a number, show the article with the charset
8222 defined in `gnus-summary-show-article-charset-alist', or the charset
8223 input.
8224 If ARG (the prefix) is non-nil and not a number, show the raw article
8225 without any article massaging functions being run.  Normally, the key strokes
8226 are `C-u g'."
8227   (interactive "P")
8228   (cond
8229    ((numberp arg)
8230     (gnus-summary-show-article t)
8231     (let* ((gnus-newsgroup-charset
8232             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8233                 (mm-read-coding-system
8234                  "View as charset: " ;; actually it is coding system.
8235                  (save-excursion
8236                    (set-buffer gnus-article-buffer)
8237                    (mm-detect-coding-region (point) (point-max))))))
8238            (default-mime-charset gnus-newsgroup-charset)
8239            (gnus-newsgroup-ignored-charsets 'gnus-all))
8240       (gnus-summary-select-article nil 'force)
8241       (let ((deps gnus-newsgroup-dependencies)
8242             head header lines)
8243         (save-excursion
8244           (set-buffer gnus-original-article-buffer)
8245           (save-restriction
8246             (message-narrow-to-head)
8247             (setq head (buffer-string))
8248             (goto-char (point-min))
8249             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8250               (goto-char (point-max))
8251               (widen)
8252               (setq lines (1- (count-lines (point) (point-max))))))
8253           (with-temp-buffer
8254             (insert (format "211 %d Article retrieved.\n"
8255                             (cdr gnus-article-current)))
8256             (insert head)
8257             (if lines (insert (format "Lines: %d\n" lines)))
8258             (insert ".\n")
8259             (let ((nntp-server-buffer (current-buffer)))
8260               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8261         (gnus-data-set-header
8262          (gnus-data-find (cdr gnus-article-current))
8263          header)
8264         (gnus-summary-update-article-line
8265          (cdr gnus-article-current) header)
8266         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8267           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8268    ((not arg)
8269     ;; Select the article the normal way.
8270     (gnus-summary-select-article nil 'force))
8271    (t
8272     ;; We have to require this here to make sure that the following
8273     ;; dynamic binding isn't shadowed by autoloading.
8274     (require 'gnus-async)
8275     (require 'gnus-art)
8276     ;; Bind the article treatment functions to nil.
8277     (let ((gnus-have-all-headers t)
8278           gnus-article-prepare-hook
8279           gnus-article-decode-hook
8280           gnus-break-pages
8281           gnus-show-mime
8282           (gnus-inhibit-treatment t))
8283       (gnus-summary-select-article nil 'force))))
8284   (gnus-summary-goto-subject gnus-current-article)
8285   (gnus-summary-position-point))
8286
8287 (defun gnus-summary-show-raw-article ()
8288   "Show the raw article without any article massaging functions being run."
8289   (interactive)
8290   (gnus-summary-show-article t))
8291
8292 (defun gnus-summary-verbose-headers (&optional arg)
8293   "Toggle permanent full header display.
8294 If ARG is a positive number, turn header display on.
8295 If ARG is a negative number, turn header display off."
8296   (interactive "P")
8297   (setq gnus-show-all-headers
8298         (cond ((or (not (numberp arg))
8299                    (zerop arg))
8300                (not gnus-show-all-headers))
8301               ((natnump arg)
8302                t)))
8303   (gnus-summary-show-article))
8304
8305 (defun gnus-summary-toggle-header (&optional arg)
8306   "Show the headers if they are hidden, or hide them if they are shown.
8307 If ARG is a positive number, show the entire header.
8308 If ARG is a negative number, hide the unwanted header lines."
8309   (interactive "P")
8310   (save-excursion
8311     (set-buffer gnus-article-buffer)
8312     (save-restriction
8313       (let* ((buffer-read-only nil)
8314              (inhibit-point-motion-hooks t)
8315              hidden e)
8316         (setq hidden
8317               (if (numberp arg)
8318                   (>= arg 0)
8319                 (save-restriction
8320                   (article-narrow-to-head)
8321                   (gnus-article-hidden-text-p 'headers))))
8322         (goto-char (point-min))
8323         (when (search-forward "\n\n" nil t)
8324           (delete-region (point-min) (1- (point))))
8325         (goto-char (point-min))
8326         (save-excursion
8327           (set-buffer gnus-original-article-buffer)
8328           (goto-char (point-min))
8329           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8330         (insert-buffer-substring gnus-original-article-buffer 1 e)
8331         (save-restriction
8332           (narrow-to-region (point-min) (point))
8333           (article-decode-encoded-words)
8334           (if  hidden
8335               (let ((gnus-treat-hide-headers nil)
8336                     (gnus-treat-hide-boring-headers nil))
8337                 (gnus-delete-wash-type 'headers)
8338                 (gnus-treat-article 'head))
8339             (gnus-treat-article 'head)))
8340         (gnus-set-mode-line 'article)))))
8341
8342 (defun gnus-summary-show-all-headers ()
8343   "Make all header lines visible."
8344   (interactive)
8345   (gnus-summary-toggle-header 1))
8346
8347 (defun gnus-summary-toggle-mime (&optional arg)
8348   "Toggle MIME processing.
8349 If ARG is a positive number, turn MIME processing on."
8350   (interactive "P")
8351   (setq gnus-show-mime
8352         (if (null arg)
8353             (not gnus-show-mime)
8354           (> (prefix-numeric-value arg) 0)))
8355   (gnus-summary-select-article t 'force))
8356
8357 (defun gnus-summary-caesar-message (&optional arg)
8358   "Caesar rotate the current article by 13.
8359 The numerical prefix specifies how many places to rotate each letter
8360 forward."
8361   (interactive "P")
8362   (gnus-summary-select-article)
8363   (let ((mail-header-separator ""))
8364     (gnus-eval-in-buffer-window gnus-article-buffer
8365       (save-restriction
8366         (widen)
8367         (let ((start (window-start))
8368               buffer-read-only)
8369           (message-caesar-buffer-body arg)
8370           (set-window-start (get-buffer-window (current-buffer)) start))))))
8371
8372 (defun gnus-summary-stop-page-breaking ()
8373   "Stop page breaking in the current article."
8374   (interactive)
8375   (gnus-summary-select-article)
8376   (gnus-eval-in-buffer-window gnus-article-buffer
8377     (widen)
8378     (when (gnus-visual-p 'page-marker)
8379       (let ((buffer-read-only nil))
8380         (gnus-remove-text-with-property 'gnus-prev)
8381         (gnus-remove-text-with-property 'gnus-next))
8382       (setq gnus-page-broken nil))))
8383
8384 (defun gnus-summary-move-article (&optional n to-newsgroup
8385                                             select-method action)
8386   "Move the current article to a different newsgroup.
8387 If N is a positive number, move the N next articles.
8388 If N is a negative number, move the N previous articles.
8389 If N is nil and any articles have been marked with the process mark,
8390 move those articles instead.
8391 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8392 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8393 re-spool using this method.
8394
8395 For this function to work, both the current newsgroup and the
8396 newsgroup that you want to move to have to support the `request-move'
8397 and `request-accept' functions.
8398
8399 ACTION can be either `move' (the default), `crosspost' or `copy'."
8400   (interactive "P")
8401   (unless action
8402     (setq action 'move))
8403   ;; Check whether the source group supports the required functions.
8404   (cond ((and (eq action 'move)
8405               (not (gnus-check-backend-function
8406                     'request-move-article gnus-newsgroup-name)))
8407          (error "The current group does not support article moving"))
8408         ((and (eq action 'crosspost)
8409               (not (gnus-check-backend-function
8410                     'request-replace-article gnus-newsgroup-name)))
8411          (error "The current group does not support article editing")))
8412   (let ((articles (gnus-summary-work-articles n))
8413         (prefix (if (gnus-check-backend-function
8414                      'request-move-article gnus-newsgroup-name)
8415                     (gnus-group-real-prefix gnus-newsgroup-name)
8416                   ""))
8417         (names '((move "Move" "Moving")
8418                  (copy "Copy" "Copying")
8419                  (crosspost "Crosspost" "Crossposting")))
8420         (copy-buf (save-excursion
8421                     (nnheader-set-temp-buffer " *copy article*")))
8422         (default-marks gnus-article-mark-lists)
8423         (no-expire-marks (delete '(expirable . expire)
8424                                  (copy-sequence gnus-article-mark-lists)))
8425         art-group to-method new-xref article to-groups)
8426     (unless (assq action names)
8427       (error "Unknown action %s" action))
8428     ;; We have to select an article to give
8429     ;; `gnus-read-move-group-name' an opportunity to suggest an
8430     ;; appropriate default.
8431     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8432       (let ((gnus-display-mime-function nil)
8433             (gnus-article-prepare-hook nil))
8434         (gnus-summary-select-article nil nil nil (car articles))))
8435     ;; Read the newsgroup name.
8436     (when (and (not to-newsgroup)
8437                (not select-method))
8438       (setq to-newsgroup
8439             (gnus-read-move-group-name
8440              (cadr (assq action names))
8441              (symbol-value (intern (format "gnus-current-%s-group" action)))
8442              articles prefix))
8443       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8444     (setq to-method (or select-method
8445                         (gnus-server-to-method
8446                          (gnus-group-method to-newsgroup))))
8447     ;; Check the method we are to move this article to...
8448     (unless (gnus-check-backend-function
8449              'request-accept-article (car to-method))
8450       (error "%s does not support article copying" (car to-method)))
8451     (unless (gnus-check-server to-method)
8452       (error "Can't open server %s" (car to-method)))
8453     (gnus-message 6 "%s to %s: %s..."
8454                   (caddr (assq action names))
8455                   (or (car select-method) to-newsgroup) articles)
8456     (while articles
8457       (setq article (pop articles))
8458       (setq
8459        art-group
8460        (cond
8461         ;; Move the article.
8462         ((eq action 'move)
8463          ;; Remove this article from future suppression.
8464          (gnus-dup-unsuppress-article article)
8465          (gnus-request-move-article
8466           article                       ; Article to move
8467           gnus-newsgroup-name           ; From newsgroup
8468           (nth 1 (gnus-find-method-for-group
8469                   gnus-newsgroup-name)) ; Server
8470           (list 'gnus-request-accept-article
8471                 to-newsgroup (list 'quote select-method)
8472                 (not articles) t)       ; Accept form
8473           (not articles)))              ; Only save nov last time
8474         ;; Copy the article.
8475         ((eq action 'copy)
8476          (save-excursion
8477            (set-buffer copy-buf)
8478            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8479              (gnus-request-accept-article
8480               to-newsgroup select-method (not articles) t))))
8481         ;; Crosspost the article.
8482         ((eq action 'crosspost)
8483          (let ((xref (message-tokenize-header
8484                       (mail-header-xref (gnus-summary-article-header article))
8485                       " ")))
8486            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8487                                   ":" (number-to-string article)))
8488            (unless xref
8489              (setq xref (list (system-name))))
8490            (setq new-xref
8491                  (concat
8492                   (mapconcat 'identity
8493                              (delete "Xref:" (delete new-xref xref))
8494                              " ")
8495                   " " new-xref))
8496            (save-excursion
8497              (set-buffer copy-buf)
8498              ;; First put the article in the destination group.
8499              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8500              (when (consp (setq art-group
8501                                 (gnus-request-accept-article
8502                                  to-newsgroup select-method (not articles))))
8503                (setq new-xref (concat new-xref " " (car art-group)
8504                                       ":"
8505                                       (number-to-string (cdr art-group))))
8506                ;; Now we have the new Xrefs header, so we insert
8507                ;; it and replace the new article.
8508                (nnheader-replace-header "Xref" new-xref)
8509                (gnus-request-replace-article
8510                 (cdr art-group) to-newsgroup (current-buffer))
8511                art-group))))))
8512       (cond
8513        ((not art-group)
8514         (gnus-message 1 "Couldn't %s article %s: %s"
8515                       (cadr (assq action names)) article
8516                       (nnheader-get-report (car to-method))))
8517        ((eq art-group 'junk)
8518         (when (eq action 'move)
8519           (gnus-summary-mark-article article gnus-canceled-mark)
8520           (gnus-message 4 "Deleted article %s" article)))
8521        (t
8522         (let* ((pto-group (gnus-group-prefixed-name
8523                            (car art-group) to-method))
8524                (entry
8525                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8526                (info (nth 2 entry))
8527                (to-group (gnus-info-group info))
8528                to-marks)
8529           ;; Update the group that has been moved to.
8530           (when (and info
8531                      (memq action '(move copy)))
8532             (unless (member to-group to-groups)
8533               (push to-group to-groups))
8534
8535             (unless (memq article gnus-newsgroup-unreads)
8536               (push 'read to-marks)
8537               (gnus-info-set-read
8538                info (gnus-add-to-range (gnus-info-read info)
8539                                        (list (cdr art-group)))))
8540
8541             ;; See whether the article is to be put in the cache.
8542             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8543                              default-marks
8544                            no-expire-marks))
8545                   (to-article (cdr art-group)))
8546
8547               ;; Enter the article into the cache in the new group,
8548               ;; if that is required.
8549               (when gnus-use-cache
8550                 (gnus-cache-possibly-enter-article
8551                  to-group to-article
8552                  (let ((header (copy-sequence
8553                                 (gnus-summary-article-header article))))
8554                    (mail-header-set-number header to-article)
8555                    header)
8556                  (memq article gnus-newsgroup-marked)
8557                  (memq article gnus-newsgroup-dormant)
8558                  (memq article gnus-newsgroup-unreads)))
8559
8560               (when gnus-preserve-marks
8561                 ;; Copy any marks over to the new group.
8562                 (when (and (equal to-group gnus-newsgroup-name)
8563                            (not (memq article gnus-newsgroup-unreads)))
8564                   ;; Mark this article as read in this group.
8565                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8566                   (setcdr (gnus-active to-group) to-article)
8567                   (setcdr gnus-newsgroup-active to-article))
8568
8569                 (while marks
8570                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8571                     (when (memq article (symbol-value
8572                                          (intern (format "gnus-newsgroup-%s"
8573                                                          (caar marks)))))
8574                       (push (cdar marks) to-marks)
8575                       ;; If the other group is the same as this group,
8576                       ;; then we have to add the mark to the list.
8577                       (when (equal to-group gnus-newsgroup-name)
8578                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8579                              (cons to-article
8580                                    (symbol-value
8581                                     (intern (format "gnus-newsgroup-%s"
8582                                                     (caar marks)))))))
8583                       ;; Copy the marks to other group.
8584                       (gnus-add-marked-articles
8585                        to-group (cdar marks) (list to-article) info)))
8586                   (setq marks (cdr marks)))
8587
8588                 (gnus-request-set-mark to-group (list (list (list to-article)
8589                                                             'add
8590                                                             to-marks))))
8591
8592               (gnus-dribble-enter
8593                (concat "(gnus-group-set-info '"
8594                        (gnus-prin1-to-string (gnus-get-info to-group))
8595                        ")"))))
8596
8597           ;; Update the Xref header in this article to point to
8598           ;; the new crossposted article we have just created.
8599           (when (eq action 'crosspost)
8600             (save-excursion
8601               (set-buffer copy-buf)
8602               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8603               (nnheader-replace-header "Xref" new-xref)
8604               (gnus-request-replace-article
8605                article gnus-newsgroup-name (current-buffer)))))
8606
8607         ;;;!!!Why is this necessary?
8608         (set-buffer gnus-summary-buffer)
8609
8610         (gnus-summary-goto-subject article)
8611         (when (eq action 'move)
8612           (gnus-summary-mark-article article gnus-canceled-mark))))
8613       (gnus-summary-remove-process-mark article))
8614     ;; Re-activate all groups that have been moved to.
8615     (save-excursion
8616       (set-buffer gnus-group-buffer)
8617       (let ((gnus-group-marked to-groups))
8618         (gnus-group-get-new-news-this-group nil t)))
8619
8620     (gnus-kill-buffer copy-buf)
8621     (gnus-summary-position-point)
8622     (gnus-set-mode-line 'summary)))
8623
8624 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8625   "Move the current article to a different newsgroup.
8626 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8627 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8628 re-spool using this method."
8629   (interactive "P")
8630   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8631
8632 (defun gnus-summary-crosspost-article (&optional n)
8633   "Crosspost the current article to some other group."
8634   (interactive "P")
8635   (gnus-summary-move-article n nil nil 'crosspost))
8636
8637 (defcustom gnus-summary-respool-default-method nil
8638   "Default method type for respooling an article.
8639 If nil, use to the current newsgroup method."
8640   :type 'symbol
8641   :group 'gnus-summary-mail)
8642
8643 (defun gnus-summary-respool-article (&optional n method)
8644   "Respool the current article.
8645 The article will be squeezed through the mail spooling process again,
8646 which means that it will be put in some mail newsgroup or other
8647 depending on `nnmail-split-methods'.
8648 If N is a positive number, respool the N next articles.
8649 If N is a negative number, respool the N previous articles.
8650 If N is nil and any articles have been marked with the process mark,
8651 respool those articles instead.
8652
8653 Respooling can be done both from mail groups and \"real\" newsgroups.
8654 In the former case, the articles in question will be moved from the
8655 current group into whatever groups they are destined to.  In the
8656 latter case, they will be copied into the relevant groups."
8657   (interactive
8658    (list current-prefix-arg
8659          (let* ((methods (gnus-methods-using 'respool))
8660                 (methname
8661                  (symbol-name (or gnus-summary-respool-default-method
8662                                   (car (gnus-find-method-for-group
8663                                         gnus-newsgroup-name)))))
8664                 (method
8665                  (gnus-completing-read-with-default
8666                   methname "What backend do you want to use when respooling?"
8667                   methods nil t nil 'gnus-mail-method-history))
8668                 ms)
8669            (cond
8670             ((zerop (length (setq ms (gnus-servers-using-backend
8671                                       (intern method)))))
8672              (list (intern method) ""))
8673             ((= 1 (length ms))
8674              (car ms))
8675             (t
8676              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8677                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8678                            ms-alist))))))))
8679   (unless method
8680     (error "No method given for respooling"))
8681   (if (assoc (symbol-name
8682               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8683              (gnus-methods-using 'respool))
8684       (gnus-summary-move-article n nil method)
8685     (gnus-summary-copy-article n nil method)))
8686
8687 (defun gnus-summary-import-article (file &optional edit)
8688   "Import an arbitrary file into a mail newsgroup."
8689   (interactive "fImport file: \nP")
8690   (let ((group gnus-newsgroup-name)
8691         (now (current-time))
8692         atts lines group-art)
8693     (unless (gnus-check-backend-function 'request-accept-article group)
8694       (error "%s does not support article importing" group))
8695     (or (file-readable-p file)
8696         (not (file-regular-p file))
8697         (error "Can't read %s" file))
8698     (save-excursion
8699       (set-buffer (gnus-get-buffer-create " *import file*"))
8700       (erase-buffer)
8701       (nnheader-insert-file-contents file)
8702       (goto-char (point-min))
8703       (if (nnheader-article-p)
8704           (save-restriction
8705             (goto-char (point-min))
8706             (search-forward "\n\n" nil t)
8707             (narrow-to-region (point-min) (1- (point)))
8708             (goto-char (point-min))
8709             (unless (re-search-forward "^date:" nil t)
8710               (goto-char (point-max))
8711               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8712         ;; This doesn't look like an article, so we fudge some headers.
8713         (setq atts (file-attributes file)
8714               lines (count-lines (point-min) (point-max)))
8715         (insert "From: " (read-string "From: ") "\n"
8716                 "Subject: " (read-string "Subject: ") "\n"
8717                 "Date: " (message-make-date (nth 5 atts)) "\n"
8718                 "Message-ID: " (message-make-message-id) "\n"
8719                 "Lines: " (int-to-string lines) "\n"
8720                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8721       (setq group-art (gnus-request-accept-article group nil t))
8722       (kill-buffer (current-buffer)))
8723     (setq gnus-newsgroup-active (gnus-activate-group group))
8724     (forward-line 1)
8725     (gnus-summary-goto-article (cdr group-art) nil t)
8726     (when edit
8727       (gnus-summary-edit-article))))
8728
8729 (defun gnus-summary-create-article ()
8730   "Create an article in a mail newsgroup."
8731   (interactive)
8732   (let ((group gnus-newsgroup-name)
8733         (now (current-time))
8734         group-art)
8735     (unless (gnus-check-backend-function 'request-accept-article group)
8736       (error "%s does not support article importing" group))
8737     (save-excursion
8738       (set-buffer (gnus-get-buffer-create " *import file*"))
8739       (erase-buffer)
8740       (goto-char (point-min))
8741       ;; This doesn't look like an article, so we fudge some headers.
8742       (insert "From: " (read-string "From: ") "\n"
8743               "Subject: " (read-string "Subject: ") "\n"
8744               "Date: " (message-make-date now) "\n"
8745               "Message-ID: " (message-make-message-id) "\n")
8746       (setq group-art (gnus-request-accept-article group nil t))
8747       (kill-buffer (current-buffer)))
8748     (setq gnus-newsgroup-active (gnus-activate-group group))
8749     (forward-line 1)
8750     (gnus-summary-goto-article (cdr group-art) nil t)
8751     (gnus-summary-edit-article)))
8752
8753 (defun gnus-summary-article-posted-p ()
8754   "Say whether the current (mail) article is available from news as well.
8755 This will be the case if the article has both been mailed and posted."
8756   (interactive)
8757   (let ((id (mail-header-references (gnus-summary-article-header)))
8758         (gnus-override-method (car (gnus-refer-article-methods))))
8759     (if (gnus-request-head id "")
8760         (gnus-message 2 "The current message was found on %s"
8761                       gnus-override-method)
8762       (gnus-message 2 "The current message couldn't be found on %s"
8763                     gnus-override-method)
8764       nil)))
8765
8766 (defun gnus-summary-expire-articles (&optional now)
8767   "Expire all articles that are marked as expirable in the current group."
8768   (interactive)
8769   (when (gnus-check-backend-function
8770          'request-expire-articles gnus-newsgroup-name)
8771     ;; This backend supports expiry.
8772     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8773            (expirable (if total
8774                           (progn
8775                             ;; We need to update the info for
8776                             ;; this group for `gnus-list-of-read-articles'
8777                             ;; to give us the right answer.
8778                             (gnus-run-hooks 'gnus-exit-group-hook)
8779                             (gnus-summary-update-info)
8780                             (gnus-list-of-read-articles gnus-newsgroup-name))
8781                         (setq gnus-newsgroup-expirable
8782                               (sort gnus-newsgroup-expirable '<))))
8783            (expiry-wait (if now 'immediate
8784                           (gnus-group-find-parameter
8785                            gnus-newsgroup-name 'expiry-wait)))
8786            (nnmail-expiry-target
8787             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8788                 nnmail-expiry-target))
8789            es)
8790       (when expirable
8791         ;; There are expirable articles in this group, so we run them
8792         ;; through the expiry process.
8793         (gnus-message 6 "Expiring articles...")
8794         (unless (gnus-check-group gnus-newsgroup-name)
8795           (error "Can't open server for %s" gnus-newsgroup-name))
8796         ;; The list of articles that weren't expired is returned.
8797         (save-excursion
8798           (if expiry-wait
8799               (let ((nnmail-expiry-wait-function nil)
8800                     (nnmail-expiry-wait expiry-wait))
8801                 (setq es (gnus-request-expire-articles
8802                           expirable gnus-newsgroup-name)))
8803             (setq es (gnus-request-expire-articles
8804                       expirable gnus-newsgroup-name)))
8805           (unless total
8806             (setq gnus-newsgroup-expirable es))
8807           ;; We go through the old list of expirable, and mark all
8808           ;; really expired articles as nonexistent.
8809           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8810             (let ((gnus-use-cache nil))
8811               (dolist (article expirable)
8812                 (when (and (not (memq article es))
8813                            (gnus-data-find article))
8814                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8815         (gnus-message 6 "Expiring articles...done")))))
8816
8817 (defun gnus-summary-expire-articles-now ()
8818   "Expunge all expirable articles in the current group.
8819 This means that *all* articles that are marked as expirable will be
8820 deleted forever, right now."
8821   (interactive)
8822   (or gnus-expert-user
8823       (gnus-yes-or-no-p
8824        "Are you really, really, really sure you want to delete all these messages? ")
8825       (error "Phew!"))
8826   (gnus-summary-expire-articles t))
8827
8828 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8829 (defun gnus-summary-delete-article (&optional n)
8830   "Delete the N next (mail) articles.
8831 This command actually deletes articles.  This is not a marking
8832 command.  The article will disappear forever from your life, never to
8833 return.
8834 If N is negative, delete backwards.
8835 If N is nil and articles have been marked with the process mark,
8836 delete these instead."
8837   (interactive "P")
8838   (unless (gnus-check-backend-function 'request-expire-articles
8839                                        gnus-newsgroup-name)
8840     (error "The current newsgroup does not support article deletion"))
8841   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8842     (error "Couldn't open server"))
8843   ;; Compute the list of articles to delete.
8844   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8845         not-deleted)
8846     (if (and gnus-novice-user
8847              (not (gnus-yes-or-no-p
8848                    (format "Do you really want to delete %s forever? "
8849                            (if (> (length articles) 1)
8850                                (format "these %s articles" (length articles))
8851                              "this article")))))
8852         ()
8853       ;; Delete the articles.
8854       (setq not-deleted (gnus-request-expire-articles
8855                          articles gnus-newsgroup-name 'force))
8856       (while articles
8857         (gnus-summary-remove-process-mark (car articles))
8858         ;; The backend might not have been able to delete the article
8859         ;; after all.
8860         (unless (memq (car articles) not-deleted)
8861           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8862         (setq articles (cdr articles)))
8863       (when not-deleted
8864         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8865     (gnus-summary-position-point)
8866     (gnus-set-mode-line 'summary)
8867     not-deleted))
8868
8869 (defun gnus-summary-edit-article (&optional force)
8870   "Edit the current article.
8871 This will have permanent effect only in mail groups.
8872 If FORCE is non-nil, allow editing of articles even in read-only
8873 groups."
8874   (interactive "P")
8875   (save-excursion
8876     (set-buffer gnus-summary-buffer)
8877     (let ((mail-parse-charset gnus-newsgroup-charset)
8878           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8879       (gnus-set-global-variables)
8880       (when (and (not force)
8881                  (gnus-group-read-only-p))
8882         (error "The current newsgroup does not support article editing"))
8883       (gnus-summary-show-article t)
8884       (gnus-article-edit-article
8885        'ignore
8886        `(lambda (no-highlight)
8887           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8888                 (message-options message-options)
8889                 (message-options-set-recipient)
8890                 (mail-parse-ignored-charsets
8891                  ',gnus-newsgroup-ignored-charsets))
8892             (gnus-summary-edit-article-done
8893              ,(or (mail-header-references gnus-current-headers) "")
8894              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8895
8896 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8897
8898 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8899                                                  no-highlight)
8900   "Make edits to the current article permanent."
8901   (interactive)
8902   (save-excursion
8903     ;; The buffer restriction contains the entire article if it exists.
8904     (when (article-goto-body)
8905       (let ((lines (count-lines (point) (point-max)))
8906             (length (- (point-max) (point)))
8907             (case-fold-search t)
8908             (body (copy-marker (point))))
8909         (goto-char (point-min))
8910         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8911           (delete-region (match-beginning 1) (match-end 1))
8912           (insert (number-to-string length)))
8913         (goto-char (point-min))
8914         (when (re-search-forward
8915                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8916           (delete-region (match-beginning 1) (match-end 1))
8917           (insert (number-to-string length)))
8918         (goto-char (point-min))
8919         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8920           (delete-region (match-beginning 1) (match-end 1))
8921           (insert (number-to-string lines))))))
8922   ;; Replace the article.
8923   (let ((buf (current-buffer)))
8924     (with-temp-buffer
8925       (insert-buffer-substring buf)
8926
8927       (if (and (not read-only)
8928                (not (gnus-request-replace-article
8929                      (cdr gnus-article-current) (car gnus-article-current)
8930                      (current-buffer) t)))
8931           (error "Couldn't replace article")
8932         ;; Update the summary buffer.
8933         (if (and references
8934                  (equal (message-tokenize-header references " ")
8935                         (message-tokenize-header
8936                          (or (message-fetch-field "references") "") " ")))
8937             ;; We only have to update this line.
8938             (save-excursion
8939               (save-restriction
8940                 (message-narrow-to-head)
8941                 (let ((head (buffer-string))
8942                       header)
8943                   (with-temp-buffer
8944                     (insert (format "211 %d Article retrieved.\n"
8945                                     (cdr gnus-article-current)))
8946                     (insert head)
8947                     (insert ".\n")
8948                     (let ((nntp-server-buffer (current-buffer)))
8949                       (setq header (car (gnus-get-newsgroup-headers
8950                                          (save-excursion
8951                                            (set-buffer gnus-summary-buffer)
8952                                            gnus-newsgroup-dependencies)
8953                                          t))))
8954                     (save-excursion
8955                       (set-buffer gnus-summary-buffer)
8956                       (gnus-data-set-header
8957                        (gnus-data-find (cdr gnus-article-current))
8958                        header)
8959                       (gnus-summary-update-article-line
8960                        (cdr gnus-article-current) header)
8961                       (if (gnus-summary-goto-subject
8962                            (cdr gnus-article-current) nil t)
8963                           (gnus-summary-update-secondary-mark
8964                            (cdr gnus-article-current))))))))
8965           ;; Update threads.
8966           (set-buffer (or buffer gnus-summary-buffer))
8967           (gnus-summary-update-article (cdr gnus-article-current))
8968           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8969               (gnus-summary-update-secondary-mark
8970                (cdr gnus-article-current))))
8971         ;; Prettify the article buffer again.
8972         (unless no-highlight
8973           (save-excursion
8974             (set-buffer gnus-article-buffer)
8975             ;;;!!! Fix this -- article should be rehighlighted.
8976             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8977             (set-buffer gnus-original-article-buffer)
8978             (gnus-request-article
8979              (cdr gnus-article-current)
8980              (car gnus-article-current) (current-buffer))))
8981         ;; Prettify the summary buffer line.
8982         (when (gnus-visual-p 'summary-highlight 'highlight)
8983           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8984
8985 (defun gnus-summary-edit-wash (key)
8986   "Perform editing command KEY in the article buffer."
8987   (interactive
8988    (list
8989     (progn
8990       (message "%s" (concat (this-command-keys) "- "))
8991       (read-char))))
8992   (message "")
8993   (gnus-summary-edit-article)
8994   (execute-kbd-macro (concat (this-command-keys) key))
8995   (gnus-article-edit-done))
8996
8997 ;;; Respooling
8998
8999 (defun gnus-summary-respool-query (&optional silent trace)
9000   "Query where the respool algorithm would put this article."
9001   (interactive)
9002   (let (gnus-mark-article-hook)
9003     (gnus-summary-select-article)
9004     (save-excursion
9005       (set-buffer gnus-original-article-buffer)
9006       (save-restriction
9007         (message-narrow-to-head)
9008         (let ((groups (nnmail-article-group 'identity trace)))
9009           (unless silent
9010             (if groups
9011                 (message "This message would go to %s"
9012                          (mapconcat 'car groups ", "))
9013               (message "This message would go to no groups"))
9014             groups))))))
9015
9016 (defun gnus-summary-respool-trace ()
9017   "Trace where the respool algorithm would put this article.
9018 Display a buffer showing all fancy splitting patterns which matched."
9019   (interactive)
9020   (gnus-summary-respool-query nil t))
9021
9022 ;; Summary marking commands.
9023
9024 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9025   "Mark articles which has the same subject as read, and then select the next.
9026 If UNMARK is positive, remove any kind of mark.
9027 If UNMARK is negative, tick articles."
9028   (interactive "P")
9029   (when unmark
9030     (setq unmark (prefix-numeric-value unmark)))
9031   (let ((count
9032          (gnus-summary-mark-same-subject
9033           (gnus-summary-article-subject) unmark)))
9034     ;; Select next unread article.  If auto-select-same mode, should
9035     ;; select the first unread article.
9036     (gnus-summary-next-article t (and gnus-auto-select-same
9037                                       (gnus-summary-article-subject)))
9038     (gnus-message 7 "%d article%s marked as %s"
9039                   count (if (= count 1) " is" "s are")
9040                   (if unmark "unread" "read"))))
9041
9042 (defun gnus-summary-kill-same-subject (&optional unmark)
9043   "Mark articles which has the same subject as read.
9044 If UNMARK is positive, remove any kind of mark.
9045 If UNMARK is negative, tick articles."
9046   (interactive "P")
9047   (when unmark
9048     (setq unmark (prefix-numeric-value unmark)))
9049   (let ((count
9050          (gnus-summary-mark-same-subject
9051           (gnus-summary-article-subject) unmark)))
9052     ;; If marked as read, go to next unread subject.
9053     (when (null unmark)
9054       ;; Go to next unread subject.
9055       (gnus-summary-next-subject 1 t))
9056     (gnus-message 7 "%d articles are marked as %s"
9057                   count (if unmark "unread" "read"))))
9058
9059 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9060   "Mark articles with same SUBJECT as read, and return marked number.
9061 If optional argument UNMARK is positive, remove any kinds of marks.
9062 If optional argument UNMARK is negative, mark articles as unread instead."
9063   (let ((count 1))
9064     (save-excursion
9065       (cond
9066        ((null unmark)                   ; Mark as read.
9067         (while (and
9068                 (progn
9069                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9070                   (gnus-summary-show-thread) t)
9071                 (gnus-summary-find-subject subject))
9072           (setq count (1+ count))))
9073        ((> unmark 0)                    ; Tick.
9074         (while (and
9075                 (progn
9076                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9077                   (gnus-summary-show-thread) t)
9078                 (gnus-summary-find-subject subject))
9079           (setq count (1+ count))))
9080        (t                               ; Mark as unread.
9081         (while (and
9082                 (progn
9083                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9084                   (gnus-summary-show-thread) t)
9085                 (gnus-summary-find-subject subject))
9086           (setq count (1+ count)))))
9087       (gnus-set-mode-line 'summary)
9088       ;; Return the number of marked articles.
9089       count)))
9090
9091 (defun gnus-summary-mark-as-processable (n &optional unmark)
9092   "Set the process mark on the next N articles.
9093 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9094 the process mark instead.  The difference between N and the actual
9095 number of articles marked is returned."
9096   (interactive "P")
9097   (if (and (null n) (gnus-region-active-p))
9098       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9099     (setq n (prefix-numeric-value n))
9100     (let ((backward (< n 0))
9101           (n (abs n)))
9102       (while (and
9103               (> n 0)
9104               (if unmark
9105                   (gnus-summary-remove-process-mark
9106                    (gnus-summary-article-number))
9107                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9108               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9109         (setq n (1- n)))
9110       (when (/= 0 n)
9111         (gnus-message 7 "No more articles"))
9112       (gnus-summary-recenter)
9113       (gnus-summary-position-point)
9114       n)))
9115
9116 (defun gnus-summary-unmark-as-processable (n)
9117   "Remove the process mark from the next N articles.
9118 If N is negative, unmark backward instead.  The difference between N and
9119 the actual number of articles unmarked is returned."
9120   (interactive "P")
9121   (gnus-summary-mark-as-processable n t))
9122
9123 (defun gnus-summary-unmark-all-processable ()
9124   "Remove the process mark from all articles."
9125   (interactive)
9126   (save-excursion
9127     (while gnus-newsgroup-processable
9128       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9129   (gnus-summary-position-point))
9130
9131 (defun gnus-summary-add-mark (article type)
9132   "Mark ARTICLE with a mark of TYPE."
9133   (let ((vtype (car (assq type gnus-article-mark-lists)))
9134         var)
9135     (if (not vtype)
9136         (error "No such mark type: %s" type)
9137       (setq var (intern (format "gnus-newsgroup-%s" type)))
9138       (set var (cons article (symbol-value var)))
9139       (if (memq type '(processable cached replied forwarded recent saved))
9140           (gnus-summary-update-secondary-mark article)
9141         ;;; !!! This is bogus.  We should find out what primary
9142         ;;; !!! mark we want to set.
9143         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9144
9145 (defun gnus-summary-mark-as-expirable (n)
9146   "Mark N articles forward as expirable.
9147 If N is negative, mark backward instead.  The difference between N and
9148 the actual number of articles marked is returned."
9149   (interactive "p")
9150   (gnus-summary-mark-forward n gnus-expirable-mark))
9151
9152 (defun gnus-summary-mark-article-as-replied (article)
9153   "Mark ARTICLE as replied to and update the summary line.
9154 ARTICLE can also be a list of articles."
9155   (interactive (list (gnus-summary-article-number)))
9156   (let ((articles (if (listp article) article (list article))))
9157     (dolist (article articles)
9158       (push article gnus-newsgroup-replied)
9159       (let ((buffer-read-only nil))
9160         (when (gnus-summary-goto-subject article nil t)
9161           (gnus-summary-update-secondary-mark article))))))
9162
9163 (defun gnus-summary-mark-article-as-forwarded (article)
9164   "Mark ARTICLE as forwarded and update the summary line.
9165 ARTICLE can also be a list of articles."
9166   (let ((articles (if (listp article) article (list article))))
9167     (dolist (article articles)
9168       (push article gnus-newsgroup-forwarded)
9169       (let ((buffer-read-only nil))
9170         (when (gnus-summary-goto-subject article nil t)
9171           (gnus-summary-update-secondary-mark article))))))
9172
9173 (defun gnus-summary-set-bookmark (article)
9174   "Set a bookmark in current article."
9175   (interactive (list (gnus-summary-article-number)))
9176   (when (or (not (get-buffer gnus-article-buffer))
9177             (not gnus-current-article)
9178             (not gnus-article-current)
9179             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9180     (error "No current article selected"))
9181   ;; Remove old bookmark, if one exists.
9182   (let ((old (assq article gnus-newsgroup-bookmarks)))
9183     (when old
9184       (setq gnus-newsgroup-bookmarks
9185             (delq old gnus-newsgroup-bookmarks))))
9186   ;; Set the new bookmark, which is on the form
9187   ;; (article-number . line-number-in-body).
9188   (push
9189    (cons article
9190          (save-excursion
9191            (set-buffer gnus-article-buffer)
9192            (count-lines
9193             (min (point)
9194                  (save-excursion
9195                    (goto-char (point-min))
9196                    (search-forward "\n\n" nil t)
9197                    (point)))
9198             (point))))
9199    gnus-newsgroup-bookmarks)
9200   (gnus-message 6 "A bookmark has been added to the current article."))
9201
9202 (defun gnus-summary-remove-bookmark (article)
9203   "Remove the bookmark from the current article."
9204   (interactive (list (gnus-summary-article-number)))
9205   ;; Remove old bookmark, if one exists.
9206   (let ((old (assq article gnus-newsgroup-bookmarks)))
9207     (if old
9208         (progn
9209           (setq gnus-newsgroup-bookmarks
9210                 (delq old gnus-newsgroup-bookmarks))
9211           (gnus-message 6 "Removed bookmark."))
9212       (gnus-message 6 "No bookmark in current article."))))
9213
9214 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9215 (defun gnus-summary-mark-as-dormant (n)
9216   "Mark N articles forward as dormant.
9217 If N is negative, mark backward instead.  The difference between N and
9218 the actual number of articles marked is returned."
9219   (interactive "p")
9220   (gnus-summary-mark-forward n gnus-dormant-mark))
9221
9222 (defun gnus-summary-set-process-mark (article)
9223   "Set the process mark on ARTICLE and update the summary line."
9224   (setq gnus-newsgroup-processable
9225         (cons article
9226               (delq article gnus-newsgroup-processable)))
9227   (when (gnus-summary-goto-subject article)
9228     (gnus-summary-show-thread)
9229     (gnus-summary-goto-subject article)
9230     (gnus-summary-update-secondary-mark article)))
9231
9232 (defun gnus-summary-remove-process-mark (article)
9233   "Remove the process mark from ARTICLE and update the summary line."
9234   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9235   (when (gnus-summary-goto-subject article)
9236     (gnus-summary-show-thread)
9237     (gnus-summary-goto-subject article)
9238     (gnus-summary-update-secondary-mark article)))
9239
9240 (defun gnus-summary-set-saved-mark (article)
9241   "Set the process mark on ARTICLE and update the summary line."
9242   (push article gnus-newsgroup-saved)
9243   (when (gnus-summary-goto-subject article)
9244     (gnus-summary-update-secondary-mark article)))
9245
9246 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9247   "Mark N articles as read forwards.
9248 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9249 The difference between N and the actual number of articles marked is
9250 returned.
9251 Iff NO-EXPIRE, auto-expiry will be inhibited."
9252   (interactive "p")
9253   (gnus-summary-show-thread)
9254   (let ((backward (< n 0))
9255         (gnus-summary-goto-unread
9256          (and gnus-summary-goto-unread
9257               (not (eq gnus-summary-goto-unread 'never))
9258               (not (memq mark (list gnus-unread-mark
9259                                     gnus-ticked-mark gnus-dormant-mark)))))
9260         (n (abs n))
9261         (mark (or mark gnus-del-mark)))
9262     (while (and (> n 0)
9263                 (gnus-summary-mark-article nil mark no-expire)
9264                 (zerop (gnus-summary-next-subject
9265                         (if backward -1 1)
9266                         (and gnus-summary-goto-unread
9267                              (not (eq gnus-summary-goto-unread 'never)))
9268                         t)))
9269       (setq n (1- n)))
9270     (when (/= 0 n)
9271       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9272     (gnus-summary-recenter)
9273     (gnus-summary-position-point)
9274     (gnus-set-mode-line 'summary)
9275     n))
9276
9277 (defun gnus-summary-mark-article-as-read (mark)
9278   "Mark the current article quickly as read with MARK."
9279   (let ((article (gnus-summary-article-number)))
9280     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9281     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9282     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9283     (push (cons article mark) gnus-newsgroup-reads)
9284     ;; Possibly remove from cache, if that is used.
9285     (when gnus-use-cache
9286       (gnus-cache-enter-remove-article article))
9287     ;; Allow the backend to change the mark.
9288     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9289     ;; Check for auto-expiry.
9290     (when (and gnus-newsgroup-auto-expire
9291                (memq mark gnus-auto-expirable-marks))
9292       (setq mark gnus-expirable-mark)
9293       ;; Let the backend know about the mark change.
9294       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9295       (push article gnus-newsgroup-expirable))
9296     ;; Set the mark in the buffer.
9297     (gnus-summary-update-mark mark 'unread)
9298     t))
9299
9300 (defun gnus-summary-mark-article-as-unread (mark)
9301   "Mark the current article quickly as unread with MARK."
9302   (let* ((article (gnus-summary-article-number))
9303          (old-mark (gnus-summary-article-mark article)))
9304     ;; Allow the backend to change the mark.
9305     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9306     (if (eq mark old-mark)
9307         t
9308       (if (<= article 0)
9309           (progn
9310             (gnus-error 1 "Can't mark negative article numbers")
9311             nil)
9312         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9313         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9314         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9315         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9316         (cond ((= mark gnus-ticked-mark)
9317                (setq gnus-newsgroup-marked
9318                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9319                                               article)))
9320               ((= mark gnus-dormant-mark)
9321                (setq gnus-newsgroup-dormant
9322                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9323                                               article)))
9324               (t
9325                (setq gnus-newsgroup-unreads
9326                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9327                                               article))))
9328         (gnus-pull article gnus-newsgroup-reads)
9329
9330         ;; See whether the article is to be put in the cache.
9331         (and gnus-use-cache
9332              (vectorp (gnus-summary-article-header article))
9333              (save-excursion
9334                (gnus-cache-possibly-enter-article
9335                 gnus-newsgroup-name article
9336                 (gnus-summary-article-header article)
9337                 (= mark gnus-ticked-mark)
9338                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9339
9340         ;; Fix the mark.
9341         (gnus-summary-update-mark mark 'unread)
9342         t))))
9343
9344 (defun gnus-summary-mark-article (&optional article mark no-expire)
9345   "Mark ARTICLE with MARK.  MARK can be any character.
9346 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9347 `??' (dormant) and `?E' (expirable).
9348 If MARK is nil, then the default character `?r' is used.
9349 If ARTICLE is nil, then the article on the current line will be
9350 marked.
9351 Iff NO-EXPIRE, auto-expiry will be inhibited."
9352   ;; The mark might be a string.
9353   (when (stringp mark)
9354     (setq mark (aref mark 0)))
9355   ;; If no mark is given, then we check auto-expiring.
9356   (when (null mark)
9357     (setq mark gnus-del-mark))
9358   (when (and (not no-expire)
9359              gnus-newsgroup-auto-expire
9360              (memq mark gnus-auto-expirable-marks))
9361     (setq mark gnus-expirable-mark))
9362   (let ((article (or article (gnus-summary-article-number)))
9363         (old-mark (gnus-summary-article-mark article)))
9364     ;; Allow the backend to change the mark.
9365     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9366     (if (eq mark old-mark)
9367         t
9368       (unless article
9369         (error "No article on current line"))
9370       (if (not (if (or (= mark gnus-unread-mark)
9371                        (= mark gnus-ticked-mark)
9372                        (= mark gnus-dormant-mark))
9373                    (gnus-mark-article-as-unread article mark)
9374                  (gnus-mark-article-as-read article mark)))
9375           t
9376         ;; See whether the article is to be put in the cache.
9377         (and gnus-use-cache
9378              (not (= mark gnus-canceled-mark))
9379              (vectorp (gnus-summary-article-header article))
9380              (save-excursion
9381                (gnus-cache-possibly-enter-article
9382                 gnus-newsgroup-name article
9383                 (gnus-summary-article-header article)
9384                 (= mark gnus-ticked-mark)
9385                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9386
9387         (when (gnus-summary-goto-subject article nil t)
9388           (let ((buffer-read-only nil))
9389             (gnus-summary-show-thread)
9390             ;; Fix the mark.
9391             (gnus-summary-update-mark mark 'unread)
9392             t))))))
9393
9394 (defun gnus-summary-update-secondary-mark (article)
9395   "Update the secondary (read, process, cache) mark."
9396   (gnus-summary-update-mark
9397    (cond ((memq article gnus-newsgroup-processable)
9398           gnus-process-mark)
9399          ((memq article gnus-newsgroup-cached)
9400           gnus-cached-mark)
9401          ((memq article gnus-newsgroup-replied)
9402           gnus-replied-mark)
9403          ((memq article gnus-newsgroup-forwarded)
9404           gnus-forwarded-mark)
9405          ((memq article gnus-newsgroup-saved)
9406           gnus-saved-mark)
9407          ((memq article gnus-newsgroup-recent)
9408           gnus-recent-mark)
9409          ((memq article gnus-newsgroup-unseen)
9410           gnus-unseen-mark)
9411          (t gnus-no-mark))
9412    'replied)
9413   (when (gnus-visual-p 'summary-highlight 'highlight)
9414     (gnus-run-hooks 'gnus-summary-update-hook))
9415   t)
9416
9417 (defun gnus-summary-update-mark (mark type)
9418   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9419         (buffer-read-only nil))
9420     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9421     (when forward
9422       (when (looking-at "\r")
9423         (incf forward))
9424       (when (<= (+ forward (point)) (point-max))
9425         ;; Go to the right position on the line.
9426         (goto-char (+ forward (point)))
9427         ;; Replace the old mark with the new mark.
9428         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9429         ;; Optionally update the marks by some user rule.
9430         (when (eq type 'unread)
9431           (gnus-data-set-mark
9432            (gnus-data-find (gnus-summary-article-number)) mark)
9433           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9434
9435 (defun gnus-mark-article-as-read (article &optional mark)
9436   "Enter ARTICLE in the pertinent lists and remove it from others."
9437   ;; Make the article expirable.
9438   (let ((mark (or mark gnus-del-mark)))
9439     (setq gnus-newsgroup-expirable
9440           (if (= mark gnus-expirable-mark)
9441               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9442             (delq article gnus-newsgroup-expirable)))
9443     ;; Remove from unread and marked lists.
9444     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9445     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9446     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9447     (push (cons article mark) gnus-newsgroup-reads)
9448     ;; Possibly remove from cache, if that is used.
9449     (when gnus-use-cache
9450       (gnus-cache-enter-remove-article article))
9451     t))
9452
9453 (defun gnus-mark-article-as-unread (article &optional mark)
9454   "Enter ARTICLE in the pertinent lists and remove it from others."
9455   (let ((mark (or mark gnus-ticked-mark)))
9456     (if (<= article 0)
9457         (progn
9458           (gnus-error 1 "Can't mark negative article numbers")
9459           nil)
9460       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9461             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9462             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9463             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9464
9465       ;; Unsuppress duplicates?
9466       (when gnus-suppress-duplicates
9467         (gnus-dup-unsuppress-article article))
9468
9469       (cond ((= mark gnus-ticked-mark)
9470              (setq gnus-newsgroup-marked
9471                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9472             ((= mark gnus-dormant-mark)
9473              (setq gnus-newsgroup-dormant
9474                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9475             (t
9476              (setq gnus-newsgroup-unreads
9477                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9478       (gnus-pull article gnus-newsgroup-reads)
9479       t)))
9480
9481 (defalias 'gnus-summary-mark-as-unread-forward
9482   'gnus-summary-tick-article-forward)
9483 (make-obsolete 'gnus-summary-mark-as-unread-forward
9484                'gnus-summary-tick-article-forward)
9485 (defun gnus-summary-tick-article-forward (n)
9486   "Tick N articles forwards.
9487 If N is negative, tick backwards instead.
9488 The difference between N and the number of articles ticked is returned."
9489   (interactive "p")
9490   (gnus-summary-mark-forward n gnus-ticked-mark))
9491
9492 (defalias 'gnus-summary-mark-as-unread-backward
9493   'gnus-summary-tick-article-backward)
9494 (make-obsolete 'gnus-summary-mark-as-unread-backward
9495                'gnus-summary-tick-article-backward)
9496 (defun gnus-summary-tick-article-backward (n)
9497   "Tick N articles backwards.
9498 The difference between N and the number of articles ticked is returned."
9499   (interactive "p")
9500   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9501
9502 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9503 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9504 (defun gnus-summary-tick-article (&optional article clear-mark)
9505   "Mark current article as unread.
9506 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9507 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9508   (interactive)
9509   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9510                                        gnus-ticked-mark)))
9511
9512 (defun gnus-summary-mark-as-read-forward (n)
9513   "Mark N articles as read forwards.
9514 If N is negative, mark backwards instead.
9515 The difference between N and the actual number of articles marked is
9516 returned."
9517   (interactive "p")
9518   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9519
9520 (defun gnus-summary-mark-as-read-backward (n)
9521   "Mark the N articles as read backwards.
9522 The difference between N and the actual number of articles marked is
9523 returned."
9524   (interactive "p")
9525   (gnus-summary-mark-forward
9526    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9527
9528 (defun gnus-summary-mark-as-read (&optional article mark)
9529   "Mark current article as read.
9530 ARTICLE specifies the article to be marked as read.
9531 MARK specifies a string to be inserted at the beginning of the line."
9532   (gnus-summary-mark-article article mark))
9533
9534 (defun gnus-summary-clear-mark-forward (n)
9535   "Clear marks from N articles forward.
9536 If N is negative, clear backward instead.
9537 The difference between N and the number of marks cleared is returned."
9538   (interactive "p")
9539   (gnus-summary-mark-forward n gnus-unread-mark))
9540
9541 (defun gnus-summary-clear-mark-backward (n)
9542   "Clear marks from N articles backward.
9543 The difference between N and the number of marks cleared is returned."
9544   (interactive "p")
9545   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9546
9547 (defun gnus-summary-mark-unread-as-read ()
9548   "Intended to be used by `gnus-summary-mark-article-hook'."
9549   (when (memq gnus-current-article gnus-newsgroup-unreads)
9550     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9551
9552 (defun gnus-summary-mark-read-and-unread-as-read ()
9553   "Intended to be used by `gnus-summary-mark-article-hook'."
9554   (let ((mark (gnus-summary-article-mark)))
9555     (when (or (gnus-unread-mark-p mark)
9556               (gnus-read-mark-p mark))
9557       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9558
9559 (defun gnus-summary-mark-unread-as-ticked ()
9560   "Intended to be used by `gnus-summary-mark-article-hook'."
9561   (when (memq gnus-current-article gnus-newsgroup-unreads)
9562     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9563
9564 (defun gnus-summary-mark-region-as-read (point mark all)
9565   "Mark all unread articles between point and mark as read.
9566 If given a prefix, mark all articles between point and mark as read,
9567 even ticked and dormant ones."
9568   (interactive "r\nP")
9569   (save-excursion
9570     (let (article)
9571       (goto-char point)
9572       (beginning-of-line)
9573       (while (and
9574               (< (point) mark)
9575               (progn
9576                 (when (or all
9577                           (memq (setq article (gnus-summary-article-number))
9578                                 gnus-newsgroup-unreads))
9579                   (gnus-summary-mark-article article gnus-del-mark))
9580                 t)
9581               (gnus-summary-find-next))))))
9582
9583 (defun gnus-summary-mark-below (score mark)
9584   "Mark articles with score less than SCORE with MARK."
9585   (interactive "P\ncMark: ")
9586   (setq score (if score
9587                   (prefix-numeric-value score)
9588                 (or gnus-summary-default-score 0)))
9589   (save-excursion
9590     (set-buffer gnus-summary-buffer)
9591     (goto-char (point-min))
9592     (while
9593         (progn
9594           (and (< (gnus-summary-article-score) score)
9595                (gnus-summary-mark-article nil mark))
9596           (gnus-summary-find-next)))))
9597
9598 (defun gnus-summary-kill-below (&optional score)
9599   "Mark articles with score below SCORE as read."
9600   (interactive "P")
9601   (gnus-summary-mark-below score gnus-killed-mark))
9602
9603 (defun gnus-summary-clear-above (&optional score)
9604   "Clear all marks from articles with score above SCORE."
9605   (interactive "P")
9606   (gnus-summary-mark-above score gnus-unread-mark))
9607
9608 (defun gnus-summary-tick-above (&optional score)
9609   "Tick all articles with score above SCORE."
9610   (interactive "P")
9611   (gnus-summary-mark-above score gnus-ticked-mark))
9612
9613 (defun gnus-summary-mark-above (score mark)
9614   "Mark articles with score over SCORE with MARK."
9615   (interactive "P\ncMark: ")
9616   (setq score (if score
9617                   (prefix-numeric-value score)
9618                 (or gnus-summary-default-score 0)))
9619   (save-excursion
9620     (set-buffer gnus-summary-buffer)
9621     (goto-char (point-min))
9622     (while (and (progn
9623                   (when (> (gnus-summary-article-score) score)
9624                     (gnus-summary-mark-article nil mark))
9625                   t)
9626                 (gnus-summary-find-next)))))
9627
9628 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9629 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9630 (defun gnus-summary-limit-include-expunged (&optional no-error)
9631   "Display all the hidden articles that were expunged for low scores."
9632   (interactive)
9633   (let ((buffer-read-only nil))
9634     (let ((scored gnus-newsgroup-scored)
9635           headers h)
9636       (while scored
9637         (unless (gnus-summary-article-header (caar scored))
9638           (and (setq h (gnus-number-to-header (caar scored)))
9639                (< (cdar scored) gnus-summary-expunge-below)
9640                (push h headers)))
9641         (setq scored (cdr scored)))
9642       (if (not headers)
9643           (when (not no-error)
9644             (error "No expunged articles hidden"))
9645         (goto-char (point-min))
9646         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9647         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9648         (mapcar (lambda (x) (push (mail-header-number x)
9649                                   gnus-newsgroup-limit))
9650                 headers)
9651         (gnus-summary-prepare-unthreaded (nreverse headers))
9652         (goto-char (point-min))
9653         (gnus-summary-position-point)
9654         t))))
9655
9656 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9657   "Mark all unread articles in this newsgroup as read.
9658 If prefix argument ALL is non-nil, ticked and dormant articles will
9659 also be marked as read.
9660 If QUIETLY is non-nil, no questions will be asked.
9661 If TO-HERE is non-nil, it should be a point in the buffer.  All
9662 articles before (after, if REVERSE is set) this point will be marked as read.
9663 Note that this function will only catch up the unread article
9664 in the current summary buffer limitation.
9665 The number of articles marked as read is returned."
9666   (interactive "P")
9667   (prog1
9668       (save-excursion
9669         (when (or quietly
9670                   (not gnus-interactive-catchup) ;Without confirmation?
9671                   gnus-expert-user
9672                   (gnus-y-or-n-p
9673                    (if all
9674                        "Mark absolutely all articles as read? "
9675                      "Mark all unread articles as read? ")))
9676           (if (and not-mark
9677                    (not gnus-newsgroup-adaptive)
9678                    (not gnus-newsgroup-auto-expire)
9679                    (not gnus-suppress-duplicates)
9680                    (or (not gnus-use-cache)
9681                        (eq gnus-use-cache 'passive)))
9682               (progn
9683                 (when all
9684                   (setq gnus-newsgroup-marked nil
9685                         gnus-newsgroup-dormant nil))
9686                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9687             ;; We actually mark all articles as canceled, which we
9688             ;; have to do when using auto-expiry or adaptive scoring.
9689             (gnus-summary-show-all-threads)
9690             (if (and to-here reverse)
9691                 (progn
9692                   (goto-char to-here)
9693                   (while (and
9694                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9695                           (gnus-summary-find-next (not all) nil nil t))))
9696               (when (gnus-summary-first-subject (not all) t)
9697                 (while (and
9698                         (if to-here (< (point) to-here) t)
9699                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9700                         (gnus-summary-find-next (not all) nil nil t)))))
9701             (gnus-set-mode-line 'summary))
9702           t))
9703     (gnus-summary-position-point)))
9704
9705 (defun gnus-summary-catchup-to-here (&optional all)
9706   "Mark all unticked articles before the current one as read.
9707 If ALL is non-nil, also mark ticked and dormant articles as read."
9708   (interactive "P")
9709   (save-excursion
9710     (gnus-save-hidden-threads
9711       (let ((beg (point)))
9712         ;; We check that there are unread articles.
9713         (when (or all (gnus-summary-find-prev))
9714           (gnus-summary-catchup all t beg)))))
9715   (gnus-summary-position-point))
9716
9717 (defun gnus-summary-catchup-from-here (&optional all)
9718   "Mark all unticked articles after the current one as read.
9719 If ALL is non-nil, also mark ticked and dormant articles as read."
9720   (interactive "P")
9721   (save-excursion
9722     (gnus-save-hidden-threads
9723       (let ((beg (point)))
9724         ;; We check that there are unread articles.
9725         (when (or all (gnus-summary-find-next))
9726           (gnus-summary-catchup all t beg nil t)))))
9727   (gnus-summary-position-point))
9728
9729 (defun gnus-summary-catchup-all (&optional quietly)
9730   "Mark all articles in this newsgroup as read."
9731   (interactive "P")
9732   (gnus-summary-catchup t quietly))
9733
9734 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9735   "Mark all unread articles in this group as read, then exit.
9736 If prefix argument ALL is non-nil, all articles are marked as read.
9737 If QUIETLY is non-nil, no questions will be asked."
9738   (interactive "P")
9739   (when (gnus-summary-catchup all quietly nil 'fast)
9740     ;; Select next newsgroup or exit.
9741     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9742              (eq gnus-auto-select-next 'quietly))
9743         (gnus-summary-next-group nil)
9744       (gnus-summary-exit))))
9745
9746 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9747   "Mark all articles in this newsgroup as read, and then exit."
9748   (interactive "P")
9749   (gnus-summary-catchup-and-exit t quietly))
9750
9751 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9752   "Mark all articles in this group as read and select the next group.
9753 If given a prefix, mark all articles, unread as well as ticked, as
9754 read."
9755   (interactive "P")
9756   (save-excursion
9757     (gnus-summary-catchup all))
9758   (gnus-summary-next-group))
9759
9760 ;;;
9761 ;;; with article
9762 ;;;
9763
9764 (defmacro gnus-with-article (article &rest forms)
9765   "Select ARTICLE and perform FORMS in the original article buffer.
9766 Then replace the article with the result."
9767   `(progn
9768      ;; We don't want the article to be marked as read.
9769      (let (gnus-mark-article-hook)
9770        (gnus-summary-select-article t t nil ,article))
9771      (set-buffer gnus-original-article-buffer)
9772      ,@forms
9773      (if (not (gnus-check-backend-function
9774                'request-replace-article (car gnus-article-current)))
9775          (gnus-message 5 "Read-only group; not replacing")
9776        (unless (gnus-request-replace-article
9777                 ,article (car gnus-article-current)
9778                 (current-buffer) t)
9779          (error "Couldn't replace article")))
9780      ;; The cache and backlog have to be flushed somewhat.
9781      (when gnus-keep-backlog
9782        (gnus-backlog-remove-article
9783         (car gnus-article-current) (cdr gnus-article-current)))
9784      (when gnus-use-cache
9785        (gnus-cache-update-article
9786         (car gnus-article-current) (cdr gnus-article-current)))))
9787
9788 (put 'gnus-with-article 'lisp-indent-function 1)
9789 (put 'gnus-with-article 'edebug-form-spec '(form body))
9790
9791 ;; Thread-based commands.
9792
9793 (defun gnus-summary-articles-in-thread (&optional article)
9794   "Return a list of all articles in the current thread.
9795 If ARTICLE is non-nil, return all articles in the thread that starts
9796 with that article."
9797   (let* ((article (or article (gnus-summary-article-number)))
9798          (data (gnus-data-find-list article))
9799          (top-level (gnus-data-level (car data)))
9800          (top-subject
9801           (cond ((null gnus-thread-operation-ignore-subject)
9802                  (gnus-simplify-subject-re
9803                   (mail-header-subject (gnus-data-header (car data)))))
9804                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9805                  (gnus-simplify-subject-fuzzy
9806                   (mail-header-subject (gnus-data-header (car data)))))
9807                 (t nil)))
9808          (end-point (save-excursion
9809                       (if (gnus-summary-go-to-next-thread)
9810                           (point) (point-max))))
9811          articles)
9812     (while (and data
9813                 (< (gnus-data-pos (car data)) end-point))
9814       (when (or (not top-subject)
9815                 (string= top-subject
9816                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9817                              (gnus-simplify-subject-fuzzy
9818                               (mail-header-subject
9819                                (gnus-data-header (car data))))
9820                            (gnus-simplify-subject-re
9821                             (mail-header-subject
9822                              (gnus-data-header (car data)))))))
9823         (push (gnus-data-number (car data)) articles))
9824       (unless (and (setq data (cdr data))
9825                    (> (gnus-data-level (car data)) top-level))
9826         (setq data nil)))
9827     ;; Return the list of articles.
9828     (nreverse articles)))
9829
9830 (defun gnus-summary-rethread-current ()
9831   "Rethread the thread the current article is part of."
9832   (interactive)
9833   (let* ((gnus-show-threads t)
9834          (article (gnus-summary-article-number))
9835          (id (mail-header-id (gnus-summary-article-header)))
9836          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9837     (unless id
9838       (error "No article on the current line"))
9839     (gnus-rebuild-thread id)
9840     (gnus-summary-goto-subject article)))
9841
9842 (defun gnus-summary-reparent-thread ()
9843   "Make the current article child of the marked (or previous) article.
9844
9845 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9846 is non-nil or the Subject: of both articles are the same."
9847   (interactive)
9848   (unless (not (gnus-group-read-only-p))
9849     (error "The current newsgroup does not support article editing"))
9850   (unless (<= (length gnus-newsgroup-processable) 1)
9851     (error "No more than one article may be marked"))
9852   (save-window-excursion
9853     (let ((gnus-article-buffer " *reparent*")
9854           (current-article (gnus-summary-article-number))
9855           ;; First grab the marked article, otherwise one line up.
9856           (parent-article (if (not (null gnus-newsgroup-processable))
9857                               (car gnus-newsgroup-processable)
9858                             (save-excursion
9859                               (if (eq (forward-line -1) 0)
9860                                   (gnus-summary-article-number)
9861                                 (error "Beginning of summary buffer"))))))
9862       (unless (not (eq current-article parent-article))
9863         (error "An article may not be self-referential"))
9864       (let ((message-id (mail-header-id
9865                          (gnus-summary-article-header parent-article))))
9866         (unless (and message-id (not (equal message-id "")))
9867           (error "No message-id in desired parent"))
9868         (gnus-with-article current-article
9869           (save-restriction
9870             (goto-char (point-min))
9871             (message-narrow-to-head)
9872             (if (re-search-forward "^References: " nil t)
9873                 (progn
9874                   (re-search-forward "^[^ \t]" nil t)
9875                   (forward-line -1)
9876                   (end-of-line)
9877                   (insert " " message-id))
9878               (insert "References: " message-id "\n"))))
9879         (set-buffer gnus-summary-buffer)
9880         (gnus-summary-unmark-all-processable)
9881         (gnus-summary-update-article current-article)
9882         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9883             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9884         (gnus-summary-rethread-current)
9885         (gnus-message 3 "Article %d is now the child of article %d"
9886                       current-article parent-article)))))
9887
9888 (defun gnus-summary-toggle-threads (&optional arg)
9889   "Toggle showing conversation threads.
9890 If ARG is positive number, turn showing conversation threads on."
9891   (interactive "P")
9892   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9893     (setq gnus-show-threads
9894           (if (null arg) (not gnus-show-threads)
9895             (> (prefix-numeric-value arg) 0)))
9896     (gnus-summary-prepare)
9897     (gnus-summary-goto-subject current)
9898     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9899     (gnus-summary-position-point)))
9900
9901 (defun gnus-summary-show-all-threads ()
9902   "Show all threads."
9903   (interactive)
9904   (save-excursion
9905     (let ((buffer-read-only nil))
9906       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9907   (gnus-summary-position-point))
9908
9909 (defun gnus-summary-show-thread ()
9910   "Show thread subtrees.
9911 Returns nil if no thread was there to be shown."
9912   (interactive)
9913   (let ((buffer-read-only nil)
9914         (orig (point))
9915         ;; first goto end then to beg, to have point at beg after let
9916         (end (progn (end-of-line) (point)))
9917         (beg (progn (beginning-of-line) (point))))
9918     (prog1
9919         ;; Any hidden lines here?
9920         (search-forward "\r" end t)
9921       (subst-char-in-region beg end ?\^M ?\n t)
9922       (goto-char orig)
9923       (gnus-summary-position-point))))
9924
9925 (defun gnus-summary-maybe-hide-threads ()
9926   "If requested, hide the threads that should be hidden."
9927   (when (and gnus-show-threads
9928              gnus-thread-hide-subtree)
9929     (gnus-summary-hide-all-threads
9930      (if (or (consp gnus-thread-hide-subtree)
9931              (gnus-functionp gnus-thread-hide-subtree))
9932          (gnus-make-predicate gnus-thread-hide-subtree)
9933        nil))))
9934
9935 ;;; Hiding predicates.
9936
9937 (defun gnus-article-unread-p (header)
9938   (memq (mail-header-number header) gnus-newsgroup-unreads))
9939
9940 (defun gnus-article-unseen-p (header)
9941   (memq (mail-header-number header) gnus-newsgroup-unseen))
9942
9943 (defun gnus-map-articles (predicate articles)
9944   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
9945   (apply 'gnus-or (mapcar predicate
9946                           (mapcar 'gnus-summary-article-header articles))))
9947
9948 (defun gnus-summary-hide-all-threads (&optional predicate)
9949   "Hide all thread subtrees.
9950 If PREDICATE is supplied, threads that satisfy this predicate
9951 will not be hidden."
9952   (interactive)
9953   (save-excursion
9954     (goto-char (point-min))
9955     (let ((end nil))
9956       (while (not end)
9957         (when (or (not predicate)
9958                   (gnus-map-articles
9959                    predicate (gnus-summary-article-children)))
9960             (gnus-summary-hide-thread))
9961         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
9962   (gnus-summary-position-point))
9963
9964 (defun gnus-summary-hide-thread ()
9965   "Hide thread subtrees.
9966 If PREDICATE is supplied, threads that satisfy this predicate
9967 will not be hidden.
9968 Returns nil if no threads were there to be hidden."
9969   (interactive)
9970   (let ((buffer-read-only nil)
9971         (start (point))
9972         (article (gnus-summary-article-number)))
9973     (goto-char start)
9974     ;; Go forward until either the buffer ends or the subthread
9975     ;; ends.
9976     (when (and (not (eobp))
9977                (or (zerop (gnus-summary-next-thread 1 t))
9978                    (goto-char (point-max))))
9979       (prog1
9980           (if (and (> (point) start)
9981                    (search-backward "\n" start t))
9982               (progn
9983                 (subst-char-in-region start (point) ?\n ?\^M)
9984                 (gnus-summary-goto-subject article))
9985             (goto-char start)
9986             nil)))))
9987
9988 (defun gnus-summary-go-to-next-thread (&optional previous)
9989   "Go to the same level (or less) next thread.
9990 If PREVIOUS is non-nil, go to previous thread instead.
9991 Return the article number moved to, or nil if moving was impossible."
9992   (let ((level (gnus-summary-thread-level))
9993         (way (if previous -1 1))
9994         (beg (point)))
9995     (forward-line way)
9996     (while (and (not (eobp))
9997                 (< level (gnus-summary-thread-level)))
9998       (forward-line way))
9999     (if (eobp)
10000         (progn
10001           (goto-char beg)
10002           nil)
10003       (setq beg (point))
10004       (prog1
10005           (gnus-summary-article-number)
10006         (goto-char beg)))))
10007
10008 (defun gnus-summary-next-thread (n &optional silent)
10009   "Go to the same level next N'th thread.
10010 If N is negative, search backward instead.
10011 Returns the difference between N and the number of skips actually
10012 done.
10013
10014 If SILENT, don't output messages."
10015   (interactive "p")
10016   (let ((backward (< n 0))
10017         (n (abs n)))
10018     (while (and (> n 0)
10019                 (gnus-summary-go-to-next-thread backward))
10020       (decf n))
10021     (unless silent
10022       (gnus-summary-position-point))
10023     (when (and (not silent) (/= 0 n))
10024       (gnus-message 7 "No more threads"))
10025     n))
10026
10027 (defun gnus-summary-prev-thread (n)
10028   "Go to the same level previous N'th thread.
10029 Returns the difference between N and the number of skips actually
10030 done."
10031   (interactive "p")
10032   (gnus-summary-next-thread (- n)))
10033
10034 (defun gnus-summary-go-down-thread ()
10035   "Go down one level in the current thread."
10036   (let ((children (gnus-summary-article-children)))
10037     (when children
10038       (gnus-summary-goto-subject (car children)))))
10039
10040 (defun gnus-summary-go-up-thread ()
10041   "Go up one level in the current thread."
10042   (let ((parent (gnus-summary-article-parent)))
10043     (when parent
10044       (gnus-summary-goto-subject parent))))
10045
10046 (defun gnus-summary-down-thread (n)
10047   "Go down thread N steps.
10048 If N is negative, go up instead.
10049 Returns the difference between N and how many steps down that were
10050 taken."
10051   (interactive "p")
10052   (let ((up (< n 0))
10053         (n (abs n)))
10054     (while (and (> n 0)
10055                 (if up (gnus-summary-go-up-thread)
10056                   (gnus-summary-go-down-thread)))
10057       (setq n (1- n)))
10058     (gnus-summary-position-point)
10059     (when (/= 0 n)
10060       (gnus-message 7 "Can't go further"))
10061     n))
10062
10063 (defun gnus-summary-up-thread (n)
10064   "Go up thread N steps.
10065 If N is negative, go down instead.
10066 Returns the difference between N and how many steps down that were
10067 taken."
10068   (interactive "p")
10069   (gnus-summary-down-thread (- n)))
10070
10071 (defun gnus-summary-top-thread ()
10072   "Go to the top of the thread."
10073   (interactive)
10074   (while (gnus-summary-go-up-thread))
10075   (gnus-summary-article-number))
10076
10077 (defun gnus-summary-kill-thread (&optional unmark)
10078   "Mark articles under current thread as read.
10079 If the prefix argument is positive, remove any kinds of marks.
10080 If the prefix argument is negative, tick articles instead."
10081   (interactive "P")
10082   (when unmark
10083     (setq unmark (prefix-numeric-value unmark)))
10084   (let ((articles (gnus-summary-articles-in-thread)))
10085     (save-excursion
10086       ;; Expand the thread.
10087       (gnus-summary-show-thread)
10088       ;; Mark all the articles.
10089       (while articles
10090         (gnus-summary-goto-subject (car articles))
10091         (cond ((null unmark)
10092                (gnus-summary-mark-article-as-read gnus-killed-mark))
10093               ((> unmark 0)
10094                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10095               (t
10096                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10097         (setq articles (cdr articles))))
10098     ;; Hide killed subtrees.
10099     (and (null unmark)
10100          gnus-thread-hide-killed
10101          (gnus-summary-hide-thread))
10102     ;; If marked as read, go to next unread subject.
10103     (when (null unmark)
10104       ;; Go to next unread subject.
10105       (gnus-summary-next-subject 1 t)))
10106   (gnus-set-mode-line 'summary))
10107
10108 ;; Summary sorting commands
10109
10110 (defun gnus-summary-sort-by-number (&optional reverse)
10111   "Sort the summary buffer by article number.
10112 Argument REVERSE means reverse order."
10113   (interactive "P")
10114   (gnus-summary-sort 'number reverse))
10115
10116 (defun gnus-summary-sort-by-author (&optional reverse)
10117   "Sort the summary buffer by author name alphabetically.
10118 If `case-fold-search' is non-nil, case of letters is ignored.
10119 Argument REVERSE means reverse order."
10120   (interactive "P")
10121   (gnus-summary-sort 'author reverse))
10122
10123 (defun gnus-summary-sort-by-subject (&optional reverse)
10124   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10125 If `case-fold-search' is non-nil, case of letters is ignored.
10126 Argument REVERSE means reverse order."
10127   (interactive "P")
10128   (gnus-summary-sort 'subject reverse))
10129
10130 (defun gnus-summary-sort-by-date (&optional reverse)
10131   "Sort the summary buffer by date.
10132 Argument REVERSE means reverse order."
10133   (interactive "P")
10134   (gnus-summary-sort 'date reverse))
10135
10136 (defun gnus-summary-sort-by-score (&optional reverse)
10137   "Sort the summary buffer by score.
10138 Argument REVERSE means reverse order."
10139   (interactive "P")
10140   (gnus-summary-sort 'score reverse))
10141
10142 (defun gnus-summary-sort-by-lines (&optional reverse)
10143   "Sort the summary buffer by the number of lines.
10144 Argument REVERSE means reverse order."
10145   (interactive "P")
10146   (gnus-summary-sort 'lines reverse))
10147
10148 (defun gnus-summary-sort-by-chars (&optional reverse)
10149   "Sort the summary buffer by article length.
10150 Argument REVERSE means reverse order."
10151   (interactive "P")
10152   (gnus-summary-sort 'chars reverse))
10153
10154 (defun gnus-summary-sort-by-original (&optional reverse)
10155   "Sort the summary buffer using the default sorting method.
10156 Argument REVERSE means reverse order."
10157   (interactive "P")
10158   (let* ((buffer-read-only)
10159          (gnus-summary-prepare-hook nil))
10160     ;; We do the sorting by regenerating the threads.
10161     (gnus-summary-prepare)
10162     ;; Hide subthreads if needed.
10163     (gnus-summary-maybe-hide-threads)))
10164
10165 (defun gnus-summary-sort (predicate reverse)
10166   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10167   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10168          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10169          (gnus-thread-sort-functions
10170           (if (not reverse)
10171               thread
10172             `(lambda (t1 t2)
10173                (,thread t2 t1))))
10174          (gnus-sort-gathered-threads-function
10175           gnus-thread-sort-functions)
10176          (gnus-article-sort-functions
10177           (if (not reverse)
10178               article
10179             `(lambda (t1 t2)
10180                (,article t2 t1))))
10181          (buffer-read-only)
10182          (gnus-summary-prepare-hook nil))
10183     ;; We do the sorting by regenerating the threads.
10184     (gnus-summary-prepare)
10185     ;; Hide subthreads if needed.
10186     (gnus-summary-maybe-hide-threads)))
10187
10188 ;; Summary saving commands.
10189
10190 (defun gnus-summary-save-article (&optional n not-saved)
10191   "Save the current article using the default saver function.
10192 If N is a positive number, save the N next articles.
10193 If N is a negative number, save the N previous articles.
10194 If N is nil and any articles have been marked with the process mark,
10195 save those articles instead.
10196 The variable `gnus-default-article-saver' specifies the saver function."
10197   (interactive "P")
10198   (let* ((articles (gnus-summary-work-articles n))
10199          (save-buffer (save-excursion
10200                         (nnheader-set-temp-buffer " *Gnus Save*")))
10201          (num (length articles))
10202          header file)
10203     (dolist (article articles)
10204       (setq header (gnus-summary-article-header article))
10205       (if (not (vectorp header))
10206           ;; This is a pseudo-article.
10207           (if (assq 'name header)
10208               (gnus-copy-file (cdr (assq 'name header)))
10209             (gnus-message 1 "Article %d is unsaveable" article))
10210         ;; This is a real article.
10211         (save-window-excursion
10212           (let ((gnus-display-mime-function nil)
10213                 (gnus-article-prepare-hook nil))
10214             (gnus-summary-select-article t nil nil article)))
10215         (save-excursion
10216           (set-buffer save-buffer)
10217           (erase-buffer)
10218           (insert-buffer-substring gnus-original-article-buffer))
10219         (setq file (gnus-article-save save-buffer file num))
10220         (gnus-summary-remove-process-mark article)
10221         (unless not-saved
10222           (gnus-summary-set-saved-mark article))))
10223     (gnus-kill-buffer save-buffer)
10224     (gnus-summary-position-point)
10225     (gnus-set-mode-line 'summary)
10226     n))
10227
10228 (defun gnus-summary-pipe-output (&optional arg)
10229   "Pipe the current article to a subprocess.
10230 If N is a positive number, pipe the N next articles.
10231 If N is a negative number, pipe the N previous articles.
10232 If N is nil and any articles have been marked with the process mark,
10233 pipe those articles instead."
10234   (interactive "P")
10235   (require 'gnus-art)
10236   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10237     (gnus-summary-save-article arg t))
10238   (let ((buffer (get-buffer "*Shell Command Output*")))
10239     (if (and buffer
10240              (with-current-buffer buffer (> (point-max) (point-min))))
10241         (gnus-configure-windows 'pipe))))
10242
10243 (defun gnus-summary-save-article-mail (&optional arg)
10244   "Append the current article to an mail file.
10245 If N is a positive number, save the N next articles.
10246 If N is a negative number, save the N previous articles.
10247 If N is nil and any articles have been marked with the process mark,
10248 save those articles instead."
10249   (interactive "P")
10250   (require 'gnus-art)
10251   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10252     (gnus-summary-save-article arg)))
10253
10254 (defun gnus-summary-save-article-rmail (&optional arg)
10255   "Append the current article to an rmail file.
10256 If N is a positive number, save the N next articles.
10257 If N is a negative number, save the N previous articles.
10258 If N is nil and any articles have been marked with the process mark,
10259 save those articles instead."
10260   (interactive "P")
10261   (require 'gnus-art)
10262   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10263     (gnus-summary-save-article arg)))
10264
10265 (defun gnus-summary-save-article-file (&optional arg)
10266   "Append the current article to a file.
10267 If N is a positive number, save the N next articles.
10268 If N is a negative number, save the N previous articles.
10269 If N is nil and any articles have been marked with the process mark,
10270 save those articles instead."
10271   (interactive "P")
10272   (require 'gnus-art)
10273   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10274     (gnus-summary-save-article arg)))
10275
10276 (defun gnus-summary-write-article-file (&optional arg)
10277   "Write the current article to a file, deleting the previous file.
10278 If N is a positive number, save the N next articles.
10279 If N is a negative number, save the N previous articles.
10280 If N is nil and any articles have been marked with the process mark,
10281 save those articles instead."
10282   (interactive "P")
10283   (require 'gnus-art)
10284   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10285     (gnus-summary-save-article arg)))
10286
10287 (defun gnus-summary-save-article-body-file (&optional arg)
10288   "Append the current article body to a file.
10289 If N is a positive number, save the N next articles.
10290 If N is a negative number, save the N previous articles.
10291 If N is nil and any articles have been marked with the process mark,
10292 save those articles instead."
10293   (interactive "P")
10294   (require 'gnus-art)
10295   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10296     (gnus-summary-save-article arg)))
10297
10298 (defun gnus-summary-muttprint (&optional arg)
10299   "Print the current article using Muttprint.
10300 If N is a positive number, save the N next articles.
10301 If N is a negative number, save the N previous articles.
10302 If N is nil and any articles have been marked with the process mark,
10303 save those articles instead."
10304   (interactive "P")
10305   (require 'gnus-art)
10306   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10307     (gnus-summary-save-article arg t)))
10308
10309 (defun gnus-summary-pipe-message (program)
10310   "Pipe the current article through PROGRAM."
10311   (interactive "sProgram: ")
10312   (gnus-summary-select-article)
10313   (let ((mail-header-separator ""))
10314     (gnus-eval-in-buffer-window gnus-article-buffer
10315       (save-restriction
10316         (widen)
10317         (let ((start (window-start))
10318               buffer-read-only)
10319           (message-pipe-buffer-body program)
10320           (set-window-start (get-buffer-window (current-buffer)) start))))))
10321
10322 (defun gnus-get-split-value (methods)
10323   "Return a value based on the split METHODS."
10324   (let (split-name method result match)
10325     (when methods
10326       (save-excursion
10327         (set-buffer gnus-original-article-buffer)
10328         (save-restriction
10329           (nnheader-narrow-to-headers)
10330           (while (and methods (not split-name))
10331             (goto-char (point-min))
10332             (setq method (pop methods))
10333             (setq match (car method))
10334             (when (cond
10335                    ((stringp match)
10336                     ;; Regular expression.
10337                     (ignore-errors
10338                       (re-search-forward match nil t)))
10339                    ((gnus-functionp match)
10340                     ;; Function.
10341                     (save-restriction
10342                       (widen)
10343                       (setq result (funcall match gnus-newsgroup-name))))
10344                    ((consp match)
10345                     ;; Form.
10346                     (save-restriction
10347                       (widen)
10348                       (setq result (eval match)))))
10349               (setq split-name (cdr method))
10350               (cond ((stringp result)
10351                      (push (expand-file-name
10352                             result gnus-article-save-directory)
10353                            split-name))
10354                     ((consp result)
10355                      (setq split-name (append result split-name)))))))))
10356     (nreverse split-name)))
10357
10358 (defun gnus-valid-move-group-p (group)
10359   (and (boundp group)
10360        (symbol-name group)
10361        (symbol-value group)
10362        (gnus-get-function (gnus-find-method-for-group
10363                            (symbol-name group)) 'request-accept-article t)))
10364
10365 (defun gnus-read-move-group-name (prompt default articles prefix)
10366   "Read a group name."
10367   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10368          (minibuffer-confirm-incomplete nil) ; XEmacs
10369          (prom
10370           (format "%s %s to:"
10371                   prompt
10372                   (if (> (length articles) 1)
10373                       (format "these %d articles" (length articles))
10374                     "this article")))
10375          (to-newsgroup
10376           (cond
10377            ((null split-name)
10378             (gnus-completing-read-with-default
10379              default prom
10380              gnus-active-hashtb
10381              'gnus-valid-move-group-p
10382              nil prefix
10383              'gnus-group-history))
10384            ((= 1 (length split-name))
10385             (gnus-completing-read-with-default
10386              (car split-name) prom
10387              gnus-active-hashtb
10388              'gnus-valid-move-group-p
10389              nil nil
10390              'gnus-group-history))
10391            (t
10392             (gnus-completing-read-with-default
10393              nil prom
10394              (mapcar (lambda (el) (list el))
10395                      (nreverse split-name))
10396              nil nil nil
10397              'gnus-group-history))))
10398          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10399     (when to-newsgroup
10400       (if (or (string= to-newsgroup "")
10401               (string= to-newsgroup prefix))
10402           (setq to-newsgroup default))
10403       (unless to-newsgroup
10404         (error "No group name entered"))
10405       (or (gnus-active to-newsgroup)
10406           (gnus-activate-group to-newsgroup nil nil to-method)
10407           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10408                                      to-newsgroup))
10409               (or (and (gnus-request-create-group to-newsgroup to-method)
10410                        (gnus-activate-group
10411                         to-newsgroup nil nil to-method)
10412                        (gnus-subscribe-group to-newsgroup))
10413                   (error "Couldn't create group %s" to-newsgroup)))
10414           (error "No such group: %s" to-newsgroup)))
10415     to-newsgroup))
10416
10417 (defun gnus-summary-save-parts (type dir n &optional reverse)
10418   "Save parts matching TYPE to DIR.
10419 If REVERSE, save parts that do not match TYPE."
10420   (interactive
10421    (list (read-string "Save parts of type: "
10422                       (or (car gnus-summary-save-parts-type-history)
10423                           gnus-summary-save-parts-default-mime)
10424                       'gnus-summary-save-parts-type-history)
10425          (setq gnus-summary-save-parts-last-directory
10426                (read-file-name "Save to directory: "
10427                                gnus-summary-save-parts-last-directory
10428                                nil t))
10429          current-prefix-arg))
10430   (gnus-summary-iterate n
10431     (let ((gnus-display-mime-function nil)
10432           (gnus-inhibit-treatment t))
10433       (gnus-summary-select-article))
10434     (save-excursion
10435       (set-buffer gnus-article-buffer)
10436       (let ((handles (or gnus-article-mime-handles
10437                          (mm-dissect-buffer
10438                           gnus-article-no-strict-mime)
10439                          (mm-uu-dissect))))
10440         (when handles
10441           (gnus-summary-save-parts-1 type dir handles reverse)
10442           (unless gnus-article-mime-handles ;; Don't destroy this case.
10443             (mm-destroy-parts handles)))))))
10444
10445 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10446   (if (stringp (car handle))
10447       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10448               (cdr handle))
10449     (when (if reverse
10450               (not (string-match type (mm-handle-media-type handle)))
10451             (string-match type (mm-handle-media-type handle)))
10452       (let ((file (expand-file-name
10453                    (file-name-nondirectory
10454                     (or
10455                      (mail-content-type-get
10456                       (mm-handle-disposition handle) 'filename)
10457                      (concat gnus-newsgroup-name
10458                              "." (number-to-string
10459                                   (cdr gnus-article-current)))))
10460                    dir)))
10461         (unless (file-exists-p file)
10462           (mm-save-part-to-file handle file))))))
10463
10464 ;; Summary extract commands
10465
10466 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10467   (let ((buffer-read-only nil)
10468         (article (gnus-summary-article-number))
10469         after-article b e)
10470     (unless (gnus-summary-goto-subject article)
10471       (error "No such article: %d" article))
10472     (gnus-summary-position-point)
10473     ;; If all commands are to be bunched up on one line, we collect
10474     ;; them here.
10475     (unless gnus-view-pseudos-separately
10476       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10477             files action)
10478         (while ps
10479           (setq action (cdr (assq 'action (car ps))))
10480           (setq files (list (cdr (assq 'name (car ps)))))
10481           (while (and ps (cdr ps)
10482                       (string= (or action "1")
10483                                (or (cdr (assq 'action (cadr ps))) "2")))
10484             (push (cdr (assq 'name (cadr ps))) files)
10485             (setcdr ps (cddr ps)))
10486           (when files
10487             (when (not (string-match "%s" action))
10488               (push " " files))
10489             (push " " files)
10490             (when (assq 'execute (car ps))
10491               (setcdr (assq 'execute (car ps))
10492                       (funcall (if (string-match "%s" action)
10493                                    'format 'concat)
10494                                action
10495                                (mapconcat
10496                                 (lambda (f)
10497                                   (if (equal f " ")
10498                                       f
10499                                     (gnus-quote-arg-for-sh-or-csh f)))
10500                                 files " ")))))
10501           (setq ps (cdr ps)))))
10502     (if (and gnus-view-pseudos (not not-view))
10503         (while pslist
10504           (when (assq 'execute (car pslist))
10505             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10506                                   (eq gnus-view-pseudos 'not-confirm)))
10507           (setq pslist (cdr pslist)))
10508       (save-excursion
10509         (while pslist
10510           (setq after-article (or (cdr (assq 'article (car pslist)))
10511                                   (gnus-summary-article-number)))
10512           (gnus-summary-goto-subject after-article)
10513           (forward-line 1)
10514           (setq b (point))
10515           (insert "    " (file-name-nondirectory
10516                           (cdr (assq 'name (car pslist))))
10517                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10518           (setq e (point))
10519           (forward-line -1)             ; back to `b'
10520           (gnus-add-text-properties
10521            b (1- e) (list 'gnus-number gnus-reffed-article-number
10522                           gnus-mouse-face-prop gnus-mouse-face))
10523           (gnus-data-enter
10524            after-article gnus-reffed-article-number
10525            gnus-unread-mark b (car pslist) 0 (- e b))
10526           (setq gnus-newsgroup-unreads
10527                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10528                                          gnus-reffed-article-number))
10529           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10530           (setq pslist (cdr pslist)))))))
10531
10532 (defun gnus-pseudos< (p1 p2)
10533   (let ((c1 (cdr (assq 'action p1)))
10534         (c2 (cdr (assq 'action p2))))
10535     (and c1 c2 (string< c1 c2))))
10536
10537 (defun gnus-request-pseudo-article (props)
10538   (cond ((assq 'execute props)
10539          (gnus-execute-command (cdr (assq 'execute props)))))
10540   (let ((gnus-current-article (gnus-summary-article-number)))
10541     (gnus-run-hooks 'gnus-mark-article-hook)))
10542
10543 (defun gnus-execute-command (command &optional automatic)
10544   (save-excursion
10545     (gnus-article-setup-buffer)
10546     (set-buffer gnus-article-buffer)
10547     (setq buffer-read-only nil)
10548     (let ((command (if automatic command
10549                      (read-string "Command: " (cons command 0)))))
10550       (erase-buffer)
10551       (insert "$ " command "\n\n")
10552       (if gnus-view-pseudo-asynchronously
10553           (start-process "gnus-execute" (current-buffer) shell-file-name
10554                          shell-command-switch command)
10555         (call-process shell-file-name nil t nil
10556                       shell-command-switch command)))))
10557
10558 ;; Summary kill commands.
10559
10560 (defun gnus-summary-edit-global-kill (article)
10561   "Edit the \"global\" kill file."
10562   (interactive (list (gnus-summary-article-number)))
10563   (gnus-group-edit-global-kill article))
10564
10565 (defun gnus-summary-edit-local-kill ()
10566   "Edit a local kill file applied to the current newsgroup."
10567   (interactive)
10568   (setq gnus-current-headers (gnus-summary-article-header))
10569   (gnus-group-edit-local-kill
10570    (gnus-summary-article-number) gnus-newsgroup-name))
10571
10572 ;;; Header reading.
10573
10574 (defun gnus-read-header (id &optional header)
10575   "Read the headers of article ID and enter them into the Gnus system."
10576   (let ((group gnus-newsgroup-name)
10577         (gnus-override-method
10578          (or
10579           gnus-override-method
10580           (and (gnus-news-group-p gnus-newsgroup-name)
10581                (car (gnus-refer-article-methods)))))
10582         where)
10583     ;; First we check to see whether the header in question is already
10584     ;; fetched.
10585     (if (stringp id)
10586         ;; This is a Message-ID.
10587         (setq header (or header (gnus-id-to-header id)))
10588       ;; This is an article number.
10589       (setq header (or header (gnus-summary-article-header id))))
10590     (if (and header
10591              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10592         ;; We have found the header.
10593         header
10594       ;; If this is a sparse article, we have to nix out its
10595       ;; previous entry in the thread hashtb.
10596       (when (and header
10597                  (gnus-summary-article-sparse-p (mail-header-number header)))
10598         (let* ((parent (gnus-parent-id (mail-header-references header)))
10599                (thread (and parent (gnus-id-to-thread parent))))
10600           (when thread
10601             (delq (assq header thread) thread))))
10602       ;; We have to really fetch the header to this article.
10603       (save-excursion
10604         (set-buffer nntp-server-buffer)
10605         (when (setq where (gnus-request-head id group))
10606           (nnheader-fold-continuation-lines)
10607           (goto-char (point-max))
10608           (insert ".\n")
10609           (goto-char (point-min))
10610           (insert "211 ")
10611           (princ (cond
10612                   ((numberp id) id)
10613                   ((cdr where) (cdr where))
10614                   (header (mail-header-number header))
10615                   (t gnus-reffed-article-number))
10616                  (current-buffer))
10617           (insert " Article retrieved.\n"))
10618         (if (or (not where)
10619                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10620             ()                          ; Malformed head.
10621           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10622             (when (and (stringp id)
10623                        (not (string= (gnus-group-real-name group)
10624                                      (car where))))
10625               ;; If we fetched by Message-ID and the article came
10626               ;; from a different group, we fudge some bogus article
10627               ;; numbers for this article.
10628               (mail-header-set-number header gnus-reffed-article-number))
10629             (save-excursion
10630               (set-buffer gnus-summary-buffer)
10631               (decf gnus-reffed-article-number)
10632               (gnus-remove-header (mail-header-number header))
10633               (push header gnus-newsgroup-headers)
10634               (setq gnus-current-headers header)
10635               (push (mail-header-number header) gnus-newsgroup-limit)))
10636           header)))))
10637
10638 (defun gnus-remove-header (number)
10639   "Remove header NUMBER from `gnus-newsgroup-headers'."
10640   (if (and gnus-newsgroup-headers
10641            (= number (mail-header-number (car gnus-newsgroup-headers))))
10642       (pop gnus-newsgroup-headers)
10643     (let ((headers gnus-newsgroup-headers))
10644       (while (and (cdr headers)
10645                   (not (= number (mail-header-number (cadr headers)))))
10646         (pop headers))
10647       (when (cdr headers)
10648         (setcdr headers (cddr headers))))))
10649
10650 ;;;
10651 ;;; summary highlights
10652 ;;;
10653
10654 (defun gnus-highlight-selected-summary ()
10655   "Highlight selected article in summary buffer."
10656   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10657   (when gnus-summary-selected-face
10658     (save-excursion
10659       (let* ((beg (progn (beginning-of-line) (point)))
10660              (end (progn (end-of-line) (point)))
10661              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10662              (from (if (get-text-property beg gnus-mouse-face-prop)
10663                        beg
10664                      (or (next-single-property-change
10665                           beg gnus-mouse-face-prop nil end)
10666                          beg)))
10667              (to
10668               (if (= from end)
10669                   (- from 2)
10670                 (or (next-single-property-change
10671                      from gnus-mouse-face-prop nil end)
10672                     end))))
10673         ;; If no mouse-face prop on line we will have to = from = end,
10674         ;; so we highlight the entire line instead.
10675         (when (= (+ to 2) from)
10676           (setq from beg)
10677           (setq to end))
10678         (if gnus-newsgroup-selected-overlay
10679             ;; Move old overlay.
10680             (gnus-move-overlay
10681              gnus-newsgroup-selected-overlay from to (current-buffer))
10682           ;; Create new overlay.
10683           (gnus-overlay-put
10684            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10685            'face gnus-summary-selected-face))))))
10686
10687 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10688 (defun gnus-summary-highlight-line ()
10689   "Highlight current line according to `gnus-summary-highlight'."
10690   (let* ((list gnus-summary-highlight)
10691          (p (point))
10692          (end (progn (end-of-line) (point)))
10693          ;; now find out where the line starts and leave point there.
10694          (beg (progn (beginning-of-line) (point)))
10695          (article (gnus-summary-article-number))
10696          (score (or (cdr (assq (or article gnus-current-article)
10697                                gnus-newsgroup-scored))
10698                     gnus-summary-default-score 0))
10699          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10700          (inhibit-read-only t))
10701     ;; Eval the cars of the lists until we find a match.
10702     (let ((default gnus-summary-default-score)
10703           (default-high gnus-summary-default-high-score)
10704           (default-low gnus-summary-default-low-score))
10705       (while (and list
10706                   (not (eval (caar list))))
10707         (setq list (cdr list))))
10708     (let ((face (cdar list)))
10709       (unless (eq face (get-text-property beg 'face))
10710         (gnus-put-text-property-excluding-characters-with-faces
10711          beg end 'face
10712          (setq face (if (boundp face) (symbol-value face) face)))
10713         (when gnus-summary-highlight-line-function
10714           (funcall gnus-summary-highlight-line-function article face))))
10715     (goto-char p)))
10716
10717 (defun gnus-update-read-articles (group unread &optional compute)
10718   "Update the list of read articles in GROUP.
10719 UNREAD is a sorted list."
10720   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10721          (entry (gnus-gethash group gnus-newsrc-hashtb))
10722          (info (nth 2 entry))
10723          (prev 1)
10724          read)
10725     (if (or (not info) (not active))
10726         ;; There is no info on this group if it was, in fact,
10727         ;; killed.  Gnus stores no information on killed groups, so
10728         ;; there's nothing to be done.
10729         ;; One could store the information somewhere temporarily,
10730         ;; perhaps...  Hmmm...
10731         ()
10732       ;; Remove any negative articles numbers.
10733       (while (and unread (< (car unread) 0))
10734         (setq unread (cdr unread)))
10735       ;; Remove any expired article numbers
10736       (while (and unread (< (car unread) (car active)))
10737         (setq unread (cdr unread)))
10738       ;; Compute the ranges of read articles by looking at the list of
10739       ;; unread articles.
10740       (while unread
10741         (when (/= (car unread) prev)
10742           (push (if (= prev (1- (car unread))) prev
10743                   (cons prev (1- (car unread))))
10744                 read))
10745         (setq prev (1+ (car unread)))
10746         (setq unread (cdr unread)))
10747       (when (<= prev (cdr active))
10748         (push (cons prev (cdr active)) read))
10749       (setq read (if (> (length read) 1) (nreverse read) read))
10750       (if compute
10751           read
10752         (save-excursion
10753           (let (setmarkundo)
10754             ;; Propagate the read marks to the backend.
10755             (when (gnus-check-backend-function 'request-set-mark group)
10756               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10757                     (add (gnus-remove-from-range read (gnus-info-read info))))
10758                 (when (or add del)
10759                   (unless (gnus-check-group group)
10760                     (error "Can't open server for %s" group))
10761                   (gnus-request-set-mark
10762                    group (delq nil (list (if add (list add 'add '(read)))
10763                                          (if del (list del 'del '(read))))))
10764                   (setq setmarkundo
10765                         `(gnus-request-set-mark
10766                           ,group
10767                           ',(delq nil (list
10768                                        (if del (list del 'add '(read)))
10769                                        (if add (list add 'del '(read))))))))))
10770             (set-buffer gnus-group-buffer)
10771             (gnus-undo-register
10772               `(progn
10773                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10774                  (gnus-info-set-read ',info ',(gnus-info-read info))
10775                  (gnus-get-unread-articles-in-group ',info
10776                                                     (gnus-active ,group))
10777                  (gnus-group-update-group ,group t)
10778                  ,setmarkundo))))
10779         ;; Enter this list into the group info.
10780         (gnus-info-set-read info read)
10781         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10782         (gnus-get-unread-articles-in-group info (gnus-active group))
10783         t))))
10784
10785 (defun gnus-offer-save-summaries ()
10786   "Offer to save all active summary buffers."
10787   (let (buffers)
10788     ;; Go through all buffers and find all summaries.
10789     (dolist (buffer (buffer-list))
10790       (when (and (setq buffer (buffer-name buffer))
10791                  (string-match "Summary" buffer)
10792                  (save-excursion
10793                    (set-buffer buffer)
10794                    ;; We check that this is, indeed, a summary buffer.
10795                    (and (eq major-mode 'gnus-summary-mode)
10796                         ;; Also make sure this isn't bogus.
10797                         gnus-newsgroup-prepared
10798                         ;; Also make sure that this isn't a
10799                         ;; dead summary buffer.
10800                         (not gnus-dead-summary-mode))))
10801         (push buffer buffers)))
10802     ;; Go through all these summary buffers and offer to save them.
10803     (when buffers
10804       (save-excursion
10805         (map-y-or-n-p
10806          "Update summary buffer %s? "
10807          (lambda (buf)
10808            (switch-to-buffer buf)
10809            (gnus-summary-exit))
10810          buffers)))))
10811
10812
10813 ;;; @ for mime-partial
10814 ;;;
10815
10816 (defun gnus-request-partial-message ()
10817   (save-excursion
10818     (let ((number (gnus-summary-article-number))
10819           (group gnus-newsgroup-name)
10820           (mother gnus-article-buffer))
10821       (set-buffer (get-buffer-create " *Partial Article*"))
10822       (erase-buffer)
10823       (setq mime-preview-buffer mother)
10824       (gnus-request-article-this-buffer number group)
10825       (mime-parse-buffer)
10826       )))
10827
10828 (autoload 'mime-combine-message/partial-pieces-automatically
10829   "mime-partial"
10830   "Internal method to combine message/partial messages automatically.")
10831
10832 (mime-add-condition
10833  'action '((type . message)(subtype . partial)
10834            (major-mode . gnus-original-article-mode)
10835            (method . mime-combine-message/partial-pieces-automatically)
10836            (summary-buffer-exp . gnus-summary-buffer)
10837            (request-partial-message-method . gnus-request-partial-message)
10838            ))
10839
10840
10841 ;;; @ for message/rfc822
10842 ;;;
10843
10844 (defun gnus-mime-extract-message/rfc822 (entity situation)
10845   "Burst a forwarded article."
10846   (save-excursion
10847     (set-buffer gnus-summary-buffer)
10848     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10849                                    gnus-newsgroup-name 'gnus-group-history))
10850            (gnus-group-marked (list group))
10851            article info)
10852       (with-temp-buffer
10853         (mime-insert-entity-content entity)
10854         (setq article (gnus-request-accept-article group)))
10855       (when (and (consp article)
10856                  (numberp (setq article (cdr article))))
10857         (setq info (gnus-get-info group))
10858         (gnus-info-set-read info
10859                             (gnus-remove-from-range (gnus-info-read info)
10860                                                     (list article)))
10861         (when (string-equal group gnus-newsgroup-name)
10862           (forward-line 1)
10863           (let (gnus-show-threads)
10864             (gnus-summary-goto-subject article t))
10865           (gnus-summary-clear-mark-forward 1))
10866         (set-buffer gnus-group-buffer)
10867         (gnus-group-get-new-news-this-group nil t)))))
10868
10869 (mime-add-condition
10870  'action '((type . message)(subtype . rfc822)
10871            (major-mode . gnus-original-article-mode)
10872            (method . gnus-mime-extract-message/rfc822)
10873            (mode . "extract")
10874            ))
10875
10876 (mime-add-condition
10877  'action '((type . message)(subtype . news)
10878            (major-mode . gnus-original-article-mode)
10879            (method . gnus-mime-extract-message/rfc822)
10880            (mode . "extract")
10881            ))
10882
10883 (defun gnus-mime-extract-multipart (entity situation)
10884   (let ((children (mime-entity-children entity))
10885         mime-acting-situation-to-override
10886         f)
10887     (while children
10888       (mime-play-entity (car children)
10889                         (cons (assq 'mode situation)
10890                               mime-acting-situation-to-override))
10891       (setq children (cdr children)))
10892     (if (setq f (cdr (assq 'after-method
10893                            mime-acting-situation-to-override)))
10894         (eval f)
10895       )))
10896
10897 (mime-add-condition
10898  'action '((type . multipart)
10899            (method . gnus-mime-extract-multipart)
10900            (mode . "extract")
10901            )
10902  'with-default)
10903
10904
10905 ;;; @ end
10906 ;;;
10907
10908 (defun gnus-summary-setup-default-charset ()
10909   "Setup newsgroup default charset."
10910   (if (equal gnus-newsgroup-name "nndraft:drafts")
10911       (setq gnus-newsgroup-charset nil)
10912     (let* ((ignored-charsets
10913             (or gnus-newsgroup-ephemeral-ignored-charsets
10914                 (append
10915                  (and gnus-newsgroup-name
10916                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10917                  gnus-newsgroup-ignored-charsets))))
10918       (setq gnus-newsgroup-charset
10919             (or gnus-newsgroup-ephemeral-charset
10920                 (and gnus-newsgroup-name
10921                      (gnus-parameter-charset gnus-newsgroup-name))
10922                 gnus-default-charset))
10923       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10924            ignored-charsets))))
10925
10926 ;;;
10927 ;;; Mime Commands
10928 ;;;
10929
10930 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10931   "Display the current article buffer fully MIME-buttonized.
10932 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10933 treated as multipart/mixed."
10934   (interactive "P")
10935   (require 'gnus-art)
10936   (let ((gnus-unbuttonized-mime-types nil)
10937         (gnus-mime-display-multipart-as-mixed show-all-parts))
10938     (gnus-summary-show-article)))
10939
10940 (defun gnus-summary-repair-multipart (article)
10941   "Add a Content-Type header to a multipart article without one."
10942   (interactive (list (gnus-summary-article-number)))
10943   (gnus-with-article article
10944     (message-narrow-to-head)
10945     (message-remove-header "Mime-Version")
10946     (goto-char (point-max))
10947     (insert "Mime-Version: 1.0\n")
10948     (widen)
10949     (when (search-forward "\n--" nil t)
10950       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10951         (message-narrow-to-head)
10952         (message-remove-header "Content-Type")
10953         (goto-char (point-max))
10954         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10955                         separator))
10956         (widen))))
10957   (let (gnus-mark-article-hook)
10958     (gnus-summary-select-article t t nil article)))
10959
10960 (defun gnus-summary-toggle-display-buttonized ()
10961   "Toggle the buttonizing of the article buffer."
10962   (interactive)
10963   (require 'gnus-art)
10964   (if (setq gnus-inhibit-mime-unbuttonizing
10965             (not gnus-inhibit-mime-unbuttonizing))
10966       (let ((gnus-unbuttonized-mime-types nil))
10967         (gnus-summary-show-article))
10968     (gnus-summary-show-article)))
10969
10970 ;;;
10971 ;;; Intelli-mouse commmands
10972 ;;;
10973
10974 (defun gnus-wheel-summary-scroll (event)
10975   (interactive "e")
10976   (let ((amount (if (memq 'shift (event-modifiers event))
10977                     (car gnus-wheel-scroll-amount)
10978                   (cdr gnus-wheel-scroll-amount)))
10979         (direction (- (* (static-if (featurep 'xemacs)
10980                              (event-button event)
10981                            (cond ((eq 'mouse-4 (event-basic-type event))
10982                                   4)
10983                                  ((eq 'mouse-5 (event-basic-type event))
10984                                   5)))
10985                          2) 9))
10986         edge)
10987     (gnus-summary-scroll-up (* amount direction))
10988     (when (gnus-eval-in-buffer-window gnus-article-buffer
10989             (save-restriction
10990               (widen)
10991               (and (if (< 0 direction)
10992                        (gnus-article-next-page 0)
10993                      (gnus-article-prev-page 0)
10994                      (bobp))
10995                    (if (setq edge (get-text-property
10996                                    (point-min) 'gnus-wheel-edge))
10997                        (setq edge (* edge direction))
10998                      (setq edge -1))
10999                    (or (plusp edge)
11000                        (let ((buffer-read-only nil)
11001                              (inhibit-read-only t))
11002                          (put-text-property (point-min) (point-max)
11003                                             'gnus-wheel-edge direction)
11004                          nil))
11005                    (or (> edge gnus-wheel-edge-resistance)
11006                        (let ((buffer-read-only nil)
11007                              (inhibit-read-only t))
11008                          (put-text-property (point-min) (point-max)
11009                                             'gnus-wheel-edge
11010                                             (* (1+ edge) direction))
11011                          nil))
11012                    (eq last-command 'gnus-wheel-summary-scroll))))
11013       (gnus-summary-next-article nil nil (minusp direction)))))
11014
11015 (defun gnus-wheel-install ()
11016   "Enable mouse wheel support on summary window."
11017   (when gnus-use-wheel
11018     (let ((keys
11019            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11020       (dolist (key keys)
11021         (define-key gnus-summary-mode-map key
11022           'gnus-wheel-summary-scroll)))))
11023
11024 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11025
11026 ;;;
11027 ;;; Traditional PGP commmands
11028 ;;;
11029
11030 (defun gnus-summary-decrypt-article (&optional force)
11031   "Decrypt the current article in traditional PGP way.
11032 This will have permanent effect only in mail groups.
11033 If FORCE is non-nil, allow editing of articles even in read-only
11034 groups."
11035   (interactive "P")
11036   (gnus-summary-select-article t)
11037   (gnus-eval-in-buffer-window gnus-article-buffer
11038     (save-excursion
11039       (save-restriction
11040         (widen)
11041         (goto-char (point-min))
11042         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11043           (error "Not a traditional PGP message!"))
11044         (let ((armor-start (match-beginning 0)))
11045           (if (and (pgg-decrypt-region armor-start (point-max))
11046                    (or force (not (gnus-group-read-only-p))))
11047               (let ((inhibit-read-only t)
11048                     buffer-read-only)
11049                 (delete-region armor-start
11050                                (progn
11051                                  (re-search-forward "^-+END PGP" nil t)
11052                                  (beginning-of-line 2)
11053                                  (point)))
11054                 (insert-buffer-substring pgg-output-buffer))))))))
11055
11056 (defun gnus-summary-verify-article ()
11057   "Verify the current article in traditional PGP way."
11058   (interactive)
11059   (save-excursion
11060     (set-buffer gnus-original-article-buffer)
11061     (goto-char (point-min))
11062     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11063       (error "Not a traditional PGP message!"))
11064     (re-search-forward "^-+END PGP" nil t)
11065     (beginning-of-line 2)
11066     (call-interactively (function pgg-verify-region))))
11067
11068 ;;;
11069 ;;; Generic summary marking commands
11070 ;;;
11071
11072 (defvar gnus-summary-marking-alist
11073   '((read gnus-del-mark "d")
11074     (unread gnus-unread-mark "u")
11075     (ticked gnus-ticked-mark "!")
11076     (dormant gnus-dormant-mark "?")
11077     (expirable gnus-expirable-mark "e"))
11078   "An alist of names/marks/keystrokes.")
11079
11080 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11081 (defvar gnus-summary-mark-map)
11082
11083 (defun gnus-summary-make-all-marking-commands ()
11084   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11085   (dolist (elem gnus-summary-marking-alist)
11086     (apply 'gnus-summary-make-marking-command elem)))
11087
11088 (defun gnus-summary-make-marking-command (name mark keystroke)
11089   (let ((map (make-sparse-keymap)))
11090     (define-key gnus-summary-generic-mark-map keystroke map)
11091     (dolist (lway `((next "next" next nil "n")
11092                     (next-unread "next unread" next t "N")
11093                     (prev "previous" prev nil "p")
11094                     (prev-unread "previous unread" prev t "P")
11095                     (nomove "" nil nil ,keystroke)))
11096       (let ((func (gnus-summary-make-marking-command-1
11097                    mark (car lway) lway name)))
11098         (setq func (eval func))
11099         (define-key map (nth 4 lway) func)))))
11100
11101 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11102   `(defun ,(intern
11103             (format "gnus-summary-put-mark-as-%s%s"
11104                     name (if (eq way 'nomove)
11105                              ""
11106                            (concat "-" (symbol-name way)))))
11107      (n)
11108      ,(format
11109        "Mark the current article as %s%s.
11110 If N, the prefix, then repeat N times.
11111 If N is negative, move in reverse order.
11112 The difference between N and the actual number of articles marked is
11113 returned."
11114        name (car (cdr lway)))
11115      (interactive "p")
11116      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11117
11118 (defun gnus-summary-generic-mark (n mark move unread)
11119   "Mark N articles with MARK."
11120   (unless (eq major-mode 'gnus-summary-mode)
11121     (error "This command can only be used in the summary buffer"))
11122   (gnus-summary-show-thread)
11123   (let ((nummove
11124          (cond
11125           ((eq move 'next) 1)
11126           ((eq move 'prev) -1)
11127           (t 0))))
11128     (if (zerop nummove)
11129         (setq n 1)
11130       (when (< n 0)
11131         (setq n (abs n)
11132               nummove (* -1 nummove))))
11133     (while (and (> n 0)
11134                 (gnus-summary-mark-article nil mark)
11135                 (zerop (gnus-summary-next-subject nummove unread t)))
11136       (setq n (1- n)))
11137     (when (/= 0 n)
11138       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11139     (gnus-summary-recenter)
11140     (gnus-summary-position-point)
11141     (gnus-set-mode-line 'summary)
11142     n))
11143
11144 (defun gnus-summary-insert-articles (articles)
11145   (when (setq articles
11146               (gnus-sorted-difference articles
11147                                       (mapcar (lambda (h)
11148                                                 (mail-header-number h))
11149                                               gnus-newsgroup-headers)))
11150     (setq gnus-newsgroup-headers
11151           (merge 'list
11152                  gnus-newsgroup-headers
11153                  (gnus-fetch-headers articles)
11154                  'gnus-article-sort-by-number))
11155     ;; Suppress duplicates?
11156     (when gnus-suppress-duplicates
11157       (gnus-dup-suppress-articles))
11158
11159     ;; We might want to build some more threads first.
11160     (when (and gnus-fetch-old-headers
11161                (eq gnus-headers-retrieved-by 'nov))
11162       (if (eq gnus-fetch-old-headers 'invisible)
11163           (gnus-build-all-threads)
11164         (gnus-build-old-threads)))
11165     ;; Let the Gnus agent mark articles as read.
11166     (when gnus-agent
11167       (gnus-agent-get-undownloaded-list))
11168     ;; Remove list identifiers from subject
11169     (when gnus-list-identifiers
11170       (gnus-summary-remove-list-identifiers))
11171     ;; First and last article in this newsgroup.
11172     (when gnus-newsgroup-headers
11173       (setq gnus-newsgroup-begin
11174             (mail-header-number (car gnus-newsgroup-headers))
11175             gnus-newsgroup-end
11176             (mail-header-number
11177              (gnus-last-element gnus-newsgroup-headers))))
11178     (when gnus-use-scoring
11179       (gnus-possibly-score-headers))))
11180
11181 (defun gnus-summary-insert-old-articles (&optional all)
11182   "Insert all old articles in this group.
11183 If ALL is non-nil, already read articles become readable.
11184 If ALL is a number, fetch this number of articles."
11185   (interactive "P")
11186   (prog1
11187       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11188             older len)
11189         (setq older
11190               (gnus-sorted-difference
11191                (gnus-uncompress-range (list gnus-newsgroup-active))
11192                old))
11193         (setq len (length older))
11194         (cond
11195          ((null older) nil)
11196          ((numberp all)
11197           (if (< all len)
11198               (setq older (last older all))))
11199          (all nil)
11200          (t
11201           (if (and (numberp gnus-large-newsgroup)
11202                    (> len gnus-large-newsgroup))
11203               (let ((input
11204                      (read-string
11205                       (format
11206                        "How many articles from %s (default %d): "
11207                        (gnus-limit-string
11208                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
11209                        len))))
11210                 (unless (string-match "^[ \t]*$" input)
11211                   (setq all (string-to-number input))
11212                   (if (< all len)
11213                       (setq older (last older all))))))))
11214         (if (not older)
11215             (message "No old news.")
11216           (gnus-summary-insert-articles older)
11217           (gnus-summary-limit (gnus-sorted-nunion old older))))
11218     (gnus-summary-position-point)))
11219
11220 (defun gnus-summary-insert-new-articles ()
11221   "Insert all new articles in this group."
11222   (interactive)
11223   (prog1
11224       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11225             (old-active gnus-newsgroup-active)
11226             (nnmail-fetched-sources (list t))
11227             i new)
11228         (setq gnus-newsgroup-active
11229               (gnus-activate-group gnus-newsgroup-name 'scan))
11230         (setq i (1+ (cdr old-active)))
11231         (while (<= i (cdr gnus-newsgroup-active))
11232           (push i new)
11233           (incf i))
11234         (if (not new)
11235             (message "No gnus is bad news.")
11236           (setq new (nreverse new))
11237           (gnus-summary-insert-articles new)
11238           (setq gnus-newsgroup-unreads
11239                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11240           (gnus-summary-limit (gnus-sorted-nunion old new))))
11241     (gnus-summary-position-point)))
11242
11243 (gnus-summary-make-all-marking-commands)
11244
11245 (gnus-ems-redefine)
11246
11247 (provide 'gnus-sum)
11248
11249 (run-hooks 'gnus-sum-load-hook)
11250
11251 ;;; gnus-sum.el ends here