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-loose-mime nil
1068   "If non-nil, don't require MIME-Version header.
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     "u" gnus-article-unsplit-urls
1762     "f" gnus-article-display-x-face
1763     "l" gnus-summary-stop-page-breaking
1764     "r" gnus-summary-caesar-message
1765     "t" gnus-article-toggle-headers
1766     "g" gnus-treat-smiley
1767     "v" gnus-summary-verbose-headers
1768     "m" gnus-summary-toggle-mime
1769     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1770     "p" gnus-article-verify-x-pgp-sig
1771     "d" gnus-article-treat-dumbquotes)
1772
1773   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1774     "a" gnus-article-hide
1775     "h" gnus-article-toggle-headers
1776     "b" gnus-article-hide-boring-headers
1777     "s" gnus-article-hide-signature
1778     "c" gnus-article-hide-citation
1779     "C" gnus-article-hide-citation-in-followups
1780     "l" gnus-article-hide-list-identifiers
1781     "p" gnus-article-hide-pgp
1782     "B" gnus-article-strip-banner
1783     "P" gnus-article-hide-pem
1784     "\C-c" gnus-article-hide-citation-maybe)
1785
1786   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1787     "a" gnus-article-highlight
1788     "h" gnus-article-highlight-headers
1789     "c" gnus-article-highlight-citation
1790     "s" gnus-article-highlight-signature)
1791
1792   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1793     "f" gnus-article-treat-fold-headers
1794     "u" gnus-article-treat-unfold-headers
1795     "n" gnus-article-treat-fold-newsgroups)
1796
1797   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1798     "x" gnus-article-display-x-face
1799     "s" gnus-treat-smiley
1800     "D" gnus-article-remove-images
1801     "f" gnus-treat-from-picon
1802     "m" gnus-treat-mail-picon
1803     "n" gnus-treat-newsgroups-picon)
1804
1805   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1806     "z" gnus-article-date-ut
1807     "u" gnus-article-date-ut
1808     "l" gnus-article-date-local
1809     "p" gnus-article-date-english
1810     "e" gnus-article-date-lapsed
1811     "o" gnus-article-date-original
1812     "i" gnus-article-date-iso8601
1813     "s" gnus-article-date-user)
1814
1815   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1816     "t" gnus-article-remove-trailing-blank-lines
1817     "l" gnus-article-strip-leading-blank-lines
1818     "m" gnus-article-strip-multiple-blank-lines
1819     "a" gnus-article-strip-blank-lines
1820     "A" gnus-article-strip-all-blank-lines
1821     "s" gnus-article-strip-leading-space
1822     "e" gnus-article-strip-trailing-space
1823     "w" gnus-article-remove-leading-whitespace)
1824
1825   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1826     "v" gnus-version
1827     "f" gnus-summary-fetch-faq
1828     "d" gnus-summary-describe-group
1829     "h" gnus-summary-describe-briefly
1830     "i" gnus-info-find-node)
1831
1832   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1833     "e" gnus-summary-expire-articles
1834     "\M-\C-e" gnus-summary-expire-articles-now
1835     "\177" gnus-summary-delete-article
1836     [delete] gnus-summary-delete-article
1837     [backspace] gnus-summary-delete-article
1838     "m" gnus-summary-move-article
1839     "r" gnus-summary-respool-article
1840     "w" gnus-summary-edit-article
1841     "c" gnus-summary-copy-article
1842     "B" gnus-summary-crosspost-article
1843     "q" gnus-summary-respool-query
1844     "t" gnus-summary-respool-trace
1845     "i" gnus-summary-import-article
1846     "I" gnus-summary-create-article
1847     "p" gnus-summary-article-posted-p)
1848
1849   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1850     "o" gnus-summary-save-article
1851     "m" gnus-summary-save-article-mail
1852     "F" gnus-summary-write-article-file
1853     "r" gnus-summary-save-article-rmail
1854     "f" gnus-summary-save-article-file
1855     "b" gnus-summary-save-article-body-file
1856     "h" gnus-summary-save-article-folder
1857     "v" gnus-summary-save-article-vm
1858     "p" gnus-summary-pipe-output
1859     "P" gnus-summary-muttprint
1860     "s" gnus-soup-add-article)
1861
1862   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1863     "b" gnus-summary-display-buttonized
1864     "m" gnus-summary-repair-multipart
1865     "v" gnus-article-view-part
1866     "o" gnus-article-save-part
1867     "c" gnus-article-copy-part
1868     "C" gnus-article-view-part-as-charset
1869     "e" gnus-article-view-part-externally
1870     "E" gnus-article-encrypt-body
1871     "i" gnus-article-inline-part
1872     "|" gnus-article-pipe-part))
1873
1874 (defvar gnus-article-post-menu nil)
1875
1876 (defun gnus-summary-make-menu-bar ()
1877   (gnus-turn-off-edit-menu 'summary)
1878
1879   (unless (boundp 'gnus-summary-misc-menu)
1880
1881     (easy-menu-define
1882      gnus-summary-kill-menu gnus-summary-mode-map ""
1883      (cons
1884       "Score"
1885       (nconc
1886        (list
1887         ["Customize" gnus-score-customize t])
1888        (gnus-make-score-map 'increase)
1889        (gnus-make-score-map 'lower)
1890        '(("Mark"
1891           ["Kill below" gnus-summary-kill-below t]
1892           ["Mark above" gnus-summary-mark-above t]
1893           ["Tick above" gnus-summary-tick-above t]
1894           ["Clear above" gnus-summary-clear-above t])
1895          ["Current score" gnus-summary-current-score t]
1896          ["Set score" gnus-summary-set-score t]
1897          ["Switch current score file..." gnus-score-change-score-file t]
1898          ["Set mark below..." gnus-score-set-mark-below t]
1899          ["Set expunge below..." gnus-score-set-expunge-below t]
1900          ["Edit current score file" gnus-score-edit-current-scores t]
1901          ["Edit score file" gnus-score-edit-file t]
1902          ["Trace score" gnus-score-find-trace t]
1903          ["Find words" gnus-score-find-favourite-words t]
1904          ["Rescore buffer" gnus-summary-rescore t]
1905          ["Increase score..." gnus-summary-increase-score t]
1906          ["Lower score..." gnus-summary-lower-score t]))))
1907
1908     ;; Define both the Article menu in the summary buffer and the
1909     ;; equivalent Commands menu in the article buffer here for
1910     ;; consistency.
1911     (let ((innards
1912            `(("Hide"
1913               ["All" gnus-article-hide t]
1914               ["Headers" gnus-article-toggle-headers t]
1915               ["Signature" gnus-article-hide-signature t]
1916               ["Citation" gnus-article-hide-citation t]
1917               ["List identifiers" gnus-article-hide-list-identifiers t]
1918               ["PGP" gnus-article-hide-pgp t]
1919               ["Banner" gnus-article-strip-banner t]
1920               ["Boring headers" gnus-article-hide-boring-headers t])
1921              ("Highlight"
1922               ["All" gnus-article-highlight t]
1923               ["Headers" gnus-article-highlight-headers t]
1924               ["Signature" gnus-article-highlight-signature t]
1925               ["Citation" gnus-article-highlight-citation t])
1926              ("Date"
1927               ["Local" gnus-article-date-local t]
1928               ["ISO8601" gnus-article-date-iso8601 t]
1929               ["UT" gnus-article-date-ut t]
1930               ["Original" gnus-article-date-original t]
1931               ["Lapsed" gnus-article-date-lapsed t]
1932               ["User-defined" gnus-article-date-user t])
1933              ("Display"
1934               ["Remove images" gnus-article-remove-images t]
1935               ["Toggle smiley" gnus-treat-smiley t]
1936               ["Show X-Face" gnus-article-display-x-face t]
1937               ["Show picons in From" gnus-treat-from-picon t]
1938               ["Show picons in mail headers" gnus-treat-mail-picon t]
1939               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1940              ("Washing"
1941               ("Remove Blanks"
1942                ["Leading" gnus-article-strip-leading-blank-lines t]
1943                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1944                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1945                ["All of the above" gnus-article-strip-blank-lines t]
1946                ["All" gnus-article-strip-all-blank-lines t]
1947                ["Leading space" gnus-article-strip-leading-space t]
1948                ["Trailing space" gnus-article-strip-trailing-space t]
1949                ["Leading space in headers"
1950                 gnus-article-remove-leading-whitespace t])
1951               ["Overstrike" gnus-article-treat-overstrike t]
1952               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1953               ["Emphasis" gnus-article-emphasize t]
1954               ["Word wrap" gnus-article-fill-cited-article t]
1955               ["Fill long lines" gnus-article-fill-long-lines t]
1956               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1957               ["CR" gnus-article-remove-cr t]
1958               ["Rot 13" gnus-summary-caesar-message
1959                ,@(if (featurep 'xemacs) '(t)
1960                    '(:help "\"Caesar rotate\" article by 13"))]
1961               ["Unix pipe" gnus-summary-pipe-message t]
1962               ["Add buttons" gnus-article-add-buttons t]
1963               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1964               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1965               ["Toggle MIME" gnus-summary-toggle-mime t]
1966               ["Verbose header" gnus-summary-verbose-headers t]
1967               ["Toggle header" gnus-summary-toggle-header t]
1968               ["Unfold headers" gnus-article-treat-unfold-headers t]
1969               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1970               ["Html" gnus-article-wash-html t]
1971               ["URLs" gnus-article-unsplit-urls t]
1972               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1973               ["HZ" gnus-article-decode-HZ t])
1974              ("Output"
1975               ["Save in default format" gnus-summary-save-article
1976                ,@(if (featurep 'xemacs) '(t)
1977                    '(:help "Save article using default method"))]
1978               ["Save in file" gnus-summary-save-article-file
1979                ,@(if (featurep 'xemacs) '(t)
1980                    '(:help "Save article in file"))]
1981               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1982               ["Save in MH folder" gnus-summary-save-article-folder t]
1983               ["Save in VM folder" gnus-summary-save-article-vm t]
1984               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1985               ["Save body in file" gnus-summary-save-article-body-file t]
1986               ["Pipe through a filter" gnus-summary-pipe-output t]
1987               ["Add to SOUP packet" gnus-soup-add-article t]
1988               ["Print with Muttprint" gnus-summary-muttprint t]
1989               ["Print" gnus-summary-print-article t])
1990              ("Backend"
1991               ["Respool article..." gnus-summary-respool-article t]
1992               ["Move article..." gnus-summary-move-article
1993                (gnus-check-backend-function
1994                 'request-move-article gnus-newsgroup-name)]
1995               ["Copy article..." gnus-summary-copy-article t]
1996               ["Crosspost article..." gnus-summary-crosspost-article
1997                (gnus-check-backend-function
1998                 'request-replace-article gnus-newsgroup-name)]
1999               ["Import file..." gnus-summary-import-article t]
2000               ["Create article..." gnus-summary-create-article t]
2001               ["Check if posted" gnus-summary-article-posted-p t]
2002               ["Edit article" gnus-summary-edit-article
2003                (not (gnus-group-read-only-p))]
2004               ["Delete article" gnus-summary-delete-article
2005                (gnus-check-backend-function
2006                 'request-expire-articles gnus-newsgroup-name)]
2007               ["Query respool" gnus-summary-respool-query t]
2008               ["Trace respool" gnus-summary-respool-trace t]
2009               ["Delete expirable articles" gnus-summary-expire-articles-now
2010                (gnus-check-backend-function
2011                 'request-expire-articles gnus-newsgroup-name)])
2012              ("Extract"
2013               ["Uudecode" gnus-uu-decode-uu
2014                ,@(if (featurep 'xemacs) '(t)
2015                    '(:help "Decode uuencoded article(s)"))]
2016               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2017               ["Unshar" gnus-uu-decode-unshar t]
2018               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2019               ["Save" gnus-uu-decode-save t]
2020               ["Binhex" gnus-uu-decode-binhex t]
2021               ["Postscript" gnus-uu-decode-postscript t])
2022              ("Cache"
2023               ["Enter article" gnus-cache-enter-article t]
2024               ["Remove article" gnus-cache-remove-article t])
2025              ["Translate" gnus-article-babel t]
2026              ["Select article buffer" gnus-summary-select-article-buffer t]
2027              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2028              ["Isearch article..." gnus-summary-isearch-article t]
2029              ["Beginning of the article" gnus-summary-beginning-of-article t]
2030              ["End of the article" gnus-summary-end-of-article t]
2031              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2032              ["Fetch referenced articles" gnus-summary-refer-references t]
2033              ["Fetch current thread" gnus-summary-refer-thread t]
2034              ["Fetch article with id..." gnus-summary-refer-article t]
2035              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2036              ["Redisplay" gnus-summary-show-article t]
2037              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2038       (easy-menu-define
2039        gnus-summary-article-menu gnus-summary-mode-map ""
2040        (cons "Article" innards))
2041
2042       (if (not (keymapp gnus-summary-article-menu))
2043           (easy-menu-define
2044            gnus-article-commands-menu gnus-article-mode-map ""
2045            (cons "Commands" innards))
2046         ;; in Emacs, don't share menu.
2047         (setq gnus-article-commands-menu
2048               (copy-keymap gnus-summary-article-menu))
2049         (define-key gnus-article-mode-map [menu-bar commands]
2050           (cons "Commands" gnus-article-commands-menu))))
2051
2052     (easy-menu-define
2053      gnus-summary-thread-menu gnus-summary-mode-map ""
2054      '("Threads"
2055        ["Toggle threading" gnus-summary-toggle-threads t]
2056        ["Hide threads" gnus-summary-hide-all-threads t]
2057        ["Show threads" gnus-summary-show-all-threads t]
2058        ["Hide thread" gnus-summary-hide-thread t]
2059        ["Show thread" gnus-summary-show-thread t]
2060        ["Go to next thread" gnus-summary-next-thread t]
2061        ["Go to previous thread" gnus-summary-prev-thread t]
2062        ["Go down thread" gnus-summary-down-thread t]
2063        ["Go up thread" gnus-summary-up-thread t]
2064        ["Top of thread" gnus-summary-top-thread t]
2065        ["Mark thread as read" gnus-summary-kill-thread t]
2066        ["Lower thread score" gnus-summary-lower-thread t]
2067        ["Raise thread score" gnus-summary-raise-thread t]
2068        ["Rethread current" gnus-summary-rethread-current t]))
2069
2070     (easy-menu-define
2071      gnus-summary-post-menu gnus-summary-mode-map ""
2072      `("Post"
2073        ["Send a message (mail or news)" gnus-summary-post-news
2074         ,@(if (featurep 'xemacs) '(t)
2075             '(:help "Post an article"))]
2076        ["Followup" gnus-summary-followup
2077         ,@(if (featurep 'xemacs) '(t)
2078             '(:help "Post followup to this article"))]
2079        ["Followup and yank" gnus-summary-followup-with-original
2080         ,@(if (featurep 'xemacs) '(t)
2081             '(:help "Post followup to this article, quoting its contents"))]
2082        ["Supersede article" gnus-summary-supersede-article t]
2083        ["Cancel article" gnus-summary-cancel-article
2084         ,@(if (featurep 'xemacs) '(t)
2085             '(:help "Cancel an article you posted"))]
2086        ["Reply" gnus-summary-reply t]
2087        ["Reply and yank" gnus-summary-reply-with-original t]
2088        ["Wide reply" gnus-summary-wide-reply t]
2089        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2090         ,@(if (featurep 'xemacs) '(t)
2091             '(:help "Mail a reply, quoting this article"))]
2092        ["Very wide reply" gnus-summary-very-wide-reply t]
2093        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2094         ,@(if (featurep 'xemacs) '(t)
2095             '(:help "Mail a very wide reply, quoting this article"))]
2096        ["Mail forward" gnus-summary-mail-forward t]
2097        ["Post forward" gnus-summary-post-forward t]
2098        ["Digest and mail" gnus-summary-digest-mail-forward t]
2099        ["Digest and post" gnus-summary-digest-post-forward t]
2100        ["Resend message" gnus-summary-resend-message t]
2101        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2102        ["Send a mail" gnus-summary-mail-other-window t]
2103        ["Create a local message" gnus-summary-news-other-window t]
2104        ["Uuencode and post" gnus-uu-post-news
2105         ,@(if (featurep 'xemacs) '(t)
2106             '(:help "Post a uuencoded article"))]
2107        ["Followup via news" gnus-summary-followup-to-mail t]
2108        ["Followup via news and yank"
2109         gnus-summary-followup-to-mail-with-original t]
2110        ;;("Draft"
2111        ;;["Send" gnus-summary-send-draft t]
2112        ;;["Send bounced" gnus-resend-bounced-mail t])
2113        ))
2114
2115     (cond
2116      ((not (keymapp gnus-summary-post-menu))
2117       (setq gnus-article-post-menu gnus-summary-post-menu))
2118      ((not gnus-article-post-menu)
2119       ;; Don't share post menu.
2120       (setq gnus-article-post-menu
2121             (copy-keymap gnus-summary-post-menu))))
2122     (define-key gnus-article-mode-map [menu-bar post]
2123       (cons "Post" gnus-article-post-menu))
2124
2125     (easy-menu-define
2126      gnus-summary-misc-menu gnus-summary-mode-map ""
2127      `("Gnus"
2128        ("Mark Read"
2129         ["Mark as read" gnus-summary-mark-as-read-forward t]
2130         ["Mark same subject and select"
2131          gnus-summary-kill-same-subject-and-select t]
2132         ["Mark same subject" gnus-summary-kill-same-subject t]
2133         ["Catchup" gnus-summary-catchup
2134          ,@(if (featurep 'xemacs) '(t)
2135              '(:help "Mark unread articles in this group as read"))]
2136         ["Catchup all" gnus-summary-catchup-all t]
2137         ["Catchup to here" gnus-summary-catchup-to-here t]
2138         ["Catchup from here" gnus-summary-catchup-from-here t]
2139         ["Catchup region" gnus-summary-mark-region-as-read t]
2140         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2141        ("Mark Various"
2142         ["Tick" gnus-summary-tick-article-forward t]
2143         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2144         ["Remove marks" gnus-summary-clear-mark-forward t]
2145         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2146         ["Set bookmark" gnus-summary-set-bookmark t]
2147         ["Remove bookmark" gnus-summary-remove-bookmark t])
2148        ("Limit to"
2149         ["Marks..." gnus-summary-limit-to-marks t]
2150         ["Subject..." gnus-summary-limit-to-subject t]
2151         ["Author..." gnus-summary-limit-to-author t]
2152         ["Age..." gnus-summary-limit-to-age t]
2153         ["Extra..." gnus-summary-limit-to-extra t]
2154         ["Score" gnus-summary-limit-to-score t]
2155         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2156         ["Unread" gnus-summary-limit-to-unread t]
2157         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2158         ["Articles" gnus-summary-limit-to-articles t]
2159         ["Pop limit" gnus-summary-pop-limit t]
2160         ["Show dormant" gnus-summary-limit-include-dormant t]
2161         ["Hide childless dormant"
2162          gnus-summary-limit-exclude-childless-dormant t]
2163         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2164         ["Hide marked" gnus-summary-limit-exclude-marks t]
2165         ["Show expunged" gnus-summary-limit-include-expunged t])
2166        ("Process Mark"
2167         ["Set mark" gnus-summary-mark-as-processable t]
2168         ["Remove mark" gnus-summary-unmark-as-processable t]
2169         ["Remove all marks" gnus-summary-unmark-all-processable t]
2170         ["Mark above" gnus-uu-mark-over t]
2171         ["Mark series" gnus-uu-mark-series t]
2172         ["Mark region" gnus-uu-mark-region t]
2173         ["Unmark region" gnus-uu-unmark-region t]
2174         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2175         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2176         ["Mark all" gnus-uu-mark-all t]
2177         ["Mark buffer" gnus-uu-mark-buffer t]
2178         ["Mark sparse" gnus-uu-mark-sparse t]
2179         ["Mark thread" gnus-uu-mark-thread t]
2180         ["Unmark thread" gnus-uu-unmark-thread t]
2181         ("Process Mark Sets"
2182          ["Kill" gnus-summary-kill-process-mark t]
2183          ["Yank" gnus-summary-yank-process-mark
2184           gnus-newsgroup-process-stack]
2185          ["Save" gnus-summary-save-process-mark t]))
2186        ("Scroll article"
2187         ["Page forward" gnus-summary-next-page
2188          ,@(if (featurep 'xemacs) '(t)
2189              '(:help "Show next page of article"))]
2190         ["Page backward" gnus-summary-prev-page
2191          ,@(if (featurep 'xemacs) '(t)
2192              '(:help "Show previous page of article"))]
2193         ["Line forward" gnus-summary-scroll-up t])
2194        ("Move"
2195         ["Next unread article" gnus-summary-next-unread-article t]
2196         ["Previous unread article" gnus-summary-prev-unread-article t]
2197         ["Next article" gnus-summary-next-article t]
2198         ["Previous article" gnus-summary-prev-article t]
2199         ["Next unread subject" gnus-summary-next-unread-subject t]
2200         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2201         ["Next article same subject" gnus-summary-next-same-subject t]
2202         ["Previous article same subject" gnus-summary-prev-same-subject t]
2203         ["First unread article" gnus-summary-first-unread-article t]
2204         ["Best unread article" gnus-summary-best-unread-article t]
2205         ["Go to subject number..." gnus-summary-goto-subject t]
2206         ["Go to article number..." gnus-summary-goto-article t]
2207         ["Go to the last article" gnus-summary-goto-last-article t]
2208         ["Pop article off history" gnus-summary-pop-article t])
2209        ("Sort"
2210         ["Sort by number" gnus-summary-sort-by-number t]
2211         ["Sort by author" gnus-summary-sort-by-author t]
2212         ["Sort by subject" gnus-summary-sort-by-subject t]
2213         ["Sort by date" gnus-summary-sort-by-date t]
2214         ["Sort by score" gnus-summary-sort-by-score t]
2215         ["Sort by lines" gnus-summary-sort-by-lines t]
2216         ["Sort by characters" gnus-summary-sort-by-chars t]
2217         ["Original sort" gnus-summary-sort-by-original t])
2218        ("Help"
2219         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2220         ["Describe group" gnus-summary-describe-group t]
2221         ["Read manual" gnus-info-find-node t])
2222        ("Modes"
2223         ["Pick and read" gnus-pick-mode t]
2224         ["Binary" gnus-binary-mode t])
2225        ("Regeneration"
2226         ["Regenerate" gnus-summary-prepare t]
2227         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2228         ["Toggle threading" gnus-summary-toggle-threads t])
2229        ["See old articles" gnus-summary-insert-old-articles t]
2230        ["See new articles" gnus-summary-insert-new-articles t]
2231        ["Filter articles..." gnus-summary-execute-command t]
2232        ["Run command on subjects..." gnus-summary-universal-argument t]
2233        ["Search articles forward..." gnus-summary-search-article-forward t]
2234        ["Search articles backward..." gnus-summary-search-article-backward t]
2235        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2236        ["Expand window" gnus-summary-expand-window t]
2237        ["Expire expirable articles" gnus-summary-expire-articles
2238         (gnus-check-backend-function
2239          'request-expire-articles gnus-newsgroup-name)]
2240        ["Edit local kill file" gnus-summary-edit-local-kill t]
2241        ["Edit main kill file" gnus-summary-edit-global-kill t]
2242        ["Edit group parameters" gnus-summary-edit-parameters t]
2243        ["Customize group parameters" gnus-summary-customize-parameters t]
2244        ["Send a bug report" gnus-bug t]
2245        ("Exit"
2246         ["Catchup and exit" gnus-summary-catchup-and-exit
2247          ,@(if (featurep 'xemacs) '(t)
2248              '(:help "Mark unread articles in this group as read, then exit"))]
2249         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2250         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2251         ["Exit group" gnus-summary-exit
2252          ,@(if (featurep 'xemacs) '(t)
2253              '(:help "Exit current group, return to group selection mode"))]
2254         ["Exit group without updating" gnus-summary-exit-no-update t]
2255         ["Exit and goto next group" gnus-summary-next-group t]
2256         ["Exit and goto prev group" gnus-summary-prev-group t]
2257         ["Reselect group" gnus-summary-reselect-current-group t]
2258         ["Rescan group" gnus-summary-rescan-group t]
2259         ["Update dribble" gnus-summary-save-newsrc t])))
2260
2261     (gnus-run-hooks 'gnus-summary-menu-hook)))
2262
2263 (defvar gnus-summary-tool-bar-map nil)
2264
2265 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2266 (defun gnus-summary-make-tool-bar ()
2267   (if (and (fboundp 'tool-bar-add-item-from-menu)
2268            (default-value 'tool-bar-mode)
2269            (not gnus-summary-tool-bar-map))
2270       (setq gnus-summary-tool-bar-map
2271             (let ((tool-bar-map (make-sparse-keymap))
2272                   (load-path (mm-image-load-path)))
2273               (tool-bar-add-item-from-menu
2274                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2275               (tool-bar-add-item-from-menu
2276                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2277               (tool-bar-add-item-from-menu
2278                'gnus-summary-post-news "post" gnus-summary-mode-map)
2279               (tool-bar-add-item-from-menu
2280                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2281               (tool-bar-add-item-from-menu
2282                'gnus-summary-followup "followup" gnus-summary-mode-map)
2283               (tool-bar-add-item-from-menu
2284                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2285               (tool-bar-add-item-from-menu
2286                'gnus-summary-reply "reply" gnus-summary-mode-map)
2287               (tool-bar-add-item-from-menu
2288                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2289               (tool-bar-add-item-from-menu
2290                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2291               (tool-bar-add-item-from-menu
2292                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2293               (tool-bar-add-item-from-menu
2294                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2295               (tool-bar-add-item-from-menu
2296                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2297               (tool-bar-add-item-from-menu
2298                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2299               (tool-bar-add-item-from-menu
2300                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2301               (tool-bar-add-item-from-menu
2302                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2303               tool-bar-map)))
2304   (if gnus-summary-tool-bar-map
2305       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2306
2307 (defun gnus-score-set-default (var value)
2308   "A version of set that updates the GNU Emacs menu-bar."
2309   (set var value)
2310   ;; It is the message that forces the active status to be updated.
2311   (message ""))
2312
2313 (defun gnus-make-score-map (type)
2314   "Make a summary score map of type TYPE."
2315   (if t
2316       nil
2317     (let ((headers '(("author" "from" string)
2318                      ("subject" "subject" string)
2319                      ("article body" "body" string)
2320                      ("article head" "head" string)
2321                      ("xref" "xref" string)
2322                      ("extra header" "extra" string)
2323                      ("lines" "lines" number)
2324                      ("followups to author" "followup" string)))
2325           (types '((number ("less than" <)
2326                            ("greater than" >)
2327                            ("equal" =))
2328                    (string ("substring" s)
2329                            ("exact string" e)
2330                            ("fuzzy string" f)
2331                            ("regexp" r))))
2332           (perms '(("temporary" (current-time-string))
2333                    ("permanent" nil)
2334                    ("immediate" now)))
2335           header)
2336       (list
2337        (apply
2338         'nconc
2339         (list
2340          (if (eq type 'lower)
2341              "Lower score"
2342            "Increase score"))
2343         (let (outh)
2344           (while headers
2345             (setq header (car headers))
2346             (setq outh
2347                   (cons
2348                    (apply
2349                     'nconc
2350                     (list (car header))
2351                     (let ((ts (cdr (assoc (nth 2 header) types)))
2352                           outt)
2353                       (while ts
2354                         (setq outt
2355                               (cons
2356                                (apply
2357                                 'nconc
2358                                 (list (caar ts))
2359                                 (let ((ps perms)
2360                                       outp)
2361                                   (while ps
2362                                     (setq outp
2363                                           (cons
2364                                            (vector
2365                                             (caar ps)
2366                                             (list
2367                                              'gnus-summary-score-entry
2368                                              (nth 1 header)
2369                                              (if (or (string= (nth 1 header)
2370                                                               "head")
2371                                                      (string= (nth 1 header)
2372                                                               "body"))
2373                                                  ""
2374                                                (list 'gnus-summary-header
2375                                                      (nth 1 header)))
2376                                              (list 'quote (nth 1 (car ts)))
2377                                              (list 'gnus-score-delta-default
2378                                                    nil)
2379                                              (nth 1 (car ps))
2380                                              t)
2381                                             t)
2382                                            outp))
2383                                     (setq ps (cdr ps)))
2384                                   (list (nreverse outp))))
2385                                outt))
2386                         (setq ts (cdr ts)))
2387                       (list (nreverse outt))))
2388                    outh))
2389             (setq headers (cdr headers)))
2390           (list (nreverse outh))))))))
2391
2392 \f
2393
2394 (defun gnus-summary-mode (&optional group)
2395   "Major mode for reading articles.
2396
2397 All normal editing commands are switched off.
2398 \\<gnus-summary-mode-map>
2399 Each line in this buffer represents one article.  To read an
2400 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2401 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2402 respectively.
2403
2404 You can also post articles and send mail from this buffer.  To
2405 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2406 of an article, type `\\[gnus-summary-reply]'.
2407
2408 There are approx. one gazillion commands you can execute in this
2409 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2410
2411 The following commands are available:
2412
2413 \\{gnus-summary-mode-map}"
2414   (interactive)
2415   (kill-all-local-variables)
2416   (when (gnus-visual-p 'summary-menu 'menu)
2417     (gnus-summary-make-menu-bar)
2418     (gnus-summary-make-tool-bar))
2419   (gnus-summary-make-local-variables)
2420   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2421     (gnus-summary-make-local-variables))
2422   (gnus-make-thread-indent-array)
2423   (gnus-simplify-mode-line)
2424   (setq major-mode 'gnus-summary-mode)
2425   (setq mode-name "Summary")
2426   (make-local-variable 'minor-mode-alist)
2427   (use-local-map gnus-summary-mode-map)
2428   (buffer-disable-undo)
2429   (setq buffer-read-only t)             ;Disable modification
2430   (setq truncate-lines t)
2431   (setq selective-display t)
2432   (setq selective-display-ellipses t)   ;Display `...'
2433   (gnus-summary-set-display-table)
2434   (gnus-set-default-directory)
2435   (setq gnus-newsgroup-name group)
2436   (unless (gnus-news-group-p group)
2437     (setq gnus-newsgroup-incorporated
2438           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2439   (make-local-variable 'gnus-summary-line-format)
2440   (make-local-variable 'gnus-summary-line-format-spec)
2441   (make-local-variable 'gnus-summary-dummy-line-format)
2442   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2443   (make-local-variable 'gnus-summary-mark-positions)
2444   (make-local-hook 'pre-command-hook)
2445   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2446   (gnus-run-hooks 'gnus-summary-mode-hook)
2447   (turn-on-gnus-mailing-list-mode)
2448   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2449   (gnus-update-summary-mark-positions))
2450
2451 (defun gnus-summary-make-local-variables ()
2452   "Make all the local summary buffer variables."
2453   (let (global)
2454     (dolist (local gnus-summary-local-variables)
2455       (if (consp local)
2456           (progn
2457             (if (eq (cdr local) 'global)
2458                 ;; Copy the global value of the variable.
2459                 (setq global (symbol-value (car local)))
2460               ;; Use the value from the list.
2461               (setq global (eval (cdr local))))
2462             (set (make-local-variable (car local)) global))
2463         ;; Simple nil-valued local variable.
2464         (set (make-local-variable local) nil)))))
2465
2466 (defun gnus-summary-clear-local-variables ()
2467   (let ((locals gnus-summary-local-variables))
2468     (while locals
2469       (if (consp (car locals))
2470           (and (vectorp (caar locals))
2471                (set (caar locals) nil))
2472         (and (vectorp (car locals))
2473              (set (car locals) nil)))
2474       (setq locals (cdr locals)))))
2475
2476 ;; Summary data functions.
2477
2478 (defmacro gnus-data-number (data)
2479   `(car ,data))
2480
2481 (defmacro gnus-data-set-number (data number)
2482   `(setcar ,data ,number))
2483
2484 (defmacro gnus-data-mark (data)
2485   `(nth 1 ,data))
2486
2487 (defmacro gnus-data-set-mark (data mark)
2488   `(setcar (nthcdr 1 ,data) ,mark))
2489
2490 (defmacro gnus-data-pos (data)
2491   `(nth 2 ,data))
2492
2493 (defmacro gnus-data-set-pos (data pos)
2494   `(setcar (nthcdr 2 ,data) ,pos))
2495
2496 (defmacro gnus-data-header (data)
2497   `(nth 3 ,data))
2498
2499 (defmacro gnus-data-set-header (data header)
2500   `(setcar (nthcdr 3 ,data) ,header))
2501
2502 (defmacro gnus-data-level (data)
2503   `(nth 4 ,data))
2504
2505 (defmacro gnus-data-unread-p (data)
2506   `(= (nth 1 ,data) gnus-unread-mark))
2507
2508 (defmacro gnus-data-read-p (data)
2509   `(/= (nth 1 ,data) gnus-unread-mark))
2510
2511 (defmacro gnus-data-pseudo-p (data)
2512   `(consp (nth 3 ,data)))
2513
2514 (defmacro gnus-data-find (number)
2515   `(assq ,number gnus-newsgroup-data))
2516
2517 (defmacro gnus-data-find-list (number &optional data)
2518   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2519      (memq (assq ,number bdata)
2520            bdata)))
2521
2522 (defmacro gnus-data-make (number mark pos header level)
2523   `(list ,number ,mark ,pos ,header ,level))
2524
2525 (defun gnus-data-enter (after-article number mark pos header level offset)
2526   (let ((data (gnus-data-find-list after-article)))
2527     (unless data
2528       (error "No such article: %d" after-article))
2529     (setcdr data (cons (gnus-data-make number mark pos header level)
2530                        (cdr data)))
2531     (setq gnus-newsgroup-data-reverse nil)
2532     (gnus-data-update-list (cddr data) offset)))
2533
2534 (defun gnus-data-enter-list (after-article list &optional offset)
2535   (when list
2536     (let ((data (and after-article (gnus-data-find-list after-article)))
2537           (ilist list))
2538       (if (not (or data
2539                    after-article))
2540           (let ((odata gnus-newsgroup-data))
2541             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2542             (when offset
2543               (gnus-data-update-list odata offset)))
2544         ;; Find the last element in the list to be spliced into the main
2545         ;; list.
2546         (while (cdr list)
2547           (setq list (cdr list)))
2548         (if (not data)
2549             (progn
2550               (setcdr list gnus-newsgroup-data)
2551               (setq gnus-newsgroup-data ilist)
2552               (when offset
2553                 (gnus-data-update-list (cdr list) offset)))
2554           (setcdr list (cdr data))
2555           (setcdr data ilist)
2556           (when offset
2557             (gnus-data-update-list (cdr list) offset))))
2558       (setq gnus-newsgroup-data-reverse nil))))
2559
2560 (defun gnus-data-remove (article &optional offset)
2561   (let ((data gnus-newsgroup-data))
2562     (if (= (gnus-data-number (car data)) article)
2563         (progn
2564           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2565                 gnus-newsgroup-data-reverse nil)
2566           (when offset
2567             (gnus-data-update-list gnus-newsgroup-data offset)))
2568       (while (cdr data)
2569         (when (= (gnus-data-number (cadr data)) article)
2570           (setcdr data (cddr data))
2571           (when offset
2572             (gnus-data-update-list (cdr data) offset))
2573           (setq data nil
2574                 gnus-newsgroup-data-reverse nil))
2575         (setq data (cdr data))))))
2576
2577 (defmacro gnus-data-list (backward)
2578   `(if ,backward
2579        (or gnus-newsgroup-data-reverse
2580            (setq gnus-newsgroup-data-reverse
2581                  (reverse gnus-newsgroup-data)))
2582      gnus-newsgroup-data))
2583
2584 (defun gnus-data-update-list (data offset)
2585   "Add OFFSET to the POS of all data entries in DATA."
2586   (setq gnus-newsgroup-data-reverse nil)
2587   (while data
2588     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2589     (setq data (cdr data))))
2590
2591 (defun gnus-summary-article-pseudo-p (article)
2592   "Say whether this article is a pseudo article or not."
2593   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2594
2595 (defmacro gnus-summary-article-sparse-p (article)
2596   "Say whether this article is a sparse article or not."
2597   `(memq ,article gnus-newsgroup-sparse))
2598
2599 (defmacro gnus-summary-article-ancient-p (article)
2600   "Say whether this article is a sparse article or not."
2601   `(memq ,article gnus-newsgroup-ancient))
2602
2603 (defun gnus-article-parent-p (number)
2604   "Say whether this article is a parent or not."
2605   (let ((data (gnus-data-find-list number)))
2606     (and (cdr data)                     ; There has to be an article after...
2607          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2608             (gnus-data-level (nth 1 data))))))
2609
2610 (defun gnus-article-children (number)
2611   "Return a list of all children to NUMBER."
2612   (let* ((data (gnus-data-find-list number))
2613          (level (gnus-data-level (car data)))
2614          children)
2615     (setq data (cdr data))
2616     (while (and data
2617                 (= (gnus-data-level (car data)) (1+ level)))
2618       (push (gnus-data-number (car data)) children)
2619       (setq data (cdr data)))
2620     children))
2621
2622 (defmacro gnus-summary-skip-intangible ()
2623   "If the current article is intangible, then jump to a different article."
2624   '(let ((to (get-text-property (point) 'gnus-intangible)))
2625      (and to (gnus-summary-goto-subject to))))
2626
2627 (defmacro gnus-summary-article-intangible-p ()
2628   "Say whether this article is intangible or not."
2629   '(get-text-property (point) 'gnus-intangible))
2630
2631 (defun gnus-article-read-p (article)
2632   "Say whether ARTICLE is read or not."
2633   (not (or (memq article gnus-newsgroup-marked)
2634            (memq article gnus-newsgroup-unreads)
2635            (memq article gnus-newsgroup-unselected)
2636            (memq article gnus-newsgroup-dormant))))
2637
2638 ;; Some summary mode macros.
2639
2640 (defmacro gnus-summary-article-number ()
2641   "The article number of the article on the current line.
2642 If there isn's an article number here, then we return the current
2643 article number."
2644   '(progn
2645      (gnus-summary-skip-intangible)
2646      (or (get-text-property (point) 'gnus-number)
2647          (gnus-summary-last-subject))))
2648
2649 (defmacro gnus-summary-article-header (&optional number)
2650   "Return the header of article NUMBER."
2651   `(gnus-data-header (gnus-data-find
2652                       ,(or number '(gnus-summary-article-number)))))
2653
2654 (defmacro gnus-summary-thread-level (&optional number)
2655   "Return the level of thread that starts with article NUMBER."
2656   `(if (and (eq gnus-summary-make-false-root 'dummy)
2657             (get-text-property (point) 'gnus-intangible))
2658        0
2659      (gnus-data-level (gnus-data-find
2660                        ,(or number '(gnus-summary-article-number))))))
2661
2662 (defmacro gnus-summary-article-mark (&optional number)
2663   "Return the mark of article NUMBER."
2664   `(gnus-data-mark (gnus-data-find
2665                     ,(or number '(gnus-summary-article-number)))))
2666
2667 (defmacro gnus-summary-article-pos (&optional number)
2668   "Return the position of the line of article NUMBER."
2669   `(gnus-data-pos (gnus-data-find
2670                    ,(or number '(gnus-summary-article-number)))))
2671
2672 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2673 (defmacro gnus-summary-article-subject (&optional number)
2674   "Return current subject string or nil if nothing."
2675   `(let ((headers
2676           ,(if number
2677                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2678              '(gnus-data-header (assq (gnus-summary-article-number)
2679                                       gnus-newsgroup-data)))))
2680      (and headers
2681           (vectorp headers)
2682           (mail-header-subject headers))))
2683
2684 (defmacro gnus-summary-article-score (&optional number)
2685   "Return current article score."
2686   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2687                   gnus-newsgroup-scored))
2688        gnus-summary-default-score 0))
2689
2690 (defun gnus-summary-article-children (&optional number)
2691   "Return a list of article numbers that are children of article NUMBER."
2692   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2693          (level (gnus-data-level (car data)))
2694          l children)
2695     (while (and (setq data (cdr data))
2696                 (> (setq l (gnus-data-level (car data))) level))
2697       (and (= (1+ level) l)
2698            (push (gnus-data-number (car data))
2699                  children)))
2700     (nreverse children)))
2701
2702 (defun gnus-summary-article-parent (&optional number)
2703   "Return the article number of the parent of article NUMBER."
2704   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2705                                     (gnus-data-list t)))
2706          (level (gnus-data-level (car data))))
2707     (if (zerop level)
2708         ()                              ; This is a root.
2709       ;; We search until we find an article with a level less than
2710       ;; this one.  That function has to be the parent.
2711       (while (and (setq data (cdr data))
2712                   (not (< (gnus-data-level (car data)) level))))
2713       (and data (gnus-data-number (car data))))))
2714
2715 (defun gnus-unread-mark-p (mark)
2716   "Say whether MARK is the unread mark."
2717   (= mark gnus-unread-mark))
2718
2719 (defun gnus-read-mark-p (mark)
2720   "Say whether MARK is one of the marks that mark as read.
2721 This is all marks except unread, ticked, dormant, and expirable."
2722   (not (or (= mark gnus-unread-mark)
2723            (= mark gnus-ticked-mark)
2724            (= mark gnus-dormant-mark)
2725            (= mark gnus-expirable-mark))))
2726
2727 (defmacro gnus-article-mark (number)
2728   "Return the MARK of article NUMBER.
2729 This macro should only be used when computing the mark the \"first\"
2730 time; i.e., when generating the summary lines.  After that,
2731 `gnus-summary-article-mark' should be used to examine the
2732 marks of articles."
2733   `(cond
2734     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2735     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2736     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2737     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2738     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2739     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2740     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2741     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2742            gnus-ancient-mark))))
2743
2744 ;; Saving hidden threads.
2745
2746 (defmacro gnus-save-hidden-threads (&rest forms)
2747   "Save hidden threads, eval FORMS, and restore the hidden threads."
2748   (let ((config (make-symbol "config")))
2749     `(let ((,config (gnus-hidden-threads-configuration)))
2750        (unwind-protect
2751            (save-excursion
2752              ,@forms)
2753          (gnus-restore-hidden-threads-configuration ,config)))))
2754 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2755 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2756
2757 (defun gnus-data-compute-positions ()
2758   "Compute the positions of all articles."
2759   (setq gnus-newsgroup-data-reverse nil)
2760   (let ((data gnus-newsgroup-data))
2761     (save-excursion
2762       (gnus-save-hidden-threads
2763         (gnus-summary-show-all-threads)
2764         (goto-char (point-min))
2765         (while data
2766           (while (get-text-property (point) 'gnus-intangible)
2767             (forward-line 1))
2768           (gnus-data-set-pos (car data) (+ (point) 3))
2769           (setq data (cdr data))
2770           (forward-line 1))))))
2771
2772 (defun gnus-hidden-threads-configuration ()
2773   "Return the current hidden threads configuration."
2774   (save-excursion
2775     (let (config)
2776       (goto-char (point-min))
2777       (while (search-forward "\r" nil t)
2778         (push (1- (point)) config))
2779       config)))
2780
2781 (defun gnus-restore-hidden-threads-configuration (config)
2782   "Restore hidden threads configuration from CONFIG."
2783   (save-excursion
2784     (let (point buffer-read-only)
2785       (while (setq point (pop config))
2786         (when (and (< point (point-max))
2787                    (goto-char point)
2788                    (eq (char-after) ?\n))
2789           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2790
2791 ;; Various summary mode internalish functions.
2792
2793 (defun gnus-mouse-pick-article (e)
2794   (interactive "e")
2795   (mouse-set-point e)
2796   (gnus-summary-next-page nil t))
2797
2798 (defun gnus-summary-set-display-table ()
2799   "Change the display table.
2800 Odd characters have a tendency to mess
2801 up nicely formatted displays - we make all possible glyphs
2802 display only a single character."
2803
2804   ;; We start from the standard display table, if any.
2805   (let ((table (or (copy-sequence standard-display-table)
2806                    (make-display-table)))
2807         (i 32))
2808     ;; Nix out all the control chars...
2809     (while (>= (setq i (1- i)) 0)
2810       (aset table i [??]))
2811     ;; ... but not newline and cr, of course.  (cr is necessary for the
2812     ;; selective display).
2813     (aset table ?\n nil)
2814     (aset table ?\r nil)
2815     ;; We keep TAB as well.
2816     (aset table ?\t nil)
2817     ;; We nix out any glyphs over 126 that are not set already.
2818     (let ((i 256))
2819       (while (>= (setq i (1- i)) 127)
2820         ;; Only modify if the entry is nil.
2821         (unless (aref table i)
2822           (aset table i [??]))))
2823     (setq buffer-display-table table)))
2824
2825 (defun gnus-summary-set-article-display-arrow (pos)
2826   "Update the overlay arrow to point to line at position POS."
2827   (when (and gnus-summary-display-arrow
2828              (boundp 'overlay-arrow-position)
2829              (boundp 'overlay-arrow-string))
2830     (save-excursion
2831       (goto-char pos)
2832       (beginning-of-line)
2833       (unless overlay-arrow-position
2834         (setq overlay-arrow-position (make-marker)))
2835       (setq overlay-arrow-string "=>"
2836             overlay-arrow-position (set-marker overlay-arrow-position
2837                                                (point)
2838                                                (current-buffer))))))
2839
2840 (defun gnus-summary-buffer-name (group)
2841   "Return the summary buffer name of GROUP."
2842   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2843
2844 (defun gnus-summary-setup-buffer (group)
2845   "Initialize summary buffer."
2846   (let ((buffer (gnus-summary-buffer-name group))
2847         (dead-name (concat "*Dead Summary "
2848                            (gnus-group-decoded-name group) "*")))
2849     ;; If a dead summary buffer exists, we kill it.
2850     (when (gnus-buffer-live-p dead-name)
2851       (gnus-kill-buffer dead-name))
2852     (if (get-buffer buffer)
2853         (progn
2854           (set-buffer buffer)
2855           (setq gnus-summary-buffer (current-buffer))
2856           (not gnus-newsgroup-prepared))
2857       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2858       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2859       (gnus-summary-mode group)
2860       (when gnus-carpal
2861         (gnus-carpal-setup-buffer 'summary))
2862       (unless gnus-single-article-buffer
2863         (make-local-variable 'gnus-article-buffer)
2864         (make-local-variable 'gnus-article-current)
2865         (make-local-variable 'gnus-original-article-buffer))
2866       (setq gnus-newsgroup-name group)
2867       ;; Set any local variables in the group parameters.
2868       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2869       t)))
2870
2871 (defun gnus-set-global-variables ()
2872   "Set the global equivalents of the buffer-local variables.
2873 They are set to the latest values they had.  These reflect the summary
2874 buffer that was in action when the last article was fetched."
2875   (when (eq major-mode 'gnus-summary-mode)
2876     (setq gnus-summary-buffer (current-buffer))
2877     (let ((name gnus-newsgroup-name)
2878           (marked gnus-newsgroup-marked)
2879           (unread gnus-newsgroup-unreads)
2880           (headers gnus-current-headers)
2881           (data gnus-newsgroup-data)
2882           (summary gnus-summary-buffer)
2883           (article-buffer gnus-article-buffer)
2884           (original gnus-original-article-buffer)
2885           (gac gnus-article-current)
2886           (reffed gnus-reffed-article-number)
2887           (score-file gnus-current-score-file)
2888           (default-charset gnus-newsgroup-charset)
2889           vlist)
2890       (let ((locals gnus-newsgroup-variables))
2891         (while locals
2892           (if (consp (car locals))
2893               (push (eval (caar locals)) vlist)
2894             (push (eval (car locals)) vlist))
2895           (setq locals (cdr locals)))
2896         (setq vlist (nreverse vlist)))
2897       (save-excursion
2898         (set-buffer gnus-group-buffer)
2899         (setq gnus-newsgroup-name name
2900               gnus-newsgroup-marked marked
2901               gnus-newsgroup-unreads unread
2902               gnus-current-headers headers
2903               gnus-newsgroup-data data
2904               gnus-article-current gac
2905               gnus-summary-buffer summary
2906               gnus-article-buffer article-buffer
2907               gnus-original-article-buffer original
2908               gnus-reffed-article-number reffed
2909               gnus-current-score-file score-file
2910               gnus-newsgroup-charset default-charset)
2911         (let ((locals gnus-newsgroup-variables))
2912           (while locals
2913             (if (consp (car locals))
2914                 (set (caar locals) (pop vlist))
2915               (set (car locals) (pop vlist)))
2916             (setq locals (cdr locals))))
2917         ;; The article buffer also has local variables.
2918         (when (gnus-buffer-live-p gnus-article-buffer)
2919           (set-buffer gnus-article-buffer)
2920           (setq gnus-summary-buffer summary))))))
2921
2922 (defun gnus-summary-article-unread-p (article)
2923   "Say whether ARTICLE is unread or not."
2924   (memq article gnus-newsgroup-unreads))
2925
2926 (defun gnus-summary-first-article-p (&optional article)
2927   "Return whether ARTICLE is the first article in the buffer."
2928   (if (not (setq article (or article (gnus-summary-article-number))))
2929       nil
2930     (eq article (caar gnus-newsgroup-data))))
2931
2932 (defun gnus-summary-last-article-p (&optional article)
2933   "Return whether ARTICLE is the last article in the buffer."
2934   (if (not (setq article (or article (gnus-summary-article-number))))
2935       ;; All non-existent numbers are the last article.  :-)
2936       t
2937     (not (cdr (gnus-data-find-list article)))))
2938
2939 (defun gnus-make-thread-indent-array ()
2940   (let ((n 200))
2941     (unless (and gnus-thread-indent-array
2942                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2943       (setq gnus-thread-indent-array (make-vector 201 "")
2944             gnus-thread-indent-array-level gnus-thread-indent-level)
2945       (while (>= n 0)
2946         (aset gnus-thread-indent-array n
2947               (make-string (* n gnus-thread-indent-level) ? ))
2948         (setq n (1- n))))))
2949
2950 (defun gnus-update-summary-mark-positions ()
2951   "Compute where the summary marks are to go."
2952   (save-excursion
2953     (when (gnus-buffer-exists-p gnus-summary-buffer)
2954       (set-buffer gnus-summary-buffer))
2955     (let ((gnus-replied-mark 129)
2956           (gnus-score-below-mark 130)
2957           (gnus-score-over-mark 130)
2958           (gnus-download-mark 131)
2959           (spec gnus-summary-line-format-spec)
2960           gnus-visual pos)
2961       (save-excursion
2962         (gnus-set-work-buffer)
2963         (let ((gnus-summary-line-format-spec spec)
2964               (gnus-newsgroup-downloadable '((0 . t))))
2965           (gnus-summary-insert-line
2966            (make-full-mail-header 0 "" "nobody"
2967                                   "05 Apr 2001 23:33:09 +0400"
2968                                   "" "" 0 0 "" nil)
2969            0 nil 128 t nil "" nil 1)
2970           (goto-char (point-min))
2971           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2972                                              (- (point) 2)))))
2973           (goto-char (point-min))
2974           (push (cons 'replied (and (search-forward "\201" nil t)
2975                                     (- (point) 2)))
2976                 pos)
2977           (goto-char (point-min))
2978           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2979                 pos)
2980           (goto-char (point-min))
2981           (push (cons 'download
2982                       (and (search-forward "\203" nil t) (- (point) 2)))
2983                 pos)))
2984       (setq gnus-summary-mark-positions pos))))
2985
2986 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2987   "Insert a dummy root in the summary buffer."
2988   (beginning-of-line)
2989   (gnus-add-text-properties
2990    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2991    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2992
2993 (defun gnus-summary-extract-address-component (from)
2994   (or (car (funcall gnus-extract-address-components from))
2995       from))
2996
2997 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2998   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
2999                                 default-mime-charset)))
3000     ;; Is it really necessary to do this next part for each summary line?
3001     ;; Luckily, doesn't seem to slow things down much.
3002     (or
3003      (and gnus-ignored-from-addresses
3004           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3005           (let ((extra-headers (mail-header-extra header))
3006                 to
3007                 newsgroups)
3008             (cond
3009              ((setq to (cdr (assq 'To extra-headers)))
3010               (concat "-> "
3011                       (inline
3012                         (gnus-summary-extract-address-component
3013                          (funcall gnus-decode-encoded-word-function to)))))
3014              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3015               (concat "=> " newsgroups)))))
3016      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3017
3018 (defun gnus-summary-insert-line (gnus-tmp-header
3019                                  gnus-tmp-level gnus-tmp-current
3020                                  gnus-tmp-unread gnus-tmp-replied
3021                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3022                                  &optional gnus-tmp-dummy gnus-tmp-score
3023                                  gnus-tmp-process)
3024   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3025          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3026          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3027          (gnus-tmp-score-char
3028           (if (or (null gnus-summary-default-score)
3029                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3030                       gnus-summary-zcore-fuzz))
3031               ?\ ;;;Whitespace
3032             (if (< gnus-tmp-score gnus-summary-default-score)
3033                 gnus-score-below-mark gnus-score-over-mark)))
3034          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3035          (gnus-tmp-replied
3036           (cond (gnus-tmp-process gnus-process-mark)
3037                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3038                  gnus-cached-mark)
3039                 (gnus-tmp-replied gnus-replied-mark)
3040                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3041                  gnus-forwarded-mark)
3042                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3043                  gnus-saved-mark)
3044                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3045                  gnus-recent-mark)
3046                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3047                  gnus-unseen-mark)
3048                 (t gnus-no-mark)))
3049          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3050          (gnus-tmp-name
3051           (cond
3052            ((string-match "<[^>]+> *$" gnus-tmp-from)
3053             (let ((beg (match-beginning 0)))
3054               (or (and (string-match "^\".+\"" gnus-tmp-from)
3055                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3056                   (substring gnus-tmp-from 0 beg))))
3057            ((string-match "(.+)" gnus-tmp-from)
3058             (substring gnus-tmp-from
3059                        (1+ (match-beginning 0)) (1- (match-end 0))))
3060            (t gnus-tmp-from)))
3061          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3062          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3063          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3064          (buffer-read-only nil))
3065     (when (string= gnus-tmp-name "")
3066       (setq gnus-tmp-name gnus-tmp-from))
3067     (unless (numberp gnus-tmp-lines)
3068       (setq gnus-tmp-lines -1))
3069     (if (= gnus-tmp-lines -1)
3070         (setq gnus-tmp-lines "?")
3071       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3072     (gnus-put-text-property-excluding-characters-with-faces
3073      (point)
3074      (progn (eval gnus-summary-line-format-spec) (point))
3075      'gnus-number gnus-tmp-number)
3076     (when (gnus-visual-p 'summary-highlight 'highlight)
3077       (forward-line -1)
3078       (gnus-run-hooks 'gnus-summary-update-hook)
3079       (forward-line 1))))
3080
3081 (defun gnus-summary-update-line (&optional dont-update)
3082   "Update summary line after change."
3083   (when (and gnus-summary-default-score
3084              (not gnus-summary-inhibit-highlight))
3085     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3086            (article (gnus-summary-article-number))
3087            (score (gnus-summary-article-score article)))
3088       (unless dont-update
3089         (if (and gnus-summary-mark-below
3090                  (< (gnus-summary-article-score)
3091                     gnus-summary-mark-below))
3092             ;; This article has a low score, so we mark it as read.
3093             (when (memq article gnus-newsgroup-unreads)
3094               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3095           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3096             ;; This article was previously marked as read on account
3097             ;; of a low score, but now it has risen, so we mark it as
3098             ;; unread.
3099             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3100         (gnus-summary-update-mark
3101          (if (or (null gnus-summary-default-score)
3102                  (<= (abs (- score gnus-summary-default-score))
3103                      gnus-summary-zcore-fuzz))
3104              ?\ ;;;Whitespace
3105            (if (< score gnus-summary-default-score)
3106                gnus-score-below-mark gnus-score-over-mark))
3107          'score))
3108       ;; Do visual highlighting.
3109       (when (gnus-visual-p 'summary-highlight 'highlight)
3110         (gnus-run-hooks 'gnus-summary-update-hook)))))
3111
3112 (defvar gnus-tmp-new-adopts nil)
3113
3114 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3115   "Return the number of articles in THREAD.
3116 This may be 0 in some cases -- if none of the articles in
3117 the thread are to be displayed."
3118   (let* ((number
3119           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3120           (cond
3121            ((not (listp thread))
3122             1)
3123            ((and (consp thread) (cdr thread))
3124             (apply
3125              '+ 1 (mapcar
3126                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3127            ((null thread)
3128             1)
3129            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3130             1)
3131            (t 0))))
3132     (when (and level (zerop level) gnus-tmp-new-adopts)
3133       (incf number
3134             (apply '+ (mapcar
3135                        'gnus-summary-number-of-articles-in-thread
3136                        gnus-tmp-new-adopts))))
3137     (if char
3138         (if (> number 1) gnus-not-empty-thread-mark
3139           gnus-empty-thread-mark)
3140       number)))
3141
3142 (defun gnus-summary-set-local-parameters (group)
3143   "Go through the local params of GROUP and set all variable specs in that list."
3144   (let ((params (gnus-group-find-parameter group))
3145         (vars '(quit-config))           ; Ignore quit-config.
3146         elem)
3147     (while params
3148       (setq elem (car params)
3149             params (cdr params))
3150       (and (consp elem)                 ; Has to be a cons.
3151            (consp (cdr elem))           ; The cdr has to be a list.
3152            (symbolp (car elem))         ; Has to be a symbol in there.
3153            (not (memq (car elem) vars))
3154            (ignore-errors               ; So we set it.
3155              (push (car elem) vars)
3156              (make-local-variable (car elem))
3157              (set (car elem) (eval (nth 1 elem))))))))
3158
3159 (defun gnus-summary-read-group (group &optional show-all no-article
3160                                       kill-buffer no-display backward
3161                                       select-articles)
3162   "Start reading news in newsgroup GROUP.
3163 If SHOW-ALL is non-nil, already read articles are also listed.
3164 If NO-ARTICLE is non-nil, no article is selected initially.
3165 If NO-DISPLAY, don't generate a summary buffer."
3166   (let (result)
3167     (while (and group
3168                 (null (setq result
3169                             (let ((gnus-auto-select-next nil))
3170                               (or (gnus-summary-read-group-1
3171                                    group show-all no-article
3172                                    kill-buffer no-display
3173                                    select-articles)
3174                                   (setq show-all nil
3175                                         select-articles nil)))))
3176                 (eq gnus-auto-select-next 'quietly))
3177       (set-buffer gnus-group-buffer)
3178       ;; The entry function called above goes to the next
3179       ;; group automatically, so we go two groups back
3180       ;; if we are searching for the previous group.
3181       (when backward
3182         (gnus-group-prev-unread-group 2))
3183       (if (not (equal group (gnus-group-group-name)))
3184           (setq group (gnus-group-group-name))
3185         (setq group nil)))
3186     result))
3187
3188 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3189   "Directly jump to the other GROUP from summary buffer.
3190 If SHOW-ALL is non-nil, already read articles are also listed."
3191   (interactive
3192    (if (eq gnus-summary-buffer (current-buffer))
3193        (list (completing-read
3194               "Group: " gnus-active-hashtb nil t
3195               (when (and gnus-newsgroup-name
3196                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3197                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3198               'gnus-group-history)
3199              current-prefix-arg)
3200      (error "%s must be invoked from a gnus summary buffer." this-command)))
3201   (unless (or (zerop (length group))
3202               (and gnus-newsgroup-name
3203                    (string-equal gnus-newsgroup-name group)))
3204     (gnus-summary-exit)
3205     (gnus-summary-read-group group show-all
3206                              gnus-dont-select-after-jump-to-other-group)))
3207
3208 (defun gnus-summary-read-group-1 (group show-all no-article
3209                                         kill-buffer no-display
3210                                         &optional select-articles)
3211   ;; Killed foreign groups can't be entered.
3212   ;;  (when (and (not (gnus-group-native-p group))
3213   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3214   ;;    (error "Dead non-native groups can't be entered"))
3215   (gnus-message 5 "Retrieving newsgroup: %s..."
3216                 (gnus-group-decoded-name group))
3217   (let* ((new-group (gnus-summary-setup-buffer group))
3218          (quit-config (gnus-group-quit-config group))
3219          (did-select (and new-group (gnus-select-newsgroup
3220                                      group show-all select-articles))))
3221     (cond
3222      ;; This summary buffer exists already, so we just select it.
3223      ((not new-group)
3224       (gnus-set-global-variables)
3225       (when kill-buffer
3226         (gnus-kill-or-deaden-summary kill-buffer))
3227       (gnus-configure-windows 'summary 'force)
3228       (gnus-set-mode-line 'summary)
3229       (gnus-summary-position-point)
3230       (message "")
3231       t)
3232      ;; We couldn't select this group.
3233      ((null did-select)
3234       (when (and (eq major-mode 'gnus-summary-mode)
3235                  (not (equal (current-buffer) kill-buffer)))
3236         (kill-buffer (current-buffer))
3237         (if (not quit-config)
3238             (progn
3239               ;; Update the info -- marks might need to be removed,
3240               ;; for instance.
3241               (gnus-summary-update-info)
3242               (set-buffer gnus-group-buffer)
3243               (gnus-group-jump-to-group group)
3244               (gnus-group-next-unread-group 1))
3245           (gnus-handle-ephemeral-exit quit-config)))
3246       (let ((grpinfo (gnus-get-info group)))
3247         (if (null (gnus-info-read grpinfo))
3248             (gnus-message 3 "Group %s contains no messages"
3249                           (gnus-group-decoded-name group))
3250           (gnus-message 3 "Can't select group")))
3251       nil)
3252      ;; The user did a `C-g' while prompting for number of articles,
3253      ;; so we exit this group.
3254      ((eq did-select 'quit)
3255       (and (eq major-mode 'gnus-summary-mode)
3256            (not (equal (current-buffer) kill-buffer))
3257            (kill-buffer (current-buffer)))
3258       (when kill-buffer
3259         (gnus-kill-or-deaden-summary kill-buffer))
3260       (if (not quit-config)
3261           (progn
3262             (set-buffer gnus-group-buffer)
3263             (gnus-group-jump-to-group group)
3264             (gnus-group-next-unread-group 1)
3265             (gnus-configure-windows 'group 'force))
3266         (gnus-handle-ephemeral-exit quit-config))
3267       ;; Finally signal the quit.
3268       (signal 'quit nil))
3269      ;; The group was successfully selected.
3270      (t
3271       (gnus-set-global-variables)
3272       ;; Save the active value in effect when the group was entered.
3273       (setq gnus-newsgroup-active
3274             (gnus-copy-sequence
3275              (gnus-active gnus-newsgroup-name)))
3276       ;; You can change the summary buffer in some way with this hook.
3277       (gnus-run-hooks 'gnus-select-group-hook)
3278       (gnus-update-format-specifications
3279        nil 'summary 'summary-mode 'summary-dummy)
3280       (gnus-update-summary-mark-positions)
3281       ;; Do score processing.
3282       (when gnus-use-scoring
3283         (gnus-possibly-score-headers))
3284       ;; Check whether to fill in the gaps in the threads.
3285       (when gnus-build-sparse-threads
3286         (gnus-build-sparse-threads))
3287       ;; Find the initial limit.
3288       (if gnus-show-threads
3289           (if show-all
3290               (let ((gnus-newsgroup-dormant nil))
3291                 (gnus-summary-initial-limit show-all))
3292             (gnus-summary-initial-limit show-all))
3293         ;; When untreaded, all articles are always shown.
3294         (setq gnus-newsgroup-limit
3295               (mapcar
3296                (lambda (header) (mail-header-number header))
3297                gnus-newsgroup-headers)))
3298       ;; Generate the summary buffer.
3299       (unless no-display
3300         (gnus-summary-prepare))
3301       (when gnus-use-trees
3302         (gnus-tree-open group)
3303         (setq gnus-summary-highlight-line-function
3304               'gnus-tree-highlight-article))
3305       ;; If the summary buffer is empty, but there are some low-scored
3306       ;; articles or some excluded dormants, we include these in the
3307       ;; buffer.
3308       (when (and (zerop (buffer-size))
3309                  (not no-display))
3310         (cond (gnus-newsgroup-dormant
3311                (gnus-summary-limit-include-dormant))
3312               ((and gnus-newsgroup-scored show-all)
3313                (gnus-summary-limit-include-expunged t))))
3314       ;; Function `gnus-apply-kill-file' must be called in this hook.
3315       (gnus-run-hooks 'gnus-apply-kill-hook)
3316       (if (and (zerop (buffer-size))
3317                (not no-display))
3318           (progn
3319             ;; This newsgroup is empty.
3320             (gnus-summary-catchup-and-exit nil t)
3321             (gnus-message 6 "No unread news")
3322             (when kill-buffer
3323               (gnus-kill-or-deaden-summary kill-buffer))
3324             ;; Return nil from this function.
3325             nil)
3326         ;; Hide conversation thread subtrees.  We cannot do this in
3327         ;; gnus-summary-prepare-hook since kill processing may not
3328         ;; work with hidden articles.
3329         (gnus-summary-maybe-hide-threads)
3330         (when kill-buffer
3331           (gnus-kill-or-deaden-summary kill-buffer))
3332         (gnus-summary-auto-select-subject)
3333         ;; Show first unread article if requested.
3334         (if (and (not no-article)
3335                  (not no-display)
3336                  gnus-newsgroup-unreads
3337                  gnus-auto-select-first)
3338             (progn
3339               (gnus-configure-windows 'summary)
3340               (let ((art (gnus-summary-article-number)))
3341                 (unless (or (memq art gnus-newsgroup-undownloaded)
3342                             (memq art gnus-newsgroup-downloadable))
3343                   (gnus-summary-goto-article art))))
3344           ;; Don't select any articles.
3345           (gnus-summary-position-point)
3346           (gnus-configure-windows 'summary 'force)
3347           (gnus-set-mode-line 'summary))
3348         (when (get-buffer-window gnus-group-buffer t)
3349           ;; Gotta use windows, because recenter does weird stuff if
3350           ;; the current buffer ain't the displayed window.
3351           (let ((owin (selected-window)))
3352             (select-window (get-buffer-window gnus-group-buffer t))
3353             (when (gnus-group-goto-group group)
3354               (recenter))
3355             (select-window owin)))
3356         ;; Mark this buffer as "prepared".
3357         (setq gnus-newsgroup-prepared t)
3358         (gnus-run-hooks 'gnus-summary-prepared-hook)
3359         t)))))
3360
3361 (defun gnus-summary-auto-select-subject ()
3362   "Select the subject line on initial group entry."
3363   (goto-char (point-min))
3364   (cond
3365    ((eq gnus-auto-select-subject 'best)
3366     (gnus-summary-best-unread-subject))
3367    ((eq gnus-auto-select-subject 'unread)
3368     (gnus-summary-first-unread-subject))
3369    ((eq gnus-auto-select-subject 'unseen)
3370     (gnus-summary-first-unseen-subject))
3371    ((eq gnus-auto-select-subject 'unseen-or-unread)
3372     (gnus-summary-first-unseen-or-unread-subject))
3373    ((eq gnus-auto-select-subject 'first)
3374     ;; Do nothing.
3375     )
3376    ((gnus-functionp gnus-auto-select-subject)
3377     (funcall gnus-auto-select-subject))))
3378
3379 (defun gnus-summary-prepare ()
3380   "Generate the summary buffer."
3381   (interactive)
3382   (let ((buffer-read-only nil))
3383     (erase-buffer)
3384     (setq gnus-newsgroup-data nil
3385           gnus-newsgroup-data-reverse nil)
3386     (gnus-run-hooks 'gnus-summary-generate-hook)
3387     ;; Generate the buffer, either with threads or without.
3388     (when gnus-newsgroup-headers
3389       (gnus-summary-prepare-threads
3390        (if gnus-show-threads
3391            (gnus-sort-gathered-threads
3392             (funcall gnus-summary-thread-gathering-function
3393                      (gnus-sort-threads
3394                       (gnus-cut-threads (gnus-make-threads)))))
3395          ;; Unthreaded display.
3396          (gnus-sort-articles gnus-newsgroup-headers))))
3397     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3398     ;; Call hooks for modifying summary buffer.
3399     (goto-char (point-min))
3400     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3401
3402 (defsubst gnus-general-simplify-subject (subject)
3403   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3404   (setq subject
3405         (cond
3406          ;; Truncate the subject.
3407          (gnus-simplify-subject-functions
3408           (gnus-map-function gnus-simplify-subject-functions subject))
3409          ((numberp gnus-summary-gather-subject-limit)
3410           (setq subject (gnus-simplify-subject-re subject))
3411           (if (> (length subject) gnus-summary-gather-subject-limit)
3412               (substring subject 0 gnus-summary-gather-subject-limit)
3413             subject))
3414          ;; Fuzzily simplify it.
3415          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3416           (gnus-simplify-subject-fuzzy subject))
3417          ;; Just remove the leading "Re:".
3418          (t
3419           (gnus-simplify-subject-re subject))))
3420
3421   (if (and gnus-summary-gather-exclude-subject
3422            (string-match gnus-summary-gather-exclude-subject subject))
3423       nil                               ; This article shouldn't be gathered
3424     subject))
3425
3426 (defun gnus-summary-simplify-subject-query ()
3427   "Query where the respool algorithm would put this article."
3428   (interactive)
3429   (gnus-summary-select-article)
3430   (message "%s"
3431            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3432
3433 (defun gnus-gather-threads-by-subject (threads)
3434   "Gather threads by looking at Subject headers."
3435   (if (not gnus-summary-make-false-root)
3436       threads
3437     (let ((hashtb (gnus-make-hashtable 1024))
3438           (prev threads)
3439           (result threads)
3440           subject hthread whole-subject)
3441       (while threads
3442         (setq subject (gnus-general-simplify-subject
3443                        (setq whole-subject (mail-header-subject
3444                                             (caar threads)))))
3445         (when subject
3446           (if (setq hthread (gnus-gethash subject hashtb))
3447               (progn
3448                 ;; We enter a dummy root into the thread, if we
3449                 ;; haven't done that already.
3450                 (unless (stringp (caar hthread))
3451                   (setcar hthread (list whole-subject (car hthread))))
3452                 ;; We add this new gathered thread to this gathered
3453                 ;; thread.
3454                 (setcdr (car hthread)
3455                         (nconc (cdar hthread) (list (car threads))))
3456                 ;; Remove it from the list of threads.
3457                 (setcdr prev (cdr threads))
3458                 (setq threads prev))
3459             ;; Enter this thread into the hash table.
3460             (gnus-sethash subject threads hashtb)))
3461         (setq prev threads)
3462         (setq threads (cdr threads)))
3463       result)))
3464
3465 (defun gnus-gather-threads-by-references (threads)
3466   "Gather threads by looking at References headers."
3467   (let ((idhashtb (gnus-make-hashtable 1024))
3468         (thhashtb (gnus-make-hashtable 1024))
3469         (prev threads)
3470         (result threads)
3471         ids references id gthread gid entered ref)
3472     (while threads
3473       (when (setq references (mail-header-references (caar threads)))
3474         (setq id (mail-header-id (caar threads))
3475               ids (inline (gnus-split-references references))
3476               entered nil)
3477         (while (setq ref (pop ids))
3478           (setq ids (delete ref ids))
3479           (if (not (setq gid (gnus-gethash ref idhashtb)))
3480               (progn
3481                 (gnus-sethash ref id idhashtb)
3482                 (gnus-sethash id threads thhashtb))
3483             (setq gthread (gnus-gethash gid thhashtb))
3484             (unless entered
3485               ;; We enter a dummy root into the thread, if we
3486               ;; haven't done that already.
3487               (unless (stringp (caar gthread))
3488                 (setcar gthread (list (mail-header-subject (caar gthread))
3489                                       (car gthread))))
3490               ;; We add this new gathered thread to this gathered
3491               ;; thread.
3492               (setcdr (car gthread)
3493                       (nconc (cdar gthread) (list (car threads)))))
3494             ;; Add it into the thread hash table.
3495             (gnus-sethash id gthread thhashtb)
3496             (setq entered t)
3497             ;; Remove it from the list of threads.
3498             (setcdr prev (cdr threads))
3499             (setq threads prev))))
3500       (setq prev threads)
3501       (setq threads (cdr threads)))
3502     result))
3503
3504 (defun gnus-sort-gathered-threads (threads)
3505   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3506   (let ((result threads))
3507     (while threads
3508       (when (stringp (caar threads))
3509         (setcdr (car threads)
3510                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3511       (setq threads (cdr threads)))
3512     result))
3513
3514 (defun gnus-thread-loop-p (root thread)
3515   "Say whether ROOT is in THREAD."
3516   (let ((stack (list thread))
3517         (infloop 0)
3518         th)
3519     (while (setq thread (pop stack))
3520       (setq th (cdr thread))
3521       (while (and th
3522                   (not (eq (caar th) root)))
3523         (pop th))
3524       (if th
3525           ;; We have found a loop.
3526           (let (ref-dep)
3527             (setcdr thread (delq (car th) (cdr thread)))
3528             (if (boundp (setq ref-dep (intern "none"
3529                                               gnus-newsgroup-dependencies)))
3530                 (setcdr (symbol-value ref-dep)
3531                         (nconc (cdr (symbol-value ref-dep))
3532                                (list (car th))))
3533               (set ref-dep (list nil (car th))))
3534             (setq infloop 1
3535                   stack nil))
3536         ;; Push all the subthreads onto the stack.
3537         (push (cdr thread) stack)))
3538     infloop))
3539
3540 (defun gnus-make-threads ()
3541   "Go through the dependency hashtb and find the roots.  Return all threads."
3542   (let (threads)
3543     (while (catch 'infloop
3544              (mapatoms
3545               (lambda (refs)
3546                 ;; Deal with self-referencing References loops.
3547                 (when (and (car (symbol-value refs))
3548                            (not (zerop
3549                                  (apply
3550                                   '+
3551                                   (mapcar
3552                                    (lambda (thread)
3553                                      (gnus-thread-loop-p
3554                                       (car (symbol-value refs)) thread))
3555                                    (cdr (symbol-value refs)))))))
3556                   (setq threads nil)
3557                   (throw 'infloop t))
3558                 (unless (car (symbol-value refs))
3559                   ;; These threads do not refer back to any other articles,
3560                   ;; so they're roots.
3561                   (setq threads (append (cdr (symbol-value refs)) threads))))
3562               gnus-newsgroup-dependencies)))
3563     threads))
3564
3565 ;; Build the thread tree.
3566 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3567   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3568
3569 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3570 if it was already present.
3571
3572 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3573 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3574 Message-IDs will be renamed to a unique Message-ID before being
3575 entered.
3576
3577 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3578   (let* ((id (mail-header-id header))
3579          (id-dep (and id (intern id dependencies)))
3580          ref ref-dep ref-header)
3581     ;; Enter this `header' in the `dependencies' table.
3582     (cond
3583      ((not id-dep)
3584       (setq header nil))
3585      ;; The first two cases do the normal part: enter a new `header'
3586      ;; in the `dependencies' table.
3587      ((not (boundp id-dep))
3588       (set id-dep (list header)))
3589      ((null (car (symbol-value id-dep)))
3590       (setcar (symbol-value id-dep) header))
3591
3592      ;; From here the `header' was already present in the
3593      ;; `dependencies' table.
3594      (force-new
3595       ;; Overrides an existing entry;
3596       ;; just set the header part of the entry.
3597       (setcar (symbol-value id-dep) header))
3598
3599      ;; Renames the existing `header' to a unique Message-ID.
3600      ((not gnus-summary-ignore-duplicates)
3601       ;; An article with this Message-ID has already been seen.
3602       ;; We rename the Message-ID.
3603       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3604            (list header))
3605       (mail-header-set-id header id))
3606
3607      ;; The last case ignores an existing entry, except it adds any
3608      ;; additional Xrefs (in case the two articles came from different
3609      ;; servers.
3610      ;; Also sets `header' to `nil' meaning that the `dependencies'
3611      ;; table was *not* modified.
3612      (t
3613       (mail-header-set-xref
3614        (car (symbol-value id-dep))
3615        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3616                    "")
3617                (or (mail-header-xref header) "")))
3618       (setq header nil)))
3619
3620     (when header
3621       ;; First check that we are not creating a References loop.
3622       (setq ref (gnus-parent-id (mail-header-references header)))
3623       (while (and ref
3624                   (setq ref-dep (intern-soft ref dependencies))
3625                   (boundp ref-dep)
3626                   (setq ref-header (car (symbol-value ref-dep))))
3627         (if (string= id ref)
3628             ;; Yuk!  This is a reference loop.  Make the article be a
3629             ;; root article.
3630             (progn
3631               (mail-header-set-references (car (symbol-value id-dep)) "none")
3632               (setq ref nil))
3633           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3634       (setq ref (gnus-parent-id (mail-header-references header)))
3635       (setq ref-dep (intern (or ref "none") dependencies))
3636       (if (boundp ref-dep)
3637           (setcdr (symbol-value ref-dep)
3638                   (nconc (cdr (symbol-value ref-dep))
3639                          (list (symbol-value id-dep))))
3640         (set ref-dep (list nil (symbol-value id-dep)))))
3641     header))
3642
3643 (defun gnus-extract-message-id-from-in-reply-to (string)
3644   (if (string-match "<[^>]+>" string)
3645       (substring string (match-beginning 0) (match-end 0))
3646     nil))
3647
3648 (defun gnus-build-sparse-threads ()
3649   (let ((headers gnus-newsgroup-headers)
3650         (mail-parse-charset gnus-newsgroup-charset)
3651         (gnus-summary-ignore-duplicates t)
3652         header references generation relations
3653         subject child end new-child date)
3654     ;; First we create an alist of generations/relations, where
3655     ;; generations is how much we trust the relation, and the relation
3656     ;; is parent/child.
3657     (gnus-message 7 "Making sparse threads...")
3658     (save-excursion
3659       (nnheader-set-temp-buffer " *gnus sparse threads*")
3660       (while (setq header (pop headers))
3661         (when (and (setq references (mail-header-references header))
3662                    (not (string= references "")))
3663           (insert references)
3664           (setq child (mail-header-id header)
3665                 subject (mail-header-subject header)
3666                 date (mail-header-date header)
3667                 generation 0)
3668           (while (search-backward ">" nil t)
3669             (setq end (1+ (point)))
3670             (when (search-backward "<" nil t)
3671               (setq new-child (buffer-substring (point) end))
3672               (push (list (incf generation)
3673                           child (setq child new-child)
3674                           subject date)
3675                     relations)))
3676           (when child
3677             (push (list (1+ generation) child nil subject) relations))
3678           (erase-buffer)))
3679       (kill-buffer (current-buffer)))
3680     ;; Sort over trustworthiness.
3681     (mapcar
3682      (lambda (relation)
3683        (when (gnus-dependencies-add-header
3684               (make-full-mail-header-from-decoded-header
3685                gnus-reffed-article-number
3686                (nth 3 relation) "" (or (nth 4 relation) "")
3687                (nth 1 relation)
3688                (or (nth 2 relation) "") 0 0 "")
3689               gnus-newsgroup-dependencies nil)
3690          (push gnus-reffed-article-number gnus-newsgroup-limit)
3691          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3692          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3693                gnus-newsgroup-reads)
3694          (decf gnus-reffed-article-number)))
3695      (sort relations 'car-less-than-car))
3696     (gnus-message 7 "Making sparse threads...done")))
3697
3698 (defun gnus-build-old-threads ()
3699   ;; Look at all the articles that refer back to old articles, and
3700   ;; fetch the headers for the articles that aren't there.  This will
3701   ;; build complete threads - if the roots haven't been expired by the
3702   ;; server, that is.
3703   (let ((mail-parse-charset gnus-newsgroup-charset)
3704         id heads)
3705     (mapatoms
3706      (lambda (refs)
3707        (when (not (car (symbol-value refs)))
3708          (setq heads (cdr (symbol-value refs)))
3709          (while heads
3710            (if (memq (mail-header-number (caar heads))
3711                      gnus-newsgroup-dormant)
3712                (setq heads (cdr heads))
3713              (setq id (symbol-name refs))
3714              (while (and (setq id (gnus-build-get-header id))
3715                          (not (car (gnus-id-to-thread id)))))
3716              (setq heads nil)))))
3717      gnus-newsgroup-dependencies)))
3718
3719 ;; This function has to be called with point after the article number
3720 ;; on the beginning of the line.
3721 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3722   (let ((eol (gnus-point-at-eol))
3723         (buffer (current-buffer))
3724         header references in-reply-to)
3725
3726     ;; overview: [num subject from date id refs chars lines misc]
3727     (unwind-protect
3728         (progn
3729           (narrow-to-region (point) eol)
3730           (unless (eobp)
3731             (forward-char))
3732
3733           (setq header
3734                 (make-full-mail-header
3735                  number                         ; number
3736                  (nnheader-nov-field)           ; subject
3737                  (nnheader-nov-field)           ; from
3738                  (nnheader-nov-field)           ; date
3739                  (nnheader-nov-read-message-id) ; id
3740                  (nnheader-nov-field)           ; refs
3741                  (nnheader-nov-read-integer)    ; chars
3742                  (nnheader-nov-read-integer)    ; lines
3743                  (unless (eobp)
3744                    (if (looking-at "Xref: ")
3745                        (goto-char (match-end 0)))
3746                    (nnheader-nov-field))        ; Xref
3747                  (nnheader-nov-parse-extra))))  ; extra
3748
3749       (widen))
3750
3751     (when (and (string= references "")
3752                (setq in-reply-to (mail-header-extra header))
3753                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3754       (mail-header-set-references
3755        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3756
3757     (when gnus-alter-header-function
3758       (funcall gnus-alter-header-function header))
3759     (gnus-dependencies-add-header header dependencies force-new)))
3760
3761 (defun gnus-build-get-header (id)
3762   "Look through the buffer of NOV lines and find the header to ID.
3763 Enter this line into the dependencies hash table, and return
3764 the id of the parent article (if any)."
3765   (let ((deps gnus-newsgroup-dependencies)
3766         found header)
3767     (prog1
3768         (save-excursion
3769           (set-buffer nntp-server-buffer)
3770           (let ((case-fold-search nil))
3771             (goto-char (point-min))
3772             (while (and (not found)
3773                         (search-forward id nil t))
3774               (beginning-of-line)
3775               (setq found (looking-at
3776                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3777                                    (regexp-quote id))))
3778               (or found (beginning-of-line 2)))
3779             (when found
3780               (beginning-of-line)
3781               (and
3782                (setq header (gnus-nov-parse-line
3783                              (read (current-buffer)) deps))
3784                (gnus-parent-id (mail-header-references header))))))
3785       (when header
3786         (let ((number (mail-header-number header)))
3787           (push number gnus-newsgroup-limit)
3788           (push header gnus-newsgroup-headers)
3789           (if (memq number gnus-newsgroup-unselected)
3790               (progn
3791                 (setq gnus-newsgroup-unreads
3792                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3793                                                number))
3794                 (setq gnus-newsgroup-unselected
3795                       (delq number gnus-newsgroup-unselected)))
3796             (push number gnus-newsgroup-ancient)))))))
3797
3798 (defun gnus-build-all-threads ()
3799   "Read all the headers."
3800   (let ((gnus-summary-ignore-duplicates t)
3801         (mail-parse-charset gnus-newsgroup-charset)
3802         (dependencies gnus-newsgroup-dependencies)
3803         header article)
3804     (save-excursion
3805       (set-buffer nntp-server-buffer)
3806       (let ((case-fold-search nil))
3807         (goto-char (point-min))
3808         (while (not (eobp))
3809           (ignore-errors
3810             (setq article (read (current-buffer))
3811                   header (gnus-nov-parse-line article dependencies)))
3812           (when header
3813             (save-excursion
3814               (set-buffer gnus-summary-buffer)
3815               (push header gnus-newsgroup-headers)
3816               (if (memq (setq article (mail-header-number header))
3817                         gnus-newsgroup-unselected)
3818                   (progn
3819                     (setq gnus-newsgroup-unreads
3820                           (gnus-add-to-sorted-list
3821                            gnus-newsgroup-unreads article))
3822                     (setq gnus-newsgroup-unselected
3823                           (delq article gnus-newsgroup-unselected)))
3824                 (push article gnus-newsgroup-ancient)))
3825             (forward-line 1)))))))
3826
3827 (defun gnus-summary-update-article-line (article header)
3828   "Update the line for ARTICLE using HEADERS."
3829   (let* ((id (mail-header-id header))
3830          (thread (gnus-id-to-thread id)))
3831     (unless thread
3832       (error "Article in no thread"))
3833     ;; Update the thread.
3834     (setcar thread header)
3835     (gnus-summary-goto-subject article)
3836     (let* ((datal (gnus-data-find-list article))
3837            (data (car datal))
3838            (length (when (cdr datal)
3839                      (- (gnus-data-pos data)
3840                         (gnus-data-pos (cadr datal)))))
3841            (buffer-read-only nil)
3842            (level (gnus-summary-thread-level)))
3843       (gnus-delete-line)
3844       (gnus-summary-insert-line
3845        header level nil (gnus-article-mark article)
3846        (memq article gnus-newsgroup-replied)
3847        (memq article gnus-newsgroup-expirable)
3848        ;; Only insert the Subject string when it's different
3849        ;; from the previous Subject string.
3850        (if (and
3851             gnus-show-threads
3852             (gnus-subject-equal
3853              (condition-case ()
3854                  (mail-header-subject
3855                   (gnus-data-header
3856                    (cadr
3857                     (gnus-data-find-list
3858                      article
3859                      (gnus-data-list t)))))
3860                ;; Error on the side of excessive subjects.
3861                (error ""))
3862              (mail-header-subject header)))
3863            ""
3864          (mail-header-subject header))
3865        nil (cdr (assq article gnus-newsgroup-scored))
3866        (memq article gnus-newsgroup-processable))
3867       (when length
3868         (gnus-data-update-list
3869          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3870
3871 (defun gnus-summary-update-article (article &optional iheader)
3872   "Update ARTICLE in the summary buffer."
3873   (set-buffer gnus-summary-buffer)
3874   (let* ((header (gnus-summary-article-header article))
3875          (id (mail-header-id header))
3876          (data (gnus-data-find article))
3877          (thread (gnus-id-to-thread id))
3878          (references (mail-header-references header))
3879          (parent
3880           (gnus-id-to-thread
3881            (or (gnus-parent-id
3882                 (when (and references
3883                            (not (equal "" references)))
3884                   references))
3885                "none")))
3886          (buffer-read-only nil)
3887          (old (car thread)))
3888     (when thread
3889       (unless iheader
3890         (setcar thread nil)
3891         (when parent
3892           (delq thread parent)))
3893       (if (gnus-summary-insert-subject id header)
3894           ;; Set the (possibly) new article number in the data structure.
3895           (gnus-data-set-number data (gnus-id-to-article id))
3896         (setcar thread old)
3897         nil))))
3898
3899 (defun gnus-rebuild-thread (id &optional line)
3900   "Rebuild the thread containing ID.
3901 If LINE, insert the rebuilt thread starting on line LINE."
3902   (let ((buffer-read-only nil)
3903         old-pos current thread data)
3904     (if (not gnus-show-threads)
3905         (setq thread (list (car (gnus-id-to-thread id))))
3906       ;; Get the thread this article is part of.
3907       (setq thread (gnus-remove-thread id)))
3908     (setq old-pos (gnus-point-at-bol))
3909     (setq current (save-excursion
3910                     (and (re-search-backward "[\r\n]" nil t)
3911                          (gnus-summary-article-number))))
3912     ;; If this is a gathered thread, we have to go some re-gathering.
3913     (when (stringp (car thread))
3914       (let ((subject (car thread))
3915             roots thr)
3916         (setq thread (cdr thread))
3917         (while thread
3918           (unless (memq (setq thr (gnus-id-to-thread
3919                                    (gnus-root-id
3920                                     (mail-header-id (caar thread)))))
3921                         roots)
3922             (push thr roots))
3923           (setq thread (cdr thread)))
3924         ;; We now have all (unique) roots.
3925         (if (= (length roots) 1)
3926             ;; All the loose roots are now one solid root.
3927             (setq thread (car roots))
3928           (setq thread (cons subject (gnus-sort-threads roots))))))
3929     (let (threads)
3930       ;; We then insert this thread into the summary buffer.
3931       (when line
3932         (goto-char (point-min))
3933         (forward-line (1- line)))
3934       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3935         (if gnus-show-threads
3936             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3937           (gnus-summary-prepare-unthreaded thread))
3938         (setq data (nreverse gnus-newsgroup-data))
3939         (setq threads gnus-newsgroup-threads))
3940       ;; We splice the new data into the data structure.
3941       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3942       ;;!!! then we want to insert at the beginning of the buffer.
3943       ;;!!! That happens to be true with Gnus now, but that may
3944       ;;!!! change in the future.  Perhaps.
3945       (gnus-data-enter-list
3946        (if line nil current) data (- (point) old-pos))
3947       (setq gnus-newsgroup-threads
3948             (nconc threads gnus-newsgroup-threads))
3949       (gnus-data-compute-positions))))
3950
3951 (defun gnus-number-to-header (number)
3952   "Return the header for article NUMBER."
3953   (let ((headers gnus-newsgroup-headers))
3954     (while (and headers
3955                 (not (= number (mail-header-number (car headers)))))
3956       (pop headers))
3957     (when headers
3958       (car headers))))
3959
3960 (defun gnus-parent-headers (in-headers &optional generation)
3961   "Return the headers of the GENERATIONeth parent of HEADERS."
3962   (unless generation
3963     (setq generation 1))
3964   (let ((parent t)
3965         (headers in-headers)
3966         references)
3967     (while (and parent
3968                 (not (zerop generation))
3969                 (setq references (mail-header-references headers)))
3970       (setq headers (if (and references
3971                              (setq parent (gnus-parent-id references)))
3972                         (car (gnus-id-to-thread parent))
3973                       nil))
3974       (decf generation))
3975     (and (not (eq headers in-headers))
3976          headers)))
3977
3978 (defun gnus-id-to-thread (id)
3979   "Return the (sub-)thread where ID appears."
3980   (gnus-gethash id gnus-newsgroup-dependencies))
3981
3982 (defun gnus-id-to-article (id)
3983   "Return the article number of ID."
3984   (let ((thread (gnus-id-to-thread id)))
3985     (when (and thread
3986                (car thread))
3987       (mail-header-number (car thread)))))
3988
3989 (defun gnus-id-to-header (id)
3990   "Return the article headers of ID."
3991   (car (gnus-id-to-thread id)))
3992
3993 (defun gnus-article-displayed-root-p (article)
3994   "Say whether ARTICLE is a root(ish) article."
3995   (let ((level (gnus-summary-thread-level article))
3996         (refs (mail-header-references  (gnus-summary-article-header article)))
3997         particle)
3998     (cond
3999      ((null level) nil)
4000      ((zerop level) t)
4001      ((null refs) t)
4002      ((null (gnus-parent-id refs)) t)
4003      ((and (= 1 level)
4004            (null (setq particle (gnus-id-to-article
4005                                  (gnus-parent-id refs))))
4006            (null (gnus-summary-thread-level particle)))))))
4007
4008 (defun gnus-root-id (id)
4009   "Return the id of the root of the thread where ID appears."
4010   (let (last-id prev)
4011     (while (and id (setq prev (car (gnus-id-to-thread id))))
4012       (setq last-id id
4013             id (gnus-parent-id (mail-header-references prev))))
4014     last-id))
4015
4016 (defun gnus-articles-in-thread (thread)
4017   "Return the list of articles in THREAD."
4018   (cons (mail-header-number (car thread))
4019         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4020
4021 (defun gnus-remove-thread (id &optional dont-remove)
4022   "Remove the thread that has ID in it."
4023   (let (headers thread last-id)
4024     ;; First go up in this thread until we find the root.
4025     (setq last-id (gnus-root-id id)
4026           headers (message-flatten-list (gnus-id-to-thread last-id)))
4027     ;; We have now found the real root of this thread.  It might have
4028     ;; been gathered into some loose thread, so we have to search
4029     ;; through the threads to find the thread we wanted.
4030     (let ((threads gnus-newsgroup-threads)
4031           sub)
4032       (while threads
4033         (setq sub (car threads))
4034         (if (stringp (car sub))
4035             ;; This is a gathered thread, so we look at the roots
4036             ;; below it to find whether this article is in this
4037             ;; gathered root.
4038             (progn
4039               (setq sub (cdr sub))
4040               (while sub
4041                 (when (member (caar sub) headers)
4042                   (setq thread (car threads)
4043                         threads nil
4044                         sub nil))
4045                 (setq sub (cdr sub))))
4046           ;; It's an ordinary thread, so we check it.
4047           (when (eq (car sub) (car headers))
4048             (setq thread sub
4049                   threads nil)))
4050         (setq threads (cdr threads)))
4051       ;; If this article is in no thread, then it's a root.
4052       (if thread
4053           (unless dont-remove
4054             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4055         (setq thread (gnus-id-to-thread last-id)))
4056       (when thread
4057         (prog1
4058             thread                      ; We return this thread.
4059           (unless dont-remove
4060             (if (stringp (car thread))
4061                 (progn
4062                   ;; If we use dummy roots, then we have to remove the
4063                   ;; dummy root as well.
4064                   (when (eq gnus-summary-make-false-root 'dummy)
4065                     ;; We go to the dummy root by going to
4066                     ;; the first sub-"thread", and then one line up.
4067                     (gnus-summary-goto-article
4068                      (mail-header-number (caadr thread)))
4069                     (forward-line -1)
4070                     (gnus-delete-line)
4071                     (gnus-data-compute-positions))
4072                   (setq thread (cdr thread))
4073                   (while thread
4074                     (gnus-remove-thread-1 (car thread))
4075                     (setq thread (cdr thread))))
4076               (gnus-remove-thread-1 thread))))))))
4077
4078 (defun gnus-remove-thread-1 (thread)
4079   "Remove the thread THREAD recursively."
4080   (let ((number (mail-header-number (pop thread)))
4081         d)
4082     (setq thread (reverse thread))
4083     (while thread
4084       (gnus-remove-thread-1 (pop thread)))
4085     (when (setq d (gnus-data-find number))
4086       (goto-char (gnus-data-pos d))
4087       (gnus-summary-show-thread)
4088       (gnus-data-remove
4089        number
4090        (- (gnus-point-at-bol)
4091           (prog1
4092               (1+ (gnus-point-at-eol))
4093             (gnus-delete-line)))))))
4094
4095 (defun gnus-sort-threads-1 (threads func)
4096   (sort (mapcar (lambda (thread)
4097                   (cons (car thread)
4098                         (and (cdr thread)
4099                              (gnus-sort-threads-1 (cdr thread) func))))
4100                 threads) func))
4101
4102 (defun gnus-sort-threads (threads)
4103   "Sort THREADS."
4104   (if (not gnus-thread-sort-functions)
4105       threads
4106     (gnus-message 8 "Sorting threads...")
4107     (prog1
4108         (gnus-sort-threads-1
4109          threads
4110          (gnus-make-sort-function gnus-thread-sort-functions))
4111       (gnus-message 8 "Sorting threads...done"))))
4112
4113 (defun gnus-sort-articles (articles)
4114   "Sort ARTICLES."
4115   (when gnus-article-sort-functions
4116     (gnus-message 7 "Sorting articles...")
4117     (prog1
4118         (setq gnus-newsgroup-headers
4119               (sort articles (gnus-make-sort-function
4120                               gnus-article-sort-functions)))
4121       (gnus-message 7 "Sorting articles...done"))))
4122
4123 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4124 (defmacro gnus-thread-header (thread)
4125   "Return header of first article in THREAD.
4126 Note that THREAD must never, ever be anything else than a variable -
4127 using some other form will lead to serious barfage."
4128   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4129   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4130   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4131         (vector thread) 2))
4132
4133 (defsubst gnus-article-sort-by-number (h1 h2)
4134   "Sort articles by article number."
4135   (< (mail-header-number h1)
4136      (mail-header-number h2)))
4137
4138 (defun gnus-thread-sort-by-number (h1 h2)
4139   "Sort threads by root article number."
4140   (gnus-article-sort-by-number
4141    (gnus-thread-header h1) (gnus-thread-header h2)))
4142
4143 (defsubst gnus-article-sort-by-lines (h1 h2)
4144   "Sort articles by article Lines header."
4145   (< (mail-header-lines h1)
4146      (mail-header-lines h2)))
4147
4148 (defun gnus-thread-sort-by-lines (h1 h2)
4149   "Sort threads by root article Lines header."
4150   (gnus-article-sort-by-lines
4151    (gnus-thread-header h1) (gnus-thread-header h2)))
4152
4153 (defsubst gnus-article-sort-by-chars (h1 h2)
4154   "Sort articles by octet length."
4155   (< (mail-header-chars h1)
4156      (mail-header-chars h2)))
4157
4158 (defun gnus-thread-sort-by-chars (h1 h2)
4159   "Sort threads by root article octet length."
4160   (gnus-article-sort-by-chars
4161    (gnus-thread-header h1) (gnus-thread-header h2)))
4162
4163 (defsubst gnus-article-sort-by-author (h1 h2)
4164   "Sort articles by root author."
4165   (string-lessp
4166    (let ((addr (car (mime-entity-read-field h1 'From))))
4167      (or (std11-full-name-string addr)
4168          (std11-address-string addr)
4169          ""))
4170    (let ((addr (car (mime-entity-read-field h2 'From))))
4171      (or (std11-full-name-string addr)
4172          (std11-address-string addr)
4173          ""))
4174    ))
4175
4176 (defun gnus-thread-sort-by-author (h1 h2)
4177   "Sort threads by root author."
4178   (gnus-article-sort-by-author
4179    (gnus-thread-header h1)  (gnus-thread-header h2)))
4180
4181 (defsubst gnus-article-sort-by-subject (h1 h2)
4182   "Sort articles by root subject."
4183   (string-lessp
4184    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4185    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4186
4187 (defun gnus-thread-sort-by-subject (h1 h2)
4188   "Sort threads by root subject."
4189   (gnus-article-sort-by-subject
4190    (gnus-thread-header h1) (gnus-thread-header h2)))
4191
4192 (defsubst gnus-article-sort-by-date (h1 h2)
4193   "Sort articles by root article date."
4194   (time-less-p
4195    (gnus-date-get-time (mail-header-date h1))
4196    (gnus-date-get-time (mail-header-date h2))))
4197
4198 (defun gnus-thread-sort-by-date (h1 h2)
4199   "Sort threads by root article date."
4200   (gnus-article-sort-by-date
4201    (gnus-thread-header h1) (gnus-thread-header h2)))
4202
4203 (defsubst gnus-article-sort-by-score (h1 h2)
4204   "Sort articles by root article score.
4205 Unscored articles will be counted as having a score of zero."
4206   (> (or (cdr (assq (mail-header-number h1)
4207                     gnus-newsgroup-scored))
4208          gnus-summary-default-score 0)
4209      (or (cdr (assq (mail-header-number h2)
4210                     gnus-newsgroup-scored))
4211          gnus-summary-default-score 0)))
4212
4213 (defun gnus-thread-sort-by-score (h1 h2)
4214   "Sort threads by root article score."
4215   (gnus-article-sort-by-score
4216    (gnus-thread-header h1) (gnus-thread-header h2)))
4217
4218 (defun gnus-thread-sort-by-total-score (h1 h2)
4219   "Sort threads by the sum of all scores in the thread.
4220 Unscored articles will be counted as having a score of zero."
4221   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4222
4223 (defun gnus-thread-total-score (thread)
4224   ;; This function find the total score of THREAD.
4225   (cond
4226    ((null thread)
4227     0)
4228    ((consp thread)
4229     (if (stringp (car thread))
4230         (apply gnus-thread-score-function 0
4231                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4232       (gnus-thread-total-score-1 thread)))
4233    (t
4234     (gnus-thread-total-score-1 (list thread)))))
4235
4236 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4237   "Sort threads such that the thread with the most recently arrived article comes first."
4238   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4239
4240 (defun gnus-thread-highest-number (thread)
4241   "Return the highest article number in THREAD."
4242   (apply 'max (mapcar (lambda (header)
4243                         (mail-header-number header))
4244                       (message-flatten-list thread))))
4245
4246 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4247   "Sort threads such that the thread with the most recently dated article comes first."
4248   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4249
4250 (defun gnus-thread-latest-date (thread)
4251   "Return the highest article date in THREAD."
4252   (let ((previous-time 0))
4253     (apply 'max (mapcar
4254                  (lambda (header)
4255                    (setq previous-time
4256                          (time-to-seconds
4257                           (mail-header-parse-date
4258                            (condition-case ()
4259                                (mail-header-date header)
4260                              (error previous-time))))))
4261                  (sort
4262                   (message-flatten-list thread)
4263                   (lambda (h1 h2)
4264                     (< (mail-header-number h1)
4265                        (mail-header-number h2))))))))
4266
4267 (defun gnus-thread-total-score-1 (root)
4268   ;; This function find the total score of the thread below ROOT.
4269   (setq root (car root))
4270   (apply gnus-thread-score-function
4271          (or (append
4272               (mapcar 'gnus-thread-total-score
4273                       (cdr (gnus-id-to-thread (mail-header-id root))))
4274               (when (> (mail-header-number root) 0)
4275                 (list (or (cdr (assq (mail-header-number root)
4276                                      gnus-newsgroup-scored))
4277                           gnus-summary-default-score 0))))
4278              (list gnus-summary-default-score)
4279              '(0))))
4280
4281 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4282 (defvar gnus-tmp-prev-subject nil)
4283 (defvar gnus-tmp-false-parent nil)
4284 (defvar gnus-tmp-root-expunged nil)
4285 (defvar gnus-tmp-dummy-line nil)
4286
4287 (eval-when-compile (defvar gnus-tmp-header))
4288 (defun gnus-extra-header (type &optional header)
4289   "Return the extra header of TYPE."
4290   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4291       ""))
4292
4293 (defvar gnus-tmp-thread-tree-header-string "")
4294
4295 (defvar gnus-sum-thread-tree-root "> "
4296   "With %B spec, used for the root of a thread.
4297 If nil, use subject instead.")
4298 (defvar gnus-sum-thread-tree-single-indent ""
4299   "With %B spec, used for a thread with just one message.
4300 If nil, use subject instead.")
4301 (defvar gnus-sum-thread-tree-vertical "| "
4302   "With %B spec, used for drawing a vertical line.")
4303 (defvar gnus-sum-thread-tree-indent "  "
4304   "With %B spec, used for indenting.")
4305 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4306   "With %B spec, used for a leaf with brothers.")
4307 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4308   "With %B spec, used for a leaf without brothers.")
4309
4310 (defun gnus-summary-prepare-threads (threads)
4311   "Prepare summary buffer from THREADS and indentation LEVEL.
4312 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4313 or a straight list of headers."
4314   (gnus-message 7 "Generating summary...")
4315
4316   (setq gnus-newsgroup-threads threads)
4317   (beginning-of-line)
4318
4319   (let ((gnus-tmp-level 0)
4320         (default-score (or gnus-summary-default-score 0))
4321         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4322         thread number subject stack state gnus-tmp-gathered beg-match
4323         new-roots gnus-tmp-new-adopts thread-end
4324         gnus-tmp-header gnus-tmp-unread
4325         gnus-tmp-replied gnus-tmp-subject-or-nil
4326         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4327         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4328         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4329         tree-stack)
4330
4331     (setq gnus-tmp-prev-subject nil)
4332
4333     (if (vectorp (car threads))
4334         ;; If this is a straight (sic) list of headers, then a
4335         ;; threaded summary display isn't required, so we just create
4336         ;; an unthreaded one.
4337         (gnus-summary-prepare-unthreaded threads)
4338
4339       ;; Do the threaded display.
4340
4341       (while (or threads stack gnus-tmp-new-adopts new-roots)
4342
4343         (if (and (= gnus-tmp-level 0)
4344                  (or (not stack)
4345                      (= (caar stack) 0))
4346                  (not gnus-tmp-false-parent)
4347                  (or gnus-tmp-new-adopts new-roots))
4348             (if gnus-tmp-new-adopts
4349                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4350                       thread (list (car gnus-tmp-new-adopts))
4351                       gnus-tmp-header (caar thread)
4352                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4353               (when new-roots
4354                 (setq thread (list (car new-roots))
4355                       gnus-tmp-header (caar thread)
4356                       new-roots (cdr new-roots))))
4357
4358           (if threads
4359               ;; If there are some threads, we do them before the
4360               ;; threads on the stack.
4361               (setq thread threads
4362                     gnus-tmp-header (caar thread))
4363             ;; There were no current threads, so we pop something off
4364             ;; the stack.
4365             (setq state (car stack)
4366                   gnus-tmp-level (car state)
4367                   tree-stack (cadr state)
4368                   thread (caddr state)
4369                   stack (cdr stack)
4370                   gnus-tmp-header (caar thread))))
4371
4372         (setq gnus-tmp-false-parent nil)
4373         (setq gnus-tmp-root-expunged nil)
4374         (setq thread-end nil)
4375
4376         (if (stringp gnus-tmp-header)
4377             ;; The header is a dummy root.
4378             (cond
4379              ((eq gnus-summary-make-false-root 'adopt)
4380               ;; We let the first article adopt the rest.
4381               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4382                                                (cddar thread)))
4383               (setq gnus-tmp-gathered
4384                     (nconc (mapcar
4385                             (lambda (h) (mail-header-number (car h)))
4386                             (cddar thread))
4387                            gnus-tmp-gathered))
4388               (setq thread (cons (list (caar thread)
4389                                        (cadar thread))
4390                                  (cdr thread)))
4391               (setq gnus-tmp-level -1
4392                     gnus-tmp-false-parent t))
4393              ((eq gnus-summary-make-false-root 'empty)
4394               ;; We print adopted articles with empty subject fields.
4395               (setq gnus-tmp-gathered
4396                     (nconc (mapcar
4397                             (lambda (h) (mail-header-number (car h)))
4398                             (cddar thread))
4399                            gnus-tmp-gathered))
4400               (setq gnus-tmp-level -1))
4401              ((eq gnus-summary-make-false-root 'dummy)
4402               ;; We remember that we probably want to output a dummy
4403               ;; root.
4404               (setq gnus-tmp-dummy-line gnus-tmp-header)
4405               (setq gnus-tmp-prev-subject gnus-tmp-header))
4406              (t
4407               ;; We do not make a root for the gathered
4408               ;; sub-threads at all.
4409               (setq gnus-tmp-level -1)))
4410
4411           (setq number (mail-header-number gnus-tmp-header)
4412                 subject (mail-header-subject gnus-tmp-header))
4413
4414           (cond
4415            ;; If the thread has changed subject, we might want to make
4416            ;; this subthread into a root.
4417            ((and (null gnus-thread-ignore-subject)
4418                  (not (zerop gnus-tmp-level))
4419                  gnus-tmp-prev-subject
4420                  (not (inline
4421                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4422             (setq new-roots (nconc new-roots (list (car thread)))
4423                   thread-end t
4424                   gnus-tmp-header nil))
4425            ;; If the article lies outside the current limit,
4426            ;; then we do not display it.
4427            ((not (memq number gnus-newsgroup-limit))
4428             (setq gnus-tmp-gathered
4429                   (nconc (mapcar
4430                           (lambda (h) (mail-header-number (car h)))
4431                           (cdar thread))
4432                          gnus-tmp-gathered))
4433             (setq gnus-tmp-new-adopts (if (cdar thread)
4434                                           (append gnus-tmp-new-adopts
4435                                                   (cdar thread))
4436                                         gnus-tmp-new-adopts)
4437                   thread-end t
4438                   gnus-tmp-header nil)
4439             (when (zerop gnus-tmp-level)
4440               (setq gnus-tmp-root-expunged t)))
4441            ;; Perhaps this article is to be marked as read?
4442            ((and gnus-summary-mark-below
4443                  (< (or (cdr (assq number gnus-newsgroup-scored))
4444                         default-score)
4445                     gnus-summary-mark-below)
4446                  ;; Don't touch sparse articles.
4447                  (not (gnus-summary-article-sparse-p number))
4448                  (not (gnus-summary-article-ancient-p number)))
4449             (setq gnus-newsgroup-unreads
4450                   (delq number gnus-newsgroup-unreads))
4451             (if gnus-newsgroup-auto-expire
4452                 (setq gnus-newsgroup-expirable
4453                       (gnus-add-to-sorted-list
4454                        gnus-newsgroup-expirable number))
4455               (push (cons number gnus-low-score-mark)
4456                     gnus-newsgroup-reads))))
4457
4458           (when gnus-tmp-header
4459             ;; We may have an old dummy line to output before this
4460             ;; article.
4461             (when (and gnus-tmp-dummy-line
4462                        (gnus-subject-equal
4463                         gnus-tmp-dummy-line
4464                         (mail-header-subject gnus-tmp-header)))
4465               (gnus-summary-insert-dummy-line
4466                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4467               (setq gnus-tmp-dummy-line nil))
4468
4469             ;; Compute the mark.
4470             (setq gnus-tmp-unread (gnus-article-mark number))
4471
4472             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4473                                   gnus-tmp-header gnus-tmp-level)
4474                   gnus-newsgroup-data)
4475
4476             ;; Actually insert the line.
4477             (setq
4478              gnus-tmp-subject-or-nil
4479              (cond
4480               ((and gnus-thread-ignore-subject
4481                     gnus-tmp-prev-subject
4482                     (not (inline (gnus-subject-equal
4483                                   gnus-tmp-prev-subject subject))))
4484                subject)
4485               ((zerop gnus-tmp-level)
4486                (if (and (eq gnus-summary-make-false-root 'empty)
4487                         (memq number gnus-tmp-gathered)
4488                         gnus-tmp-prev-subject
4489                         (inline (gnus-subject-equal
4490                                  gnus-tmp-prev-subject subject)))
4491                    gnus-summary-same-subject
4492                  subject))
4493               (t gnus-summary-same-subject)))
4494             (if (and (eq gnus-summary-make-false-root 'adopt)
4495                      (= gnus-tmp-level 1)
4496                      (memq number gnus-tmp-gathered))
4497                 (setq gnus-tmp-opening-bracket ?\<
4498                       gnus-tmp-closing-bracket ?\>)
4499               (setq gnus-tmp-opening-bracket ?\[
4500                     gnus-tmp-closing-bracket ?\]))
4501             (setq
4502              gnus-tmp-indentation
4503              (aref gnus-thread-indent-array gnus-tmp-level)
4504              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4505              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4506                                 gnus-summary-default-score 0)
4507              gnus-tmp-score-char
4508              (if (or (null gnus-summary-default-score)
4509                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4510                          gnus-summary-zcore-fuzz))
4511                  ?\ ;;;Whitespace
4512                (if (< gnus-tmp-score gnus-summary-default-score)
4513                    gnus-score-below-mark gnus-score-over-mark))
4514              gnus-tmp-replied
4515              (cond ((memq number gnus-newsgroup-processable)
4516                     gnus-process-mark)
4517                    ((memq number gnus-newsgroup-cached)
4518                     gnus-cached-mark)
4519                    ((memq number gnus-newsgroup-replied)
4520                     gnus-replied-mark)
4521                    ((memq number gnus-newsgroup-forwarded)
4522                     gnus-forwarded-mark)
4523                    ((memq number gnus-newsgroup-saved)
4524                     gnus-saved-mark)
4525                    ((memq number gnus-newsgroup-recent)
4526                     gnus-recent-mark)
4527                    ((memq number gnus-newsgroup-unseen)
4528                     gnus-unseen-mark)
4529                    (t gnus-no-mark))
4530              gnus-tmp-from (mail-header-from gnus-tmp-header)
4531              gnus-tmp-name
4532              (cond
4533               ((string-match "<[^>]+> *$" gnus-tmp-from)
4534                (setq beg-match (match-beginning 0))
4535                (or (and (string-match "^\".+\"" gnus-tmp-from)
4536                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4537                    (substring gnus-tmp-from 0 beg-match)))
4538               ((string-match "(.+)" gnus-tmp-from)
4539                (substring gnus-tmp-from
4540                           (1+ (match-beginning 0)) (1- (match-end 0))))
4541               (t gnus-tmp-from))
4542              gnus-tmp-thread-tree-header-string
4543              (cond
4544               ((not gnus-show-threads) "")
4545               ((zerop gnus-tmp-level)
4546                (if (cdar thread)
4547                    (or gnus-sum-thread-tree-root subject)
4548                  (or gnus-sum-thread-tree-single-indent subject)))
4549               (t
4550                (concat (apply 'concat
4551                               (mapcar (lambda (item)
4552                                         (if (= item 1)
4553                                             gnus-sum-thread-tree-vertical
4554                                           gnus-sum-thread-tree-indent))
4555                                       (cdr (reverse tree-stack))))
4556                        (if (nth 1 thread)
4557                            gnus-sum-thread-tree-leaf-with-other
4558                          gnus-sum-thread-tree-single-leaf)))))
4559             (when (string= gnus-tmp-name "")
4560               (setq gnus-tmp-name gnus-tmp-from))
4561             (unless (numberp gnus-tmp-lines)
4562               (setq gnus-tmp-lines -1))
4563             (if (= gnus-tmp-lines -1)
4564                 (setq gnus-tmp-lines "?")
4565               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4566             (gnus-put-text-property
4567              (point)
4568              (progn (eval gnus-summary-line-format-spec) (point))
4569              'gnus-number number)
4570             (when gnus-visual-p
4571               (forward-line -1)
4572               (gnus-run-hooks 'gnus-summary-update-hook)
4573               (forward-line 1))
4574
4575             (setq gnus-tmp-prev-subject subject)))
4576
4577         (when (nth 1 thread)
4578           (push (list (max 0 gnus-tmp-level)
4579                       (copy-list tree-stack)
4580                       (nthcdr 1 thread))
4581                 stack))
4582         (push (if (nth 1 thread) 1 0) tree-stack)
4583         (incf gnus-tmp-level)
4584         (setq threads (if thread-end nil (cdar thread)))
4585         (unless threads
4586           (setq gnus-tmp-level 0)))))
4587   (gnus-message 7 "Generating summary...done"))
4588
4589 (defun gnus-summary-prepare-unthreaded (headers)
4590   "Generate an unthreaded summary buffer based on HEADERS."
4591   (let (header number mark)
4592
4593     (beginning-of-line)
4594
4595     (while headers
4596       ;; We may have to root out some bad articles...
4597       (when (memq (setq number (mail-header-number
4598                                 (setq header (pop headers))))
4599                   gnus-newsgroup-limit)
4600         ;; Mark article as read when it has a low score.
4601         (when (and gnus-summary-mark-below
4602                    (< (or (cdr (assq number gnus-newsgroup-scored))
4603                           gnus-summary-default-score 0)
4604                       gnus-summary-mark-below)
4605                    (not (gnus-summary-article-ancient-p number)))
4606           (setq gnus-newsgroup-unreads
4607                 (delq number gnus-newsgroup-unreads))
4608           (if gnus-newsgroup-auto-expire
4609               (push number gnus-newsgroup-expirable)
4610             (push (cons number gnus-low-score-mark)
4611                   gnus-newsgroup-reads)))
4612
4613         (setq mark (gnus-article-mark number))
4614         (push (gnus-data-make number mark (1+ (point)) header 0)
4615               gnus-newsgroup-data)
4616         (gnus-summary-insert-line
4617          header 0 number
4618          mark (memq number gnus-newsgroup-replied)
4619          (memq number gnus-newsgroup-expirable)
4620          (mail-header-subject header) nil
4621          (cdr (assq number gnus-newsgroup-scored))
4622          (memq number gnus-newsgroup-processable))))))
4623
4624 (defun gnus-summary-remove-list-identifiers ()
4625   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4626   (let ((regexp (if (consp gnus-list-identifiers)
4627                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4628                   gnus-list-identifiers))
4629         changed subject)
4630     (when regexp
4631       (dolist (header gnus-newsgroup-headers)
4632         (setq subject (mail-header-subject header)
4633               changed nil)
4634         (while (string-match
4635                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4636                 subject)
4637           (setq subject
4638                 (concat (substring subject 0 (match-beginning 2))
4639                         (substring subject (match-end 0)))
4640                 changed t))
4641         (when (and changed
4642                    (string-match
4643                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4644           (setq subject
4645                 (concat (substring subject 0 (match-beginning 1))
4646                         (substring subject (match-end 1)))))
4647         (when changed
4648           (mail-header-set-subject header subject))))))
4649
4650 (defun gnus-fetch-headers (articles)
4651   "Fetch headers of ARTICLES."
4652   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4653     (gnus-message 5 "Fetching headers for %s..." name)
4654     (prog1
4655         (if (eq 'nov
4656                 (setq gnus-headers-retrieved-by
4657                       (gnus-retrieve-headers
4658                        articles gnus-newsgroup-name
4659                        ;; We might want to fetch old headers, but
4660                        ;; not if there is only 1 article.
4661                        (and (or (and
4662                                  (not (eq gnus-fetch-old-headers 'some))
4663                                  (not (numberp gnus-fetch-old-headers)))
4664                                 (> (length articles) 1))
4665                             gnus-fetch-old-headers))))
4666             (gnus-get-newsgroup-headers-xover
4667              articles nil nil gnus-newsgroup-name t)
4668           (gnus-get-newsgroup-headers))
4669       (gnus-message 5 "Fetching headers for %s...done" name))))
4670
4671 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4672   "Select newsgroup GROUP.
4673 If READ-ALL is non-nil, all articles in the group are selected.
4674 If SELECT-ARTICLES, only select those articles from GROUP."
4675   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4676          ;;!!! Dirty hack; should be removed.
4677          (gnus-summary-ignore-duplicates
4678           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4679               t
4680             gnus-summary-ignore-duplicates))
4681          (info (nth 2 entry))
4682          articles fetched-articles cached)
4683
4684     (unless (gnus-check-server
4685              (set (make-local-variable 'gnus-current-select-method)
4686                   (gnus-find-method-for-group group)))
4687       (error "Couldn't open server"))
4688
4689     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4690         (gnus-activate-group group)     ; Or we can activate it...
4691         (progn                          ; Or we bug out.
4692           (when (equal major-mode 'gnus-summary-mode)
4693             (kill-buffer (current-buffer)))
4694           (error "Couldn't activate group %s: %s"
4695                  group (gnus-status-message group))))
4696
4697     (unless (gnus-request-group group t)
4698       (when (equal major-mode 'gnus-summary-mode)
4699         (kill-buffer (current-buffer)))
4700       (error "Couldn't request group %s: %s"
4701              group (gnus-status-message group)))
4702
4703     (setq gnus-newsgroup-name group
4704           gnus-newsgroup-unselected nil
4705           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4706
4707     (let ((display (gnus-group-find-parameter group 'display)))
4708       (setq gnus-newsgroup-display
4709             (cond
4710              ((not (zerop (or (car-safe read-all) 0)))
4711               ;; The user entered the group with C-u SPC/RET, let's show
4712               ;; all articles.
4713               'gnus-not-ignore)
4714              ((eq display 'all)
4715               'gnus-not-ignore)
4716              ((arrayp display)
4717               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4718              ((numberp display)
4719               ;; The following is probably the "correct" solution, but
4720               ;; it makes Gnus fetch all headers and then limit the
4721               ;; articles (which is slow), so instead we hack the
4722               ;; select-articles parameter instead. -- Simon Josefsson
4723               ;; <jas@kth.se>
4724               ;;
4725               ;; (gnus-byte-compile
4726               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4727               ;;                         display)))))
4728               (setq select-articles
4729                     (gnus-uncompress-range
4730                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4731                              (if (> tmp 0)
4732                                  tmp
4733                                1))
4734                            (cdr (gnus-active group)))))
4735               nil)
4736              (t
4737               nil))))
4738
4739     (gnus-summary-setup-default-charset)
4740
4741     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4742     (when (gnus-virtual-group-p group)
4743       (setq cached gnus-newsgroup-cached))
4744
4745     (setq gnus-newsgroup-unreads
4746           (gnus-sorted-ndifference
4747            (gnus-sorted-ndifference gnus-newsgroup-unreads
4748                                     gnus-newsgroup-marked)
4749            gnus-newsgroup-dormant))
4750
4751     (setq gnus-newsgroup-processable nil)
4752
4753     (gnus-update-read-articles group gnus-newsgroup-unreads)
4754
4755     ;; Adjust and set lists of article marks.
4756     (when info
4757       (gnus-adjust-marked-articles info))
4758
4759     (if (setq articles select-articles)
4760         (setq gnus-newsgroup-unselected
4761               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4762       (setq articles (gnus-articles-to-read group read-all)))
4763
4764     (cond
4765      ((null articles)
4766       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4767       'quit)
4768      ((eq articles 0) nil)
4769      (t
4770       ;; Init the dependencies hash table.
4771       (setq gnus-newsgroup-dependencies
4772             (gnus-make-hashtable (length articles)))
4773       (gnus-set-global-variables)
4774       ;; Retrieve the headers and read them in.
4775       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4776
4777       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4778       (when cached
4779         (setq gnus-newsgroup-cached cached))
4780
4781       ;; Suppress duplicates?
4782       (when gnus-suppress-duplicates
4783         (gnus-dup-suppress-articles))
4784
4785       ;; Set the initial limit.
4786       (setq gnus-newsgroup-limit (copy-sequence articles))
4787       ;; Remove canceled articles from the list of unread articles.
4788       (setq fetched-articles
4789             (mapcar (lambda (headers) (mail-header-number headers))
4790                     gnus-newsgroup-headers))
4791       (setq gnus-newsgroup-articles fetched-articles)
4792       (setq gnus-newsgroup-unreads
4793             (gnus-sorted-nintersection
4794              gnus-newsgroup-unreads fetched-articles))
4795       (gnus-compute-unseen-list)
4796
4797       ;; Removed marked articles that do not exist.
4798       (gnus-update-missing-marks
4799        (gnus-sorted-difference articles fetched-articles))
4800       ;; We might want to build some more threads first.
4801       (when (and gnus-fetch-old-headers
4802                  (eq gnus-headers-retrieved-by 'nov))
4803         (if (eq gnus-fetch-old-headers 'invisible)
4804             (gnus-build-all-threads)
4805           (gnus-build-old-threads)))
4806       ;; Let the Gnus agent mark articles as read.
4807       (when gnus-agent
4808         (gnus-agent-get-undownloaded-list))
4809       ;; Remove list identifiers from subject
4810       (when gnus-list-identifiers
4811         (gnus-summary-remove-list-identifiers))
4812       ;; Check whether auto-expire is to be done in this group.
4813       (setq gnus-newsgroup-auto-expire
4814             (gnus-group-auto-expirable-p group))
4815       ;; Set up the article buffer now, if necessary.
4816       (unless gnus-single-article-buffer
4817         (gnus-article-setup-buffer))
4818       ;; First and last article in this newsgroup.
4819       (when gnus-newsgroup-headers
4820         (setq gnus-newsgroup-begin
4821               (mail-header-number (car gnus-newsgroup-headers))
4822               gnus-newsgroup-end
4823               (mail-header-number
4824                (gnus-last-element gnus-newsgroup-headers))))
4825       ;; GROUP is successfully selected.
4826       (or gnus-newsgroup-headers t)))))
4827
4828 (defun gnus-compute-unseen-list ()
4829   ;; The `seen' marks are treated specially.
4830   (if (not gnus-newsgroup-seen)
4831       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4832     (setq gnus-newsgroup-unseen
4833           (gnus-inverse-list-range-intersection
4834            gnus-newsgroup-articles gnus-newsgroup-seen))))
4835
4836 (defun gnus-summary-display-make-predicate (display)
4837   (require 'gnus-agent)
4838   (when (= (length display) 1)
4839     (setq display (car display)))
4840   (unless gnus-summary-display-cache
4841     (dolist (elem (append '((unread . unread)
4842                             (read . read)
4843                             (unseen . unseen))
4844                           gnus-article-mark-lists))
4845       (push (cons (cdr elem)
4846                   (gnus-byte-compile
4847                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4848             gnus-summary-display-cache)))
4849   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4850         (gnus-category-predicate-cache gnus-summary-display-cache))
4851     (gnus-get-predicate display)))
4852
4853 ;; Uses the dynamically bound `number' variable.
4854 (defvar number)
4855 (defun gnus-article-marked-p (type &optional article)
4856   (let ((article (or article number)))
4857     (cond
4858      ((eq type 'tick)
4859       (memq article gnus-newsgroup-marked))
4860      ((eq type 'unsend)
4861       (memq article gnus-newsgroup-unsendable))
4862      ((eq type 'undownload)
4863       (memq article gnus-newsgroup-undownloaded))
4864      ((eq type 'download)
4865       (memq article gnus-newsgroup-downloadable))
4866      ((eq type 'unread)
4867       (memq article gnus-newsgroup-unreads))
4868      ((eq type 'read)
4869       (memq article gnus-newsgroup-reads))
4870      ((eq type 'dormant)
4871       (memq article gnus-newsgroup-dormant) )
4872      ((eq type 'expire)
4873       (memq article gnus-newsgroup-expirable))
4874      ((eq type 'reply)
4875       (memq article gnus-newsgroup-replied))
4876      ((eq type 'killed)
4877       (memq article gnus-newsgroup-killed))
4878      ((eq type 'bookmark)
4879       (assq article gnus-newsgroup-bookmarks))
4880      ((eq type 'score)
4881       (assq article gnus-newsgroup-scored))
4882      ((eq type 'save)
4883       (memq article gnus-newsgroup-saved))
4884      ((eq type 'cache)
4885       (memq article gnus-newsgroup-cached))
4886      ((eq type 'forward)
4887       (memq article gnus-newsgroup-forwarded))
4888      ((eq type 'seen)
4889       (not (memq article gnus-newsgroup-unseen)))
4890      ((eq type 'recent)
4891       (memq article gnus-newsgroup-recent))
4892      (t t))))
4893
4894 (defun gnus-articles-to-read (group &optional read-all)
4895   "Find out what articles the user wants to read."
4896   (let* ((articles
4897           ;; Select all articles if `read-all' is non-nil, or if there
4898           ;; are no unread articles.
4899           (if (or read-all
4900                   (and (zerop (length gnus-newsgroup-marked))
4901                        (zerop (length gnus-newsgroup-unreads)))
4902                   ;; Fetch all if the predicate is non-nil.
4903                   gnus-newsgroup-display)
4904               ;; We want to select the headers for all the articles in
4905               ;; the group, so we select either all the active
4906               ;; articles in the group, or (if that's nil), the
4907               ;; articles in the cache.
4908               (or
4909                (gnus-uncompress-range (gnus-active group))
4910                (gnus-cache-articles-in-group group))
4911             ;; Select only the "normal" subset of articles.
4912             (gnus-sorted-nunion
4913              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4914              gnus-newsgroup-unreads)))
4915          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4916          (scored (length scored-list))
4917          (number (length articles))
4918          (marked (+ (length gnus-newsgroup-marked)
4919                     (length gnus-newsgroup-dormant)))
4920          (select
4921           (cond
4922            ((numberp read-all)
4923             read-all)
4924            ((numberp gnus-newsgroup-display)
4925             gnus-newsgroup-display)
4926            (t
4927             (condition-case ()
4928                 (cond
4929                  ((and (or (<= scored marked) (= scored number))
4930                        (natnump gnus-large-newsgroup)
4931                        (> number gnus-large-newsgroup))
4932                   (let* ((cursor-in-echo-area nil)
4933                          (input
4934                           (read-from-minibuffer
4935                            (format
4936                             "How many articles from %s (max %d): "
4937                             (gnus-limit-string
4938                              (gnus-group-decoded-name gnus-newsgroup-name)
4939                              35)
4940                             number)
4941                            (cons (number-to-string gnus-large-newsgroup)
4942                                  0))))
4943                     (if (string-match "^[ \t]*$" input)
4944                         number
4945                       input)))
4946                  ((and (> scored marked) (< scored number)
4947                        (> (- scored number) 20))
4948                   (let ((input
4949                          (read-string
4950                           (format "%s %s (%d scored, %d total): "
4951                                   "How many articles from"
4952                                   (gnus-group-decoded-name group)
4953                                   scored number))))
4954                     (if (string-match "^[ \t]*$" input)
4955                         number input)))
4956                  (t number))
4957               (quit
4958                (message "Quit getting the articles to read")
4959                nil))))))
4960     (setq select (if (stringp select) (string-to-number select) select))
4961     (if (or (null select) (zerop select))
4962         select
4963       (if (and (not (zerop scored)) (<= (abs select) scored))
4964           (progn
4965             (setq articles (sort scored-list '<))
4966             (setq number (length articles)))
4967         (setq articles (copy-sequence articles)))
4968
4969       (when (< (abs select) number)
4970         (if (< select 0)
4971             ;; Select the N oldest articles.
4972             (setcdr (nthcdr (1- (abs select)) articles) nil)
4973           ;; Select the N most recent articles.
4974           (setq articles (nthcdr (- number select) articles))))
4975       (setq gnus-newsgroup-unselected
4976             (gnus-sorted-difference gnus-newsgroup-unreads articles))
4977       (when gnus-alter-articles-to-read-function
4978         (setq gnus-newsgroup-unreads
4979               (sort
4980                (funcall gnus-alter-articles-to-read-function
4981                         gnus-newsgroup-name gnus-newsgroup-unreads)
4982                '<)))
4983       articles)))
4984
4985 (defun gnus-killed-articles (killed articles)
4986   (let (out)
4987     (while articles
4988       (when (inline (gnus-member-of-range (car articles) killed))
4989         (push (car articles) out))
4990       (setq articles (cdr articles)))
4991     out))
4992
4993 (defun gnus-uncompress-marks (marks)
4994   "Uncompress the mark ranges in MARKS."
4995   (let ((uncompressed '(score bookmark))
4996         out)
4997     (while marks
4998       (if (memq (caar marks) uncompressed)
4999           (push (car marks) out)
5000         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5001       (setq marks (cdr marks)))
5002     out))
5003
5004 (defun gnus-article-mark-to-type (mark)
5005   "Return the type of MARK."
5006   (or (cadr (assq mark gnus-article-special-mark-lists))
5007       'list))
5008
5009 (defun gnus-article-unpropagatable-p (mark)
5010   "Return whether MARK should be propagated to backend."
5011   (memq mark gnus-article-unpropagated-mark-lists))
5012
5013 (defun gnus-adjust-marked-articles (info)
5014   "Set all article lists and remove all marks that are no longer valid."
5015   (let* ((marked-lists (gnus-info-marks info))
5016          (active (gnus-active (gnus-info-group info)))
5017          (min (car active))
5018          (max (cdr active))
5019          (types gnus-article-mark-lists)
5020          marks var articles article mark mark-type)
5021
5022     (dolist (marks marked-lists)
5023       (setq mark (car marks)
5024             mark-type (gnus-article-mark-to-type mark)
5025             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5026
5027       ;; We set the variable according to the type of the marks list,
5028       ;; and then adjust the marks to a subset of the active articles.
5029       (cond
5030        ;; Adjust "simple" lists.
5031        ((eq mark-type 'list)
5032         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5033         (when (memq mark '(tick dormant expire reply save))
5034           (while articles
5035             (when (or (< (setq article (pop articles)) min) (> article max))
5036               (set var (delq article (symbol-value var)))))))
5037        ;; Adjust assocs.
5038        ((eq mark-type 'tuple)
5039         (set var (setq articles (cdr marks)))
5040         (when (not (listp (cdr (symbol-value var))))
5041           (set var (list (symbol-value var))))
5042         (when (not (listp (cdr articles)))
5043           (setq articles (list articles)))
5044         (while articles
5045           (when (or (not (consp (setq article (pop articles))))
5046                     (< (car article) min)
5047                     (> (car article) max))
5048             (set var (delq article (symbol-value var))))))
5049        ;; Adjust ranges (sloppily).
5050        ((eq mark-type 'range)
5051         (cond
5052          ((eq mark 'seen)
5053           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5054           ;; It should be (seen (NUM1 . NUM2)).
5055           (when (numberp (cddr marks))
5056             (setcdr marks (list (cdr marks))))
5057           (setq articles (cdr marks))
5058           (while (and articles
5059                       (or (and (consp (car articles))
5060                                (> min (cdar articles)))
5061                           (and (numberp (car articles))
5062                                (> min (car articles)))))
5063             (pop articles))
5064           (set var articles))))))))
5065
5066 (defun gnus-update-missing-marks (missing)
5067   "Go through the list of MISSING articles and remove them from the mark lists."
5068   (when missing
5069     (let (var m)
5070       ;; Go through all types.
5071       (dolist (elem gnus-article-mark-lists)
5072         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5073           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5074           (when (symbol-value var)
5075             ;; This list has articles.  So we delete all missing
5076             ;; articles from it.
5077             (setq m missing)
5078             (while m
5079               (set var (delq (pop m) (symbol-value var))))))))))
5080
5081 (defun gnus-update-marks ()
5082   "Enter the various lists of marked articles into the newsgroup info list."
5083   (let ((types gnus-article-mark-lists)
5084         (info (gnus-get-info gnus-newsgroup-name))
5085         type list newmarked symbol delta-marks)
5086     (when info
5087       ;; Add all marks lists to the list of marks lists.
5088       (while (setq type (pop types))
5089         (setq list (symbol-value
5090                     (setq symbol
5091                           (intern (format "gnus-newsgroup-%s" (car type))))))
5092
5093         (when list
5094           ;; Get rid of the entries of the articles that have the
5095           ;; default score.
5096           (when (and (eq (cdr type) 'score)
5097                      gnus-save-score
5098                      list)
5099             (let* ((arts list)
5100                    (prev (cons nil list))
5101                    (all prev))
5102               (while arts
5103                 (if (or (not (consp (car arts)))
5104                         (= (cdar arts) gnus-summary-default-score))
5105                     (setcdr prev (cdr arts))
5106                   (setq prev arts))
5107                 (setq arts (cdr arts)))
5108               (setq list (cdr all)))))
5109
5110         (when (eq (cdr type) 'seen)
5111           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5112
5113         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5114           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5115
5116         (when (and (gnus-check-backend-function
5117                     'request-set-mark gnus-newsgroup-name)
5118                    (not (gnus-article-unpropagatable-p (cdr type))))
5119           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5120                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5121                  (add (gnus-remove-from-range
5122                        (gnus-copy-sequence list) old)))
5123             (when add
5124               (push (list add 'add (list (cdr type))) delta-marks))
5125             (when del
5126               (push (list del 'del (list (cdr type))) delta-marks))))
5127
5128         (when list
5129           (push (cons (cdr type) list) newmarked)))
5130
5131       (when delta-marks
5132         (unless (gnus-check-group gnus-newsgroup-name)
5133           (error "Can't open server for %s" gnus-newsgroup-name))
5134         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5135
5136       ;; Enter these new marks into the info of the group.
5137       (if (nthcdr 3 info)
5138           (setcar (nthcdr 3 info) newmarked)
5139         ;; Add the marks lists to the end of the info.
5140         (when newmarked
5141           (setcdr (nthcdr 2 info) (list newmarked))))
5142
5143       ;; Cut off the end of the info if there's nothing else there.
5144       (let ((i 5))
5145         (while (and (> i 2)
5146                     (not (nth i info)))
5147           (when (nthcdr (decf i) info)
5148             (setcdr (nthcdr i info) nil)))))))
5149
5150 (defun gnus-set-mode-line (where)
5151   "Set the mode line of the article or summary buffers.
5152 If WHERE is `summary', the summary mode line format will be used."
5153   ;; Is this mode line one we keep updated?
5154   (when (and (memq where gnus-updated-mode-lines)
5155              (symbol-value
5156               (intern (format "gnus-%s-mode-line-format-spec" where))))
5157     (let (mode-string)
5158       (save-excursion
5159         ;; We evaluate this in the summary buffer since these
5160         ;; variables are buffer-local to that buffer.
5161         (set-buffer gnus-summary-buffer)
5162         ;; We bind all these variables that are used in the `eval' form
5163         ;; below.
5164         (let* ((mformat (symbol-value
5165                          (intern
5166                           (format "gnus-%s-mode-line-format-spec" where))))
5167                (gnus-tmp-group-name (gnus-group-decoded-name
5168                                      gnus-newsgroup-name))
5169                (gnus-tmp-article-number (or gnus-current-article 0))
5170                (gnus-tmp-unread gnus-newsgroup-unreads)
5171                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5172                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5173                (gnus-tmp-unread-and-unselected
5174                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5175                             (zerop gnus-tmp-unselected))
5176                        "")
5177                       ((zerop gnus-tmp-unselected)
5178                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5179                       (t (format "{%d(+%d) more}"
5180                                  gnus-tmp-unread-and-unticked
5181                                  gnus-tmp-unselected))))
5182                (gnus-tmp-subject
5183                 (if (and gnus-current-headers
5184                          (vectorp gnus-current-headers))
5185                     (gnus-mode-string-quote
5186                      (mail-header-subject gnus-current-headers))
5187                   ""))
5188                bufname-length max-len
5189                gnus-tmp-header);; passed as argument to any user-format-funcs
5190           (setq mode-string (eval mformat))
5191           (setq bufname-length (if (string-match "%b" mode-string)
5192                                    (- (length
5193                                        (buffer-name
5194                                         (if (eq where 'summary)
5195                                             nil
5196                                           (get-buffer gnus-article-buffer))))
5197                                       2)
5198                                  0))
5199           (setq max-len (max 4 (if gnus-mode-non-string-length
5200                                    (- (window-width)
5201                                       gnus-mode-non-string-length
5202                                       bufname-length)
5203                                  (length mode-string))))
5204           ;; We might have to chop a bit of the string off...
5205           (when (> (length mode-string) max-len)
5206             (setq mode-string
5207                   (concat (gnus-truncate-string mode-string (- max-len 3))
5208                           "...")))
5209           ;; Pad the mode string a bit.
5210           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5211       ;; Update the mode line.
5212       (setq mode-line-buffer-identification
5213             (gnus-mode-line-buffer-identification (list mode-string)))
5214       (set-buffer-modified-p t))))
5215
5216 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5217   "Go through the HEADERS list and add all Xrefs to a hash table.
5218 The resulting hash table is returned, or nil if no Xrefs were found."
5219   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5220          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5221          (xref-hashtb (gnus-make-hashtable))
5222          start group entry number xrefs header)
5223     (while headers
5224       (setq header (pop headers))
5225       (when (and (setq xrefs (mail-header-xref header))
5226                  (not (memq (setq number (mail-header-number header))
5227                             unreads)))
5228         (setq start 0)
5229         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5230           (setq start (match-end 0))
5231           (setq group (if prefix
5232                           (concat prefix (substring xrefs (match-beginning 1)
5233                                                     (match-end 1)))
5234                         (substring xrefs (match-beginning 1) (match-end 1))))
5235           (setq number
5236                 (string-to-int (substring xrefs (match-beginning 2)
5237                                           (match-end 2))))
5238           (if (setq entry (gnus-gethash group xref-hashtb))
5239               (setcdr entry (cons number (cdr entry)))
5240             (gnus-sethash group (cons number nil) xref-hashtb)))))
5241     (and start xref-hashtb)))
5242
5243 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5244   "Look through all the headers and mark the Xrefs as read."
5245   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5246         name entry info xref-hashtb idlist method nth4)
5247     (save-excursion
5248       (set-buffer gnus-group-buffer)
5249       (when (setq xref-hashtb
5250                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5251         (mapatoms
5252          (lambda (group)
5253            (unless (string= from-newsgroup (setq name (symbol-name group)))
5254              (setq idlist (symbol-value group))
5255              ;; Dead groups are not updated.
5256              (and (prog1
5257                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5258                             info (nth 2 entry))
5259                     (when (stringp (setq nth4 (gnus-info-method info)))
5260                       (setq nth4 (gnus-server-to-method nth4))))
5261                   ;; Only do the xrefs if the group has the same
5262                   ;; select method as the group we have just read.
5263                   (or (gnus-methods-equal-p
5264                        nth4 (gnus-find-method-for-group from-newsgroup))
5265                       virtual
5266                       (equal nth4 (setq method (gnus-find-method-for-group
5267                                                 from-newsgroup)))
5268                       (and (equal (car nth4) (car method))
5269                            (equal (nth 1 nth4) (nth 1 method))))
5270                   gnus-use-cross-reference
5271                   (or (not (eq gnus-use-cross-reference t))
5272                       virtual
5273                       ;; Only do cross-references on subscribed
5274                       ;; groups, if that is what is wanted.
5275                       (<= (gnus-info-level info) gnus-level-subscribed))
5276                   (gnus-group-make-articles-read name idlist))))
5277          xref-hashtb)))))
5278
5279 (defun gnus-compute-read-articles (group articles)
5280   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5281          (info (nth 2 entry))
5282          (active (gnus-active group))
5283          ninfo)
5284     (when entry
5285       ;; First peel off all invalid article numbers.
5286       (when active
5287         (let ((ids articles)
5288               id first)
5289           (while (setq id (pop ids))
5290             (when (and first (> id (cdr active)))
5291               ;; We'll end up in this situation in one particular
5292               ;; obscure situation.  If you re-scan a group and get
5293               ;; a new article that is cross-posted to a different
5294               ;; group that has not been re-scanned, you might get
5295               ;; crossposted article that has a higher number than
5296               ;; Gnus believes possible.  So we re-activate this
5297               ;; group as well.  This might mean doing the
5298               ;; crossposting thingy will *increase* the number
5299               ;; of articles in some groups.  Tsk, tsk.
5300               (setq active (or (gnus-activate-group group) active)))
5301             (when (or (> id (cdr active))
5302                       (< id (car active)))
5303               (setq articles (delq id articles))))))
5304       ;; If the read list is nil, we init it.
5305       (if (and active
5306                (null (gnus-info-read info))
5307                (> (car active) 1))
5308           (setq ninfo (cons 1 (1- (car active))))
5309         (setq ninfo (gnus-info-read info)))
5310       ;; Then we add the read articles to the range.
5311       (gnus-add-to-range
5312        ninfo (setq articles (sort articles '<))))))
5313
5314 (defun gnus-group-make-articles-read (group articles)
5315   "Update the info of GROUP to say that ARTICLES are read."
5316   (let* ((num 0)
5317          (entry (gnus-gethash group gnus-newsrc-hashtb))
5318          (info (nth 2 entry))
5319          (active (gnus-active group))
5320          range)
5321     (when entry
5322       (setq range (gnus-compute-read-articles group articles))
5323       (save-excursion
5324         (set-buffer gnus-group-buffer)
5325         (gnus-undo-register
5326           `(progn
5327              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5328              (gnus-info-set-read ',info ',(gnus-info-read info))
5329              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5330              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5331              (gnus-group-update-group ,group t))))
5332       ;; Add the read articles to the range.
5333       (gnus-info-set-read info range)
5334       (gnus-request-set-mark group (list (list range 'add '(read))))
5335       ;; Then we have to re-compute how many unread
5336       ;; articles there are in this group.
5337       (when active
5338         (cond
5339          ((not range)
5340           (setq num (- (1+ (cdr active)) (car active))))
5341          ((not (listp (cdr range)))
5342           (setq num (- (cdr active) (- (1+ (cdr range))
5343                                        (car range)))))
5344          (t
5345           (while range
5346             (if (numberp (car range))
5347                 (setq num (1+ num))
5348               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5349             (setq range (cdr range)))
5350           (setq num (- (cdr active) num))))
5351         ;; Update the number of unread articles.
5352         (setcar entry num)
5353         ;; Update the group buffer.
5354         (gnus-group-update-group group t)))))
5355
5356 (defvar gnus-newsgroup-none-id 0)
5357
5358 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5359   (let ((cur nntp-server-buffer)
5360         (dependencies
5361          (or dependencies
5362              (save-excursion (set-buffer gnus-summary-buffer)
5363                              gnus-newsgroup-dependencies)))
5364         headers id end ref
5365         (mail-parse-charset gnus-newsgroup-charset)
5366         (mail-parse-ignored-charsets
5367          (save-excursion (condition-case nil
5368                              (set-buffer gnus-summary-buffer)
5369                            (error))
5370                          gnus-newsgroup-ignored-charsets)))
5371     (save-excursion
5372       (set-buffer nntp-server-buffer)
5373       ;; Translate all TAB characters into SPACE characters.
5374       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5375       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5376       (gnus-run-hooks 'gnus-parse-headers-hook)
5377       (let ((case-fold-search t)
5378             in-reply-to header p lines chars ctype)
5379         (goto-char (point-min))
5380         ;; Search to the beginning of the next header.  Error messages
5381         ;; do not begin with 2 or 3.
5382         (while (re-search-forward "^[23][0-9]+ " nil t)
5383           (setq id nil
5384                 ref nil)
5385           ;; This implementation of this function, with nine
5386           ;; search-forwards instead of the one re-search-forward and
5387           ;; a case (which basically was the old function) is actually
5388           ;; about twice as fast, even though it looks messier.  You
5389           ;; can't have everything, I guess.  Speed and elegance
5390           ;; doesn't always go hand in hand.
5391           (setq
5392            header
5393            (make-full-mail-header
5394             ;; Number.
5395             (prog1
5396                 (read cur)
5397               (end-of-line)
5398               (setq p (point))
5399               (narrow-to-region (point)
5400                                 (or (and (search-forward "\n.\n" nil t)
5401                                          (- (point) 2))
5402                                     (point))))
5403             ;; Subject.
5404             (progn
5405               (goto-char p)
5406               (if (search-forward "\nsubject:" nil t)
5407                   (nnheader-header-value)
5408                 "(none)"))
5409             ;; From.
5410             (progn
5411               (goto-char p)
5412               (if (search-forward "\nfrom:" nil t)
5413                   (nnheader-header-value)
5414                 "(nobody)"))
5415             ;; Date.
5416             (progn
5417               (goto-char p)
5418               (if (search-forward "\ndate:" nil t)
5419                   (nnheader-header-value) ""))
5420             ;; Message-ID.
5421             (progn
5422               (goto-char p)
5423               (setq id (if (re-search-forward
5424                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5425                            ;; We do it this way to make sure the Message-ID
5426                            ;; is (somewhat) syntactically valid.
5427                            (buffer-substring (match-beginning 1)
5428                                              (match-end 1))
5429                          ;; If there was no message-id, we just fake one
5430                          ;; to make subsequent routines simpler.
5431                          (nnheader-generate-fake-message-id))))
5432             ;; References.
5433             (progn
5434               (goto-char p)
5435               (if (search-forward "\nreferences:" nil t)
5436                   (progn
5437                     (setq end (point))
5438                     (prog1
5439                         (nnheader-header-value)
5440                       (setq ref
5441                             (buffer-substring
5442                              (progn
5443                                ;; (end-of-line)
5444                                (search-backward ">" end t)
5445                                (1+ (point)))
5446                              (progn
5447                                (search-backward "<" end t)
5448                                (point))))))
5449                 ;; Get the references from the in-reply-to header if there
5450                 ;; were no references and the in-reply-to header looks
5451                 ;; promising.
5452                 (if (and (search-forward "\nin-reply-to:" nil t)
5453                          (setq in-reply-to (nnheader-header-value))
5454                          (string-match "<[^>]+>" in-reply-to))
5455                     (let (ref2)
5456                       (setq ref (substring in-reply-to (match-beginning 0)
5457                                            (match-end 0)))
5458                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5459                         (setq ref2 (substring in-reply-to (match-beginning 0)
5460                                               (match-end 0)))
5461                         (when (> (length ref2) (length ref))
5462                           (setq ref ref2)))
5463                       ref)
5464                   (setq ref nil))))
5465             ;; Chars.
5466             (progn
5467               (goto-char p)
5468               (if (search-forward "\nchars: " nil t)
5469                   (if (numberp (setq chars (ignore-errors (read cur))))
5470                       chars -1)
5471                 -1))
5472             ;; Lines.
5473             (progn
5474               (goto-char p)
5475               (if (search-forward "\nlines: " nil t)
5476                   (if (numberp (setq lines (ignore-errors (read cur))))
5477                       lines -1)
5478                 -1))
5479             ;; Xref.
5480             (progn
5481               (goto-char p)
5482               (and (search-forward "\nxref:" nil t)
5483                    (nnheader-header-value)))
5484             ;; Extra.
5485             (when gnus-extra-headers
5486               (let ((extra gnus-extra-headers)
5487                     out)
5488                 (while extra
5489                   (goto-char p)
5490                   (when (search-forward
5491                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5492                     (push (cons (car extra) (nnheader-header-value)) out))
5493                   (pop extra))
5494                 out))))
5495           (goto-char p)
5496           (if (and (search-forward "\ncontent-type: " nil t)
5497                    (setq ctype (nnheader-header-value)))
5498               (mime-entity-set-content-type-internal
5499                header (mime-parse-Content-Type ctype)))
5500           (when (equal id ref)
5501             (setq ref nil))
5502
5503           (when gnus-alter-header-function
5504             (funcall gnus-alter-header-function header)
5505             (setq id (mail-header-id header)
5506                   ref (gnus-parent-id (mail-header-references header))))
5507
5508           (when (setq header
5509                       (gnus-dependencies-add-header
5510                        header dependencies force-new))
5511             (push header headers))
5512           (goto-char (point-max))
5513           (widen))
5514         (nreverse headers)))))
5515
5516 ;; Goes through the xover lines and returns a list of vectors
5517 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5518                                                   force-new dependencies
5519                                                   group also-fetch-heads)
5520   "Parse the news overview data in the server buffer.
5521 Return a list of headers that match SEQUENCE (see
5522 `nntp-retrieve-headers')."
5523   ;; Get the Xref when the users reads the articles since most/some
5524   ;; NNTP servers do not include Xrefs when using XOVER.
5525   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5526   (let ((mail-parse-charset gnus-newsgroup-charset)
5527         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5528         (cur nntp-server-buffer)
5529         (dependencies (or dependencies gnus-newsgroup-dependencies))
5530         (allp (cond
5531                ((eq gnus-read-all-available-headers t)
5532                 t)
5533                ((stringp gnus-read-all-available-headers)
5534                 (string-match gnus-read-all-available-headers group))
5535                (t
5536                 nil)))
5537         number headers header)
5538     (save-excursion
5539       (set-buffer nntp-server-buffer)
5540       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5541       ;; Allow the user to mangle the headers before parsing them.
5542       (gnus-run-hooks 'gnus-parse-headers-hook)
5543       (goto-char (point-min))
5544       (gnus-parse-without-error
5545         (while (and (or sequence allp)
5546                     (not (eobp)))
5547           (setq number (read cur))
5548           (when (not allp)
5549             (while (and sequence
5550                         (< (car sequence) number))
5551               (setq sequence (cdr sequence))))
5552           (when (and (or allp
5553                          (and sequence
5554                               (eq number (car sequence))))
5555                      (progn
5556                        (setq sequence (cdr sequence))
5557                        (setq header (inline
5558                                       (gnus-nov-parse-line
5559                                        number dependencies force-new)))))
5560             (push header headers))
5561           (forward-line 1)))
5562       ;; A common bug in inn is that if you have posted an article and
5563       ;; then retrieves the active file, it will answer correctly --
5564       ;; the new article is included.  However, a NOV entry for the
5565       ;; article may not have been generated yet, so this may fail.
5566       ;; We work around this problem by retrieving the last few
5567       ;; headers using HEAD.
5568       (if (or (not also-fetch-heads)
5569               (not sequence))
5570           ;; We (probably) got all the headers.
5571           (nreverse headers)
5572         (let ((gnus-nov-is-evil t))
5573           (nconc
5574            (nreverse headers)
5575            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5576              (gnus-get-newsgroup-headers))))))))
5577
5578 (defun gnus-article-get-xrefs ()
5579   "Fill in the Xref value in `gnus-current-headers', if necessary.
5580 This is meant to be called in `gnus-article-internal-prepare-hook'."
5581   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5582                                  gnus-current-headers)))
5583     (or (not gnus-use-cross-reference)
5584         (not headers)
5585         (and (mail-header-xref headers)
5586              (not (string= (mail-header-xref headers) "")))
5587         (let ((case-fold-search t)
5588               xref)
5589           (save-restriction
5590             (nnheader-narrow-to-headers)
5591             (goto-char (point-min))
5592             (when (or (and (not (eobp))
5593                            (eq (downcase (char-after)) ?x)
5594                            (looking-at "Xref:"))
5595                       (search-forward "\nXref:" nil t))
5596               (goto-char (1+ (match-end 0)))
5597               (setq xref (buffer-substring (point)
5598                                            (progn (end-of-line) (point))))
5599               (mail-header-set-xref headers xref)))))))
5600
5601 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5602   "Find article ID and insert the summary line for that article.
5603 OLD-HEADER can either be a header or a line number to insert
5604 the subject line on."
5605   (let* ((line (and (numberp old-header) old-header))
5606          (old-header (and (vectorp old-header) old-header))
5607          (header (cond ((and old-header use-old-header)
5608                         old-header)
5609                        ((and (numberp id)
5610                              (gnus-number-to-header id))
5611                         (gnus-number-to-header id))
5612                        (t
5613                         (gnus-read-header id))))
5614          (number (and (numberp id) id))
5615          d)
5616     (when header
5617       ;; Rebuild the thread that this article is part of and go to the
5618       ;; article we have fetched.
5619       (when (and (not gnus-show-threads)
5620                  old-header)
5621         (when (and number
5622                    (setq d (gnus-data-find (mail-header-number old-header))))
5623           (goto-char (gnus-data-pos d))
5624           (gnus-data-remove
5625            number
5626            (- (gnus-point-at-bol)
5627               (prog1
5628                   (1+ (gnus-point-at-eol))
5629                 (gnus-delete-line))))))
5630       (when old-header
5631         (mail-header-set-number header (mail-header-number old-header)))
5632       (setq gnus-newsgroup-sparse
5633             (delq (setq number (mail-header-number header))
5634                   gnus-newsgroup-sparse))
5635       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5636       (push number gnus-newsgroup-limit)
5637       (gnus-rebuild-thread (mail-header-id header) line)
5638       (gnus-summary-goto-subject number nil t))
5639     (when (and (numberp number)
5640                (> number 0))
5641       ;; We have to update the boundaries even if we can't fetch the
5642       ;; article if ID is a number -- so that the next `P' or `N'
5643       ;; command will fetch the previous (or next) article even
5644       ;; if the one we tried to fetch this time has been canceled.
5645       (when (> number gnus-newsgroup-end)
5646         (setq gnus-newsgroup-end number))
5647       (when (< number gnus-newsgroup-begin)
5648         (setq gnus-newsgroup-begin number))
5649       (setq gnus-newsgroup-unselected
5650             (delq number gnus-newsgroup-unselected)))
5651     ;; Report back a success?
5652     (and header (mail-header-number header))))
5653
5654 ;;; Process/prefix in the summary buffer
5655
5656 (defun gnus-summary-work-articles (n)
5657   "Return a list of articles to be worked upon.
5658 The prefix argument, the list of process marked articles, and the
5659 current article will be taken into consideration."
5660   (save-excursion
5661     (set-buffer gnus-summary-buffer)
5662     (cond
5663      (n
5664       ;; A numerical prefix has been given.
5665       (setq n (prefix-numeric-value n))
5666       (let ((backward (< n 0))
5667             (n (abs (prefix-numeric-value n)))
5668             articles article)
5669         (save-excursion
5670           (while
5671               (and (> n 0)
5672                    (push (setq article (gnus-summary-article-number))
5673                          articles)
5674                    (if backward
5675                        (gnus-summary-find-prev nil article)
5676                      (gnus-summary-find-next nil article)))
5677             (decf n)))
5678         (nreverse articles)))
5679      ((and (gnus-region-active-p) (mark))
5680       (message "region active")
5681       ;; Work on the region between point and mark.
5682       (let ((max (max (point) (mark)))
5683             articles article)
5684         (save-excursion
5685           (goto-char (min (point) (mark)))
5686           (while
5687               (and
5688                (push (setq article (gnus-summary-article-number)) articles)
5689                (gnus-summary-find-next nil article)
5690                (< (point) max)))
5691           (nreverse articles))))
5692      (gnus-newsgroup-processable
5693       ;; There are process-marked articles present.
5694       ;; Save current state.
5695       (gnus-summary-save-process-mark)
5696       ;; Return the list.
5697       (reverse gnus-newsgroup-processable))
5698      (t
5699       ;; Just return the current article.
5700       (list (gnus-summary-article-number))))))
5701
5702 (defmacro gnus-summary-iterate (arg &rest forms)
5703   "Iterate over the process/prefixed articles and do FORMS.
5704 ARG is the interactive prefix given to the command.  FORMS will be
5705 executed with point over the summary line of the articles."
5706   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5707     `(let ((,articles (gnus-summary-work-articles ,arg)))
5708        (while ,articles
5709          (gnus-summary-goto-subject (car ,articles))
5710          ,@forms
5711          (pop ,articles)))))
5712
5713 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5714 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5715
5716 (defun gnus-summary-save-process-mark ()
5717   "Push the current set of process marked articles on the stack."
5718   (interactive)
5719   (push (copy-sequence gnus-newsgroup-processable)
5720         gnus-newsgroup-process-stack))
5721
5722 (defun gnus-summary-kill-process-mark ()
5723   "Push the current set of process marked articles on the stack and unmark."
5724   (interactive)
5725   (gnus-summary-save-process-mark)
5726   (gnus-summary-unmark-all-processable))
5727
5728 (defun gnus-summary-yank-process-mark ()
5729   "Pop the last process mark state off the stack and restore it."
5730   (interactive)
5731   (unless gnus-newsgroup-process-stack
5732     (error "Empty mark stack"))
5733   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5734
5735 (defun gnus-summary-process-mark-set (set)
5736   "Make SET into the current process marked articles."
5737   (gnus-summary-unmark-all-processable)
5738   (while set
5739     (gnus-summary-set-process-mark (pop set))))
5740
5741 ;;; Searching and stuff
5742
5743 (defun gnus-summary-search-group (&optional backward use-level)
5744   "Search for next unread newsgroup.
5745 If optional argument BACKWARD is non-nil, search backward instead."
5746   (save-excursion
5747     (set-buffer gnus-group-buffer)
5748     (when (gnus-group-search-forward
5749            backward nil (if use-level (gnus-group-group-level) nil))
5750       (gnus-group-group-name))))
5751
5752 (defun gnus-summary-best-group (&optional exclude-group)
5753   "Find the name of the best unread group.
5754 If EXCLUDE-GROUP, do not go to this group."
5755   (save-excursion
5756     (set-buffer gnus-group-buffer)
5757     (save-excursion
5758       (gnus-group-best-unread-group exclude-group))))
5759
5760 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5761   (if backward (gnus-summary-find-prev)
5762     (let* ((dummy (gnus-summary-article-intangible-p))
5763            (article (or article (gnus-summary-article-number)))
5764            (arts (gnus-data-find-list article))
5765            result)
5766       (when (and (not dummy)
5767                  (or (not gnus-summary-check-current)
5768                      (not unread)
5769                      (not (gnus-data-unread-p (car arts)))))
5770         (setq arts (cdr arts)))
5771       (when (setq result
5772                   (if unread
5773                       (progn
5774                         (while arts
5775                           (when (or (and undownloaded
5776                                          (eq gnus-undownloaded-mark
5777                                              (gnus-data-mark (car arts))))
5778                                     (gnus-data-unread-p (car arts)))
5779                             (setq result (car arts)
5780                                   arts nil))
5781                           (setq arts (cdr arts)))
5782                         result)
5783                     (car arts)))
5784         (goto-char (gnus-data-pos result))
5785         (gnus-data-number result)))))
5786
5787 (defun gnus-summary-find-prev (&optional unread article)
5788   (let* ((eobp (eobp))
5789          (article (or article (gnus-summary-article-number)))
5790          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5791          result)
5792     (when (and (not eobp)
5793                (or (not gnus-summary-check-current)
5794                    (not unread)
5795                    (not (gnus-data-unread-p (car arts)))))
5796       (setq arts (cdr arts)))
5797     (when (setq result
5798                 (if unread
5799                     (progn
5800                       (while arts
5801                         (when (gnus-data-unread-p (car arts))
5802                           (setq result (car arts)
5803                                 arts nil))
5804                         (setq arts (cdr arts)))
5805                       result)
5806                   (car arts)))
5807       (goto-char (gnus-data-pos result))
5808       (gnus-data-number result))))
5809
5810 (defun gnus-summary-find-subject (subject &optional unread backward article)
5811   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5812          (article (or article (gnus-summary-article-number)))
5813          (articles (gnus-data-list backward))
5814          (arts (gnus-data-find-list article articles))
5815          result)
5816     (when (or (not gnus-summary-check-current)
5817               (not unread)
5818               (not (gnus-data-unread-p (car arts))))
5819       (setq arts (cdr arts)))
5820     (while arts
5821       (and (or (not unread)
5822                (gnus-data-unread-p (car arts)))
5823            (vectorp (gnus-data-header (car arts)))
5824            (gnus-subject-equal
5825             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5826            (setq result (car arts)
5827                  arts nil))
5828       (setq arts (cdr arts)))
5829     (and result
5830          (goto-char (gnus-data-pos result))
5831          (gnus-data-number result))))
5832
5833 (defun gnus-summary-search-forward (&optional unread subject backward)
5834   "Search forward for an article.
5835 If UNREAD, look for unread articles.  If SUBJECT, look for
5836 articles with that subject.  If BACKWARD, search backward instead."
5837   (cond (subject (gnus-summary-find-subject subject unread backward))
5838         (backward (gnus-summary-find-prev unread))
5839         (t (gnus-summary-find-next unread))))
5840
5841 (defun gnus-recenter (&optional n)
5842   "Center point in window and redisplay frame.
5843 Also do horizontal recentering."
5844   (interactive "P")
5845   (when (and gnus-auto-center-summary
5846              (not (eq gnus-auto-center-summary 'vertical)))
5847     (gnus-horizontal-recenter))
5848   (recenter n))
5849
5850 (defun gnus-summary-recenter ()
5851   "Center point in the summary window.
5852 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5853 displayed, no centering will be performed."
5854   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5855   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5856   (interactive)
5857   (let* ((top (cond ((< (window-height) 4) 0)
5858                     ((< (window-height) 7) 1)
5859                     (t (if (numberp gnus-auto-center-summary)
5860                            gnus-auto-center-summary
5861                          2))))
5862          (height (1- (window-height)))
5863          (bottom (save-excursion (goto-char (point-max))
5864                                  (forward-line (- height))
5865                                  (point)))
5866          (window (get-buffer-window (current-buffer))))
5867     ;; The user has to want it.
5868     (when gnus-auto-center-summary
5869       (when (get-buffer-window gnus-article-buffer)
5870         ;; Only do recentering when the article buffer is displayed,
5871         ;; Set the window start to either `bottom', which is the biggest
5872         ;; possible valid number, or the second line from the top,
5873         ;; whichever is the least.
5874         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5875           (if (> bottom top-pos)
5876               ;; Keep the second line from the top visible
5877               (set-window-start window top-pos t)
5878             ;; Try to keep the bottom line visible; if it's partially
5879             ;; obscured, either scroll one more line to make it fully
5880             ;; visible, or revert to using TOP-POS.
5881             (save-excursion
5882               (goto-char (point-max))
5883               (forward-line -1)
5884               (let ((last-line-start (point)))
5885                 (goto-char bottom)
5886                 (set-window-start window (point) t)
5887                 (when (not (pos-visible-in-window-p last-line-start window))
5888                   (forward-line 1)
5889                   (set-window-start window (min (point) top-pos) t)))))))
5890       ;; Do horizontal recentering while we're at it.
5891       (when (and (get-buffer-window (current-buffer) t)
5892                  (not (eq gnus-auto-center-summary 'vertical)))
5893         (let ((selected (selected-window)))
5894           (select-window (get-buffer-window (current-buffer) t))
5895           (gnus-summary-position-point)
5896           (gnus-horizontal-recenter)
5897           (select-window selected))))))
5898
5899 (defun gnus-summary-jump-to-group (newsgroup)
5900   "Move point to NEWSGROUP in group mode buffer."
5901   ;; Keep update point of group mode buffer if visible.
5902   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5903       (save-window-excursion
5904         ;; Take care of tree window mode.
5905         (when (get-buffer-window gnus-group-buffer)
5906           (pop-to-buffer gnus-group-buffer))
5907         (gnus-group-jump-to-group newsgroup))
5908     (save-excursion
5909       ;; Take care of tree window mode.
5910       (if (get-buffer-window gnus-group-buffer)
5911           (pop-to-buffer gnus-group-buffer)
5912         (set-buffer gnus-group-buffer))
5913       (gnus-group-jump-to-group newsgroup))))
5914
5915 ;; This function returns a list of article numbers based on the
5916 ;; difference between the ranges of read articles in this group and
5917 ;; the range of active articles.
5918 (defun gnus-list-of-unread-articles (group)
5919   (let* ((read (gnus-info-read (gnus-get-info group)))
5920          (active (or (gnus-active group) (gnus-activate-group group)))
5921          (last (cdr active))
5922          first nlast unread)
5923     ;; If none are read, then all are unread.
5924     (if (not read)
5925         (setq first (car active))
5926       ;; If the range of read articles is a single range, then the
5927       ;; first unread article is the article after the last read
5928       ;; article.  Sounds logical, doesn't it?
5929       (if (and (not (listp (cdr read)))
5930                (or (< (car read) (car active))
5931                    (progn (setq read (list read))
5932                           nil)))
5933           (setq first (max (car active) (1+ (cdr read))))
5934         ;; `read' is a list of ranges.
5935         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5936                                   (caar read)))
5937                   1)
5938           (setq first (car active)))
5939         (while read
5940           (when first
5941             (while (< first nlast)
5942               (push first unread)
5943               (setq first (1+ first))))
5944           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5945           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5946           (setq read (cdr read)))))
5947     ;; And add the last unread articles.
5948     (while (<= first last)
5949       (push first unread)
5950       (setq first (1+ first)))
5951     ;; Return the list of unread articles.
5952     (delq 0 (nreverse unread))))
5953
5954 (defun gnus-list-of-read-articles (group)
5955   "Return a list of unread, unticked and non-dormant articles."
5956   (let* ((info (gnus-get-info group))
5957          (marked (gnus-info-marks info))
5958          (active (gnus-active group)))
5959     (and info active
5960          (gnus-list-range-difference
5961           (gnus-list-range-difference
5962            (gnus-sorted-complement
5963             (gnus-uncompress-range active)
5964             (gnus-list-of-unread-articles group))
5965            (cdr (assq 'dormant marked)))
5966           (cdr (assq 'tick marked))))))
5967
5968 ;; Various summary commands
5969
5970 (defun gnus-summary-select-article-buffer ()
5971   "Reconfigure windows to show article buffer."
5972   (interactive)
5973   (if (not (gnus-buffer-live-p gnus-article-buffer))
5974       (error "There is no article buffer for this summary buffer")
5975     (gnus-configure-windows 'article)
5976     (select-window (get-buffer-window gnus-article-buffer))))
5977
5978 (defun gnus-summary-universal-argument (arg)
5979   "Perform any operation on all articles that are process/prefixed."
5980   (interactive "P")
5981   (let ((articles (gnus-summary-work-articles arg))
5982         func article)
5983     (if (eq
5984          (setq
5985           func
5986           (key-binding
5987            (read-key-sequence
5988             (substitute-command-keys
5989              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5990          'undefined)
5991         (gnus-error 1 "Undefined key")
5992       (save-excursion
5993         (while articles
5994           (gnus-summary-goto-subject (setq article (pop articles)))
5995           (let (gnus-newsgroup-processable)
5996             (command-execute func))
5997           (gnus-summary-remove-process-mark article)))))
5998   (gnus-summary-position-point))
5999
6000 (defun gnus-summary-toggle-truncation (&optional arg)
6001   "Toggle truncation of summary lines.
6002 With arg, turn line truncation on iff arg is positive."
6003   (interactive "P")
6004   (setq truncate-lines
6005         (if (null arg) (not truncate-lines)
6006           (> (prefix-numeric-value arg) 0)))
6007   (redraw-display))
6008
6009 (defun gnus-summary-reselect-current-group (&optional all rescan)
6010   "Exit and then reselect the current newsgroup.
6011 The prefix argument ALL means to select all articles."
6012   (interactive "P")
6013   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6014     (error "Ephemeral groups can't be reselected"))
6015   (let ((current-subject (gnus-summary-article-number))
6016         (group gnus-newsgroup-name))
6017     (setq gnus-newsgroup-begin nil)
6018     (gnus-summary-exit)
6019     ;; We have to adjust the point of group mode buffer because
6020     ;; point was moved to the next unread newsgroup by exiting.
6021     (gnus-summary-jump-to-group group)
6022     (when rescan
6023       (save-excursion
6024         (save-window-excursion
6025           ;; Don't show group contents.
6026           (set-window-start (selected-window) (point-max))
6027           (gnus-group-get-new-news-this-group 1))))
6028     (gnus-group-read-group all t)
6029     (gnus-summary-goto-subject current-subject nil t)))
6030
6031 (defun gnus-summary-rescan-group (&optional all)
6032   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6033   (interactive "P")
6034   (gnus-summary-reselect-current-group all t))
6035
6036 (defun gnus-summary-update-info (&optional non-destructive)
6037   (save-excursion
6038     (let ((group gnus-newsgroup-name))
6039       (when group
6040         (when gnus-newsgroup-kill-headers
6041           (setq gnus-newsgroup-killed
6042                 (gnus-compress-sequence
6043                  (gnus-sorted-union
6044                   (gnus-list-range-intersection
6045                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6046                   gnus-newsgroup-unreads)
6047                  t)))
6048         (unless (listp (cdr gnus-newsgroup-killed))
6049           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6050         (let ((headers gnus-newsgroup-headers))
6051           ;; Set the new ranges of read articles.
6052           (save-excursion
6053             (set-buffer gnus-group-buffer)
6054             (gnus-undo-force-boundary))
6055           (gnus-update-read-articles
6056            group (gnus-sorted-union
6057                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6058           ;; Set the current article marks.
6059           (let ((gnus-newsgroup-scored
6060                  (if (and (not gnus-save-score)
6061                           (not non-destructive))
6062                      nil
6063                    gnus-newsgroup-scored)))
6064             (save-excursion
6065               (gnus-update-marks)))
6066           ;; Do the cross-ref thing.
6067           (when gnus-use-cross-reference
6068             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6069           ;; Do not switch windows but change the buffer to work.
6070           (set-buffer gnus-group-buffer)
6071           (unless (gnus-ephemeral-group-p group)
6072             (gnus-group-update-group group)))))))
6073
6074 (defun gnus-summary-save-newsrc (&optional force)
6075   "Save the current number of read/marked articles in the dribble buffer.
6076 The dribble buffer will then be saved.
6077 If FORCE (the prefix), also save the .newsrc file(s)."
6078   (interactive "P")
6079   (gnus-summary-update-info t)
6080   (if force
6081       (gnus-save-newsrc-file)
6082     (gnus-dribble-save)))
6083
6084 (defun gnus-summary-exit (&optional temporary)
6085   "Exit reading current newsgroup, and then return to group selection mode.
6086 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6087   (interactive)
6088   (gnus-set-global-variables)
6089   (gnus-kill-save-kill-buffer)
6090   (gnus-async-halt-prefetch)
6091   (let* ((group gnus-newsgroup-name)
6092          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6093          (mode major-mode)
6094          (group-point nil)
6095          (buf (current-buffer)))
6096     (unless quit-config
6097       ;; Do adaptive scoring, and possibly save score files.
6098       (when gnus-newsgroup-adaptive
6099         (gnus-score-adaptive))
6100       (when gnus-use-scoring
6101         (gnus-score-save)))
6102     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6103     ;; If we have several article buffers, we kill them at exit.
6104     (unless gnus-single-article-buffer
6105       (gnus-kill-buffer gnus-original-article-buffer)
6106       (setq gnus-article-current nil))
6107     (when gnus-use-cache
6108       (gnus-cache-possibly-remove-articles)
6109       (gnus-cache-save-buffers))
6110     (gnus-async-prefetch-remove-group group)
6111     (when gnus-suppress-duplicates
6112       (gnus-dup-enter-articles))
6113     (when gnus-use-trees
6114       (gnus-tree-close group))
6115     (when gnus-use-cache
6116       (gnus-cache-write-active))
6117     ;; Remove entries for this group.
6118     (nnmail-purge-split-history (gnus-group-real-name group))
6119     ;; Make all changes in this group permanent.
6120     (unless quit-config
6121       (gnus-run-hooks 'gnus-exit-group-hook)
6122       (gnus-summary-update-info))
6123     (gnus-close-group group)
6124     ;; Make sure where we were, and go to next newsgroup.
6125     (set-buffer gnus-group-buffer)
6126     (unless quit-config
6127       (gnus-group-jump-to-group group))
6128     (gnus-run-hooks 'gnus-summary-exit-hook)
6129     (unless (or quit-config
6130                 ;; If this group has disappeared from the summary
6131                 ;; buffer, don't skip forwards.
6132                 (not (string= group (gnus-group-group-name))))
6133       (gnus-group-next-unread-group 1))
6134     (setq group-point (point))
6135     (if temporary
6136         nil                             ;Nothing to do.
6137       ;; If we have several article buffers, we kill them at exit.
6138       (unless gnus-single-article-buffer
6139         (gnus-kill-buffer gnus-article-buffer)
6140         (gnus-kill-buffer gnus-original-article-buffer)
6141         (setq gnus-article-current nil))
6142       (set-buffer buf)
6143       (if (not gnus-kill-summary-on-exit)
6144           (progn
6145             (gnus-deaden-summary)
6146             (setq mode nil))
6147         ;; We set all buffer-local variables to nil.  It is unclear why
6148         ;; this is needed, but if we don't, buffer-local variables are
6149         ;; not garbage-collected, it seems.  This would the lead to en
6150         ;; ever-growing Emacs.
6151         (gnus-summary-clear-local-variables)
6152         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6153           (gnus-summary-clear-local-variables))
6154         (when (get-buffer gnus-article-buffer)
6155           (bury-buffer gnus-article-buffer))
6156         ;; We clear the global counterparts of the buffer-local
6157         ;; variables as well, just to be on the safe side.
6158         (set-buffer gnus-group-buffer)
6159         (gnus-summary-clear-local-variables)
6160         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6161           (gnus-summary-clear-local-variables)))
6162       (setq gnus-current-select-method gnus-select-method)
6163       (pop-to-buffer gnus-group-buffer)
6164       (if (not quit-config)
6165           (progn
6166             (goto-char group-point)
6167             (gnus-configure-windows 'group 'force)
6168             (unless (pos-visible-in-window-p)
6169               (forward-line (/ (static-if (featurep 'xemacs)
6170                                    (window-displayed-height)
6171                                  (1- (window-height)))
6172                                -2))
6173               (set-window-start (selected-window) (point))
6174               (goto-char group-point)))
6175         (gnus-handle-ephemeral-exit quit-config))
6176       ;; Return to group mode buffer.
6177       (when (eq mode 'gnus-summary-mode)
6178         (gnus-kill-buffer buf))
6179       ;; Clear the current group name.
6180       (unless quit-config
6181         (setq gnus-newsgroup-name nil)))))
6182
6183 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6184 (defun gnus-summary-exit-no-update (&optional no-questions)
6185   "Quit reading current newsgroup without updating read article info."
6186   (interactive)
6187   (let* ((group gnus-newsgroup-name)
6188          (quit-config (gnus-group-quit-config group)))
6189     (when (or no-questions
6190               gnus-expert-user
6191               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6192       (gnus-async-halt-prefetch)
6193       (mapcar 'funcall
6194               (delq 'gnus-summary-expire-articles
6195                     (copy-sequence gnus-summary-prepare-exit-hook)))
6196       ;; If we have several article buffers, we kill them at exit.
6197       (unless gnus-single-article-buffer
6198         (gnus-kill-buffer gnus-article-buffer)
6199         (gnus-kill-buffer gnus-original-article-buffer)
6200         (setq gnus-article-current nil))
6201       (if (not gnus-kill-summary-on-exit)
6202           (gnus-deaden-summary)
6203         (gnus-close-group group)
6204         (gnus-summary-clear-local-variables)
6205         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6206           (gnus-summary-clear-local-variables))
6207         (set-buffer gnus-group-buffer)
6208         (gnus-summary-clear-local-variables)
6209         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6210           (gnus-summary-clear-local-variables))
6211         (when (get-buffer gnus-summary-buffer)
6212           (kill-buffer gnus-summary-buffer)))
6213       (unless gnus-single-article-buffer
6214         (setq gnus-article-current nil))
6215       (when gnus-use-trees
6216         (gnus-tree-close group))
6217       (gnus-async-prefetch-remove-group group)
6218       (when (get-buffer gnus-article-buffer)
6219         (bury-buffer gnus-article-buffer))
6220       ;; Return to the group buffer.
6221       (gnus-configure-windows 'group 'force)
6222       ;; Clear the current group name.
6223       (setq gnus-newsgroup-name nil)
6224       (when (equal (gnus-group-group-name) group)
6225         (gnus-group-next-unread-group 1))
6226       (when quit-config
6227         (gnus-handle-ephemeral-exit quit-config)))))
6228
6229 (defun gnus-handle-ephemeral-exit (quit-config)
6230   "Handle movement when leaving an ephemeral group.
6231 The state which existed when entering the ephemeral is reset."
6232   (if (not (buffer-name (car quit-config)))
6233       (gnus-configure-windows 'group 'force)
6234     (set-buffer (car quit-config))
6235     (cond ((eq major-mode 'gnus-summary-mode)
6236            (gnus-set-global-variables))
6237           ((eq major-mode 'gnus-article-mode)
6238            (save-excursion
6239              ;; The `gnus-summary-buffer' variable may point
6240              ;; to the old summary buffer when using a single
6241              ;; article buffer.
6242              (unless (gnus-buffer-live-p gnus-summary-buffer)
6243                (set-buffer gnus-group-buffer))
6244              (set-buffer gnus-summary-buffer)
6245              (gnus-set-global-variables))))
6246     (if (or (eq (cdr quit-config) 'article)
6247             (eq (cdr quit-config) 'pick))
6248         (progn
6249           ;; The current article may be from the ephemeral group
6250           ;; thus it is best that we reload this article
6251           (gnus-summary-show-article)
6252           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6253               (gnus-configure-windows 'pick 'force)
6254             (gnus-configure-windows (cdr quit-config) 'force)))
6255       (gnus-configure-windows (cdr quit-config) 'force))
6256     (when (eq major-mode 'gnus-summary-mode)
6257       (gnus-summary-next-subject 1 nil t)
6258       (gnus-summary-recenter)
6259       (gnus-summary-position-point))))
6260
6261 (defun gnus-summary-preview-mime-message ()
6262   "MIME decode and play this message."
6263   (interactive)
6264   (let ((gnus-break-pages nil)
6265         (gnus-show-mime t))
6266     (gnus-summary-select-article gnus-show-all-headers t))
6267   (let ((w (get-buffer-window gnus-article-buffer)))
6268     (when w
6269       (select-window (get-buffer-window gnus-article-buffer)))))
6270
6271 ;;; Dead summaries.
6272
6273 (defvar gnus-dead-summary-mode-map nil)
6274
6275 (unless gnus-dead-summary-mode-map
6276   (setq gnus-dead-summary-mode-map (make-keymap))
6277   (suppress-keymap gnus-dead-summary-mode-map)
6278   (substitute-key-definition
6279    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6280   (dolist (key '("\C-d" "\r" "\177" [delete]))
6281     (define-key gnus-dead-summary-mode-map
6282       key 'gnus-summary-wake-up-the-dead))
6283   (dolist (key '("q" "Q"))
6284     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6285
6286 (defvar gnus-dead-summary-mode nil
6287   "Minor mode for Gnus summary buffers.")
6288
6289 (defun gnus-dead-summary-mode (&optional arg)
6290   "Minor mode for Gnus summary buffers."
6291   (interactive "P")
6292   (when (eq major-mode 'gnus-summary-mode)
6293     (make-local-variable 'gnus-dead-summary-mode)
6294     (setq gnus-dead-summary-mode
6295           (if (null arg) (not gnus-dead-summary-mode)
6296             (> (prefix-numeric-value arg) 0)))
6297     (when gnus-dead-summary-mode
6298       (gnus-add-minor-mode
6299        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6300
6301 (defun gnus-deaden-summary ()
6302   "Make the current summary buffer into a dead summary buffer."
6303   ;; Kill any previous dead summary buffer.
6304   (when (and gnus-dead-summary
6305              (buffer-name gnus-dead-summary))
6306     (save-excursion
6307       (set-buffer gnus-dead-summary)
6308       (when gnus-dead-summary-mode
6309         (kill-buffer (current-buffer)))))
6310   ;; Make this the current dead summary.
6311   (setq gnus-dead-summary (current-buffer))
6312   (gnus-dead-summary-mode 1)
6313   (let ((name (buffer-name)))
6314     (when (string-match "Summary" name)
6315       (rename-buffer
6316        (concat (substring name 0 (match-beginning 0)) "Dead "
6317                (substring name (match-beginning 0)))
6318        t)
6319       (bury-buffer))))
6320
6321 (defun gnus-kill-or-deaden-summary (buffer)
6322   "Kill or deaden the summary BUFFER."
6323   (save-excursion
6324     (when (and (buffer-name buffer)
6325                (not gnus-single-article-buffer))
6326       (save-excursion
6327         (set-buffer buffer)
6328         (gnus-kill-buffer gnus-article-buffer)
6329         (gnus-kill-buffer gnus-original-article-buffer)))
6330     (cond
6331      ;; Kill the buffer.
6332      (gnus-kill-summary-on-exit
6333       (when (and gnus-use-trees
6334                  (gnus-buffer-exists-p buffer))
6335         (save-excursion
6336           (set-buffer buffer)
6337           (gnus-tree-close gnus-newsgroup-name)))
6338       (gnus-kill-buffer buffer))
6339      ;; Deaden the buffer.
6340      ((gnus-buffer-exists-p buffer)
6341       (save-excursion
6342         (set-buffer buffer)
6343         (gnus-deaden-summary))))))
6344
6345 (defun gnus-summary-wake-up-the-dead (&rest args)
6346   "Wake up the dead summary buffer."
6347   (interactive)
6348   (gnus-dead-summary-mode -1)
6349   (let ((name (buffer-name)))
6350     (when (string-match "Dead " name)
6351       (rename-buffer
6352        (concat (substring name 0 (match-beginning 0))
6353                (substring name (match-end 0)))
6354        t)))
6355   (gnus-message 3 "This dead summary is now alive again"))
6356
6357 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6358 (defun gnus-summary-fetch-faq (&optional faq-dir)
6359   "Fetch the FAQ for the current group.
6360 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6361 in."
6362   (interactive
6363    (list
6364     (when current-prefix-arg
6365       (completing-read
6366        "Faq dir: " (and (listp gnus-group-faq-directory)
6367                         (mapcar (lambda (file) (list file))
6368                                 gnus-group-faq-directory))))))
6369   (let (gnus-faq-buffer)
6370     (when (setq gnus-faq-buffer
6371                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6372       (gnus-configure-windows 'summary-faq))))
6373
6374 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6375 (defun gnus-summary-describe-group (&optional force)
6376   "Describe the current newsgroup."
6377   (interactive "P")
6378   (gnus-group-describe-group force gnus-newsgroup-name))
6379
6380 (defun gnus-summary-describe-briefly ()
6381   "Describe summary mode commands briefly."
6382   (interactive)
6383   (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")))
6384
6385 ;; Walking around group mode buffer from summary mode.
6386
6387 (defun gnus-summary-next-group (&optional no-article target-group backward)
6388   "Exit current newsgroup and then select next unread newsgroup.
6389 If prefix argument NO-ARTICLE is non-nil, no article is selected
6390 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6391 previous group instead."
6392   (interactive "P")
6393   ;; Stop pre-fetching.
6394   (gnus-async-halt-prefetch)
6395   (let ((current-group gnus-newsgroup-name)
6396         (current-buffer (current-buffer))
6397         entered)
6398     ;; First we semi-exit this group to update Xrefs and all variables.
6399     ;; We can't do a real exit, because the window conf must remain
6400     ;; the same in case the user is prompted for info, and we don't
6401     ;; want the window conf to change before that...
6402     (gnus-summary-exit t)
6403     (while (not entered)
6404       ;; Then we find what group we are supposed to enter.
6405       (set-buffer gnus-group-buffer)
6406       (gnus-group-jump-to-group current-group)
6407       (setq target-group
6408             (or target-group
6409                 (if (eq gnus-keep-same-level 'best)
6410                     (gnus-summary-best-group gnus-newsgroup-name)
6411                   (gnus-summary-search-group backward gnus-keep-same-level))))
6412       (if (not target-group)
6413           ;; There are no further groups, so we return to the group
6414           ;; buffer.
6415           (progn
6416             (gnus-message 5 "Returning to the group buffer")
6417             (setq entered t)
6418             (when (gnus-buffer-live-p current-buffer)
6419               (set-buffer current-buffer)
6420               (gnus-summary-exit))
6421             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6422         ;; We try to enter the target group.
6423         (gnus-group-jump-to-group target-group)
6424         (let ((unreads (gnus-group-group-unread)))
6425           (if (and (or (eq t unreads)
6426                        (and unreads (not (zerop unreads))))
6427                    (gnus-summary-read-group
6428                     target-group nil no-article
6429                     (and (buffer-name current-buffer) current-buffer)
6430                     nil backward))
6431               (setq entered t)
6432             (setq current-group target-group
6433                   target-group nil)))))))
6434
6435 (defun gnus-summary-prev-group (&optional no-article)
6436   "Exit current newsgroup and then select previous unread newsgroup.
6437 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6438   (interactive "P")
6439   (gnus-summary-next-group no-article nil t))
6440
6441 ;; Walking around summary lines.
6442
6443 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6444   "Go to the first unread subject.
6445 If UNREAD is non-nil, go to the first unread article.
6446 Returns the article selected or nil if there are no unread articles."
6447   (interactive "P")
6448   (prog1
6449       (cond
6450        ;; Empty summary.
6451        ((null gnus-newsgroup-data)
6452         (gnus-message 3 "No articles in the group")
6453         nil)
6454        ;; Pick the first article.
6455        ((not unread)
6456         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6457         (gnus-data-number (car gnus-newsgroup-data)))
6458        ;; No unread articles.
6459        ((null gnus-newsgroup-unreads)
6460         (gnus-message 3 "No more unread articles")
6461         nil)
6462        ;; Find the first unread article.
6463        (t
6464         (let ((data gnus-newsgroup-data))
6465           (while (and data
6466                       (and (not (and undownloaded
6467                                      (eq gnus-undownloaded-mark
6468                                          (gnus-data-mark (car data)))))
6469                            (if unseen
6470                                (or (not (memq
6471                                          (gnus-data-number (car data))
6472                                          gnus-newsgroup-unseen))
6473                                    (not (gnus-data-unread-p (car data))))
6474                              (not (gnus-data-unread-p (car data))))))
6475             (setq data (cdr data)))
6476           (when data
6477             (goto-char (gnus-data-pos (car data)))
6478             (gnus-data-number (car data))))))
6479     (gnus-summary-position-point)))
6480
6481 (defun gnus-summary-next-subject (n &optional unread dont-display)
6482   "Go to next N'th summary line.
6483 If N is negative, go to the previous N'th subject line.
6484 If UNREAD is non-nil, only unread articles are selected.
6485 The difference between N and the actual number of steps taken is
6486 returned."
6487   (interactive "p")
6488   (let ((backward (< n 0))
6489         (n (abs n)))
6490     (while (and (> n 0)
6491                 (if backward
6492                     (gnus-summary-find-prev unread)
6493                   (gnus-summary-find-next unread)))
6494       (unless (zerop (setq n (1- n)))
6495         (gnus-summary-show-thread)))
6496     (when (/= 0 n)
6497       (gnus-message 7 "No more%s articles"
6498                     (if unread " unread" "")))
6499     (unless dont-display
6500       (gnus-summary-recenter)
6501       (gnus-summary-position-point))
6502     n))
6503
6504 (defun gnus-summary-next-unread-subject (n)
6505   "Go to next N'th unread summary line."
6506   (interactive "p")
6507   (gnus-summary-next-subject n t))
6508
6509 (defun gnus-summary-prev-subject (n &optional unread)
6510   "Go to previous N'th summary line.
6511 If optional argument UNREAD is non-nil, only unread article is selected."
6512   (interactive "p")
6513   (gnus-summary-next-subject (- n) unread))
6514
6515 (defun gnus-summary-prev-unread-subject (n)
6516   "Go to previous N'th unread summary line."
6517   (interactive "p")
6518   (gnus-summary-next-subject (- n) t))
6519
6520 (defun gnus-summary-goto-subject (article &optional force silent)
6521   "Go the subject line of ARTICLE.
6522 If FORCE, also allow jumping to articles not currently shown."
6523   (interactive "nArticle number: ")
6524   (unless (numberp article)
6525     (error "Article %s is not a number" article))
6526   (let ((b (point))
6527         (data (gnus-data-find article)))
6528     ;; We read in the article if we have to.
6529     (and (not data)
6530          force
6531          (gnus-summary-insert-subject
6532           article
6533           (if (or (numberp force) (vectorp force)) force)
6534           t)
6535          (setq data (gnus-data-find article)))
6536     (goto-char b)
6537     (if (not data)
6538         (progn
6539           (unless silent
6540             (gnus-message 3 "Can't find article %d" article))
6541           nil)
6542       (let ((pt (gnus-data-pos data)))
6543         (goto-char pt)
6544         (gnus-summary-set-article-display-arrow pt))
6545       (gnus-summary-position-point)
6546       article)))
6547
6548 ;; Walking around summary lines with displaying articles.
6549
6550 (defun gnus-summary-expand-window (&optional arg)
6551   "Make the summary buffer take up the entire Emacs frame.
6552 Given a prefix, will force an `article' buffer configuration."
6553   (interactive "P")
6554   (if arg
6555       (gnus-configure-windows 'article 'force)
6556     (gnus-configure-windows 'summary 'force)))
6557
6558 (defun gnus-summary-display-article (article &optional all-header)
6559   "Display ARTICLE in article buffer."
6560   (when (gnus-buffer-live-p gnus-article-buffer)
6561     (with-current-buffer gnus-article-buffer
6562       (set-buffer-multibyte t)))
6563   (gnus-set-global-variables)
6564   (when (gnus-buffer-live-p gnus-article-buffer)
6565     (with-current-buffer gnus-article-buffer
6566       (setq gnus-article-charset gnus-newsgroup-charset)
6567       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6568       (set-buffer-multibyte t)))
6569   (if (null article)
6570       nil
6571     (prog1
6572         (if gnus-summary-display-article-function
6573             (funcall gnus-summary-display-article-function article all-header)
6574           (gnus-article-prepare article all-header))
6575       (with-current-buffer gnus-article-buffer
6576         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6577              nil))
6578       (gnus-run-hooks 'gnus-select-article-hook)
6579       (when (and gnus-current-article
6580                  (not (zerop gnus-current-article)))
6581         (gnus-summary-goto-subject gnus-current-article))
6582       (gnus-summary-recenter)
6583       (when (and gnus-use-trees gnus-show-threads)
6584         (gnus-possibly-generate-tree article)
6585         (gnus-highlight-selected-tree article))
6586       ;; Successfully display article.
6587       (gnus-article-set-window-start
6588        (cdr (assq article gnus-newsgroup-bookmarks))))))
6589
6590 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6591   "Select the current article.
6592 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6593 non-nil, the article will be re-fetched even if it already present in
6594 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6595 be displayed."
6596   ;; Make sure we are in the summary buffer to work around bbdb bug.
6597   (unless (eq major-mode 'gnus-summary-mode)
6598     (set-buffer gnus-summary-buffer))
6599   (let ((article (or article (gnus-summary-article-number)))
6600         (all-headers (not (not all-headers))) ;Must be T or NIL.
6601         gnus-summary-display-article-function)
6602     (and (not pseudo)
6603          (gnus-summary-article-pseudo-p article)
6604          (error "This is a pseudo-article"))
6605     (save-excursion
6606       (set-buffer gnus-summary-buffer)
6607       (if (or (and gnus-single-article-buffer
6608                    (or (null gnus-current-article)
6609                        (null gnus-article-current)
6610                        (null (get-buffer gnus-article-buffer))
6611                        (not (eq article (cdr gnus-article-current)))
6612                        (not (equal (car gnus-article-current)
6613                                    gnus-newsgroup-name))))
6614               (and (not gnus-single-article-buffer)
6615                    (or (null gnus-current-article)
6616                        (not (eq gnus-current-article article))))
6617               force)
6618           ;; The requested article is different from the current article.
6619           (progn
6620             (gnus-summary-display-article article all-headers)
6621             (gnus-article-set-window-start
6622              (cdr (assq article gnus-newsgroup-bookmarks)))
6623             article)
6624         'old))))
6625
6626 (defun gnus-summary-force-verify-and-decrypt ()
6627   (interactive)
6628   (let ((mm-verify-option 'known)
6629         (mm-decrypt-option 'known))
6630     (gnus-summary-select-article nil 'force)))
6631
6632 (defun gnus-summary-set-current-mark (&optional current-mark)
6633   "Obsolete function."
6634   nil)
6635
6636 (defun gnus-summary-next-article (&optional unread subject backward push)
6637   "Select the next article.
6638 If UNREAD, only unread articles are selected.
6639 If SUBJECT, only articles with SUBJECT are selected.
6640 If BACKWARD, the previous article is selected instead of the next."
6641   (interactive "P")
6642   (cond
6643    ;; Is there such an article?
6644    ((and (gnus-summary-search-forward unread subject backward)
6645          (or (gnus-summary-display-article (gnus-summary-article-number))
6646              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6647     (gnus-summary-position-point))
6648    ;; If not, we try the first unread, if that is wanted.
6649    ((and subject
6650          gnus-auto-select-same
6651          (gnus-summary-first-unread-article))
6652     (gnus-summary-position-point)
6653     (gnus-message 6 "Wrapped"))
6654    ;; Try to get next/previous article not displayed in this group.
6655    ((and gnus-auto-extend-newsgroup
6656          (not unread) (not subject))
6657     (gnus-summary-goto-article
6658      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6659      nil (count-lines (point-min) (point))))
6660    ;; Go to next/previous group.
6661    (t
6662     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6663       (gnus-summary-jump-to-group gnus-newsgroup-name))
6664     (let ((cmd last-command-char)
6665           (point
6666            (save-excursion
6667              (set-buffer gnus-group-buffer)
6668              (point)))
6669           (group
6670            (if (eq gnus-keep-same-level 'best)
6671                (gnus-summary-best-group gnus-newsgroup-name)
6672              (gnus-summary-search-group backward gnus-keep-same-level))))
6673       ;; For some reason, the group window gets selected.  We change
6674       ;; it back.
6675       (select-window (get-buffer-window (current-buffer)))
6676       ;; Select next unread newsgroup automagically.
6677       (cond
6678        ((or (not gnus-auto-select-next)
6679             (not cmd))
6680         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6681        ((or (eq gnus-auto-select-next 'quietly)
6682             (and (eq gnus-auto-select-next 'slightly-quietly)
6683                  push)
6684             (and (eq gnus-auto-select-next 'almost-quietly)
6685                  (gnus-summary-last-article-p)))
6686         ;; Select quietly.
6687         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6688             (gnus-summary-exit)
6689           (gnus-message 7 "No more%s articles (%s)..."
6690                         (if unread " unread" "")
6691                         (if group (concat "selecting " group)
6692                           "exiting"))
6693           (gnus-summary-next-group nil group backward)))
6694        (t
6695         (when (gnus-key-press-event-p last-input-event)
6696           (gnus-summary-walk-group-buffer
6697            gnus-newsgroup-name cmd unread backward point))))))))
6698
6699 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6700   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6701                       (?\C-p (gnus-group-prev-unread-group 1))))
6702         (cursor-in-echo-area t)
6703         keve key group ended)
6704     (save-excursion
6705       (set-buffer gnus-group-buffer)
6706       (goto-char start)
6707       (setq group
6708             (if (eq gnus-keep-same-level 'best)
6709                 (gnus-summary-best-group gnus-newsgroup-name)
6710               (gnus-summary-search-group backward gnus-keep-same-level))))
6711     (while (not ended)
6712       (gnus-message
6713        5 "No more%s articles%s" (if unread " unread" "")
6714        (if (and group
6715                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6716            (format " (Type %s for %s [%s])"
6717                    (single-key-description cmd) group
6718                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6719          (format " (Type %s to exit %s)"
6720                  (single-key-description cmd)
6721                  gnus-newsgroup-name)))
6722       ;; Confirm auto selection.
6723       (setq key (car (setq keve (gnus-read-event-char))))
6724       (setq ended t)
6725       (cond
6726        ((assq key keystrokes)
6727         (let ((obuf (current-buffer)))
6728           (switch-to-buffer gnus-group-buffer)
6729           (when group
6730             (gnus-group-jump-to-group group))
6731           (eval (cadr (assq key keystrokes)))
6732           (setq group (gnus-group-group-name))
6733           (switch-to-buffer obuf))
6734         (setq ended nil))
6735        ((equal key cmd)
6736         (if (or (not group)
6737                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6738             (gnus-summary-exit)
6739           (gnus-summary-next-group nil group backward)))
6740        (t
6741         (push (cdr keve) unread-command-events))))))
6742
6743 (defun gnus-summary-next-unread-article ()
6744   "Select unread article after current one."
6745   (interactive)
6746   (gnus-summary-next-article
6747    (or (not (eq gnus-summary-goto-unread 'never))
6748        (gnus-summary-last-article-p (gnus-summary-article-number)))
6749    (and gnus-auto-select-same
6750         (gnus-summary-article-subject))))
6751
6752 (defun gnus-summary-prev-article (&optional unread subject)
6753   "Select the article after the current one.
6754 If UNREAD is non-nil, only unread articles are selected."
6755   (interactive "P")
6756   (gnus-summary-next-article unread subject t))
6757
6758 (defun gnus-summary-prev-unread-article ()
6759   "Select unread article before current one."
6760   (interactive)
6761   (gnus-summary-prev-article
6762    (or (not (eq gnus-summary-goto-unread 'never))
6763        (gnus-summary-first-article-p (gnus-summary-article-number)))
6764    (and gnus-auto-select-same
6765         (gnus-summary-article-subject))))
6766
6767 (defun gnus-summary-next-page (&optional lines circular)
6768   "Show next page of the selected article.
6769 If at the end of the current article, select the next article.
6770 LINES says how many lines should be scrolled up.
6771
6772 If CIRCULAR is non-nil, go to the start of the article instead of
6773 selecting the next article when reaching the end of the current
6774 article."
6775   (interactive "P")
6776   (setq gnus-summary-buffer (current-buffer))
6777   (gnus-set-global-variables)
6778   (let ((article (gnus-summary-article-number))
6779         (article-window (get-buffer-window gnus-article-buffer t))
6780         endp)
6781     ;; If the buffer is empty, we have no article.
6782     (unless article
6783       (error "No article to select"))
6784     (gnus-configure-windows 'article)
6785     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6786         (if (and (eq gnus-summary-goto-unread 'never)
6787                  (not (gnus-summary-last-article-p article)))
6788             (gnus-summary-next-article)
6789           (gnus-summary-next-unread-article))
6790       (if (or (null gnus-current-article)
6791               (null gnus-article-current)
6792               (/= article (cdr gnus-article-current))
6793               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6794           ;; Selected subject is different from current article's.
6795           (gnus-summary-display-article article)
6796         (when article-window
6797           (gnus-eval-in-buffer-window gnus-article-buffer
6798             (setq endp (gnus-article-next-page lines)))
6799           (when endp
6800             (cond (circular
6801                    (gnus-summary-beginning-of-article))
6802                   (lines
6803                    (gnus-message 3 "End of message"))
6804                   ((null lines)
6805                    (if (and (eq gnus-summary-goto-unread 'never)
6806                             (not (gnus-summary-last-article-p article)))
6807                        (gnus-summary-next-article)
6808                      (gnus-summary-next-unread-article))))))))
6809     (gnus-summary-recenter)
6810     (gnus-summary-position-point)))
6811
6812 (defun gnus-summary-prev-page (&optional lines move)
6813   "Show previous page of selected article.
6814 Argument LINES specifies lines to be scrolled down.
6815 If MOVE, move to the previous unread article if point is at
6816 the beginning of the buffer."
6817   (interactive "P")
6818   (let ((article (gnus-summary-article-number))
6819         (article-window (get-buffer-window gnus-article-buffer t))
6820         endp)
6821     (gnus-configure-windows 'article)
6822     (if (or (null gnus-current-article)
6823             (null gnus-article-current)
6824             (/= article (cdr gnus-article-current))
6825             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6826         ;; Selected subject is different from current article's.
6827         (gnus-summary-display-article article)
6828       (gnus-summary-recenter)
6829       (when article-window
6830         (gnus-eval-in-buffer-window gnus-article-buffer
6831           (setq endp (gnus-article-prev-page lines)))
6832         (when (and move endp)
6833           (cond (lines
6834                  (gnus-message 3 "Beginning of message"))
6835                 ((null lines)
6836                  (if (and (eq gnus-summary-goto-unread 'never)
6837                           (not (gnus-summary-first-article-p article)))
6838                      (gnus-summary-prev-article)
6839                    (gnus-summary-prev-unread-article))))))))
6840   (gnus-summary-position-point))
6841
6842 (defun gnus-summary-prev-page-or-article (&optional lines)
6843   "Show previous page of selected article.
6844 Argument LINES specifies lines to be scrolled down.
6845 If at the beginning of the article, go to the next article."
6846   (interactive "P")
6847   (gnus-summary-prev-page lines t))
6848
6849 (defun gnus-summary-scroll-up (lines)
6850   "Scroll up (or down) one line current article.
6851 Argument LINES specifies lines to be scrolled up (or down if negative)."
6852   (interactive "p")
6853   (gnus-configure-windows 'article)
6854   (gnus-summary-show-thread)
6855   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6856     (gnus-eval-in-buffer-window gnus-article-buffer
6857       (cond ((> lines 0)
6858              (when (gnus-article-next-page lines)
6859                (gnus-message 3 "End of message")))
6860             ((< lines 0)
6861              (gnus-article-prev-page (- lines))))))
6862   (gnus-summary-recenter)
6863   (gnus-summary-position-point))
6864
6865 (defun gnus-summary-scroll-down (lines)
6866   "Scroll down (or up) one line current article.
6867 Argument LINES specifies lines to be scrolled down (or up if negative)."
6868   (interactive "p")
6869   (gnus-summary-scroll-up (- lines)))
6870
6871 (defun gnus-summary-next-same-subject ()
6872   "Select next article which has the same subject as current one."
6873   (interactive)
6874   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6875
6876 (defun gnus-summary-prev-same-subject ()
6877   "Select previous article which has the same subject as current one."
6878   (interactive)
6879   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6880
6881 (defun gnus-summary-next-unread-same-subject ()
6882   "Select next unread article which has the same subject as current one."
6883   (interactive)
6884   (gnus-summary-next-article t (gnus-summary-article-subject)))
6885
6886 (defun gnus-summary-prev-unread-same-subject ()
6887   "Select previous unread article which has the same subject as current one."
6888   (interactive)
6889   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6890
6891 (defun gnus-summary-first-unread-article ()
6892   "Select the first unread article.
6893 Return nil if there are no unread articles."
6894   (interactive)
6895   (prog1
6896       (when (gnus-summary-first-subject t)
6897         (gnus-summary-show-thread)
6898         (gnus-summary-first-subject t)
6899         (gnus-summary-display-article (gnus-summary-article-number)))
6900     (gnus-summary-position-point)))
6901
6902 (defun gnus-summary-first-unread-subject ()
6903   "Place the point on the subject line of the first unread article.
6904 Return nil if there are no unread articles."
6905   (interactive)
6906   (prog1
6907       (when (gnus-summary-first-subject t)
6908         (gnus-summary-show-thread)
6909         (gnus-summary-first-subject t))
6910     (gnus-summary-position-point)))
6911
6912 (defun gnus-summary-first-unseen-subject ()
6913   "Place the point on the subject line of the first unseen article.
6914 Return nil if there are no unseen articles."
6915   (interactive)
6916   (prog1
6917       (when (gnus-summary-first-subject t t t)
6918         (gnus-summary-show-thread)
6919         (gnus-summary-first-subject t t t))
6920     (gnus-summary-position-point)))
6921
6922 (defun gnus-summary-first-unseen-or-unread-subject ()
6923   "Place the point on the subject line of the first unseen article.
6924 Return nil if there are no unseen articles."
6925   (interactive)
6926   (prog1
6927       (unless (when (gnus-summary-first-subject t t t)
6928                 (gnus-summary-show-thread)
6929                 (gnus-summary-first-subject t t t))
6930         (when (gnus-summary-first-subject t)
6931           (gnus-summary-show-thread)
6932           (gnus-summary-first-subject t)))
6933     (gnus-summary-position-point)))
6934
6935 (defun gnus-summary-first-article ()
6936   "Select the first article.
6937 Return nil if there are no articles."
6938   (interactive)
6939   (prog1
6940       (when (gnus-summary-first-subject)
6941         (gnus-summary-show-thread)
6942         (gnus-summary-first-subject)
6943         (gnus-summary-display-article (gnus-summary-article-number)))
6944     (gnus-summary-position-point)))
6945
6946 (defun gnus-summary-best-unread-article (&optional arg)
6947   "Select the unread article with the highest score.
6948 If given a prefix argument, select the next unread article that has a
6949 score higher than the default score."
6950   (interactive "P")
6951   (let ((article (if arg
6952                      (gnus-summary-better-unread-subject)
6953                    (gnus-summary-best-unread-subject))))
6954     (if article
6955         (gnus-summary-goto-article article)
6956       (error "No unread articles"))))
6957
6958 (defun gnus-summary-best-unread-subject ()
6959   "Select the unread subject with the highest score."
6960   (interactive)
6961   (let ((best -1000000)
6962         (data gnus-newsgroup-data)
6963         article score)
6964     (while data
6965       (and (gnus-data-unread-p (car data))
6966            (> (setq score
6967                     (gnus-summary-article-score (gnus-data-number (car data))))
6968               best)
6969            (setq best score
6970                  article (gnus-data-number (car data))))
6971       (setq data (cdr data)))
6972     (when article
6973       (gnus-summary-goto-subject article))
6974     (gnus-summary-position-point)
6975     article))
6976
6977 (defun gnus-summary-better-unread-subject ()
6978   "Select the first unread subject that has a score over the default score."
6979   (interactive)
6980   (let ((data gnus-newsgroup-data)
6981         article score)
6982     (while (and (setq article (gnus-data-number (car data)))
6983                 (or (gnus-data-read-p (car data))
6984                     (not (> (gnus-summary-article-score article)
6985                             gnus-summary-default-score))))
6986       (setq data (cdr data)))
6987     (when article
6988       (gnus-summary-goto-subject article))
6989     (gnus-summary-position-point)
6990     article))
6991
6992 (defun gnus-summary-last-subject ()
6993   "Go to the last displayed subject line in the group."
6994   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6995     (when article
6996       (gnus-summary-goto-subject article))))
6997
6998 (defun gnus-summary-goto-article (article &optional all-headers force)
6999   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7000 If ALL-HEADERS is non-nil, no header lines are hidden.
7001 If FORCE, go to the article even if it isn't displayed.  If FORCE
7002 is a number, it is the line the article is to be displayed on."
7003   (interactive
7004    (list
7005     (completing-read
7006      "Article number or Message-ID: "
7007      (mapcar (lambda (number) (list (int-to-string number)))
7008              gnus-newsgroup-limit))
7009     current-prefix-arg
7010     t))
7011   (prog1
7012       (if (and (stringp article)
7013                (string-match "@" article))
7014           (gnus-summary-refer-article article)
7015         (when (stringp article)
7016           (setq article (string-to-number article)))
7017         (if (gnus-summary-goto-subject article force)
7018             (gnus-summary-display-article article all-headers)
7019           (gnus-message 4 "Couldn't go to article %s" article) nil))
7020     (gnus-summary-position-point)))
7021
7022 (defun gnus-summary-goto-last-article ()
7023   "Go to the previously read article."
7024   (interactive)
7025   (prog1
7026       (when gnus-last-article
7027         (gnus-summary-goto-article gnus-last-article nil t))
7028     (gnus-summary-position-point)))
7029
7030 (defun gnus-summary-pop-article (number)
7031   "Pop one article off the history and go to the previous.
7032 NUMBER articles will be popped off."
7033   (interactive "p")
7034   (let (to)
7035     (setq gnus-newsgroup-history
7036           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7037     (if to
7038         (gnus-summary-goto-article (car to) nil t)
7039       (error "Article history empty")))
7040   (gnus-summary-position-point))
7041
7042 ;; Summary commands and functions for limiting the summary buffer.
7043
7044 (defun gnus-summary-limit-to-articles (n)
7045   "Limit the summary buffer to the next N articles.
7046 If not given a prefix, use the process marked articles instead."
7047   (interactive "P")
7048   (prog1
7049       (let ((articles (gnus-summary-work-articles n)))
7050         (setq gnus-newsgroup-processable nil)
7051         (gnus-summary-limit articles))
7052     (gnus-summary-position-point)))
7053
7054 (defun gnus-summary-pop-limit (&optional total)
7055   "Restore the previous limit.
7056 If given a prefix, remove all limits."
7057   (interactive "P")
7058   (when total
7059     (setq gnus-newsgroup-limits
7060           (list (mapcar (lambda (h) (mail-header-number h))
7061                         gnus-newsgroup-headers))))
7062   (unless gnus-newsgroup-limits
7063     (error "No limit to pop"))
7064   (prog1
7065       (gnus-summary-limit nil 'pop)
7066     (gnus-summary-position-point)))
7067
7068 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7069   "Limit the summary buffer to articles that have subjects that match a regexp.
7070 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7071   (interactive
7072    (list (read-string (if current-prefix-arg
7073                           "Exclude subject (regexp): "
7074                         "Limit to subject (regexp): "))
7075          nil current-prefix-arg))
7076   (unless header
7077     (setq header "subject"))
7078   (when (not (equal "" subject))
7079     (prog1
7080         (let ((articles (gnus-summary-find-matching
7081                          (or header "subject") subject 'all nil nil
7082                          not-matching)))
7083           (unless articles
7084             (error "Found no matches for \"%s\"" subject))
7085           (gnus-summary-limit articles))
7086       (gnus-summary-position-point))))
7087
7088 (defun gnus-summary-limit-to-author (from &optional not-matching)
7089   "Limit the summary buffer to articles that have authors that match a regexp.
7090 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7091   (interactive
7092    (list (read-string (if current-prefix-arg
7093                           "Exclude author (regexp): "
7094                         "Limit to author (regexp): "))
7095          current-prefix-arg))
7096   (gnus-summary-limit-to-subject from "from" not-matching))
7097
7098 (defun gnus-summary-limit-to-age (age &optional younger-p)
7099   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7100 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7101 articles that are younger than AGE days."
7102   (interactive
7103    (let ((younger current-prefix-arg)
7104          (days-got nil)
7105          days)
7106      (while (not days-got)
7107        (setq days (if younger
7108                       (read-string "Limit to articles within (in days): ")
7109                     (read-string "Limit to articles older than (in days): ")))
7110        (when (> (length days) 0)
7111          (setq days (read days)))
7112        (if (numberp days)
7113            (progn
7114              (setq days-got t)
7115              (if (< days 0)
7116                  (progn
7117                    (setq younger (not younger))
7118                    (setq days (* days -1)))))
7119          (message "Please enter a number.")
7120          (sleep-for 1)))
7121      (list days younger)))
7122   (prog1
7123       (let ((data gnus-newsgroup-data)
7124             (cutoff (days-to-time age))
7125             articles d date is-younger)
7126         (while (setq d (pop data))
7127           (when (and (vectorp (gnus-data-header d))
7128                      (setq date (mail-header-date (gnus-data-header d))))
7129             (setq is-younger (time-less-p
7130                               (time-since (condition-case ()
7131                                               (date-to-time date)
7132                                             (error '(0 0))))
7133                               cutoff))
7134             (when (if younger-p
7135                       is-younger
7136                     (not is-younger))
7137               (push (gnus-data-number d) articles))))
7138         (gnus-summary-limit (nreverse articles)))
7139     (gnus-summary-position-point)))
7140
7141 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7142   "Limit the summary buffer to articles that match an 'extra' header."
7143   (interactive
7144    (let ((header
7145           (intern
7146            (gnus-completing-read-with-default
7147             (symbol-name (car gnus-extra-headers))
7148             (if current-prefix-arg
7149                 "Exclude extra header:"
7150               "Limit extra header:")
7151             (mapcar (lambda (x)
7152                       (cons (symbol-name x) x))
7153                     gnus-extra-headers)
7154             nil
7155             t))))
7156      (list header
7157            (read-string (format "%s header %s (regexp): "
7158                                 (if current-prefix-arg "Exclude" "Limit to")
7159                                 header))
7160            current-prefix-arg)))
7161   (when (not (equal "" regexp))
7162     (prog1
7163         (let ((articles (gnus-summary-find-matching
7164                          (cons 'extra header) regexp 'all nil nil
7165                          not-matching)))
7166           (unless articles
7167             (error "Found no matches for \"%s\"" regexp))
7168           (gnus-summary-limit articles))
7169       (gnus-summary-position-point))))
7170
7171 (defun gnus-summary-limit-to-display-predicate ()
7172   "Limit the summary buffer to the predicated in the `display' group parameter."
7173   (interactive)
7174   (unless gnus-newsgroup-display
7175     (error "There is no `display' group parameter"))
7176   (let (articles)
7177     (dolist (number gnus-newsgroup-articles)
7178       (when (funcall gnus-newsgroup-display)
7179         (push number articles)))
7180     (gnus-summary-limit articles))
7181   (gnus-summary-position-point))
7182
7183 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7184 (make-obsolete
7185  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7186
7187 (defun gnus-summary-limit-to-unread (&optional all)
7188   "Limit the summary buffer to articles that are not marked as read.
7189 If ALL is non-nil, limit strictly to unread articles."
7190   (interactive "P")
7191   (if all
7192       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7193     (gnus-summary-limit-to-marks
7194      ;; Concat all the marks that say that an article is read and have
7195      ;; those removed.
7196      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7197            gnus-killed-mark gnus-kill-file-mark
7198            gnus-low-score-mark gnus-expirable-mark
7199            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7200            gnus-duplicate-mark gnus-souped-mark)
7201      'reverse)))
7202
7203 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7204 (make-obsolete 'gnus-summary-delete-marked-with
7205                'gnus-summary-limit-exlude-marks)
7206
7207 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7208   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7209 If REVERSE, limit the summary buffer to articles that are marked
7210 with MARKS.  MARKS can either be a string of marks or a list of marks.
7211 Returns how many articles were removed."
7212   (interactive "sMarks: ")
7213   (gnus-summary-limit-to-marks marks t))
7214
7215 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7216   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7217 If REVERSE (the prefix), limit the summary buffer to articles that are
7218 not marked with MARKS.  MARKS can either be a string of marks or a
7219 list of marks.
7220 Returns how many articles were removed."
7221   (interactive "sMarks: \nP")
7222   (prog1
7223       (let ((data gnus-newsgroup-data)
7224             (marks (if (listp marks) marks
7225                      (append marks nil))) ; Transform to list.
7226             articles)
7227         (while data
7228           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7229                   (memq (gnus-data-mark (car data)) marks))
7230             (push (gnus-data-number (car data)) articles))
7231           (setq data (cdr data)))
7232         (gnus-summary-limit articles))
7233     (gnus-summary-position-point)))
7234
7235 (defun gnus-summary-limit-to-score (score)
7236   "Limit to articles with score at or above SCORE."
7237   (interactive "NLimit to articles with score of at least: ")
7238   (let ((data gnus-newsgroup-data)
7239         articles)
7240     (while data
7241       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7242                 score)
7243         (push (gnus-data-number (car data)) articles))
7244       (setq data (cdr data)))
7245     (prog1
7246         (gnus-summary-limit articles)
7247       (gnus-summary-position-point))))
7248
7249 (defun gnus-summary-limit-include-thread (id)
7250   "Display all the hidden articles that is in the thread with ID in it.
7251 When called interactively, ID is the Message-ID of the current
7252 article."
7253   (interactive (list (mail-header-id (gnus-summary-article-header))))
7254   (let ((articles (gnus-articles-in-thread
7255                    (gnus-id-to-thread (gnus-root-id id)))))
7256     (prog1
7257         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7258       (gnus-summary-limit-include-matching-articles
7259        "subject"
7260        (regexp-quote (gnus-simplify-subject-re
7261                       (mail-header-subject (gnus-id-to-header id)))))
7262       (gnus-summary-position-point))))
7263
7264 (defun gnus-summary-limit-include-matching-articles (header regexp)
7265   "Display all the hidden articles that have HEADERs that match REGEXP."
7266   (interactive (list (read-string "Match on header: ")
7267                      (read-string "Regexp: ")))
7268   (let ((articles (gnus-find-matching-articles header regexp)))
7269     (prog1
7270         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7271       (gnus-summary-position-point))))
7272
7273 (defun gnus-summary-limit-include-dormant ()
7274   "Display all the hidden articles that are marked as dormant.
7275 Note that this command only works on a subset of the articles currently
7276 fetched for this group."
7277   (interactive)
7278   (unless gnus-newsgroup-dormant
7279     (error "There are no dormant articles in this group"))
7280   (prog1
7281       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7282     (gnus-summary-position-point)))
7283
7284 (defun gnus-summary-limit-exclude-dormant ()
7285   "Hide all dormant articles."
7286   (interactive)
7287   (prog1
7288       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7289     (gnus-summary-position-point)))
7290
7291 (defun gnus-summary-limit-exclude-childless-dormant ()
7292   "Hide all dormant articles that have no children."
7293   (interactive)
7294   (let ((data (gnus-data-list t))
7295         articles d children)
7296     ;; Find all articles that are either not dormant or have
7297     ;; children.
7298     (while (setq d (pop data))
7299       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7300                 (and (setq children
7301                            (gnus-article-children (gnus-data-number d)))
7302                      (let (found)
7303                        (while children
7304                          (when (memq (car children) articles)
7305                            (setq children nil
7306                                  found t))
7307                          (pop children))
7308                        found)))
7309         (push (gnus-data-number d) articles)))
7310     ;; Do the limiting.
7311     (prog1
7312         (gnus-summary-limit articles)
7313       (gnus-summary-position-point))))
7314
7315 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7316   "Mark all unread excluded articles as read.
7317 If ALL, mark even excluded ticked and dormants as read."
7318   (interactive "P")
7319   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7320   (let ((articles (gnus-sorted-ndifference
7321                    (sort
7322                     (mapcar (lambda (h) (mail-header-number h))
7323                             gnus-newsgroup-headers)
7324                     '<)
7325                    gnus-newsgroup-limit))
7326         article)
7327     (setq gnus-newsgroup-unreads
7328           (gnus-sorted-intersection gnus-newsgroup-unreads
7329                                     gnus-newsgroup-limit))
7330     (if all
7331         (setq gnus-newsgroup-dormant nil
7332               gnus-newsgroup-marked nil
7333               gnus-newsgroup-reads
7334               (nconc
7335                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7336                gnus-newsgroup-reads))
7337       (while (setq article (pop articles))
7338         (unless (or (memq article gnus-newsgroup-dormant)
7339                     (memq article gnus-newsgroup-marked))
7340           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7341
7342 (defun gnus-summary-limit (articles &optional pop)
7343   (if pop
7344       ;; We pop the previous limit off the stack and use that.
7345       (setq articles (car gnus-newsgroup-limits)
7346             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7347     ;; We use the new limit, so we push the old limit on the stack.
7348     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7349   ;; Set the limit.
7350   (setq gnus-newsgroup-limit articles)
7351   (let ((total (length gnus-newsgroup-data))
7352         (data (gnus-data-find-list (gnus-summary-article-number)))
7353         (gnus-summary-mark-below nil)   ; Inhibit this.
7354         found)
7355     ;; This will do all the work of generating the new summary buffer
7356     ;; according to the new limit.
7357     (gnus-summary-prepare)
7358     ;; Hide any threads, possibly.
7359     (gnus-summary-maybe-hide-threads)
7360     ;; Try to return to the article you were at, or one in the
7361     ;; neighborhood.
7362     (when data
7363       ;; We try to find some article after the current one.
7364       (while data
7365         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7366           (setq data nil
7367                 found t))
7368         (setq data (cdr data))))
7369     (unless found
7370       ;; If there is no data, that means that we were after the last
7371       ;; article.  The same goes when we can't find any articles
7372       ;; after the current one.
7373       (goto-char (point-max))
7374       (gnus-summary-find-prev))
7375     (gnus-set-mode-line 'summary)
7376     ;; We return how many articles were removed from the summary
7377     ;; buffer as a result of the new limit.
7378     (- total (length gnus-newsgroup-data))))
7379
7380 (defsubst gnus-invisible-cut-children (threads)
7381   (let ((num 0))
7382     (while threads
7383       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7384         (incf num))
7385       (pop threads))
7386     (< num 2)))
7387
7388 (defsubst gnus-cut-thread (thread)
7389   "Go forwards in the thread until we find an article that we want to display."
7390   (when (or (eq gnus-fetch-old-headers 'some)
7391             (eq gnus-fetch-old-headers 'invisible)
7392             (numberp gnus-fetch-old-headers)
7393             (eq gnus-build-sparse-threads 'some)
7394             (eq gnus-build-sparse-threads 'more))
7395     ;; Deal with old-fetched headers and sparse threads.
7396     (while (and
7397             thread
7398             (or
7399              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7400              (gnus-summary-article-ancient-p
7401               (mail-header-number (car thread))))
7402             (if (or (<= (length (cdr thread)) 1)
7403                     (eq gnus-fetch-old-headers 'invisible))
7404                 (setq gnus-newsgroup-limit
7405                       (delq (mail-header-number (car thread))
7406                             gnus-newsgroup-limit)
7407                       thread (cadr thread))
7408               (when (gnus-invisible-cut-children (cdr thread))
7409                 (let ((th (cdr thread)))
7410                   (while th
7411                     (if (memq (mail-header-number (caar th))
7412                               gnus-newsgroup-limit)
7413                         (setq thread (car th)
7414                               th nil)
7415                       (setq th (cdr th))))))))))
7416   thread)
7417
7418 (defun gnus-cut-threads (threads)
7419   "Cut off all uninteresting articles from the beginning of threads."
7420   (when (or (eq gnus-fetch-old-headers 'some)
7421             (eq gnus-fetch-old-headers 'invisible)
7422             (numberp gnus-fetch-old-headers)
7423             (eq gnus-build-sparse-threads 'some)
7424             (eq gnus-build-sparse-threads 'more))
7425     (let ((th threads))
7426       (while th
7427         (setcar th (gnus-cut-thread (car th)))
7428         (setq th (cdr th)))))
7429   ;; Remove nixed out threads.
7430   (delq nil threads))
7431
7432 (defun gnus-summary-initial-limit (&optional show-if-empty)
7433   "Figure out what the initial limit is supposed to be on group entry.
7434 This entails weeding out unwanted dormants, low-scored articles,
7435 fetch-old-headers verbiage, and so on."
7436   ;; Most groups have nothing to remove.
7437   (if (or gnus-inhibit-limiting
7438           (and (null gnus-newsgroup-dormant)
7439                (eq gnus-newsgroup-display 'gnus-not-ignore)
7440                (not (eq gnus-fetch-old-headers 'some))
7441                (not (numberp gnus-fetch-old-headers))
7442                (not (eq gnus-fetch-old-headers 'invisible))
7443                (null gnus-summary-expunge-below)
7444                (not (eq gnus-build-sparse-threads 'some))
7445                (not (eq gnus-build-sparse-threads 'more))
7446                (null gnus-thread-expunge-below)
7447                (not gnus-use-nocem)))
7448       ()                                ; Do nothing.
7449     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7450     (setq gnus-newsgroup-limit nil)
7451     (mapatoms
7452      (lambda (node)
7453        (unless (car (symbol-value node))
7454          ;; These threads have no parents -- they are roots.
7455          (let ((nodes (cdr (symbol-value node)))
7456                thread)
7457            (while nodes
7458              (if (and gnus-thread-expunge-below
7459                       (< (gnus-thread-total-score (car nodes))
7460                          gnus-thread-expunge-below))
7461                  (gnus-expunge-thread (pop nodes))
7462                (setq thread (pop nodes))
7463                (gnus-summary-limit-children thread))))))
7464      gnus-newsgroup-dependencies)
7465     ;; If this limitation resulted in an empty group, we might
7466     ;; pop the previous limit and use it instead.
7467     (when (and (not gnus-newsgroup-limit)
7468                show-if-empty)
7469       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7470     gnus-newsgroup-limit))
7471
7472 (defun gnus-summary-limit-children (thread)
7473   "Return 1 if this subthread is visible and 0 if it is not."
7474   ;; First we get the number of visible children to this thread.  This
7475   ;; is done by recursing down the thread using this function, so this
7476   ;; will really go down to a leaf article first, before slowly
7477   ;; working its way up towards the root.
7478   (when thread
7479     (let ((children
7480            (if (cdr thread)
7481                (apply '+ (mapcar 'gnus-summary-limit-children
7482                                  (cdr thread)))
7483              0))
7484           (number (mail-header-number (car thread)))
7485           score)
7486       (if (and
7487            (not (memq number gnus-newsgroup-marked))
7488            (or
7489             ;; If this article is dormant and has absolutely no visible
7490             ;; children, then this article isn't visible.
7491             (and (memq number gnus-newsgroup-dormant)
7492                  (zerop children))
7493             ;; If this is "fetch-old-headered" and there is no
7494             ;; visible children, then we don't want this article.
7495             (and (or (eq gnus-fetch-old-headers 'some)
7496                      (numberp gnus-fetch-old-headers))
7497                  (gnus-summary-article-ancient-p number)
7498                  (zerop children))
7499             ;; If this is "fetch-old-headered" and `invisible', then
7500             ;; we don't want this article.
7501             (and (eq gnus-fetch-old-headers 'invisible)
7502                  (gnus-summary-article-ancient-p number))
7503             ;; If this is a sparsely inserted article with no children,
7504             ;; we don't want it.
7505             (and (eq gnus-build-sparse-threads 'some)
7506                  (gnus-summary-article-sparse-p number)
7507                  (zerop children))
7508             ;; If we use expunging, and this article is really
7509             ;; low-scored, then we don't want this article.
7510             (when (and gnus-summary-expunge-below
7511                        (< (setq score
7512                                 (or (cdr (assq number gnus-newsgroup-scored))
7513                                     gnus-summary-default-score))
7514                           gnus-summary-expunge-below))
7515               ;; We increase the expunge-tally here, but that has
7516               ;; nothing to do with the limits, really.
7517               (incf gnus-newsgroup-expunged-tally)
7518               ;; We also mark as read here, if that's wanted.
7519               (when (and gnus-summary-mark-below
7520                          (< score gnus-summary-mark-below))
7521                 (setq gnus-newsgroup-unreads
7522                       (delq number gnus-newsgroup-unreads))
7523                 (if gnus-newsgroup-auto-expire
7524                     (push number gnus-newsgroup-expirable)
7525                   (push (cons number gnus-low-score-mark)
7526                         gnus-newsgroup-reads)))
7527               t)
7528             ;; Do the `display' group parameter.
7529             (and gnus-newsgroup-display
7530                  (not (funcall gnus-newsgroup-display)))
7531             ;; Check NoCeM things.
7532             (if (and gnus-use-nocem
7533                      (gnus-nocem-unwanted-article-p
7534                       (mail-header-id (car thread))))
7535                 (progn
7536                   (setq gnus-newsgroup-unreads
7537                         (delq number gnus-newsgroup-unreads))
7538                   t))))
7539           ;; Nope, invisible article.
7540           0
7541         ;; Ok, this article is to be visible, so we add it to the limit
7542         ;; and return 1.
7543         (push number gnus-newsgroup-limit)
7544         1))))
7545
7546 (defun gnus-expunge-thread (thread)
7547   "Mark all articles in THREAD as read."
7548   (let* ((number (mail-header-number (car thread))))
7549     (incf gnus-newsgroup-expunged-tally)
7550     ;; We also mark as read here, if that's wanted.
7551     (setq gnus-newsgroup-unreads
7552           (delq number gnus-newsgroup-unreads))
7553     (if gnus-newsgroup-auto-expire
7554         (push number gnus-newsgroup-expirable)
7555       (push (cons number gnus-low-score-mark)
7556             gnus-newsgroup-reads)))
7557   ;; Go recursively through all subthreads.
7558   (mapcar 'gnus-expunge-thread (cdr thread)))
7559
7560 ;; Summary article oriented commands
7561
7562 (defun gnus-summary-refer-parent-article (n)
7563   "Refer parent article N times.
7564 If N is negative, go to ancestor -N instead.
7565 The difference between N and the number of articles fetched is returned."
7566   (interactive "p")
7567   (let ((skip 1)
7568         error header ref)
7569     (when (not (natnump n))
7570       (setq skip (abs n)
7571             n 1))
7572     (while (and (> n 0)
7573                 (not error))
7574       (setq header (gnus-summary-article-header))
7575       (if (and (eq (mail-header-number header)
7576                    (cdr gnus-article-current))
7577                (equal gnus-newsgroup-name
7578                       (car gnus-article-current)))
7579           ;; If we try to find the parent of the currently
7580           ;; displayed article, then we take a look at the actual
7581           ;; References header, since this is slightly more
7582           ;; reliable than the References field we got from the
7583           ;; server.
7584           (save-excursion
7585             (set-buffer gnus-original-article-buffer)
7586             (nnheader-narrow-to-headers)
7587             (unless (setq ref (message-fetch-field "references"))
7588               (setq ref (message-fetch-field "in-reply-to")))
7589             (widen))
7590         (setq ref
7591               ;; It's not the current article, so we take a bet on
7592               ;; the value we got from the server.
7593               (mail-header-references header)))
7594       (if (and ref
7595                (not (equal ref "")))
7596           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7597             (gnus-message 1 "Couldn't find parent"))
7598         (gnus-message 1 "No references in article %d"
7599                       (gnus-summary-article-number))
7600         (setq error t))
7601       (decf n))
7602     (gnus-summary-position-point)
7603     n))
7604
7605 (defun gnus-summary-refer-references ()
7606   "Fetch all articles mentioned in the References header.
7607 Return the number of articles fetched."
7608   (interactive)
7609   (let ((ref (mail-header-references (gnus-summary-article-header)))
7610         (current (gnus-summary-article-number))
7611         (n 0))
7612     (if (or (not ref)
7613             (equal ref ""))
7614         (error "No References in the current article")
7615       ;; For each Message-ID in the References header...
7616       (while (string-match "<[^>]*>" ref)
7617         (incf n)
7618         ;; ... fetch that article.
7619         (gnus-summary-refer-article
7620          (prog1 (match-string 0 ref)
7621            (setq ref (substring ref (match-end 0))))))
7622       (gnus-summary-goto-subject current)
7623       (gnus-summary-position-point)
7624       n)))
7625
7626 (defun gnus-summary-refer-thread (&optional limit)
7627   "Fetch all articles in the current thread.
7628 If LIMIT (the numerical prefix), fetch that many old headers instead
7629 of what's specified by the `gnus-refer-thread-limit' variable."
7630   (interactive "P")
7631   (let ((id (mail-header-id (gnus-summary-article-header)))
7632         (limit (if limit (prefix-numeric-value limit)
7633                  gnus-refer-thread-limit)))
7634     ;; We want to fetch LIMIT *old* headers, but we also have to
7635     ;; re-fetch all the headers in the current buffer, because many of
7636     ;; them may be undisplayed.  So we adjust LIMIT.
7637     (when (numberp limit)
7638       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7639     (unless (eq gnus-fetch-old-headers 'invisible)
7640       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7641       ;; Retrieve the headers and read them in.
7642       (if (eq (gnus-retrieve-headers
7643                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7644               'nov)
7645           (gnus-build-all-threads)
7646         (error "Can't fetch thread from backends that don't support NOV"))
7647       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7648     (gnus-summary-limit-include-thread id)))
7649
7650 (defun gnus-summary-refer-article (message-id)
7651   "Fetch an article specified by MESSAGE-ID."
7652   (interactive "sMessage-ID: ")
7653   (when (and (stringp message-id)
7654              (not (zerop (length message-id))))
7655     ;; Construct the correct Message-ID if necessary.
7656     ;; Suggested by tale@pawl.rpi.edu.
7657     (unless (string-match "^<" message-id)
7658       (setq message-id (concat "<" message-id)))
7659     (unless (string-match ">$" message-id)
7660       (setq message-id (concat message-id ">")))
7661     (let* ((header (gnus-id-to-header message-id))
7662            (sparse (and header
7663                         (gnus-summary-article-sparse-p
7664                          (mail-header-number header))
7665                         (memq (mail-header-number header)
7666                               gnus-newsgroup-limit)))
7667            number)
7668       (cond
7669        ;; If the article is present in the buffer we just go to it.
7670        ((and header
7671              (or (not (gnus-summary-article-sparse-p
7672                        (mail-header-number header)))
7673                  sparse))
7674         (prog1
7675             (gnus-summary-goto-article
7676              (mail-header-number header) nil t)
7677           (when sparse
7678             (gnus-summary-update-article (mail-header-number header)))))
7679        (t
7680         ;; We fetch the article.
7681         (catch 'found
7682           (dolist (gnus-override-method (gnus-refer-article-methods))
7683             (gnus-check-server gnus-override-method)
7684             ;; Fetch the header, and display the article.
7685             (when (setq number (gnus-summary-insert-subject message-id))
7686               (gnus-summary-select-article nil nil nil number)
7687               (throw 'found t)))
7688           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7689
7690 (defun gnus-refer-article-methods ()
7691   "Return a list of referrable methods."
7692   (cond
7693    ;; No method, so we default to current and native.
7694    ((null gnus-refer-article-method)
7695     (list gnus-current-select-method gnus-select-method))
7696    ;; Current.
7697    ((eq 'current gnus-refer-article-method)
7698     (list gnus-current-select-method))
7699    ;; List of select methods.
7700    ((not (and (symbolp (car gnus-refer-article-method))
7701               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7702     (let (out)
7703       (dolist (method gnus-refer-article-method)
7704         (push (if (eq 'current method)
7705                   gnus-current-select-method
7706                 method)
7707               out))
7708       (nreverse out)))
7709    ;; One single select method.
7710    (t
7711     (list gnus-refer-article-method))))
7712
7713 (defun gnus-summary-edit-parameters ()
7714   "Edit the group parameters of the current group."
7715   (interactive)
7716   (gnus-group-edit-group gnus-newsgroup-name 'params))
7717
7718 (defun gnus-summary-customize-parameters ()
7719   "Customize the group parameters of the current group."
7720   (interactive)
7721   (gnus-group-customize gnus-newsgroup-name))
7722
7723 (defun gnus-summary-enter-digest-group (&optional force)
7724   "Enter an nndoc group based on the current article.
7725 If FORCE, force a digest interpretation.  If not, try
7726 to guess what the document format is."
7727   (interactive "P")
7728   (let ((conf gnus-current-window-configuration))
7729     (save-excursion
7730       (gnus-summary-select-article))
7731     (setq gnus-current-window-configuration conf)
7732     (let* ((name (format "%s-%d"
7733                          (gnus-group-prefixed-name
7734                           gnus-newsgroup-name (list 'nndoc ""))
7735                          (save-excursion
7736                            (set-buffer gnus-summary-buffer)
7737                            gnus-current-article)))
7738            (ogroup gnus-newsgroup-name)
7739            (params (append (gnus-info-params (gnus-get-info ogroup))
7740                            (list (cons 'to-group ogroup))
7741                            (list (cons 'save-article-group ogroup))))
7742            (case-fold-search t)
7743            (buf (current-buffer))
7744            dig to-address)
7745       (save-excursion
7746         (set-buffer gnus-original-article-buffer)
7747         ;; Have the digest group inherit the main mail address of
7748         ;; the parent article.
7749         (when (setq to-address (or (message-fetch-field "reply-to")
7750                                    (message-fetch-field "from")))
7751           (setq params (append
7752                         (list (cons 'to-address
7753                                     (funcall gnus-decode-encoded-word-function
7754                                              to-address))))))
7755         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7756         (insert-buffer-substring gnus-original-article-buffer)
7757         ;; Remove lines that may lead nndoc to misinterpret the
7758         ;; document type.
7759         (narrow-to-region
7760          (goto-char (point-min))
7761          (or (search-forward "\n\n" nil t) (point)))
7762         (goto-char (point-min))
7763         (delete-matching-lines "^Path:\\|^From ")
7764         (widen))
7765       (unwind-protect
7766           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7767                     (gnus-newsgroup-ephemeral-ignored-charsets
7768                      gnus-newsgroup-ignored-charsets))
7769                 (gnus-group-read-ephemeral-group
7770                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7771                               (nndoc-article-type
7772                                ,(if force 'mbox 'guess)))
7773                  t nil nil nil
7774                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7775                                                         "ADAPT")))))
7776               ;; Make all postings to this group go to the parent group.
7777               (nconc (gnus-info-params (gnus-get-info name))
7778                      params)
7779             ;; Couldn't select this doc group.
7780             (switch-to-buffer buf)
7781             (gnus-set-global-variables)
7782             (gnus-configure-windows 'summary)
7783             (gnus-message 3 "Article couldn't be entered?"))
7784         (kill-buffer dig)))))
7785
7786 (defun gnus-summary-read-document (n)
7787   "Open a new group based on the current article(s).
7788 This will allow you to read digests and other similar
7789 documents as newsgroups.
7790 Obeys the standard process/prefix convention."
7791   (interactive "P")
7792   (let* ((articles (gnus-summary-work-articles n))
7793          (ogroup gnus-newsgroup-name)
7794          (params (append (gnus-info-params (gnus-get-info ogroup))
7795                          (list (cons 'to-group ogroup))))
7796          article group egroup groups vgroup)
7797     (while (setq article (pop articles))
7798       (setq group (format "%s-%d" gnus-newsgroup-name article))
7799       (gnus-summary-remove-process-mark article)
7800       (when (gnus-summary-display-article article)
7801         (save-excursion
7802           (with-temp-buffer
7803             (insert-buffer-substring gnus-original-article-buffer)
7804             ;; Remove some headers that may lead nndoc to make
7805             ;; the wrong guess.
7806             (message-narrow-to-head)
7807             (goto-char (point-min))
7808             (delete-matching-lines "^\\(Path\\):\\|^From ")
7809             (widen)
7810             (if (setq egroup
7811                       (gnus-group-read-ephemeral-group
7812                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7813                                      (nndoc-article-type guess))
7814                        t nil t))
7815                 (progn
7816                   ;; Make all postings to this group go to the parent group.
7817                   (nconc (gnus-info-params (gnus-get-info egroup))
7818                          params)
7819                   (push egroup groups))
7820               ;; Couldn't select this doc group.
7821               (gnus-error 3 "Article couldn't be entered"))))))
7822     ;; Now we have selected all the documents.
7823     (cond
7824      ((not groups)
7825       (error "None of the articles could be interpreted as documents"))
7826      ((gnus-group-read-ephemeral-group
7827        (setq vgroup (format
7828                      "nnvirtual:%s-%s" gnus-newsgroup-name
7829                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7830        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7831        t
7832        (cons (current-buffer) 'summary)))
7833      (t
7834       (error "Couldn't select virtual nndoc group")))))
7835
7836 (defun gnus-summary-isearch-article (&optional regexp-p)
7837   "Do incremental search forward on the current article.
7838 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7839   (interactive "P")
7840   (let* ((gnus-inhibit-treatment t)
7841          (old (gnus-summary-select-article)))
7842     (gnus-configure-windows 'article)
7843     (gnus-eval-in-buffer-window gnus-article-buffer
7844       (save-restriction
7845         (widen)
7846         (when (eq 'old old)
7847           (gnus-article-show-all-headers))
7848         (goto-char (point-min))
7849         (isearch-forward regexp-p)))))
7850
7851 (defun gnus-summary-search-article-forward (regexp &optional backward)
7852   "Search for an article containing REGEXP forward.
7853 If BACKWARD, search backward instead."
7854   (interactive
7855    (list (read-string
7856           (format "Search article %s (regexp%s): "
7857                   (if current-prefix-arg "backward" "forward")
7858                   (if gnus-last-search-regexp
7859                       (concat ", default " gnus-last-search-regexp)
7860                     "")))
7861          current-prefix-arg))
7862   (if (string-equal regexp "")
7863       (setq regexp (or gnus-last-search-regexp ""))
7864     (setq gnus-last-search-regexp regexp)
7865     (setq gnus-article-before-search gnus-current-article))
7866   ;; Intentionally set gnus-last-article.
7867   (setq gnus-last-article gnus-article-before-search)
7868   (let ((gnus-last-article gnus-last-article))
7869     (if (gnus-summary-search-article regexp backward)
7870         (gnus-summary-show-thread)
7871       (error "Search failed: \"%s\"" regexp))))
7872
7873 (defun gnus-summary-search-article-backward (regexp)
7874   "Search for an article containing REGEXP backward."
7875   (interactive
7876    (list (read-string
7877           (format "Search article backward (regexp%s): "
7878                   (if gnus-last-search-regexp
7879                       (concat ", default " gnus-last-search-regexp)
7880                     "")))))
7881   (gnus-summary-search-article-forward regexp 'backward))
7882
7883 (eval-when-compile
7884   (defmacro gnus-summary-search-article-position-point (regexp backward)
7885     "Dehighlight the last matched text and goto the beginning position."
7886     (` (if (and gnus-summary-search-article-matched-data
7887                 (let ((text (caddr gnus-summary-search-article-matched-data))
7888                       (inhibit-read-only t)
7889                       buffer-read-only)
7890                   (delete-region
7891                    (goto-char (car gnus-summary-search-article-matched-data))
7892                    (cadr gnus-summary-search-article-matched-data))
7893                   (insert text)
7894                   (string-match (, regexp) text)))
7895            (if (, backward) (beginning-of-line) (end-of-line))
7896          (goto-char (if (, backward) (point-max) (point-min))))))
7897
7898   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7899     "Place point where X-Face image is displayed."
7900     (if (featurep 'xemacs)
7901         (` (let ((end (if (search-forward "\n\n" nil t)
7902                           (goto-char (1- (point)))
7903                         (point-min)))
7904                  extent)
7905              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7906              (unless (and (re-search-forward "^From:" end t)
7907                           (setq extent (extent-at (point)))
7908                           (extent-begin-glyph extent))
7909                (goto-char (, opoint)))))
7910       (` (let ((end (if (search-forward "\n\n" nil t)
7911                         (goto-char (1- (point)))
7912                       (point-min)))
7913                (start (or (search-backward "\n\n" nil t) (point-min))))
7914            (goto-char
7915             (or (text-property-any start end 'x-face-image t);; x-face-e21
7916                 (text-property-any start end 'x-face-mule-bitmap-image t)
7917                 (, opoint)))))))
7918
7919   (defmacro gnus-summary-search-article-highlight-matched-text
7920     (backward treated x-face)
7921     "Highlight matched text in the function `gnus-summary-search-article'."
7922     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7923              (end (set-marker (make-marker) (match-end 0)))
7924              (inhibit-read-only t)
7925              buffer-read-only)
7926          (unless treated
7927            (let ((,@
7928                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7929                     (mapcar
7930                      (lambda (item) (setq items (delq item items)))
7931                      '(gnus-treat-buttonize
7932                        gnus-treat-fill-article
7933                        gnus-treat-fill-long-lines
7934                        gnus-treat-emphasize
7935                        gnus-treat-highlight-headers
7936                        gnus-treat-highlight-citation
7937                        gnus-treat-highlight-signature
7938                        gnus-treat-overstrike
7939                        gnus-treat-display-xface
7940                        gnus-treat-buttonize-head
7941                        gnus-treat-decode-article-as-default-mime-charset))
7942                     (static-if (featurep 'xemacs)
7943                         items
7944                       (cons '(x-face-mule-delete-x-face-field
7945                               (quote never))
7946                             items))))
7947                  (gnus-treat-display-xface
7948                   (when (, x-face) gnus-treat-display-xface)))
7949              (gnus-article-prepare-mime-display)))
7950          (goto-char (if (, backward) start end))
7951          (when (, x-face)
7952            (gnus-summary-search-article-highlight-goto-x-face (point)))
7953          (setq gnus-summary-search-article-matched-data
7954                (list start end (buffer-substring start end)))
7955          (unless (eq start end);; matched text has been deleted. :-<
7956            (put-text-property start end 'face
7957                               (or (find-face 'isearch)
7958                                   'secondary-selection))))))
7959   )
7960
7961 (defun gnus-summary-search-article (regexp &optional backward)
7962   "Search for an article containing REGEXP.
7963 Optional argument BACKWARD means do search for backward.
7964 `gnus-select-article-hook' is not called during the search."
7965   ;; We have to require this here to make sure that the following
7966   ;; dynamic binding isn't shadowed by autoloading.
7967   (require 'gnus-async)
7968   (require 'gnus-art)
7969   (let ((gnus-select-article-hook nil)  ;Disable hook.
7970         (gnus-article-prepare-hook nil)
7971         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7972         (gnus-use-article-prefetch nil)
7973         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7974         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7975         (sum (current-buffer))
7976         (found nil)
7977         point treated)
7978     (gnus-save-hidden-threads
7979       (static-if (featurep 'xemacs)
7980           (let ((gnus-inhibit-treatment t))
7981             (setq treated (eq 'old (gnus-summary-select-article)))
7982             (when (and treated
7983                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7984                                  (window-live-p (get-buffer-window
7985                                                  gnus-article-buffer t)))))
7986               (gnus-summary-select-article nil t)
7987               (setq treated nil)))
7988         (let ((gnus-inhibit-treatment t)
7989               (x-face-mule-delete-x-face-field 'never))
7990           (setq treated (eq 'old (gnus-summary-select-article)))
7991           (when (and treated
7992                      (not
7993                       (and (gnus-buffer-live-p gnus-article-buffer)
7994                            (window-live-p (get-buffer-window
7995                                            gnus-article-buffer t))
7996                            (or (not (string-match "^\\^X-Face:" regexp))
7997                                (with-current-buffer gnus-article-buffer
7998                                  gnus-summary-search-article-matched-data)))))
7999             (gnus-summary-select-article nil t)
8000             (setq treated nil))))
8001       (set-buffer gnus-article-buffer)
8002       (widen)
8003       (if treated
8004           (progn
8005             (gnus-article-show-all-headers)
8006             (gnus-summary-search-article-position-point regexp backward))
8007         (goto-char (if backward (point-max) (point-min))))
8008       (while (not found)
8009         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8010         (if (if backward
8011                 (re-search-backward regexp nil t)
8012               (re-search-forward regexp nil t))
8013             ;; We found the regexp.
8014             (progn
8015               (gnus-summary-search-article-highlight-matched-text
8016                backward treated (string-match "^\\^X-Face:" regexp))
8017               (setq found 'found)
8018               (forward-line
8019                (/ (- 2 (window-height
8020                         (get-buffer-window gnus-article-buffer t)))
8021                   2))
8022               (set-window-start
8023                (get-buffer-window (current-buffer))
8024                (point))
8025               (set-buffer sum)
8026               (setq point (point)))
8027           ;; We didn't find it, so we go to the next article.
8028           (set-buffer sum)
8029           (setq found 'not)
8030           (while (eq found 'not)
8031             (if (not (if backward (gnus-summary-find-prev)
8032                        (gnus-summary-find-next)))
8033                 ;; No more articles.
8034                 (setq found t)
8035               ;; Select the next article and adjust point.
8036               (unless (gnus-summary-article-sparse-p
8037                        (gnus-summary-article-number))
8038                 (setq found nil)
8039                 (let ((gnus-inhibit-treatment t))
8040                   (gnus-summary-select-article))
8041                 (setq treated nil)
8042                 (set-buffer gnus-article-buffer)
8043                 (widen)
8044                 (goto-char (if backward (point-max) (point-min))))))))
8045       (gnus-message 7 ""))
8046     ;; Return whether we found the regexp.
8047     (when (eq found 'found)
8048       (goto-char point)
8049       (gnus-summary-show-thread)
8050       (gnus-summary-goto-subject gnus-current-article)
8051       (gnus-summary-position-point)
8052       t)))
8053
8054 (defun gnus-find-matching-articles (header regexp)
8055   "Return a list of all articles that match REGEXP on HEADER.
8056 This search includes all articles in the current group that Gnus has
8057 fetched headers for, whether they are displayed or not."
8058   (let ((articles nil)
8059         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8060         (case-fold-search t))
8061     (dolist (header gnus-newsgroup-headers)
8062       (when (string-match regexp (funcall func header))
8063         (push (mail-header-number header) articles)))
8064     (nreverse articles)))
8065
8066 (defun gnus-summary-find-matching (header regexp &optional backward unread
8067                                           not-case-fold not-matching)
8068   "Return a list of all articles that match REGEXP on HEADER.
8069 The search stars on the current article and goes forwards unless
8070 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8071 If UNREAD is non-nil, only unread articles will
8072 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8073 in the comparisons. If NOT-MATCHING, return a list of all articles that
8074 not match REGEXP on HEADER."
8075   (let ((case-fold-search (not not-case-fold))
8076         articles d func)
8077     (if (consp header)
8078         (if (eq (car header) 'extra)
8079             (setq func
8080                   `(lambda (h)
8081                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8082                          "")))
8083           (error "%s is an invalid header" header))
8084       (unless (fboundp (intern (concat "mail-header-" header)))
8085         (error "%s is not a valid header" header))
8086       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8087     (dolist (d (if (eq backward 'all)
8088                    gnus-newsgroup-data
8089                  (gnus-data-find-list
8090                   (gnus-summary-article-number)
8091                   (gnus-data-list backward))))
8092       (when (and (or (not unread)       ; We want all articles...
8093                      (gnus-data-unread-p d)) ; Or just unreads.
8094                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8095                  (if not-matching
8096                      (not (string-match
8097                            regexp
8098                            (funcall func (gnus-data-header d))))
8099                    (string-match regexp
8100                                  (funcall func (gnus-data-header d)))))
8101         (push (gnus-data-number d) articles))) ; Success!
8102     (nreverse articles)))
8103
8104 (defun gnus-summary-execute-command (header regexp command &optional backward)
8105   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8106 If HEADER is an empty string (or nil), the match is done on the entire
8107 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8108   (interactive
8109    (list (let ((completion-ignore-case t))
8110            (completing-read
8111             "Header name: "
8112             (mapcar (lambda (header) (list (format "%s" header)))
8113                     (append
8114                      '("Number" "Subject" "From" "Lines" "Date"
8115                        "Message-ID" "Xref" "References" "Body")
8116                      gnus-extra-headers))
8117             nil 'require-match))
8118          (read-string "Regexp: ")
8119          (read-key-sequence "Command: ")
8120          current-prefix-arg))
8121   (when (equal header "Body")
8122     (setq header ""))
8123   ;; Hidden thread subtrees must be searched as well.
8124   (gnus-summary-show-all-threads)
8125   ;; We don't want to change current point nor window configuration.
8126   (save-excursion
8127     (save-window-excursion
8128       (gnus-message 6 "Executing %s..." (key-description command))
8129       ;; We'd like to execute COMMAND interactively so as to give arguments.
8130       (gnus-execute header regexp
8131                     `(call-interactively ',(key-binding command))
8132                     backward)
8133       (gnus-message 6 "Executing %s...done" (key-description command)))))
8134
8135 (defun gnus-summary-beginning-of-article ()
8136   "Scroll the article back to the beginning."
8137   (interactive)
8138   (gnus-summary-select-article)
8139   (gnus-configure-windows 'article)
8140   (gnus-eval-in-buffer-window gnus-article-buffer
8141     (widen)
8142     (goto-char (point-min))
8143     (when gnus-page-broken
8144       (gnus-narrow-to-page))))
8145
8146 (defun gnus-summary-end-of-article ()
8147   "Scroll to the end of the article."
8148   (interactive)
8149   (gnus-summary-select-article)
8150   (gnus-configure-windows 'article)
8151   (gnus-eval-in-buffer-window gnus-article-buffer
8152     (widen)
8153     (goto-char (point-max))
8154     (recenter -3)
8155     (when gnus-page-broken
8156       (gnus-narrow-to-page))))
8157
8158 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8159   "Truncate to LEN and quote all \"(\"'s in STRING."
8160   (gnus-replace-in-string (if (and len (> (length string) len))
8161                               (substring string 0 len)
8162                             string)
8163                           "[()]" "\\\\\\&"))
8164
8165 (defun gnus-summary-print-article (&optional filename n)
8166   "Generate and print a PostScript image of the N next (mail) articles.
8167
8168 If N is negative, print the N previous articles.  If N is nil and articles
8169 have been marked with the process mark, print these instead.
8170
8171 If the optional first argument FILENAME is nil, send the image to the
8172 printer.  If FILENAME is a string, save the PostScript image in a file with
8173 that name.  If FILENAME is a number, prompt the user for the name of the file
8174 to save in."
8175   (interactive (list (ps-print-preprint current-prefix-arg)))
8176   (dolist (article (gnus-summary-work-articles n))
8177     (gnus-summary-select-article nil nil 'pseudo article)
8178     (gnus-eval-in-buffer-window gnus-article-buffer
8179       (gnus-print-buffer))
8180     (gnus-summary-remove-process-mark article))
8181   (ps-despool filename))
8182
8183 (defun gnus-print-buffer ()
8184   (let ((buffer (generate-new-buffer " *print*")))
8185     (unwind-protect
8186         (progn
8187           (copy-to-buffer buffer (point-min) (point-max))
8188           (set-buffer buffer)
8189           (gnus-article-delete-invisible-text)
8190           (when (gnus-visual-p 'article-highlight 'highlight)
8191             ;; Copy-to-buffer doesn't copy overlay.  So redo
8192             ;; highlight.
8193             (let ((gnus-article-buffer buffer))
8194               (gnus-article-highlight-citation t)
8195               (gnus-article-highlight-signature)))
8196           (let ((ps-left-header
8197                  (list
8198                   (concat "("
8199                           (gnus-summary-print-truncate-and-quote
8200                            (mail-header-subject gnus-current-headers)
8201                            66) ")")
8202                   (concat "("
8203                           (gnus-summary-print-truncate-and-quote
8204                            (mail-header-from gnus-current-headers)
8205                            45) ")")))
8206                 (ps-right-header
8207                  (list
8208                   "/pagenumberstring load"
8209                   (concat "("
8210                           (mail-header-date gnus-current-headers) ")"))))
8211             (gnus-run-hooks 'gnus-ps-print-hook)
8212             (save-excursion
8213               (if window-system
8214                   (ps-spool-buffer-with-faces)
8215                 (ps-spool-buffer)))))
8216       (kill-buffer buffer))))
8217
8218 (defun gnus-summary-show-article (&optional arg)
8219   "Force redisplaying of the current article.
8220 If ARG (the prefix) is a number, show the article with the charset
8221 defined in `gnus-summary-show-article-charset-alist', or the charset
8222 input.
8223 If ARG (the prefix) is non-nil and not a number, show the raw article
8224 without any article massaging functions being run.  Normally, the key strokes
8225 are `C-u g'."
8226   (interactive "P")
8227   (cond
8228    ((numberp arg)
8229     (gnus-summary-show-article t)
8230     (let* ((gnus-newsgroup-charset
8231             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8232                 (mm-read-coding-system
8233                  "View as charset: " ;; actually it is coding system.
8234                  (save-excursion
8235                    (set-buffer gnus-article-buffer)
8236                    (mm-detect-coding-region (point) (point-max))))))
8237            (default-mime-charset gnus-newsgroup-charset)
8238            (gnus-newsgroup-ignored-charsets 'gnus-all))
8239       (gnus-summary-select-article nil 'force)
8240       (let ((deps gnus-newsgroup-dependencies)
8241             head header lines)
8242         (save-excursion
8243           (set-buffer gnus-original-article-buffer)
8244           (save-restriction
8245             (message-narrow-to-head)
8246             (setq head (buffer-string))
8247             (goto-char (point-min))
8248             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8249               (goto-char (point-max))
8250               (widen)
8251               (setq lines (1- (count-lines (point) (point-max))))))
8252           (with-temp-buffer
8253             (insert (format "211 %d Article retrieved.\n"
8254                             (cdr gnus-article-current)))
8255             (insert head)
8256             (if lines (insert (format "Lines: %d\n" lines)))
8257             (insert ".\n")
8258             (let ((nntp-server-buffer (current-buffer)))
8259               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8260         (gnus-data-set-header
8261          (gnus-data-find (cdr gnus-article-current))
8262          header)
8263         (gnus-summary-update-article-line
8264          (cdr gnus-article-current) header)
8265         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8266           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8267    ((not arg)
8268     ;; Select the article the normal way.
8269     (gnus-summary-select-article nil 'force))
8270    (t
8271     ;; We have to require this here to make sure that the following
8272     ;; dynamic binding isn't shadowed by autoloading.
8273     (require 'gnus-async)
8274     (require 'gnus-art)
8275     ;; Bind the article treatment functions to nil.
8276     (let ((gnus-have-all-headers t)
8277           gnus-article-prepare-hook
8278           gnus-article-decode-hook
8279           gnus-break-pages
8280           gnus-show-mime
8281           (gnus-inhibit-treatment t))
8282       (gnus-summary-select-article nil 'force))))
8283   (gnus-summary-goto-subject gnus-current-article)
8284   (gnus-summary-position-point))
8285
8286 (defun gnus-summary-show-raw-article ()
8287   "Show the raw article without any article massaging functions being run."
8288   (interactive)
8289   (gnus-summary-show-article t))
8290
8291 (defun gnus-summary-verbose-headers (&optional arg)
8292   "Toggle permanent full header display.
8293 If ARG is a positive number, turn header display on.
8294 If ARG is a negative number, turn header display off."
8295   (interactive "P")
8296   (setq gnus-show-all-headers
8297         (cond ((or (not (numberp arg))
8298                    (zerop arg))
8299                (not gnus-show-all-headers))
8300               ((natnump arg)
8301                t)))
8302   (gnus-summary-show-article))
8303
8304 (defun gnus-summary-toggle-header (&optional arg)
8305   "Show the headers if they are hidden, or hide them if they are shown.
8306 If ARG is a positive number, show the entire header.
8307 If ARG is a negative number, hide the unwanted header lines."
8308   (interactive "P")
8309   (save-excursion
8310     (set-buffer gnus-article-buffer)
8311     (save-restriction
8312       (let* ((buffer-read-only nil)
8313              (inhibit-point-motion-hooks t)
8314              hidden e)
8315         (save-restriction
8316           (article-narrow-to-head)
8317           (setq e (point-max)
8318                 hidden (if (numberp arg)
8319                            (>= arg 0)
8320                          (gnus-article-hidden-text-p 'headers))))
8321         (delete-region (point-min) e)
8322         (goto-char (point-min))
8323         (save-excursion
8324           (set-buffer gnus-original-article-buffer)
8325           (goto-char (point-min))
8326           (setq e (search-forward "\n\n" nil t)
8327                 e (if e (1- e) (point-max))))
8328         (insert-buffer-substring gnus-original-article-buffer 1 e)
8329         (save-restriction
8330           (narrow-to-region (point-min) (point))
8331           (article-decode-encoded-words)
8332           (if  hidden
8333               (let ((gnus-treat-hide-headers nil)
8334                     (gnus-treat-hide-boring-headers nil))
8335                 (gnus-delete-wash-type 'headers)
8336                 (gnus-treat-article 'head))
8337             (gnus-treat-article 'head)))
8338         (gnus-set-mode-line 'article)))))
8339
8340 (defun gnus-summary-show-all-headers ()
8341   "Make all header lines visible."
8342   (interactive)
8343   (gnus-summary-toggle-header 1))
8344
8345 (defun gnus-summary-toggle-mime (&optional arg)
8346   "Toggle MIME processing.
8347 If ARG is a positive number, turn MIME processing on."
8348   (interactive "P")
8349   (setq gnus-show-mime
8350         (if (null arg)
8351             (not gnus-show-mime)
8352           (> (prefix-numeric-value arg) 0)))
8353   (gnus-summary-select-article t 'force))
8354
8355 (defun gnus-summary-caesar-message (&optional arg)
8356   "Caesar rotate the current article by 13.
8357 The numerical prefix specifies how many places to rotate each letter
8358 forward."
8359   (interactive "P")
8360   (gnus-summary-select-article)
8361   (let ((mail-header-separator ""))
8362     (gnus-eval-in-buffer-window gnus-article-buffer
8363       (save-restriction
8364         (widen)
8365         (let ((start (window-start))
8366               buffer-read-only)
8367           (message-caesar-buffer-body arg)
8368           (set-window-start (get-buffer-window (current-buffer)) start))))))
8369
8370 (defun gnus-summary-stop-page-breaking ()
8371   "Stop page breaking in the current article."
8372   (interactive)
8373   (gnus-summary-select-article)
8374   (gnus-eval-in-buffer-window gnus-article-buffer
8375     (widen)
8376     (when (gnus-visual-p 'page-marker)
8377       (let ((buffer-read-only nil))
8378         (gnus-remove-text-with-property 'gnus-prev)
8379         (gnus-remove-text-with-property 'gnus-next))
8380       (setq gnus-page-broken nil))))
8381
8382 (defun gnus-summary-move-article (&optional n to-newsgroup
8383                                             select-method action)
8384   "Move the current article to a different newsgroup.
8385 If N is a positive number, move the N next articles.
8386 If N is a negative number, move the N previous articles.
8387 If N is nil and any articles have been marked with the process mark,
8388 move those articles instead.
8389 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8390 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8391 re-spool using this method.
8392
8393 For this function to work, both the current newsgroup and the
8394 newsgroup that you want to move to have to support the `request-move'
8395 and `request-accept' functions.
8396
8397 ACTION can be either `move' (the default), `crosspost' or `copy'."
8398   (interactive "P")
8399   (unless action
8400     (setq action 'move))
8401   ;; Check whether the source group supports the required functions.
8402   (cond ((and (eq action 'move)
8403               (not (gnus-check-backend-function
8404                     'request-move-article gnus-newsgroup-name)))
8405          (error "The current group does not support article moving"))
8406         ((and (eq action 'crosspost)
8407               (not (gnus-check-backend-function
8408                     'request-replace-article gnus-newsgroup-name)))
8409          (error "The current group does not support article editing")))
8410   (let ((articles (gnus-summary-work-articles n))
8411         (prefix (if (gnus-check-backend-function
8412                      'request-move-article gnus-newsgroup-name)
8413                     (gnus-group-real-prefix gnus-newsgroup-name)
8414                   ""))
8415         (names '((move "Move" "Moving")
8416                  (copy "Copy" "Copying")
8417                  (crosspost "Crosspost" "Crossposting")))
8418         (copy-buf (save-excursion
8419                     (nnheader-set-temp-buffer " *copy article*")))
8420         (default-marks gnus-article-mark-lists)
8421         (no-expire-marks (delete '(expirable . expire)
8422                                  (copy-sequence gnus-article-mark-lists)))
8423         art-group to-method new-xref article to-groups)
8424     (unless (assq action names)
8425       (error "Unknown action %s" action))
8426     ;; Read the newsgroup name.
8427     (when (and (not to-newsgroup)
8428                (not select-method))
8429       (if (and gnus-move-split-methods
8430                (not
8431                 (and (memq gnus-current-article articles)
8432                      (gnus-buffer-live-p gnus-original-article-buffer))))
8433           ;; When `gnus-move-split-methods' is non-nil, we have to
8434           ;; select an article to give `gnus-read-move-group-name' an
8435           ;; opportunity to suggest an appropriate default.  However,
8436           ;; we needn't render or mark the article.
8437           (let ((gnus-display-mime-function nil)
8438                 (gnus-article-prepare-hook nil)
8439                 (gnus-mark-article-hook nil))
8440             (gnus-summary-select-article nil nil nil (car articles))))
8441       (setq to-newsgroup
8442             (gnus-read-move-group-name
8443              (cadr (assq action names))
8444              (symbol-value (intern (format "gnus-current-%s-group" action)))
8445              articles prefix))
8446       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8447     (setq to-method (or select-method
8448                         (gnus-server-to-method
8449                          (gnus-group-method to-newsgroup))))
8450     ;; Check the method we are to move this article to...
8451     (unless (gnus-check-backend-function
8452              'request-accept-article (car to-method))
8453       (error "%s does not support article copying" (car to-method)))
8454     (unless (gnus-check-server to-method)
8455       (error "Can't open server %s" (car to-method)))
8456     (gnus-message 6 "%s to %s: %s..."
8457                   (caddr (assq action names))
8458                   (or (car select-method) to-newsgroup) articles)
8459     (while articles
8460       (setq article (pop articles))
8461       (setq
8462        art-group
8463        (cond
8464         ;; Move the article.
8465         ((eq action 'move)
8466          ;; Remove this article from future suppression.
8467          (gnus-dup-unsuppress-article article)
8468          (gnus-request-move-article
8469           article                       ; Article to move
8470           gnus-newsgroup-name           ; From newsgroup
8471           (nth 1 (gnus-find-method-for-group
8472                   gnus-newsgroup-name)) ; Server
8473           (list 'gnus-request-accept-article
8474                 to-newsgroup (list 'quote select-method)
8475                 (not articles) t)       ; Accept form
8476           (not articles)))              ; Only save nov last time
8477         ;; Copy the article.
8478         ((eq action 'copy)
8479          (save-excursion
8480            (set-buffer copy-buf)
8481            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8482              (gnus-request-accept-article
8483               to-newsgroup select-method (not articles) t))))
8484         ;; Crosspost the article.
8485         ((eq action 'crosspost)
8486          (let ((xref (message-tokenize-header
8487                       (mail-header-xref (gnus-summary-article-header article))
8488                       " ")))
8489            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8490                                   ":" (number-to-string article)))
8491            (unless xref
8492              (setq xref (list (system-name))))
8493            (setq new-xref
8494                  (concat
8495                   (mapconcat 'identity
8496                              (delete "Xref:" (delete new-xref xref))
8497                              " ")
8498                   " " new-xref))
8499            (save-excursion
8500              (set-buffer copy-buf)
8501              ;; First put the article in the destination group.
8502              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8503              (when (consp (setq art-group
8504                                 (gnus-request-accept-article
8505                                  to-newsgroup select-method (not articles))))
8506                (setq new-xref (concat new-xref " " (car art-group)
8507                                       ":"
8508                                       (number-to-string (cdr art-group))))
8509                ;; Now we have the new Xrefs header, so we insert
8510                ;; it and replace the new article.
8511                (nnheader-replace-header "Xref" new-xref)
8512                (gnus-request-replace-article
8513                 (cdr art-group) to-newsgroup (current-buffer))
8514                art-group))))))
8515       (cond
8516        ((not art-group)
8517         (gnus-message 1 "Couldn't %s article %s: %s"
8518                       (cadr (assq action names)) article
8519                       (nnheader-get-report (car to-method))))
8520        ((eq art-group 'junk)
8521         (when (eq action 'move)
8522           (gnus-summary-mark-article article gnus-canceled-mark)
8523           (gnus-message 4 "Deleted article %s" article)))
8524        (t
8525         (let* ((pto-group (gnus-group-prefixed-name
8526                            (car art-group) to-method))
8527                (entry
8528                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8529                (info (nth 2 entry))
8530                (to-group (gnus-info-group info))
8531                to-marks)
8532           ;; Update the group that has been moved to.
8533           (when (and info
8534                      (memq action '(move copy)))
8535             (unless (member to-group to-groups)
8536               (push to-group to-groups))
8537
8538             (unless (memq article gnus-newsgroup-unreads)
8539               (push 'read to-marks)
8540               (gnus-info-set-read
8541                info (gnus-add-to-range (gnus-info-read info)
8542                                        (list (cdr art-group)))))
8543
8544             ;; See whether the article is to be put in the cache.
8545             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8546                              default-marks
8547                            no-expire-marks))
8548                   (to-article (cdr art-group)))
8549
8550               ;; Enter the article into the cache in the new group,
8551               ;; if that is required.
8552               (when gnus-use-cache
8553                 (gnus-cache-possibly-enter-article
8554                  to-group to-article
8555                  (let ((header (copy-sequence
8556                                 (gnus-summary-article-header article))))
8557                    (mail-header-set-number header to-article)
8558                    header)
8559                  (memq article gnus-newsgroup-marked)
8560                  (memq article gnus-newsgroup-dormant)
8561                  (memq article gnus-newsgroup-unreads)))
8562
8563               (when gnus-preserve-marks
8564                 ;; Copy any marks over to the new group.
8565                 (when (and (equal to-group gnus-newsgroup-name)
8566                            (not (memq article gnus-newsgroup-unreads)))
8567                   ;; Mark this article as read in this group.
8568                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8569                   (setcdr (gnus-active to-group) to-article)
8570                   (setcdr gnus-newsgroup-active to-article))
8571
8572                 (while marks
8573                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8574                     (when (memq article (symbol-value
8575                                          (intern (format "gnus-newsgroup-%s"
8576                                                          (caar marks)))))
8577                       (push (cdar marks) to-marks)
8578                       ;; If the other group is the same as this group,
8579                       ;; then we have to add the mark to the list.
8580                       (when (equal to-group gnus-newsgroup-name)
8581                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8582                              (cons to-article
8583                                    (symbol-value
8584                                     (intern (format "gnus-newsgroup-%s"
8585                                                     (caar marks)))))))
8586                       ;; Copy the marks to other group.
8587                       (gnus-add-marked-articles
8588                        to-group (cdar marks) (list to-article) info)))
8589                   (setq marks (cdr marks)))
8590
8591                 (gnus-request-set-mark to-group (list (list (list to-article)
8592                                                             'add
8593                                                             to-marks))))
8594
8595               (gnus-dribble-enter
8596                (concat "(gnus-group-set-info '"
8597                        (gnus-prin1-to-string (gnus-get-info to-group))
8598                        ")"))))
8599
8600           ;; Update the Xref header in this article to point to
8601           ;; the new crossposted article we have just created.
8602           (when (eq action 'crosspost)
8603             (save-excursion
8604               (set-buffer copy-buf)
8605               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8606               (nnheader-replace-header "Xref" new-xref)
8607               (gnus-request-replace-article
8608                article gnus-newsgroup-name (current-buffer)))))
8609
8610         ;;;!!!Why is this necessary?
8611         (set-buffer gnus-summary-buffer)
8612
8613         (gnus-summary-goto-subject article)
8614         (when (eq action 'move)
8615           (gnus-summary-mark-article article gnus-canceled-mark))))
8616       (gnus-summary-remove-process-mark article))
8617     ;; Re-activate all groups that have been moved to.
8618     (save-excursion
8619       (set-buffer gnus-group-buffer)
8620       (let ((gnus-group-marked to-groups))
8621         (gnus-group-get-new-news-this-group nil t)))
8622
8623     (gnus-kill-buffer copy-buf)
8624     (gnus-summary-position-point)
8625     (gnus-set-mode-line 'summary)))
8626
8627 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8628   "Move the current article to a different newsgroup.
8629 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8630 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8631 re-spool using this method."
8632   (interactive "P")
8633   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8634
8635 (defun gnus-summary-crosspost-article (&optional n)
8636   "Crosspost the current article to some other group."
8637   (interactive "P")
8638   (gnus-summary-move-article n nil nil 'crosspost))
8639
8640 (defcustom gnus-summary-respool-default-method nil
8641   "Default method type for respooling an article.
8642 If nil, use to the current newsgroup method."
8643   :type 'symbol
8644   :group 'gnus-summary-mail)
8645
8646 (defun gnus-summary-respool-article (&optional n method)
8647   "Respool the current article.
8648 The article will be squeezed through the mail spooling process again,
8649 which means that it will be put in some mail newsgroup or other
8650 depending on `nnmail-split-methods'.
8651 If N is a positive number, respool the N next articles.
8652 If N is a negative number, respool the N previous articles.
8653 If N is nil and any articles have been marked with the process mark,
8654 respool those articles instead.
8655
8656 Respooling can be done both from mail groups and \"real\" newsgroups.
8657 In the former case, the articles in question will be moved from the
8658 current group into whatever groups they are destined to.  In the
8659 latter case, they will be copied into the relevant groups."
8660   (interactive
8661    (list current-prefix-arg
8662          (let* ((methods (gnus-methods-using 'respool))
8663                 (methname
8664                  (symbol-name (or gnus-summary-respool-default-method
8665                                   (car (gnus-find-method-for-group
8666                                         gnus-newsgroup-name)))))
8667                 (method
8668                  (gnus-completing-read-with-default
8669                   methname "What backend do you want to use when respooling?"
8670                   methods nil t nil 'gnus-mail-method-history))
8671                 ms)
8672            (cond
8673             ((zerop (length (setq ms (gnus-servers-using-backend
8674                                       (intern method)))))
8675              (list (intern method) ""))
8676             ((= 1 (length ms))
8677              (car ms))
8678             (t
8679              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8680                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8681                            ms-alist))))))))
8682   (unless method
8683     (error "No method given for respooling"))
8684   (if (assoc (symbol-name
8685               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8686              (gnus-methods-using 'respool))
8687       (gnus-summary-move-article n nil method)
8688     (gnus-summary-copy-article n nil method)))
8689
8690 (defun gnus-summary-import-article (file &optional edit)
8691   "Import an arbitrary file into a mail newsgroup."
8692   (interactive "fImport file: \nP")
8693   (let ((group gnus-newsgroup-name)
8694         (now (current-time))
8695         atts lines group-art)
8696     (unless (gnus-check-backend-function 'request-accept-article group)
8697       (error "%s does not support article importing" group))
8698     (or (file-readable-p file)
8699         (not (file-regular-p file))
8700         (error "Can't read %s" file))
8701     (save-excursion
8702       (set-buffer (gnus-get-buffer-create " *import file*"))
8703       (erase-buffer)
8704       (nnheader-insert-file-contents file)
8705       (goto-char (point-min))
8706       (if (nnheader-article-p)
8707           (save-restriction
8708             (goto-char (point-min))
8709             (search-forward "\n\n" nil t)
8710             (narrow-to-region (point-min) (1- (point)))
8711             (goto-char (point-min))
8712             (unless (re-search-forward "^date:" nil t)
8713               (goto-char (point-max))
8714               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8715         ;; This doesn't look like an article, so we fudge some headers.
8716         (setq atts (file-attributes file)
8717               lines (count-lines (point-min) (point-max)))
8718         (insert "From: " (read-string "From: ") "\n"
8719                 "Subject: " (read-string "Subject: ") "\n"
8720                 "Date: " (message-make-date (nth 5 atts)) "\n"
8721                 "Message-ID: " (message-make-message-id) "\n"
8722                 "Lines: " (int-to-string lines) "\n"
8723                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8724       (setq group-art (gnus-request-accept-article group nil t))
8725       (kill-buffer (current-buffer)))
8726     (setq gnus-newsgroup-active (gnus-activate-group group))
8727     (forward-line 1)
8728     (gnus-summary-goto-article (cdr group-art) nil t)
8729     (when edit
8730       (gnus-summary-edit-article))))
8731
8732 (defun gnus-summary-create-article ()
8733   "Create an article in a mail newsgroup."
8734   (interactive)
8735   (let ((group gnus-newsgroup-name)
8736         (now (current-time))
8737         group-art)
8738     (unless (gnus-check-backend-function 'request-accept-article group)
8739       (error "%s does not support article importing" group))
8740     (save-excursion
8741       (set-buffer (gnus-get-buffer-create " *import file*"))
8742       (erase-buffer)
8743       (goto-char (point-min))
8744       ;; This doesn't look like an article, so we fudge some headers.
8745       (insert "From: " (read-string "From: ") "\n"
8746               "Subject: " (read-string "Subject: ") "\n"
8747               "Date: " (message-make-date now) "\n"
8748               "Message-ID: " (message-make-message-id) "\n")
8749       (setq group-art (gnus-request-accept-article group nil t))
8750       (kill-buffer (current-buffer)))
8751     (setq gnus-newsgroup-active (gnus-activate-group group))
8752     (forward-line 1)
8753     (gnus-summary-goto-article (cdr group-art) nil t)
8754     (gnus-summary-edit-article)))
8755
8756 (defun gnus-summary-article-posted-p ()
8757   "Say whether the current (mail) article is available from news as well.
8758 This will be the case if the article has both been mailed and posted."
8759   (interactive)
8760   (let ((id (mail-header-references (gnus-summary-article-header)))
8761         (gnus-override-method (car (gnus-refer-article-methods))))
8762     (if (gnus-request-head id "")
8763         (gnus-message 2 "The current message was found on %s"
8764                       gnus-override-method)
8765       (gnus-message 2 "The current message couldn't be found on %s"
8766                     gnus-override-method)
8767       nil)))
8768
8769 (defun gnus-summary-expire-articles (&optional now)
8770   "Expire all articles that are marked as expirable in the current group."
8771   (interactive)
8772   (when (gnus-check-backend-function
8773          'request-expire-articles gnus-newsgroup-name)
8774     ;; This backend supports expiry.
8775     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8776            (expirable (if total
8777                           (progn
8778                             ;; We need to update the info for
8779                             ;; this group for `gnus-list-of-read-articles'
8780                             ;; to give us the right answer.
8781                             (gnus-run-hooks 'gnus-exit-group-hook)
8782                             (gnus-summary-update-info)
8783                             (gnus-list-of-read-articles gnus-newsgroup-name))
8784                         (setq gnus-newsgroup-expirable
8785                               (sort gnus-newsgroup-expirable '<))))
8786            (expiry-wait (if now 'immediate
8787                           (gnus-group-find-parameter
8788                            gnus-newsgroup-name 'expiry-wait)))
8789            (nnmail-expiry-target
8790             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8791                 nnmail-expiry-target))
8792            es)
8793       (when expirable
8794         ;; There are expirable articles in this group, so we run them
8795         ;; through the expiry process.
8796         (gnus-message 6 "Expiring articles...")
8797         (unless (gnus-check-group gnus-newsgroup-name)
8798           (error "Can't open server for %s" gnus-newsgroup-name))
8799         ;; The list of articles that weren't expired is returned.
8800         (save-excursion
8801           (if expiry-wait
8802               (let ((nnmail-expiry-wait-function nil)
8803                     (nnmail-expiry-wait expiry-wait))
8804                 (setq es (gnus-request-expire-articles
8805                           expirable gnus-newsgroup-name)))
8806             (setq es (gnus-request-expire-articles
8807                       expirable gnus-newsgroup-name)))
8808           (unless total
8809             (setq gnus-newsgroup-expirable es))
8810           ;; We go through the old list of expirable, and mark all
8811           ;; really expired articles as nonexistent.
8812           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8813             (let ((gnus-use-cache nil))
8814               (dolist (article expirable)
8815                 (when (and (not (memq article es))
8816                            (gnus-data-find article))
8817                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8818         (gnus-message 6 "Expiring articles...done")))))
8819
8820 (defun gnus-summary-expire-articles-now ()
8821   "Expunge all expirable articles in the current group.
8822 This means that *all* articles that are marked as expirable will be
8823 deleted forever, right now."
8824   (interactive)
8825   (or gnus-expert-user
8826       (gnus-yes-or-no-p
8827        "Are you really, really, really sure you want to delete all these messages? ")
8828       (error "Phew!"))
8829   (gnus-summary-expire-articles t))
8830
8831 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8832 (defun gnus-summary-delete-article (&optional n)
8833   "Delete the N next (mail) articles.
8834 This command actually deletes articles.  This is not a marking
8835 command.  The article will disappear forever from your life, never to
8836 return.
8837 If N is negative, delete backwards.
8838 If N is nil and articles have been marked with the process mark,
8839 delete these instead."
8840   (interactive "P")
8841   (unless (gnus-check-backend-function 'request-expire-articles
8842                                        gnus-newsgroup-name)
8843     (error "The current newsgroup does not support article deletion"))
8844   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8845     (error "Couldn't open server"))
8846   ;; Compute the list of articles to delete.
8847   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8848         not-deleted)
8849     (if (and gnus-novice-user
8850              (not (gnus-yes-or-no-p
8851                    (format "Do you really want to delete %s forever? "
8852                            (if (> (length articles) 1)
8853                                (format "these %s articles" (length articles))
8854                              "this article")))))
8855         ()
8856       ;; Delete the articles.
8857       (setq not-deleted (gnus-request-expire-articles
8858                          articles gnus-newsgroup-name 'force))
8859       (while articles
8860         (gnus-summary-remove-process-mark (car articles))
8861         ;; The backend might not have been able to delete the article
8862         ;; after all.
8863         (unless (memq (car articles) not-deleted)
8864           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8865         (setq articles (cdr articles)))
8866       (when not-deleted
8867         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8868     (gnus-summary-position-point)
8869     (gnus-set-mode-line 'summary)
8870     not-deleted))
8871
8872 (defun gnus-summary-edit-article (&optional force)
8873   "Edit the current article.
8874 This will have permanent effect only in mail groups.
8875 If FORCE is non-nil, allow editing of articles even in read-only
8876 groups."
8877   (interactive "P")
8878   (save-excursion
8879     (set-buffer gnus-summary-buffer)
8880     (let ((mail-parse-charset gnus-newsgroup-charset)
8881           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8882       (gnus-set-global-variables)
8883       (when (and (not force)
8884                  (gnus-group-read-only-p))
8885         (error "The current newsgroup does not support article editing"))
8886       (gnus-summary-show-article t)
8887       (gnus-article-edit-article
8888        'ignore
8889        `(lambda (no-highlight)
8890           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8891                 (message-options message-options)
8892                 (message-options-set-recipient)
8893                 (mail-parse-ignored-charsets
8894                  ',gnus-newsgroup-ignored-charsets))
8895             (gnus-summary-edit-article-done
8896              ,(or (mail-header-references gnus-current-headers) "")
8897              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8898
8899 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8900
8901 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8902                                                  no-highlight)
8903   "Make edits to the current article permanent."
8904   (interactive)
8905   (save-excursion
8906     ;; The buffer restriction contains the entire article if it exists.
8907     (when (article-goto-body)
8908       (let ((lines (count-lines (point) (point-max)))
8909             (length (- (point-max) (point)))
8910             (case-fold-search t)
8911             (body (copy-marker (point))))
8912         (goto-char (point-min))
8913         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8914           (delete-region (match-beginning 1) (match-end 1))
8915           (insert (number-to-string length)))
8916         (goto-char (point-min))
8917         (when (re-search-forward
8918                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8919           (delete-region (match-beginning 1) (match-end 1))
8920           (insert (number-to-string length)))
8921         (goto-char (point-min))
8922         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8923           (delete-region (match-beginning 1) (match-end 1))
8924           (insert (number-to-string lines))))))
8925   ;; Replace the article.
8926   (let ((buf (current-buffer)))
8927     (with-temp-buffer
8928       (insert-buffer-substring buf)
8929
8930       (if (and (not read-only)
8931                (not (gnus-request-replace-article
8932                      (cdr gnus-article-current) (car gnus-article-current)
8933                      (current-buffer) t)))
8934           (error "Couldn't replace article")
8935         ;; Update the summary buffer.
8936         (if (and references
8937                  (equal (message-tokenize-header references " ")
8938                         (message-tokenize-header
8939                          (or (message-fetch-field "references") "") " ")))
8940             ;; We only have to update this line.
8941             (save-excursion
8942               (save-restriction
8943                 (message-narrow-to-head)
8944                 (let ((head (buffer-string))
8945                       header)
8946                   (with-temp-buffer
8947                     (insert (format "211 %d Article retrieved.\n"
8948                                     (cdr gnus-article-current)))
8949                     (insert head)
8950                     (insert ".\n")
8951                     (let ((nntp-server-buffer (current-buffer)))
8952                       (setq header (car (gnus-get-newsgroup-headers
8953                                          (save-excursion
8954                                            (set-buffer gnus-summary-buffer)
8955                                            gnus-newsgroup-dependencies)
8956                                          t))))
8957                     (save-excursion
8958                       (set-buffer gnus-summary-buffer)
8959                       (gnus-data-set-header
8960                        (gnus-data-find (cdr gnus-article-current))
8961                        header)
8962                       (gnus-summary-update-article-line
8963                        (cdr gnus-article-current) header)
8964                       (if (gnus-summary-goto-subject
8965                            (cdr gnus-article-current) nil t)
8966                           (gnus-summary-update-secondary-mark
8967                            (cdr gnus-article-current))))))))
8968           ;; Update threads.
8969           (set-buffer (or buffer gnus-summary-buffer))
8970           (gnus-summary-update-article (cdr gnus-article-current))
8971           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8972               (gnus-summary-update-secondary-mark
8973                (cdr gnus-article-current))))
8974         ;; Prettify the article buffer again.
8975         (unless no-highlight
8976           (save-excursion
8977             (set-buffer gnus-article-buffer)
8978             ;;;!!! Fix this -- article should be rehighlighted.
8979             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8980             (set-buffer gnus-original-article-buffer)
8981             (gnus-request-article
8982              (cdr gnus-article-current)
8983              (car gnus-article-current) (current-buffer))))
8984         ;; Prettify the summary buffer line.
8985         (when (gnus-visual-p 'summary-highlight 'highlight)
8986           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8987
8988 (defun gnus-summary-edit-wash (key)
8989   "Perform editing command KEY in the article buffer."
8990   (interactive
8991    (list
8992     (progn
8993       (message "%s" (concat (this-command-keys) "- "))
8994       (read-char))))
8995   (message "")
8996   (gnus-summary-edit-article)
8997   (execute-kbd-macro (concat (this-command-keys) key))
8998   (gnus-article-edit-done))
8999
9000 ;;; Respooling
9001
9002 (defun gnus-summary-respool-query (&optional silent trace)
9003   "Query where the respool algorithm would put this article."
9004   (interactive)
9005   (let (gnus-mark-article-hook)
9006     (gnus-summary-select-article)
9007     (save-excursion
9008       (set-buffer gnus-original-article-buffer)
9009       (save-restriction
9010         (message-narrow-to-head)
9011         (let ((groups (nnmail-article-group 'identity trace)))
9012           (unless silent
9013             (if groups
9014                 (message "This message would go to %s"
9015                          (mapconcat 'car groups ", "))
9016               (message "This message would go to no groups"))
9017             groups))))))
9018
9019 (defun gnus-summary-respool-trace ()
9020   "Trace where the respool algorithm would put this article.
9021 Display a buffer showing all fancy splitting patterns which matched."
9022   (interactive)
9023   (gnus-summary-respool-query nil t))
9024
9025 ;; Summary marking commands.
9026
9027 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9028   "Mark articles which has the same subject as read, and then select the next.
9029 If UNMARK is positive, remove any kind of mark.
9030 If UNMARK is negative, tick articles."
9031   (interactive "P")
9032   (when unmark
9033     (setq unmark (prefix-numeric-value unmark)))
9034   (let ((count
9035          (gnus-summary-mark-same-subject
9036           (gnus-summary-article-subject) unmark)))
9037     ;; Select next unread article.  If auto-select-same mode, should
9038     ;; select the first unread article.
9039     (gnus-summary-next-article t (and gnus-auto-select-same
9040                                       (gnus-summary-article-subject)))
9041     (gnus-message 7 "%d article%s marked as %s"
9042                   count (if (= count 1) " is" "s are")
9043                   (if unmark "unread" "read"))))
9044
9045 (defun gnus-summary-kill-same-subject (&optional unmark)
9046   "Mark articles which has the same subject as read.
9047 If UNMARK is positive, remove any kind of mark.
9048 If UNMARK is negative, tick articles."
9049   (interactive "P")
9050   (when unmark
9051     (setq unmark (prefix-numeric-value unmark)))
9052   (let ((count
9053          (gnus-summary-mark-same-subject
9054           (gnus-summary-article-subject) unmark)))
9055     ;; If marked as read, go to next unread subject.
9056     (when (null unmark)
9057       ;; Go to next unread subject.
9058       (gnus-summary-next-subject 1 t))
9059     (gnus-message 7 "%d articles are marked as %s"
9060                   count (if unmark "unread" "read"))))
9061
9062 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9063   "Mark articles with same SUBJECT as read, and return marked number.
9064 If optional argument UNMARK is positive, remove any kinds of marks.
9065 If optional argument UNMARK is negative, mark articles as unread instead."
9066   (let ((count 1))
9067     (save-excursion
9068       (cond
9069        ((null unmark)                   ; Mark as read.
9070         (while (and
9071                 (progn
9072                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9073                   (gnus-summary-show-thread) t)
9074                 (gnus-summary-find-subject subject))
9075           (setq count (1+ count))))
9076        ((> unmark 0)                    ; Tick.
9077         (while (and
9078                 (progn
9079                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9080                   (gnus-summary-show-thread) t)
9081                 (gnus-summary-find-subject subject))
9082           (setq count (1+ count))))
9083        (t                               ; Mark as unread.
9084         (while (and
9085                 (progn
9086                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9087                   (gnus-summary-show-thread) t)
9088                 (gnus-summary-find-subject subject))
9089           (setq count (1+ count)))))
9090       (gnus-set-mode-line 'summary)
9091       ;; Return the number of marked articles.
9092       count)))
9093
9094 (defun gnus-summary-mark-as-processable (n &optional unmark)
9095   "Set the process mark on the next N articles.
9096 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9097 the process mark instead.  The difference between N and the actual
9098 number of articles marked is returned."
9099   (interactive "P")
9100   (if (and (null n) (gnus-region-active-p))
9101       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9102     (setq n (prefix-numeric-value n))
9103     (let ((backward (< n 0))
9104           (n (abs n)))
9105       (while (and
9106               (> n 0)
9107               (if unmark
9108                   (gnus-summary-remove-process-mark
9109                    (gnus-summary-article-number))
9110                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9111               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9112         (setq n (1- n)))
9113       (when (/= 0 n)
9114         (gnus-message 7 "No more articles"))
9115       (gnus-summary-recenter)
9116       (gnus-summary-position-point)
9117       n)))
9118
9119 (defun gnus-summary-unmark-as-processable (n)
9120   "Remove the process mark from the next N articles.
9121 If N is negative, unmark backward instead.  The difference between N and
9122 the actual number of articles unmarked is returned."
9123   (interactive "P")
9124   (gnus-summary-mark-as-processable n t))
9125
9126 (defun gnus-summary-unmark-all-processable ()
9127   "Remove the process mark from all articles."
9128   (interactive)
9129   (save-excursion
9130     (while gnus-newsgroup-processable
9131       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9132   (gnus-summary-position-point))
9133
9134 (defun gnus-summary-add-mark (article type)
9135   "Mark ARTICLE with a mark of TYPE."
9136   (let ((vtype (car (assq type gnus-article-mark-lists)))
9137         var)
9138     (if (not vtype)
9139         (error "No such mark type: %s" type)
9140       (setq var (intern (format "gnus-newsgroup-%s" type)))
9141       (set var (cons article (symbol-value var)))
9142       (if (memq type '(processable cached replied forwarded recent saved))
9143           (gnus-summary-update-secondary-mark article)
9144         ;;; !!! This is bogus.  We should find out what primary
9145         ;;; !!! mark we want to set.
9146         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9147
9148 (defun gnus-summary-mark-as-expirable (n)
9149   "Mark N articles forward as expirable.
9150 If N is negative, mark backward instead.  The difference between N and
9151 the actual number of articles marked is returned."
9152   (interactive "p")
9153   (gnus-summary-mark-forward n gnus-expirable-mark))
9154
9155 (defun gnus-summary-mark-article-as-replied (article)
9156   "Mark ARTICLE as replied to and update the summary line.
9157 ARTICLE can also be a list of articles."
9158   (interactive (list (gnus-summary-article-number)))
9159   (let ((articles (if (listp article) article (list article))))
9160     (dolist (article articles)
9161       (push article gnus-newsgroup-replied)
9162       (let ((buffer-read-only nil))
9163         (when (gnus-summary-goto-subject article nil t)
9164           (gnus-summary-update-secondary-mark article))))))
9165
9166 (defun gnus-summary-mark-article-as-forwarded (article)
9167   "Mark ARTICLE as forwarded and update the summary line.
9168 ARTICLE can also be a list of articles."
9169   (let ((articles (if (listp article) article (list article))))
9170     (dolist (article articles)
9171       (push article gnus-newsgroup-forwarded)
9172       (let ((buffer-read-only nil))
9173         (when (gnus-summary-goto-subject article nil t)
9174           (gnus-summary-update-secondary-mark article))))))
9175
9176 (defun gnus-summary-set-bookmark (article)
9177   "Set a bookmark in current article."
9178   (interactive (list (gnus-summary-article-number)))
9179   (when (or (not (get-buffer gnus-article-buffer))
9180             (not gnus-current-article)
9181             (not gnus-article-current)
9182             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9183     (error "No current article selected"))
9184   ;; Remove old bookmark, if one exists.
9185   (let ((old (assq article gnus-newsgroup-bookmarks)))
9186     (when old
9187       (setq gnus-newsgroup-bookmarks
9188             (delq old gnus-newsgroup-bookmarks))))
9189   ;; Set the new bookmark, which is on the form
9190   ;; (article-number . line-number-in-body).
9191   (push
9192    (cons article
9193          (save-excursion
9194            (set-buffer gnus-article-buffer)
9195            (count-lines
9196             (min (point)
9197                  (save-excursion
9198                    (goto-char (point-min))
9199                    (search-forward "\n\n" nil t)
9200                    (point)))
9201             (point))))
9202    gnus-newsgroup-bookmarks)
9203   (gnus-message 6 "A bookmark has been added to the current article."))
9204
9205 (defun gnus-summary-remove-bookmark (article)
9206   "Remove the bookmark from the current article."
9207   (interactive (list (gnus-summary-article-number)))
9208   ;; Remove old bookmark, if one exists.
9209   (let ((old (assq article gnus-newsgroup-bookmarks)))
9210     (if old
9211         (progn
9212           (setq gnus-newsgroup-bookmarks
9213                 (delq old gnus-newsgroup-bookmarks))
9214           (gnus-message 6 "Removed bookmark."))
9215       (gnus-message 6 "No bookmark in current article."))))
9216
9217 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9218 (defun gnus-summary-mark-as-dormant (n)
9219   "Mark N articles forward as dormant.
9220 If N is negative, mark backward instead.  The difference between N and
9221 the actual number of articles marked is returned."
9222   (interactive "p")
9223   (gnus-summary-mark-forward n gnus-dormant-mark))
9224
9225 (defun gnus-summary-set-process-mark (article)
9226   "Set the process mark on ARTICLE and update the summary line."
9227   (setq gnus-newsgroup-processable
9228         (cons article
9229               (delq article gnus-newsgroup-processable)))
9230   (when (gnus-summary-goto-subject article)
9231     (gnus-summary-show-thread)
9232     (gnus-summary-goto-subject article)
9233     (gnus-summary-update-secondary-mark article)))
9234
9235 (defun gnus-summary-remove-process-mark (article)
9236   "Remove the process mark from ARTICLE and update the summary line."
9237   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9238   (when (gnus-summary-goto-subject article)
9239     (gnus-summary-show-thread)
9240     (gnus-summary-goto-subject article)
9241     (gnus-summary-update-secondary-mark article)))
9242
9243 (defun gnus-summary-set-saved-mark (article)
9244   "Set the process mark on ARTICLE and update the summary line."
9245   (push article gnus-newsgroup-saved)
9246   (when (gnus-summary-goto-subject article)
9247     (gnus-summary-update-secondary-mark article)))
9248
9249 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9250   "Mark N articles as read forwards.
9251 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9252 The difference between N and the actual number of articles marked is
9253 returned.
9254 Iff NO-EXPIRE, auto-expiry will be inhibited."
9255   (interactive "p")
9256   (gnus-summary-show-thread)
9257   (let ((backward (< n 0))
9258         (gnus-summary-goto-unread
9259          (and gnus-summary-goto-unread
9260               (not (eq gnus-summary-goto-unread 'never))
9261               (not (memq mark (list gnus-unread-mark
9262                                     gnus-ticked-mark gnus-dormant-mark)))))
9263         (n (abs n))
9264         (mark (or mark gnus-del-mark)))
9265     (while (and (> n 0)
9266                 (gnus-summary-mark-article nil mark no-expire)
9267                 (zerop (gnus-summary-next-subject
9268                         (if backward -1 1)
9269                         (and gnus-summary-goto-unread
9270                              (not (eq gnus-summary-goto-unread 'never)))
9271                         t)))
9272       (setq n (1- n)))
9273     (when (/= 0 n)
9274       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9275     (gnus-summary-recenter)
9276     (gnus-summary-position-point)
9277     (gnus-set-mode-line 'summary)
9278     n))
9279
9280 (defun gnus-summary-mark-article-as-read (mark)
9281   "Mark the current article quickly as read with MARK."
9282   (let ((article (gnus-summary-article-number)))
9283     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9284     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9285     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9286     (push (cons article mark) gnus-newsgroup-reads)
9287     ;; Possibly remove from cache, if that is used.
9288     (when gnus-use-cache
9289       (gnus-cache-enter-remove-article article))
9290     ;; Allow the backend to change the mark.
9291     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9292     ;; Check for auto-expiry.
9293     (when (and gnus-newsgroup-auto-expire
9294                (memq mark gnus-auto-expirable-marks))
9295       (setq mark gnus-expirable-mark)
9296       ;; Let the backend know about the mark change.
9297       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9298       (push article gnus-newsgroup-expirable))
9299     ;; Set the mark in the buffer.
9300     (gnus-summary-update-mark mark 'unread)
9301     t))
9302
9303 (defun gnus-summary-mark-article-as-unread (mark)
9304   "Mark the current article quickly as unread with MARK."
9305   (let* ((article (gnus-summary-article-number))
9306          (old-mark (gnus-summary-article-mark article)))
9307     ;; Allow the backend to change the mark.
9308     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9309     (if (eq mark old-mark)
9310         t
9311       (if (<= article 0)
9312           (progn
9313             (gnus-error 1 "Can't mark negative article numbers")
9314             nil)
9315         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9316         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9317         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9318         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9319         (cond ((= mark gnus-ticked-mark)
9320                (setq gnus-newsgroup-marked
9321                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9322                                               article)))
9323               ((= mark gnus-dormant-mark)
9324                (setq gnus-newsgroup-dormant
9325                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9326                                               article)))
9327               (t
9328                (setq gnus-newsgroup-unreads
9329                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9330                                               article))))
9331         (gnus-pull article gnus-newsgroup-reads)
9332
9333         ;; See whether the article is to be put in the cache.
9334         (and gnus-use-cache
9335              (vectorp (gnus-summary-article-header article))
9336              (save-excursion
9337                (gnus-cache-possibly-enter-article
9338                 gnus-newsgroup-name article
9339                 (gnus-summary-article-header article)
9340                 (= mark gnus-ticked-mark)
9341                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9342
9343         ;; Fix the mark.
9344         (gnus-summary-update-mark mark 'unread)
9345         t))))
9346
9347 (defun gnus-summary-mark-article (&optional article mark no-expire)
9348   "Mark ARTICLE with MARK.  MARK can be any character.
9349 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9350 `??' (dormant) and `?E' (expirable).
9351 If MARK is nil, then the default character `?r' is used.
9352 If ARTICLE is nil, then the article on the current line will be
9353 marked.
9354 Iff NO-EXPIRE, auto-expiry will be inhibited."
9355   ;; The mark might be a string.
9356   (when (stringp mark)
9357     (setq mark (aref mark 0)))
9358   ;; If no mark is given, then we check auto-expiring.
9359   (when (null mark)
9360     (setq mark gnus-del-mark))
9361   (when (and (not no-expire)
9362              gnus-newsgroup-auto-expire
9363              (memq mark gnus-auto-expirable-marks))
9364     (setq mark gnus-expirable-mark))
9365   (let ((article (or article (gnus-summary-article-number)))
9366         (old-mark (gnus-summary-article-mark article)))
9367     ;; Allow the backend to change the mark.
9368     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9369     (if (eq mark old-mark)
9370         t
9371       (unless article
9372         (error "No article on current line"))
9373       (if (not (if (or (= mark gnus-unread-mark)
9374                        (= mark gnus-ticked-mark)
9375                        (= mark gnus-dormant-mark))
9376                    (gnus-mark-article-as-unread article mark)
9377                  (gnus-mark-article-as-read article mark)))
9378           t
9379         ;; See whether the article is to be put in the cache.
9380         (and gnus-use-cache
9381              (not (= mark gnus-canceled-mark))
9382              (vectorp (gnus-summary-article-header article))
9383              (save-excursion
9384                (gnus-cache-possibly-enter-article
9385                 gnus-newsgroup-name article
9386                 (gnus-summary-article-header article)
9387                 (= mark gnus-ticked-mark)
9388                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9389
9390         (when (gnus-summary-goto-subject article nil t)
9391           (let ((buffer-read-only nil))
9392             (gnus-summary-show-thread)
9393             ;; Fix the mark.
9394             (gnus-summary-update-mark mark 'unread)
9395             t))))))
9396
9397 (defun gnus-summary-update-secondary-mark (article)
9398   "Update the secondary (read, process, cache) mark."
9399   (gnus-summary-update-mark
9400    (cond ((memq article gnus-newsgroup-processable)
9401           gnus-process-mark)
9402          ((memq article gnus-newsgroup-cached)
9403           gnus-cached-mark)
9404          ((memq article gnus-newsgroup-replied)
9405           gnus-replied-mark)
9406          ((memq article gnus-newsgroup-forwarded)
9407           gnus-forwarded-mark)
9408          ((memq article gnus-newsgroup-saved)
9409           gnus-saved-mark)
9410          ((memq article gnus-newsgroup-recent)
9411           gnus-recent-mark)
9412          ((memq article gnus-newsgroup-unseen)
9413           gnus-unseen-mark)
9414          (t gnus-no-mark))
9415    'replied)
9416   (when (gnus-visual-p 'summary-highlight 'highlight)
9417     (gnus-run-hooks 'gnus-summary-update-hook))
9418   t)
9419
9420 (defun gnus-summary-update-mark (mark type)
9421   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9422         (buffer-read-only nil))
9423     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9424     (when forward
9425       (when (looking-at "\r")
9426         (incf forward))
9427       (when (<= (+ forward (point)) (point-max))
9428         ;; Go to the right position on the line.
9429         (goto-char (+ forward (point)))
9430         ;; Replace the old mark with the new mark.
9431         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9432         ;; Optionally update the marks by some user rule.
9433         (when (eq type 'unread)
9434           (gnus-data-set-mark
9435            (gnus-data-find (gnus-summary-article-number)) mark)
9436           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9437
9438 (defun gnus-mark-article-as-read (article &optional mark)
9439   "Enter ARTICLE in the pertinent lists and remove it from others."
9440   ;; Make the article expirable.
9441   (let ((mark (or mark gnus-del-mark)))
9442     (setq gnus-newsgroup-expirable
9443           (if (= mark gnus-expirable-mark)
9444               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9445             (delq article gnus-newsgroup-expirable)))
9446     ;; Remove from unread and marked lists.
9447     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9448     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9449     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9450     (push (cons article mark) gnus-newsgroup-reads)
9451     ;; Possibly remove from cache, if that is used.
9452     (when gnus-use-cache
9453       (gnus-cache-enter-remove-article article))
9454     t))
9455
9456 (defun gnus-mark-article-as-unread (article &optional mark)
9457   "Enter ARTICLE in the pertinent lists and remove it from others."
9458   (let ((mark (or mark gnus-ticked-mark)))
9459     (if (<= article 0)
9460         (progn
9461           (gnus-error 1 "Can't mark negative article numbers")
9462           nil)
9463       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9464             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9465             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9466             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9467
9468       ;; Unsuppress duplicates?
9469       (when gnus-suppress-duplicates
9470         (gnus-dup-unsuppress-article article))
9471
9472       (cond ((= mark gnus-ticked-mark)
9473              (setq gnus-newsgroup-marked
9474                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9475             ((= mark gnus-dormant-mark)
9476              (setq gnus-newsgroup-dormant
9477                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9478             (t
9479              (setq gnus-newsgroup-unreads
9480                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9481       (gnus-pull article gnus-newsgroup-reads)
9482       t)))
9483
9484 (defalias 'gnus-summary-mark-as-unread-forward
9485   'gnus-summary-tick-article-forward)
9486 (make-obsolete 'gnus-summary-mark-as-unread-forward
9487                'gnus-summary-tick-article-forward)
9488 (defun gnus-summary-tick-article-forward (n)
9489   "Tick N articles forwards.
9490 If N is negative, tick backwards instead.
9491 The difference between N and the number of articles ticked is returned."
9492   (interactive "p")
9493   (gnus-summary-mark-forward n gnus-ticked-mark))
9494
9495 (defalias 'gnus-summary-mark-as-unread-backward
9496   'gnus-summary-tick-article-backward)
9497 (make-obsolete 'gnus-summary-mark-as-unread-backward
9498                'gnus-summary-tick-article-backward)
9499 (defun gnus-summary-tick-article-backward (n)
9500   "Tick N articles backwards.
9501 The difference between N and the number of articles ticked is returned."
9502   (interactive "p")
9503   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9504
9505 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9506 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9507 (defun gnus-summary-tick-article (&optional article clear-mark)
9508   "Mark current article as unread.
9509 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9510 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9511   (interactive)
9512   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9513                                        gnus-ticked-mark)))
9514
9515 (defun gnus-summary-mark-as-read-forward (n)
9516   "Mark N articles as read forwards.
9517 If N is negative, mark backwards instead.
9518 The difference between N and the actual number of articles marked is
9519 returned."
9520   (interactive "p")
9521   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9522
9523 (defun gnus-summary-mark-as-read-backward (n)
9524   "Mark the N articles as read backwards.
9525 The difference between N and the actual number of articles marked is
9526 returned."
9527   (interactive "p")
9528   (gnus-summary-mark-forward
9529    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9530
9531 (defun gnus-summary-mark-as-read (&optional article mark)
9532   "Mark current article as read.
9533 ARTICLE specifies the article to be marked as read.
9534 MARK specifies a string to be inserted at the beginning of the line."
9535   (gnus-summary-mark-article article mark))
9536
9537 (defun gnus-summary-clear-mark-forward (n)
9538   "Clear marks from N articles forward.
9539 If N is negative, clear backward instead.
9540 The difference between N and the number of marks cleared is returned."
9541   (interactive "p")
9542   (gnus-summary-mark-forward n gnus-unread-mark))
9543
9544 (defun gnus-summary-clear-mark-backward (n)
9545   "Clear marks from N articles backward.
9546 The difference between N and the number of marks cleared is returned."
9547   (interactive "p")
9548   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9549
9550 (defun gnus-summary-mark-unread-as-read ()
9551   "Intended to be used by `gnus-summary-mark-article-hook'."
9552   (when (memq gnus-current-article gnus-newsgroup-unreads)
9553     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9554
9555 (defun gnus-summary-mark-read-and-unread-as-read ()
9556   "Intended to be used by `gnus-summary-mark-article-hook'."
9557   (let ((mark (gnus-summary-article-mark)))
9558     (when (or (gnus-unread-mark-p mark)
9559               (gnus-read-mark-p mark))
9560       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9561
9562 (defun gnus-summary-mark-unread-as-ticked ()
9563   "Intended to be used by `gnus-summary-mark-article-hook'."
9564   (when (memq gnus-current-article gnus-newsgroup-unreads)
9565     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9566
9567 (defun gnus-summary-mark-region-as-read (point mark all)
9568   "Mark all unread articles between point and mark as read.
9569 If given a prefix, mark all articles between point and mark as read,
9570 even ticked and dormant ones."
9571   (interactive "r\nP")
9572   (save-excursion
9573     (let (article)
9574       (goto-char point)
9575       (beginning-of-line)
9576       (while (and
9577               (< (point) mark)
9578               (progn
9579                 (when (or all
9580                           (memq (setq article (gnus-summary-article-number))
9581                                 gnus-newsgroup-unreads))
9582                   (gnus-summary-mark-article article gnus-del-mark))
9583                 t)
9584               (gnus-summary-find-next))))))
9585
9586 (defun gnus-summary-mark-below (score mark)
9587   "Mark articles with score less than SCORE with MARK."
9588   (interactive "P\ncMark: ")
9589   (setq score (if score
9590                   (prefix-numeric-value score)
9591                 (or gnus-summary-default-score 0)))
9592   (save-excursion
9593     (set-buffer gnus-summary-buffer)
9594     (goto-char (point-min))
9595     (while
9596         (progn
9597           (and (< (gnus-summary-article-score) score)
9598                (gnus-summary-mark-article nil mark))
9599           (gnus-summary-find-next)))))
9600
9601 (defun gnus-summary-kill-below (&optional score)
9602   "Mark articles with score below SCORE as read."
9603   (interactive "P")
9604   (gnus-summary-mark-below score gnus-killed-mark))
9605
9606 (defun gnus-summary-clear-above (&optional score)
9607   "Clear all marks from articles with score above SCORE."
9608   (interactive "P")
9609   (gnus-summary-mark-above score gnus-unread-mark))
9610
9611 (defun gnus-summary-tick-above (&optional score)
9612   "Tick all articles with score above SCORE."
9613   (interactive "P")
9614   (gnus-summary-mark-above score gnus-ticked-mark))
9615
9616 (defun gnus-summary-mark-above (score mark)
9617   "Mark articles with score over SCORE with MARK."
9618   (interactive "P\ncMark: ")
9619   (setq score (if score
9620                   (prefix-numeric-value score)
9621                 (or gnus-summary-default-score 0)))
9622   (save-excursion
9623     (set-buffer gnus-summary-buffer)
9624     (goto-char (point-min))
9625     (while (and (progn
9626                   (when (> (gnus-summary-article-score) score)
9627                     (gnus-summary-mark-article nil mark))
9628                   t)
9629                 (gnus-summary-find-next)))))
9630
9631 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9632 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9633 (defun gnus-summary-limit-include-expunged (&optional no-error)
9634   "Display all the hidden articles that were expunged for low scores."
9635   (interactive)
9636   (let ((buffer-read-only nil))
9637     (let ((scored gnus-newsgroup-scored)
9638           headers h)
9639       (while scored
9640         (unless (gnus-summary-article-header (caar scored))
9641           (and (setq h (gnus-number-to-header (caar scored)))
9642                (< (cdar scored) gnus-summary-expunge-below)
9643                (push h headers)))
9644         (setq scored (cdr scored)))
9645       (if (not headers)
9646           (when (not no-error)
9647             (error "No expunged articles hidden"))
9648         (goto-char (point-min))
9649         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9650         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9651         (mapcar (lambda (x) (push (mail-header-number x)
9652                                   gnus-newsgroup-limit))
9653                 headers)
9654         (gnus-summary-prepare-unthreaded (nreverse headers))
9655         (goto-char (point-min))
9656         (gnus-summary-position-point)
9657         t))))
9658
9659 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9660   "Mark all unread articles in this newsgroup as read.
9661 If prefix argument ALL is non-nil, ticked and dormant articles will
9662 also be marked as read.
9663 If QUIETLY is non-nil, no questions will be asked.
9664 If TO-HERE is non-nil, it should be a point in the buffer.  All
9665 articles before (after, if REVERSE is set) this point will be marked as read.
9666 Note that this function will only catch up the unread article
9667 in the current summary buffer limitation.
9668 The number of articles marked as read is returned."
9669   (interactive "P")
9670   (prog1
9671       (save-excursion
9672         (when (or quietly
9673                   (not gnus-interactive-catchup) ;Without confirmation?
9674                   gnus-expert-user
9675                   (gnus-y-or-n-p
9676                    (if all
9677                        "Mark absolutely all articles as read? "
9678                      "Mark all unread articles as read? ")))
9679           (if (and not-mark
9680                    (not gnus-newsgroup-adaptive)
9681                    (not gnus-newsgroup-auto-expire)
9682                    (not gnus-suppress-duplicates)
9683                    (or (not gnus-use-cache)
9684                        (eq gnus-use-cache 'passive)))
9685               (progn
9686                 (when all
9687                   (setq gnus-newsgroup-marked nil
9688                         gnus-newsgroup-dormant nil))
9689                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9690             ;; We actually mark all articles as canceled, which we
9691             ;; have to do when using auto-expiry or adaptive scoring.
9692             (gnus-summary-show-all-threads)
9693             (if (and to-here reverse)
9694                 (progn
9695                   (goto-char to-here)
9696                   (while (and
9697                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9698                           (gnus-summary-find-next (not all) nil nil t))))
9699               (when (gnus-summary-first-subject (not all) t)
9700                 (while (and
9701                         (if to-here (< (point) to-here) t)
9702                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9703                         (gnus-summary-find-next (not all) nil nil t)))))
9704             (gnus-set-mode-line 'summary))
9705           t))
9706     (gnus-summary-position-point)))
9707
9708 (defun gnus-summary-catchup-to-here (&optional all)
9709   "Mark all unticked articles before the current one as read.
9710 If ALL is non-nil, also mark ticked and dormant articles as read."
9711   (interactive "P")
9712   (save-excursion
9713     (gnus-save-hidden-threads
9714       (let ((beg (point)))
9715         ;; We check that there are unread articles.
9716         (when (or all (gnus-summary-find-prev))
9717           (gnus-summary-catchup all t beg)))))
9718   (gnus-summary-position-point))
9719
9720 (defun gnus-summary-catchup-from-here (&optional all)
9721   "Mark all unticked articles after the current one as read.
9722 If ALL is non-nil, also mark ticked and dormant articles as read."
9723   (interactive "P")
9724   (save-excursion
9725     (gnus-save-hidden-threads
9726       (let ((beg (point)))
9727         ;; We check that there are unread articles.
9728         (when (or all (gnus-summary-find-next))
9729           (gnus-summary-catchup all t beg nil t)))))
9730   (gnus-summary-position-point))
9731
9732 (defun gnus-summary-catchup-all (&optional quietly)
9733   "Mark all articles in this newsgroup as read."
9734   (interactive "P")
9735   (gnus-summary-catchup t quietly))
9736
9737 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9738   "Mark all unread articles in this group as read, then exit.
9739 If prefix argument ALL is non-nil, all articles are marked as read.
9740 If QUIETLY is non-nil, no questions will be asked."
9741   (interactive "P")
9742   (when (gnus-summary-catchup all quietly nil 'fast)
9743     ;; Select next newsgroup or exit.
9744     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9745              (eq gnus-auto-select-next 'quietly))
9746         (gnus-summary-next-group nil)
9747       (gnus-summary-exit))))
9748
9749 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9750   "Mark all articles in this newsgroup as read, and then exit."
9751   (interactive "P")
9752   (gnus-summary-catchup-and-exit t quietly))
9753
9754 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9755   "Mark all articles in this group as read and select the next group.
9756 If given a prefix, mark all articles, unread as well as ticked, as
9757 read."
9758   (interactive "P")
9759   (save-excursion
9760     (gnus-summary-catchup all))
9761   (gnus-summary-next-group))
9762
9763 ;;;
9764 ;;; with article
9765 ;;;
9766
9767 (defmacro gnus-with-article (article &rest forms)
9768   "Select ARTICLE and perform FORMS in the original article buffer.
9769 Then replace the article with the result."
9770   `(progn
9771      ;; We don't want the article to be marked as read.
9772      (let (gnus-mark-article-hook)
9773        (gnus-summary-select-article t t nil ,article))
9774      (set-buffer gnus-original-article-buffer)
9775      ,@forms
9776      (if (not (gnus-check-backend-function
9777                'request-replace-article (car gnus-article-current)))
9778          (gnus-message 5 "Read-only group; not replacing")
9779        (unless (gnus-request-replace-article
9780                 ,article (car gnus-article-current)
9781                 (current-buffer) t)
9782          (error "Couldn't replace article")))
9783      ;; The cache and backlog have to be flushed somewhat.
9784      (when gnus-keep-backlog
9785        (gnus-backlog-remove-article
9786         (car gnus-article-current) (cdr gnus-article-current)))
9787      (when gnus-use-cache
9788        (gnus-cache-update-article
9789         (car gnus-article-current) (cdr gnus-article-current)))))
9790
9791 (put 'gnus-with-article 'lisp-indent-function 1)
9792 (put 'gnus-with-article 'edebug-form-spec '(form body))
9793
9794 ;; Thread-based commands.
9795
9796 (defun gnus-summary-articles-in-thread (&optional article)
9797   "Return a list of all articles in the current thread.
9798 If ARTICLE is non-nil, return all articles in the thread that starts
9799 with that article."
9800   (let* ((article (or article (gnus-summary-article-number)))
9801          (data (gnus-data-find-list article))
9802          (top-level (gnus-data-level (car data)))
9803          (top-subject
9804           (cond ((null gnus-thread-operation-ignore-subject)
9805                  (gnus-simplify-subject-re
9806                   (mail-header-subject (gnus-data-header (car data)))))
9807                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9808                  (gnus-simplify-subject-fuzzy
9809                   (mail-header-subject (gnus-data-header (car data)))))
9810                 (t nil)))
9811          (end-point (save-excursion
9812                       (if (gnus-summary-go-to-next-thread)
9813                           (point) (point-max))))
9814          articles)
9815     (while (and data
9816                 (< (gnus-data-pos (car data)) end-point))
9817       (when (or (not top-subject)
9818                 (string= top-subject
9819                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9820                              (gnus-simplify-subject-fuzzy
9821                               (mail-header-subject
9822                                (gnus-data-header (car data))))
9823                            (gnus-simplify-subject-re
9824                             (mail-header-subject
9825                              (gnus-data-header (car data)))))))
9826         (push (gnus-data-number (car data)) articles))
9827       (unless (and (setq data (cdr data))
9828                    (> (gnus-data-level (car data)) top-level))
9829         (setq data nil)))
9830     ;; Return the list of articles.
9831     (nreverse articles)))
9832
9833 (defun gnus-summary-rethread-current ()
9834   "Rethread the thread the current article is part of."
9835   (interactive)
9836   (let* ((gnus-show-threads t)
9837          (article (gnus-summary-article-number))
9838          (id (mail-header-id (gnus-summary-article-header)))
9839          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9840     (unless id
9841       (error "No article on the current line"))
9842     (gnus-rebuild-thread id)
9843     (gnus-summary-goto-subject article)))
9844
9845 (defun gnus-summary-reparent-thread ()
9846   "Make the current article child of the marked (or previous) article.
9847
9848 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9849 is non-nil or the Subject: of both articles are the same."
9850   (interactive)
9851   (unless (not (gnus-group-read-only-p))
9852     (error "The current newsgroup does not support article editing"))
9853   (unless (<= (length gnus-newsgroup-processable) 1)
9854     (error "No more than one article may be marked"))
9855   (save-window-excursion
9856     (let ((gnus-article-buffer " *reparent*")
9857           (current-article (gnus-summary-article-number))
9858           ;; First grab the marked article, otherwise one line up.
9859           (parent-article (if (not (null gnus-newsgroup-processable))
9860                               (car gnus-newsgroup-processable)
9861                             (save-excursion
9862                               (if (eq (forward-line -1) 0)
9863                                   (gnus-summary-article-number)
9864                                 (error "Beginning of summary buffer"))))))
9865       (unless (not (eq current-article parent-article))
9866         (error "An article may not be self-referential"))
9867       (let ((message-id (mail-header-id
9868                          (gnus-summary-article-header parent-article))))
9869         (unless (and message-id (not (equal message-id "")))
9870           (error "No message-id in desired parent"))
9871         (gnus-with-article current-article
9872           (save-restriction
9873             (goto-char (point-min))
9874             (message-narrow-to-head)
9875             (if (re-search-forward "^References: " nil t)
9876                 (progn
9877                   (re-search-forward "^[^ \t]" nil t)
9878                   (forward-line -1)
9879                   (end-of-line)
9880                   (insert " " message-id))
9881               (insert "References: " message-id "\n"))))
9882         (set-buffer gnus-summary-buffer)
9883         (gnus-summary-unmark-all-processable)
9884         (gnus-summary-update-article current-article)
9885         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9886             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9887         (gnus-summary-rethread-current)
9888         (gnus-message 3 "Article %d is now the child of article %d"
9889                       current-article parent-article)))))
9890
9891 (defun gnus-summary-toggle-threads (&optional arg)
9892   "Toggle showing conversation threads.
9893 If ARG is positive number, turn showing conversation threads on."
9894   (interactive "P")
9895   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9896     (setq gnus-show-threads
9897           (if (null arg) (not gnus-show-threads)
9898             (> (prefix-numeric-value arg) 0)))
9899     (gnus-summary-prepare)
9900     (gnus-summary-goto-subject current)
9901     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9902     (gnus-summary-position-point)))
9903
9904 (defun gnus-summary-show-all-threads ()
9905   "Show all threads."
9906   (interactive)
9907   (save-excursion
9908     (let ((buffer-read-only nil))
9909       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9910   (gnus-summary-position-point))
9911
9912 (defun gnus-summary-show-thread ()
9913   "Show thread subtrees.
9914 Returns nil if no thread was there to be shown."
9915   (interactive)
9916   (let ((buffer-read-only nil)
9917         (orig (point))
9918         ;; first goto end then to beg, to have point at beg after let
9919         (end (progn (end-of-line) (point)))
9920         (beg (progn (beginning-of-line) (point))))
9921     (prog1
9922         ;; Any hidden lines here?
9923         (search-forward "\r" end t)
9924       (subst-char-in-region beg end ?\^M ?\n t)
9925       (goto-char orig)
9926       (gnus-summary-position-point))))
9927
9928 (defun gnus-summary-maybe-hide-threads ()
9929   "If requested, hide the threads that should be hidden."
9930   (when (and gnus-show-threads
9931              gnus-thread-hide-subtree)
9932     (gnus-summary-hide-all-threads
9933      (if (or (consp gnus-thread-hide-subtree)
9934              (gnus-functionp gnus-thread-hide-subtree))
9935          (gnus-make-predicate gnus-thread-hide-subtree)
9936        nil))))
9937
9938 ;;; Hiding predicates.
9939
9940 (defun gnus-article-unread-p (header)
9941   (memq (mail-header-number header) gnus-newsgroup-unreads))
9942
9943 (defun gnus-article-unseen-p (header)
9944   (memq (mail-header-number header) gnus-newsgroup-unseen))
9945
9946 (defun gnus-map-articles (predicate articles)
9947   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
9948   (apply 'gnus-or (mapcar predicate
9949                           (mapcar 'gnus-summary-article-header articles))))
9950
9951 (defun gnus-summary-hide-all-threads (&optional predicate)
9952   "Hide all thread subtrees.
9953 If PREDICATE is supplied, threads that satisfy this predicate
9954 will not be hidden."
9955   (interactive)
9956   (save-excursion
9957     (goto-char (point-min))
9958     (let ((end nil))
9959       (while (not end)
9960         (when (or (not predicate)
9961                   (gnus-map-articles
9962                    predicate (gnus-summary-article-children)))
9963             (gnus-summary-hide-thread))
9964         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
9965   (gnus-summary-position-point))
9966
9967 (defun gnus-summary-hide-thread ()
9968   "Hide thread subtrees.
9969 If PREDICATE is supplied, threads that satisfy this predicate
9970 will not be hidden.
9971 Returns nil if no threads were there to be hidden."
9972   (interactive)
9973   (let ((buffer-read-only nil)
9974         (start (point))
9975         (article (gnus-summary-article-number)))
9976     (goto-char start)
9977     ;; Go forward until either the buffer ends or the subthread
9978     ;; ends.
9979     (when (and (not (eobp))
9980                (or (zerop (gnus-summary-next-thread 1 t))
9981                    (goto-char (point-max))))
9982       (prog1
9983           (if (and (> (point) start)
9984                    (search-backward "\n" start t))
9985               (progn
9986                 (subst-char-in-region start (point) ?\n ?\^M)
9987                 (gnus-summary-goto-subject article))
9988             (goto-char start)
9989             nil)))))
9990
9991 (defun gnus-summary-go-to-next-thread (&optional previous)
9992   "Go to the same level (or less) next thread.
9993 If PREVIOUS is non-nil, go to previous thread instead.
9994 Return the article number moved to, or nil if moving was impossible."
9995   (let ((level (gnus-summary-thread-level))
9996         (way (if previous -1 1))
9997         (beg (point)))
9998     (forward-line way)
9999     (while (and (not (eobp))
10000                 (< level (gnus-summary-thread-level)))
10001       (forward-line way))
10002     (if (eobp)
10003         (progn
10004           (goto-char beg)
10005           nil)
10006       (setq beg (point))
10007       (prog1
10008           (gnus-summary-article-number)
10009         (goto-char beg)))))
10010
10011 (defun gnus-summary-next-thread (n &optional silent)
10012   "Go to the same level next N'th thread.
10013 If N is negative, search backward instead.
10014 Returns the difference between N and the number of skips actually
10015 done.
10016
10017 If SILENT, don't output messages."
10018   (interactive "p")
10019   (let ((backward (< n 0))
10020         (n (abs n)))
10021     (while (and (> n 0)
10022                 (gnus-summary-go-to-next-thread backward))
10023       (decf n))
10024     (unless silent
10025       (gnus-summary-position-point))
10026     (when (and (not silent) (/= 0 n))
10027       (gnus-message 7 "No more threads"))
10028     n))
10029
10030 (defun gnus-summary-prev-thread (n)
10031   "Go to the same level previous N'th thread.
10032 Returns the difference between N and the number of skips actually
10033 done."
10034   (interactive "p")
10035   (gnus-summary-next-thread (- n)))
10036
10037 (defun gnus-summary-go-down-thread ()
10038   "Go down one level in the current thread."
10039   (let ((children (gnus-summary-article-children)))
10040     (when children
10041       (gnus-summary-goto-subject (car children)))))
10042
10043 (defun gnus-summary-go-up-thread ()
10044   "Go up one level in the current thread."
10045   (let ((parent (gnus-summary-article-parent)))
10046     (when parent
10047       (gnus-summary-goto-subject parent))))
10048
10049 (defun gnus-summary-down-thread (n)
10050   "Go down thread N steps.
10051 If N is negative, go up instead.
10052 Returns the difference between N and how many steps down that were
10053 taken."
10054   (interactive "p")
10055   (let ((up (< n 0))
10056         (n (abs n)))
10057     (while (and (> n 0)
10058                 (if up (gnus-summary-go-up-thread)
10059                   (gnus-summary-go-down-thread)))
10060       (setq n (1- n)))
10061     (gnus-summary-position-point)
10062     (when (/= 0 n)
10063       (gnus-message 7 "Can't go further"))
10064     n))
10065
10066 (defun gnus-summary-up-thread (n)
10067   "Go up thread N steps.
10068 If N is negative, go down instead.
10069 Returns the difference between N and how many steps down that were
10070 taken."
10071   (interactive "p")
10072   (gnus-summary-down-thread (- n)))
10073
10074 (defun gnus-summary-top-thread ()
10075   "Go to the top of the thread."
10076   (interactive)
10077   (while (gnus-summary-go-up-thread))
10078   (gnus-summary-article-number))
10079
10080 (defun gnus-summary-kill-thread (&optional unmark)
10081   "Mark articles under current thread as read.
10082 If the prefix argument is positive, remove any kinds of marks.
10083 If the prefix argument is negative, tick articles instead."
10084   (interactive "P")
10085   (when unmark
10086     (setq unmark (prefix-numeric-value unmark)))
10087   (let ((articles (gnus-summary-articles-in-thread)))
10088     (save-excursion
10089       ;; Expand the thread.
10090       (gnus-summary-show-thread)
10091       ;; Mark all the articles.
10092       (while articles
10093         (gnus-summary-goto-subject (car articles))
10094         (cond ((null unmark)
10095                (gnus-summary-mark-article-as-read gnus-killed-mark))
10096               ((> unmark 0)
10097                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10098               (t
10099                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10100         (setq articles (cdr articles))))
10101     ;; Hide killed subtrees.
10102     (and (null unmark)
10103          gnus-thread-hide-killed
10104          (gnus-summary-hide-thread))
10105     ;; If marked as read, go to next unread subject.
10106     (when (null unmark)
10107       ;; Go to next unread subject.
10108       (gnus-summary-next-subject 1 t)))
10109   (gnus-set-mode-line 'summary))
10110
10111 ;; Summary sorting commands
10112
10113 (defun gnus-summary-sort-by-number (&optional reverse)
10114   "Sort the summary buffer by article number.
10115 Argument REVERSE means reverse order."
10116   (interactive "P")
10117   (gnus-summary-sort 'number reverse))
10118
10119 (defun gnus-summary-sort-by-author (&optional reverse)
10120   "Sort the summary buffer by author name alphabetically.
10121 If `case-fold-search' is non-nil, case of letters is ignored.
10122 Argument REVERSE means reverse order."
10123   (interactive "P")
10124   (gnus-summary-sort 'author reverse))
10125
10126 (defun gnus-summary-sort-by-subject (&optional reverse)
10127   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10128 If `case-fold-search' is non-nil, case of letters is ignored.
10129 Argument REVERSE means reverse order."
10130   (interactive "P")
10131   (gnus-summary-sort 'subject reverse))
10132
10133 (defun gnus-summary-sort-by-date (&optional reverse)
10134   "Sort the summary buffer by date.
10135 Argument REVERSE means reverse order."
10136   (interactive "P")
10137   (gnus-summary-sort 'date reverse))
10138
10139 (defun gnus-summary-sort-by-score (&optional reverse)
10140   "Sort the summary buffer by score.
10141 Argument REVERSE means reverse order."
10142   (interactive "P")
10143   (gnus-summary-sort 'score reverse))
10144
10145 (defun gnus-summary-sort-by-lines (&optional reverse)
10146   "Sort the summary buffer by the number of lines.
10147 Argument REVERSE means reverse order."
10148   (interactive "P")
10149   (gnus-summary-sort 'lines reverse))
10150
10151 (defun gnus-summary-sort-by-chars (&optional reverse)
10152   "Sort the summary buffer by article length.
10153 Argument REVERSE means reverse order."
10154   (interactive "P")
10155   (gnus-summary-sort 'chars reverse))
10156
10157 (defun gnus-summary-sort-by-original (&optional reverse)
10158   "Sort the summary buffer using the default sorting method.
10159 Argument REVERSE means reverse order."
10160   (interactive "P")
10161   (let* ((buffer-read-only)
10162          (gnus-summary-prepare-hook nil))
10163     ;; We do the sorting by regenerating the threads.
10164     (gnus-summary-prepare)
10165     ;; Hide subthreads if needed.
10166     (gnus-summary-maybe-hide-threads)))
10167
10168 (defun gnus-summary-sort (predicate reverse)
10169   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10170   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10171          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10172          (gnus-thread-sort-functions
10173           (if (not reverse)
10174               thread
10175             `(lambda (t1 t2)
10176                (,thread t2 t1))))
10177          (gnus-sort-gathered-threads-function
10178           gnus-thread-sort-functions)
10179          (gnus-article-sort-functions
10180           (if (not reverse)
10181               article
10182             `(lambda (t1 t2)
10183                (,article t2 t1))))
10184          (buffer-read-only)
10185          (gnus-summary-prepare-hook nil))
10186     ;; We do the sorting by regenerating the threads.
10187     (gnus-summary-prepare)
10188     ;; Hide subthreads if needed.
10189     (gnus-summary-maybe-hide-threads)))
10190
10191 ;; Summary saving commands.
10192
10193 (defun gnus-summary-save-article (&optional n not-saved)
10194   "Save the current article using the default saver function.
10195 If N is a positive number, save the N next articles.
10196 If N is a negative number, save the N previous articles.
10197 If N is nil and any articles have been marked with the process mark,
10198 save those articles instead.
10199 The variable `gnus-default-article-saver' specifies the saver function."
10200   (interactive "P")
10201   (let* ((articles (gnus-summary-work-articles n))
10202          (save-buffer (save-excursion
10203                         (nnheader-set-temp-buffer " *Gnus Save*")))
10204          (num (length articles))
10205          header file)
10206     (dolist (article articles)
10207       (setq header (gnus-summary-article-header article))
10208       (if (not (vectorp header))
10209           ;; This is a pseudo-article.
10210           (if (assq 'name header)
10211               (gnus-copy-file (cdr (assq 'name header)))
10212             (gnus-message 1 "Article %d is unsaveable" article))
10213         ;; This is a real article.
10214         (save-window-excursion
10215           (let ((gnus-display-mime-function nil)
10216                 (gnus-article-prepare-hook nil))
10217             (gnus-summary-select-article t nil nil article)))
10218         (save-excursion
10219           (set-buffer save-buffer)
10220           (erase-buffer)
10221           (insert-buffer-substring gnus-original-article-buffer))
10222         (setq file (gnus-article-save save-buffer file num))
10223         (gnus-summary-remove-process-mark article)
10224         (unless not-saved
10225           (gnus-summary-set-saved-mark article))))
10226     (gnus-kill-buffer save-buffer)
10227     (gnus-summary-position-point)
10228     (gnus-set-mode-line 'summary)
10229     n))
10230
10231 (defun gnus-summary-pipe-output (&optional arg)
10232   "Pipe the current article to a subprocess.
10233 If N is a positive number, pipe the N next articles.
10234 If N is a negative number, pipe the N previous articles.
10235 If N is nil and any articles have been marked with the process mark,
10236 pipe those articles instead."
10237   (interactive "P")
10238   (require 'gnus-art)
10239   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10240     (gnus-summary-save-article arg t))
10241   (let ((buffer (get-buffer "*Shell Command Output*")))
10242     (if (and buffer
10243              (with-current-buffer buffer (> (point-max) (point-min))))
10244         (gnus-configure-windows 'pipe))))
10245
10246 (defun gnus-summary-save-article-mail (&optional arg)
10247   "Append the current article to an mail file.
10248 If N is a positive number, save the N next articles.
10249 If N is a negative number, save the N previous articles.
10250 If N is nil and any articles have been marked with the process mark,
10251 save those articles instead."
10252   (interactive "P")
10253   (require 'gnus-art)
10254   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10255     (gnus-summary-save-article arg)))
10256
10257 (defun gnus-summary-save-article-rmail (&optional arg)
10258   "Append the current article to an rmail file.
10259 If N is a positive number, save the N next articles.
10260 If N is a negative number, save the N previous articles.
10261 If N is nil and any articles have been marked with the process mark,
10262 save those articles instead."
10263   (interactive "P")
10264   (require 'gnus-art)
10265   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10266     (gnus-summary-save-article arg)))
10267
10268 (defun gnus-summary-save-article-file (&optional arg)
10269   "Append the current article to a file.
10270 If N is a positive number, save the N next articles.
10271 If N is a negative number, save the N previous articles.
10272 If N is nil and any articles have been marked with the process mark,
10273 save those articles instead."
10274   (interactive "P")
10275   (require 'gnus-art)
10276   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10277     (gnus-summary-save-article arg)))
10278
10279 (defun gnus-summary-write-article-file (&optional arg)
10280   "Write the current article to a file, deleting the previous file.
10281 If N is a positive number, save the N next articles.
10282 If N is a negative number, save the N previous articles.
10283 If N is nil and any articles have been marked with the process mark,
10284 save those articles instead."
10285   (interactive "P")
10286   (require 'gnus-art)
10287   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10288     (gnus-summary-save-article arg)))
10289
10290 (defun gnus-summary-save-article-body-file (&optional arg)
10291   "Append the current article body to a file.
10292 If N is a positive number, save the N next articles.
10293 If N is a negative number, save the N previous articles.
10294 If N is nil and any articles have been marked with the process mark,
10295 save those articles instead."
10296   (interactive "P")
10297   (require 'gnus-art)
10298   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10299     (gnus-summary-save-article arg)))
10300
10301 (defun gnus-summary-muttprint (&optional arg)
10302   "Print the current article using Muttprint.
10303 If N is a positive number, save the N next articles.
10304 If N is a negative number, save the N previous articles.
10305 If N is nil and any articles have been marked with the process mark,
10306 save those articles instead."
10307   (interactive "P")
10308   (require 'gnus-art)
10309   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10310     (gnus-summary-save-article arg t)))
10311
10312 (defun gnus-summary-pipe-message (program)
10313   "Pipe the current article through PROGRAM."
10314   (interactive "sProgram: ")
10315   (gnus-summary-select-article)
10316   (let ((mail-header-separator ""))
10317     (gnus-eval-in-buffer-window gnus-article-buffer
10318       (save-restriction
10319         (widen)
10320         (let ((start (window-start))
10321               buffer-read-only)
10322           (message-pipe-buffer-body program)
10323           (set-window-start (get-buffer-window (current-buffer)) start))))))
10324
10325 (defun gnus-get-split-value (methods)
10326   "Return a value based on the split METHODS."
10327   (let (split-name method result match)
10328     (when methods
10329       (save-excursion
10330         (set-buffer gnus-original-article-buffer)
10331         (save-restriction
10332           (nnheader-narrow-to-headers)
10333           (while (and methods (not split-name))
10334             (goto-char (point-min))
10335             (setq method (pop methods))
10336             (setq match (car method))
10337             (when (cond
10338                    ((stringp match)
10339                     ;; Regular expression.
10340                     (ignore-errors
10341                       (re-search-forward match nil t)))
10342                    ((gnus-functionp match)
10343                     ;; Function.
10344                     (save-restriction
10345                       (widen)
10346                       (setq result (funcall match gnus-newsgroup-name))))
10347                    ((consp match)
10348                     ;; Form.
10349                     (save-restriction
10350                       (widen)
10351                       (setq result (eval match)))))
10352               (setq split-name (cdr method))
10353               (cond ((stringp result)
10354                      (push (expand-file-name
10355                             result gnus-article-save-directory)
10356                            split-name))
10357                     ((consp result)
10358                      (setq split-name (append result split-name)))))))))
10359     (nreverse split-name)))
10360
10361 (defun gnus-valid-move-group-p (group)
10362   (and (boundp group)
10363        (symbol-name group)
10364        (symbol-value group)
10365        (gnus-get-function (gnus-find-method-for-group
10366                            (symbol-name group)) 'request-accept-article t)))
10367
10368 (defun gnus-read-move-group-name (prompt default articles prefix)
10369   "Read a group name."
10370   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10371          (minibuffer-confirm-incomplete nil) ; XEmacs
10372          (prom
10373           (format "%s %s to:"
10374                   prompt
10375                   (if (> (length articles) 1)
10376                       (format "these %d articles" (length articles))
10377                     "this article")))
10378          (to-newsgroup
10379           (cond
10380            ((null split-name)
10381             (gnus-completing-read-with-default
10382              default prom
10383              gnus-active-hashtb
10384              'gnus-valid-move-group-p
10385              nil prefix
10386              'gnus-group-history))
10387            ((= 1 (length split-name))
10388             (gnus-completing-read-with-default
10389              (car split-name) prom
10390              gnus-active-hashtb
10391              'gnus-valid-move-group-p
10392              nil nil
10393              'gnus-group-history))
10394            (t
10395             (gnus-completing-read-with-default
10396              nil prom
10397              (mapcar (lambda (el) (list el))
10398                      (nreverse split-name))
10399              nil nil nil
10400              'gnus-group-history))))
10401          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10402     (when to-newsgroup
10403       (if (or (string= to-newsgroup "")
10404               (string= to-newsgroup prefix))
10405           (setq to-newsgroup default))
10406       (unless to-newsgroup
10407         (error "No group name entered"))
10408       (or (gnus-active to-newsgroup)
10409           (gnus-activate-group to-newsgroup nil nil to-method)
10410           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10411                                      to-newsgroup))
10412               (or (and (gnus-request-create-group to-newsgroup to-method)
10413                        (gnus-activate-group
10414                         to-newsgroup nil nil to-method)
10415                        (gnus-subscribe-group to-newsgroup))
10416                   (error "Couldn't create group %s" to-newsgroup)))
10417           (error "No such group: %s" to-newsgroup)))
10418     to-newsgroup))
10419
10420 (defun gnus-summary-save-parts (type dir n &optional reverse)
10421   "Save parts matching TYPE to DIR.
10422 If REVERSE, save parts that do not match TYPE."
10423   (interactive
10424    (list (read-string "Save parts of type: "
10425                       (or (car gnus-summary-save-parts-type-history)
10426                           gnus-summary-save-parts-default-mime)
10427                       'gnus-summary-save-parts-type-history)
10428          (setq gnus-summary-save-parts-last-directory
10429                (read-file-name "Save to directory: "
10430                                gnus-summary-save-parts-last-directory
10431                                nil t))
10432          current-prefix-arg))
10433   (gnus-summary-iterate n
10434     (let ((gnus-display-mime-function nil)
10435           (gnus-inhibit-treatment t))
10436       (gnus-summary-select-article))
10437     (save-excursion
10438       (set-buffer gnus-article-buffer)
10439       (let ((handles (or gnus-article-mime-handles
10440                          (mm-dissect-buffer nil gnus-article-loose-mime)
10441                          (mm-uu-dissect))))
10442         (when handles
10443           (gnus-summary-save-parts-1 type dir handles reverse)
10444           (unless gnus-article-mime-handles ;; Don't destroy this case.
10445             (mm-destroy-parts handles)))))))
10446
10447 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10448   (if (stringp (car handle))
10449       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10450               (cdr handle))
10451     (when (if reverse
10452               (not (string-match type (mm-handle-media-type handle)))
10453             (string-match type (mm-handle-media-type handle)))
10454       (let ((file (expand-file-name
10455                    (file-name-nondirectory
10456                     (or
10457                      (mail-content-type-get
10458                       (mm-handle-disposition handle) 'filename)
10459                      (concat gnus-newsgroup-name
10460                              "." (number-to-string
10461                                   (cdr gnus-article-current)))))
10462                    dir)))
10463         (unless (file-exists-p file)
10464           (mm-save-part-to-file handle file))))))
10465
10466 ;; Summary extract commands
10467
10468 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10469   (let ((buffer-read-only nil)
10470         (article (gnus-summary-article-number))
10471         after-article b e)
10472     (unless (gnus-summary-goto-subject article)
10473       (error "No such article: %d" article))
10474     (gnus-summary-position-point)
10475     ;; If all commands are to be bunched up on one line, we collect
10476     ;; them here.
10477     (unless gnus-view-pseudos-separately
10478       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10479             files action)
10480         (while ps
10481           (setq action (cdr (assq 'action (car ps))))
10482           (setq files (list (cdr (assq 'name (car ps)))))
10483           (while (and ps (cdr ps)
10484                       (string= (or action "1")
10485                                (or (cdr (assq 'action (cadr ps))) "2")))
10486             (push (cdr (assq 'name (cadr ps))) files)
10487             (setcdr ps (cddr ps)))
10488           (when files
10489             (when (not (string-match "%s" action))
10490               (push " " files))
10491             (push " " files)
10492             (when (assq 'execute (car ps))
10493               (setcdr (assq 'execute (car ps))
10494                       (funcall (if (string-match "%s" action)
10495                                    'format 'concat)
10496                                action
10497                                (mapconcat
10498                                 (lambda (f)
10499                                   (if (equal f " ")
10500                                       f
10501                                     (gnus-quote-arg-for-sh-or-csh f)))
10502                                 files " ")))))
10503           (setq ps (cdr ps)))))
10504     (if (and gnus-view-pseudos (not not-view))
10505         (while pslist
10506           (when (assq 'execute (car pslist))
10507             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10508                                   (eq gnus-view-pseudos 'not-confirm)))
10509           (setq pslist (cdr pslist)))
10510       (save-excursion
10511         (while pslist
10512           (setq after-article (or (cdr (assq 'article (car pslist)))
10513                                   (gnus-summary-article-number)))
10514           (gnus-summary-goto-subject after-article)
10515           (forward-line 1)
10516           (setq b (point))
10517           (insert "    " (file-name-nondirectory
10518                           (cdr (assq 'name (car pslist))))
10519                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10520           (setq e (point))
10521           (forward-line -1)             ; back to `b'
10522           (gnus-add-text-properties
10523            b (1- e) (list 'gnus-number gnus-reffed-article-number
10524                           gnus-mouse-face-prop gnus-mouse-face))
10525           (gnus-data-enter
10526            after-article gnus-reffed-article-number
10527            gnus-unread-mark b (car pslist) 0 (- e b))
10528           (setq gnus-newsgroup-unreads
10529                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10530                                          gnus-reffed-article-number))
10531           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10532           (setq pslist (cdr pslist)))))))
10533
10534 (defun gnus-pseudos< (p1 p2)
10535   (let ((c1 (cdr (assq 'action p1)))
10536         (c2 (cdr (assq 'action p2))))
10537     (and c1 c2 (string< c1 c2))))
10538
10539 (defun gnus-request-pseudo-article (props)
10540   (cond ((assq 'execute props)
10541          (gnus-execute-command (cdr (assq 'execute props)))))
10542   (let ((gnus-current-article (gnus-summary-article-number)))
10543     (gnus-run-hooks 'gnus-mark-article-hook)))
10544
10545 (defun gnus-execute-command (command &optional automatic)
10546   (save-excursion
10547     (gnus-article-setup-buffer)
10548     (set-buffer gnus-article-buffer)
10549     (setq buffer-read-only nil)
10550     (let ((command (if automatic command
10551                      (read-string "Command: " (cons command 0)))))
10552       (erase-buffer)
10553       (insert "$ " command "\n\n")
10554       (if gnus-view-pseudo-asynchronously
10555           (start-process "gnus-execute" (current-buffer) shell-file-name
10556                          shell-command-switch command)
10557         (call-process shell-file-name nil t nil
10558                       shell-command-switch command)))))
10559
10560 ;; Summary kill commands.
10561
10562 (defun gnus-summary-edit-global-kill (article)
10563   "Edit the \"global\" kill file."
10564   (interactive (list (gnus-summary-article-number)))
10565   (gnus-group-edit-global-kill article))
10566
10567 (defun gnus-summary-edit-local-kill ()
10568   "Edit a local kill file applied to the current newsgroup."
10569   (interactive)
10570   (setq gnus-current-headers (gnus-summary-article-header))
10571   (gnus-group-edit-local-kill
10572    (gnus-summary-article-number) gnus-newsgroup-name))
10573
10574 ;;; Header reading.
10575
10576 (defun gnus-read-header (id &optional header)
10577   "Read the headers of article ID and enter them into the Gnus system."
10578   (let ((group gnus-newsgroup-name)
10579         (gnus-override-method
10580          (or
10581           gnus-override-method
10582           (and (gnus-news-group-p gnus-newsgroup-name)
10583                (car (gnus-refer-article-methods)))))
10584         where)
10585     ;; First we check to see whether the header in question is already
10586     ;; fetched.
10587     (if (stringp id)
10588         ;; This is a Message-ID.
10589         (setq header (or header (gnus-id-to-header id)))
10590       ;; This is an article number.
10591       (setq header (or header (gnus-summary-article-header id))))
10592     (if (and header
10593              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10594         ;; We have found the header.
10595         header
10596       ;; If this is a sparse article, we have to nix out its
10597       ;; previous entry in the thread hashtb.
10598       (when (and header
10599                  (gnus-summary-article-sparse-p (mail-header-number header)))
10600         (let* ((parent (gnus-parent-id (mail-header-references header)))
10601                (thread (and parent (gnus-id-to-thread parent))))
10602           (when thread
10603             (delq (assq header thread) thread))))
10604       ;; We have to really fetch the header to this article.
10605       (save-excursion
10606         (set-buffer nntp-server-buffer)
10607         (when (setq where (gnus-request-head id group))
10608           (nnheader-fold-continuation-lines)
10609           (goto-char (point-max))
10610           (insert ".\n")
10611           (goto-char (point-min))
10612           (insert "211 ")
10613           (princ (cond
10614                   ((numberp id) id)
10615                   ((cdr where) (cdr where))
10616                   (header (mail-header-number header))
10617                   (t gnus-reffed-article-number))
10618                  (current-buffer))
10619           (insert " Article retrieved.\n"))
10620         (if (or (not where)
10621                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10622             ()                          ; Malformed head.
10623           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10624             (when (and (stringp id)
10625                        (not (string= (gnus-group-real-name group)
10626                                      (car where))))
10627               ;; If we fetched by Message-ID and the article came
10628               ;; from a different group, we fudge some bogus article
10629               ;; numbers for this article.
10630               (mail-header-set-number header gnus-reffed-article-number))
10631             (save-excursion
10632               (set-buffer gnus-summary-buffer)
10633               (decf gnus-reffed-article-number)
10634               (gnus-remove-header (mail-header-number header))
10635               (push header gnus-newsgroup-headers)
10636               (setq gnus-current-headers header)
10637               (push (mail-header-number header) gnus-newsgroup-limit)))
10638           header)))))
10639
10640 (defun gnus-remove-header (number)
10641   "Remove header NUMBER from `gnus-newsgroup-headers'."
10642   (if (and gnus-newsgroup-headers
10643            (= number (mail-header-number (car gnus-newsgroup-headers))))
10644       (pop gnus-newsgroup-headers)
10645     (let ((headers gnus-newsgroup-headers))
10646       (while (and (cdr headers)
10647                   (not (= number (mail-header-number (cadr headers)))))
10648         (pop headers))
10649       (when (cdr headers)
10650         (setcdr headers (cddr headers))))))
10651
10652 ;;;
10653 ;;; summary highlights
10654 ;;;
10655
10656 (defun gnus-highlight-selected-summary ()
10657   "Highlight selected article in summary buffer."
10658   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10659   (when gnus-summary-selected-face
10660     (save-excursion
10661       (let* ((beg (progn (beginning-of-line) (point)))
10662              (end (progn (end-of-line) (point)))
10663              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10664              (from (if (get-text-property beg gnus-mouse-face-prop)
10665                        beg
10666                      (or (next-single-property-change
10667                           beg gnus-mouse-face-prop nil end)
10668                          beg)))
10669              (to
10670               (if (= from end)
10671                   (- from 2)
10672                 (or (next-single-property-change
10673                      from gnus-mouse-face-prop nil end)
10674                     end))))
10675         ;; If no mouse-face prop on line we will have to = from = end,
10676         ;; so we highlight the entire line instead.
10677         (when (= (+ to 2) from)
10678           (setq from beg)
10679           (setq to end))
10680         (if gnus-newsgroup-selected-overlay
10681             ;; Move old overlay.
10682             (gnus-move-overlay
10683              gnus-newsgroup-selected-overlay from to (current-buffer))
10684           ;; Create new overlay.
10685           (gnus-overlay-put
10686            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10687            'face gnus-summary-selected-face))))))
10688
10689 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10690 (defun gnus-summary-highlight-line ()
10691   "Highlight current line according to `gnus-summary-highlight'."
10692   (let* ((list gnus-summary-highlight)
10693          (p (point))
10694          (end (progn (end-of-line) (point)))
10695          ;; now find out where the line starts and leave point there.
10696          (beg (progn (beginning-of-line) (point)))
10697          (article (gnus-summary-article-number))
10698          (score (or (cdr (assq (or article gnus-current-article)
10699                                gnus-newsgroup-scored))
10700                     gnus-summary-default-score 0))
10701          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10702          (inhibit-read-only t))
10703     ;; Eval the cars of the lists until we find a match.
10704     (let ((default gnus-summary-default-score)
10705           (default-high gnus-summary-default-high-score)
10706           (default-low gnus-summary-default-low-score))
10707       (while (and list
10708                   (not (eval (caar list))))
10709         (setq list (cdr list))))
10710     (let ((face (cdar list)))
10711       (unless (eq face (get-text-property beg 'face))
10712         (gnus-put-text-property-excluding-characters-with-faces
10713          beg end 'face
10714          (setq face (if (boundp face) (symbol-value face) face)))
10715         (when gnus-summary-highlight-line-function
10716           (funcall gnus-summary-highlight-line-function article face))))
10717     (goto-char p)))
10718
10719 (defun gnus-update-read-articles (group unread &optional compute)
10720   "Update the list of read articles in GROUP.
10721 UNREAD is a sorted list."
10722   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10723          (entry (gnus-gethash group gnus-newsrc-hashtb))
10724          (info (nth 2 entry))
10725          (prev 1)
10726          read)
10727     (if (or (not info) (not active))
10728         ;; There is no info on this group if it was, in fact,
10729         ;; killed.  Gnus stores no information on killed groups, so
10730         ;; there's nothing to be done.
10731         ;; One could store the information somewhere temporarily,
10732         ;; perhaps...  Hmmm...
10733         ()
10734       ;; Remove any negative articles numbers.
10735       (while (and unread (< (car unread) 0))
10736         (setq unread (cdr unread)))
10737       ;; Remove any expired article numbers
10738       (while (and unread (< (car unread) (car active)))
10739         (setq unread (cdr unread)))
10740       ;; Compute the ranges of read articles by looking at the list of
10741       ;; unread articles.
10742       (while unread
10743         (when (/= (car unread) prev)
10744           (push (if (= prev (1- (car unread))) prev
10745                   (cons prev (1- (car unread))))
10746                 read))
10747         (setq prev (1+ (car unread)))
10748         (setq unread (cdr unread)))
10749       (when (<= prev (cdr active))
10750         (push (cons prev (cdr active)) read))
10751       (setq read (if (> (length read) 1) (nreverse read) read))
10752       (if compute
10753           read
10754         (save-excursion
10755           (let (setmarkundo)
10756             ;; Propagate the read marks to the backend.
10757             (when (gnus-check-backend-function 'request-set-mark group)
10758               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10759                     (add (gnus-remove-from-range read (gnus-info-read info))))
10760                 (when (or add del)
10761                   (unless (gnus-check-group group)
10762                     (error "Can't open server for %s" group))
10763                   (gnus-request-set-mark
10764                    group (delq nil (list (if add (list add 'add '(read)))
10765                                          (if del (list del 'del '(read))))))
10766                   (setq setmarkundo
10767                         `(gnus-request-set-mark
10768                           ,group
10769                           ',(delq nil (list
10770                                        (if del (list del 'add '(read)))
10771                                        (if add (list add 'del '(read))))))))))
10772             (set-buffer gnus-group-buffer)
10773             (gnus-undo-register
10774               `(progn
10775                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10776                  (gnus-info-set-read ',info ',(gnus-info-read info))
10777                  (gnus-get-unread-articles-in-group ',info
10778                                                     (gnus-active ,group))
10779                  (gnus-group-update-group ,group t)
10780                  ,setmarkundo))))
10781         ;; Enter this list into the group info.
10782         (gnus-info-set-read info read)
10783         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10784         (gnus-get-unread-articles-in-group info (gnus-active group))
10785         t))))
10786
10787 (defun gnus-offer-save-summaries ()
10788   "Offer to save all active summary buffers."
10789   (let (buffers)
10790     ;; Go through all buffers and find all summaries.
10791     (dolist (buffer (buffer-list))
10792       (when (and (setq buffer (buffer-name buffer))
10793                  (string-match "Summary" buffer)
10794                  (save-excursion
10795                    (set-buffer buffer)
10796                    ;; We check that this is, indeed, a summary buffer.
10797                    (and (eq major-mode 'gnus-summary-mode)
10798                         ;; Also make sure this isn't bogus.
10799                         gnus-newsgroup-prepared
10800                         ;; Also make sure that this isn't a
10801                         ;; dead summary buffer.
10802                         (not gnus-dead-summary-mode))))
10803         (push buffer buffers)))
10804     ;; Go through all these summary buffers and offer to save them.
10805     (when buffers
10806       (save-excursion
10807         (map-y-or-n-p
10808          "Update summary buffer %s? "
10809          (lambda (buf)
10810            (switch-to-buffer buf)
10811            (gnus-summary-exit))
10812          buffers)))))
10813
10814
10815 ;;; @ for mime-partial
10816 ;;;
10817
10818 (defun gnus-request-partial-message ()
10819   (save-excursion
10820     (let ((number (gnus-summary-article-number))
10821           (group gnus-newsgroup-name)
10822           (mother gnus-article-buffer))
10823       (set-buffer (get-buffer-create " *Partial Article*"))
10824       (erase-buffer)
10825       (setq mime-preview-buffer mother)
10826       (gnus-request-article-this-buffer number group)
10827       (mime-parse-buffer)
10828       )))
10829
10830 (autoload 'mime-combine-message/partial-pieces-automatically
10831   "mime-partial"
10832   "Internal method to combine message/partial messages automatically.")
10833
10834 (mime-add-condition
10835  'action '((type . message)(subtype . partial)
10836            (major-mode . gnus-original-article-mode)
10837            (method . mime-combine-message/partial-pieces-automatically)
10838            (summary-buffer-exp . gnus-summary-buffer)
10839            (request-partial-message-method . gnus-request-partial-message)
10840            ))
10841
10842
10843 ;;; @ for message/rfc822
10844 ;;;
10845
10846 (defun gnus-mime-extract-message/rfc822 (entity situation)
10847   "Burst a forwarded article."
10848   (save-excursion
10849     (set-buffer gnus-summary-buffer)
10850     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10851                                    gnus-newsgroup-name 'gnus-group-history))
10852            (gnus-group-marked (list group))
10853            article info)
10854       (with-temp-buffer
10855         (mime-insert-entity-content entity)
10856         (setq article (gnus-request-accept-article group)))
10857       (when (and (consp article)
10858                  (numberp (setq article (cdr article))))
10859         (setq info (gnus-get-info group))
10860         (gnus-info-set-read info
10861                             (gnus-remove-from-range (gnus-info-read info)
10862                                                     (list article)))
10863         (when (string-equal group gnus-newsgroup-name)
10864           (forward-line 1)
10865           (let (gnus-show-threads)
10866             (gnus-summary-goto-subject article t))
10867           (gnus-summary-clear-mark-forward 1))
10868         (set-buffer gnus-group-buffer)
10869         (gnus-group-get-new-news-this-group nil t)))))
10870
10871 (mime-add-condition
10872  'action '((type . message)(subtype . rfc822)
10873            (major-mode . gnus-original-article-mode)
10874            (method . gnus-mime-extract-message/rfc822)
10875            (mode . "extract")
10876            ))
10877
10878 (mime-add-condition
10879  'action '((type . message)(subtype . news)
10880            (major-mode . gnus-original-article-mode)
10881            (method . gnus-mime-extract-message/rfc822)
10882            (mode . "extract")
10883            ))
10884
10885 (defun gnus-mime-extract-multipart (entity situation)
10886   (let ((children (mime-entity-children entity))
10887         mime-acting-situation-to-override
10888         f)
10889     (while children
10890       (mime-play-entity (car children)
10891                         (cons (assq 'mode situation)
10892                               mime-acting-situation-to-override))
10893       (setq children (cdr children)))
10894     (if (setq f (cdr (assq 'after-method
10895                            mime-acting-situation-to-override)))
10896         (eval f)
10897       )))
10898
10899 (mime-add-condition
10900  'action '((type . multipart)
10901            (method . gnus-mime-extract-multipart)
10902            (mode . "extract")
10903            )
10904  'with-default)
10905
10906
10907 ;;; @ end
10908 ;;;
10909
10910 (defun gnus-summary-setup-default-charset ()
10911   "Setup newsgroup default charset."
10912   (if (equal gnus-newsgroup-name "nndraft:drafts")
10913       (setq gnus-newsgroup-charset nil)
10914     (let* ((ignored-charsets
10915             (or gnus-newsgroup-ephemeral-ignored-charsets
10916                 (append
10917                  (and gnus-newsgroup-name
10918                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10919                  gnus-newsgroup-ignored-charsets))))
10920       (setq gnus-newsgroup-charset
10921             (or gnus-newsgroup-ephemeral-charset
10922                 (and gnus-newsgroup-name
10923                      (gnus-parameter-charset gnus-newsgroup-name))
10924                 gnus-default-charset))
10925       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10926            ignored-charsets))))
10927
10928 ;;;
10929 ;;; Mime Commands
10930 ;;;
10931
10932 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10933   "Display the current article buffer fully MIME-buttonized.
10934 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10935 treated as multipart/mixed."
10936   (interactive "P")
10937   (require 'gnus-art)
10938   (let ((gnus-unbuttonized-mime-types nil)
10939         (gnus-mime-display-multipart-as-mixed show-all-parts))
10940     (gnus-summary-show-article)))
10941
10942 (defun gnus-summary-repair-multipart (article)
10943   "Add a Content-Type header to a multipart article without one."
10944   (interactive (list (gnus-summary-article-number)))
10945   (gnus-with-article article
10946     (message-narrow-to-head)
10947     (message-remove-header "Mime-Version")
10948     (goto-char (point-max))
10949     (insert "Mime-Version: 1.0\n")
10950     (widen)
10951     (when (search-forward "\n--" nil t)
10952       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10953         (message-narrow-to-head)
10954         (message-remove-header "Content-Type")
10955         (goto-char (point-max))
10956         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10957                         separator))
10958         (widen))))
10959   (let (gnus-mark-article-hook)
10960     (gnus-summary-select-article t t nil article)))
10961
10962 (defun gnus-summary-toggle-display-buttonized ()
10963   "Toggle the buttonizing of the article buffer."
10964   (interactive)
10965   (require 'gnus-art)
10966   (if (setq gnus-inhibit-mime-unbuttonizing
10967             (not gnus-inhibit-mime-unbuttonizing))
10968       (let ((gnus-unbuttonized-mime-types nil))
10969         (gnus-summary-show-article))
10970     (gnus-summary-show-article)))
10971
10972 ;;;
10973 ;;; Intelli-mouse commmands
10974 ;;;
10975
10976 (defun gnus-wheel-summary-scroll (event)
10977   (interactive "e")
10978   (let ((amount (if (memq 'shift (event-modifiers event))
10979                     (car gnus-wheel-scroll-amount)
10980                   (cdr gnus-wheel-scroll-amount)))
10981         (direction (- (* (static-if (featurep 'xemacs)
10982                              (event-button event)
10983                            (cond ((eq 'mouse-4 (event-basic-type event))
10984                                   4)
10985                                  ((eq 'mouse-5 (event-basic-type event))
10986                                   5)))
10987                          2) 9))
10988         edge)
10989     (gnus-summary-scroll-up (* amount direction))
10990     (when (gnus-eval-in-buffer-window gnus-article-buffer
10991             (save-restriction
10992               (widen)
10993               (and (if (< 0 direction)
10994                        (gnus-article-next-page 0)
10995                      (gnus-article-prev-page 0)
10996                      (bobp))
10997                    (if (setq edge (get-text-property
10998                                    (point-min) 'gnus-wheel-edge))
10999                        (setq edge (* edge direction))
11000                      (setq edge -1))
11001                    (or (plusp edge)
11002                        (let ((buffer-read-only nil)
11003                              (inhibit-read-only t))
11004                          (put-text-property (point-min) (point-max)
11005                                             'gnus-wheel-edge direction)
11006                          nil))
11007                    (or (> edge gnus-wheel-edge-resistance)
11008                        (let ((buffer-read-only nil)
11009                              (inhibit-read-only t))
11010                          (put-text-property (point-min) (point-max)
11011                                             'gnus-wheel-edge
11012                                             (* (1+ edge) direction))
11013                          nil))
11014                    (eq last-command 'gnus-wheel-summary-scroll))))
11015       (gnus-summary-next-article nil nil (minusp direction)))))
11016
11017 (defun gnus-wheel-install ()
11018   "Enable mouse wheel support on summary window."
11019   (when gnus-use-wheel
11020     (let ((keys
11021            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11022       (dolist (key keys)
11023         (define-key gnus-summary-mode-map key
11024           'gnus-wheel-summary-scroll)))))
11025
11026 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11027
11028 ;;;
11029 ;;; Traditional PGP commmands
11030 ;;;
11031
11032 (defun gnus-summary-decrypt-article (&optional force)
11033   "Decrypt the current article in traditional PGP way.
11034 This will have permanent effect only in mail groups.
11035 If FORCE is non-nil, allow editing of articles even in read-only
11036 groups."
11037   (interactive "P")
11038   (gnus-summary-select-article t)
11039   (gnus-eval-in-buffer-window gnus-article-buffer
11040     (save-excursion
11041       (save-restriction
11042         (widen)
11043         (goto-char (point-min))
11044         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11045           (error "Not a traditional PGP message!"))
11046         (let ((armor-start (match-beginning 0)))
11047           (if (and (pgg-decrypt-region armor-start (point-max))
11048                    (or force (not (gnus-group-read-only-p))))
11049               (let ((inhibit-read-only t)
11050                     buffer-read-only)
11051                 (delete-region armor-start
11052                                (progn
11053                                  (re-search-forward "^-+END PGP" nil t)
11054                                  (beginning-of-line 2)
11055                                  (point)))
11056                 (insert-buffer-substring pgg-output-buffer))))))))
11057
11058 (defun gnus-summary-verify-article ()
11059   "Verify the current article in traditional PGP way."
11060   (interactive)
11061   (save-excursion
11062     (set-buffer gnus-original-article-buffer)
11063     (goto-char (point-min))
11064     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11065       (error "Not a traditional PGP message!"))
11066     (re-search-forward "^-+END PGP" nil t)
11067     (beginning-of-line 2)
11068     (call-interactively (function pgg-verify-region))))
11069
11070 ;;;
11071 ;;; Generic summary marking commands
11072 ;;;
11073
11074 (defvar gnus-summary-marking-alist
11075   '((read gnus-del-mark "d")
11076     (unread gnus-unread-mark "u")
11077     (ticked gnus-ticked-mark "!")
11078     (dormant gnus-dormant-mark "?")
11079     (expirable gnus-expirable-mark "e"))
11080   "An alist of names/marks/keystrokes.")
11081
11082 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11083 (defvar gnus-summary-mark-map)
11084
11085 (defun gnus-summary-make-all-marking-commands ()
11086   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11087   (dolist (elem gnus-summary-marking-alist)
11088     (apply 'gnus-summary-make-marking-command elem)))
11089
11090 (defun gnus-summary-make-marking-command (name mark keystroke)
11091   (let ((map (make-sparse-keymap)))
11092     (define-key gnus-summary-generic-mark-map keystroke map)
11093     (dolist (lway `((next "next" next nil "n")
11094                     (next-unread "next unread" next t "N")
11095                     (prev "previous" prev nil "p")
11096                     (prev-unread "previous unread" prev t "P")
11097                     (nomove "" nil nil ,keystroke)))
11098       (let ((func (gnus-summary-make-marking-command-1
11099                    mark (car lway) lway name)))
11100         (setq func (eval func))
11101         (define-key map (nth 4 lway) func)))))
11102
11103 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11104   `(defun ,(intern
11105             (format "gnus-summary-put-mark-as-%s%s"
11106                     name (if (eq way 'nomove)
11107                              ""
11108                            (concat "-" (symbol-name way)))))
11109      (n)
11110      ,(format
11111        "Mark the current article as %s%s.
11112 If N, the prefix, then repeat N times.
11113 If N is negative, move in reverse order.
11114 The difference between N and the actual number of articles marked is
11115 returned."
11116        name (car (cdr lway)))
11117      (interactive "p")
11118      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11119
11120 (defun gnus-summary-generic-mark (n mark move unread)
11121   "Mark N articles with MARK."
11122   (unless (eq major-mode 'gnus-summary-mode)
11123     (error "This command can only be used in the summary buffer"))
11124   (gnus-summary-show-thread)
11125   (let ((nummove
11126          (cond
11127           ((eq move 'next) 1)
11128           ((eq move 'prev) -1)
11129           (t 0))))
11130     (if (zerop nummove)
11131         (setq n 1)
11132       (when (< n 0)
11133         (setq n (abs n)
11134               nummove (* -1 nummove))))
11135     (while (and (> n 0)
11136                 (gnus-summary-mark-article nil mark)
11137                 (zerop (gnus-summary-next-subject nummove unread t)))
11138       (setq n (1- n)))
11139     (when (/= 0 n)
11140       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11141     (gnus-summary-recenter)
11142     (gnus-summary-position-point)
11143     (gnus-set-mode-line 'summary)
11144     n))
11145
11146 (defun gnus-summary-insert-articles (articles)
11147   (when (setq articles
11148               (gnus-sorted-difference articles
11149                                       (mapcar (lambda (h)
11150                                                 (mail-header-number h))
11151                                               gnus-newsgroup-headers)))
11152     (setq gnus-newsgroup-headers
11153           (merge 'list
11154                  gnus-newsgroup-headers
11155                  (gnus-fetch-headers articles)
11156                  'gnus-article-sort-by-number))
11157     ;; Suppress duplicates?
11158     (when gnus-suppress-duplicates
11159       (gnus-dup-suppress-articles))
11160
11161     ;; We might want to build some more threads first.
11162     (when (and gnus-fetch-old-headers
11163                (eq gnus-headers-retrieved-by 'nov))
11164       (if (eq gnus-fetch-old-headers 'invisible)
11165           (gnus-build-all-threads)
11166         (gnus-build-old-threads)))
11167     ;; Let the Gnus agent mark articles as read.
11168     (when gnus-agent
11169       (gnus-agent-get-undownloaded-list))
11170     ;; Remove list identifiers from subject
11171     (when gnus-list-identifiers
11172       (gnus-summary-remove-list-identifiers))
11173     ;; First and last article in this newsgroup.
11174     (when gnus-newsgroup-headers
11175       (setq gnus-newsgroup-begin
11176             (mail-header-number (car gnus-newsgroup-headers))
11177             gnus-newsgroup-end
11178             (mail-header-number
11179              (gnus-last-element gnus-newsgroup-headers))))
11180     (when gnus-use-scoring
11181       (gnus-possibly-score-headers))))
11182
11183 (defun gnus-summary-insert-old-articles (&optional all)
11184   "Insert all old articles in this group.
11185 If ALL is non-nil, already read articles become readable.
11186 If ALL is a number, fetch this number of articles."
11187   (interactive "P")
11188   (prog1
11189       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11190             older len)
11191         (setq older
11192               (gnus-sorted-difference
11193                (gnus-uncompress-range (list gnus-newsgroup-active))
11194                old))
11195         (setq len (length older))
11196         (cond
11197          ((null older) nil)
11198          ((numberp all)
11199           (if (< all len)
11200               (setq older (last older all))))
11201          (all nil)
11202          (t
11203           (if (and (numberp gnus-large-newsgroup)
11204                    (> len gnus-large-newsgroup))
11205               (let ((input
11206                      (read-string
11207                       (format
11208                        "How many articles from %s (default %d): "
11209                        (gnus-limit-string
11210                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
11211                        len))))
11212                 (unless (string-match "^[ \t]*$" input)
11213                   (setq all (string-to-number input))
11214                   (if (< all len)
11215                       (setq older (last older all))))))))
11216         (if (not older)
11217             (message "No old news.")
11218           (gnus-summary-insert-articles older)
11219           (gnus-summary-limit (gnus-sorted-nunion old older))))
11220     (gnus-summary-position-point)))
11221
11222 (defun gnus-summary-insert-new-articles ()
11223   "Insert all new articles in this group."
11224   (interactive)
11225   (prog1
11226       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11227             (old-active gnus-newsgroup-active)
11228             (nnmail-fetched-sources (list t))
11229             i new)
11230         (setq gnus-newsgroup-active
11231               (gnus-activate-group gnus-newsgroup-name 'scan))
11232         (setq i (1+ (cdr old-active)))
11233         (while (<= i (cdr gnus-newsgroup-active))
11234           (push i new)
11235           (incf i))
11236         (if (not new)
11237             (message "No gnus is bad news.")
11238           (setq new (nreverse new))
11239           (gnus-summary-insert-articles new)
11240           (setq gnus-newsgroup-unreads
11241                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11242           (gnus-summary-limit (gnus-sorted-nunion old new))))
11243     (gnus-summary-position-point)))
11244
11245 (gnus-summary-make-all-marking-commands)
11246
11247 (gnus-ems-redefine)
11248
11249 (provide 'gnus-sum)
11250
11251 (run-hooks 'gnus-sum-load-hook)
11252
11253 ;;; gnus-sum.el ends here