d7f6a8ed68f625da290c77d78dbbcdba033a6f0e
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58
59 (defcustom gnus-kill-summary-on-exit t
60   "*If non-nil, kill the summary buffer when you exit from it.
61 If nil, the summary will become a \"*Dead Summary*\" buffer, and
62 it will be killed sometime later."
63   :group 'gnus-summary-exit
64   :type 'boolean)
65
66 (defcustom gnus-fetch-old-headers nil
67   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
68 If an unread article in the group refers to an older, already read (or
69 just marked as read) article, the old article will not normally be
70 displayed in the Summary buffer.  If this variable is non-nil, Gnus
71 will attempt to grab the headers to the old articles, and thereby
72 build complete threads.  If it has the value `some', only enough
73 headers to connect otherwise loose threads will be displayed.  This
74 variable can also be a number.  In that case, no more than that number
75 of old headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work."
79   :group 'gnus-thread
80   :type '(choice (const :tag "off" nil)
81                  (const some)
82                  number
83                  (sexp :menu-tag "other" t)))
84
85 (defcustom gnus-refer-thread-limit 200
86   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
87 If t, fetch all the available old headers."
88   :group 'gnus-thread
89   :type '(choice number
90                  (sexp :menu-tag "other" t)))
91
92 (defcustom gnus-summary-make-false-root 'adopt
93   "*nil means that Gnus won't gather loose threads.
94 If the root of a thread has expired or been read in a previous
95 session, the information necessary to build a complete thread has been
96 lost.  Instead of having many small sub-threads from this original thread
97 scattered all over the summary buffer, Gnus can gather them.
98
99 If non-nil, Gnus will try to gather all loose sub-threads from an
100 original thread into one large thread.
101
102 If this variable is non-nil, it should be one of `none', `adopt',
103 `dummy' or `empty'.
104
105 If this variable is `none', Gnus will not make a false root, but just
106 present the sub-threads after another.
107 If this variable is `dummy', Gnus will create a dummy root that will
108 have all the sub-threads as children.
109 If this variable is `adopt', Gnus will make one of the \"children\"
110 the parent and mark all the step-children as such.
111 If this variable is `empty', the \"children\" are printed with empty
112 subject fields.  (Or rather, they will be printed with a string
113 given by the `gnus-summary-same-subject' variable.)"
114   :group 'gnus-thread
115   :type '(choice (const :tag "off" nil)
116                  (const none)
117                  (const dummy)
118                  (const adopt)
119                  (const empty)))
120
121 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
122   "*A regexp to match subjects to be excluded from loose thread gathering.
123 As loose thread gathering is done on subjects only, that means that
124 there can be many false gatherings performed.  By rooting out certain
125 common subjects, gathering might become saner."
126   :group 'gnus-thread
127   :type 'regexp)
128
129 (defcustom gnus-summary-gather-subject-limit nil
130   "*Maximum length of subject comparisons when gathering loose threads.
131 Use nil to compare full subjects.  Setting this variable to a low
132 number will help gather threads that have been corrupted by
133 newsreaders chopping off subject lines, but it might also mean that
134 unrelated articles that have subject that happen to begin with the
135 same few characters will be incorrectly gathered.
136
137 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
138 comparing subjects."
139   :group 'gnus-thread
140   :type '(choice (const :tag "off" nil)
141                  (const fuzzy)
142                  (sexp :menu-tag "on" t)))
143
144 (defcustom gnus-simplify-subject-functions nil
145   "List of functions taking a string argument that simplify subjects.
146 The functions are applied recursively.
147
148 Useful functions to put in this list include: `gnus-simplify-subject-re',
149 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
150   :group 'gnus-thread
151   :type '(repeat function))
152
153 (defcustom gnus-simplify-ignored-prefixes nil
154   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
155   :group 'gnus-thread
156   :type '(choice (const :tag "off" nil)
157                  regexp))
158
159 (defcustom gnus-build-sparse-threads nil
160   "*If non-nil, fill in the gaps in threads.
161 If `some', only fill in the gaps that are needed to tie loose threads
162 together.  If `more', fill in all leaf nodes that Gnus can find.  If
163 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
164   :group 'gnus-thread
165   :type '(choice (const :tag "off" nil)
166                  (const some)
167                  (const more)
168                  (sexp :menu-tag "all" t)))
169
170 (defcustom gnus-summary-thread-gathering-function
171   'gnus-gather-threads-by-subject
172   "*Function used for gathering loose threads.
173 There are two pre-defined functions: `gnus-gather-threads-by-subject',
174 which only takes Subjects into consideration; and
175 `gnus-gather-threads-by-references', which compared the References
176 headers of the articles to find matches."
177   :group 'gnus-thread
178   :type '(radio (function-item gnus-gather-threads-by-subject)
179                 (function-item gnus-gather-threads-by-references)
180                 (function :tag "other")))
181
182 (defcustom gnus-summary-same-subject ""
183   "*String indicating that the current article has the same subject as the previous.
184 This variable will only be used if the value of
185 `gnus-summary-make-false-root' is `empty'."
186   :group 'gnus-summary-format
187   :type 'string)
188
189 (defcustom gnus-summary-goto-unread t
190   "*If t, many commands will go to the next unread article.
191 This applies to marking commands as well as other commands that
192 \"naturally\" select the next article, like, for instance, `SPC' at
193 the end of an article.
194
195 If nil, the marking commands do NOT go to the next unread article
196 (they go to the next article instead).  If `never', commands that
197 usually go to the next unread article, will go to the next article,
198 whether it is read or not."
199   :group 'gnus-summary-marks
200   :link '(custom-manual "(gnus)Setting Marks")
201   :type '(choice (const :tag "off" nil)
202                  (const never)
203                  (sexp :menu-tag "on" t)))
204
205 (defcustom gnus-summary-default-score 0
206   "*Default article score level.
207 All scores generated by the score files will be added to this score.
208 If this variable is nil, scoring will be disabled."
209   :group 'gnus-score-default
210   :type '(choice (const :tag "disable")
211                  integer))
212
213 (defcustom gnus-summary-default-high-score 0
214   "*Default threshold for a high scored article.
215 An article will be highlighted as high scored if its score is greater
216 than this score."
217   :group 'gnus-score-default
218   :type 'integer)
219
220 (defcustom gnus-summary-default-low-score 0
221   "*Default threshold for a low scored article.
222 An article will be highlighted as low scored if its score is smaller
223 than this score."
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-zcore-fuzz 0
228   "*Fuzziness factor for the zcore in the summary buffer.
229 Articles with scores closer than this to `gnus-summary-default-score'
230 will not be marked."
231   :group 'gnus-summary-format
232   :type 'integer)
233
234 (defcustom gnus-simplify-subject-fuzzy-regexp nil
235   "*Strings to be removed when doing fuzzy matches.
236 This can either be a regular expression or list of regular expressions
237 that will be removed from subject strings if fuzzy subject
238 simplification is selected."
239   :group 'gnus-thread
240   :type '(repeat regexp))
241
242 (defcustom gnus-show-threads t
243   "*If non-nil, display threads in summary mode."
244   :group 'gnus-thread
245   :type 'boolean)
246
247 (defcustom gnus-thread-hide-subtree nil
248   "*If non-nil, hide all threads initially.
249 If threads are hidden, you have to run the command
250 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
251 to expose hidden threads."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-killed t
256   "*If non-nil, hide killed threads automatically."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-ignore-subject t
261   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
262 If nil, articles that have different subjects from their parents will
263 start separate threads."
264   :group 'gnus-thread
265   :type 'boolean)
266
267 (defcustom gnus-thread-operation-ignore-subject t
268   "*If non-nil, subjects will be ignored when doing thread commands.
269 This affects commands like `gnus-summary-kill-thread' and
270 `gnus-summary-lower-thread'.
271
272 If this variable is nil, articles in the same thread with different
273 subjects will not be included in the operation in question.  If this
274 variable is `fuzzy', only articles that have subjects that are fuzzily
275 equal will be included."
276   :group 'gnus-thread
277   :type '(choice (const :tag "off" nil)
278                  (const fuzzy)
279                  (sexp :tag "on" t)))
280
281 (defcustom gnus-thread-indent-level 4
282   "*Number that says how much each sub-thread should be indented."
283   :group 'gnus-thread
284   :type 'integer)
285
286 (defcustom gnus-auto-extend-newsgroup t
287   "*If non-nil, extend newsgroup forward and backward when requested."
288   :group 'gnus-summary-choose
289   :type 'boolean)
290
291 (defcustom gnus-auto-select-first t
292   "*If non-nil, select the article under point.
293 Which article this is is controlled by the `gnus-auto-select-subject'
294 variable.
295
296 If you want to prevent automatic selection of articles in some
297 newsgroups, set the variable to nil in `gnus-select-group-hook'."
298   :group 'gnus-group-select
299   :type '(choice (const :tag "none" nil)
300                  (sexp :menu-tag "first" t)))
301
302 (defcustom gnus-auto-select-subject 'unread
303   "*Says what subject to place under point when entering a group.
304
305 This variable can either be the symbols `first' (place point on the
306 first subject), `unread' (place point on the subject line of the first
307 unread article), `best' (place point on the subject line of the
308 higest-scored article), `unseen' (place point on the subject line of
309 the first unseen article), or a function to be called to place point on
310 some subject line.."
311   :group 'gnus-group-select
312   :type '(choice (const best)
313                  (const unread)
314                  (const first)
315                  (const unseen)))
316
317 (defcustom gnus-dont-select-after-jump-to-other-group nil
318   "If non-nil, don't select the first unread article after entering the
319 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
320 it is depend on the value of `gnus-auto-select-first' whether to select
321 or not."
322   :group 'gnus-group-select
323   :type 'boolean)
324
325 (defcustom gnus-auto-select-next t
326   "*If non-nil, offer to go to the next group from the end of the previous.
327 If the value is t and the next newsgroup is empty, Gnus will exit
328 summary mode and go back to group mode.  If the value is neither nil
329 nor t, Gnus will select the following unread newsgroup.  In
330 particular, if the value is the symbol `quietly', the next unread
331 newsgroup will be selected without any confirmation, and if it is
332 `almost-quietly', the next group will be selected without any
333 confirmation if you are located on the last article in the group.
334 Finally, if this variable is `slightly-quietly', the `Z n' command
335 will go to the next group without confirmation."
336   :group 'gnus-summary-maneuvering
337   :type '(choice (const :tag "off" nil)
338                  (const quietly)
339                  (const almost-quietly)
340                  (const slightly-quietly)
341                  (sexp :menu-tag "on" t)))
342
343 (defcustom gnus-auto-select-same nil
344   "*If non-nil, select the next article with the same subject.
345 If there are no more articles with the same subject, go to
346 the first unread article."
347   :group 'gnus-summary-maneuvering
348   :type 'boolean)
349
350 (defcustom gnus-summary-check-current nil
351   "*If non-nil, consider the current article when moving.
352 The \"unread\" movement commands will stay on the same line if the
353 current article is unread."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-auto-center-summary t
358   "*If non-nil, always center the current summary buffer.
359 In particular, if `vertical' do only vertical recentering.  If non-nil
360 and non-`vertical', do both horizontal and vertical recentering."
361   :group 'gnus-summary-maneuvering
362   :type '(choice (const :tag "none" nil)
363                  (const vertical)
364                  (integer :tag "height")
365                  (sexp :menu-tag "both" t)))
366
367 (defcustom gnus-show-all-headers nil
368   "*If non-nil, don't hide any headers."
369   :group 'gnus-article-hiding
370   :group 'gnus-article-headers
371   :type 'boolean)
372
373 (defcustom gnus-summary-ignore-duplicates nil
374   "*If non-nil, ignore articles with identical Message-ID headers."
375   :group 'gnus-summary
376   :type 'boolean)
377
378 (defcustom gnus-single-article-buffer t
379   "*If non-nil, display all articles in the same buffer.
380 If nil, each group will get its own article buffer."
381   :group 'gnus-article-various
382   :type 'boolean)
383
384 (defcustom gnus-break-pages t
385   "*If non-nil, do page breaking on articles.
386 The page delimiter is specified by the `gnus-page-delimiter'
387 variable."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-show-mime t
392   "*If non-nil, do mime processing of articles.
393 The articles will simply be fed to the function given by
394 `gnus-article-display-method-for-mime'."
395   :group 'gnus-article-mime
396   :type 'boolean)
397
398 (defcustom gnus-move-split-methods nil
399   "*Variable used to suggest where articles are to be moved to.
400 It uses the same syntax as the `gnus-split-methods' variable.
401 However, whereas `gnus-split-methods' specifies file names as targets,
402 this variable specifies group names."
403   :group 'gnus-summary-mail
404   :type '(repeat (choice (list :value (fun) function)
405                          (cons :value ("" "") regexp (repeat string))
406                          (sexp :value nil))))
407
408 (defcustom gnus-unread-mark ?\ ;;;Whitespace
409   "*Mark used for unread articles."
410   :group 'gnus-summary-marks
411   :type 'character)
412
413 (defcustom gnus-ticked-mark ?!
414   "*Mark used for ticked articles."
415   :group 'gnus-summary-marks
416   :type 'character)
417
418 (defcustom gnus-dormant-mark ??
419   "*Mark used for dormant articles."
420   :group 'gnus-summary-marks
421   :type 'character)
422
423 (defcustom gnus-del-mark ?r
424   "*Mark used for del'd articles."
425   :group 'gnus-summary-marks
426   :type 'character)
427
428 (defcustom gnus-read-mark ?R
429   "*Mark used for read articles."
430   :group 'gnus-summary-marks
431   :type 'character)
432
433 (defcustom gnus-expirable-mark ?E
434   "*Mark used for expirable articles."
435   :group 'gnus-summary-marks
436   :type 'character)
437
438 (defcustom gnus-killed-mark ?K
439   "*Mark used for killed articles."
440   :group 'gnus-summary-marks
441   :type 'character)
442
443 (defcustom gnus-souped-mark ?F
444   "*Mark used for souped articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-kill-file-mark ?X
449   "*Mark used for articles killed by kill files."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-low-score-mark ?Y
454   "*Mark used for articles with a low score."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-catchup-mark ?C
459   "*Mark used for articles that are caught up."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-replied-mark ?A
464   "*Mark used for articles that have been replied to."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-forwarded-mark ?F
469   "*Mark used for articles that have been forwarded."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-recent-mark ?N
474   "*Mark used for articles that are recent."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-cached-mark ?*
479   "*Mark used for articles that are in the cache."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-saved-mark ?S
484   "*Mark used for articles that have been saved."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-unseen-mark ?.
489   "*Mark used for articles that haven't been seen."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-no-mark ?\ ;;;Whitespace
494   "*Mark used for articles that have no other secondary mark."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-ancient-mark ?O
499   "*Mark used for ancient articles."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-sparse-mark ?Q
504   "*Mark used for sparsely reffed articles."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-canceled-mark ?G
509   "*Mark used for canceled articles."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-duplicate-mark ?M
514   "*Mark used for duplicate articles."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-undownloaded-mark ?@
519   "*Mark used for articles that weren't downloaded."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-downloadable-mark ?%
524   "*Mark used for articles that are to be downloaded."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-unsendable-mark ?=
529   "*Mark used for articles that won't be sent."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-score-over-mark ?+
534   "*Score mark used for articles with high scores."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-score-below-mark ?-
539   "*Score mark used for articles with low scores."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
544   "*There is no thread under the article."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-not-empty-thread-mark ?=
549   "*There is a thread under the article."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-view-pseudo-asynchronously nil
554   "*If non-nil, Gnus will view pseudo-articles asynchronously."
555   :group 'gnus-extract-view
556   :type 'boolean)
557
558 (defcustom gnus-auto-expirable-marks
559   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
560         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
561         gnus-souped-mark gnus-duplicate-mark)
562   "*The list of marks converted into expiration if a group is auto-expirable."
563   :version "21.1"
564   :group 'gnus-summary
565   :type '(repeat character))
566
567 (defcustom gnus-inhibit-user-auto-expire t
568   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
569   :version "21.1"
570   :group 'gnus-summary
571   :type 'boolean)
572
573 (defcustom gnus-view-pseudos nil
574   "*If `automatic', pseudo-articles will be viewed automatically.
575 If `not-confirm', pseudos will be viewed automatically, and the user
576 will not be asked to confirm the command."
577   :group 'gnus-extract-view
578   :type '(choice (const :tag "off" nil)
579                  (const automatic)
580                  (const not-confirm)))
581
582 (defcustom gnus-view-pseudos-separately t
583   "*If non-nil, one pseudo-article will be created for each file to be viewed.
584 If nil, all files that use the same viewing command will be given as a
585 list of parameters to that command."
586   :group 'gnus-extract-view
587   :type 'boolean)
588
589 (defcustom gnus-insert-pseudo-articles t
590   "*If non-nil, insert pseudo-articles when decoding articles."
591   :group 'gnus-extract-view
592   :type 'boolean)
593
594 (defcustom gnus-summary-dummy-line-format
595   "  %(:                          :%) %S\n"
596   "*The format specification for the dummy roots in the summary buffer.
597 It works along the same lines as a normal formatting string,
598 with some simple extensions.
599
600 %S  The subject"
601   :group 'gnus-threading
602   :type 'string)
603
604 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
605   "*The format specification for the summary mode line.
606 It works along the same lines as a normal formatting string,
607 with some simple extensions:
608
609 %G  Group name
610 %p  Unprefixed group name
611 %A  Current article number
612 %z  Current article score
613 %V  Gnus version
614 %U  Number of unread articles in the group
615 %e  Number of unselected articles in the group
616 %Z  A string with unread/unselected article counts
617 %g  Shortish group name
618 %S  Subject of the current article
619 %u  User-defined spec
620 %s  Current score file name
621 %d  Number of dormant articles
622 %r  Number of articles that have been marked as read in this session
623 %E  Number of articles expunged by the score files"
624   :group 'gnus-summary-format
625   :type 'string)
626
627 (defcustom gnus-list-identifiers nil
628   "Regexp that matches list identifiers to be removed from subject.
629 This can also be a list of regexps."
630   :version "21.1"
631   :group 'gnus-summary-format
632   :group 'gnus-article-hiding
633   :type '(choice (const :tag "none" nil)
634                  (regexp :value ".*")
635                  (repeat :value (".*") regexp)))
636
637 (defcustom gnus-summary-mark-below 0
638   "*Mark all articles with a score below this variable as read.
639 This variable is local to each summary buffer and usually set by the
640 score file."
641   :group 'gnus-score-default
642   :type 'integer)
643
644 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
645   "*List of functions used for sorting articles in the summary buffer.
646
647 Each function takes two articles and returns non-nil if the first
648 article should be sorted before the other.  If you use more than one
649 function, the primary sort function should be the last.  You should
650 probably always include `gnus-article-sort-by-number' in the list of
651 sorting functions -- preferably first.  Also note that sorting by date
652 is often much slower than sorting by number, and the sorting order is
653 very similar.  (Sorting by date means sorting by the time the message
654 was sent, sorting by number means sorting by arrival time.)
655
656 Ready-made functions include `gnus-article-sort-by-number',
657 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
658 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
659
660 When threading is turned on, the variable `gnus-thread-sort-functions'
661 controls how articles are sorted."
662   :group 'gnus-summary-sort
663   :type '(repeat (choice (function-item gnus-article-sort-by-number)
664                          (function-item gnus-article-sort-by-author)
665                          (function-item gnus-article-sort-by-subject)
666                          (function-item gnus-article-sort-by-date)
667                          (function-item gnus-article-sort-by-score)
668                          (function :tag "other"))))
669
670 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
671   "*List of functions used for sorting threads in the summary buffer.
672 By default, threads are sorted by article number.
673
674 Each function takes two threads and returns non-nil if the first
675 thread should be sorted before the other.  If you use more than one
676 function, the primary sort function should be the last.  You should
677 probably always include `gnus-thread-sort-by-number' in the list of
678 sorting functions -- preferably first.  Also note that sorting by date
679 is often much slower than sorting by number, and the sorting order is
680 very similar.  (Sorting by date means sorting by the time the message
681 was sent, sorting by number means sorting by arrival time.)
682
683 Ready-made functions include `gnus-thread-sort-by-number',
684 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
685 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
686 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
687
688 When threading is turned off, the variable
689 `gnus-article-sort-functions' controls how articles are sorted."
690   :group 'gnus-summary-sort
691   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
692                          (function-item gnus-thread-sort-by-author)
693                          (function-item gnus-thread-sort-by-subject)
694                          (function-item gnus-thread-sort-by-date)
695                          (function-item gnus-thread-sort-by-score)
696                          (function-item gnus-thread-sort-by-total-score)
697                          (function :tag "other"))))
698
699 (defcustom gnus-thread-score-function '+
700   "*Function used for calculating the total score of a thread.
701
702 The function is called with the scores of the article and each
703 subthread and should then return the score of the thread.
704
705 Some functions you can use are `+', `max', or `min'."
706   :group 'gnus-summary-sort
707   :type 'function)
708
709 (defcustom gnus-summary-expunge-below nil
710   "All articles that have a score less than this variable will be expunged.
711 This variable is local to the summary buffers."
712   :group 'gnus-score-default
713   :type '(choice (const :tag "off" nil)
714                  integer))
715
716 (defcustom gnus-thread-expunge-below nil
717   "All threads that have a total score less than this variable will be expunged.
718 See `gnus-thread-score-function' for en explanation of what a
719 \"thread score\" is.
720
721 This variable is local to the summary buffers."
722   :group 'gnus-threading
723   :group 'gnus-score-default
724   :type '(choice (const :tag "off" nil)
725                  integer))
726
727 (defcustom gnus-summary-mode-hook nil
728   "*A hook for Gnus summary mode.
729 This hook is run before any variables are set in the summary buffer."
730   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
731   :group 'gnus-summary-various
732   :type 'hook)
733
734 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
735 (when (featurep 'xemacs)
736   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
737   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
738   (add-hook 'gnus-summary-mode-hook
739             'gnus-xmas-switch-horizontal-scrollbar-off))
740
741 (defcustom gnus-summary-menu-hook nil
742   "*Hook run after the creation of the summary mode menu."
743   :group 'gnus-summary-visual
744   :type 'hook)
745
746 (defcustom gnus-summary-exit-hook nil
747   "*A hook called on exit from the summary buffer.
748 It will be called with point in the group buffer."
749   :group 'gnus-summary-exit
750   :type 'hook)
751
752 (defcustom gnus-summary-prepare-hook nil
753   "*A hook called after the summary buffer has been generated.
754 If you want to modify the summary buffer, you can use this hook."
755   :group 'gnus-summary-various
756   :type 'hook)
757
758 (defcustom gnus-summary-prepared-hook nil
759   "*A hook called as the last thing after the summary buffer has been generated."
760   :group 'gnus-summary-various
761   :type 'hook)
762
763 (defcustom gnus-summary-generate-hook nil
764   "*A hook run just before generating the summary buffer.
765 This hook is commonly used to customize threading variables and the
766 like."
767   :group 'gnus-summary-various
768   :type 'hook)
769
770 (defcustom gnus-select-group-hook nil
771   "*A hook called when a newsgroup is selected.
772
773 If you'd like to simplify subjects like the
774 `gnus-summary-next-same-subject' command does, you can use the
775 following hook:
776
777  (setq gnus-select-group-hook
778       (list
779         (lambda ()
780           (mapcar (lambda (header)
781                      (mail-header-set-subject
782                       header
783                       (gnus-simplify-subject
784                        (mail-header-subject header) 're-only)))
785                   gnus-newsgroup-headers))))"
786   :group 'gnus-group-select
787   :type 'hook)
788
789 (defcustom gnus-select-article-hook nil
790   "*A hook called when an article is selected."
791   :group 'gnus-summary-choose
792   :type 'hook)
793
794 (defcustom gnus-visual-mark-article-hook
795   (list 'gnus-highlight-selected-summary)
796   "*Hook run after selecting an article in the summary buffer.
797 It is meant to be used for highlighting the article in some way.  It
798 is not run if `gnus-visual' is nil."
799   :group 'gnus-summary-visual
800   :type 'hook)
801
802 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
803   "*A hook called before parsing the headers."
804   :group 'gnus-various
805   :type 'hook)
806
807 (defcustom gnus-exit-group-hook nil
808   "*A hook called when exiting summary mode.
809 This hook is not called from the non-updating exit commands like `Q'."
810   :group 'gnus-various
811   :type 'hook)
812
813 (defcustom gnus-summary-update-hook
814   (list 'gnus-summary-highlight-line)
815   "*A hook called when a summary line is changed.
816 The hook will not be called if `gnus-visual' is nil.
817
818 The default function `gnus-summary-highlight-line' will
819 highlight the line according to the `gnus-summary-highlight'
820 variable."
821   :group 'gnus-summary-visual
822   :type 'hook)
823
824 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
825   "*A hook called when an article is selected for the first time.
826 The hook is intended to mark an article as read (or unread)
827 automatically when it is selected."
828   :group 'gnus-summary-choose
829   :type 'hook)
830
831 (defcustom gnus-group-no-more-groups-hook nil
832   "*A hook run when returning to group mode having no more (unread) groups."
833   :group 'gnus-group-select
834   :type 'hook)
835
836 (defcustom gnus-ps-print-hook nil
837   "*A hook run before ps-printing something from Gnus."
838   :group 'gnus-summary
839   :type 'hook)
840
841 (defcustom gnus-summary-display-arrow
842   (and (fboundp 'display-graphic-p)
843        (display-graphic-p))
844   "*If non-nil, display an arrow highlighting the current article."
845   :version "21.1"
846   :group 'gnus-summary
847   :type 'boolean)
848
849 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
850   "Face used for highlighting the current article in the summary buffer."
851   :group 'gnus-summary-visual
852   :type 'face)
853
854 (defcustom gnus-summary-highlight
855   '(((= mark gnus-canceled-mark)
856      . gnus-summary-cancelled-face)
857     ((and (> score default-high)
858           (or (= mark gnus-dormant-mark)
859               (= mark gnus-ticked-mark)))
860      . gnus-summary-high-ticked-face)
861     ((and (< score default-low)
862           (or (= mark gnus-dormant-mark)
863               (= mark gnus-ticked-mark)))
864      . gnus-summary-low-ticked-face)
865     ((or (= mark gnus-dormant-mark)
866          (= mark gnus-ticked-mark))
867      . gnus-summary-normal-ticked-face)
868     ((and (> score default-high) (= mark gnus-ancient-mark))
869      . gnus-summary-high-ancient-face)
870     ((and (< score default-low) (= mark gnus-ancient-mark))
871      . gnus-summary-low-ancient-face)
872     ((= mark gnus-ancient-mark)
873      . gnus-summary-normal-ancient-face)
874     ((and (> score default-high) (= mark gnus-unread-mark))
875      . gnus-summary-high-unread-face)
876     ((and (< score default-low) (= mark gnus-unread-mark))
877      . gnus-summary-low-unread-face)
878     ((= mark gnus-unread-mark)
879      . gnus-summary-normal-unread-face)
880     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
881                                                   gnus-undownloaded-mark)))
882      . gnus-summary-high-unread-face)
883     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
884                                                  gnus-undownloaded-mark)))
885      . gnus-summary-low-unread-face)
886     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
887           (memq article gnus-newsgroup-unreads))
888      . gnus-summary-normal-unread-face)
889     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
890      . gnus-summary-normal-read-face)
891     ((> score default-high)
892      . gnus-summary-high-read-face)
893     ((< score default-low)
894      . gnus-summary-low-read-face)
895     (t
896      . gnus-summary-normal-read-face))
897   "*Controls the highlighting of summary buffer lines.
898
899 A list of (FORM . FACE) pairs.  When deciding how a a particular
900 summary line should be displayed, each form is evaluated.  The content
901 of the face field after the first true form is used.  You can change
902 how those summary lines are displayed, by editing the face field.
903
904 You can use the following variables in the FORM field.
905
906 score:        The article's score
907 default:      The default article score.
908 default-high: The default score for high scored articles.
909 default-low:  The default score for low scored articles.
910 below:        The score below which articles are automatically marked as read.
911 mark:         The articles mark."
912   :group 'gnus-summary-visual
913   :type '(repeat (cons (sexp :tag "Form" nil)
914                        face)))
915
916 (defcustom gnus-alter-header-function nil
917   "Function called to allow alteration of article header structures.
918 The function is called with one parameter, the article header vector,
919 which it may alter in any way.")
920
921 (defvar gnus-decode-encoded-word-function
922   (mime-find-field-decoder 'From 'nov)
923   "Variable that says which function should be used to decode a string with encoded words.")
924
925 (defcustom gnus-extra-headers nil
926   "*Extra headers to parse."
927   :version "21.1"
928   :group 'gnus-summary
929   :type '(repeat symbol))
930
931 (defcustom gnus-ignored-from-addresses
932   (and user-mail-address (regexp-quote user-mail-address))
933   "*Regexp of From headers that may be suppressed in favor of To headers."
934   :version "21.1"
935   :group 'gnus-summary
936   :type 'regexp)
937
938 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
939   "List of charsets that should be ignored.
940 When these charsets are used in the \"charset\" parameter, the
941 default charset will be used instead."
942   :version "21.1"
943   :type '(repeat symbol)
944   :group 'gnus-charset)
945
946 (gnus-define-group-parameter
947  ignored-charsets
948  :type list
949  :function-document
950  "Return the ignored charsets of GROUP."
951  :variable gnus-group-ignored-charsets-alist
952  :variable-default
953  '(("alt\\.chinese\\.text" iso-8859-1))
954  :variable-document
955  "Alist of regexps (to match group names) and charsets that should be ignored.
956 When these charsets are used in the \"charset\" parameter, the
957 default charset will be used instead."
958  :variable-group gnus-charset
959  :variable-type '(repeat (cons (regexp :tag "Group")
960                                (repeat symbol)))
961  :parameter-type '(choice :tag "Ignored charsets"
962                           :value nil
963                           (repeat (symbol)))
964  :parameter-document       "\
965 List of charsets that should be ignored.
966
967 When these charsets are used in the \"charset\" parameter, the
968 default charset will be used instead.")
969
970 (defcustom gnus-group-highlight-words-alist nil
971   "Alist of group regexps and highlight regexps.
972 This variable uses the same syntax as `gnus-emphasis-alist'."
973   :version "21.1"
974   :type '(repeat (cons (regexp :tag "Group")
975                        (repeat (list (regexp :tag "Highlight regexp")
976                                      (number :tag "Group for entire word" 0)
977                                      (number :tag "Group for displayed part" 0)
978                                      (symbol :tag "Face"
979                                              gnus-emphasis-highlight-words)))))
980   :group 'gnus-summary-visual)
981
982 (defcustom gnus-use-wheel nil
983   "Use Intelli-mouse on summary movement"
984   :type 'boolean
985   :group 'gnus-summary-maneuvering)
986
987 (defcustom gnus-wheel-scroll-amount '(5 . 1)
988   "Amount to scroll messages by spinning the mouse wheel.
989 This is actually a cons cell, where the first item is the amount to scroll
990 on a normal wheel event, and the second is the amount to scroll when the
991 wheel is moved with the shift key depressed."
992   :type '(cons (integer :tag "Shift") integer)
993   :group 'gnus-summary-maneuvering)
994
995 (defcustom gnus-wheel-edge-resistance 2
996   "How hard it should be to change the current article
997 by moving the mouse over the edge of the article window."
998   :type 'integer
999   :group 'gnus-summary-maneuvering)
1000
1001 (defcustom gnus-summary-show-article-charset-alist
1002   nil
1003   "Alist of number and charset.
1004 The article will be shown with the charset corresponding to the
1005 numbered argument.
1006 For example: ((1 . cn-gb-2312) (2 . big5))."
1007   :version "21.1"
1008   :type '(repeat (cons (number :tag "Argument" 1)
1009                        (symbol :tag "Charset")))
1010   :group 'gnus-charset)
1011
1012 (defcustom gnus-preserve-marks t
1013   "Whether marks are preserved when moving, copying and respooling messages."
1014   :version "21.1"
1015   :type 'boolean
1016   :group 'gnus-summary-marks)
1017
1018 (defcustom gnus-alter-articles-to-read-function nil
1019   "Function to be called to alter the list of articles to be selected."
1020   :type '(choice (const nil) function)
1021   :group 'gnus-summary)
1022
1023 (defcustom gnus-orphan-score nil
1024   "*All orphans get this score added.  Set in the score file."
1025   :group 'gnus-score-default
1026   :type '(choice (const nil)
1027                  integer))
1028
1029 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1030   "*A regexp to match MIME parts when saving multiple parts of a message
1031 with gnus-summary-save-parts (X m). This regexp will be used by default
1032 when prompting the user for which type of files to save."
1033   :group 'gnus-summary
1034   :type 'regexp)
1035
1036
1037 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1038   "*A regexp to match MIME parts when saving multiple parts of a message
1039 with gnus-summary-save-parts (X m). This regexp will be used by default
1040 when prompting the user for which type of files to save."
1041   :group 'gnus-summary
1042   :type 'regexp)
1043
1044 (defcustom gnus-read-all-available-headers nil
1045   "Whether Gnus should parse all headers made available to it.
1046 This is mostly relevant for slow backends where the user may
1047 wish to widen the summary buffer to include all headers
1048 that were fetched.  Say, for nnultimate groups."
1049   :group 'gnus-summary
1050   :type '(choice boolean regexp))
1051
1052 (defcustom gnus-summary-muttprint-program "muttprint"
1053   "Command (and optional arguments) used to run Muttprint."
1054   :group 'gnus-summary
1055   :type 'string)
1056
1057 ;;; Internal variables
1058
1059 (defvar gnus-summary-display-cache nil)
1060 (defvar gnus-article-mime-handles nil)
1061 (defvar gnus-article-decoded-p nil)
1062 (defvar gnus-article-charset nil)
1063 (defvar gnus-article-ignored-charsets nil)
1064 (defvar gnus-scores-exclude-files nil)
1065 (defvar gnus-page-broken nil)
1066 (defvar gnus-inhibit-mime-unbuttonizing nil)
1067
1068 (defvar gnus-original-article nil)
1069 (defvar gnus-article-internal-prepare-hook nil)
1070 (defvar gnus-newsgroup-process-stack nil)
1071
1072 (defvar gnus-thread-indent-array nil)
1073 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1074 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1075   "Function called to sort the articles within a thread after it has been gathered together.")
1076
1077 (defvar gnus-summary-save-parts-type-history nil)
1078 (defvar gnus-summary-save-parts-last-directory nil)
1079
1080 (defvar gnus-summary-save-parts-type-history nil)
1081 (defvar gnus-summary-save-parts-last-directory nil)
1082
1083 ;; Avoid highlighting in kill files.
1084 (defvar gnus-summary-inhibit-highlight nil)
1085 (defvar gnus-newsgroup-selected-overlay nil)
1086 (defvar gnus-inhibit-limiting nil)
1087 (defvar gnus-newsgroup-adaptive-score-file nil)
1088 (defvar gnus-current-score-file nil)
1089 (defvar gnus-current-move-group nil)
1090 (defvar gnus-current-copy-group nil)
1091 (defvar gnus-current-crosspost-group nil)
1092 (defvar gnus-newsgroup-display nil)
1093
1094 (defvar gnus-newsgroup-dependencies nil)
1095 (defvar gnus-newsgroup-adaptive nil)
1096 (defvar gnus-summary-display-article-function nil)
1097 (defvar gnus-summary-highlight-line-function nil
1098   "Function called after highlighting a summary line.")
1099
1100 (defvar gnus-summary-line-format-alist
1101   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1102     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1103     (?s gnus-tmp-subject-or-nil ?s)
1104     (?n gnus-tmp-name ?s)
1105     (?A (std11-address-string
1106          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1107     (?a (or (std11-full-name-string
1108              (car (mime-entity-read-field gnus-tmp-header 'From)))
1109             gnus-tmp-from) ?s)
1110     (?F gnus-tmp-from ?s)
1111     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1112     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1113     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1114     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1115     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1116     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1117     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1118     (?L gnus-tmp-lines ?s)
1119     (?I gnus-tmp-indentation ?s)
1120     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1121     (?R gnus-tmp-replied ?c)
1122     (?\[ gnus-tmp-opening-bracket ?c)
1123     (?\] gnus-tmp-closing-bracket ?c)
1124     (?\> (make-string gnus-tmp-level ? ) ?s)
1125     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1126     (?i gnus-tmp-score ?d)
1127     (?z gnus-tmp-score-char ?c)
1128     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1129     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1130     (?U gnus-tmp-unread ?c)
1131     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1132         ?s)
1133     (?t (gnus-summary-number-of-articles-in-thread
1134          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1135         ?d)
1136     (?e (gnus-summary-number-of-articles-in-thread
1137          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1138         ?c)
1139     (?u gnus-tmp-user-defined ?s)
1140     (?P (gnus-pick-line-number) ?d)
1141     (?B gnus-tmp-thread-tree-header-string ?s)
1142     (user-date (gnus-user-date
1143                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1144   "An alist of format specifications that can appear in summary lines.
1145 These are paired with what variables they correspond with, along with
1146 the type of the variable (string, integer, character, etc).")
1147
1148 (defvar gnus-summary-dummy-line-format-alist
1149   `((?S gnus-tmp-subject ?s)
1150     (?N gnus-tmp-number ?d)
1151     (?u gnus-tmp-user-defined ?s)))
1152
1153 (defvar gnus-summary-mode-line-format-alist
1154   `((?G gnus-tmp-group-name ?s)
1155     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1156     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1157     (?A gnus-tmp-article-number ?d)
1158     (?Z gnus-tmp-unread-and-unselected ?s)
1159     (?V gnus-version ?s)
1160     (?U gnus-tmp-unread-and-unticked ?d)
1161     (?S gnus-tmp-subject ?s)
1162     (?e gnus-tmp-unselected ?d)
1163     (?u gnus-tmp-user-defined ?s)
1164     (?d (length gnus-newsgroup-dormant) ?d)
1165     (?t (length gnus-newsgroup-marked) ?d)
1166     (?r (length gnus-newsgroup-reads) ?d)
1167     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1168     (?E gnus-newsgroup-expunged-tally ?d)
1169     (?s (gnus-current-score-file-nondirectory) ?s)))
1170
1171 (defvar gnus-last-search-regexp nil
1172   "Default regexp for article search command.")
1173
1174 (defvar gnus-summary-search-article-matched-data nil
1175   "Last matched data of article search command.  It is the local variable
1176 in `gnus-article-buffer' which consists of the list of start position,
1177 end position and text.")
1178
1179 (defvar gnus-last-shell-command nil
1180   "Default shell command on article.")
1181
1182 (defvar gnus-newsgroup-begin nil)
1183 (defvar gnus-newsgroup-end nil)
1184 (defvar gnus-newsgroup-last-rmail nil)
1185 (defvar gnus-newsgroup-last-mail nil)
1186 (defvar gnus-newsgroup-last-folder nil)
1187 (defvar gnus-newsgroup-last-file nil)
1188 (defvar gnus-newsgroup-auto-expire nil)
1189 (defvar gnus-newsgroup-active nil)
1190
1191 (defvar gnus-newsgroup-data nil)
1192 (defvar gnus-newsgroup-data-reverse nil)
1193 (defvar gnus-newsgroup-limit nil)
1194 (defvar gnus-newsgroup-limits nil)
1195
1196 (defvar gnus-newsgroup-unreads nil
1197   "List of unread articles in the current newsgroup.")
1198
1199 (defvar gnus-newsgroup-unselected nil
1200   "List of unselected unread articles in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-reads nil
1203   "Alist of read articles and article marks in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-expunged-tally nil)
1206
1207 (defvar gnus-newsgroup-marked nil
1208   "List of ticked articles in the current newsgroup (a subset of unread art).")
1209
1210 (defvar gnus-newsgroup-killed nil
1211   "List of ranges of articles that have been through the scoring process.")
1212
1213 (defvar gnus-newsgroup-cached nil
1214   "List of articles that come from the article cache.")
1215
1216 (defvar gnus-newsgroup-saved nil
1217   "List of articles that have been saved.")
1218
1219 (defvar gnus-newsgroup-kill-headers nil)
1220
1221 (defvar gnus-newsgroup-replied nil
1222   "List of articles that have been replied to in the current newsgroup.")
1223
1224 (defvar gnus-newsgroup-forwarded nil
1225   "List of articles that have been forwarded in the current newsgroup.")
1226
1227 (defvar gnus-newsgroup-recent nil
1228   "List of articles that have are recent in the current newsgroup.")
1229
1230 (defvar gnus-newsgroup-expirable nil
1231   "List of articles in the current newsgroup that can be expired.")
1232
1233 (defvar gnus-newsgroup-processable nil
1234   "List of articles in the current newsgroup that can be processed.")
1235
1236 (defvar gnus-newsgroup-downloadable nil
1237   "List of articles in the current newsgroup that can be processed.")
1238
1239 (defvar gnus-newsgroup-undownloaded nil
1240   "List of articles in the current newsgroup that haven't been downloaded..")
1241
1242 (defvar gnus-newsgroup-unsendable nil
1243   "List of articles in the current newsgroup that won't be sent.")
1244
1245 (defvar gnus-newsgroup-bookmarks nil
1246   "List of articles in the current newsgroup that have bookmarks.")
1247
1248 (defvar gnus-newsgroup-dormant nil
1249   "List of dormant articles in the current newsgroup.")
1250
1251 (defvar gnus-newsgroup-unseen nil
1252   "List of unseen articles in the current newsgroup.")
1253
1254 (defvar gnus-newsgroup-seen nil
1255   "Range of seen articles in the current newsgroup.")
1256
1257 (defvar gnus-newsgroup-articles nil
1258   "List of articles in the current newsgroup.")
1259
1260 (defvar gnus-newsgroup-scored nil
1261   "List of scored articles in the current newsgroup.")
1262
1263 (defvar gnus-newsgroup-incorporated nil
1264   "List of incorporated articles in the current newsgroup.")
1265
1266 (defvar gnus-newsgroup-headers nil
1267   "List of article headers in the current newsgroup.")
1268
1269 (defvar gnus-newsgroup-threads nil)
1270
1271 (defvar gnus-newsgroup-prepared nil
1272   "Whether the current group has been prepared properly.")
1273
1274 (defvar gnus-newsgroup-ancient nil
1275   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-sparse nil)
1278
1279 (defvar gnus-current-article nil)
1280 (defvar gnus-article-current nil)
1281 (defvar gnus-current-headers nil)
1282 (defvar gnus-have-all-headers nil)
1283 (defvar gnus-last-article nil)
1284 (defvar gnus-newsgroup-history nil)
1285 (defvar gnus-newsgroup-charset nil)
1286 (defvar gnus-newsgroup-ephemeral-charset nil)
1287 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1288
1289 (defvar gnus-article-before-search nil)
1290
1291 (defconst gnus-summary-local-variables
1292   '(gnus-newsgroup-name
1293     gnus-newsgroup-begin gnus-newsgroup-end
1294     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1295     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1296     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1297     gnus-newsgroup-unselected gnus-newsgroup-marked
1298     gnus-newsgroup-reads gnus-newsgroup-saved
1299     gnus-newsgroup-replied gnus-newsgroup-forwarded
1300     gnus-newsgroup-recent
1301     gnus-newsgroup-expirable
1302     gnus-newsgroup-processable gnus-newsgroup-killed
1303     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1304     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1305     gnus-newsgroup-seen gnus-newsgroup-articles
1306     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1307     gnus-newsgroup-headers gnus-newsgroup-threads
1308     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1309     gnus-current-article gnus-current-headers gnus-have-all-headers
1310     gnus-last-article gnus-article-internal-prepare-hook
1311     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1312     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1313     gnus-thread-expunge-below
1314     gnus-score-alist gnus-current-score-file
1315     (gnus-summary-expunge-below . global)
1316     (gnus-summary-mark-below . global)
1317     (gnus-orphan-score . global)
1318     gnus-newsgroup-active gnus-scores-exclude-files
1319     gnus-newsgroup-history gnus-newsgroup-ancient
1320     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1321     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1322     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1323     (gnus-newsgroup-expunged-tally . 0)
1324     gnus-cache-removable-articles gnus-newsgroup-cached
1325     gnus-newsgroup-data gnus-newsgroup-data-reverse
1326     gnus-newsgroup-limit gnus-newsgroup-limits
1327     gnus-newsgroup-charset gnus-newsgroup-display
1328     gnus-newsgroup-incorporated)
1329   "Variables that are buffer-local to the summary buffers.")
1330
1331 (defvar gnus-newsgroup-variables nil
1332   "A list of variables that have separate values in different newsgroups.
1333 A list of newsgroup (summary buffer) local variables, or cons of
1334 variables and their default values (when the default values are not
1335 nil), that should be made global while the summary buffer is active.
1336 These variables can be used to set variables in the group parameters
1337 while still allowing them to affect operations done in other
1338 buffers. For example:
1339
1340 \(setq gnus-newsgroup-variables
1341      '(message-use-followup-to
1342        (gnus-visible-headers .
1343          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1344 ")
1345
1346 ;; Byte-compiler warning.
1347 (eval-when-compile (defvar gnus-article-mode-map))
1348
1349 ;; Subject simplification.
1350
1351 (defun gnus-simplify-whitespace (str)
1352   "Remove excessive whitespace from STR."
1353   (let ((mystr str))
1354     ;; Multiple spaces.
1355     (while (string-match "[ \t][ \t]+" mystr)
1356       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1357                           " "
1358                           (substring mystr (match-end 0)))))
1359     ;; Leading spaces.
1360     (when (string-match "^[ \t]+" mystr)
1361       (setq mystr (substring mystr (match-end 0))))
1362     ;; Trailing spaces.
1363     (when (string-match "[ \t]+$" mystr)
1364       (setq mystr (substring mystr 0 (match-beginning 0))))
1365     mystr))
1366
1367 (defsubst gnus-simplify-subject-re (subject)
1368   "Remove \"Re:\" from subject lines."
1369   (if (string-match message-subject-re-regexp subject)
1370       (substring subject (match-end 0))
1371     subject))
1372
1373 (defun gnus-simplify-subject (subject &optional re-only)
1374   "Remove `Re:' and words in parentheses.
1375 If RE-ONLY is non-nil, strip leading `Re:'s only."
1376   (let ((case-fold-search t))           ;Ignore case.
1377     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1378     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1379       (setq subject (substring subject (match-end 0))))
1380     ;; Remove uninteresting prefixes.
1381     (when (and (not re-only)
1382                gnus-simplify-ignored-prefixes
1383                (string-match gnus-simplify-ignored-prefixes subject))
1384       (setq subject (substring subject (match-end 0))))
1385     ;; Remove words in parentheses from end.
1386     (unless re-only
1387       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1388         (setq subject (substring subject 0 (match-beginning 0)))))
1389     ;; Return subject string.
1390     subject))
1391
1392 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1393 ;; all whitespace.
1394 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1395   (goto-char (point-min))
1396   (while (re-search-forward regexp nil t)
1397     (replace-match (or newtext ""))))
1398
1399 (defun gnus-simplify-buffer-fuzzy ()
1400   "Simplify string in the buffer fuzzily.
1401 The string in the accessible portion of the current buffer is simplified.
1402 It is assumed to be a single-line subject.
1403 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1404 matter is removed.  Additional things can be deleted by setting
1405 `gnus-simplify-subject-fuzzy-regexp'."
1406   (let ((case-fold-search t)
1407         (modified-tick))
1408     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1409
1410     (while (not (eq modified-tick (buffer-modified-tick)))
1411       (setq modified-tick (buffer-modified-tick))
1412       (cond
1413        ((listp gnus-simplify-subject-fuzzy-regexp)
1414         (mapcar 'gnus-simplify-buffer-fuzzy-step
1415                 gnus-simplify-subject-fuzzy-regexp))
1416        (gnus-simplify-subject-fuzzy-regexp
1417         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1418       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1419       (gnus-simplify-buffer-fuzzy-step
1420        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1421       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1422
1423     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1424     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1425     (gnus-simplify-buffer-fuzzy-step " $")
1426     (gnus-simplify-buffer-fuzzy-step "^ +")))
1427
1428 (defun gnus-simplify-subject-fuzzy (subject)
1429   "Simplify a subject string fuzzily.
1430 See `gnus-simplify-buffer-fuzzy' for details."
1431   (save-excursion
1432     (gnus-set-work-buffer)
1433     (let ((case-fold-search t))
1434       ;; Remove uninteresting prefixes.
1435       (when (and gnus-simplify-ignored-prefixes
1436                  (string-match gnus-simplify-ignored-prefixes subject))
1437         (setq subject (substring subject (match-end 0))))
1438       (insert subject)
1439       (inline (gnus-simplify-buffer-fuzzy))
1440       (buffer-string))))
1441
1442 (defsubst gnus-simplify-subject-fully (subject)
1443   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1444   (cond
1445    (gnus-simplify-subject-functions
1446     (gnus-map-function gnus-simplify-subject-functions subject))
1447    ((null gnus-summary-gather-subject-limit)
1448     (gnus-simplify-subject-re subject))
1449    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1450     (gnus-simplify-subject-fuzzy subject))
1451    ((numberp gnus-summary-gather-subject-limit)
1452     (gnus-limit-string (gnus-simplify-subject-re subject)
1453                        gnus-summary-gather-subject-limit))
1454    (t
1455     subject)))
1456
1457 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1458   "Check whether two subjects are equal.
1459 If optional argument simple-first is t, first argument is already
1460 simplified."
1461   (cond
1462    ((null simple-first)
1463     (equal (gnus-simplify-subject-fully s1)
1464            (gnus-simplify-subject-fully s2)))
1465    (t
1466     (equal s1
1467            (gnus-simplify-subject-fully s2)))))
1468
1469 (defun gnus-summary-bubble-group ()
1470   "Increase the score of the current group.
1471 This is a handy function to add to `gnus-summary-exit-hook' to
1472 increase the score of each group you read."
1473   (gnus-group-add-score gnus-newsgroup-name))
1474
1475 \f
1476 ;;;
1477 ;;; Gnus summary mode
1478 ;;;
1479
1480 (put 'gnus-summary-mode 'mode-class 'special)
1481
1482 (defvar gnus-article-commands-menu)
1483
1484 (when t
1485   ;; Non-orthogonal keys
1486
1487   (gnus-define-keys gnus-summary-mode-map
1488     " " gnus-summary-next-page
1489     "\177" gnus-summary-prev-page
1490     [delete] gnus-summary-prev-page
1491     [backspace] gnus-summary-prev-page
1492     "\r" gnus-summary-scroll-up
1493     "\M-\r" gnus-summary-scroll-down
1494     "n" gnus-summary-next-unread-article
1495     "p" gnus-summary-prev-unread-article
1496     "N" gnus-summary-next-article
1497     "P" gnus-summary-prev-article
1498     "\M-\C-n" gnus-summary-next-same-subject
1499     "\M-\C-p" gnus-summary-prev-same-subject
1500     "\M-n" gnus-summary-next-unread-subject
1501     "\M-p" gnus-summary-prev-unread-subject
1502     "." gnus-summary-first-unread-article
1503     "," gnus-summary-best-unread-article
1504     "\M-s" gnus-summary-search-article-forward
1505     "\M-r" gnus-summary-search-article-backward
1506     "<" gnus-summary-beginning-of-article
1507     ">" gnus-summary-end-of-article
1508     "j" gnus-summary-goto-article
1509     "^" gnus-summary-refer-parent-article
1510     "\M-^" gnus-summary-refer-article
1511     "u" gnus-summary-tick-article-forward
1512     "!" gnus-summary-tick-article-forward
1513     "U" gnus-summary-tick-article-backward
1514     "d" gnus-summary-mark-as-read-forward
1515     "D" gnus-summary-mark-as-read-backward
1516     "E" gnus-summary-mark-as-expirable
1517     "\M-u" gnus-summary-clear-mark-forward
1518     "\M-U" gnus-summary-clear-mark-backward
1519     "k" gnus-summary-kill-same-subject-and-select
1520     "\C-k" gnus-summary-kill-same-subject
1521     "\M-\C-k" gnus-summary-kill-thread
1522     "\M-\C-l" gnus-summary-lower-thread
1523     "e" gnus-summary-edit-article
1524     "#" gnus-summary-mark-as-processable
1525     "\M-#" gnus-summary-unmark-as-processable
1526     "\M-\C-t" gnus-summary-toggle-threads
1527     "\M-\C-s" gnus-summary-show-thread
1528     "\M-\C-h" gnus-summary-hide-thread
1529     "\M-\C-f" gnus-summary-next-thread
1530     "\M-\C-b" gnus-summary-prev-thread
1531     [(meta down)] gnus-summary-next-thread
1532     [(meta up)] gnus-summary-prev-thread
1533     "\M-\C-u" gnus-summary-up-thread
1534     "\M-\C-d" gnus-summary-down-thread
1535     "&" gnus-summary-execute-command
1536     "c" gnus-summary-catchup-and-exit
1537     "\C-w" gnus-summary-mark-region-as-read
1538     "\C-t" gnus-summary-toggle-truncation
1539     "?" gnus-summary-mark-as-dormant
1540     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1541     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1542     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1543     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1544     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1545     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1546     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1547     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1548     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1549     "=" gnus-summary-expand-window
1550     "\C-x\C-s" gnus-summary-reselect-current-group
1551     "\M-g" gnus-summary-rescan-group
1552     "w" gnus-summary-stop-page-breaking
1553     "\C-c\C-r" gnus-summary-caesar-message
1554     "\M-t" gnus-summary-toggle-mime
1555     "f" gnus-summary-followup
1556     "F" gnus-summary-followup-with-original
1557     "C" gnus-summary-cancel-article
1558     "r" gnus-summary-reply
1559     "R" gnus-summary-reply-with-original
1560     "\C-c\C-f" gnus-summary-mail-forward
1561     "o" gnus-summary-save-article
1562     "\C-o" gnus-summary-save-article-mail
1563     "|" gnus-summary-pipe-output
1564     "\M-k" gnus-summary-edit-local-kill
1565     "\M-K" gnus-summary-edit-global-kill
1566     ;; "V" gnus-version
1567     "\C-c\C-d" gnus-summary-describe-group
1568     "q" gnus-summary-exit
1569     "Q" gnus-summary-exit-no-update
1570     "\C-c\C-i" gnus-info-find-node
1571     gnus-mouse-2 gnus-mouse-pick-article
1572     "m" gnus-summary-mail-other-window
1573     "a" gnus-summary-post-news
1574     "i" gnus-summary-news-other-window
1575     "x" gnus-summary-limit-to-unread
1576     "s" gnus-summary-isearch-article
1577     "t" gnus-article-toggle-headers
1578     "g" gnus-summary-show-article
1579     "l" gnus-summary-goto-last-article
1580     "v" gnus-summary-preview-mime-message
1581     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1582     "\C-d" gnus-summary-enter-digest-group
1583     "\M-\C-d" gnus-summary-read-document
1584     "\M-\C-e" gnus-summary-edit-parameters
1585     "\M-\C-a" gnus-summary-customize-parameters
1586     "\C-c\C-b" gnus-bug
1587     "\C-c\C-n" gnus-namazu-search
1588     "*" gnus-cache-enter-article
1589     "\M-*" gnus-cache-remove-article
1590     "\M-&" gnus-summary-universal-argument
1591     "\C-l" gnus-recenter
1592     "I" gnus-summary-increase-score
1593     "L" gnus-summary-lower-score
1594     "\M-i" gnus-symbolic-argument
1595     "h" gnus-summary-select-article-buffer
1596
1597     "V" gnus-summary-score-map
1598     "X" gnus-uu-extract-map
1599     "S" gnus-summary-send-map)
1600
1601   ;; Sort of orthogonal keymap
1602   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1603     "t" gnus-summary-tick-article-forward
1604     "!" gnus-summary-tick-article-forward
1605     "d" gnus-summary-mark-as-read-forward
1606     "r" gnus-summary-mark-as-read-forward
1607     "c" gnus-summary-clear-mark-forward
1608     " " gnus-summary-clear-mark-forward
1609     "e" gnus-summary-mark-as-expirable
1610     "x" gnus-summary-mark-as-expirable
1611     "?" gnus-summary-mark-as-dormant
1612     "b" gnus-summary-set-bookmark
1613     "B" gnus-summary-remove-bookmark
1614     "#" gnus-summary-mark-as-processable
1615     "\M-#" gnus-summary-unmark-as-processable
1616     "S" gnus-summary-limit-include-expunged
1617     "C" gnus-summary-catchup
1618     "H" gnus-summary-catchup-to-here
1619     "h" gnus-summary-catchup-from-here
1620     "\C-c" gnus-summary-catchup-all
1621     "k" gnus-summary-kill-same-subject-and-select
1622     "K" gnus-summary-kill-same-subject
1623     "P" gnus-uu-mark-map)
1624
1625   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1626     "c" gnus-summary-clear-above
1627     "u" gnus-summary-tick-above
1628     "m" gnus-summary-mark-above
1629     "k" gnus-summary-kill-below)
1630
1631   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1632     "/" gnus-summary-limit-to-subject
1633     "n" gnus-summary-limit-to-articles
1634     "w" gnus-summary-pop-limit
1635     "s" gnus-summary-limit-to-subject
1636     "a" gnus-summary-limit-to-author
1637     "u" gnus-summary-limit-to-unread
1638     "m" gnus-summary-limit-to-marks
1639     "M" gnus-summary-limit-exclude-marks
1640     "v" gnus-summary-limit-to-score
1641     "*" gnus-summary-limit-include-cached
1642     "D" gnus-summary-limit-include-dormant
1643     "T" gnus-summary-limit-include-thread
1644     "d" gnus-summary-limit-exclude-dormant
1645     "t" gnus-summary-limit-to-age
1646     "x" gnus-summary-limit-to-extra
1647     "p" gnus-summary-limit-to-display-predicate
1648     "E" gnus-summary-limit-include-expunged
1649     "c" gnus-summary-limit-exclude-childless-dormant
1650     "C" gnus-summary-limit-mark-excluded-as-read
1651     "o" gnus-summary-insert-old-articles
1652     "N" gnus-summary-insert-new-articles)
1653
1654   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1655     "n" gnus-summary-next-unread-article
1656     "p" gnus-summary-prev-unread-article
1657     "N" gnus-summary-next-article
1658     "P" gnus-summary-prev-article
1659     "\C-n" gnus-summary-next-same-subject
1660     "\C-p" gnus-summary-prev-same-subject
1661     "\M-n" gnus-summary-next-unread-subject
1662     "\M-p" gnus-summary-prev-unread-subject
1663     "f" gnus-summary-first-unread-article
1664     "b" gnus-summary-best-unread-article
1665     "j" gnus-summary-goto-article
1666     "g" gnus-summary-goto-subject
1667     "l" gnus-summary-goto-last-article
1668     "o" gnus-summary-pop-article)
1669
1670   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1671     "k" gnus-summary-kill-thread
1672     "l" gnus-summary-lower-thread
1673     "i" gnus-summary-raise-thread
1674     "T" gnus-summary-toggle-threads
1675     "t" gnus-summary-rethread-current
1676     "^" gnus-summary-reparent-thread
1677     "s" gnus-summary-show-thread
1678     "S" gnus-summary-show-all-threads
1679     "h" gnus-summary-hide-thread
1680     "H" gnus-summary-hide-all-threads
1681     "n" gnus-summary-next-thread
1682     "p" gnus-summary-prev-thread
1683     "u" gnus-summary-up-thread
1684     "o" gnus-summary-top-thread
1685     "d" gnus-summary-down-thread
1686     "#" gnus-uu-mark-thread
1687     "\M-#" gnus-uu-unmark-thread)
1688
1689   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1690     "g" gnus-summary-prepare
1691     "c" gnus-summary-insert-cached-articles)
1692
1693   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1694     "c" gnus-summary-catchup-and-exit
1695     "C" gnus-summary-catchup-all-and-exit
1696     "E" gnus-summary-exit-no-update
1697     "J" gnus-summary-jump-to-other-group
1698     "Q" gnus-summary-exit
1699     "Z" gnus-summary-exit
1700     "n" gnus-summary-catchup-and-goto-next-group
1701     "R" gnus-summary-reselect-current-group
1702     "G" gnus-summary-rescan-group
1703     "N" gnus-summary-next-group
1704     "s" gnus-summary-save-newsrc
1705     "P" gnus-summary-prev-group)
1706
1707   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1708     " " gnus-summary-next-page
1709     "n" gnus-summary-next-page
1710     "\177" gnus-summary-prev-page
1711     [delete] gnus-summary-prev-page
1712     "p" gnus-summary-prev-page
1713     "\r" gnus-summary-scroll-up
1714     "\M-\r" gnus-summary-scroll-down
1715     "<" gnus-summary-beginning-of-article
1716     ">" gnus-summary-end-of-article
1717     "b" gnus-summary-beginning-of-article
1718     "e" gnus-summary-end-of-article
1719     "^" gnus-summary-refer-parent-article
1720     "r" gnus-summary-refer-parent-article
1721     "D" gnus-summary-enter-digest-group
1722     "R" gnus-summary-refer-references
1723     "T" gnus-summary-refer-thread
1724     "g" gnus-summary-show-article
1725     "s" gnus-summary-isearch-article
1726     "P" gnus-summary-print-article
1727     "M" gnus-mailing-list-insinuate
1728     "t" gnus-article-babel)
1729
1730   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1731     "b" gnus-article-add-buttons
1732     "B" gnus-article-add-buttons-to-head
1733     "o" gnus-article-treat-overstrike
1734     "e" gnus-article-emphasize
1735     "w" gnus-article-fill-cited-article
1736     "Q" gnus-article-fill-long-lines
1737     "C" gnus-article-capitalize-sentences
1738     "c" gnus-article-remove-cr
1739     "Z" gnus-article-decode-HZ
1740     "f" gnus-article-display-x-face
1741     "l" gnus-summary-stop-page-breaking
1742     "r" gnus-summary-caesar-message
1743     "t" gnus-article-toggle-headers
1744     "g" gnus-summary-toggle-smiley
1745     "u" gnus-article-treat-unfold-headers
1746     "n" gnus-article-treat-fold-newsgroups
1747     "v" gnus-summary-verbose-headers
1748     "m" gnus-summary-toggle-mime
1749     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1750     "p" gnus-article-verify-x-pgp-sig
1751     "d" gnus-article-treat-dumbquotes)
1752
1753   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1754     "a" gnus-article-hide
1755     "h" gnus-article-toggle-headers
1756     "b" gnus-article-hide-boring-headers
1757     "s" gnus-article-hide-signature
1758     "c" gnus-article-hide-citation
1759     "C" gnus-article-hide-citation-in-followups
1760     "l" gnus-article-hide-list-identifiers
1761     "p" gnus-article-hide-pgp
1762     "B" gnus-article-strip-banner
1763     "P" gnus-article-hide-pem
1764     "\C-c" gnus-article-hide-citation-maybe)
1765
1766   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1767     "a" gnus-article-highlight
1768     "h" gnus-article-highlight-headers
1769     "c" gnus-article-highlight-citation
1770     "s" gnus-article-highlight-signature)
1771
1772   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1773     "x" gnus-article-display-x-face
1774     "s" gnus-summary-toggle-smiley
1775     "f" gnus-treat-from-picon
1776     "m" gnus-treat-mail-picon
1777     "n" gnus-treat-newsgroups-picon)
1778
1779   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1780     "z" gnus-article-date-ut
1781     "u" gnus-article-date-ut
1782     "l" gnus-article-date-local
1783     "p" gnus-article-date-english
1784     "e" gnus-article-date-lapsed
1785     "o" gnus-article-date-original
1786     "i" gnus-article-date-iso8601
1787     "s" gnus-article-date-user)
1788
1789   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1790     "t" gnus-article-remove-trailing-blank-lines
1791     "l" gnus-article-strip-leading-blank-lines
1792     "m" gnus-article-strip-multiple-blank-lines
1793     "a" gnus-article-strip-blank-lines
1794     "A" gnus-article-strip-all-blank-lines
1795     "s" gnus-article-strip-leading-space
1796     "e" gnus-article-strip-trailing-space
1797     "w" gnus-article-remove-leading-whitespace)
1798
1799   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1800     "v" gnus-version
1801     "f" gnus-summary-fetch-faq
1802     "d" gnus-summary-describe-group
1803     "h" gnus-summary-describe-briefly
1804     "i" gnus-info-find-node)
1805
1806   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1807     "e" gnus-summary-expire-articles
1808     "\M-\C-e" gnus-summary-expire-articles-now
1809     "\177" gnus-summary-delete-article
1810     [delete] gnus-summary-delete-article
1811     [backspace] gnus-summary-delete-article
1812     "m" gnus-summary-move-article
1813     "r" gnus-summary-respool-article
1814     "w" gnus-summary-edit-article
1815     "c" gnus-summary-copy-article
1816     "B" gnus-summary-crosspost-article
1817     "q" gnus-summary-respool-query
1818     "t" gnus-summary-respool-trace
1819     "i" gnus-summary-import-article
1820     "I" gnus-summary-create-article
1821     "p" gnus-summary-article-posted-p)
1822
1823   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1824     "o" gnus-summary-save-article
1825     "m" gnus-summary-save-article-mail
1826     "F" gnus-summary-write-article-file
1827     "r" gnus-summary-save-article-rmail
1828     "f" gnus-summary-save-article-file
1829     "b" gnus-summary-save-article-body-file
1830     "h" gnus-summary-save-article-folder
1831     "v" gnus-summary-save-article-vm
1832     "p" gnus-summary-pipe-output
1833     "P" gnus-summary-muttprint
1834     "s" gnus-soup-add-article)
1835
1836   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1837     "b" gnus-summary-display-buttonized
1838     "m" gnus-summary-repair-multipart
1839     "v" gnus-article-view-part
1840     "o" gnus-article-save-part
1841     "c" gnus-article-copy-part
1842     "C" gnus-article-view-part-as-charset
1843     "e" gnus-article-externalize-part
1844     "E" gnus-article-encrypt-body
1845     "i" gnus-article-inline-part
1846     "|" gnus-article-pipe-part))
1847
1848 (defvar gnus-article-post-menu nil)
1849
1850 (defun gnus-summary-make-menu-bar ()
1851   (gnus-turn-off-edit-menu 'summary)
1852
1853   (unless (boundp 'gnus-summary-misc-menu)
1854
1855     (easy-menu-define
1856      gnus-summary-kill-menu gnus-summary-mode-map ""
1857      (cons
1858       "Score"
1859       (nconc
1860        (list
1861         ["Customize" gnus-score-customize t])
1862        (gnus-make-score-map 'increase)
1863        (gnus-make-score-map 'lower)
1864        '(("Mark"
1865           ["Kill below" gnus-summary-kill-below t]
1866           ["Mark above" gnus-summary-mark-above t]
1867           ["Tick above" gnus-summary-tick-above t]
1868           ["Clear above" gnus-summary-clear-above t])
1869          ["Current score" gnus-summary-current-score t]
1870          ["Set score" gnus-summary-set-score t]
1871          ["Switch current score file..." gnus-score-change-score-file t]
1872          ["Set mark below..." gnus-score-set-mark-below t]
1873          ["Set expunge below..." gnus-score-set-expunge-below t]
1874          ["Edit current score file" gnus-score-edit-current-scores t]
1875          ["Edit score file" gnus-score-edit-file t]
1876          ["Trace score" gnus-score-find-trace t]
1877          ["Find words" gnus-score-find-favourite-words t]
1878          ["Rescore buffer" gnus-summary-rescore t]
1879          ["Increase score..." gnus-summary-increase-score t]
1880          ["Lower score..." gnus-summary-lower-score t]))))
1881
1882     ;; Define both the Article menu in the summary buffer and the
1883     ;; equivalent Commands menu in the article buffer here for
1884     ;; consistency.
1885     (let ((innards
1886            `(("Hide"
1887               ["All" gnus-article-hide t]
1888               ["Headers" gnus-article-toggle-headers t]
1889               ["Signature" gnus-article-hide-signature t]
1890               ["Citation" gnus-article-hide-citation t]
1891               ["List identifiers" gnus-article-hide-list-identifiers t]
1892               ["PGP" gnus-article-hide-pgp t]
1893               ["Banner" gnus-article-strip-banner t]
1894               ["Boring headers" gnus-article-hide-boring-headers t])
1895              ("Highlight"
1896               ["All" gnus-article-highlight t]
1897               ["Headers" gnus-article-highlight-headers t]
1898               ["Signature" gnus-article-highlight-signature t]
1899               ["Citation" gnus-article-highlight-citation t])
1900              ("Date"
1901               ["Local" gnus-article-date-local t]
1902               ["ISO8601" gnus-article-date-iso8601 t]
1903               ["UT" gnus-article-date-ut t]
1904               ["Original" gnus-article-date-original t]
1905               ["Lapsed" gnus-article-date-lapsed t]
1906               ["User-defined" gnus-article-date-user t])
1907              ("Display"
1908               ["Toggle smiley" gnus-summary-toggle-smiley t]
1909               ["Show X-Face" gnus-article-display-x-face t]
1910               ["Show picons in From" gnus-treat-from-picon t]
1911               ["Show picons in mail headers" gnus-treat-mail-picon t]
1912               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1913              ("Washing"
1914               ("Remove Blanks"
1915                ["Leading" gnus-article-strip-leading-blank-lines t]
1916                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1917                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1918                ["All of the above" gnus-article-strip-blank-lines t]
1919                ["All" gnus-article-strip-all-blank-lines t]
1920                ["Leading space" gnus-article-strip-leading-space t]
1921                ["Trailing space" gnus-article-strip-trailing-space t]
1922                ["Leading space in headers"
1923                 gnus-article-remove-leading-whitespace t])
1924               ["Overstrike" gnus-article-treat-overstrike t]
1925               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1926               ["Emphasis" gnus-article-emphasize t]
1927               ["Word wrap" gnus-article-fill-cited-article t]
1928               ["Fill long lines" gnus-article-fill-long-lines t]
1929               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1930               ["CR" gnus-article-remove-cr t]
1931               ["Rot 13" gnus-summary-caesar-message
1932                ,@(if (featurep 'xemacs) '(t)
1933                    '(:help "\"Caesar rotate\" article by 13"))]
1934               ["Unix pipe" gnus-summary-pipe-message t]
1935               ["Add buttons" gnus-article-add-buttons t]
1936               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1937               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1938               ["Toggle MIME" gnus-summary-toggle-mime t]
1939               ["Verbose header" gnus-summary-verbose-headers t]
1940               ["Toggle header" gnus-summary-toggle-header t]
1941               ["Unfold headers" gnus-article-treat-unfold-headers t]
1942               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1943               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1944               ["HZ" gnus-article-decode-HZ t])
1945              ("Output"
1946               ["Save in default format" gnus-summary-save-article
1947                ,@(if (featurep 'xemacs) '(t)
1948                    '(:help "Save article using default method"))]
1949               ["Save in file" gnus-summary-save-article-file
1950                ,@(if (featurep 'xemacs) '(t)
1951                    '(:help "Save article in file"))]
1952               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1953               ["Save in MH folder" gnus-summary-save-article-folder t]
1954               ["Save in VM folder" gnus-summary-save-article-vm t]
1955               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1956               ["Save body in file" gnus-summary-save-article-body-file t]
1957               ["Pipe through a filter" gnus-summary-pipe-output t]
1958               ["Add to SOUP packet" gnus-soup-add-article t]
1959               ["Print with Muttprint" gnus-summary-muttprint t]
1960               ["Print" gnus-summary-print-article t])
1961              ("Backend"
1962               ["Respool article..." gnus-summary-respool-article t]
1963               ["Move article..." gnus-summary-move-article
1964                (gnus-check-backend-function
1965                 'request-move-article gnus-newsgroup-name)]
1966               ["Copy article..." gnus-summary-copy-article t]
1967               ["Crosspost article..." gnus-summary-crosspost-article
1968                (gnus-check-backend-function
1969                 'request-replace-article gnus-newsgroup-name)]
1970               ["Import file..." gnus-summary-import-article t]
1971               ["Create article..." gnus-summary-create-article t]
1972               ["Check if posted" gnus-summary-article-posted-p t]
1973               ["Edit article" gnus-summary-edit-article
1974                (not (gnus-group-read-only-p))]
1975               ["Delete article" gnus-summary-delete-article
1976                (gnus-check-backend-function
1977                 'request-expire-articles gnus-newsgroup-name)]
1978               ["Query respool" gnus-summary-respool-query t]
1979               ["Trace respool" gnus-summary-respool-trace t]
1980               ["Delete expirable articles" gnus-summary-expire-articles-now
1981                (gnus-check-backend-function
1982                 'request-expire-articles gnus-newsgroup-name)])
1983              ("Extract"
1984               ["Uudecode" gnus-uu-decode-uu
1985                ,@(if (featurep 'xemacs) '(t)
1986                    '(:help "Decode uuencoded article(s)"))]
1987               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1988               ["Unshar" gnus-uu-decode-unshar t]
1989               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1990               ["Save" gnus-uu-decode-save t]
1991               ["Binhex" gnus-uu-decode-binhex t]
1992               ["Postscript" gnus-uu-decode-postscript t])
1993              ("Cache"
1994               ["Enter article" gnus-cache-enter-article t]
1995               ["Remove article" gnus-cache-remove-article t])
1996              ["Translate" gnus-article-babel t]
1997              ["Select article buffer" gnus-summary-select-article-buffer t]
1998              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1999              ["Isearch article..." gnus-summary-isearch-article t]
2000              ["Beginning of the article" gnus-summary-beginning-of-article t]
2001              ["End of the article" gnus-summary-end-of-article t]
2002              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2003              ["Fetch referenced articles" gnus-summary-refer-references t]
2004              ["Fetch current thread" gnus-summary-refer-thread t]
2005              ["Fetch article with id..." gnus-summary-refer-article t]
2006              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2007              ["Redisplay" gnus-summary-show-article t]
2008              ["Raw article" gnus-summary-show-raw-article t])))
2009       (easy-menu-define
2010        gnus-summary-article-menu gnus-summary-mode-map ""
2011        (cons "Article" innards))
2012
2013       (if (not (keymapp gnus-summary-article-menu))
2014           (easy-menu-define
2015            gnus-article-commands-menu gnus-article-mode-map ""
2016            (cons "Commands" innards))
2017         ;; in Emacs, don't share menu.
2018         (setq gnus-article-commands-menu
2019               (copy-keymap gnus-summary-article-menu))
2020         (define-key gnus-article-mode-map [menu-bar commands]
2021           (cons "Commands" gnus-article-commands-menu))))
2022
2023     (easy-menu-define
2024      gnus-summary-thread-menu gnus-summary-mode-map ""
2025      '("Threads"
2026        ["Toggle threading" gnus-summary-toggle-threads t]
2027        ["Hide threads" gnus-summary-hide-all-threads t]
2028        ["Show threads" gnus-summary-show-all-threads t]
2029        ["Hide thread" gnus-summary-hide-thread t]
2030        ["Show thread" gnus-summary-show-thread t]
2031        ["Go to next thread" gnus-summary-next-thread t]
2032        ["Go to previous thread" gnus-summary-prev-thread t]
2033        ["Go down thread" gnus-summary-down-thread t]
2034        ["Go up thread" gnus-summary-up-thread t]
2035        ["Top of thread" gnus-summary-top-thread t]
2036        ["Mark thread as read" gnus-summary-kill-thread t]
2037        ["Lower thread score" gnus-summary-lower-thread t]
2038        ["Raise thread score" gnus-summary-raise-thread t]
2039        ["Rethread current" gnus-summary-rethread-current t]))
2040
2041     (easy-menu-define
2042      gnus-summary-post-menu gnus-summary-mode-map ""
2043      `("Post"
2044        ["Send a message (mail or news)" gnus-summary-post-news
2045         ,@(if (featurep 'xemacs) '(t)
2046             '(:help "Post an article"))]
2047        ["Followup" gnus-summary-followup
2048         ,@(if (featurep 'xemacs) '(t)
2049             '(:help "Post followup to this article"))]
2050        ["Followup and yank" gnus-summary-followup-with-original
2051         ,@(if (featurep 'xemacs) '(t)
2052             '(:help "Post followup to this article, quoting its contents"))]
2053        ["Supersede article" gnus-summary-supersede-article t]
2054        ["Cancel article" gnus-summary-cancel-article
2055         ,@(if (featurep 'xemacs) '(t)
2056             '(:help "Cancel an article you posted"))]
2057        ["Reply" gnus-summary-reply t]
2058        ["Reply and yank" gnus-summary-reply-with-original t]
2059        ["Wide reply" gnus-summary-wide-reply t]
2060        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2061         ,@(if (featurep 'xemacs) '(t)
2062             '(:help "Mail a reply, quoting this article"))]
2063        ["Mail forward" gnus-summary-mail-forward t]
2064        ["Post forward" gnus-summary-post-forward t]
2065        ["Digest and mail" gnus-summary-digest-mail-forward t]
2066        ["Digest and post" gnus-summary-digest-post-forward t]
2067        ["Resend message" gnus-summary-resend-message t]
2068        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2069        ["Send a mail" gnus-summary-mail-other-window t]
2070        ["Create a local message" gnus-summary-news-other-window t]
2071        ["Uuencode and post" gnus-uu-post-news
2072         ,@(if (featurep 'xemacs) '(t)
2073             '(:help "Post a uuencoded article"))]
2074        ["Followup via news" gnus-summary-followup-to-mail t]
2075        ["Followup via news and yank"
2076         gnus-summary-followup-to-mail-with-original t]
2077        ;;("Draft"
2078        ;;["Send" gnus-summary-send-draft t]
2079        ;;["Send bounced" gnus-resend-bounced-mail t])
2080        ))
2081
2082     (cond
2083      ((not (keymapp gnus-summary-post-menu))
2084       (setq gnus-article-post-menu gnus-summary-post-menu))
2085      ((not gnus-article-post-menu)
2086       ;; Don't share post menu.
2087       (setq gnus-article-post-menu
2088             (copy-keymap gnus-summary-post-menu))))
2089     (define-key gnus-article-mode-map [menu-bar post]
2090       (cons "Post" gnus-article-post-menu))
2091
2092     (easy-menu-define
2093      gnus-summary-misc-menu gnus-summary-mode-map ""
2094      `("Gnus"
2095        ("Mark Read"
2096         ["Mark as read" gnus-summary-mark-as-read-forward t]
2097         ["Mark same subject and select"
2098          gnus-summary-kill-same-subject-and-select t]
2099         ["Mark same subject" gnus-summary-kill-same-subject t]
2100         ["Catchup" gnus-summary-catchup
2101          ,@(if (featurep 'xemacs) '(t)
2102              '(:help "Mark unread articles in this group as read"))]
2103         ["Catchup all" gnus-summary-catchup-all t]
2104         ["Catchup to here" gnus-summary-catchup-to-here t]
2105         ["Catchup from here" gnus-summary-catchup-from-here t]
2106         ["Catchup region" gnus-summary-mark-region-as-read t]
2107         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2108        ("Mark Various"
2109         ["Tick" gnus-summary-tick-article-forward t]
2110         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2111         ["Remove marks" gnus-summary-clear-mark-forward t]
2112         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2113         ["Set bookmark" gnus-summary-set-bookmark t]
2114         ["Remove bookmark" gnus-summary-remove-bookmark t])
2115        ("Limit to"
2116         ["Marks..." gnus-summary-limit-to-marks t]
2117         ["Subject..." gnus-summary-limit-to-subject t]
2118         ["Author..." gnus-summary-limit-to-author t]
2119         ["Age..." gnus-summary-limit-to-age t]
2120         ["Extra..." gnus-summary-limit-to-extra t]
2121         ["Score" gnus-summary-limit-to-score t]
2122         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2123         ["Unread" gnus-summary-limit-to-unread t]
2124         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2125         ["Articles" gnus-summary-limit-to-articles t]
2126         ["Pop limit" gnus-summary-pop-limit t]
2127         ["Show dormant" gnus-summary-limit-include-dormant t]
2128         ["Hide childless dormant"
2129          gnus-summary-limit-exclude-childless-dormant t]
2130         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2131         ["Hide marked" gnus-summary-limit-exclude-marks t]
2132         ["Show expunged" gnus-summary-limit-include-expunged t])
2133        ("Process Mark"
2134         ["Set mark" gnus-summary-mark-as-processable t]
2135         ["Remove mark" gnus-summary-unmark-as-processable t]
2136         ["Remove all marks" gnus-summary-unmark-all-processable t]
2137         ["Mark above" gnus-uu-mark-over t]
2138         ["Mark series" gnus-uu-mark-series t]
2139         ["Mark region" gnus-uu-mark-region t]
2140         ["Unmark region" gnus-uu-unmark-region t]
2141         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2142         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2143         ["Mark all" gnus-uu-mark-all t]
2144         ["Mark buffer" gnus-uu-mark-buffer t]
2145         ["Mark sparse" gnus-uu-mark-sparse t]
2146         ["Mark thread" gnus-uu-mark-thread t]
2147         ["Unmark thread" gnus-uu-unmark-thread t]
2148         ("Process Mark Sets"
2149          ["Kill" gnus-summary-kill-process-mark t]
2150          ["Yank" gnus-summary-yank-process-mark
2151           gnus-newsgroup-process-stack]
2152          ["Save" gnus-summary-save-process-mark t]))
2153        ("Scroll article"
2154         ["Page forward" gnus-summary-next-page
2155          ,@(if (featurep 'xemacs) '(t)
2156              '(:help "Show next page of article"))]
2157         ["Page backward" gnus-summary-prev-page
2158          ,@(if (featurep 'xemacs) '(t)
2159              '(:help "Show previous page of article"))]
2160         ["Line forward" gnus-summary-scroll-up t])
2161        ("Move"
2162         ["Next unread article" gnus-summary-next-unread-article t]
2163         ["Previous unread article" gnus-summary-prev-unread-article t]
2164         ["Next article" gnus-summary-next-article t]
2165         ["Previous article" gnus-summary-prev-article t]
2166         ["Next unread subject" gnus-summary-next-unread-subject t]
2167         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2168         ["Next article same subject" gnus-summary-next-same-subject t]
2169         ["Previous article same subject" gnus-summary-prev-same-subject t]
2170         ["First unread article" gnus-summary-first-unread-article t]
2171         ["Best unread article" gnus-summary-best-unread-article t]
2172         ["Go to subject number..." gnus-summary-goto-subject t]
2173         ["Go to article number..." gnus-summary-goto-article t]
2174         ["Go to the last article" gnus-summary-goto-last-article t]
2175         ["Pop article off history" gnus-summary-pop-article t])
2176        ("Sort"
2177         ["Sort by number" gnus-summary-sort-by-number t]
2178         ["Sort by author" gnus-summary-sort-by-author t]
2179         ["Sort by subject" gnus-summary-sort-by-subject t]
2180         ["Sort by date" gnus-summary-sort-by-date t]
2181         ["Sort by score" gnus-summary-sort-by-score t]
2182         ["Sort by lines" gnus-summary-sort-by-lines t]
2183         ["Sort by characters" gnus-summary-sort-by-chars t]
2184         ["Original sort" gnus-summary-sort-by-original t])
2185        ("Help"
2186         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2187         ["Describe group" gnus-summary-describe-group t]
2188         ["Read manual" gnus-info-find-node t])
2189        ("Modes"
2190         ["Pick and read" gnus-pick-mode t]
2191         ["Binary" gnus-binary-mode t])
2192        ("Regeneration"
2193         ["Regenerate" gnus-summary-prepare t]
2194         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2195         ["Toggle threading" gnus-summary-toggle-threads t])
2196        ["See old articles" gnus-summary-insert-old-articles t]
2197        ["See new articles" gnus-summary-insert-new-articles t]
2198        ["Filter articles..." gnus-summary-execute-command t]
2199        ["Run command on subjects..." gnus-summary-universal-argument t]
2200        ["Search articles forward..." gnus-summary-search-article-forward t]
2201        ["Search articles backward..." gnus-summary-search-article-backward t]
2202        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2203        ["Expand window" gnus-summary-expand-window t]
2204        ["Expire expirable articles" gnus-summary-expire-articles
2205         (gnus-check-backend-function
2206          'request-expire-articles gnus-newsgroup-name)]
2207        ["Edit local kill file" gnus-summary-edit-local-kill t]
2208        ["Edit main kill file" gnus-summary-edit-global-kill t]
2209        ["Edit group parameters" gnus-summary-edit-parameters t]
2210        ["Customize group parameters" gnus-summary-customize-parameters t]
2211        ["Send a bug report" gnus-bug t]
2212        ("Exit"
2213         ["Catchup and exit" gnus-summary-catchup-and-exit
2214          ,@(if (featurep 'xemacs) '(t)
2215              '(:help "Mark unread articles in this group as read, then exit"))]
2216         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2217         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2218         ["Exit group" gnus-summary-exit
2219          ,@(if (featurep 'xemacs) '(t)
2220              '(:help "Exit current group, return to group selection mode"))]
2221         ["Exit group without updating" gnus-summary-exit-no-update t]
2222         ["Exit and goto next group" gnus-summary-next-group t]
2223         ["Exit and goto prev group" gnus-summary-prev-group t]
2224         ["Reselect group" gnus-summary-reselect-current-group t]
2225         ["Rescan group" gnus-summary-rescan-group t]
2226         ["Update dribble" gnus-summary-save-newsrc t])))
2227
2228     (gnus-run-hooks 'gnus-summary-menu-hook)))
2229
2230 (defvar gnus-summary-tool-bar-map nil)
2231
2232 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2233 (defun gnus-summary-make-tool-bar ()
2234   (if (and (fboundp 'tool-bar-add-item-from-menu)
2235            (default-value 'tool-bar-mode)
2236            (not gnus-summary-tool-bar-map))
2237       (setq gnus-summary-tool-bar-map
2238             (let ((tool-bar-map (make-sparse-keymap))
2239                   (load-path (mm-image-load-path)))
2240               (tool-bar-add-item-from-menu
2241                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2242               (tool-bar-add-item-from-menu
2243                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2244               (tool-bar-add-item-from-menu
2245                'gnus-summary-post-news "post" gnus-summary-mode-map)
2246               (tool-bar-add-item-from-menu
2247                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2248               (tool-bar-add-item-from-menu
2249                'gnus-summary-followup "followup" gnus-summary-mode-map)
2250               (tool-bar-add-item-from-menu
2251                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2252               (tool-bar-add-item-from-menu
2253                'gnus-summary-reply "reply" gnus-summary-mode-map)
2254               (tool-bar-add-item-from-menu
2255                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2256               (tool-bar-add-item-from-menu
2257                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2258               (tool-bar-add-item-from-menu
2259                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2260               (tool-bar-add-item-from-menu
2261                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2262               (tool-bar-add-item-from-menu
2263                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2264               (tool-bar-add-item-from-menu
2265                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2266               (tool-bar-add-item-from-menu
2267                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2268               (tool-bar-add-item-from-menu
2269                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2270               tool-bar-map)))
2271   (if gnus-summary-tool-bar-map
2272       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2273
2274 (defun gnus-score-set-default (var value)
2275   "A version of set that updates the GNU Emacs menu-bar."
2276   (set var value)
2277   ;; It is the message that forces the active status to be updated.
2278   (message ""))
2279
2280 (defun gnus-make-score-map (type)
2281   "Make a summary score map of type TYPE."
2282   (if t
2283       nil
2284     (let ((headers '(("author" "from" string)
2285                      ("subject" "subject" string)
2286                      ("article body" "body" string)
2287                      ("article head" "head" string)
2288                      ("xref" "xref" string)
2289                      ("extra header" "extra" string)
2290                      ("lines" "lines" number)
2291                      ("followups to author" "followup" string)))
2292           (types '((number ("less than" <)
2293                            ("greater than" >)
2294                            ("equal" =))
2295                    (string ("substring" s)
2296                            ("exact string" e)
2297                            ("fuzzy string" f)
2298                            ("regexp" r))))
2299           (perms '(("temporary" (current-time-string))
2300                    ("permanent" nil)
2301                    ("immediate" now)))
2302           header)
2303       (list
2304        (apply
2305         'nconc
2306         (list
2307          (if (eq type 'lower)
2308              "Lower score"
2309            "Increase score"))
2310         (let (outh)
2311           (while headers
2312             (setq header (car headers))
2313             (setq outh
2314                   (cons
2315                    (apply
2316                     'nconc
2317                     (list (car header))
2318                     (let ((ts (cdr (assoc (nth 2 header) types)))
2319                           outt)
2320                       (while ts
2321                         (setq outt
2322                               (cons
2323                                (apply
2324                                 'nconc
2325                                 (list (caar ts))
2326                                 (let ((ps perms)
2327                                       outp)
2328                                   (while ps
2329                                     (setq outp
2330                                           (cons
2331                                            (vector
2332                                             (caar ps)
2333                                             (list
2334                                              'gnus-summary-score-entry
2335                                              (nth 1 header)
2336                                              (if (or (string= (nth 1 header)
2337                                                               "head")
2338                                                      (string= (nth 1 header)
2339                                                               "body"))
2340                                                  ""
2341                                                (list 'gnus-summary-header
2342                                                      (nth 1 header)))
2343                                              (list 'quote (nth 1 (car ts)))
2344                                              (list 'gnus-score-delta-default
2345                                                    nil)
2346                                              (nth 1 (car ps))
2347                                              t)
2348                                             t)
2349                                            outp))
2350                                     (setq ps (cdr ps)))
2351                                   (list (nreverse outp))))
2352                                outt))
2353                         (setq ts (cdr ts)))
2354                       (list (nreverse outt))))
2355                    outh))
2356             (setq headers (cdr headers)))
2357           (list (nreverse outh))))))))
2358
2359 \f
2360
2361 (defun gnus-summary-mode (&optional group)
2362   "Major mode for reading articles.
2363
2364 All normal editing commands are switched off.
2365 \\<gnus-summary-mode-map>
2366 Each line in this buffer represents one article.  To read an
2367 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2368 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2369 respectively.
2370
2371 You can also post articles and send mail from this buffer.  To
2372 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2373 of an article, type `\\[gnus-summary-reply]'.
2374
2375 There are approx. one gazillion commands you can execute in this
2376 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2377
2378 The following commands are available:
2379
2380 \\{gnus-summary-mode-map}"
2381   (interactive)
2382   (kill-all-local-variables)
2383   (when (gnus-visual-p 'summary-menu 'menu)
2384     (gnus-summary-make-menu-bar)
2385     (gnus-summary-make-tool-bar))
2386   (gnus-summary-make-local-variables)
2387   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2388     (gnus-summary-make-local-variables))
2389   (gnus-make-thread-indent-array)
2390   (gnus-simplify-mode-line)
2391   (setq major-mode 'gnus-summary-mode)
2392   (setq mode-name "Summary")
2393   (make-local-variable 'minor-mode-alist)
2394   (use-local-map gnus-summary-mode-map)
2395   (buffer-disable-undo)
2396   (setq buffer-read-only t)             ;Disable modification
2397   (setq truncate-lines t)
2398   (setq selective-display t)
2399   (setq selective-display-ellipses t)   ;Display `...'
2400   (gnus-summary-set-display-table)
2401   (gnus-set-default-directory)
2402   (setq gnus-newsgroup-name group)
2403   (unless (gnus-news-group-p group)
2404     (setq gnus-newsgroup-incorporated
2405           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2406   (make-local-variable 'gnus-summary-line-format)
2407   (make-local-variable 'gnus-summary-line-format-spec)
2408   (make-local-variable 'gnus-summary-dummy-line-format)
2409   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2410   (make-local-variable 'gnus-summary-mark-positions)
2411   (make-local-hook 'pre-command-hook)
2412   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2413   (gnus-run-hooks 'gnus-summary-mode-hook)
2414   (turn-on-gnus-mailing-list-mode)
2415   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2416   (gnus-update-summary-mark-positions))
2417
2418 (defun gnus-summary-make-local-variables ()
2419   "Make all the local summary buffer variables."
2420   (let (global)
2421     (dolist (local gnus-summary-local-variables)
2422       (if (consp local)
2423           (progn
2424             (if (eq (cdr local) 'global)
2425                 ;; Copy the global value of the variable.
2426                 (setq global (symbol-value (car local)))
2427               ;; Use the value from the list.
2428               (setq global (eval (cdr local))))
2429             (set (make-local-variable (car local)) global))
2430         ;; Simple nil-valued local variable.
2431         (set (make-local-variable local) nil)))))
2432
2433 (defun gnus-summary-clear-local-variables ()
2434   (let ((locals gnus-summary-local-variables))
2435     (while locals
2436       (if (consp (car locals))
2437           (and (vectorp (caar locals))
2438                (set (caar locals) nil))
2439         (and (vectorp (car locals))
2440              (set (car locals) nil)))
2441       (setq locals (cdr locals)))))
2442
2443 ;; Summary data functions.
2444
2445 (defmacro gnus-data-number (data)
2446   `(car ,data))
2447
2448 (defmacro gnus-data-set-number (data number)
2449   `(setcar ,data ,number))
2450
2451 (defmacro gnus-data-mark (data)
2452   `(nth 1 ,data))
2453
2454 (defmacro gnus-data-set-mark (data mark)
2455   `(setcar (nthcdr 1 ,data) ,mark))
2456
2457 (defmacro gnus-data-pos (data)
2458   `(nth 2 ,data))
2459
2460 (defmacro gnus-data-set-pos (data pos)
2461   `(setcar (nthcdr 2 ,data) ,pos))
2462
2463 (defmacro gnus-data-header (data)
2464   `(nth 3 ,data))
2465
2466 (defmacro gnus-data-set-header (data header)
2467   `(setcar (nthcdr 3 ,data) ,header))
2468
2469 (defmacro gnus-data-level (data)
2470   `(nth 4 ,data))
2471
2472 (defmacro gnus-data-unread-p (data)
2473   `(= (nth 1 ,data) gnus-unread-mark))
2474
2475 (defmacro gnus-data-read-p (data)
2476   `(/= (nth 1 ,data) gnus-unread-mark))
2477
2478 (defmacro gnus-data-pseudo-p (data)
2479   `(consp (nth 3 ,data)))
2480
2481 (defmacro gnus-data-find (number)
2482   `(assq ,number gnus-newsgroup-data))
2483
2484 (defmacro gnus-data-find-list (number &optional data)
2485   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2486      (memq (assq ,number bdata)
2487            bdata)))
2488
2489 (defmacro gnus-data-make (number mark pos header level)
2490   `(list ,number ,mark ,pos ,header ,level))
2491
2492 (defun gnus-data-enter (after-article number mark pos header level offset)
2493   (let ((data (gnus-data-find-list after-article)))
2494     (unless data
2495       (error "No such article: %d" after-article))
2496     (setcdr data (cons (gnus-data-make number mark pos header level)
2497                        (cdr data)))
2498     (setq gnus-newsgroup-data-reverse nil)
2499     (gnus-data-update-list (cddr data) offset)))
2500
2501 (defun gnus-data-enter-list (after-article list &optional offset)
2502   (when list
2503     (let ((data (and after-article (gnus-data-find-list after-article)))
2504           (ilist list))
2505       (if (not (or data
2506                    after-article))
2507           (let ((odata gnus-newsgroup-data))
2508             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2509             (when offset
2510               (gnus-data-update-list odata offset)))
2511         ;; Find the last element in the list to be spliced into the main
2512         ;; list.
2513         (while (cdr list)
2514           (setq list (cdr list)))
2515         (if (not data)
2516             (progn
2517               (setcdr list gnus-newsgroup-data)
2518               (setq gnus-newsgroup-data ilist)
2519               (when offset
2520                 (gnus-data-update-list (cdr list) offset)))
2521           (setcdr list (cdr data))
2522           (setcdr data ilist)
2523           (when offset
2524             (gnus-data-update-list (cdr list) offset))))
2525       (setq gnus-newsgroup-data-reverse nil))))
2526
2527 (defun gnus-data-remove (article &optional offset)
2528   (let ((data gnus-newsgroup-data))
2529     (if (= (gnus-data-number (car data)) article)
2530         (progn
2531           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2532                 gnus-newsgroup-data-reverse nil)
2533           (when offset
2534             (gnus-data-update-list gnus-newsgroup-data offset)))
2535       (while (cdr data)
2536         (when (= (gnus-data-number (cadr data)) article)
2537           (setcdr data (cddr data))
2538           (when offset
2539             (gnus-data-update-list (cdr data) offset))
2540           (setq data nil
2541                 gnus-newsgroup-data-reverse nil))
2542         (setq data (cdr data))))))
2543
2544 (defmacro gnus-data-list (backward)
2545   `(if ,backward
2546        (or gnus-newsgroup-data-reverse
2547            (setq gnus-newsgroup-data-reverse
2548                  (reverse gnus-newsgroup-data)))
2549      gnus-newsgroup-data))
2550
2551 (defun gnus-data-update-list (data offset)
2552   "Add OFFSET to the POS of all data entries in DATA."
2553   (setq gnus-newsgroup-data-reverse nil)
2554   (while data
2555     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2556     (setq data (cdr data))))
2557
2558 (defun gnus-summary-article-pseudo-p (article)
2559   "Say whether this article is a pseudo article or not."
2560   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2561
2562 (defmacro gnus-summary-article-sparse-p (article)
2563   "Say whether this article is a sparse article or not."
2564   `(memq ,article gnus-newsgroup-sparse))
2565
2566 (defmacro gnus-summary-article-ancient-p (article)
2567   "Say whether this article is a sparse article or not."
2568   `(memq ,article gnus-newsgroup-ancient))
2569
2570 (defun gnus-article-parent-p (number)
2571   "Say whether this article is a parent or not."
2572   (let ((data (gnus-data-find-list number)))
2573     (and (cdr data)                     ; There has to be an article after...
2574          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2575             (gnus-data-level (nth 1 data))))))
2576
2577 (defun gnus-article-children (number)
2578   "Return a list of all children to NUMBER."
2579   (let* ((data (gnus-data-find-list number))
2580          (level (gnus-data-level (car data)))
2581          children)
2582     (setq data (cdr data))
2583     (while (and data
2584                 (= (gnus-data-level (car data)) (1+ level)))
2585       (push (gnus-data-number (car data)) children)
2586       (setq data (cdr data)))
2587     children))
2588
2589 (defmacro gnus-summary-skip-intangible ()
2590   "If the current article is intangible, then jump to a different article."
2591   '(let ((to (get-text-property (point) 'gnus-intangible)))
2592      (and to (gnus-summary-goto-subject to))))
2593
2594 (defmacro gnus-summary-article-intangible-p ()
2595   "Say whether this article is intangible or not."
2596   '(get-text-property (point) 'gnus-intangible))
2597
2598 (defun gnus-article-read-p (article)
2599   "Say whether ARTICLE is read or not."
2600   (not (or (memq article gnus-newsgroup-marked)
2601            (memq article gnus-newsgroup-unreads)
2602            (memq article gnus-newsgroup-unselected)
2603            (memq article gnus-newsgroup-dormant))))
2604
2605 ;; Some summary mode macros.
2606
2607 (defmacro gnus-summary-article-number ()
2608   "The article number of the article on the current line.
2609 If there isn's an article number here, then we return the current
2610 article number."
2611   '(progn
2612      (gnus-summary-skip-intangible)
2613      (or (get-text-property (point) 'gnus-number)
2614          (gnus-summary-last-subject))))
2615
2616 (defmacro gnus-summary-article-header (&optional number)
2617   "Return the header of article NUMBER."
2618   `(gnus-data-header (gnus-data-find
2619                       ,(or number '(gnus-summary-article-number)))))
2620
2621 (defmacro gnus-summary-thread-level (&optional number)
2622   "Return the level of thread that starts with article NUMBER."
2623   `(if (and (eq gnus-summary-make-false-root 'dummy)
2624             (get-text-property (point) 'gnus-intangible))
2625        0
2626      (gnus-data-level (gnus-data-find
2627                        ,(or number '(gnus-summary-article-number))))))
2628
2629 (defmacro gnus-summary-article-mark (&optional number)
2630   "Return the mark of article NUMBER."
2631   `(gnus-data-mark (gnus-data-find
2632                     ,(or number '(gnus-summary-article-number)))))
2633
2634 (defmacro gnus-summary-article-pos (&optional number)
2635   "Return the position of the line of article NUMBER."
2636   `(gnus-data-pos (gnus-data-find
2637                    ,(or number '(gnus-summary-article-number)))))
2638
2639 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2640 (defmacro gnus-summary-article-subject (&optional number)
2641   "Return current subject string or nil if nothing."
2642   `(let ((headers
2643           ,(if number
2644                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2645              '(gnus-data-header (assq (gnus-summary-article-number)
2646                                       gnus-newsgroup-data)))))
2647      (and headers
2648           (vectorp headers)
2649           (mail-header-subject headers))))
2650
2651 (defmacro gnus-summary-article-score (&optional number)
2652   "Return current article score."
2653   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2654                   gnus-newsgroup-scored))
2655        gnus-summary-default-score 0))
2656
2657 (defun gnus-summary-article-children (&optional number)
2658   "Return a list of article numbers that are children of article NUMBER."
2659   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2660          (level (gnus-data-level (car data)))
2661          l children)
2662     (while (and (setq data (cdr data))
2663                 (> (setq l (gnus-data-level (car data))) level))
2664       (and (= (1+ level) l)
2665            (push (gnus-data-number (car data))
2666                  children)))
2667     (nreverse children)))
2668
2669 (defun gnus-summary-article-parent (&optional number)
2670   "Return the article number of the parent of article NUMBER."
2671   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2672                                     (gnus-data-list t)))
2673          (level (gnus-data-level (car data))))
2674     (if (zerop level)
2675         ()                              ; This is a root.
2676       ;; We search until we find an article with a level less than
2677       ;; this one.  That function has to be the parent.
2678       (while (and (setq data (cdr data))
2679                   (not (< (gnus-data-level (car data)) level))))
2680       (and data (gnus-data-number (car data))))))
2681
2682 (defun gnus-unread-mark-p (mark)
2683   "Say whether MARK is the unread mark."
2684   (= mark gnus-unread-mark))
2685
2686 (defun gnus-read-mark-p (mark)
2687   "Say whether MARK is one of the marks that mark as read.
2688 This is all marks except unread, ticked, dormant, and expirable."
2689   (not (or (= mark gnus-unread-mark)
2690            (= mark gnus-ticked-mark)
2691            (= mark gnus-dormant-mark)
2692            (= mark gnus-expirable-mark))))
2693
2694 (defmacro gnus-article-mark (number)
2695   "Return the MARK of article NUMBER.
2696 This macro should only be used when computing the mark the \"first\"
2697 time; i.e., when generating the summary lines.  After that,
2698 `gnus-summary-article-mark' should be used to examine the
2699 marks of articles."
2700   `(cond
2701     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2702     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2703     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2704     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2705     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2706     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2707     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2708     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2709            gnus-ancient-mark))))
2710
2711 ;; Saving hidden threads.
2712
2713 (defmacro gnus-save-hidden-threads (&rest forms)
2714   "Save hidden threads, eval FORMS, and restore the hidden threads."
2715   (let ((config (make-symbol "config")))
2716     `(let ((,config (gnus-hidden-threads-configuration)))
2717        (unwind-protect
2718            (save-excursion
2719              ,@forms)
2720          (gnus-restore-hidden-threads-configuration ,config)))))
2721 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2722 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2723
2724 (defun gnus-data-compute-positions ()
2725   "Compute the positions of all articles."
2726   (setq gnus-newsgroup-data-reverse nil)
2727   (let ((data gnus-newsgroup-data))
2728     (save-excursion
2729       (gnus-save-hidden-threads
2730         (gnus-summary-show-all-threads)
2731         (goto-char (point-min))
2732         (while data
2733           (while (get-text-property (point) 'gnus-intangible)
2734             (forward-line 1))
2735           (gnus-data-set-pos (car data) (+ (point) 3))
2736           (setq data (cdr data))
2737           (forward-line 1))))))
2738
2739 (defun gnus-hidden-threads-configuration ()
2740   "Return the current hidden threads configuration."
2741   (save-excursion
2742     (let (config)
2743       (goto-char (point-min))
2744       (while (search-forward "\r" nil t)
2745         (push (1- (point)) config))
2746       config)))
2747
2748 (defun gnus-restore-hidden-threads-configuration (config)
2749   "Restore hidden threads configuration from CONFIG."
2750   (save-excursion
2751     (let (point buffer-read-only)
2752       (while (setq point (pop config))
2753         (when (and (< point (point-max))
2754                    (goto-char point)
2755                    (eq (char-after) ?\n))
2756           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2757
2758 ;; Various summary mode internalish functions.
2759
2760 (defun gnus-mouse-pick-article (e)
2761   (interactive "e")
2762   (mouse-set-point e)
2763   (gnus-summary-next-page nil t))
2764
2765 (defun gnus-summary-set-display-table ()
2766   "Change the display table.
2767 Odd characters have a tendency to mess
2768 up nicely formatted displays - we make all possible glyphs
2769 display only a single character."
2770
2771   ;; We start from the standard display table, if any.
2772   (let ((table (or (copy-sequence standard-display-table)
2773                    (make-display-table)))
2774         (i 32))
2775     ;; Nix out all the control chars...
2776     (while (>= (setq i (1- i)) 0)
2777       (aset table i [??]))
2778     ;; ... but not newline and cr, of course.  (cr is necessary for the
2779     ;; selective display).
2780     (aset table ?\n nil)
2781     (aset table ?\r nil)
2782     ;; We keep TAB as well.
2783     (aset table ?\t nil)
2784     ;; We nix out any glyphs over 126 that are not set already.
2785     (let ((i 256))
2786       (while (>= (setq i (1- i)) 127)
2787         ;; Only modify if the entry is nil.
2788         (unless (aref table i)
2789           (aset table i [??]))))
2790     (setq buffer-display-table table)))
2791
2792 (defun gnus-summary-set-article-display-arrow (pos)
2793   "Update the overlay arrow to point to line at position POS."
2794   (when (and gnus-summary-display-arrow
2795              (boundp 'overlay-arrow-position)
2796              (boundp 'overlay-arrow-string))
2797     (save-excursion
2798       (goto-char pos)
2799       (beginning-of-line)
2800       (unless overlay-arrow-position
2801         (setq overlay-arrow-position (make-marker)))
2802       (setq overlay-arrow-string "=>"
2803             overlay-arrow-position (set-marker overlay-arrow-position
2804                                                (point)
2805                                                (current-buffer))))))
2806
2807 (defun gnus-summary-buffer-name (group)
2808   "Return the summary buffer name of GROUP."
2809   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2810
2811 (defun gnus-summary-setup-buffer (group)
2812   "Initialize summary buffer."
2813   (let ((buffer (gnus-summary-buffer-name group)))
2814     (if (get-buffer buffer)
2815         (progn
2816           (set-buffer buffer)
2817           (setq gnus-summary-buffer (current-buffer))
2818           (not gnus-newsgroup-prepared))
2819       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2820       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2821       (gnus-summary-mode group)
2822       (when gnus-carpal
2823         (gnus-carpal-setup-buffer 'summary))
2824       (unless gnus-single-article-buffer
2825         (make-local-variable 'gnus-article-buffer)
2826         (make-local-variable 'gnus-article-current)
2827         (make-local-variable 'gnus-original-article-buffer))
2828       (setq gnus-newsgroup-name group)
2829       ;; Set any local variables in the group parameters.
2830       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2831       t)))
2832
2833 (defun gnus-set-global-variables ()
2834   "Set the global equivalents of the buffer-local variables.
2835 They are set to the latest values they had.  These reflect the summary
2836 buffer that was in action when the last article was fetched."
2837   (when (eq major-mode 'gnus-summary-mode)
2838     (setq gnus-summary-buffer (current-buffer))
2839     (let ((name gnus-newsgroup-name)
2840           (marked gnus-newsgroup-marked)
2841           (unread gnus-newsgroup-unreads)
2842           (headers gnus-current-headers)
2843           (data gnus-newsgroup-data)
2844           (summary gnus-summary-buffer)
2845           (article-buffer gnus-article-buffer)
2846           (original gnus-original-article-buffer)
2847           (gac gnus-article-current)
2848           (reffed gnus-reffed-article-number)
2849           (score-file gnus-current-score-file)
2850           (default-charset gnus-newsgroup-charset)
2851           vlist)
2852       (let ((locals gnus-newsgroup-variables))
2853         (while locals
2854           (if (consp (car locals))
2855               (push (eval (caar locals)) vlist)
2856             (push (eval (car locals)) vlist))
2857           (setq locals (cdr locals)))
2858         (setq vlist (nreverse vlist)))
2859       (save-excursion
2860         (set-buffer gnus-group-buffer)
2861         (setq gnus-newsgroup-name name
2862               gnus-newsgroup-marked marked
2863               gnus-newsgroup-unreads unread
2864               gnus-current-headers headers
2865               gnus-newsgroup-data data
2866               gnus-article-current gac
2867               gnus-summary-buffer summary
2868               gnus-article-buffer article-buffer
2869               gnus-original-article-buffer original
2870               gnus-reffed-article-number reffed
2871               gnus-current-score-file score-file
2872               gnus-newsgroup-charset default-charset)
2873         (let ((locals gnus-newsgroup-variables))
2874           (while locals
2875             (if (consp (car locals))
2876                 (set (caar locals) (pop vlist))
2877               (set (car locals) (pop vlist)))
2878             (setq locals (cdr locals))))
2879         ;; The article buffer also has local variables.
2880         (when (gnus-buffer-live-p gnus-article-buffer)
2881           (set-buffer gnus-article-buffer)
2882           (setq gnus-summary-buffer summary))))))
2883
2884 (defun gnus-summary-article-unread-p (article)
2885   "Say whether ARTICLE is unread or not."
2886   (memq article gnus-newsgroup-unreads))
2887
2888 (defun gnus-summary-first-article-p (&optional article)
2889   "Return whether ARTICLE is the first article in the buffer."
2890   (if (not (setq article (or article (gnus-summary-article-number))))
2891       nil
2892     (eq article (caar gnus-newsgroup-data))))
2893
2894 (defun gnus-summary-last-article-p (&optional article)
2895   "Return whether ARTICLE is the last article in the buffer."
2896   (if (not (setq article (or article (gnus-summary-article-number))))
2897       ;; All non-existent numbers are the last article.  :-)
2898       t
2899     (not (cdr (gnus-data-find-list article)))))
2900
2901 (defun gnus-make-thread-indent-array ()
2902   (let ((n 200))
2903     (unless (and gnus-thread-indent-array
2904                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2905       (setq gnus-thread-indent-array (make-vector 201 "")
2906             gnus-thread-indent-array-level gnus-thread-indent-level)
2907       (while (>= n 0)
2908         (aset gnus-thread-indent-array n
2909               (make-string (* n gnus-thread-indent-level) ? ))
2910         (setq n (1- n))))))
2911
2912 (defun gnus-update-summary-mark-positions ()
2913   "Compute where the summary marks are to go."
2914   (save-excursion
2915     (when (gnus-buffer-exists-p gnus-summary-buffer)
2916       (set-buffer gnus-summary-buffer))
2917     (let ((gnus-replied-mark 129)
2918           (gnus-score-below-mark 130)
2919           (gnus-score-over-mark 130)
2920           (gnus-download-mark 131)
2921           (spec gnus-summary-line-format-spec)
2922           gnus-visual pos)
2923       (save-excursion
2924         (gnus-set-work-buffer)
2925         (let ((gnus-summary-line-format-spec spec)
2926               (gnus-newsgroup-downloadable '((0 . t))))
2927           (gnus-summary-insert-line
2928            (make-full-mail-header 0 "" "nobody"
2929                                   "05 Apr 2001 23:33:09 +0400"
2930                                   "" "" 0 0 "" nil)
2931            0 nil 128 t nil "" nil 1)
2932           (goto-char (point-min))
2933           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2934                                              (- (point) 2)))))
2935           (goto-char (point-min))
2936           (push (cons 'replied (and (search-forward "\201" nil t)
2937                                     (- (point) 2)))
2938                 pos)
2939           (goto-char (point-min))
2940           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2941                 pos)
2942           (goto-char (point-min))
2943           (push (cons 'download
2944                       (and (search-forward "\203" nil t) (- (point) 2)))
2945                 pos)))
2946       (setq gnus-summary-mark-positions pos))))
2947
2948 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2949   "Insert a dummy root in the summary buffer."
2950   (beginning-of-line)
2951   (gnus-add-text-properties
2952    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2953    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2954
2955 (defun gnus-summary-extract-address-component (from)
2956   (or (car (funcall gnus-extract-address-components from))
2957       from))
2958
2959 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2960   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
2961                                 default-mime-charset)))
2962     ;; Is it really necessary to do this next part for each summary line?
2963     ;; Luckily, doesn't seem to slow things down much.
2964     (or
2965      (and gnus-ignored-from-addresses
2966           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2967           (let ((extra-headers (mail-header-extra header))
2968                 to
2969                 newsgroups)
2970             (cond
2971              ((setq to (cdr (assq 'To extra-headers)))
2972               (concat "-> "
2973                       (gnus-summary-extract-address-component
2974                        (funcall gnus-decode-encoded-word-function to))))
2975              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2976               (concat "=> " newsgroups)))))
2977      (gnus-summary-extract-address-component gnus-tmp-from))))
2978
2979 (defun gnus-summary-insert-line (gnus-tmp-header
2980                                  gnus-tmp-level gnus-tmp-current
2981                                  gnus-tmp-unread gnus-tmp-replied
2982                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2983                                  &optional gnus-tmp-dummy gnus-tmp-score
2984                                  gnus-tmp-process)
2985   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2986          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2987          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2988          (gnus-tmp-score-char
2989           (if (or (null gnus-summary-default-score)
2990                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2991                       gnus-summary-zcore-fuzz))
2992               ?\ ;;;Whitespace
2993             (if (< gnus-tmp-score gnus-summary-default-score)
2994                 gnus-score-below-mark gnus-score-over-mark)))
2995          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2996          (gnus-tmp-replied
2997           (cond (gnus-tmp-process gnus-process-mark)
2998                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2999                  gnus-cached-mark)
3000                 (gnus-tmp-replied gnus-replied-mark)
3001                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3002                  gnus-forwarded-mark)
3003                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3004                  gnus-saved-mark)
3005                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3006                  gnus-recent-mark)
3007                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3008                  gnus-unseen-mark)
3009                 (t gnus-no-mark)))
3010          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3011          (gnus-tmp-name
3012           (cond
3013            ((string-match "<[^>]+> *$" gnus-tmp-from)
3014             (let ((beg (match-beginning 0)))
3015               (or (and (string-match "^\".+\"" gnus-tmp-from)
3016                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3017                   (substring gnus-tmp-from 0 beg))))
3018            ((string-match "(.+)" gnus-tmp-from)
3019             (substring gnus-tmp-from
3020                        (1+ (match-beginning 0)) (1- (match-end 0))))
3021            (t gnus-tmp-from)))
3022          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3023          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3024          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3025          (buffer-read-only nil))
3026     (when (string= gnus-tmp-name "")
3027       (setq gnus-tmp-name gnus-tmp-from))
3028     (unless (numberp gnus-tmp-lines)
3029       (setq gnus-tmp-lines -1))
3030     (if (= gnus-tmp-lines -1)
3031         (setq gnus-tmp-lines "?")
3032       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3033     (gnus-put-text-property-excluding-characters-with-faces
3034      (point)
3035      (progn (eval gnus-summary-line-format-spec) (point))
3036      'gnus-number gnus-tmp-number)
3037     (when (gnus-visual-p 'summary-highlight 'highlight)
3038       (forward-line -1)
3039       (gnus-run-hooks 'gnus-summary-update-hook)
3040       (forward-line 1))))
3041
3042 (defun gnus-summary-update-line (&optional dont-update)
3043   "Update summary line after change."
3044   (when (and gnus-summary-default-score
3045              (not gnus-summary-inhibit-highlight))
3046     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3047            (article (gnus-summary-article-number))
3048            (score (gnus-summary-article-score article)))
3049       (unless dont-update
3050         (if (and gnus-summary-mark-below
3051                  (< (gnus-summary-article-score)
3052                     gnus-summary-mark-below))
3053             ;; This article has a low score, so we mark it as read.
3054             (when (memq article gnus-newsgroup-unreads)
3055               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3056           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3057             ;; This article was previously marked as read on account
3058             ;; of a low score, but now it has risen, so we mark it as
3059             ;; unread.
3060             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3061         (gnus-summary-update-mark
3062          (if (or (null gnus-summary-default-score)
3063                  (<= (abs (- score gnus-summary-default-score))
3064                      gnus-summary-zcore-fuzz))
3065              ?\ ;;;Whitespace
3066            (if (< score gnus-summary-default-score)
3067                gnus-score-below-mark gnus-score-over-mark))
3068          'score))
3069       ;; Do visual highlighting.
3070       (when (gnus-visual-p 'summary-highlight 'highlight)
3071         (gnus-run-hooks 'gnus-summary-update-hook)))))
3072
3073 (defvar gnus-tmp-new-adopts nil)
3074
3075 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3076   "Return the number of articles in THREAD.
3077 This may be 0 in some cases -- if none of the articles in
3078 the thread are to be displayed."
3079   (let* ((number
3080           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3081           (cond
3082            ((not (listp thread))
3083             1)
3084            ((and (consp thread) (cdr thread))
3085             (apply
3086              '+ 1 (mapcar
3087                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3088            ((null thread)
3089             1)
3090            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3091             1)
3092            (t 0))))
3093     (when (and level (zerop level) gnus-tmp-new-adopts)
3094       (incf number
3095             (apply '+ (mapcar
3096                        'gnus-summary-number-of-articles-in-thread
3097                        gnus-tmp-new-adopts))))
3098     (if char
3099         (if (> number 1) gnus-not-empty-thread-mark
3100           gnus-empty-thread-mark)
3101       number)))
3102
3103 (defun gnus-summary-set-local-parameters (group)
3104   "Go through the local params of GROUP and set all variable specs in that list."
3105   (let ((params (gnus-group-find-parameter group))
3106         (vars '(quit-config))           ; Ignore quit-config.
3107         elem)
3108     (while params
3109       (setq elem (car params)
3110             params (cdr params))
3111       (and (consp elem)                 ; Has to be a cons.
3112            (consp (cdr elem))           ; The cdr has to be a list.
3113            (symbolp (car elem))         ; Has to be a symbol in there.
3114            (not (memq (car elem) vars))
3115            (ignore-errors               ; So we set it.
3116              (push (car elem) vars)
3117              (make-local-variable (car elem))
3118              (set (car elem) (eval (nth 1 elem))))))))
3119
3120 (defun gnus-summary-read-group (group &optional show-all no-article
3121                                       kill-buffer no-display backward
3122                                       select-articles)
3123   "Start reading news in newsgroup GROUP.
3124 If SHOW-ALL is non-nil, already read articles are also listed.
3125 If NO-ARTICLE is non-nil, no article is selected initially.
3126 If NO-DISPLAY, don't generate a summary buffer."
3127   (let (result)
3128     (while (and group
3129                 (null (setq result
3130                             (let ((gnus-auto-select-next nil))
3131                               (or (gnus-summary-read-group-1
3132                                    group show-all no-article
3133                                    kill-buffer no-display
3134                                    select-articles)
3135                                   (setq show-all nil
3136                                         select-articles nil)))))
3137                 (eq gnus-auto-select-next 'quietly))
3138       (set-buffer gnus-group-buffer)
3139       ;; The entry function called above goes to the next
3140       ;; group automatically, so we go two groups back
3141       ;; if we are searching for the previous group.
3142       (when backward
3143         (gnus-group-prev-unread-group 2))
3144       (if (not (equal group (gnus-group-group-name)))
3145           (setq group (gnus-group-group-name))
3146         (setq group nil)))
3147     result))
3148
3149 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3150   "Directly jump to the other GROUP from summary buffer.
3151 If SHOW-ALL is non-nil, already read articles are also listed."
3152   (interactive
3153    (if (eq gnus-summary-buffer (current-buffer))
3154        (list (completing-read
3155               "Group: " gnus-active-hashtb nil t
3156               (when (and gnus-newsgroup-name
3157                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3158                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3159               'gnus-group-history)
3160              current-prefix-arg)
3161      (error "%s must be invoked from a gnus summary buffer." this-command)))
3162   (unless (or (zerop (length group))
3163               (and gnus-newsgroup-name
3164                    (string-equal gnus-newsgroup-name group)))
3165     (gnus-summary-exit)
3166     (gnus-summary-read-group group show-all
3167                              gnus-dont-select-after-jump-to-other-group)))
3168
3169 (defun gnus-summary-read-group-1 (group show-all no-article
3170                                         kill-buffer no-display
3171                                         &optional select-articles)
3172   ;; Killed foreign groups can't be entered.
3173   ;;  (when (and (not (gnus-group-native-p group))
3174   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3175   ;;    (error "Dead non-native groups can't be entered"))
3176   (gnus-message 5 "Retrieving newsgroup: %s..."
3177                 (gnus-group-decoded-name group))
3178   (let* ((new-group (gnus-summary-setup-buffer group))
3179          (quit-config (gnus-group-quit-config group))
3180          (did-select (and new-group (gnus-select-newsgroup
3181                                      group show-all select-articles))))
3182     (cond
3183      ;; This summary buffer exists already, so we just select it.
3184      ((not new-group)
3185       (gnus-set-global-variables)
3186       (when kill-buffer
3187         (gnus-kill-or-deaden-summary kill-buffer))
3188       (gnus-configure-windows 'summary 'force)
3189       (gnus-set-mode-line 'summary)
3190       (gnus-summary-position-point)
3191       (message "")
3192       t)
3193      ;; We couldn't select this group.
3194      ((null did-select)
3195       (when (and (eq major-mode 'gnus-summary-mode)
3196                  (not (equal (current-buffer) kill-buffer)))
3197         (kill-buffer (current-buffer))
3198         (if (not quit-config)
3199             (progn
3200               ;; Update the info -- marks might need to be removed,
3201               ;; for instance.
3202               (gnus-summary-update-info)
3203               (set-buffer gnus-group-buffer)
3204               (gnus-group-jump-to-group group)
3205               (gnus-group-next-unread-group 1))
3206           (gnus-handle-ephemeral-exit quit-config)))
3207       (let ((grpinfo (gnus-get-info group)))
3208         (if (null (gnus-info-read grpinfo))
3209             (gnus-message 3 "Group %s contains no messages"
3210                           (gnus-group-decoded-name group))
3211           (gnus-message 3 "Can't select group")))
3212       nil)
3213      ;; The user did a `C-g' while prompting for number of articles,
3214      ;; so we exit this group.
3215      ((eq did-select 'quit)
3216       (and (eq major-mode 'gnus-summary-mode)
3217            (not (equal (current-buffer) kill-buffer))
3218            (kill-buffer (current-buffer)))
3219       (when kill-buffer
3220         (gnus-kill-or-deaden-summary kill-buffer))
3221       (if (not quit-config)
3222           (progn
3223             (set-buffer gnus-group-buffer)
3224             (gnus-group-jump-to-group group)
3225             (gnus-group-next-unread-group 1)
3226             (gnus-configure-windows 'group 'force))
3227         (gnus-handle-ephemeral-exit quit-config))
3228       ;; Finally signal the quit.
3229       (signal 'quit nil))
3230      ;; The group was successfully selected.
3231      (t
3232       (gnus-set-global-variables)
3233       ;; Save the active value in effect when the group was entered.
3234       (setq gnus-newsgroup-active
3235             (gnus-copy-sequence
3236              (gnus-active gnus-newsgroup-name)))
3237       ;; You can change the summary buffer in some way with this hook.
3238       (gnus-run-hooks 'gnus-select-group-hook)
3239       (gnus-update-format-specifications
3240        nil 'summary 'summary-mode 'summary-dummy)
3241       (gnus-update-summary-mark-positions)
3242       ;; Do score processing.
3243       (when gnus-use-scoring
3244         (gnus-possibly-score-headers))
3245       ;; Check whether to fill in the gaps in the threads.
3246       (when gnus-build-sparse-threads
3247         (gnus-build-sparse-threads))
3248       ;; Find the initial limit.
3249       (if gnus-show-threads
3250           (if show-all
3251               (let ((gnus-newsgroup-dormant nil))
3252                 (gnus-summary-initial-limit show-all))
3253             (gnus-summary-initial-limit show-all))
3254         ;; When untreaded, all articles are always shown.
3255         (setq gnus-newsgroup-limit
3256               (mapcar
3257                (lambda (header) (mail-header-number header))
3258                gnus-newsgroup-headers)))
3259       ;; Generate the summary buffer.
3260       (unless no-display
3261         (gnus-summary-prepare))
3262       (when gnus-use-trees
3263         (gnus-tree-open group)
3264         (setq gnus-summary-highlight-line-function
3265               'gnus-tree-highlight-article))
3266       ;; If the summary buffer is empty, but there are some low-scored
3267       ;; articles or some excluded dormants, we include these in the
3268       ;; buffer.
3269       (when (and (zerop (buffer-size))
3270                  (not no-display))
3271         (cond (gnus-newsgroup-dormant
3272                (gnus-summary-limit-include-dormant))
3273               ((and gnus-newsgroup-scored show-all)
3274                (gnus-summary-limit-include-expunged t))))
3275       ;; Function `gnus-apply-kill-file' must be called in this hook.
3276       (gnus-run-hooks 'gnus-apply-kill-hook)
3277       (if (and (zerop (buffer-size))
3278                (not no-display))
3279           (progn
3280             ;; This newsgroup is empty.
3281             (gnus-summary-catchup-and-exit nil t)
3282             (gnus-message 6 "No unread news")
3283             (when kill-buffer
3284               (gnus-kill-or-deaden-summary kill-buffer))
3285             ;; Return nil from this function.
3286             nil)
3287         ;; Hide conversation thread subtrees.  We cannot do this in
3288         ;; gnus-summary-prepare-hook since kill processing may not
3289         ;; work with hidden articles.
3290         (and gnus-show-threads
3291              gnus-thread-hide-subtree
3292              (gnus-summary-hide-all-threads))
3293         (when kill-buffer
3294           (gnus-kill-or-deaden-summary kill-buffer))
3295         (gnus-summary-auto-select-subject)
3296         ;; Show first unread article if requested.
3297         (if (and (not no-article)
3298                  (not no-display)
3299                  gnus-newsgroup-unreads
3300                  gnus-auto-select-first)
3301             (progn
3302               (gnus-configure-windows 'summary)
3303               (gnus-summary-goto-article (gnus-summary-article-number)))
3304           ;; Don't select any articles.
3305           (gnus-summary-position-point)
3306           (gnus-configure-windows 'summary 'force)
3307           (gnus-set-mode-line 'summary))
3308         (when (get-buffer-window gnus-group-buffer t)
3309           ;; Gotta use windows, because recenter does weird stuff if
3310           ;; the current buffer ain't the displayed window.
3311           (let ((owin (selected-window)))
3312             (select-window (get-buffer-window gnus-group-buffer t))
3313             (when (gnus-group-goto-group group)
3314               (recenter))
3315             (select-window owin)))
3316         ;; Mark this buffer as "prepared".
3317         (setq gnus-newsgroup-prepared t)
3318         (gnus-run-hooks 'gnus-summary-prepared-hook)
3319         t)))))
3320
3321 (defun gnus-summary-auto-select-subject ()
3322   "Select the subject line on initial group entry."
3323   (goto-char (point-min))
3324   (cond
3325    ((eq gnus-auto-select-subject 'best)
3326     (gnus-summary-best-unread-subject))
3327    ((eq gnus-auto-select-subject 'unread)
3328     (gnus-summary-first-unread-subject))
3329    ((eq gnus-auto-select-subject 'unseen)
3330     (gnus-summary-first-unseen-subject))
3331    ((eq gnus-auto-select-subject 'first)
3332     ;; Do nothing.
3333     )
3334    ((gnus-functionp gnus-auto-select-subject)
3335     (funcall gnus-auto-select-subject))))
3336
3337 (defun gnus-summary-prepare ()
3338   "Generate the summary buffer."
3339   (interactive)
3340   (let ((buffer-read-only nil))
3341     (erase-buffer)
3342     (setq gnus-newsgroup-data nil
3343           gnus-newsgroup-data-reverse nil)
3344     (gnus-run-hooks 'gnus-summary-generate-hook)
3345     ;; Generate the buffer, either with threads or without.
3346     (when gnus-newsgroup-headers
3347       (gnus-summary-prepare-threads
3348        (if gnus-show-threads
3349            (gnus-sort-gathered-threads
3350             (funcall gnus-summary-thread-gathering-function
3351                      (gnus-sort-threads
3352                       (gnus-cut-threads (gnus-make-threads)))))
3353          ;; Unthreaded display.
3354          (gnus-sort-articles gnus-newsgroup-headers))))
3355     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3356     ;; Call hooks for modifying summary buffer.
3357     (goto-char (point-min))
3358     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3359
3360 (defsubst gnus-general-simplify-subject (subject)
3361   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3362   (setq subject
3363         (cond
3364          ;; Truncate the subject.
3365          (gnus-simplify-subject-functions
3366           (gnus-map-function gnus-simplify-subject-functions subject))
3367          ((numberp gnus-summary-gather-subject-limit)
3368           (setq subject (gnus-simplify-subject-re subject))
3369           (if (> (length subject) gnus-summary-gather-subject-limit)
3370               (substring subject 0 gnus-summary-gather-subject-limit)
3371             subject))
3372          ;; Fuzzily simplify it.
3373          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3374           (gnus-simplify-subject-fuzzy subject))
3375          ;; Just remove the leading "Re:".
3376          (t
3377           (gnus-simplify-subject-re subject))))
3378
3379   (if (and gnus-summary-gather-exclude-subject
3380            (string-match gnus-summary-gather-exclude-subject subject))
3381       nil                               ; This article shouldn't be gathered
3382     subject))
3383
3384 (defun gnus-summary-simplify-subject-query ()
3385   "Query where the respool algorithm would put this article."
3386   (interactive)
3387   (gnus-summary-select-article)
3388   (message "%s"
3389            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3390
3391 (defun gnus-gather-threads-by-subject (threads)
3392   "Gather threads by looking at Subject headers."
3393   (if (not gnus-summary-make-false-root)
3394       threads
3395     (let ((hashtb (gnus-make-hashtable 1024))
3396           (prev threads)
3397           (result threads)
3398           subject hthread whole-subject)
3399       (while threads
3400         (setq subject (gnus-general-simplify-subject
3401                        (setq whole-subject (mail-header-subject
3402                                             (caar threads)))))
3403         (when subject
3404           (if (setq hthread (gnus-gethash subject hashtb))
3405               (progn
3406                 ;; We enter a dummy root into the thread, if we
3407                 ;; haven't done that already.
3408                 (unless (stringp (caar hthread))
3409                   (setcar hthread (list whole-subject (car hthread))))
3410                 ;; We add this new gathered thread to this gathered
3411                 ;; thread.
3412                 (setcdr (car hthread)
3413                         (nconc (cdar hthread) (list (car threads))))
3414                 ;; Remove it from the list of threads.
3415                 (setcdr prev (cdr threads))
3416                 (setq threads prev))
3417             ;; Enter this thread into the hash table.
3418             (gnus-sethash subject threads hashtb)))
3419         (setq prev threads)
3420         (setq threads (cdr threads)))
3421       result)))
3422
3423 (defun gnus-gather-threads-by-references (threads)
3424   "Gather threads by looking at References headers."
3425   (let ((idhashtb (gnus-make-hashtable 1024))
3426         (thhashtb (gnus-make-hashtable 1024))
3427         (prev threads)
3428         (result threads)
3429         ids references id gthread gid entered ref)
3430     (while threads
3431       (when (setq references (mail-header-references (caar threads)))
3432         (setq id (mail-header-id (caar threads))
3433               ids (gnus-split-references references)
3434               entered nil)
3435         (while (setq ref (pop ids))
3436           (setq ids (delete ref ids))
3437           (if (not (setq gid (gnus-gethash ref idhashtb)))
3438               (progn
3439                 (gnus-sethash ref id idhashtb)
3440                 (gnus-sethash id threads thhashtb))
3441             (setq gthread (gnus-gethash gid thhashtb))
3442             (unless entered
3443               ;; We enter a dummy root into the thread, if we
3444               ;; haven't done that already.
3445               (unless (stringp (caar gthread))
3446                 (setcar gthread (list (mail-header-subject (caar gthread))
3447                                       (car gthread))))
3448               ;; We add this new gathered thread to this gathered
3449               ;; thread.
3450               (setcdr (car gthread)
3451                       (nconc (cdar gthread) (list (car threads)))))
3452             ;; Add it into the thread hash table.
3453             (gnus-sethash id gthread thhashtb)
3454             (setq entered t)
3455             ;; Remove it from the list of threads.
3456             (setcdr prev (cdr threads))
3457             (setq threads prev))))
3458       (setq prev threads)
3459       (setq threads (cdr threads)))
3460     result))
3461
3462 (defun gnus-sort-gathered-threads (threads)
3463   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3464   (let ((result threads))
3465     (while threads
3466       (when (stringp (caar threads))
3467         (setcdr (car threads)
3468                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3469       (setq threads (cdr threads)))
3470     result))
3471
3472 (defun gnus-thread-loop-p (root thread)
3473   "Say whether ROOT is in THREAD."
3474   (let ((stack (list thread))
3475         (infloop 0)
3476         th)
3477     (while (setq thread (pop stack))
3478       (setq th (cdr thread))
3479       (while (and th
3480                   (not (eq (caar th) root)))
3481         (pop th))
3482       (if th
3483           ;; We have found a loop.
3484           (let (ref-dep)
3485             (setcdr thread (delq (car th) (cdr thread)))
3486             (if (boundp (setq ref-dep (intern "none"
3487                                               gnus-newsgroup-dependencies)))
3488                 (setcdr (symbol-value ref-dep)
3489                         (nconc (cdr (symbol-value ref-dep))
3490                                (list (car th))))
3491               (set ref-dep (list nil (car th))))
3492             (setq infloop 1
3493                   stack nil))
3494         ;; Push all the subthreads onto the stack.
3495         (push (cdr thread) stack)))
3496     infloop))
3497
3498 (defun gnus-make-threads ()
3499   "Go through the dependency hashtb and find the roots.  Return all threads."
3500   (let (threads)
3501     (while (catch 'infloop
3502              (mapatoms
3503               (lambda (refs)
3504                 ;; Deal with self-referencing References loops.
3505                 (when (and (car (symbol-value refs))
3506                            (not (zerop
3507                                  (apply
3508                                   '+
3509                                   (mapcar
3510                                    (lambda (thread)
3511                                      (gnus-thread-loop-p
3512                                       (car (symbol-value refs)) thread))
3513                                    (cdr (symbol-value refs)))))))
3514                   (setq threads nil)
3515                   (throw 'infloop t))
3516                 (unless (car (symbol-value refs))
3517                   ;; These threads do not refer back to any other articles,
3518                   ;; so they're roots.
3519                   (setq threads (append (cdr (symbol-value refs)) threads))))
3520               gnus-newsgroup-dependencies)))
3521     threads))
3522
3523 ;; Build the thread tree.
3524 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3525   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3526
3527 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3528 if it was already present.
3529
3530 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3531 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3532 Message-IDs will be renamed be renamed to a unique Message-ID before
3533 being entered.
3534
3535 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3536   (let* ((id (mail-header-id header))
3537          (id-dep (and id (intern id dependencies)))
3538          ref ref-dep ref-header)
3539     ;; Enter this `header' in the `dependencies' table.
3540     (cond
3541      ((not id-dep)
3542       (setq header nil))
3543      ;; The first two cases do the normal part: enter a new `header'
3544      ;; in the `dependencies' table.
3545      ((not (boundp id-dep))
3546       (set id-dep (list header)))
3547      ((null (car (symbol-value id-dep)))
3548       (setcar (symbol-value id-dep) header))
3549
3550      ;; From here the `header' was already present in the
3551      ;; `dependencies' table.
3552      (force-new
3553       ;; Overrides an existing entry;
3554       ;; just set the header part of the entry.
3555       (setcar (symbol-value id-dep) header))
3556
3557      ;; Renames the existing `header' to a unique Message-ID.
3558      ((not gnus-summary-ignore-duplicates)
3559       ;; An article with this Message-ID has already been seen.
3560       ;; We rename the Message-ID.
3561       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3562            (list header))
3563       (mail-header-set-id header id))
3564
3565      ;; The last case ignores an existing entry, except it adds any
3566      ;; additional Xrefs (in case the two articles came from different
3567      ;; servers.
3568      ;; Also sets `header' to `nil' meaning that the `dependencies'
3569      ;; table was *not* modified.
3570      (t
3571       (mail-header-set-xref
3572        (car (symbol-value id-dep))
3573        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3574                    "")
3575                (or (mail-header-xref header) "")))
3576       (setq header nil)))
3577
3578     (when header
3579       ;; First check if that we are not creating a References loop.
3580       (setq ref (gnus-parent-id (mail-header-references header)))
3581       (while (and ref
3582                   (setq ref-dep (intern-soft ref dependencies))
3583                   (boundp ref-dep)
3584                   (setq ref-header (car (symbol-value ref-dep))))
3585         (if (string= id ref)
3586             ;; Yuk!  This is a reference loop.  Make the article be a
3587             ;; root article.
3588             (progn
3589               (mail-header-set-references (car (symbol-value id-dep)) "none")
3590               (setq ref nil))
3591           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3592       (setq ref (gnus-parent-id (mail-header-references header)))
3593       (setq ref-dep (intern (or ref "none") dependencies))
3594       (if (boundp ref-dep)
3595           (setcdr (symbol-value ref-dep)
3596                   (nconc (cdr (symbol-value ref-dep))
3597                          (list (symbol-value id-dep))))
3598         (set ref-dep (list nil (symbol-value id-dep)))))
3599     header))
3600
3601 (defun gnus-build-sparse-threads ()
3602   (let ((headers gnus-newsgroup-headers)
3603         (mail-parse-charset gnus-newsgroup-charset)
3604         (gnus-summary-ignore-duplicates t)
3605         header references generation relations
3606         subject child end new-child date)
3607     ;; First we create an alist of generations/relations, where
3608     ;; generations is how much we trust the relation, and the relation
3609     ;; is parent/child.
3610     (gnus-message 7 "Making sparse threads...")
3611     (save-excursion
3612       (nnheader-set-temp-buffer " *gnus sparse threads*")
3613       (while (setq header (pop headers))
3614         (when (and (setq references (mail-header-references header))
3615                    (not (string= references "")))
3616           (insert references)
3617           (setq child (mail-header-id header)
3618                 subject (mail-header-subject header)
3619                 date (mail-header-date header)
3620                 generation 0)
3621           (while (search-backward ">" nil t)
3622             (setq end (1+ (point)))
3623             (when (search-backward "<" nil t)
3624               (setq new-child (buffer-substring (point) end))
3625               (push (list (incf generation)
3626                           child (setq child new-child)
3627                           subject date)
3628                     relations)))
3629           (when child
3630             (push (list (1+ generation) child nil subject) relations))
3631           (erase-buffer)))
3632       (kill-buffer (current-buffer)))
3633     ;; Sort over trustworthiness.
3634     (mapcar
3635      (lambda (relation)
3636        (when (gnus-dependencies-add-header
3637               (make-full-mail-header-from-decoded-header
3638                gnus-reffed-article-number
3639                (nth 3 relation) "" (or (nth 4 relation) "")
3640                (nth 1 relation)
3641                (or (nth 2 relation) "") 0 0 "")
3642               gnus-newsgroup-dependencies nil)
3643          (push gnus-reffed-article-number gnus-newsgroup-limit)
3644          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3645          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3646                gnus-newsgroup-reads)
3647          (decf gnus-reffed-article-number)))
3648      (sort relations 'car-less-than-car))
3649     (gnus-message 7 "Making sparse threads...done")))
3650
3651 (defun gnus-build-old-threads ()
3652   ;; Look at all the articles that refer back to old articles, and
3653   ;; fetch the headers for the articles that aren't there.  This will
3654   ;; build complete threads - if the roots haven't been expired by the
3655   ;; server, that is.
3656   (let ((mail-parse-charset gnus-newsgroup-charset)
3657         id heads)
3658     (mapatoms
3659      (lambda (refs)
3660        (when (not (car (symbol-value refs)))
3661          (setq heads (cdr (symbol-value refs)))
3662          (while heads
3663            (if (memq (mail-header-number (caar heads))
3664                      gnus-newsgroup-dormant)
3665                (setq heads (cdr heads))
3666              (setq id (symbol-name refs))
3667              (while (and (setq id (gnus-build-get-header id))
3668                          (not (car (gnus-id-to-thread id)))))
3669              (setq heads nil)))))
3670      gnus-newsgroup-dependencies)))
3671
3672 ;; This function has to be called with point after the article number
3673 ;; on the beginning of the line.
3674 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3675   (let ((eol (gnus-point-at-eol))
3676         (buffer (current-buffer))
3677         header)
3678
3679     ;; overview: [num subject from date id refs chars lines misc]
3680     (unwind-protect
3681         (progn
3682           (narrow-to-region (point) eol)
3683           (unless (eobp)
3684             (forward-char))
3685
3686           (setq header
3687                 (make-full-mail-header
3688                  number                         ; number
3689                  (nnheader-nov-field)           ; subject
3690                  (nnheader-nov-field)           ; from
3691                  (nnheader-nov-field)           ; date
3692                  (nnheader-nov-read-message-id) ; id
3693                  (nnheader-nov-field)           ; refs
3694                  (nnheader-nov-read-integer)    ; chars
3695                  (nnheader-nov-read-integer)    ; lines
3696                  (unless (eobp)
3697                    (if (looking-at "Xref: ")
3698                        (goto-char (match-end 0)))
3699                    (nnheader-nov-field))        ; Xref
3700                  (nnheader-nov-parse-extra))))  ; extra
3701
3702       (widen))
3703
3704     (when gnus-alter-header-function
3705       (funcall gnus-alter-header-function header))
3706     (gnus-dependencies-add-header header dependencies force-new)))
3707
3708 (defun gnus-build-get-header (id)
3709   "Look through the buffer of NOV lines and find the header to ID.
3710 Enter this line into the dependencies hash table, and return
3711 the id of the parent article (if any)."
3712   (let ((deps gnus-newsgroup-dependencies)
3713         found header)
3714     (prog1
3715         (save-excursion
3716           (set-buffer nntp-server-buffer)
3717           (let ((case-fold-search nil))
3718             (goto-char (point-min))
3719             (while (and (not found)
3720                         (search-forward id nil t))
3721               (beginning-of-line)
3722               (setq found (looking-at
3723                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3724                                    (regexp-quote id))))
3725               (or found (beginning-of-line 2)))
3726             (when found
3727               (beginning-of-line)
3728               (and
3729                (setq header (gnus-nov-parse-line
3730                              (read (current-buffer)) deps))
3731                (gnus-parent-id (mail-header-references header))))))
3732       (when header
3733         (let ((number (mail-header-number header)))
3734           (push number gnus-newsgroup-limit)
3735           (push header gnus-newsgroup-headers)
3736           (if (memq number gnus-newsgroup-unselected)
3737               (progn
3738                 (push number gnus-newsgroup-unreads)
3739                 (setq gnus-newsgroup-unselected
3740                       (delq number gnus-newsgroup-unselected)))
3741             (push number gnus-newsgroup-ancient)))))))
3742
3743 (defun gnus-build-all-threads ()
3744   "Read all the headers."
3745   (let ((gnus-summary-ignore-duplicates t)
3746         (mail-parse-charset gnus-newsgroup-charset)
3747         (dependencies gnus-newsgroup-dependencies)
3748         header article)
3749     (save-excursion
3750       (set-buffer nntp-server-buffer)
3751       (let ((case-fold-search nil))
3752         (goto-char (point-min))
3753         (while (not (eobp))
3754           (ignore-errors
3755             (setq article (read (current-buffer))
3756                   header (gnus-nov-parse-line article dependencies)))
3757           (when header
3758             (save-excursion
3759               (set-buffer gnus-summary-buffer)
3760               (push header gnus-newsgroup-headers)
3761               (if (memq (setq article (mail-header-number header))
3762                         gnus-newsgroup-unselected)
3763                   (progn
3764                     (push article gnus-newsgroup-unreads)
3765                     (setq gnus-newsgroup-unselected
3766                           (delq article gnus-newsgroup-unselected)))
3767                 (push article gnus-newsgroup-ancient)))
3768             (forward-line 1)))))))
3769
3770 (defun gnus-summary-update-article-line (article header)
3771   "Update the line for ARTICLE using HEADERS."
3772   (let* ((id (mail-header-id header))
3773          (thread (gnus-id-to-thread id)))
3774     (unless thread
3775       (error "Article in no thread"))
3776     ;; Update the thread.
3777     (setcar thread header)
3778     (gnus-summary-goto-subject article)
3779     (let* ((datal (gnus-data-find-list article))
3780            (data (car datal))
3781            (length (when (cdr datal)
3782                      (- (gnus-data-pos data)
3783                         (gnus-data-pos (cadr datal)))))
3784            (buffer-read-only nil)
3785            (level (gnus-summary-thread-level)))
3786       (gnus-delete-line)
3787       (gnus-summary-insert-line
3788        header level nil (gnus-article-mark article)
3789        (memq article gnus-newsgroup-replied)
3790        (memq article gnus-newsgroup-expirable)
3791        ;; Only insert the Subject string when it's different
3792        ;; from the previous Subject string.
3793        (if (and
3794             gnus-show-threads
3795             (gnus-subject-equal
3796              (condition-case ()
3797                  (mail-header-subject
3798                   (gnus-data-header
3799                    (cadr
3800                     (gnus-data-find-list
3801                      article
3802                      (gnus-data-list t)))))
3803                ;; Error on the side of excessive subjects.
3804                (error ""))
3805              (mail-header-subject header)))
3806            ""
3807          (mail-header-subject header))
3808        nil (cdr (assq article gnus-newsgroup-scored))
3809        (memq article gnus-newsgroup-processable))
3810       (when length
3811         (gnus-data-update-list
3812          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3813
3814 (defun gnus-summary-update-article (article &optional iheader)
3815   "Update ARTICLE in the summary buffer."
3816   (set-buffer gnus-summary-buffer)
3817   (let* ((header (gnus-summary-article-header article))
3818          (id (mail-header-id header))
3819          (data (gnus-data-find article))
3820          (thread (gnus-id-to-thread id))
3821          (references (mail-header-references header))
3822          (parent
3823           (gnus-id-to-thread
3824            (or (gnus-parent-id
3825                 (when (and references
3826                            (not (equal "" references)))
3827                   references))
3828                "none")))
3829          (buffer-read-only nil)
3830          (old (car thread)))
3831     (when thread
3832       (unless iheader
3833         (setcar thread nil)
3834         (when parent
3835           (delq thread parent)))
3836       (if (gnus-summary-insert-subject id header)
3837           ;; Set the (possibly) new article number in the data structure.
3838           (gnus-data-set-number data (gnus-id-to-article id))
3839         (setcar thread old)
3840         nil))))
3841
3842 (defun gnus-rebuild-thread (id &optional line)
3843   "Rebuild the thread containing ID.
3844 If LINE, insert the rebuilt thread starting on line LINE."
3845   (let ((buffer-read-only nil)
3846         old-pos current thread data)
3847     (if (not gnus-show-threads)
3848         (setq thread (list (car (gnus-id-to-thread id))))
3849       ;; Get the thread this article is part of.
3850       (setq thread (gnus-remove-thread id)))
3851     (setq old-pos (gnus-point-at-bol))
3852     (setq current (save-excursion
3853                     (and (re-search-backward "[\r\n]" nil t)
3854                          (gnus-summary-article-number))))
3855     ;; If this is a gathered thread, we have to go some re-gathering.
3856     (when (stringp (car thread))
3857       (let ((subject (car thread))
3858             roots thr)
3859         (setq thread (cdr thread))
3860         (while thread
3861           (unless (memq (setq thr (gnus-id-to-thread
3862                                    (gnus-root-id
3863                                     (mail-header-id (caar thread)))))
3864                         roots)
3865             (push thr roots))
3866           (setq thread (cdr thread)))
3867         ;; We now have all (unique) roots.
3868         (if (= (length roots) 1)
3869             ;; All the loose roots are now one solid root.
3870             (setq thread (car roots))
3871           (setq thread (cons subject (gnus-sort-threads roots))))))
3872     (let (threads)
3873       ;; We then insert this thread into the summary buffer.
3874       (when line
3875         (goto-char (point-min))
3876         (forward-line (1- line)))
3877       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3878         (if gnus-show-threads
3879             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3880           (gnus-summary-prepare-unthreaded thread))
3881         (setq data (nreverse gnus-newsgroup-data))
3882         (setq threads gnus-newsgroup-threads))
3883       ;; We splice the new data into the data structure.
3884       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3885       ;;!!! then we want to insert at the beginning of the buffer.
3886       ;;!!! That happens to be true with Gnus now, but that may
3887       ;;!!! change in the future.  Perhaps.
3888       (gnus-data-enter-list
3889        (if line nil current) data (- (point) old-pos))
3890       (setq gnus-newsgroup-threads
3891             (nconc threads gnus-newsgroup-threads))
3892       (gnus-data-compute-positions))))
3893
3894 (defun gnus-number-to-header (number)
3895   "Return the header for article NUMBER."
3896   (let ((headers gnus-newsgroup-headers))
3897     (while (and headers
3898                 (not (= number (mail-header-number (car headers)))))
3899       (pop headers))
3900     (when headers
3901       (car headers))))
3902
3903 (defun gnus-parent-headers (in-headers &optional generation)
3904   "Return the headers of the GENERATIONeth parent of HEADERS."
3905   (unless generation
3906     (setq generation 1))
3907   (let ((parent t)
3908         (headers in-headers)
3909         references)
3910     (while (and parent
3911                 (not (zerop generation))
3912                 (setq references (mail-header-references headers)))
3913       (setq headers (if (and references
3914                              (setq parent (gnus-parent-id references)))
3915                         (car (gnus-id-to-thread parent))
3916                       nil))
3917       (decf generation))
3918     (and (not (eq headers in-headers))
3919          headers)))
3920
3921 (defun gnus-id-to-thread (id)
3922   "Return the (sub-)thread where ID appears."
3923   (gnus-gethash id gnus-newsgroup-dependencies))
3924
3925 (defun gnus-id-to-article (id)
3926   "Return the article number of ID."
3927   (let ((thread (gnus-id-to-thread id)))
3928     (when (and thread
3929                (car thread))
3930       (mail-header-number (car thread)))))
3931
3932 (defun gnus-id-to-header (id)
3933   "Return the article headers of ID."
3934   (car (gnus-id-to-thread id)))
3935
3936 (defun gnus-article-displayed-root-p (article)
3937   "Say whether ARTICLE is a root(ish) article."
3938   (let ((level (gnus-summary-thread-level article))
3939         (refs (mail-header-references  (gnus-summary-article-header article)))
3940         particle)
3941     (cond
3942      ((null level) nil)
3943      ((zerop level) t)
3944      ((null refs) t)
3945      ((null (gnus-parent-id refs)) t)
3946      ((and (= 1 level)
3947            (null (setq particle (gnus-id-to-article
3948                                  (gnus-parent-id refs))))
3949            (null (gnus-summary-thread-level particle)))))))
3950
3951 (defun gnus-root-id (id)
3952   "Return the id of the root of the thread where ID appears."
3953   (let (last-id prev)
3954     (while (and id (setq prev (car (gnus-id-to-thread id))))
3955       (setq last-id id
3956             id (gnus-parent-id (mail-header-references prev))))
3957     last-id))
3958
3959 (defun gnus-articles-in-thread (thread)
3960   "Return the list of articles in THREAD."
3961   (cons (mail-header-number (car thread))
3962         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3963
3964 (defun gnus-remove-thread (id &optional dont-remove)
3965   "Remove the thread that has ID in it."
3966   (let (headers thread last-id)
3967     ;; First go up in this thread until we find the root.
3968     (setq last-id (gnus-root-id id)
3969           headers (message-flatten-list (gnus-id-to-thread last-id)))
3970     ;; We have now found the real root of this thread.  It might have
3971     ;; been gathered into some loose thread, so we have to search
3972     ;; through the threads to find the thread we wanted.
3973     (let ((threads gnus-newsgroup-threads)
3974           sub)
3975       (while threads
3976         (setq sub (car threads))
3977         (if (stringp (car sub))
3978             ;; This is a gathered thread, so we look at the roots
3979             ;; below it to find whether this article is in this
3980             ;; gathered root.
3981             (progn
3982               (setq sub (cdr sub))
3983               (while sub
3984                 (when (member (caar sub) headers)
3985                   (setq thread (car threads)
3986                         threads nil
3987                         sub nil))
3988                 (setq sub (cdr sub))))
3989           ;; It's an ordinary thread, so we check it.
3990           (when (eq (car sub) (car headers))
3991             (setq thread sub
3992                   threads nil)))
3993         (setq threads (cdr threads)))
3994       ;; If this article is in no thread, then it's a root.
3995       (if thread
3996           (unless dont-remove
3997             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3998         (setq thread (gnus-id-to-thread last-id)))
3999       (when thread
4000         (prog1
4001             thread                      ; We return this thread.
4002           (unless dont-remove
4003             (if (stringp (car thread))
4004                 (progn
4005                   ;; If we use dummy roots, then we have to remove the
4006                   ;; dummy root as well.
4007                   (when (eq gnus-summary-make-false-root 'dummy)
4008                     ;; We go to the dummy root by going to
4009                     ;; the first sub-"thread", and then one line up.
4010                     (gnus-summary-goto-article
4011                      (mail-header-number (caadr thread)))
4012                     (forward-line -1)
4013                     (gnus-delete-line)
4014                     (gnus-data-compute-positions))
4015                   (setq thread (cdr thread))
4016                   (while thread
4017                     (gnus-remove-thread-1 (car thread))
4018                     (setq thread (cdr thread))))
4019               (gnus-remove-thread-1 thread))))))))
4020
4021 (defun gnus-remove-thread-1 (thread)
4022   "Remove the thread THREAD recursively."
4023   (let ((number (mail-header-number (pop thread)))
4024         d)
4025     (setq thread (reverse thread))
4026     (while thread
4027       (gnus-remove-thread-1 (pop thread)))
4028     (when (setq d (gnus-data-find number))
4029       (goto-char (gnus-data-pos d))
4030       (gnus-summary-show-thread)
4031       (gnus-data-remove
4032        number
4033        (- (gnus-point-at-bol)
4034           (prog1
4035               (1+ (gnus-point-at-eol))
4036             (gnus-delete-line)))))))
4037
4038 (defun gnus-sort-threads-1 (threads func)
4039   (sort (mapcar (lambda (thread)
4040                   (cons (car thread)
4041                         (and (cdr thread)
4042                              (gnus-sort-threads-1 (cdr thread) func))))
4043                 threads) func))
4044
4045 (defun gnus-sort-threads (threads)
4046   "Sort THREADS."
4047   (if (not gnus-thread-sort-functions)
4048       threads
4049     (gnus-message 8 "Sorting threads...")
4050     (prog1
4051         (gnus-sort-threads-1
4052          threads
4053          (gnus-make-sort-function gnus-thread-sort-functions))
4054       (gnus-message 8 "Sorting threads...done"))))
4055
4056 (defun gnus-sort-articles (articles)
4057   "Sort ARTICLES."
4058   (when gnus-article-sort-functions
4059     (gnus-message 7 "Sorting articles...")
4060     (prog1
4061         (setq gnus-newsgroup-headers
4062               (sort articles (gnus-make-sort-function
4063                               gnus-article-sort-functions)))
4064       (gnus-message 7 "Sorting articles...done"))))
4065
4066 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4067 (defmacro gnus-thread-header (thread)
4068   "Return header of first article in THREAD.
4069 Note that THREAD must never, ever be anything else than a variable -
4070 using some other form will lead to serious barfage."
4071   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4072   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4073   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4074         (vector thread) 2))
4075
4076 (defsubst gnus-article-sort-by-number (h1 h2)
4077   "Sort articles by article number."
4078   (< (mail-header-number h1)
4079      (mail-header-number h2)))
4080
4081 (defun gnus-thread-sort-by-number (h1 h2)
4082   "Sort threads by root article number."
4083   (gnus-article-sort-by-number
4084    (gnus-thread-header h1) (gnus-thread-header h2)))
4085
4086 (defsubst gnus-article-sort-by-lines (h1 h2)
4087   "Sort articles by article Lines header."
4088   (< (mail-header-lines h1)
4089      (mail-header-lines h2)))
4090
4091 (defun gnus-thread-sort-by-lines (h1 h2)
4092   "Sort threads by root article Lines header."
4093   (gnus-article-sort-by-lines
4094    (gnus-thread-header h1) (gnus-thread-header h2)))
4095
4096 (defsubst gnus-article-sort-by-chars (h1 h2)
4097   "Sort articles by octet length."
4098   (< (mail-header-chars h1)
4099      (mail-header-chars h2)))
4100
4101 (defun gnus-thread-sort-by-chars (h1 h2)
4102   "Sort threads by root article octet length."
4103   (gnus-article-sort-by-chars
4104    (gnus-thread-header h1) (gnus-thread-header h2)))
4105
4106 (defsubst gnus-article-sort-by-author (h1 h2)
4107   "Sort articles by root author."
4108   (string-lessp
4109    (let ((addr (car (mime-entity-read-field h1 'From))))
4110      (or (std11-full-name-string addr)
4111          (std11-address-string addr)
4112          ""))
4113    (let ((addr (car (mime-entity-read-field h2 'From))))
4114      (or (std11-full-name-string addr)
4115          (std11-address-string addr)
4116          ""))
4117    ))
4118
4119 (defun gnus-thread-sort-by-author (h1 h2)
4120   "Sort threads by root author."
4121   (gnus-article-sort-by-author
4122    (gnus-thread-header h1)  (gnus-thread-header h2)))
4123
4124 (defsubst gnus-article-sort-by-subject (h1 h2)
4125   "Sort articles by root subject."
4126   (string-lessp
4127    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4128    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4129
4130 (defun gnus-thread-sort-by-subject (h1 h2)
4131   "Sort threads by root subject."
4132   (gnus-article-sort-by-subject
4133    (gnus-thread-header h1) (gnus-thread-header h2)))
4134
4135 (defsubst gnus-article-sort-by-date (h1 h2)
4136   "Sort articles by root article date."
4137   (time-less-p
4138    (gnus-date-get-time (mail-header-date h1))
4139    (gnus-date-get-time (mail-header-date h2))))
4140
4141 (defun gnus-thread-sort-by-date (h1 h2)
4142   "Sort threads by root article date."
4143   (gnus-article-sort-by-date
4144    (gnus-thread-header h1) (gnus-thread-header h2)))
4145
4146 (defsubst gnus-article-sort-by-score (h1 h2)
4147   "Sort articles by root article score.
4148 Unscored articles will be counted as having a score of zero."
4149   (> (or (cdr (assq (mail-header-number h1)
4150                     gnus-newsgroup-scored))
4151          gnus-summary-default-score 0)
4152      (or (cdr (assq (mail-header-number h2)
4153                     gnus-newsgroup-scored))
4154          gnus-summary-default-score 0)))
4155
4156 (defun gnus-thread-sort-by-score (h1 h2)
4157   "Sort threads by root article score."
4158   (gnus-article-sort-by-score
4159    (gnus-thread-header h1) (gnus-thread-header h2)))
4160
4161 (defun gnus-thread-sort-by-total-score (h1 h2)
4162   "Sort threads by the sum of all scores in the thread.
4163 Unscored articles will be counted as having a score of zero."
4164   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4165
4166 (defun gnus-thread-total-score (thread)
4167   ;; This function find the total score of THREAD.
4168   (cond ((null thread)
4169          0)
4170         ((consp thread)
4171          (if (stringp (car thread))
4172              (apply gnus-thread-score-function 0
4173                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4174            (gnus-thread-total-score-1 thread)))
4175         (t
4176          (gnus-thread-total-score-1 (list thread)))))
4177
4178 (defun gnus-thread-total-score-1 (root)
4179   ;; This function find the total score of the thread below ROOT.
4180   (setq root (car root))
4181   (apply gnus-thread-score-function
4182          (or (append
4183               (mapcar 'gnus-thread-total-score
4184                       (cdr (gnus-id-to-thread (mail-header-id root))))
4185               (when (> (mail-header-number root) 0)
4186                 (list (or (cdr (assq (mail-header-number root)
4187                                      gnus-newsgroup-scored))
4188                           gnus-summary-default-score 0))))
4189              (list gnus-summary-default-score)
4190              '(0))))
4191
4192 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4193 (defvar gnus-tmp-prev-subject nil)
4194 (defvar gnus-tmp-false-parent nil)
4195 (defvar gnus-tmp-root-expunged nil)
4196 (defvar gnus-tmp-dummy-line nil)
4197
4198 (eval-when-compile (defvar gnus-tmp-header))
4199 (defun gnus-extra-header (type &optional header)
4200   "Return the extra header of TYPE."
4201   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4202       ""))
4203
4204 (defvar gnus-tmp-thread-tree-header-string "")
4205
4206 (defvar gnus-sum-thread-tree-root "> "
4207   "With %B spec, used for the root of a thread.
4208 If nil, use subject instead.")
4209 (defvar gnus-sum-thread-tree-single-indent ""
4210   "With %B spec, used for a thread with just one message.
4211 If nil, use subject instead.")
4212 (defvar gnus-sum-thread-tree-vertical "| "
4213   "With %B spec, used for drawing a vertical line.")
4214 (defvar gnus-sum-thread-tree-indent "  "
4215   "With %B spec, used for indenting.")
4216 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4217   "With %B spec, used for a leaf with brothers.")
4218 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4219   "With %B spec, used for a leaf without brothers.")
4220
4221 (defun gnus-summary-prepare-threads (threads)
4222   "Prepare summary buffer from THREADS and indentation LEVEL.
4223 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4224 or a straight list of headers."
4225   (gnus-message 7 "Generating summary...")
4226
4227   (setq gnus-newsgroup-threads threads)
4228   (beginning-of-line)
4229
4230   (let ((gnus-tmp-level 0)
4231         (default-score (or gnus-summary-default-score 0))
4232         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4233         thread number subject stack state gnus-tmp-gathered beg-match
4234         new-roots gnus-tmp-new-adopts thread-end
4235         gnus-tmp-header gnus-tmp-unread
4236         gnus-tmp-replied gnus-tmp-subject-or-nil
4237         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4238         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4239         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4240         tree-stack)
4241
4242     (setq gnus-tmp-prev-subject nil)
4243
4244     (if (vectorp (car threads))
4245         ;; If this is a straight (sic) list of headers, then a
4246         ;; threaded summary display isn't required, so we just create
4247         ;; an unthreaded one.
4248         (gnus-summary-prepare-unthreaded threads)
4249
4250       ;; Do the threaded display.
4251
4252       (while (or threads stack gnus-tmp-new-adopts new-roots)
4253
4254         (if (and (= gnus-tmp-level 0)
4255                  (or (not stack)
4256                      (= (caar stack) 0))
4257                  (not gnus-tmp-false-parent)
4258                  (or gnus-tmp-new-adopts new-roots))
4259             (if gnus-tmp-new-adopts
4260                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4261                       thread (list (car gnus-tmp-new-adopts))
4262                       gnus-tmp-header (caar thread)
4263                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4264               (when new-roots
4265                 (setq thread (list (car new-roots))
4266                       gnus-tmp-header (caar thread)
4267                       new-roots (cdr new-roots))))
4268
4269           (if threads
4270               ;; If there are some threads, we do them before the
4271               ;; threads on the stack.
4272               (setq thread threads
4273                     gnus-tmp-header (caar thread))
4274             ;; There were no current threads, so we pop something off
4275             ;; the stack.
4276             (setq state (car stack)
4277                   gnus-tmp-level (car state)
4278                   tree-stack (cadr state)
4279                   thread (caddr state)
4280                   stack (cdr stack)
4281                   gnus-tmp-header (caar thread))))
4282
4283         (setq gnus-tmp-false-parent nil)
4284         (setq gnus-tmp-root-expunged nil)
4285         (setq thread-end nil)
4286
4287         (if (stringp gnus-tmp-header)
4288             ;; The header is a dummy root.
4289             (cond
4290              ((eq gnus-summary-make-false-root 'adopt)
4291               ;; We let the first article adopt the rest.
4292               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4293                                                (cddar thread)))
4294               (setq gnus-tmp-gathered
4295                     (nconc (mapcar
4296                             (lambda (h) (mail-header-number (car h)))
4297                             (cddar thread))
4298                            gnus-tmp-gathered))
4299               (setq thread (cons (list (caar thread)
4300                                        (cadar thread))
4301                                  (cdr thread)))
4302               (setq gnus-tmp-level -1
4303                     gnus-tmp-false-parent t))
4304              ((eq gnus-summary-make-false-root 'empty)
4305               ;; We print adopted articles with empty subject fields.
4306               (setq gnus-tmp-gathered
4307                     (nconc (mapcar
4308                             (lambda (h) (mail-header-number (car h)))
4309                             (cddar thread))
4310                            gnus-tmp-gathered))
4311               (setq gnus-tmp-level -1))
4312              ((eq gnus-summary-make-false-root 'dummy)
4313               ;; We remember that we probably want to output a dummy
4314               ;; root.
4315               (setq gnus-tmp-dummy-line gnus-tmp-header)
4316               (setq gnus-tmp-prev-subject gnus-tmp-header))
4317              (t
4318               ;; We do not make a root for the gathered
4319               ;; sub-threads at all.
4320               (setq gnus-tmp-level -1)))
4321
4322           (setq number (mail-header-number gnus-tmp-header)
4323                 subject (mail-header-subject gnus-tmp-header))
4324
4325           (cond
4326            ;; If the thread has changed subject, we might want to make
4327            ;; this subthread into a root.
4328            ((and (null gnus-thread-ignore-subject)
4329                  (not (zerop gnus-tmp-level))
4330                  gnus-tmp-prev-subject
4331                  (not (inline
4332                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4333             (setq new-roots (nconc new-roots (list (car thread)))
4334                   thread-end t
4335                   gnus-tmp-header nil))
4336            ;; If the article lies outside the current limit,
4337            ;; then we do not display it.
4338            ((not (memq number gnus-newsgroup-limit))
4339             (setq gnus-tmp-gathered
4340                   (nconc (mapcar
4341                           (lambda (h) (mail-header-number (car h)))
4342                           (cdar thread))
4343                          gnus-tmp-gathered))
4344             (setq gnus-tmp-new-adopts (if (cdar thread)
4345                                           (append gnus-tmp-new-adopts
4346                                                   (cdar thread))
4347                                         gnus-tmp-new-adopts)
4348                   thread-end t
4349                   gnus-tmp-header nil)
4350             (when (zerop gnus-tmp-level)
4351               (setq gnus-tmp-root-expunged t)))
4352            ;; Perhaps this article is to be marked as read?
4353            ((and gnus-summary-mark-below
4354                  (< (or (cdr (assq number gnus-newsgroup-scored))
4355                         default-score)
4356                     gnus-summary-mark-below)
4357                  ;; Don't touch sparse articles.
4358                  (not (gnus-summary-article-sparse-p number))
4359                  (not (gnus-summary-article-ancient-p number)))
4360             (setq gnus-newsgroup-unreads
4361                   (delq number gnus-newsgroup-unreads))
4362             (if gnus-newsgroup-auto-expire
4363                 (push number gnus-newsgroup-expirable)
4364               (push (cons number gnus-low-score-mark)
4365                     gnus-newsgroup-reads))))
4366
4367           (when gnus-tmp-header
4368             ;; We may have an old dummy line to output before this
4369             ;; article.
4370             (when (and gnus-tmp-dummy-line
4371                        (gnus-subject-equal
4372                         gnus-tmp-dummy-line
4373                         (mail-header-subject gnus-tmp-header)))
4374               (gnus-summary-insert-dummy-line
4375                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4376               (setq gnus-tmp-dummy-line nil))
4377
4378             ;; Compute the mark.
4379             (setq gnus-tmp-unread (gnus-article-mark number))
4380
4381             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4382                                   gnus-tmp-header gnus-tmp-level)
4383                   gnus-newsgroup-data)
4384
4385             ;; Actually insert the line.
4386             (setq
4387              gnus-tmp-subject-or-nil
4388              (cond
4389               ((and gnus-thread-ignore-subject
4390                     gnus-tmp-prev-subject
4391                     (not (inline (gnus-subject-equal
4392                                   gnus-tmp-prev-subject subject))))
4393                subject)
4394               ((zerop gnus-tmp-level)
4395                (if (and (eq gnus-summary-make-false-root 'empty)
4396                         (memq number gnus-tmp-gathered)
4397                         gnus-tmp-prev-subject
4398                         (inline (gnus-subject-equal
4399                                  gnus-tmp-prev-subject subject)))
4400                    gnus-summary-same-subject
4401                  subject))
4402               (t gnus-summary-same-subject)))
4403             (if (and (eq gnus-summary-make-false-root 'adopt)
4404                      (= gnus-tmp-level 1)
4405                      (memq number gnus-tmp-gathered))
4406                 (setq gnus-tmp-opening-bracket ?\<
4407                       gnus-tmp-closing-bracket ?\>)
4408               (setq gnus-tmp-opening-bracket ?\[
4409                     gnus-tmp-closing-bracket ?\]))
4410             (setq
4411              gnus-tmp-indentation
4412              (aref gnus-thread-indent-array gnus-tmp-level)
4413              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4414              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4415                                 gnus-summary-default-score 0)
4416              gnus-tmp-score-char
4417              (if (or (null gnus-summary-default-score)
4418                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4419                          gnus-summary-zcore-fuzz))
4420                  ?\ ;;;Whitespace
4421                (if (< gnus-tmp-score gnus-summary-default-score)
4422                    gnus-score-below-mark gnus-score-over-mark))
4423              gnus-tmp-replied
4424              (cond ((memq number gnus-newsgroup-processable)
4425                     gnus-process-mark)
4426                    ((memq number gnus-newsgroup-cached)
4427                     gnus-cached-mark)
4428                    ((memq number gnus-newsgroup-replied)
4429                     gnus-replied-mark)
4430                    ((memq number gnus-newsgroup-forwarded)
4431                     gnus-forwarded-mark)
4432                    ((memq number gnus-newsgroup-saved)
4433                     gnus-saved-mark)
4434                    ((memq number gnus-newsgroup-recent)
4435                     gnus-recent-mark)
4436                    ((memq number gnus-newsgroup-unseen)
4437                     gnus-unseen-mark)
4438                    (t gnus-no-mark))
4439              gnus-tmp-from (mail-header-from gnus-tmp-header)
4440              gnus-tmp-name
4441              (cond
4442               ((string-match "<[^>]+> *$" gnus-tmp-from)
4443                (setq beg-match (match-beginning 0))
4444                (or (and (string-match "^\".+\"" gnus-tmp-from)
4445                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4446                    (substring gnus-tmp-from 0 beg-match)))
4447               ((string-match "(.+)" gnus-tmp-from)
4448                (substring gnus-tmp-from
4449                           (1+ (match-beginning 0)) (1- (match-end 0))))
4450               (t gnus-tmp-from))
4451              gnus-tmp-thread-tree-header-string
4452              (cond
4453               ((not gnus-show-threads) "")
4454               ((zerop gnus-tmp-level)
4455                (if (cdar thread)
4456                    (or gnus-sum-thread-tree-root subject)
4457                  (or gnus-sum-thread-tree-single-indent subject)))
4458               (t
4459                (concat (apply 'concat
4460                               (mapcar (lambda (item)
4461                                         (if (= item 1)
4462                                             gnus-sum-thread-tree-vertical
4463                                           gnus-sum-thread-tree-indent))
4464                                       (cdr (reverse tree-stack))))
4465                        (if (nth 1 thread)
4466                            gnus-sum-thread-tree-leaf-with-other
4467                          gnus-sum-thread-tree-single-leaf)))))
4468             (when (string= gnus-tmp-name "")
4469               (setq gnus-tmp-name gnus-tmp-from))
4470             (unless (numberp gnus-tmp-lines)
4471               (setq gnus-tmp-lines -1))
4472             (if (= gnus-tmp-lines -1)
4473                 (setq gnus-tmp-lines "?")
4474               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4475             (gnus-put-text-property
4476              (point)
4477              (progn (eval gnus-summary-line-format-spec) (point))
4478              'gnus-number number)
4479             (when gnus-visual-p
4480               (forward-line -1)
4481               (gnus-run-hooks 'gnus-summary-update-hook)
4482               (forward-line 1))
4483
4484             (setq gnus-tmp-prev-subject subject)))
4485
4486         (when (nth 1 thread)
4487           (push (list (max 0 gnus-tmp-level)
4488                       (copy-list tree-stack)
4489                       (nthcdr 1 thread))
4490                 stack))
4491         (push (if (nth 1 thread) 1 0) tree-stack)
4492         (incf gnus-tmp-level)
4493         (setq threads (if thread-end nil (cdar thread)))
4494         (unless threads
4495           (setq gnus-tmp-level 0)))))
4496   (gnus-message 7 "Generating summary...done"))
4497
4498 (defun gnus-summary-prepare-unthreaded (headers)
4499   "Generate an unthreaded summary buffer based on HEADERS."
4500   (let (header number mark)
4501
4502     (beginning-of-line)
4503
4504     (while headers
4505       ;; We may have to root out some bad articles...
4506       (when (memq (setq number (mail-header-number
4507                                 (setq header (pop headers))))
4508                   gnus-newsgroup-limit)
4509         ;; Mark article as read when it has a low score.
4510         (when (and gnus-summary-mark-below
4511                    (< (or (cdr (assq number gnus-newsgroup-scored))
4512                           gnus-summary-default-score 0)
4513                       gnus-summary-mark-below)
4514                    (not (gnus-summary-article-ancient-p number)))
4515           (setq gnus-newsgroup-unreads
4516                 (delq number gnus-newsgroup-unreads))
4517           (if gnus-newsgroup-auto-expire
4518               (push number gnus-newsgroup-expirable)
4519             (push (cons number gnus-low-score-mark)
4520                   gnus-newsgroup-reads)))
4521
4522         (setq mark (gnus-article-mark number))
4523         (push (gnus-data-make number mark (1+ (point)) header 0)
4524               gnus-newsgroup-data)
4525         (gnus-summary-insert-line
4526          header 0 number
4527          mark (memq number gnus-newsgroup-replied)
4528          (memq number gnus-newsgroup-expirable)
4529          (mail-header-subject header) nil
4530          (cdr (assq number gnus-newsgroup-scored))
4531          (memq number gnus-newsgroup-processable))))))
4532
4533 (defun gnus-summary-remove-list-identifiers ()
4534   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4535   (let ((regexp (if (consp gnus-list-identifiers)
4536                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4537                   gnus-list-identifiers))
4538         changed subject)
4539     (when regexp
4540       (dolist (header gnus-newsgroup-headers)
4541         (setq subject (mail-header-subject header)
4542               changed nil)
4543         (while (string-match
4544                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4545                 subject)
4546           (setq subject
4547                 (concat (substring subject 0 (match-beginning 2))
4548                         (substring subject (match-end 0)))
4549                 changed t))
4550         (when (and changed
4551                    (string-match
4552                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4553           (setq subject
4554                 (concat (substring subject 0 (match-beginning 1))
4555                         (substring subject (match-end 1)))))
4556         (when changed
4557           (mail-header-set-subject header subject))))))
4558
4559 (defun gnus-fetch-headers (articles)
4560   "Fetch headers of ARTICLES."
4561   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4562     (gnus-message 5 "Fetching headers for %s..." name)
4563     (prog1
4564         (if (eq 'nov
4565                 (setq gnus-headers-retrieved-by
4566                       (gnus-retrieve-headers
4567                        articles gnus-newsgroup-name
4568                        ;; We might want to fetch old headers, but
4569                        ;; not if there is only 1 article.
4570                        (and (or (and
4571                                  (not (eq gnus-fetch-old-headers 'some))
4572                                  (not (numberp gnus-fetch-old-headers)))
4573                                 (> (length articles) 1))
4574                             gnus-fetch-old-headers))))
4575             (gnus-get-newsgroup-headers-xover
4576              articles nil nil gnus-newsgroup-name t)
4577           (gnus-get-newsgroup-headers))
4578       (gnus-message 5 "Fetching headers for %s...done" name))))
4579
4580 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4581   "Select newsgroup GROUP.
4582 If READ-ALL is non-nil, all articles in the group are selected.
4583 If SELECT-ARTICLES, only select those articles from GROUP."
4584   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4585          ;;!!! Dirty hack; should be removed.
4586          (gnus-summary-ignore-duplicates
4587           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4588               t
4589             gnus-summary-ignore-duplicates))
4590          (info (nth 2 entry))
4591          articles fetched-articles cached)
4592
4593     (unless (gnus-check-server
4594              (set (make-local-variable 'gnus-current-select-method)
4595                   (gnus-find-method-for-group group)))
4596       (error "Couldn't open server"))
4597
4598     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4599         (gnus-activate-group group)     ; Or we can activate it...
4600         (progn                          ; Or we bug out.
4601           (when (equal major-mode 'gnus-summary-mode)
4602             (kill-buffer (current-buffer)))
4603           (error "Couldn't activate group %s: %s"
4604                  group (gnus-status-message group))))
4605
4606     (unless (gnus-request-group group t)
4607       (when (equal major-mode 'gnus-summary-mode)
4608         (kill-buffer (current-buffer)))
4609       (error "Couldn't request group %s: %s"
4610              group (gnus-status-message group)))
4611
4612     (setq gnus-newsgroup-name group
4613           gnus-newsgroup-unselected nil
4614           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4615
4616     (let ((display (gnus-group-find-parameter group 'display)))
4617       (setq gnus-newsgroup-display
4618             (cond
4619              ((not (zerop (or (car-safe read-all) 0)))
4620               ;; The user entered the group with C-u SPC/RET, let's show
4621               ;; all articles.
4622               'gnus-not-ignore)
4623              ((eq display 'all)
4624               'gnus-not-ignore)
4625              ((arrayp display)
4626               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4627              ((numberp display)
4628               ;; The following is probably the "correct" solution, but
4629               ;; it makes Gnus fetch all headers and then limit the
4630               ;; articles (which is slow), so instead we hack the
4631               ;; select-articles parameter instead. -- Simon Josefsson
4632               ;; <jas@kth.se>
4633               ;;
4634               ;; (gnus-byte-compile
4635               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4636               ;;                         display)))))
4637               (setq select-articles
4638                     (gnus-uncompress-range
4639                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4640                              (if (> tmp 0)
4641                                  tmp
4642                                1))
4643                            (cdr (gnus-active group)))))
4644               nil)
4645              (t
4646               nil))))
4647
4648     (gnus-summary-setup-default-charset)
4649
4650     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4651     (when (gnus-virtual-group-p group)
4652       (setq cached gnus-newsgroup-cached))
4653
4654     (setq gnus-newsgroup-unreads
4655           (gnus-set-difference
4656            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4657            gnus-newsgroup-dormant))
4658
4659     (setq gnus-newsgroup-processable nil)
4660
4661     (gnus-update-read-articles group gnus-newsgroup-unreads)
4662
4663     ;; Adjust and set lists of article marks.
4664     (when info
4665       (gnus-adjust-marked-articles info))
4666
4667     (if (setq articles select-articles)
4668         (setq gnus-newsgroup-unselected
4669               (gnus-sorted-intersection
4670                gnus-newsgroup-unreads
4671                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4672       (setq articles (gnus-articles-to-read group read-all)))
4673
4674     (cond
4675      ((null articles)
4676       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4677       'quit)
4678      ((eq articles 0) nil)
4679      (t
4680       ;; Init the dependencies hash table.
4681       (setq gnus-newsgroup-dependencies
4682             (gnus-make-hashtable (length articles)))
4683       (gnus-set-global-variables)
4684       ;; Retrieve the headers and read them in.
4685       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4686
4687       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4688       (when cached
4689         (setq gnus-newsgroup-cached cached))
4690
4691       ;; Suppress duplicates?
4692       (when gnus-suppress-duplicates
4693         (gnus-dup-suppress-articles))
4694
4695       ;; Set the initial limit.
4696       (setq gnus-newsgroup-limit (copy-sequence articles))
4697       ;; Remove canceled articles from the list of unread articles.
4698       (setq fetched-articles
4699             (mapcar (lambda (headers) (mail-header-number headers))
4700                     gnus-newsgroup-headers))
4701       (setq gnus-newsgroup-articles fetched-articles)
4702       (setq gnus-newsgroup-unreads
4703             (gnus-set-sorted-intersection
4704              gnus-newsgroup-unreads fetched-articles))
4705
4706       ;; The `seen' marks are treated specially.
4707       (if (not gnus-newsgroup-seen)
4708           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4709         (dolist (article gnus-newsgroup-articles)
4710           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4711             (push article gnus-newsgroup-unseen)))
4712         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4713
4714       ;; Removed marked articles that do not exist.
4715       (gnus-update-missing-marks
4716        (gnus-sorted-complement fetched-articles articles))
4717       ;; We might want to build some more threads first.
4718       (when (and gnus-fetch-old-headers
4719                  (eq gnus-headers-retrieved-by 'nov))
4720         (if (eq gnus-fetch-old-headers 'invisible)
4721             (gnus-build-all-threads)
4722           (gnus-build-old-threads)))
4723       ;; Let the Gnus agent mark articles as read.
4724       (when gnus-agent
4725         (gnus-agent-get-undownloaded-list))
4726       ;; Remove list identifiers from subject
4727       (when gnus-list-identifiers
4728         (gnus-summary-remove-list-identifiers))
4729       ;; Check whether auto-expire is to be done in this group.
4730       (setq gnus-newsgroup-auto-expire
4731             (gnus-group-auto-expirable-p group))
4732       ;; Set up the article buffer now, if necessary.
4733       (unless gnus-single-article-buffer
4734         (gnus-article-setup-buffer))
4735       ;; First and last article in this newsgroup.
4736       (when gnus-newsgroup-headers
4737         (setq gnus-newsgroup-begin
4738               (mail-header-number (car gnus-newsgroup-headers))
4739               gnus-newsgroup-end
4740               (mail-header-number
4741                (gnus-last-element gnus-newsgroup-headers))))
4742       ;; GROUP is successfully selected.
4743       (or gnus-newsgroup-headers t)))))
4744
4745 (defun gnus-summary-display-make-predicate (display)
4746   (require 'gnus-agent)
4747   (when (= (length display) 1)
4748     (setq display (car display)))
4749   (unless gnus-summary-display-cache
4750     (dolist (elem (append (list (cons 'read 'read)
4751                                 (cons 'unseen 'unseen))
4752                           gnus-article-mark-lists))
4753       (push (cons (cdr elem)
4754                   (gnus-byte-compile
4755                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4756             gnus-summary-display-cache)))
4757   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4758     (gnus-get-predicate display)))
4759
4760 ;; Uses the dynamically bound `number' variable.
4761 (defvar number)
4762 (defun gnus-article-marked-p (type &optional article)
4763   (let ((article (or article number)))
4764     (cond
4765      ((eq type 'tick)
4766       (memq article gnus-newsgroup-marked))
4767      ((eq type 'unsend)
4768       (memq article gnus-newsgroup-unsendable))
4769      ((eq type 'undownload)
4770       (memq article gnus-newsgroup-undownloaded))
4771      ((eq type 'download)
4772       (memq article gnus-newsgroup-downloadable))
4773      ((eq type 'unread)
4774       (memq article gnus-newsgroup-unreads))
4775      ((eq type 'read)
4776       (memq article gnus-newsgroup-reads))
4777      ((eq type 'dormant)
4778       (memq article gnus-newsgroup-dormant) )
4779      ((eq type 'expire)
4780       (memq article gnus-newsgroup-expirable))
4781      ((eq type 'reply)
4782       (memq article gnus-newsgroup-replied))
4783      ((eq type 'killed)
4784       (memq article gnus-newsgroup-killed))
4785      ((eq type 'bookmark)
4786       (assq article gnus-newsgroup-bookmarks))
4787      ((eq type 'score)
4788       (assq article gnus-newsgroup-scored))
4789      ((eq type 'save)
4790       (memq article gnus-newsgroup-saved))
4791      ((eq type 'cache)
4792       (memq article gnus-newsgroup-cached))
4793      ((eq type 'forward)
4794       (memq article gnus-newsgroup-forwarded))
4795      ((eq type 'seen)
4796       (not (memq article gnus-newsgroup-unseen)))
4797      ((eq type 'recent)
4798       (memq article gnus-newsgroup-recent))
4799      (t t))))
4800
4801 (defun gnus-articles-to-read (group &optional read-all)
4802   "Find out what articles the user wants to read."
4803   (let* ((articles
4804           ;; Select all articles if `read-all' is non-nil, or if there
4805           ;; are no unread articles.
4806           (if (or read-all
4807                   (and (zerop (length gnus-newsgroup-marked))
4808                        (zerop (length gnus-newsgroup-unreads)))
4809                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4810               ;; We want to select the headers for all the articles in
4811               ;; the group, so we select either all the active
4812               ;; articles in the group, or (if that's nil), the
4813               ;; articles in the cache.
4814               (or
4815                (gnus-uncompress-range (gnus-active group))
4816                (gnus-cache-articles-in-group group))
4817             ;; Select only the "normal" subset of articles.
4818             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4819                           (copy-sequence gnus-newsgroup-unreads))
4820                   '<)))
4821          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4822          (scored (length scored-list))
4823          (number (length articles))
4824          (marked (+ (length gnus-newsgroup-marked)
4825                     (length gnus-newsgroup-dormant)))
4826          (select
4827           (cond
4828            ((numberp read-all)
4829             read-all)
4830            (t
4831             (condition-case ()
4832                 (cond
4833                  ((and (or (<= scored marked) (= scored number))
4834                        (natnump gnus-large-newsgroup)
4835                        (> number gnus-large-newsgroup))
4836                   (let* ((cursor-in-echo-area nil)
4837                          (input
4838                           (read-from-minibuffer
4839                            (format
4840                             "How many articles from %s (max %d): "
4841                             (gnus-limit-string
4842                              (gnus-group-decoded-name gnus-newsgroup-name)
4843                              35)
4844                             number)
4845                            (cons (number-to-string gnus-large-newsgroup)
4846                                  0))))
4847                     (if (string-match "^[ \t]*$" input)
4848                         number
4849                       input)))
4850                  ((and (> scored marked) (< scored number)
4851                        (> (- scored number) 20))
4852                   (let ((input
4853                          (read-string
4854                           (format "%s %s (%d scored, %d total): "
4855                                   "How many articles from"
4856                                   (gnus-group-decoded-name group)
4857                                   scored number))))
4858                     (if (string-match "^[ \t]*$" input)
4859                         number input)))
4860                  (t number))
4861               (quit
4862                (message "Quit getting the articles to read")
4863                nil))))))
4864     (setq select (if (stringp select) (string-to-number select) select))
4865     (if (or (null select) (zerop select))
4866         select
4867       (if (and (not (zerop scored)) (<= (abs select) scored))
4868           (progn
4869             (setq articles (sort scored-list '<))
4870             (setq number (length articles)))
4871         (setq articles (copy-sequence articles)))
4872
4873       (when (< (abs select) number)
4874         (if (< select 0)
4875             ;; Select the N oldest articles.
4876             (setcdr (nthcdr (1- (abs select)) articles) nil)
4877           ;; Select the N most recent articles.
4878           (setq articles (nthcdr (- number select) articles))))
4879       (setq gnus-newsgroup-unselected
4880             (gnus-sorted-intersection
4881              gnus-newsgroup-unreads
4882              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4883       (when gnus-alter-articles-to-read-function
4884         (setq gnus-newsgroup-unreads
4885               (sort
4886                (funcall gnus-alter-articles-to-read-function
4887                         gnus-newsgroup-name gnus-newsgroup-unreads)
4888                '<)))
4889       articles)))
4890
4891 (defun gnus-killed-articles (killed articles)
4892   (let (out)
4893     (while articles
4894       (when (inline (gnus-member-of-range (car articles) killed))
4895         (push (car articles) out))
4896       (setq articles (cdr articles)))
4897     out))
4898
4899 (defun gnus-uncompress-marks (marks)
4900   "Uncompress the mark ranges in MARKS."
4901   (let ((uncompressed '(score bookmark))
4902         out)
4903     (while marks
4904       (if (memq (caar marks) uncompressed)
4905           (push (car marks) out)
4906         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4907       (setq marks (cdr marks)))
4908     out))
4909
4910 (defun gnus-article-mark-to-type (mark)
4911   "Return the type of MARK."
4912   (or (cadr (assq mark gnus-article-special-mark-lists))
4913       'list))
4914
4915 (defun gnus-article-unpropagatable-p (mark)
4916   "Return whether MARK should be propagated to backend."
4917   (memq mark gnus-article-unpropagated-mark-lists))
4918
4919 (defun gnus-adjust-marked-articles (info)
4920   "Set all article lists and remove all marks that are no longer valid."
4921   (let* ((marked-lists (gnus-info-marks info))
4922          (active (gnus-active (gnus-info-group info)))
4923          (min (car active))
4924          (max (cdr active))
4925          (types gnus-article-mark-lists)
4926          marks var articles article mark mark-type)
4927
4928     (dolist (marks marked-lists)
4929       (setq mark (car marks)
4930             mark-type (gnus-article-mark-to-type mark)
4931             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4932
4933       ;; We set the variable according to the type of the marks list,
4934       ;; and then adjust the marks to a subset of the active articles.
4935       (cond
4936        ;; Adjust "simple" lists.
4937        ((eq mark-type 'list)
4938         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4939         (when (memq mark '(tick dormant expire reply save))
4940           (while articles
4941             (when (or (< (setq article (pop articles)) min) (> article max))
4942               (set var (delq article (symbol-value var)))))))
4943        ;; Adjust assocs.
4944        ((eq mark-type 'tuple)
4945         (set var (setq articles (cdr marks)))
4946         (when (not (listp (cdr (symbol-value var))))
4947           (set var (list (symbol-value var))))
4948         (when (not (listp (cdr articles)))
4949           (setq articles (list articles)))
4950         (while articles
4951           (when (or (not (consp (setq article (pop articles))))
4952                     (< (car article) min)
4953                     (> (car article) max))
4954             (set var (delq article (symbol-value var))))))
4955        ;; Adjust ranges (sloppily).
4956        ((eq mark-type 'range)
4957         (cond
4958          ((eq mark 'seen)
4959           (setq articles (cdr marks))
4960           (while (and articles
4961                       (or (and (consp (car articles))
4962                                (> min (cdar articles)))
4963                           (and (numberp (car articles))
4964                                (> min (car articles)))))
4965             (pop articles))
4966           (set var articles))))))))
4967
4968 (defun gnus-update-missing-marks (missing)
4969   "Go through the list of MISSING articles and remove them from the mark lists."
4970   (when missing
4971     (let (var m)
4972       ;; Go through all types.
4973       (dolist (elem gnus-article-mark-lists)
4974         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4975           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4976           (when (symbol-value var)
4977             ;; This list has articles.  So we delete all missing
4978             ;; articles from it.
4979             (setq m missing)
4980             (while m
4981               (set var (delq (pop m) (symbol-value var))))))))))
4982
4983 (defun gnus-update-marks ()
4984   "Enter the various lists of marked articles into the newsgroup info list."
4985   (let ((types gnus-article-mark-lists)
4986         (info (gnus-get-info gnus-newsgroup-name))
4987         type list newmarked symbol delta-marks)
4988     (when info
4989       ;; Add all marks lists to the list of marks lists.
4990       (while (setq type (pop types))
4991         (setq list (symbol-value
4992                     (setq symbol
4993                           (intern (format "gnus-newsgroup-%s" (car type))))))
4994
4995         (when list
4996           ;; Get rid of the entries of the articles that have the
4997           ;; default score.
4998           (when (and (eq (cdr type) 'score)
4999                      gnus-save-score
5000                      list)
5001             (let* ((arts list)
5002                    (prev (cons nil list))
5003                    (all prev))
5004               (while arts
5005                 (if (or (not (consp (car arts)))
5006                         (= (cdar arts) gnus-summary-default-score))
5007                     (setcdr prev (cdr arts))
5008                   (setq prev arts))
5009                 (setq arts (cdr arts)))
5010               (setq list (cdr all)))))
5011
5012         (when (eq (cdr type) 'seen)
5013           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5014
5015         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5016           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5017
5018         (when (and (gnus-check-backend-function
5019                     'request-set-mark gnus-newsgroup-name)
5020                    (not (gnus-article-unpropagatable-p (cdr type))))
5021           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5022                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5023                  (add (gnus-remove-from-range
5024                        (gnus-copy-sequence list) old)))
5025             (when add
5026               (push (list add 'add (list (cdr type))) delta-marks))
5027             (when del
5028               (push (list del 'del (list (cdr type))) delta-marks))))
5029
5030         (when list
5031           (push (cons (cdr type) list) newmarked)))
5032
5033       (when delta-marks
5034         (unless (gnus-check-group gnus-newsgroup-name)
5035           (error "Can't open server for %s" gnus-newsgroup-name))
5036         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5037
5038       ;; Enter these new marks into the info of the group.
5039       (if (nthcdr 3 info)
5040           (setcar (nthcdr 3 info) newmarked)
5041         ;; Add the marks lists to the end of the info.
5042         (when newmarked
5043           (setcdr (nthcdr 2 info) (list newmarked))))
5044
5045       ;; Cut off the end of the info if there's nothing else there.
5046       (let ((i 5))
5047         (while (and (> i 2)
5048                     (not (nth i info)))
5049           (when (nthcdr (decf i) info)
5050             (setcdr (nthcdr i info) nil)))))))
5051
5052 (defun gnus-set-mode-line (where)
5053   "Set the mode line of the article or summary buffers.
5054 If WHERE is `summary', the summary mode line format will be used."
5055   ;; Is this mode line one we keep updated?
5056   (when (and (memq where gnus-updated-mode-lines)
5057              (symbol-value
5058               (intern (format "gnus-%s-mode-line-format-spec" where))))
5059     (let (mode-string)
5060       (save-excursion
5061         ;; We evaluate this in the summary buffer since these
5062         ;; variables are buffer-local to that buffer.
5063         (set-buffer gnus-summary-buffer)
5064         ;; We bind all these variables that are used in the `eval' form
5065         ;; below.
5066         (let* ((mformat (symbol-value
5067                          (intern
5068                           (format "gnus-%s-mode-line-format-spec" where))))
5069                (gnus-tmp-group-name (gnus-group-decoded-name
5070                                      gnus-newsgroup-name))
5071                (gnus-tmp-article-number (or gnus-current-article 0))
5072                (gnus-tmp-unread gnus-newsgroup-unreads)
5073                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5074                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5075                (gnus-tmp-unread-and-unselected
5076                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5077                             (zerop gnus-tmp-unselected))
5078                        "")
5079                       ((zerop gnus-tmp-unselected)
5080                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5081                       (t (format "{%d(+%d) more}"
5082                                  gnus-tmp-unread-and-unticked
5083                                  gnus-tmp-unselected))))
5084                (gnus-tmp-subject
5085                 (if (and gnus-current-headers
5086                          (vectorp gnus-current-headers))
5087                     (gnus-mode-string-quote
5088                      (mail-header-subject gnus-current-headers))
5089                   ""))
5090                bufname-length max-len
5091                gnus-tmp-header);; passed as argument to any user-format-funcs
5092           (setq mode-string (eval mformat))
5093           (setq bufname-length (if (string-match "%b" mode-string)
5094                                    (- (length
5095                                        (buffer-name
5096                                         (if (eq where 'summary)
5097                                             nil
5098                                           (get-buffer gnus-article-buffer))))
5099                                       2)
5100                                  0))
5101           (setq max-len (max 4 (if gnus-mode-non-string-length
5102                                    (- (window-width)
5103                                       gnus-mode-non-string-length
5104                                       bufname-length)
5105                                  (length mode-string))))
5106           ;; We might have to chop a bit of the string off...
5107           (when (> (length mode-string) max-len)
5108             (setq mode-string
5109                   (concat (gnus-truncate-string mode-string (- max-len 3))
5110                           "...")))
5111           ;; Pad the mode string a bit.
5112           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5113       ;; Update the mode line.
5114       (setq mode-line-buffer-identification
5115             (gnus-mode-line-buffer-identification (list mode-string)))
5116       (set-buffer-modified-p t))))
5117
5118 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5119   "Go through the HEADERS list and add all Xrefs to a hash table.
5120 The resulting hash table is returned, or nil if no Xrefs were found."
5121   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5122          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5123          (xref-hashtb (gnus-make-hashtable))
5124          start group entry number xrefs header)
5125     (while headers
5126       (setq header (pop headers))
5127       (when (and (setq xrefs (mail-header-xref header))
5128                  (not (memq (setq number (mail-header-number header))
5129                             unreads)))
5130         (setq start 0)
5131         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5132           (setq start (match-end 0))
5133           (setq group (if prefix
5134                           (concat prefix (substring xrefs (match-beginning 1)
5135                                                     (match-end 1)))
5136                         (substring xrefs (match-beginning 1) (match-end 1))))
5137           (setq number
5138                 (string-to-int (substring xrefs (match-beginning 2)
5139                                           (match-end 2))))
5140           (if (setq entry (gnus-gethash group xref-hashtb))
5141               (setcdr entry (cons number (cdr entry)))
5142             (gnus-sethash group (cons number nil) xref-hashtb)))))
5143     (and start xref-hashtb)))
5144
5145 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5146   "Look through all the headers and mark the Xrefs as read."
5147   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5148         name entry info xref-hashtb idlist method nth4)
5149     (save-excursion
5150       (set-buffer gnus-group-buffer)
5151       (when (setq xref-hashtb
5152                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5153         (mapatoms
5154          (lambda (group)
5155            (unless (string= from-newsgroup (setq name (symbol-name group)))
5156              (setq idlist (symbol-value group))
5157              ;; Dead groups are not updated.
5158              (and (prog1
5159                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5160                             info (nth 2 entry))
5161                     (when (stringp (setq nth4 (gnus-info-method info)))
5162                       (setq nth4 (gnus-server-to-method nth4))))
5163                   ;; Only do the xrefs if the group has the same
5164                   ;; select method as the group we have just read.
5165                   (or (gnus-methods-equal-p
5166                        nth4 (gnus-find-method-for-group from-newsgroup))
5167                       virtual
5168                       (equal nth4 (setq method (gnus-find-method-for-group
5169                                                 from-newsgroup)))
5170                       (and (equal (car nth4) (car method))
5171                            (equal (nth 1 nth4) (nth 1 method))))
5172                   gnus-use-cross-reference
5173                   (or (not (eq gnus-use-cross-reference t))
5174                       virtual
5175                       ;; Only do cross-references on subscribed
5176                       ;; groups, if that is what is wanted.
5177                       (<= (gnus-info-level info) gnus-level-subscribed))
5178                   (gnus-group-make-articles-read name idlist))))
5179          xref-hashtb)))))
5180
5181 (defun gnus-compute-read-articles (group articles)
5182   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5183          (info (nth 2 entry))
5184          (active (gnus-active group))
5185          ninfo)
5186     (when entry
5187       ;; First peel off all invalid article numbers.
5188       (when active
5189         (let ((ids articles)
5190               id first)
5191           (while (setq id (pop ids))
5192             (when (and first (> id (cdr active)))
5193               ;; We'll end up in this situation in one particular
5194               ;; obscure situation.  If you re-scan a group and get
5195               ;; a new article that is cross-posted to a different
5196               ;; group that has not been re-scanned, you might get
5197               ;; crossposted article that has a higher number than
5198               ;; Gnus believes possible.  So we re-activate this
5199               ;; group as well.  This might mean doing the
5200               ;; crossposting thingy will *increase* the number
5201               ;; of articles in some groups.  Tsk, tsk.
5202               (setq active (or (gnus-activate-group group) active)))
5203             (when (or (> id (cdr active))
5204                       (< id (car active)))
5205               (setq articles (delq id articles))))))
5206       ;; If the read list is nil, we init it.
5207       (if (and active
5208                (null (gnus-info-read info))
5209                (> (car active) 1))
5210           (setq ninfo (cons 1 (1- (car active))))
5211         (setq ninfo (gnus-info-read info)))
5212       ;; Then we add the read articles to the range.
5213       (gnus-add-to-range
5214        ninfo (setq articles (sort articles '<))))))
5215
5216 (defun gnus-group-make-articles-read (group articles)
5217   "Update the info of GROUP to say that ARTICLES are read."
5218   (let* ((num 0)
5219          (entry (gnus-gethash group gnus-newsrc-hashtb))
5220          (info (nth 2 entry))
5221          (active (gnus-active group))
5222          range)
5223     (when entry
5224       (setq range (gnus-compute-read-articles group articles))
5225       (save-excursion
5226         (set-buffer gnus-group-buffer)
5227         (gnus-undo-register
5228           `(progn
5229              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5230              (gnus-info-set-read ',info ',(gnus-info-read info))
5231              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5232              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5233              (gnus-group-update-group ,group t))))
5234       ;; Add the read articles to the range.
5235       (gnus-info-set-read info range)
5236       (gnus-request-set-mark group (list (list range 'add '(read))))
5237       ;; Then we have to re-compute how many unread
5238       ;; articles there are in this group.
5239       (when active
5240         (cond
5241          ((not range)
5242           (setq num (- (1+ (cdr active)) (car active))))
5243          ((not (listp (cdr range)))
5244           (setq num (- (cdr active) (- (1+ (cdr range))
5245                                        (car range)))))
5246          (t
5247           (while range
5248             (if (numberp (car range))
5249                 (setq num (1+ num))
5250               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5251             (setq range (cdr range)))
5252           (setq num (- (cdr active) num))))
5253         ;; Update the number of unread articles.
5254         (setcar entry num)
5255         ;; Update the group buffer.
5256         (gnus-group-update-group group t)))))
5257
5258 (defvar gnus-newsgroup-none-id 0)
5259
5260 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5261   (let ((cur nntp-server-buffer)
5262         (dependencies
5263          (or dependencies
5264              (save-excursion (set-buffer gnus-summary-buffer)
5265                              gnus-newsgroup-dependencies)))
5266         headers id end ref
5267         (mail-parse-charset gnus-newsgroup-charset)
5268         (mail-parse-ignored-charsets
5269          (save-excursion (condition-case nil
5270                              (set-buffer gnus-summary-buffer)
5271                            (error))
5272                          gnus-newsgroup-ignored-charsets)))
5273     (save-excursion
5274       (set-buffer nntp-server-buffer)
5275       ;; Translate all TAB characters into SPACE characters.
5276       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5277       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5278       (gnus-run-hooks 'gnus-parse-headers-hook)
5279       (let ((case-fold-search t)
5280             in-reply-to header p lines chars ctype)
5281         (goto-char (point-min))
5282         ;; Search to the beginning of the next header.  Error messages
5283         ;; do not begin with 2 or 3.
5284         (while (re-search-forward "^[23][0-9]+ " nil t)
5285           (setq id nil
5286                 ref nil)
5287           ;; This implementation of this function, with nine
5288           ;; search-forwards instead of the one re-search-forward and
5289           ;; a case (which basically was the old function) is actually
5290           ;; about twice as fast, even though it looks messier.  You
5291           ;; can't have everything, I guess.  Speed and elegance
5292           ;; doesn't always go hand in hand.
5293           (setq
5294            header
5295            (make-full-mail-header
5296             ;; Number.
5297             (prog1
5298                 (read cur)
5299               (end-of-line)
5300               (setq p (point))
5301               (narrow-to-region (point)
5302                                 (or (and (search-forward "\n.\n" nil t)
5303                                          (- (point) 2))
5304                                     (point))))
5305             ;; Subject.
5306             (progn
5307               (goto-char p)
5308               (if (search-forward "\nsubject:" nil t)
5309                   (nnheader-header-value)
5310                 "(none)"))
5311             ;; From.
5312             (progn
5313               (goto-char p)
5314               (if (search-forward "\nfrom:" nil t)
5315                   (nnheader-header-value)
5316                 "(nobody)"))
5317             ;; Date.
5318             (progn
5319               (goto-char p)
5320               (if (search-forward "\ndate:" nil t)
5321                   (nnheader-header-value) ""))
5322             ;; Message-ID.
5323             (progn
5324               (goto-char p)
5325               (setq id (if (re-search-forward
5326                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5327                            ;; We do it this way to make sure the Message-ID
5328                            ;; is (somewhat) syntactically valid.
5329                            (buffer-substring (match-beginning 1)
5330                                              (match-end 1))
5331                          ;; If there was no message-id, we just fake one
5332                          ;; to make subsequent routines simpler.
5333                          (nnheader-generate-fake-message-id))))
5334             ;; References.
5335             (progn
5336               (goto-char p)
5337               (if (search-forward "\nreferences:" nil t)
5338                   (progn
5339                     (setq end (point))
5340                     (prog1
5341                         (nnheader-header-value)
5342                       (setq ref
5343                             (buffer-substring
5344                              (progn
5345                                ;; (end-of-line)
5346                                (search-backward ">" end t)
5347                                (1+ (point)))
5348                              (progn
5349                                (search-backward "<" end t)
5350                                (point))))))
5351                 ;; Get the references from the in-reply-to header if there
5352                 ;; were no references and the in-reply-to header looks
5353                 ;; promising.
5354                 (if (and (search-forward "\nin-reply-to:" nil t)
5355                          (setq in-reply-to (nnheader-header-value))
5356                          (string-match "<[^>]+>" in-reply-to))
5357                     (let (ref2)
5358                       (setq ref (substring in-reply-to (match-beginning 0)
5359                                            (match-end 0)))
5360                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5361                         (setq ref2 (substring in-reply-to (match-beginning 0)
5362                                               (match-end 0)))
5363                         (when (> (length ref2) (length ref))
5364                           (setq ref ref2)))
5365                       ref)
5366                   (setq ref nil))))
5367             ;; Chars.
5368             (progn
5369               (goto-char p)
5370               (if (search-forward "\nchars: " nil t)
5371                   (if (numberp (setq chars (ignore-errors (read cur))))
5372                       chars -1)
5373                 -1))
5374             ;; Lines.
5375             (progn
5376               (goto-char p)
5377               (if (search-forward "\nlines: " nil t)
5378                   (if (numberp (setq lines (ignore-errors (read cur))))
5379                       lines -1)
5380                 -1))
5381             ;; Xref.
5382             (progn
5383               (goto-char p)
5384               (and (search-forward "\nxref:" nil t)
5385                    (nnheader-header-value)))
5386             ;; Extra.
5387             (when gnus-extra-headers
5388               (let ((extra gnus-extra-headers)
5389                     out)
5390                 (while extra
5391                   (goto-char p)
5392                   (when (search-forward
5393                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5394                     (push (cons (car extra) (nnheader-header-value)) out))
5395                   (pop extra))
5396                 out))))
5397           (goto-char p)
5398           (if (and (search-forward "\ncontent-type: " nil t)
5399                    (setq ctype (nnheader-header-value)))
5400               (mime-entity-set-content-type-internal
5401                header (mime-parse-Content-Type ctype)))
5402           (when (equal id ref)
5403             (setq ref nil))
5404
5405           (when gnus-alter-header-function
5406             (funcall gnus-alter-header-function header)
5407             (setq id (mail-header-id header)
5408                   ref (gnus-parent-id (mail-header-references header))))
5409
5410           (when (setq header
5411                       (gnus-dependencies-add-header
5412                        header dependencies force-new))
5413             (push header headers))
5414           (goto-char (point-max))
5415           (widen))
5416         (nreverse headers)))))
5417
5418 ;; Goes through the xover lines and returns a list of vectors
5419 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5420                                                   force-new dependencies
5421                                                   group also-fetch-heads)
5422   "Parse the news overview data in the server buffer.
5423 Return a list of headers that match SEQUENCE (see
5424 `nntp-retrieve-headers')."
5425   ;; Get the Xref when the users reads the articles since most/some
5426   ;; NNTP servers do not include Xrefs when using XOVER.
5427   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5428   (let ((mail-parse-charset gnus-newsgroup-charset)
5429         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5430         (cur nntp-server-buffer)
5431         (dependencies (or dependencies gnus-newsgroup-dependencies))
5432         (allp (cond
5433                ((eq gnus-read-all-available-headers t)
5434                 t)
5435                ((stringp gnus-read-all-available-headers)
5436                 (string-match gnus-read-all-available-headers group))
5437                (t
5438                 nil)))
5439         number headers header)
5440     (save-excursion
5441       (set-buffer nntp-server-buffer)
5442       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5443       ;; Allow the user to mangle the headers before parsing them.
5444       (gnus-run-hooks 'gnus-parse-headers-hook)
5445       (goto-char (point-min))
5446       (while (not (eobp))
5447         (condition-case ()
5448             (while (and (or sequence allp)
5449                         (not (eobp)))
5450               (setq number (read cur))
5451               (when (not allp)
5452                 (while (and sequence
5453                             (< (car sequence) number))
5454                   (setq sequence (cdr sequence))))
5455               (when (and (or allp
5456                              (and sequence
5457                                   (eq number (car sequence))))
5458                          (progn
5459                            (setq sequence (cdr sequence))
5460                            (setq header (inline
5461                                           (gnus-nov-parse-line
5462                                            number dependencies force-new)))))
5463                 (push header headers))
5464               (forward-line 1))
5465           (error
5466            (gnus-error 4 "Strange nov line (%d)"
5467                        (count-lines (point-min) (point)))))
5468         (forward-line 1))
5469       ;; A common bug in inn is that if you have posted an article and
5470       ;; then retrieves the active file, it will answer correctly --
5471       ;; the new article is included.  However, a NOV entry for the
5472       ;; article may not have been generated yet, so this may fail.
5473       ;; We work around this problem by retrieving the last few
5474       ;; headers using HEAD.
5475       (if (or (not also-fetch-heads)
5476               (not sequence))
5477           ;; We (probably) got all the headers.
5478           (nreverse headers)
5479         (let ((gnus-nov-is-evil t))
5480           (nconc
5481            (nreverse headers)
5482            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5483              (gnus-get-newsgroup-headers))))))))
5484
5485 (defun gnus-article-get-xrefs ()
5486   "Fill in the Xref value in `gnus-current-headers', if necessary.
5487 This is meant to be called in `gnus-article-internal-prepare-hook'."
5488   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5489                                  gnus-current-headers)))
5490     (or (not gnus-use-cross-reference)
5491         (not headers)
5492         (and (mail-header-xref headers)
5493              (not (string= (mail-header-xref headers) "")))
5494         (let ((case-fold-search t)
5495               xref)
5496           (save-restriction
5497             (nnheader-narrow-to-headers)
5498             (goto-char (point-min))
5499             (when (or (and (not (eobp))
5500                            (eq (downcase (char-after)) ?x)
5501                            (looking-at "Xref:"))
5502                       (search-forward "\nXref:" nil t))
5503               (goto-char (1+ (match-end 0)))
5504               (setq xref (buffer-substring (point)
5505                                            (progn (end-of-line) (point))))
5506               (mail-header-set-xref headers xref)))))))
5507
5508 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5509   "Find article ID and insert the summary line for that article.
5510 OLD-HEADER can either be a header or a line number to insert
5511 the subject line on."
5512   (let* ((line (and (numberp old-header) old-header))
5513          (old-header (and (vectorp old-header) old-header))
5514          (header (cond ((and old-header use-old-header)
5515                         old-header)
5516                        ((and (numberp id)
5517                              (gnus-number-to-header id))
5518                         (gnus-number-to-header id))
5519                        (t
5520                         (gnus-read-header id))))
5521          (number (and (numberp id) id))
5522          d)
5523     (when header
5524       ;; Rebuild the thread that this article is part of and go to the
5525       ;; article we have fetched.
5526       (when (and (not gnus-show-threads)
5527                  old-header)
5528         (when (and number
5529                    (setq d (gnus-data-find (mail-header-number old-header))))
5530           (goto-char (gnus-data-pos d))
5531           (gnus-data-remove
5532            number
5533            (- (gnus-point-at-bol)
5534               (prog1
5535                   (1+ (gnus-point-at-eol))
5536                 (gnus-delete-line))))))
5537       (when old-header
5538         (mail-header-set-number header (mail-header-number old-header)))
5539       (setq gnus-newsgroup-sparse
5540             (delq (setq number (mail-header-number header))
5541                   gnus-newsgroup-sparse))
5542       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5543       (push number gnus-newsgroup-limit)
5544       (gnus-rebuild-thread (mail-header-id header) line)
5545       (gnus-summary-goto-subject number nil t))
5546     (when (and (numberp number)
5547                (> number 0))
5548       ;; We have to update the boundaries even if we can't fetch the
5549       ;; article if ID is a number -- so that the next `P' or `N'
5550       ;; command will fetch the previous (or next) article even
5551       ;; if the one we tried to fetch this time has been canceled.
5552       (when (> number gnus-newsgroup-end)
5553         (setq gnus-newsgroup-end number))
5554       (when (< number gnus-newsgroup-begin)
5555         (setq gnus-newsgroup-begin number))
5556       (setq gnus-newsgroup-unselected
5557             (delq number gnus-newsgroup-unselected)))
5558     ;; Report back a success?
5559     (and header (mail-header-number header))))
5560
5561 ;;; Process/prefix in the summary buffer
5562
5563 (defun gnus-summary-work-articles (n)
5564   "Return a list of articles to be worked upon.
5565 The prefix argument, the list of process marked articles, and the
5566 current article will be taken into consideration."
5567   (save-excursion
5568     (set-buffer gnus-summary-buffer)
5569     (cond
5570      (n
5571       ;; A numerical prefix has been given.
5572       (setq n (prefix-numeric-value n))
5573       (let ((backward (< n 0))
5574             (n (abs (prefix-numeric-value n)))
5575             articles article)
5576         (save-excursion
5577           (while
5578               (and (> n 0)
5579                    (push (setq article (gnus-summary-article-number))
5580                          articles)
5581                    (if backward
5582                        (gnus-summary-find-prev nil article)
5583                      (gnus-summary-find-next nil article)))
5584             (decf n)))
5585         (nreverse articles)))
5586      ((and (gnus-region-active-p) (mark))
5587       (message "region active")
5588       ;; Work on the region between point and mark.
5589       (let ((max (max (point) (mark)))
5590             articles article)
5591         (save-excursion
5592           (goto-char (min (point) (mark)))
5593           (while
5594               (and
5595                (push (setq article (gnus-summary-article-number)) articles)
5596                (gnus-summary-find-next nil article)
5597                (< (point) max)))
5598           (nreverse articles))))
5599      (gnus-newsgroup-processable
5600       ;; There are process-marked articles present.
5601       ;; Save current state.
5602       (gnus-summary-save-process-mark)
5603       ;; Return the list.
5604       (reverse gnus-newsgroup-processable))
5605      (t
5606       ;; Just return the current article.
5607       (list (gnus-summary-article-number))))))
5608
5609 (defmacro gnus-summary-iterate (arg &rest forms)
5610   "Iterate over the process/prefixed articles and do FORMS.
5611 ARG is the interactive prefix given to the command.  FORMS will be
5612 executed with point over the summary line of the articles."
5613   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5614     `(let ((,articles (gnus-summary-work-articles ,arg)))
5615        (while ,articles
5616          (gnus-summary-goto-subject (car ,articles))
5617          ,@forms
5618          (pop ,articles)))))
5619
5620 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5621 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5622
5623 (defun gnus-summary-save-process-mark ()
5624   "Push the current set of process marked articles on the stack."
5625   (interactive)
5626   (push (copy-sequence gnus-newsgroup-processable)
5627         gnus-newsgroup-process-stack))
5628
5629 (defun gnus-summary-kill-process-mark ()
5630   "Push the current set of process marked articles on the stack and unmark."
5631   (interactive)
5632   (gnus-summary-save-process-mark)
5633   (gnus-summary-unmark-all-processable))
5634
5635 (defun gnus-summary-yank-process-mark ()
5636   "Pop the last process mark state off the stack and restore it."
5637   (interactive)
5638   (unless gnus-newsgroup-process-stack
5639     (error "Empty mark stack"))
5640   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5641
5642 (defun gnus-summary-process-mark-set (set)
5643   "Make SET into the current process marked articles."
5644   (gnus-summary-unmark-all-processable)
5645   (while set
5646     (gnus-summary-set-process-mark (pop set))))
5647
5648 ;;; Searching and stuff
5649
5650 (defun gnus-summary-search-group (&optional backward use-level)
5651   "Search for next unread newsgroup.
5652 If optional argument BACKWARD is non-nil, search backward instead."
5653   (save-excursion
5654     (set-buffer gnus-group-buffer)
5655     (when (gnus-group-search-forward
5656            backward nil (if use-level (gnus-group-group-level) nil))
5657       (gnus-group-group-name))))
5658
5659 (defun gnus-summary-best-group (&optional exclude-group)
5660   "Find the name of the best unread group.
5661 If EXCLUDE-GROUP, do not go to this group."
5662   (save-excursion
5663     (set-buffer gnus-group-buffer)
5664     (save-excursion
5665       (gnus-group-best-unread-group exclude-group))))
5666
5667 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5668   (if backward (gnus-summary-find-prev)
5669     (let* ((dummy (gnus-summary-article-intangible-p))
5670            (article (or article (gnus-summary-article-number)))
5671            (arts (gnus-data-find-list article))
5672            result)
5673       (when (and (not dummy)
5674                  (or (not gnus-summary-check-current)
5675                      (not unread)
5676                      (not (gnus-data-unread-p (car arts)))))
5677         (setq arts (cdr arts)))
5678       (when (setq result
5679                   (if unread
5680                       (progn
5681                         (while arts
5682                           (when (or (and undownloaded
5683                                          (eq gnus-undownloaded-mark
5684                                              (gnus-data-mark (car arts))))
5685                                     (gnus-data-unread-p (car arts)))
5686                             (setq result (car arts)
5687                                   arts nil))
5688                           (setq arts (cdr arts)))
5689                         result)
5690                     (car arts)))
5691         (goto-char (gnus-data-pos result))
5692         (gnus-data-number result)))))
5693
5694 (defun gnus-summary-find-prev (&optional unread article)
5695   (let* ((eobp (eobp))
5696          (article (or article (gnus-summary-article-number)))
5697          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5698          result)
5699     (when (and (not eobp)
5700                (or (not gnus-summary-check-current)
5701                    (not unread)
5702                    (not (gnus-data-unread-p (car arts)))))
5703       (setq arts (cdr arts)))
5704     (when (setq result
5705                 (if unread
5706                     (progn
5707                       (while arts
5708                         (when (gnus-data-unread-p (car arts))
5709                           (setq result (car arts)
5710                                 arts nil))
5711                         (setq arts (cdr arts)))
5712                       result)
5713                   (car arts)))
5714       (goto-char (gnus-data-pos result))
5715       (gnus-data-number result))))
5716
5717 (defun gnus-summary-find-subject (subject &optional unread backward article)
5718   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5719          (article (or article (gnus-summary-article-number)))
5720          (articles (gnus-data-list backward))
5721          (arts (gnus-data-find-list article articles))
5722          result)
5723     (when (or (not gnus-summary-check-current)
5724               (not unread)
5725               (not (gnus-data-unread-p (car arts))))
5726       (setq arts (cdr arts)))
5727     (while arts
5728       (and (or (not unread)
5729                (gnus-data-unread-p (car arts)))
5730            (vectorp (gnus-data-header (car arts)))
5731            (gnus-subject-equal
5732             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5733            (setq result (car arts)
5734                  arts nil))
5735       (setq arts (cdr arts)))
5736     (and result
5737          (goto-char (gnus-data-pos result))
5738          (gnus-data-number result))))
5739
5740 (defun gnus-summary-search-forward (&optional unread subject backward)
5741   "Search forward for an article.
5742 If UNREAD, look for unread articles.  If SUBJECT, look for
5743 articles with that subject.  If BACKWARD, search backward instead."
5744   (cond (subject (gnus-summary-find-subject subject unread backward))
5745         (backward (gnus-summary-find-prev unread))
5746         (t (gnus-summary-find-next unread))))
5747
5748 (defun gnus-recenter (&optional n)
5749   "Center point in window and redisplay frame.
5750 Also do horizontal recentering."
5751   (interactive "P")
5752   (when (and gnus-auto-center-summary
5753              (not (eq gnus-auto-center-summary 'vertical)))
5754     (gnus-horizontal-recenter))
5755   (recenter n))
5756
5757 (defun gnus-summary-recenter ()
5758   "Center point in the summary window.
5759 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5760 displayed, no centering will be performed."
5761   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5762   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5763   (interactive)
5764   (let* ((top (cond ((< (window-height) 4) 0)
5765                     ((< (window-height) 7) 1)
5766                     (t (if (numberp gnus-auto-center-summary)
5767                            gnus-auto-center-summary
5768                          2))))
5769          (height (1- (window-height)))
5770          (bottom (save-excursion (goto-char (point-max))
5771                                  (forward-line (- height))
5772                                  (point)))
5773          (window (get-buffer-window (current-buffer))))
5774     ;; The user has to want it.
5775     (when gnus-auto-center-summary
5776       (when (get-buffer-window gnus-article-buffer)
5777         ;; Only do recentering when the article buffer is displayed,
5778         ;; Set the window start to either `bottom', which is the biggest
5779         ;; possible valid number, or the second line from the top,
5780         ;; whichever is the least.
5781         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5782           (if (> bottom top-pos)
5783               ;; Keep the second line from the top visible
5784               (set-window-start window top-pos t)
5785             ;; Try to keep the bottom line visible; if it's partially
5786             ;; obscured, either scroll one more line to make it fully
5787             ;; visible, or revert to using TOP-POS.
5788             (save-excursion
5789               (goto-char (point-max))
5790               (forward-line -1)
5791               (let ((last-line-start (point)))
5792                 (goto-char bottom)
5793                 (set-window-start window (point) t)
5794                 (when (not (pos-visible-in-window-p last-line-start window))
5795                   (forward-line 1)
5796                   (set-window-start window (min (point) top-pos) t)))))))
5797       ;; Do horizontal recentering while we're at it.
5798       (when (and (get-buffer-window (current-buffer) t)
5799                  (not (eq gnus-auto-center-summary 'vertical)))
5800         (let ((selected (selected-window)))
5801           (select-window (get-buffer-window (current-buffer) t))
5802           (gnus-summary-position-point)
5803           (gnus-horizontal-recenter)
5804           (select-window selected))))))
5805
5806 (defun gnus-summary-jump-to-group (newsgroup)
5807   "Move point to NEWSGROUP in group mode buffer."
5808   ;; Keep update point of group mode buffer if visible.
5809   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5810       (save-window-excursion
5811         ;; Take care of tree window mode.
5812         (when (get-buffer-window gnus-group-buffer)
5813           (pop-to-buffer gnus-group-buffer))
5814         (gnus-group-jump-to-group newsgroup))
5815     (save-excursion
5816       ;; Take care of tree window mode.
5817       (if (get-buffer-window gnus-group-buffer)
5818           (pop-to-buffer gnus-group-buffer)
5819         (set-buffer gnus-group-buffer))
5820       (gnus-group-jump-to-group newsgroup))))
5821
5822 ;; This function returns a list of article numbers based on the
5823 ;; difference between the ranges of read articles in this group and
5824 ;; the range of active articles.
5825 (defun gnus-list-of-unread-articles (group)
5826   (let* ((read (gnus-info-read (gnus-get-info group)))
5827          (active (or (gnus-active group) (gnus-activate-group group)))
5828          (last (cdr active))
5829          first nlast unread)
5830     ;; If none are read, then all are unread.
5831     (if (not read)
5832         (setq first (car active))
5833       ;; If the range of read articles is a single range, then the
5834       ;; first unread article is the article after the last read
5835       ;; article.  Sounds logical, doesn't it?
5836       (if (and (not (listp (cdr read)))
5837                (or (< (car read) (car active))
5838                    (progn (setq read (list read))
5839                           nil)))
5840           (setq first (max (car active) (1+ (cdr read))))
5841         ;; `read' is a list of ranges.
5842         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5843                                   (caar read)))
5844                   1)
5845           (setq first (car active)))
5846         (while read
5847           (when first
5848             (while (< first nlast)
5849               (push first unread)
5850               (setq first (1+ first))))
5851           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5852           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5853           (setq read (cdr read)))))
5854     ;; And add the last unread articles.
5855     (while (<= first last)
5856       (push first unread)
5857       (setq first (1+ first)))
5858     ;; Return the list of unread articles.
5859     (delq 0 (nreverse unread))))
5860
5861 (defun gnus-list-of-read-articles (group)
5862   "Return a list of unread, unticked and non-dormant articles."
5863   (let* ((info (gnus-get-info group))
5864          (marked (gnus-info-marks info))
5865          (active (gnus-active group)))
5866     (and info active
5867          (gnus-set-difference
5868           (gnus-sorted-complement
5869            (gnus-uncompress-range active)
5870            (gnus-list-of-unread-articles group))
5871           (append
5872            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5873            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5874
5875 ;; Various summary commands
5876
5877 (defun gnus-summary-select-article-buffer ()
5878   "Reconfigure windows to show article buffer."
5879   (interactive)
5880   (if (not (gnus-buffer-live-p gnus-article-buffer))
5881       (error "There is no article buffer for this summary buffer")
5882     (gnus-configure-windows 'article)
5883     (select-window (get-buffer-window gnus-article-buffer))))
5884
5885 (defun gnus-summary-universal-argument (arg)
5886   "Perform any operation on all articles that are process/prefixed."
5887   (interactive "P")
5888   (let ((articles (gnus-summary-work-articles arg))
5889         func article)
5890     (if (eq
5891          (setq
5892           func
5893           (key-binding
5894            (read-key-sequence
5895             (substitute-command-keys
5896              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5897          'undefined)
5898         (gnus-error 1 "Undefined key")
5899       (save-excursion
5900         (while articles
5901           (gnus-summary-goto-subject (setq article (pop articles)))
5902           (let (gnus-newsgroup-processable)
5903             (command-execute func))
5904           (gnus-summary-remove-process-mark article)))))
5905   (gnus-summary-position-point))
5906
5907 (defun gnus-summary-toggle-truncation (&optional arg)
5908   "Toggle truncation of summary lines.
5909 With arg, turn line truncation on iff arg is positive."
5910   (interactive "P")
5911   (setq truncate-lines
5912         (if (null arg) (not truncate-lines)
5913           (> (prefix-numeric-value arg) 0)))
5914   (redraw-display))
5915
5916 (defun gnus-summary-reselect-current-group (&optional all rescan)
5917   "Exit and then reselect the current newsgroup.
5918 The prefix argument ALL means to select all articles."
5919   (interactive "P")
5920   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5921     (error "Ephemeral groups can't be reselected"))
5922   (let ((current-subject (gnus-summary-article-number))
5923         (group gnus-newsgroup-name))
5924     (setq gnus-newsgroup-begin nil)
5925     (gnus-summary-exit)
5926     ;; We have to adjust the point of group mode buffer because
5927     ;; point was moved to the next unread newsgroup by exiting.
5928     (gnus-summary-jump-to-group group)
5929     (when rescan
5930       (save-excursion
5931         (save-window-excursion
5932           ;; Don't show group contents.
5933           (set-window-start (selected-window) (point-max))
5934           (gnus-group-get-new-news-this-group 1))))
5935     (gnus-group-read-group all t)
5936     (gnus-summary-goto-subject current-subject nil t)))
5937
5938 (defun gnus-summary-rescan-group (&optional all)
5939   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5940   (interactive "P")
5941   (gnus-summary-reselect-current-group all t))
5942
5943 (defun gnus-summary-update-info (&optional non-destructive)
5944   (save-excursion
5945     (let ((group gnus-newsgroup-name))
5946       (when group
5947         (when gnus-newsgroup-kill-headers
5948           (setq gnus-newsgroup-killed
5949                 (gnus-compress-sequence
5950                  (nconc
5951                   (gnus-set-sorted-intersection
5952                    (gnus-uncompress-range gnus-newsgroup-killed)
5953                    (setq gnus-newsgroup-unselected
5954                          (sort gnus-newsgroup-unselected '<)))
5955                   (setq gnus-newsgroup-unreads
5956                         (sort gnus-newsgroup-unreads '<)))
5957                  t)))
5958         (unless (listp (cdr gnus-newsgroup-killed))
5959           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5960         (let ((headers gnus-newsgroup-headers))
5961           ;; Set the new ranges of read articles.
5962           (save-excursion
5963             (set-buffer gnus-group-buffer)
5964             (gnus-undo-force-boundary))
5965           (gnus-update-read-articles
5966            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5967           ;; Set the current article marks.
5968           (let ((gnus-newsgroup-scored
5969                  (if (and (not gnus-save-score)
5970                           (not non-destructive))
5971                      nil
5972                    gnus-newsgroup-scored)))
5973             (save-excursion
5974               (gnus-update-marks)))
5975           ;; Do the cross-ref thing.
5976           (when gnus-use-cross-reference
5977             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5978           ;; Do not switch windows but change the buffer to work.
5979           (set-buffer gnus-group-buffer)
5980           (unless (gnus-ephemeral-group-p group)
5981             (gnus-group-update-group group)))))))
5982
5983 (defun gnus-summary-save-newsrc (&optional force)
5984   "Save the current number of read/marked articles in the dribble buffer.
5985 The dribble buffer will then be saved.
5986 If FORCE (the prefix), also save the .newsrc file(s)."
5987   (interactive "P")
5988   (gnus-summary-update-info t)
5989   (if force
5990       (gnus-save-newsrc-file)
5991     (gnus-dribble-save)))
5992
5993 (defun gnus-summary-exit (&optional temporary)
5994   "Exit reading current newsgroup, and then return to group selection mode.
5995 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5996   (interactive)
5997   (gnus-set-global-variables)
5998   (gnus-kill-save-kill-buffer)
5999   (gnus-async-halt-prefetch)
6000   (let* ((group gnus-newsgroup-name)
6001          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6002          (mode major-mode)
6003          (group-point nil)
6004          (buf (current-buffer)))
6005     (unless quit-config
6006       ;; Do adaptive scoring, and possibly save score files.
6007       (when gnus-newsgroup-adaptive
6008         (gnus-score-adaptive))
6009       (when gnus-use-scoring
6010         (gnus-score-save)))
6011     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6012     ;; If we have several article buffers, we kill them at exit.
6013     (unless gnus-single-article-buffer
6014       (gnus-kill-buffer gnus-original-article-buffer)
6015       (setq gnus-article-current nil))
6016     (when gnus-use-cache
6017       (gnus-cache-possibly-remove-articles)
6018       (gnus-cache-save-buffers))
6019     (gnus-async-prefetch-remove-group group)
6020     (when gnus-suppress-duplicates
6021       (gnus-dup-enter-articles))
6022     (when gnus-use-trees
6023       (gnus-tree-close group))
6024     (when gnus-use-cache
6025       (gnus-cache-write-active))
6026     ;; Remove entries for this group.
6027     (nnmail-purge-split-history (gnus-group-real-name group))
6028     ;; Make all changes in this group permanent.
6029     (unless quit-config
6030       (gnus-run-hooks 'gnus-exit-group-hook)
6031       (gnus-summary-update-info))
6032     (gnus-close-group group)
6033     ;; Make sure where we were, and go to next newsgroup.
6034     (set-buffer gnus-group-buffer)
6035     (unless quit-config
6036       (gnus-group-jump-to-group group))
6037     (gnus-run-hooks 'gnus-summary-exit-hook)
6038     (unless (or quit-config
6039                 ;; If this group has disappeared from the summary
6040                 ;; buffer, don't skip forwards.
6041                 (not (string= group (gnus-group-group-name))))
6042       (gnus-group-next-unread-group 1))
6043     (setq group-point (point))
6044     (if temporary
6045         nil                             ;Nothing to do.
6046       ;; If we have several article buffers, we kill them at exit.
6047       (unless gnus-single-article-buffer
6048         (gnus-kill-buffer gnus-article-buffer)
6049         (gnus-kill-buffer gnus-original-article-buffer)
6050         (setq gnus-article-current nil))
6051       (set-buffer buf)
6052       (if (not gnus-kill-summary-on-exit)
6053           (progn
6054             (gnus-deaden-summary)
6055             (setq mode nil))
6056         ;; We set all buffer-local variables to nil.  It is unclear why
6057         ;; this is needed, but if we don't, buffer-local variables are
6058         ;; not garbage-collected, it seems.  This would the lead to en
6059         ;; ever-growing Emacs.
6060         (gnus-summary-clear-local-variables)
6061         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6062           (gnus-summary-clear-local-variables))
6063         (when (get-buffer gnus-article-buffer)
6064           (bury-buffer gnus-article-buffer))
6065         ;; We clear the global counterparts of the buffer-local
6066         ;; variables as well, just to be on the safe side.
6067         (set-buffer gnus-group-buffer)
6068         (gnus-summary-clear-local-variables)
6069         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6070           (gnus-summary-clear-local-variables)))
6071       (setq gnus-current-select-method gnus-select-method)
6072       (pop-to-buffer gnus-group-buffer)
6073       (if (not quit-config)
6074           (progn
6075             (goto-char group-point)
6076             (gnus-configure-windows 'group 'force)
6077             (unless (pos-visible-in-window-p)
6078               (forward-line (/ (static-if (featurep 'xemacs)
6079                                    (window-displayed-height)
6080                                  (1- (window-height)))
6081                                -2))
6082               (set-window-start (selected-window) (point))
6083               (goto-char group-point)))
6084         (gnus-handle-ephemeral-exit quit-config))
6085       ;; Return to group mode buffer.
6086       (when (eq mode 'gnus-summary-mode)
6087         (gnus-kill-buffer buf))
6088       ;; Clear the current group name.
6089       (unless quit-config
6090         (setq gnus-newsgroup-name nil)))))
6091
6092 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6093 (defun gnus-summary-exit-no-update (&optional no-questions)
6094   "Quit reading current newsgroup without updating read article info."
6095   (interactive)
6096   (let* ((group gnus-newsgroup-name)
6097          (quit-config (gnus-group-quit-config group)))
6098     (when (or no-questions
6099               gnus-expert-user
6100               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6101       (gnus-async-halt-prefetch)
6102       (mapcar 'funcall
6103               (delq 'gnus-summary-expire-articles
6104                     (copy-sequence gnus-summary-prepare-exit-hook)))
6105       ;; If we have several article buffers, we kill them at exit.
6106       (unless gnus-single-article-buffer
6107         (gnus-kill-buffer gnus-article-buffer)
6108         (gnus-kill-buffer gnus-original-article-buffer)
6109         (setq gnus-article-current nil))
6110       (if (not gnus-kill-summary-on-exit)
6111           (gnus-deaden-summary)
6112         (gnus-close-group group)
6113         (gnus-summary-clear-local-variables)
6114         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6115           (gnus-summary-clear-local-variables))
6116         (set-buffer gnus-group-buffer)
6117         (gnus-summary-clear-local-variables)
6118         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6119           (gnus-summary-clear-local-variables))
6120         (when (get-buffer gnus-summary-buffer)
6121           (kill-buffer gnus-summary-buffer)))
6122       (unless gnus-single-article-buffer
6123         (setq gnus-article-current nil))
6124       (when gnus-use-trees
6125         (gnus-tree-close group))
6126       (gnus-async-prefetch-remove-group group)
6127       (when (get-buffer gnus-article-buffer)
6128         (bury-buffer gnus-article-buffer))
6129       ;; Return to the group buffer.
6130       (gnus-configure-windows 'group 'force)
6131       ;; Clear the current group name.
6132       (setq gnus-newsgroup-name nil)
6133       (when (equal (gnus-group-group-name) group)
6134         (gnus-group-next-unread-group 1))
6135       (when quit-config
6136         (gnus-handle-ephemeral-exit quit-config)))))
6137
6138 (defun gnus-handle-ephemeral-exit (quit-config)
6139   "Handle movement when leaving an ephemeral group.
6140 The state which existed when entering the ephemeral is reset."
6141   (if (not (buffer-name (car quit-config)))
6142       (gnus-configure-windows 'group 'force)
6143     (set-buffer (car quit-config))
6144     (cond ((eq major-mode 'gnus-summary-mode)
6145            (gnus-set-global-variables))
6146           ((eq major-mode 'gnus-article-mode)
6147            (save-excursion
6148              ;; The `gnus-summary-buffer' variable may point
6149              ;; to the old summary buffer when using a single
6150              ;; article buffer.
6151              (unless (gnus-buffer-live-p gnus-summary-buffer)
6152                (set-buffer gnus-group-buffer))
6153              (set-buffer gnus-summary-buffer)
6154              (gnus-set-global-variables))))
6155     (if (or (eq (cdr quit-config) 'article)
6156             (eq (cdr quit-config) 'pick))
6157         (progn
6158           ;; The current article may be from the ephemeral group
6159           ;; thus it is best that we reload this article
6160           (gnus-summary-show-article)
6161           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6162               (gnus-configure-windows 'pick 'force)
6163             (gnus-configure-windows (cdr quit-config) 'force)))
6164       (gnus-configure-windows (cdr quit-config) 'force))
6165     (when (eq major-mode 'gnus-summary-mode)
6166       (gnus-summary-next-subject 1 nil t)
6167       (gnus-summary-recenter)
6168       (gnus-summary-position-point))))
6169
6170 (defun gnus-summary-preview-mime-message ()
6171   "MIME decode and play this message."
6172   (interactive)
6173   (let ((gnus-break-pages nil)
6174         (gnus-show-mime t))
6175     (gnus-summary-select-article gnus-show-all-headers t))
6176   (select-window (get-buffer-window gnus-article-buffer)))
6177
6178 ;;; Dead summaries.
6179
6180 (defvar gnus-dead-summary-mode-map nil)
6181
6182 (unless gnus-dead-summary-mode-map
6183   (setq gnus-dead-summary-mode-map (make-keymap))
6184   (suppress-keymap gnus-dead-summary-mode-map)
6185   (substitute-key-definition
6186    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6187   (let ((keys '("\C-d" "\r" "\177" [delete])))
6188     (while keys
6189       (define-key gnus-dead-summary-mode-map
6190         (pop keys) 'gnus-summary-wake-up-the-dead))))
6191
6192 (defvar gnus-dead-summary-mode nil
6193   "Minor mode for Gnus summary buffers.")
6194
6195 (defun gnus-dead-summary-mode (&optional arg)
6196   "Minor mode for Gnus summary buffers."
6197   (interactive "P")
6198   (when (eq major-mode 'gnus-summary-mode)
6199     (make-local-variable 'gnus-dead-summary-mode)
6200     (setq gnus-dead-summary-mode
6201           (if (null arg) (not gnus-dead-summary-mode)
6202             (> (prefix-numeric-value arg) 0)))
6203     (when gnus-dead-summary-mode
6204       (gnus-add-minor-mode
6205        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6206
6207 (defun gnus-deaden-summary ()
6208   "Make the current summary buffer into a dead summary buffer."
6209   ;; Kill any previous dead summary buffer.
6210   (when (and gnus-dead-summary
6211              (buffer-name gnus-dead-summary))
6212     (save-excursion
6213       (set-buffer gnus-dead-summary)
6214       (when gnus-dead-summary-mode
6215         (kill-buffer (current-buffer)))))
6216   ;; Make this the current dead summary.
6217   (setq gnus-dead-summary (current-buffer))
6218   (gnus-dead-summary-mode 1)
6219   (let ((name (buffer-name)))
6220     (when (string-match "Summary" name)
6221       (rename-buffer
6222        (concat (substring name 0 (match-beginning 0)) "Dead "
6223                (substring name (match-beginning 0)))
6224        t)
6225       (bury-buffer))))
6226
6227 (defun gnus-kill-or-deaden-summary (buffer)
6228   "Kill or deaden the summary BUFFER."
6229   (save-excursion
6230     (when (and (buffer-name buffer)
6231                (not gnus-single-article-buffer))
6232       (save-excursion
6233         (set-buffer buffer)
6234         (gnus-kill-buffer gnus-article-buffer)
6235         (gnus-kill-buffer gnus-original-article-buffer)))
6236     (cond (gnus-kill-summary-on-exit
6237            (when (and gnus-use-trees
6238                       (gnus-buffer-exists-p buffer))
6239              (save-excursion
6240                (set-buffer buffer)
6241                (gnus-tree-close gnus-newsgroup-name)))
6242            (gnus-kill-buffer buffer))
6243           ((gnus-buffer-exists-p buffer)
6244            (save-excursion
6245              (set-buffer buffer)
6246              (gnus-deaden-summary))))))
6247
6248 (defun gnus-summary-wake-up-the-dead (&rest args)
6249   "Wake up the dead summary buffer."
6250   (interactive)
6251   (gnus-dead-summary-mode -1)
6252   (let ((name (buffer-name)))
6253     (when (string-match "Dead " name)
6254       (rename-buffer
6255        (concat (substring name 0 (match-beginning 0))
6256                (substring name (match-end 0)))
6257        t)))
6258   (gnus-message 3 "This dead summary is now alive again"))
6259
6260 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6261 (defun gnus-summary-fetch-faq (&optional faq-dir)
6262   "Fetch the FAQ for the current group.
6263 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6264 in."
6265   (interactive
6266    (list
6267     (when current-prefix-arg
6268       (completing-read
6269        "Faq dir: " (and (listp gnus-group-faq-directory)
6270                         (mapcar (lambda (file) (list file))
6271                                 gnus-group-faq-directory))))))
6272   (let (gnus-faq-buffer)
6273     (when (setq gnus-faq-buffer
6274                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6275       (gnus-configure-windows 'summary-faq))))
6276
6277 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6278 (defun gnus-summary-describe-group (&optional force)
6279   "Describe the current newsgroup."
6280   (interactive "P")
6281   (gnus-group-describe-group force gnus-newsgroup-name))
6282
6283 (defun gnus-summary-describe-briefly ()
6284   "Describe summary mode commands briefly."
6285   (interactive)
6286   (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")))
6287
6288 ;; Walking around group mode buffer from summary mode.
6289
6290 (defun gnus-summary-next-group (&optional no-article target-group backward)
6291   "Exit current newsgroup and then select next unread newsgroup.
6292 If prefix argument NO-ARTICLE is non-nil, no article is selected
6293 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6294 previous group instead."
6295   (interactive "P")
6296   ;; Stop pre-fetching.
6297   (gnus-async-halt-prefetch)
6298   (let ((current-group gnus-newsgroup-name)
6299         (current-buffer (current-buffer))
6300         entered)
6301     ;; First we semi-exit this group to update Xrefs and all variables.
6302     ;; We can't do a real exit, because the window conf must remain
6303     ;; the same in case the user is prompted for info, and we don't
6304     ;; want the window conf to change before that...
6305     (gnus-summary-exit t)
6306     (while (not entered)
6307       ;; Then we find what group we are supposed to enter.
6308       (set-buffer gnus-group-buffer)
6309       (gnus-group-jump-to-group current-group)
6310       (setq target-group
6311             (or target-group
6312                 (if (eq gnus-keep-same-level 'best)
6313                     (gnus-summary-best-group gnus-newsgroup-name)
6314                   (gnus-summary-search-group backward gnus-keep-same-level))))
6315       (if (not target-group)
6316           ;; There are no further groups, so we return to the group
6317           ;; buffer.
6318           (progn
6319             (gnus-message 5 "Returning to the group buffer")
6320             (setq entered t)
6321             (when (gnus-buffer-live-p current-buffer)
6322               (set-buffer current-buffer)
6323               (gnus-summary-exit))
6324             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6325         ;; We try to enter the target group.
6326         (gnus-group-jump-to-group target-group)
6327         (let ((unreads (gnus-group-group-unread)))
6328           (if (and (or (eq t unreads)
6329                        (and unreads (not (zerop unreads))))
6330                    (gnus-summary-read-group
6331                     target-group nil no-article
6332                     (and (buffer-name current-buffer) current-buffer)
6333                     nil backward))
6334               (setq entered t)
6335             (setq current-group target-group
6336                   target-group nil)))))))
6337
6338 (defun gnus-summary-prev-group (&optional no-article)
6339   "Exit current newsgroup and then select previous unread newsgroup.
6340 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6341   (interactive "P")
6342   (gnus-summary-next-group no-article nil t))
6343
6344 ;; Walking around summary lines.
6345
6346 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6347   "Go to the first unread subject.
6348 If UNREAD is non-nil, go to the first unread article.
6349 Returns the article selected or nil if there are no unread articles."
6350   (interactive "P")
6351   (prog1
6352       (cond
6353        ;; Empty summary.
6354        ((null gnus-newsgroup-data)
6355         (gnus-message 3 "No articles in the group")
6356         nil)
6357        ;; Pick the first article.
6358        ((not unread)
6359         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6360         (gnus-data-number (car gnus-newsgroup-data)))
6361        ;; No unread articles.
6362        ((null gnus-newsgroup-unreads)
6363         (gnus-message 3 "No more unread articles")
6364         nil)
6365        ;; Find the first unread article.
6366        (t
6367         (let ((data gnus-newsgroup-data))
6368           (while (and data
6369                       (and (not (and undownloaded
6370                                      (eq gnus-undownloaded-mark
6371                                          (gnus-data-mark (car data)))))
6372                            (not (and unseen
6373                                      (memq (car data) gnus-newsgroup-unseen)))
6374                            (not (gnus-data-unread-p (car data)))))
6375             (setq data (cdr data)))
6376           (when data
6377             (goto-char (gnus-data-pos (car data)))
6378             (gnus-data-number (car data))))))
6379     (gnus-summary-position-point)))
6380
6381 (defun gnus-summary-next-subject (n &optional unread dont-display)
6382   "Go to next N'th summary line.
6383 If N is negative, go to the previous N'th subject line.
6384 If UNREAD is non-nil, only unread articles are selected.
6385 The difference between N and the actual number of steps taken is
6386 returned."
6387   (interactive "p")
6388   (let ((backward (< n 0))
6389         (n (abs n)))
6390     (while (and (> n 0)
6391                 (if backward
6392                     (gnus-summary-find-prev unread)
6393                   (gnus-summary-find-next unread)))
6394       (unless (zerop (setq n (1- n)))
6395         (gnus-summary-show-thread)))
6396     (when (/= 0 n)
6397       (gnus-message 7 "No more%s articles"
6398                     (if unread " unread" "")))
6399     (unless dont-display
6400       (gnus-summary-recenter)
6401       (gnus-summary-position-point))
6402     n))
6403
6404 (defun gnus-summary-next-unread-subject (n)
6405   "Go to next N'th unread summary line."
6406   (interactive "p")
6407   (gnus-summary-next-subject n t))
6408
6409 (defun gnus-summary-prev-subject (n &optional unread)
6410   "Go to previous N'th summary line.
6411 If optional argument UNREAD is non-nil, only unread article is selected."
6412   (interactive "p")
6413   (gnus-summary-next-subject (- n) unread))
6414
6415 (defun gnus-summary-prev-unread-subject (n)
6416   "Go to previous N'th unread summary line."
6417   (interactive "p")
6418   (gnus-summary-next-subject (- n) t))
6419
6420 (defun gnus-summary-goto-subject (article &optional force silent)
6421   "Go the subject line of ARTICLE.
6422 If FORCE, also allow jumping to articles not currently shown."
6423   (interactive "nArticle number: ")
6424   (let ((b (point))
6425         (data (gnus-data-find article)))
6426     ;; We read in the article if we have to.
6427     (and (not data)
6428          force
6429          (gnus-summary-insert-subject
6430           article
6431           (if (or (numberp force) (vectorp force)) force)
6432           t)
6433          (setq data (gnus-data-find article)))
6434     (goto-char b)
6435     (if (not data)
6436         (progn
6437           (unless silent
6438             (gnus-message 3 "Can't find article %d" article))
6439           nil)
6440       (let ((pt (gnus-data-pos data)))
6441         (goto-char pt)
6442         (gnus-summary-set-article-display-arrow pt))
6443       (gnus-summary-position-point)
6444       article)))
6445
6446 ;; Walking around summary lines with displaying articles.
6447
6448 (defun gnus-summary-expand-window (&optional arg)
6449   "Make the summary buffer take up the entire Emacs frame.
6450 Given a prefix, will force an `article' buffer configuration."
6451   (interactive "P")
6452   (if arg
6453       (gnus-configure-windows 'article 'force)
6454     (gnus-configure-windows 'summary 'force)))
6455
6456 (defun gnus-summary-display-article (article &optional all-header)
6457   "Display ARTICLE in article buffer."
6458   (when (gnus-buffer-live-p gnus-article-buffer)
6459     (with-current-buffer gnus-article-buffer
6460       (set-buffer-multibyte t)))
6461   (gnus-set-global-variables)
6462   (when (gnus-buffer-live-p gnus-article-buffer)
6463     (with-current-buffer gnus-article-buffer
6464       (setq gnus-article-charset gnus-newsgroup-charset)
6465       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6466   (if (null article)
6467       nil
6468     (prog1
6469         (if gnus-summary-display-article-function
6470             (funcall gnus-summary-display-article-function article all-header)
6471           (gnus-article-prepare article all-header))
6472       (with-current-buffer gnus-article-buffer
6473         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6474              nil))
6475       (gnus-run-hooks 'gnus-select-article-hook)
6476       (when (and gnus-current-article
6477                  (not (zerop gnus-current-article)))
6478         (gnus-summary-goto-subject gnus-current-article))
6479       (gnus-summary-recenter)
6480       (when (and gnus-use-trees gnus-show-threads)
6481         (gnus-possibly-generate-tree article)
6482         (gnus-highlight-selected-tree article))
6483       ;; Successfully display article.
6484       (gnus-article-set-window-start
6485        (cdr (assq article gnus-newsgroup-bookmarks))))))
6486
6487 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6488   "Select the current article.
6489 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6490 non-nil, the article will be re-fetched even if it already present in
6491 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6492 be displayed."
6493   ;; Make sure we are in the summary buffer to work around bbdb bug.
6494   (unless (eq major-mode 'gnus-summary-mode)
6495     (set-buffer gnus-summary-buffer))
6496   (let ((article (or article (gnus-summary-article-number)))
6497         (all-headers (not (not all-headers))) ;Must be T or NIL.
6498         gnus-summary-display-article-function)
6499     (and (not pseudo)
6500          (gnus-summary-article-pseudo-p article)
6501          (error "This is a pseudo-article"))
6502     (save-excursion
6503       (set-buffer gnus-summary-buffer)
6504       (if (or (and gnus-single-article-buffer
6505                    (or (null gnus-current-article)
6506                        (null gnus-article-current)
6507                        (null (get-buffer gnus-article-buffer))
6508                        (not (eq article (cdr gnus-article-current)))
6509                        (not (equal (car gnus-article-current)
6510                                    gnus-newsgroup-name))))
6511               (and (not gnus-single-article-buffer)
6512                    (or (null gnus-current-article)
6513                        (not (eq gnus-current-article article))))
6514               force)
6515           ;; The requested article is different from the current article.
6516           (progn
6517             (gnus-summary-display-article article all-headers)
6518             (when (or all-headers gnus-show-all-headers)
6519               (gnus-article-show-all-headers))
6520             (gnus-article-set-window-start
6521              (cdr (assq article gnus-newsgroup-bookmarks)))
6522             article)
6523         (when (or all-headers gnus-show-all-headers)
6524           (gnus-article-show-all-headers))
6525         'old))))
6526
6527 (defun gnus-summary-force-verify-and-decrypt ()
6528   (interactive)
6529   (let ((mm-verify-option 'known)
6530         (mm-decrypt-option 'known))
6531     (gnus-summary-select-article nil 'force)))
6532
6533 (defun gnus-summary-set-current-mark (&optional current-mark)
6534   "Obsolete function."
6535   nil)
6536
6537 (defun gnus-summary-next-article (&optional unread subject backward push)
6538   "Select the next article.
6539 If UNREAD, only unread articles are selected.
6540 If SUBJECT, only articles with SUBJECT are selected.
6541 If BACKWARD, the previous article is selected instead of the next."
6542   (interactive "P")
6543   (cond
6544    ;; Is there such an article?
6545    ((and (gnus-summary-search-forward unread subject backward)
6546          (or (gnus-summary-display-article (gnus-summary-article-number))
6547              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6548     (gnus-summary-position-point))
6549    ;; If not, we try the first unread, if that is wanted.
6550    ((and subject
6551          gnus-auto-select-same
6552          (gnus-summary-first-unread-article))
6553     (gnus-summary-position-point)
6554     (gnus-message 6 "Wrapped"))
6555    ;; Try to get next/previous article not displayed in this group.
6556    ((and gnus-auto-extend-newsgroup
6557          (not unread) (not subject))
6558     (gnus-summary-goto-article
6559      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6560      nil (count-lines (point-min) (point))))
6561    ;; Go to next/previous group.
6562    (t
6563     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6564       (gnus-summary-jump-to-group gnus-newsgroup-name))
6565     (let ((cmd last-command-char)
6566           (point
6567            (save-excursion
6568              (set-buffer gnus-group-buffer)
6569              (point)))
6570           (group
6571            (if (eq gnus-keep-same-level 'best)
6572                (gnus-summary-best-group gnus-newsgroup-name)
6573              (gnus-summary-search-group backward gnus-keep-same-level))))
6574       ;; For some reason, the group window gets selected.  We change
6575       ;; it back.
6576       (select-window (get-buffer-window (current-buffer)))
6577       ;; Select next unread newsgroup automagically.
6578       (cond
6579        ((or (not gnus-auto-select-next)
6580             (not cmd))
6581         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6582        ((or (eq gnus-auto-select-next 'quietly)
6583             (and (eq gnus-auto-select-next 'slightly-quietly)
6584                  push)
6585             (and (eq gnus-auto-select-next 'almost-quietly)
6586                  (gnus-summary-last-article-p)))
6587         ;; Select quietly.
6588         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6589             (gnus-summary-exit)
6590           (gnus-message 7 "No more%s articles (%s)..."
6591                         (if unread " unread" "")
6592                         (if group (concat "selecting " group)
6593                           "exiting"))
6594           (gnus-summary-next-group nil group backward)))
6595        (t
6596         (when (gnus-key-press-event-p last-input-event)
6597           (gnus-summary-walk-group-buffer
6598            gnus-newsgroup-name cmd unread backward point))))))))
6599
6600 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6601   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6602                       (?\C-p (gnus-group-prev-unread-group 1))))
6603         (cursor-in-echo-area t)
6604         keve key group ended)
6605     (save-excursion
6606       (set-buffer gnus-group-buffer)
6607       (goto-char start)
6608       (setq group
6609             (if (eq gnus-keep-same-level 'best)
6610                 (gnus-summary-best-group gnus-newsgroup-name)
6611               (gnus-summary-search-group backward gnus-keep-same-level))))
6612     (while (not ended)
6613       (gnus-message
6614        5 "No more%s articles%s" (if unread " unread" "")
6615        (if (and group
6616                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6617            (format " (Type %s for %s [%s])"
6618                    (single-key-description cmd) group
6619                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6620          (format " (Type %s to exit %s)"
6621                  (single-key-description cmd)
6622                  gnus-newsgroup-name)))
6623       ;; Confirm auto selection.
6624       (setq key (car (setq keve (gnus-read-event-char))))
6625       (setq ended t)
6626       (cond
6627        ((assq key keystrokes)
6628         (let ((obuf (current-buffer)))
6629           (switch-to-buffer gnus-group-buffer)
6630           (when group
6631             (gnus-group-jump-to-group group))
6632           (eval (cadr (assq key keystrokes)))
6633           (setq group (gnus-group-group-name))
6634           (switch-to-buffer obuf))
6635         (setq ended nil))
6636        ((equal key cmd)
6637         (if (or (not group)
6638                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6639             (gnus-summary-exit)
6640           (gnus-summary-next-group nil group backward)))
6641        (t
6642         (push (cdr keve) unread-command-events))))))
6643
6644 (defun gnus-summary-next-unread-article ()
6645   "Select unread article after current one."
6646   (interactive)
6647   (gnus-summary-next-article
6648    (or (not (eq gnus-summary-goto-unread 'never))
6649        (gnus-summary-last-article-p (gnus-summary-article-number)))
6650    (and gnus-auto-select-same
6651         (gnus-summary-article-subject))))
6652
6653 (defun gnus-summary-prev-article (&optional unread subject)
6654   "Select the article after the current one.
6655 If UNREAD is non-nil, only unread articles are selected."
6656   (interactive "P")
6657   (gnus-summary-next-article unread subject t))
6658
6659 (defun gnus-summary-prev-unread-article ()
6660   "Select unread article before current one."
6661   (interactive)
6662   (gnus-summary-prev-article
6663    (or (not (eq gnus-summary-goto-unread 'never))
6664        (gnus-summary-first-article-p (gnus-summary-article-number)))
6665    (and gnus-auto-select-same
6666         (gnus-summary-article-subject))))
6667
6668 (defun gnus-summary-next-page (&optional lines circular)
6669   "Show next page of the selected article.
6670 If at the end of the current article, select the next article.
6671 LINES says how many lines should be scrolled up.
6672
6673 If CIRCULAR is non-nil, go to the start of the article instead of
6674 selecting the next article when reaching the end of the current
6675 article."
6676   (interactive "P")
6677   (setq gnus-summary-buffer (current-buffer))
6678   (gnus-set-global-variables)
6679   (let ((article (gnus-summary-article-number))
6680         (article-window (get-buffer-window gnus-article-buffer t))
6681         endp)
6682     ;; If the buffer is empty, we have no article.
6683     (unless article
6684       (error "No article to select"))
6685     (gnus-configure-windows 'article)
6686     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6687         (if (and (eq gnus-summary-goto-unread 'never)
6688                  (not (gnus-summary-last-article-p article)))
6689             (gnus-summary-next-article)
6690           (gnus-summary-next-unread-article))
6691       (if (or (null gnus-current-article)
6692               (null gnus-article-current)
6693               (/= article (cdr gnus-article-current))
6694               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6695           ;; Selected subject is different from current article's.
6696           (gnus-summary-display-article article)
6697         (when article-window
6698           (gnus-eval-in-buffer-window gnus-article-buffer
6699             (setq endp (gnus-article-next-page lines)))
6700           (when endp
6701             (cond (circular
6702                    (gnus-summary-beginning-of-article))
6703                   (lines
6704                    (gnus-message 3 "End of message"))
6705                   ((null lines)
6706                    (if (and (eq gnus-summary-goto-unread 'never)
6707                             (not (gnus-summary-last-article-p article)))
6708                        (gnus-summary-next-article)
6709                      (gnus-summary-next-unread-article))))))))
6710     (gnus-summary-recenter)
6711     (gnus-summary-position-point)))
6712
6713 (defun gnus-summary-prev-page (&optional lines move)
6714   "Show previous page of selected article.
6715 Argument LINES specifies lines to be scrolled down.
6716 If MOVE, move to the previous unread article if point is at
6717 the beginning of the buffer."
6718   (interactive "P")
6719   (let ((article (gnus-summary-article-number))
6720         (article-window (get-buffer-window gnus-article-buffer t))
6721         endp)
6722     (gnus-configure-windows 'article)
6723     (if (or (null gnus-current-article)
6724             (null gnus-article-current)
6725             (/= article (cdr gnus-article-current))
6726             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6727         ;; Selected subject is different from current article's.
6728         (gnus-summary-display-article article)
6729       (gnus-summary-recenter)
6730       (when article-window
6731         (gnus-eval-in-buffer-window gnus-article-buffer
6732           (setq endp (gnus-article-prev-page lines)))
6733         (when (and move endp)
6734           (cond (lines
6735                  (gnus-message 3 "Beginning of message"))
6736                 ((null lines)
6737                  (if (and (eq gnus-summary-goto-unread 'never)
6738                           (not (gnus-summary-first-article-p article)))
6739                      (gnus-summary-prev-article)
6740                    (gnus-summary-prev-unread-article))))))))
6741   (gnus-summary-position-point))
6742
6743 (defun gnus-summary-prev-page-or-article (&optional lines)
6744   "Show previous page of selected article.
6745 Argument LINES specifies lines to be scrolled down.
6746 If at the beginning of the article, go to the next article."
6747   (interactive "P")
6748   (gnus-summary-prev-page lines t))
6749
6750 (defun gnus-summary-scroll-up (lines)
6751   "Scroll up (or down) one line current article.
6752 Argument LINES specifies lines to be scrolled up (or down if negative)."
6753   (interactive "p")
6754   (gnus-configure-windows 'article)
6755   (gnus-summary-show-thread)
6756   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6757     (gnus-eval-in-buffer-window gnus-article-buffer
6758       (cond ((> lines 0)
6759              (when (gnus-article-next-page lines)
6760                (gnus-message 3 "End of message")))
6761             ((< lines 0)
6762              (gnus-article-prev-page (- lines))))))
6763   (gnus-summary-recenter)
6764   (gnus-summary-position-point))
6765
6766 (defun gnus-summary-scroll-down (lines)
6767   "Scroll down (or up) one line current article.
6768 Argument LINES specifies lines to be scrolled down (or up if negative)."
6769   (interactive "p")
6770   (gnus-summary-scroll-up (- lines)))
6771
6772 (defun gnus-summary-next-same-subject ()
6773   "Select next article which has the same subject as current one."
6774   (interactive)
6775   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6776
6777 (defun gnus-summary-prev-same-subject ()
6778   "Select previous article which has the same subject as current one."
6779   (interactive)
6780   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6781
6782 (defun gnus-summary-next-unread-same-subject ()
6783   "Select next unread article which has the same subject as current one."
6784   (interactive)
6785   (gnus-summary-next-article t (gnus-summary-article-subject)))
6786
6787 (defun gnus-summary-prev-unread-same-subject ()
6788   "Select previous unread article which has the same subject as current one."
6789   (interactive)
6790   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6791
6792 (defun gnus-summary-first-unread-article ()
6793   "Select the first unread article.
6794 Return nil if there are no unread articles."
6795   (interactive)
6796   (prog1
6797       (when (gnus-summary-first-subject t)
6798         (gnus-summary-show-thread)
6799         (gnus-summary-first-subject t)
6800         (gnus-summary-display-article (gnus-summary-article-number)))
6801     (gnus-summary-position-point)))
6802
6803 (defun gnus-summary-first-unread-subject ()
6804   "Place the point on the subject line of the first unread article.
6805 Return nil if there are no unread articles."
6806   (interactive)
6807   (prog1
6808       (when (gnus-summary-first-subject t)
6809         (gnus-summary-show-thread)
6810         (gnus-summary-first-subject t))
6811     (gnus-summary-position-point)))
6812
6813 (defun gnus-summary-first-unseen-subject ()
6814   "Place the point on the subject line of the first unseen article.
6815 Return nil if there are no unseen articles."
6816   (interactive)
6817   (prog1
6818       (when (gnus-summary-first-subject t t t)
6819         (gnus-summary-show-thread)
6820         (gnus-summary-first-subject t t t))
6821     (gnus-summary-position-point)))
6822
6823 (defun gnus-summary-first-article ()
6824   "Select the first article.
6825 Return nil if there are no articles."
6826   (interactive)
6827   (prog1
6828       (when (gnus-summary-first-subject)
6829         (gnus-summary-show-thread)
6830         (gnus-summary-first-subject)
6831         (gnus-summary-display-article (gnus-summary-article-number)))
6832     (gnus-summary-position-point)))
6833
6834 (defun gnus-summary-best-unread-article (&optional arg)
6835   "Select the unread article with the highest score.
6836 If given a prefix argument, select the next unread article that has a
6837 score higher than the default score."
6838   (interactive "P")
6839   (let ((article (if arg
6840                      (gnus-summary-better-unread-subject)
6841                    (gnus-summary-best-unread-subject))))
6842     (if article
6843         (gnus-summary-goto-article article)
6844       (error "No unread articles"))))
6845
6846 (defun gnus-summary-best-unread-subject ()
6847   "Select the unread subject with the highest score."
6848   (interactive)
6849   (let ((best -1000000)
6850         (data gnus-newsgroup-data)
6851         article score)
6852     (while data
6853       (and (gnus-data-unread-p (car data))
6854            (> (setq score
6855                     (gnus-summary-article-score (gnus-data-number (car data))))
6856               best)
6857            (setq best score
6858                  article (gnus-data-number (car data))))
6859       (setq data (cdr data)))
6860     (when article
6861       (gnus-summary-goto-subject article))
6862     (gnus-summary-position-point)
6863     article))
6864
6865 (defun gnus-summary-better-unread-subject ()
6866   "Select the first unread subject that has a score over the default score."
6867   (interactive)
6868   (let ((data gnus-newsgroup-data)
6869         article score)
6870     (while (and (setq article (gnus-data-number (car data)))
6871                 (or (gnus-data-read-p (car data))
6872                     (not (> (gnus-summary-article-score article)
6873                             gnus-summary-default-score))))
6874       (setq data (cdr data)))
6875     (when article
6876       (gnus-summary-goto-subject article))
6877     (gnus-summary-position-point)
6878     article))
6879
6880 (defun gnus-summary-last-subject ()
6881   "Go to the last displayed subject line in the group."
6882   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6883     (when article
6884       (gnus-summary-goto-subject article))))
6885
6886 (defun gnus-summary-goto-article (article &optional all-headers force)
6887   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6888 If ALL-HEADERS is non-nil, no header lines are hidden.
6889 If FORCE, go to the article even if it isn't displayed.  If FORCE
6890 is a number, it is the line the article is to be displayed on."
6891   (interactive
6892    (list
6893     (completing-read
6894      "Article number or Message-ID: "
6895      (mapcar (lambda (number) (list (int-to-string number)))
6896              gnus-newsgroup-limit))
6897     current-prefix-arg
6898     t))
6899   (prog1
6900       (if (and (stringp article)
6901                (string-match "@" article))
6902           (gnus-summary-refer-article article)
6903         (when (stringp article)
6904           (setq article (string-to-number article)))
6905         (if (gnus-summary-goto-subject article force)
6906             (gnus-summary-display-article article all-headers)
6907           (gnus-message 4 "Couldn't go to article %s" article) nil))
6908     (gnus-summary-position-point)))
6909
6910 (defun gnus-summary-goto-last-article ()
6911   "Go to the previously read article."
6912   (interactive)
6913   (prog1
6914       (when gnus-last-article
6915         (gnus-summary-goto-article gnus-last-article nil t))
6916     (gnus-summary-position-point)))
6917
6918 (defun gnus-summary-pop-article (number)
6919   "Pop one article off the history and go to the previous.
6920 NUMBER articles will be popped off."
6921   (interactive "p")
6922   (let (to)
6923     (setq gnus-newsgroup-history
6924           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6925     (if to
6926         (gnus-summary-goto-article (car to) nil t)
6927       (error "Article history empty")))
6928   (gnus-summary-position-point))
6929
6930 ;; Summary commands and functions for limiting the summary buffer.
6931
6932 (defun gnus-summary-limit-to-articles (n)
6933   "Limit the summary buffer to the next N articles.
6934 If not given a prefix, use the process marked articles instead."
6935   (interactive "P")
6936   (prog1
6937       (let ((articles (gnus-summary-work-articles n)))
6938         (setq gnus-newsgroup-processable nil)
6939         (gnus-summary-limit articles))
6940     (gnus-summary-position-point)))
6941
6942 (defun gnus-summary-pop-limit (&optional total)
6943   "Restore the previous limit.
6944 If given a prefix, remove all limits."
6945   (interactive "P")
6946   (when total
6947     (setq gnus-newsgroup-limits
6948           (list (mapcar (lambda (h) (mail-header-number h))
6949                         gnus-newsgroup-headers))))
6950   (unless gnus-newsgroup-limits
6951     (error "No limit to pop"))
6952   (prog1
6953       (gnus-summary-limit nil 'pop)
6954     (gnus-summary-position-point)))
6955
6956 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6957   "Limit the summary buffer to articles that have subjects that match a regexp.
6958 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6959   (interactive
6960    (list (read-string (if current-prefix-arg
6961                           "Exclude subject (regexp): "
6962                         "Limit to subject (regexp): "))
6963          nil current-prefix-arg))
6964   (unless header
6965     (setq header "subject"))
6966   (when (not (equal "" subject))
6967     (prog1
6968         (let ((articles (gnus-summary-find-matching
6969                          (or header "subject") subject 'all nil nil
6970                          not-matching)))
6971           (unless articles
6972             (error "Found no matches for \"%s\"" subject))
6973           (gnus-summary-limit articles))
6974       (gnus-summary-position-point))))
6975
6976 (defun gnus-summary-limit-to-author (from &optional not-matching)
6977   "Limit the summary buffer to articles that have authors that match a regexp.
6978 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6979   (interactive
6980    (list (read-string (if current-prefix-arg
6981                           "Exclude author (regexp): "
6982                         "Limit to author (regexp): "))
6983          current-prefix-arg))
6984   (gnus-summary-limit-to-subject from "from" not-matching))
6985
6986 (defun gnus-summary-limit-to-age (age &optional younger-p)
6987   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6988 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6989 articles that are younger than AGE days."
6990   (interactive
6991    (let ((younger current-prefix-arg)
6992          (days-got nil)
6993          days)
6994      (while (not days-got)
6995        (setq days (if younger
6996                       (read-string "Limit to articles within (in days): ")
6997                     (read-string "Limit to articles older than (in days): ")))
6998        (when (> (length days) 0)
6999          (setq days (read days)))
7000        (if (numberp days)
7001            (progn
7002              (setq days-got t)
7003              (if (< days 0)
7004                  (progn
7005                    (setq younger (not younger))
7006                    (setq days (* days -1)))))
7007          (message "Please enter a number.")
7008          (sleep-for 1)))
7009      (list days younger)))
7010   (prog1
7011       (let ((data gnus-newsgroup-data)
7012             (cutoff (days-to-time age))
7013             articles d date is-younger)
7014         (while (setq d (pop data))
7015           (when (and (vectorp (gnus-data-header d))
7016                      (setq date (mail-header-date (gnus-data-header d))))
7017             (setq is-younger (time-less-p
7018                               (time-since (condition-case ()
7019                                               (date-to-time date)
7020                                             (error '(0 0))))
7021                               cutoff))
7022             (when (if younger-p
7023                       is-younger
7024                     (not is-younger))
7025               (push (gnus-data-number d) articles))))
7026         (gnus-summary-limit (nreverse articles)))
7027     (gnus-summary-position-point)))
7028
7029 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7030   "Limit the summary buffer to articles that match an 'extra' header."
7031   (interactive
7032    (let ((header
7033           (intern
7034            (gnus-completing-read
7035             (symbol-name (car gnus-extra-headers))
7036             (if current-prefix-arg
7037                 "Exclude extra header:"
7038               "Limit extra header:")
7039             (mapcar (lambda (x)
7040                       (cons (symbol-name x) x))
7041                     gnus-extra-headers)
7042             nil
7043             t))))
7044      (list header
7045            (read-string (format "%s header %s (regexp): "
7046                                 (if current-prefix-arg "Exclude" "Limit to")
7047                                 header))
7048            current-prefix-arg)))
7049   (when (not (equal "" regexp))
7050     (prog1
7051         (let ((articles (gnus-summary-find-matching
7052                          (cons 'extra header) regexp 'all nil nil
7053                          not-matching)))
7054           (unless articles
7055             (error "Found no matches for \"%s\"" regexp))
7056           (gnus-summary-limit articles))
7057       (gnus-summary-position-point))))
7058
7059 (defun gnus-summary-limit-to-display-predicate ()
7060   "Limit the summary buffer to the predicated in the `display' group parameter."
7061   (interactive)
7062   (unless gnus-newsgroup-display
7063     (error "There is no `display' group parameter"))
7064   (let (articles)
7065     (dolist (number gnus-newsgroup-articles)
7066       (when (funcall gnus-newsgroup-display)
7067         (push number articles)))
7068     (gnus-summary-limit articles))
7069   (gnus-summary-position-point))
7070
7071 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7072 (make-obsolete
7073  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7074
7075 (defun gnus-summary-limit-to-unread (&optional all)
7076   "Limit the summary buffer to articles that are not marked as read.
7077 If ALL is non-nil, limit strictly to unread articles."
7078   (interactive "P")
7079   (if all
7080       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7081     (gnus-summary-limit-to-marks
7082      ;; Concat all the marks that say that an article is read and have
7083      ;; those removed.
7084      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7085            gnus-killed-mark gnus-kill-file-mark
7086            gnus-low-score-mark gnus-expirable-mark
7087            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7088            gnus-duplicate-mark gnus-souped-mark)
7089      'reverse)))
7090
7091 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7092 (make-obsolete 'gnus-summary-delete-marked-with
7093                'gnus-summary-limit-exlude-marks)
7094
7095 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7096   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7097 If REVERSE, limit the summary buffer to articles that are marked
7098 with MARKS.  MARKS can either be a string of marks or a list of marks.
7099 Returns how many articles were removed."
7100   (interactive "sMarks: ")
7101   (gnus-summary-limit-to-marks marks t))
7102
7103 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7104   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7105 If REVERSE (the prefix), limit the summary buffer to articles that are
7106 not marked with MARKS.  MARKS can either be a string of marks or a
7107 list of marks.
7108 Returns how many articles were removed."
7109   (interactive "sMarks: \nP")
7110   (prog1
7111       (let ((data gnus-newsgroup-data)
7112             (marks (if (listp marks) marks
7113                      (append marks nil))) ; Transform to list.
7114             articles)
7115         (while data
7116           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7117                   (memq (gnus-data-mark (car data)) marks))
7118             (push (gnus-data-number (car data)) articles))
7119           (setq data (cdr data)))
7120         (gnus-summary-limit articles))
7121     (gnus-summary-position-point)))
7122
7123 (defun gnus-summary-limit-to-score (score)
7124   "Limit to articles with score at or above SCORE."
7125   (interactive "NLimit to articles with score of at least: ")
7126   (let ((data gnus-newsgroup-data)
7127         articles)
7128     (while data
7129       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7130                 score)
7131         (push (gnus-data-number (car data)) articles))
7132       (setq data (cdr data)))
7133     (prog1
7134         (gnus-summary-limit articles)
7135       (gnus-summary-position-point))))
7136
7137 (defun gnus-summary-limit-include-thread (id)
7138   "Display all the hidden articles that is in the thread with ID in it.
7139 When called interactively, ID is the Message-ID of the current
7140 article."
7141   (interactive (list (mail-header-id (gnus-summary-article-header))))
7142   (let ((articles (gnus-articles-in-thread
7143                    (gnus-id-to-thread (gnus-root-id id)))))
7144     (prog1
7145         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7146       (gnus-summary-limit-include-matching-articles
7147        "subject"
7148        (regexp-quote (gnus-simplify-subject-re
7149                       (mail-header-subject (gnus-id-to-header id)))))
7150       (gnus-summary-position-point))))
7151
7152 (defun gnus-summary-limit-include-matching-articles (header regexp)
7153   "Display all the hidden articles that have HEADERs that match REGEXP."
7154   (interactive (list (read-string "Match on header: ")
7155                      (read-string "Regexp: ")))
7156   (let ((articles (gnus-find-matching-articles header regexp)))
7157     (prog1
7158         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7159       (gnus-summary-position-point))))
7160
7161 (defun gnus-summary-limit-include-dormant ()
7162   "Display all the hidden articles that are marked as dormant.
7163 Note that this command only works on a subset of the articles currently
7164 fetched for this group."
7165   (interactive)
7166   (unless gnus-newsgroup-dormant
7167     (error "There are no dormant articles in this group"))
7168   (prog1
7169       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7170     (gnus-summary-position-point)))
7171
7172 (defun gnus-summary-limit-exclude-dormant ()
7173   "Hide all dormant articles."
7174   (interactive)
7175   (prog1
7176       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7177     (gnus-summary-position-point)))
7178
7179 (defun gnus-summary-limit-exclude-childless-dormant ()
7180   "Hide all dormant articles that have no children."
7181   (interactive)
7182   (let ((data (gnus-data-list t))
7183         articles d children)
7184     ;; Find all articles that are either not dormant or have
7185     ;; children.
7186     (while (setq d (pop data))
7187       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7188                 (and (setq children
7189                            (gnus-article-children (gnus-data-number d)))
7190                      (let (found)
7191                        (while children
7192                          (when (memq (car children) articles)
7193                            (setq children nil
7194                                  found t))
7195                          (pop children))
7196                        found)))
7197         (push (gnus-data-number d) articles)))
7198     ;; Do the limiting.
7199     (prog1
7200         (gnus-summary-limit articles)
7201       (gnus-summary-position-point))))
7202
7203 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7204   "Mark all unread excluded articles as read.
7205 If ALL, mark even excluded ticked and dormants as read."
7206   (interactive "P")
7207   (let ((articles (gnus-sorted-complement
7208                    (sort
7209                     (mapcar (lambda (h) (mail-header-number h))
7210                             gnus-newsgroup-headers)
7211                     '<)
7212                    (sort gnus-newsgroup-limit '<)))
7213         article)
7214     (setq gnus-newsgroup-unreads
7215           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7216     (if all
7217         (setq gnus-newsgroup-dormant nil
7218               gnus-newsgroup-marked nil
7219               gnus-newsgroup-reads
7220               (nconc
7221                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7222                gnus-newsgroup-reads))
7223       (while (setq article (pop articles))
7224         (unless (or (memq article gnus-newsgroup-dormant)
7225                     (memq article gnus-newsgroup-marked))
7226           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7227
7228 (defun gnus-summary-limit (articles &optional pop)
7229   (if pop
7230       ;; We pop the previous limit off the stack and use that.
7231       (setq articles (car gnus-newsgroup-limits)
7232             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7233     ;; We use the new limit, so we push the old limit on the stack.
7234     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7235   ;; Set the limit.
7236   (setq gnus-newsgroup-limit articles)
7237   (let ((total (length gnus-newsgroup-data))
7238         (data (gnus-data-find-list (gnus-summary-article-number)))
7239         (gnus-summary-mark-below nil)   ; Inhibit this.
7240         found)
7241     ;; This will do all the work of generating the new summary buffer
7242     ;; according to the new limit.
7243     (gnus-summary-prepare)
7244     ;; Hide any threads, possibly.
7245     (and gnus-show-threads
7246          gnus-thread-hide-subtree
7247          (gnus-summary-hide-all-threads))
7248     ;; Try to return to the article you were at, or one in the
7249     ;; neighborhood.
7250     (when data
7251       ;; We try to find some article after the current one.
7252       (while data
7253         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7254           (setq data nil
7255                 found t))
7256         (setq data (cdr data))))
7257     (unless found
7258       ;; If there is no data, that means that we were after the last
7259       ;; article.  The same goes when we can't find any articles
7260       ;; after the current one.
7261       (goto-char (point-max))
7262       (gnus-summary-find-prev))
7263     (gnus-set-mode-line 'summary)
7264     ;; We return how many articles were removed from the summary
7265     ;; buffer as a result of the new limit.
7266     (- total (length gnus-newsgroup-data))))
7267
7268 (defsubst gnus-invisible-cut-children (threads)
7269   (let ((num 0))
7270     (while threads
7271       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7272         (incf num))
7273       (pop threads))
7274     (< num 2)))
7275
7276 (defsubst gnus-cut-thread (thread)
7277   "Go forwards in the thread until we find an article that we want to display."
7278   (when (or (eq gnus-fetch-old-headers 'some)
7279             (eq gnus-fetch-old-headers 'invisible)
7280             (numberp gnus-fetch-old-headers)
7281             (eq gnus-build-sparse-threads 'some)
7282             (eq gnus-build-sparse-threads 'more))
7283     ;; Deal with old-fetched headers and sparse threads.
7284     (while (and
7285             thread
7286             (or
7287              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7288              (gnus-summary-article-ancient-p
7289               (mail-header-number (car thread))))
7290             (if (or (<= (length (cdr thread)) 1)
7291                     (eq gnus-fetch-old-headers 'invisible))
7292                 (setq gnus-newsgroup-limit
7293                       (delq (mail-header-number (car thread))
7294                             gnus-newsgroup-limit)
7295                       thread (cadr thread))
7296               (when (gnus-invisible-cut-children (cdr thread))
7297                 (let ((th (cdr thread)))
7298                   (while th
7299                     (if (memq (mail-header-number (caar th))
7300                               gnus-newsgroup-limit)
7301                         (setq thread (car th)
7302                               th nil)
7303                       (setq th (cdr th))))))))))
7304   thread)
7305
7306 (defun gnus-cut-threads (threads)
7307   "Cut off all uninteresting articles from the beginning of threads."
7308   (when (or (eq gnus-fetch-old-headers 'some)
7309             (eq gnus-fetch-old-headers 'invisible)
7310             (numberp gnus-fetch-old-headers)
7311             (eq gnus-build-sparse-threads 'some)
7312             (eq gnus-build-sparse-threads 'more))
7313     (let ((th threads))
7314       (while th
7315         (setcar th (gnus-cut-thread (car th)))
7316         (setq th (cdr th)))))
7317   ;; Remove nixed out threads.
7318   (delq nil threads))
7319
7320 (defun gnus-summary-initial-limit (&optional show-if-empty)
7321   "Figure out what the initial limit is supposed to be on group entry.
7322 This entails weeding out unwanted dormants, low-scored articles,
7323 fetch-old-headers verbiage, and so on."
7324   ;; Most groups have nothing to remove.
7325   (if (or gnus-inhibit-limiting
7326           (and (null gnus-newsgroup-dormant)
7327                (eq gnus-newsgroup-display 'gnus-not-ignore)
7328                (not (eq gnus-fetch-old-headers 'some))
7329                (not (numberp gnus-fetch-old-headers))
7330                (not (eq gnus-fetch-old-headers 'invisible))
7331                (null gnus-summary-expunge-below)
7332                (not (eq gnus-build-sparse-threads 'some))
7333                (not (eq gnus-build-sparse-threads 'more))
7334                (null gnus-thread-expunge-below)
7335                (not gnus-use-nocem)))
7336       ()                                ; Do nothing.
7337     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7338     (setq gnus-newsgroup-limit nil)
7339     (mapatoms
7340      (lambda (node)
7341        (unless (car (symbol-value node))
7342          ;; These threads have no parents -- they are roots.
7343          (let ((nodes (cdr (symbol-value node)))
7344                thread)
7345            (while nodes
7346              (if (and gnus-thread-expunge-below
7347                       (< (gnus-thread-total-score (car nodes))
7348                          gnus-thread-expunge-below))
7349                  (gnus-expunge-thread (pop nodes))
7350                (setq thread (pop nodes))
7351                (gnus-summary-limit-children thread))))))
7352      gnus-newsgroup-dependencies)
7353     ;; If this limitation resulted in an empty group, we might
7354     ;; pop the previous limit and use it instead.
7355     (when (and (not gnus-newsgroup-limit)
7356                show-if-empty)
7357       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7358     gnus-newsgroup-limit))
7359
7360 (defun gnus-summary-limit-children (thread)
7361   "Return 1 if this subthread is visible and 0 if it is not."
7362   ;; First we get the number of visible children to this thread.  This
7363   ;; is done by recursing down the thread using this function, so this
7364   ;; will really go down to a leaf article first, before slowly
7365   ;; working its way up towards the root.
7366   (when thread
7367     (let ((children
7368            (if (cdr thread)
7369                (apply '+ (mapcar 'gnus-summary-limit-children
7370                                  (cdr thread)))
7371              0))
7372           (number (mail-header-number (car thread)))
7373           score)
7374       (if (and
7375            (not (memq number gnus-newsgroup-marked))
7376            (or
7377             ;; If this article is dormant and has absolutely no visible
7378             ;; children, then this article isn't visible.
7379             (and (memq number gnus-newsgroup-dormant)
7380                  (zerop children))
7381             ;; If this is "fetch-old-headered" and there is no
7382             ;; visible children, then we don't want this article.
7383             (and (or (eq gnus-fetch-old-headers 'some)
7384                      (numberp gnus-fetch-old-headers))
7385                  (gnus-summary-article-ancient-p number)
7386                  (zerop children))
7387             ;; If this is "fetch-old-headered" and `invisible', then
7388             ;; we don't want this article.
7389             (and (eq gnus-fetch-old-headers 'invisible)
7390                  (gnus-summary-article-ancient-p number))
7391             ;; If this is a sparsely inserted article with no children,
7392             ;; we don't want it.
7393             (and (eq gnus-build-sparse-threads 'some)
7394                  (gnus-summary-article-sparse-p number)
7395                  (zerop children))
7396             ;; If we use expunging, and this article is really
7397             ;; low-scored, then we don't want this article.
7398             (when (and gnus-summary-expunge-below
7399                        (< (setq score
7400                                 (or (cdr (assq number gnus-newsgroup-scored))
7401                                     gnus-summary-default-score))
7402                           gnus-summary-expunge-below))
7403               ;; We increase the expunge-tally here, but that has
7404               ;; nothing to do with the limits, really.
7405               (incf gnus-newsgroup-expunged-tally)
7406               ;; We also mark as read here, if that's wanted.
7407               (when (and gnus-summary-mark-below
7408                          (< score gnus-summary-mark-below))
7409                 (setq gnus-newsgroup-unreads
7410                       (delq number gnus-newsgroup-unreads))
7411                 (if gnus-newsgroup-auto-expire
7412                     (push number gnus-newsgroup-expirable)
7413                   (push (cons number gnus-low-score-mark)
7414                         gnus-newsgroup-reads)))
7415               t)
7416             ;; Do the `display' group parameter.
7417             (and gnus-newsgroup-display
7418                  (not (funcall gnus-newsgroup-display)))
7419             ;; Check NoCeM things.
7420             (if (and gnus-use-nocem
7421                      (gnus-nocem-unwanted-article-p
7422                       (mail-header-id (car thread))))
7423                 (progn
7424                   (setq gnus-newsgroup-unreads
7425                         (delq number gnus-newsgroup-unreads))
7426                   t))))
7427           ;; Nope, invisible article.
7428           0
7429         ;; Ok, this article is to be visible, so we add it to the limit
7430         ;; and return 1.
7431         (push number gnus-newsgroup-limit)
7432         1))))
7433
7434 (defun gnus-expunge-thread (thread)
7435   "Mark all articles in THREAD as read."
7436   (let* ((number (mail-header-number (car thread))))
7437     (incf gnus-newsgroup-expunged-tally)
7438     ;; We also mark as read here, if that's wanted.
7439     (setq gnus-newsgroup-unreads
7440           (delq number gnus-newsgroup-unreads))
7441     (if gnus-newsgroup-auto-expire
7442         (push number gnus-newsgroup-expirable)
7443       (push (cons number gnus-low-score-mark)
7444             gnus-newsgroup-reads)))
7445   ;; Go recursively through all subthreads.
7446   (mapcar 'gnus-expunge-thread (cdr thread)))
7447
7448 ;; Summary article oriented commands
7449
7450 (defun gnus-summary-refer-parent-article (n)
7451   "Refer parent article N times.
7452 If N is negative, go to ancestor -N instead.
7453 The difference between N and the number of articles fetched is returned."
7454   (interactive "p")
7455   (let ((skip 1)
7456         error header ref)
7457     (when (not (natnump n))
7458       (setq skip (abs n)
7459             n 1))
7460     (while (and (> n 0)
7461                 (not error))
7462       (setq header (gnus-summary-article-header))
7463       (if (and (eq (mail-header-number header)
7464                    (cdr gnus-article-current))
7465                (equal gnus-newsgroup-name
7466                       (car gnus-article-current)))
7467           ;; If we try to find the parent of the currently
7468           ;; displayed article, then we take a look at the actual
7469           ;; References header, since this is slightly more
7470           ;; reliable than the References field we got from the
7471           ;; server.
7472           (save-excursion
7473             (set-buffer gnus-original-article-buffer)
7474             (nnheader-narrow-to-headers)
7475             (unless (setq ref (message-fetch-field "references"))
7476               (setq ref (message-fetch-field "in-reply-to")))
7477             (widen))
7478         (setq ref
7479               ;; It's not the current article, so we take a bet on
7480               ;; the value we got from the server.
7481               (mail-header-references header)))
7482       (if (and ref
7483                (not (equal ref "")))
7484           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7485             (gnus-message 1 "Couldn't find parent"))
7486         (gnus-message 1 "No references in article %d"
7487                       (gnus-summary-article-number))
7488         (setq error t))
7489       (decf n))
7490     (gnus-summary-position-point)
7491     n))
7492
7493 (defun gnus-summary-refer-references ()
7494   "Fetch all articles mentioned in the References header.
7495 Return the number of articles fetched."
7496   (interactive)
7497   (let ((ref (mail-header-references (gnus-summary-article-header)))
7498         (current (gnus-summary-article-number))
7499         (n 0))
7500     (if (or (not ref)
7501             (equal ref ""))
7502         (error "No References in the current article")
7503       ;; For each Message-ID in the References header...
7504       (while (string-match "<[^>]*>" ref)
7505         (incf n)
7506         ;; ... fetch that article.
7507         (gnus-summary-refer-article
7508          (prog1 (match-string 0 ref)
7509            (setq ref (substring ref (match-end 0))))))
7510       (gnus-summary-goto-subject current)
7511       (gnus-summary-position-point)
7512       n)))
7513
7514 (defun gnus-summary-refer-thread (&optional limit)
7515   "Fetch all articles in the current thread.
7516 If LIMIT (the numerical prefix), fetch that many old headers instead
7517 of what's specified by the `gnus-refer-thread-limit' variable."
7518   (interactive "P")
7519   (let ((id (mail-header-id (gnus-summary-article-header)))
7520         (limit (if limit (prefix-numeric-value limit)
7521                  gnus-refer-thread-limit)))
7522     ;; We want to fetch LIMIT *old* headers, but we also have to
7523     ;; re-fetch all the headers in the current buffer, because many of
7524     ;; them may be undisplayed.  So we adjust LIMIT.
7525     (when (numberp limit)
7526       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7527     (unless (eq gnus-fetch-old-headers 'invisible)
7528       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7529       ;; Retrieve the headers and read them in.
7530       (if (eq (gnus-retrieve-headers
7531                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7532               'nov)
7533           (gnus-build-all-threads)
7534         (error "Can't fetch thread from backends that don't support NOV"))
7535       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7536     (gnus-summary-limit-include-thread id)))
7537
7538 (defun gnus-summary-refer-article (message-id)
7539   "Fetch an article specified by MESSAGE-ID."
7540   (interactive "sMessage-ID: ")
7541   (when (and (stringp message-id)
7542              (not (zerop (length message-id))))
7543     ;; Construct the correct Message-ID if necessary.
7544     ;; Suggested by tale@pawl.rpi.edu.
7545     (unless (string-match "^<" message-id)
7546       (setq message-id (concat "<" message-id)))
7547     (unless (string-match ">$" message-id)
7548       (setq message-id (concat message-id ">")))
7549     (let* ((header (gnus-id-to-header message-id))
7550            (sparse (and header
7551                         (gnus-summary-article-sparse-p
7552                          (mail-header-number header))
7553                         (memq (mail-header-number header)
7554                               gnus-newsgroup-limit)))
7555            number)
7556       (cond
7557        ;; If the article is present in the buffer we just go to it.
7558        ((and header
7559              (or (not (gnus-summary-article-sparse-p
7560                        (mail-header-number header)))
7561                  sparse))
7562         (prog1
7563             (gnus-summary-goto-article
7564              (mail-header-number header) nil t)
7565           (when sparse
7566             (gnus-summary-update-article (mail-header-number header)))))
7567        (t
7568         ;; We fetch the article.
7569         (catch 'found
7570           (dolist (gnus-override-method (gnus-refer-article-methods))
7571             (gnus-check-server gnus-override-method)
7572             ;; Fetch the header, and display the article.
7573             (when (setq number (gnus-summary-insert-subject message-id))
7574               (gnus-summary-select-article nil nil nil number)
7575               (throw 'found t)))
7576           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7577
7578 (defun gnus-refer-article-methods ()
7579   "Return a list of referrable methods."
7580   (cond
7581    ;; No method, so we default to current and native.
7582    ((null gnus-refer-article-method)
7583     (list gnus-current-select-method gnus-select-method))
7584    ;; Current.
7585    ((eq 'current gnus-refer-article-method)
7586     (list gnus-current-select-method))
7587    ;; List of select methods.
7588    ((not (and (symbolp (car gnus-refer-article-method))
7589               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7590     (let (out)
7591       (dolist (method gnus-refer-article-method)
7592         (push (if (eq 'current method)
7593                   gnus-current-select-method
7594                 method)
7595               out))
7596       (nreverse out)))
7597    ;; One single select method.
7598    (t
7599     (list gnus-refer-article-method))))
7600
7601 (defun gnus-summary-edit-parameters ()
7602   "Edit the group parameters of the current group."
7603   (interactive)
7604   (gnus-group-edit-group gnus-newsgroup-name 'params))
7605
7606 (defun gnus-summary-customize-parameters ()
7607   "Customize the group parameters of the current group."
7608   (interactive)
7609   (gnus-group-customize gnus-newsgroup-name))
7610
7611 (defun gnus-summary-enter-digest-group (&optional force)
7612   "Enter an nndoc group based on the current article.
7613 If FORCE, force a digest interpretation.  If not, try
7614 to guess what the document format is."
7615   (interactive "P")
7616   (let ((conf gnus-current-window-configuration))
7617     (save-excursion
7618       (gnus-summary-select-article))
7619     (setq gnus-current-window-configuration conf)
7620     (let* ((name (format "%s-%d"
7621                          (gnus-group-prefixed-name
7622                           gnus-newsgroup-name (list 'nndoc ""))
7623                          (save-excursion
7624                            (set-buffer gnus-summary-buffer)
7625                            gnus-current-article)))
7626            (ogroup gnus-newsgroup-name)
7627            (params (append (gnus-info-params (gnus-get-info ogroup))
7628                            (list (cons 'to-group ogroup))
7629                            (list (cons 'save-article-group ogroup))))
7630            (case-fold-search t)
7631            (buf (current-buffer))
7632            dig to-address)
7633       (save-excursion
7634         (set-buffer gnus-original-article-buffer)
7635         ;; Have the digest group inherit the main mail address of
7636         ;; the parent article.
7637         (when (setq to-address (or (message-fetch-field "reply-to")
7638                                    (message-fetch-field "from")))
7639           (setq params (append
7640                         (list (cons 'to-address
7641                                     (funcall gnus-decode-encoded-word-function
7642                                              to-address))))))
7643         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7644         (insert-buffer-substring gnus-original-article-buffer)
7645         ;; Remove lines that may lead nndoc to misinterpret the
7646         ;; document type.
7647         (narrow-to-region
7648          (goto-char (point-min))
7649          (or (search-forward "\n\n" nil t) (point)))
7650         (goto-char (point-min))
7651         (delete-matching-lines "^Path:\\|^From ")
7652         (widen))
7653       (unwind-protect
7654           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7655                     (gnus-newsgroup-ephemeral-ignored-charsets
7656                      gnus-newsgroup-ignored-charsets))
7657                 (gnus-group-read-ephemeral-group
7658                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7659                               (nndoc-article-type
7660                                ,(if force 'mbox 'guess))) t))
7661               ;; Make all postings to this group go to the parent group.
7662               (nconc (gnus-info-params (gnus-get-info name))
7663                      params)
7664             ;; Couldn't select this doc group.
7665             (switch-to-buffer buf)
7666             (gnus-set-global-variables)
7667             (gnus-configure-windows 'summary)
7668             (gnus-message 3 "Article couldn't be entered?"))
7669         (kill-buffer dig)))))
7670
7671 (defun gnus-summary-read-document (n)
7672   "Open a new group based on the current article(s).
7673 This will allow you to read digests and other similar
7674 documents as newsgroups.
7675 Obeys the standard process/prefix convention."
7676   (interactive "P")
7677   (let* ((articles (gnus-summary-work-articles n))
7678          (ogroup gnus-newsgroup-name)
7679          (params (append (gnus-info-params (gnus-get-info ogroup))
7680                          (list (cons 'to-group ogroup))))
7681          article group egroup groups vgroup)
7682     (while (setq article (pop articles))
7683       (setq group (format "%s-%d" gnus-newsgroup-name article))
7684       (gnus-summary-remove-process-mark article)
7685       (when (gnus-summary-display-article article)
7686         (save-excursion
7687           (with-temp-buffer
7688             (insert-buffer-substring gnus-original-article-buffer)
7689             ;; Remove some headers that may lead nndoc to make
7690             ;; the wrong guess.
7691             (message-narrow-to-head)
7692             (goto-char (point-min))
7693             (delete-matching-lines "^\\(Path\\):\\|^From ")
7694             (widen)
7695             (if (setq egroup
7696                       (gnus-group-read-ephemeral-group
7697                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7698                                      (nndoc-article-type guess))
7699                        t nil t))
7700                 (progn
7701                   ;; Make all postings to this group go to the parent group.
7702                   (nconc (gnus-info-params (gnus-get-info egroup))
7703                          params)
7704                   (push egroup groups))
7705               ;; Couldn't select this doc group.
7706               (gnus-error 3 "Article couldn't be entered"))))))
7707     ;; Now we have selected all the documents.
7708     (cond
7709      ((not groups)
7710       (error "None of the articles could be interpreted as documents"))
7711      ((gnus-group-read-ephemeral-group
7712        (setq vgroup (format
7713                      "nnvirtual:%s-%s" gnus-newsgroup-name
7714                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7715        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7716        t
7717        (cons (current-buffer) 'summary)))
7718      (t
7719       (error "Couldn't select virtual nndoc group")))))
7720
7721 (defun gnus-summary-isearch-article (&optional regexp-p)
7722   "Do incremental search forward on the current article.
7723 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7724   (interactive "P")
7725   (let* ((gnus-inhibit-treatment t)
7726          (old (gnus-summary-select-article)))
7727     (gnus-configure-windows 'article)
7728     (gnus-eval-in-buffer-window gnus-article-buffer
7729       (save-restriction
7730         (widen)
7731         (when (eq 'old old)
7732           (gnus-article-show-all-headers))
7733         (goto-char (point-min))
7734         (isearch-forward regexp-p)))))
7735
7736 (defun gnus-summary-search-article-forward (regexp &optional backward)
7737   "Search for an article containing REGEXP forward.
7738 If BACKWARD, search backward instead."
7739   (interactive
7740    (list (read-string
7741           (format "Search article %s (regexp%s): "
7742                   (if current-prefix-arg "backward" "forward")
7743                   (if gnus-last-search-regexp
7744                       (concat ", default " gnus-last-search-regexp)
7745                     "")))
7746          current-prefix-arg))
7747   (if (string-equal regexp "")
7748       (setq regexp (or gnus-last-search-regexp ""))
7749     (setq gnus-last-search-regexp regexp)
7750     (setq gnus-article-before-search gnus-current-article))
7751   ;; Intentionally set gnus-last-article.
7752   (setq gnus-last-article gnus-article-before-search)
7753   (let ((gnus-last-article gnus-last-article))
7754     (if (gnus-summary-search-article regexp backward)
7755         (gnus-summary-show-thread)
7756       (error "Search failed: \"%s\"" regexp))))
7757
7758 (defun gnus-summary-search-article-backward (regexp)
7759   "Search for an article containing REGEXP backward."
7760   (interactive
7761    (list (read-string
7762           (format "Search article backward (regexp%s): "
7763                   (if gnus-last-search-regexp
7764                       (concat ", default " gnus-last-search-regexp)
7765                     "")))))
7766   (gnus-summary-search-article-forward regexp 'backward))
7767
7768 (eval-when-compile
7769   (defmacro gnus-summary-search-article-position-point (regexp backward)
7770     "Dehighlight the last matched text and goto the beginning position."
7771     (` (if (and gnus-summary-search-article-matched-data
7772                 (let ((text (caddr gnus-summary-search-article-matched-data))
7773                       (inhibit-read-only t)
7774                       buffer-read-only)
7775                   (delete-region
7776                    (goto-char (car gnus-summary-search-article-matched-data))
7777                    (cadr gnus-summary-search-article-matched-data))
7778                   (insert text)
7779                   (string-match (, regexp) text)))
7780            (if (, backward) (beginning-of-line) (end-of-line))
7781          (goto-char (if (, backward) (point-max) (point-min))))))
7782
7783   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7784     "Place point where X-Face image is displayed."
7785     (if (featurep 'xemacs)
7786         (` (let ((end (if (search-forward "\n\n" nil t)
7787                           (goto-char (1- (point)))
7788                         (point-min)))
7789                  extent)
7790              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7791              (unless (and (re-search-forward "^From:" end t)
7792                           (setq extent (extent-at (point)))
7793                           (extent-begin-glyph extent))
7794                (goto-char (, opoint)))))
7795       (` (let ((end (if (search-forward "\n\n" nil t)
7796                         (goto-char (1- (point)))
7797                       (point-min)))
7798                (start (or (search-backward "\n\n" nil t) (point-min))))
7799            (goto-char
7800             (or (text-property-any start end 'x-face-image t);; x-face-e21
7801                 (text-property-any start end 'x-face-mule-bitmap-image t)
7802                 (, opoint)))))))
7803
7804   (defmacro gnus-summary-search-article-highlight-matched-text
7805     (backward treated x-face)
7806     "Highlight matched text in the function `gnus-summary-search-article'."
7807     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7808              (end (set-marker (make-marker) (match-end 0)))
7809              (inhibit-read-only t)
7810              buffer-read-only)
7811          (unless treated
7812            (let ((,@
7813                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7814                     (mapcar
7815                      (lambda (item) (setq items (delq item items)))
7816                      '(gnus-treat-buttonize
7817                        gnus-treat-fill-article
7818                        gnus-treat-fill-long-lines
7819                        gnus-treat-emphasize
7820                        gnus-treat-highlight-headers
7821                        gnus-treat-highlight-citation
7822                        gnus-treat-highlight-signature
7823                        gnus-treat-overstrike
7824                        gnus-treat-display-xface
7825                        gnus-treat-buttonize-head
7826                        gnus-treat-decode-article-as-default-mime-charset))
7827                     (static-if (featurep 'xemacs)
7828                         items
7829                       (cons '(x-face-mule-delete-x-face-field
7830                               (quote never))
7831                             items))))
7832                  (gnus-treat-display-xface
7833                   (when (, x-face) gnus-treat-display-xface)))
7834              (gnus-article-prepare-mime-display)))
7835          (goto-char (if (, backward) start end))
7836          (when (, x-face)
7837            (gnus-summary-search-article-highlight-goto-x-face (point)))
7838          (setq gnus-summary-search-article-matched-data
7839                (list start end (buffer-substring start end)))
7840          (unless (eq start end);; matched text has been deleted. :-<
7841            (put-text-property start end 'face
7842                               (or (find-face 'isearch)
7843                                   'secondary-selection))))))
7844   )
7845
7846 (defun gnus-summary-search-article (regexp &optional backward)
7847   "Search for an article containing REGEXP.
7848 Optional argument BACKWARD means do search for backward.
7849 `gnus-select-article-hook' is not called during the search."
7850   ;; We have to require this here to make sure that the following
7851   ;; dynamic binding isn't shadowed by autoloading.
7852   (require 'gnus-async)
7853   (require 'gnus-art)
7854   (let ((gnus-select-article-hook nil)  ;Disable hook.
7855         (gnus-article-prepare-hook nil)
7856         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7857         (gnus-use-article-prefetch nil)
7858         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7859         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7860         (sum (current-buffer))
7861         (found nil)
7862         point treated)
7863     (gnus-save-hidden-threads
7864       (static-if (featurep 'xemacs)
7865           (let ((gnus-inhibit-treatment t))
7866             (setq treated (eq 'old (gnus-summary-select-article)))
7867             (when (and treated
7868                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7869                                  (window-live-p (get-buffer-window
7870                                                  gnus-article-buffer t)))))
7871               (gnus-summary-select-article nil t)
7872               (setq treated nil)))
7873         (let ((gnus-inhibit-treatment t)
7874               (x-face-mule-delete-x-face-field 'never))
7875           (setq treated (eq 'old (gnus-summary-select-article)))
7876           (when (and treated
7877                      (not
7878                       (and (gnus-buffer-live-p gnus-article-buffer)
7879                            (window-live-p (get-buffer-window
7880                                            gnus-article-buffer t))
7881                            (or (not (string-match "^\\^X-Face:" regexp))
7882                                (with-current-buffer gnus-article-buffer
7883                                  gnus-summary-search-article-matched-data)))))
7884             (gnus-summary-select-article nil t)
7885             (setq treated nil))))
7886       (set-buffer gnus-article-buffer)
7887       (widen)
7888       (if treated
7889           (progn
7890             (gnus-article-show-all-headers)
7891             (gnus-summary-search-article-position-point regexp backward))
7892         (goto-char (if backward (point-max) (point-min))))
7893       (while (not found)
7894         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7895         (if (if backward
7896                 (re-search-backward regexp nil t)
7897               (re-search-forward regexp nil t))
7898             ;; We found the regexp.
7899             (progn
7900               (gnus-summary-search-article-highlight-matched-text
7901                backward treated (string-match "^\\^X-Face:" regexp))
7902               (setq found 'found)
7903               (forward-line
7904                (/ (- 2 (window-height
7905                         (get-buffer-window gnus-article-buffer t)))
7906                   2))
7907               (set-window-start
7908                (get-buffer-window (current-buffer))
7909                (point))
7910               (set-buffer sum)
7911               (setq point (point)))
7912           ;; We didn't find it, so we go to the next article.
7913           (set-buffer sum)
7914           (setq found 'not)
7915           (while (eq found 'not)
7916             (if (not (if backward (gnus-summary-find-prev)
7917                        (gnus-summary-find-next)))
7918                 ;; No more articles.
7919                 (setq found t)
7920               ;; Select the next article and adjust point.
7921               (unless (gnus-summary-article-sparse-p
7922                        (gnus-summary-article-number))
7923                 (setq found nil)
7924                 (let ((gnus-inhibit-treatment t))
7925                   (gnus-summary-select-article))
7926                 (setq treated nil)
7927                 (set-buffer gnus-article-buffer)
7928                 (widen)
7929                 (goto-char (if backward (point-max) (point-min))))))))
7930       (gnus-message 7 ""))
7931     ;; Return whether we found the regexp.
7932     (when (eq found 'found)
7933       (goto-char point)
7934       (gnus-summary-show-thread)
7935       (gnus-summary-goto-subject gnus-current-article)
7936       (gnus-summary-position-point)
7937       t)))
7938
7939 (defun gnus-find-matching-articles (header regexp)
7940   "Return a list of all articles that match REGEXP on HEADER.
7941 This search includes all articles in the current group that Gnus has
7942 fetched headers for, whether they are displayed or not."
7943   (let ((articles nil)
7944         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7945         (case-fold-search t))
7946     (dolist (header gnus-newsgroup-headers)
7947       (when (string-match regexp (funcall func header))
7948         (push (mail-header-number header) articles)))
7949     (nreverse articles)))
7950
7951 (defun gnus-summary-find-matching (header regexp &optional backward unread
7952                                           not-case-fold not-matching)
7953   "Return a list of all articles that match REGEXP on HEADER.
7954 The search stars on the current article and goes forwards unless
7955 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7956 If UNREAD is non-nil, only unread articles will
7957 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7958 in the comparisons. If NOT-MATCHING, return a list of all articles that
7959 not match REGEXP on HEADER."
7960   (let ((case-fold-search (not not-case-fold))
7961         articles d func)
7962     (if (consp header)
7963         (if (eq (car header) 'extra)
7964             (setq func
7965                   `(lambda (h)
7966                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7967                          "")))
7968           (error "%s is an invalid header" header))
7969       (unless (fboundp (intern (concat "mail-header-" header)))
7970         (error "%s is not a valid header" header))
7971       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7972     (dolist (d (if (eq backward 'all)
7973                    gnus-newsgroup-data
7974                  (gnus-data-find-list
7975                   (gnus-summary-article-number)
7976                   (gnus-data-list backward))))
7977       (when (and (or (not unread)       ; We want all articles...
7978                      (gnus-data-unread-p d)) ; Or just unreads.
7979                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7980                  (if not-matching
7981                      (not (string-match
7982                            regexp
7983                            (funcall func (gnus-data-header d))))
7984                    (string-match regexp
7985                                  (funcall func (gnus-data-header d)))))
7986         (push (gnus-data-number d) articles))) ; Success!
7987     (nreverse articles)))
7988
7989 (defun gnus-summary-execute-command (header regexp command &optional backward)
7990   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7991 If HEADER is an empty string (or nil), the match is done on the entire
7992 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7993   (interactive
7994    (list (let ((completion-ignore-case t))
7995            (completing-read
7996             "Header name: "
7997             (mapcar (lambda (header) (list (format "%s" header)))
7998                     (append
7999                      '("Number" "Subject" "From" "Lines" "Date"
8000                        "Message-ID" "Xref" "References" "Body")
8001                      gnus-extra-headers))
8002             nil 'require-match))
8003          (read-string "Regexp: ")
8004          (read-key-sequence "Command: ")
8005          current-prefix-arg))
8006   (when (equal header "Body")
8007     (setq header ""))
8008   ;; Hidden thread subtrees must be searched as well.
8009   (gnus-summary-show-all-threads)
8010   ;; We don't want to change current point nor window configuration.
8011   (save-excursion
8012     (save-window-excursion
8013       (gnus-message 6 "Executing %s..." (key-description command))
8014       ;; We'd like to execute COMMAND interactively so as to give arguments.
8015       (gnus-execute header regexp
8016                     `(call-interactively ',(key-binding command))
8017                     backward)
8018       (gnus-message 6 "Executing %s...done" (key-description command)))))
8019
8020 (defun gnus-summary-beginning-of-article ()
8021   "Scroll the article back to the beginning."
8022   (interactive)
8023   (gnus-summary-select-article)
8024   (gnus-configure-windows 'article)
8025   (gnus-eval-in-buffer-window gnus-article-buffer
8026     (widen)
8027     (goto-char (point-min))
8028     (when gnus-page-broken
8029       (gnus-narrow-to-page))))
8030
8031 (defun gnus-summary-end-of-article ()
8032   "Scroll to the end of the article."
8033   (interactive)
8034   (gnus-summary-select-article)
8035   (gnus-configure-windows 'article)
8036   (gnus-eval-in-buffer-window gnus-article-buffer
8037     (widen)
8038     (goto-char (point-max))
8039     (recenter -3)
8040     (when gnus-page-broken
8041       (gnus-narrow-to-page))))
8042
8043 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8044   "Truncate to LEN and quote all \"(\"'s in STRING."
8045   (gnus-replace-in-string (if (and len (> (length string) len))
8046                               (substring string 0 len)
8047                             string)
8048                           "[()]" "\\\\\\&"))
8049
8050 (defun gnus-summary-print-article (&optional filename n)
8051   "Generate and print a PostScript image of the N next (mail) articles.
8052
8053 If N is negative, print the N previous articles.  If N is nil and articles
8054 have been marked with the process mark, print these instead.
8055
8056 If the optional first argument FILENAME is nil, send the image to the
8057 printer.  If FILENAME is a string, save the PostScript image in a file with
8058 that name.  If FILENAME is a number, prompt the user for the name of the file
8059 to save in."
8060   (interactive (list (ps-print-preprint current-prefix-arg)))
8061   (dolist (article (gnus-summary-work-articles n))
8062     (gnus-summary-select-article nil nil 'pseudo article)
8063     (gnus-eval-in-buffer-window gnus-article-buffer
8064       (gnus-print-buffer))
8065     (gnus-summary-remove-process-mark article))
8066   (ps-despool filename))
8067
8068 (defun gnus-print-buffer ()
8069   (let ((buffer (generate-new-buffer " *print*")))
8070     (unwind-protect
8071         (progn
8072           (copy-to-buffer buffer (point-min) (point-max))
8073           (set-buffer buffer)
8074           (gnus-article-delete-invisible-text)
8075           (when (gnus-visual-p 'article-highlight 'highlight)
8076             ;; Copy-to-buffer doesn't copy overlay.  So redo
8077             ;; highlight.
8078             (let ((gnus-article-buffer buffer))
8079               (gnus-article-highlight-citation t)
8080               (gnus-article-highlight-signature)))
8081           (let ((ps-left-header
8082                  (list
8083                   (concat "("
8084                           (gnus-summary-print-truncate-and-quote
8085                            (mail-header-subject gnus-current-headers)
8086                            66) ")")
8087                   (concat "("
8088                           (gnus-summary-print-truncate-and-quote
8089                            (mail-header-from gnus-current-headers)
8090                            45) ")")))
8091                 (ps-right-header
8092                  (list
8093                   "/pagenumberstring load"
8094                   (concat "("
8095                           (mail-header-date gnus-current-headers) ")"))))
8096             (gnus-run-hooks 'gnus-ps-print-hook)
8097             (save-excursion
8098               (if window-system
8099                   (ps-spool-buffer-with-faces)
8100                 (ps-spool-buffer)))))
8101       (kill-buffer buffer))))
8102
8103 (defun gnus-summary-show-article (&optional arg)
8104   "Force redisplaying of the current article.
8105 If ARG (the prefix) is a number, show the article with the charset
8106 defined in `gnus-summary-show-article-charset-alist', or the charset
8107 input.
8108 If ARG (the prefix) is non-nil and not a number, show the raw article
8109 without any article massaging functions being run.  Normally, the key strokes
8110 are `C-u g'."
8111   (interactive "P")
8112   (cond
8113    ((numberp arg)
8114     (gnus-summary-show-article t)
8115     (let ((gnus-newsgroup-charset
8116            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8117                (mm-read-coding-system
8118                 "View as charset: "
8119                 (save-excursion
8120                   (set-buffer gnus-article-buffer)
8121                   (let ((coding-systems
8122                          (detect-coding-region (point) (point-max))))
8123                     (or (car-safe coding-systems)
8124                         coding-systems))))))
8125           (gnus-newsgroup-ignored-charsets 'gnus-all))
8126       (gnus-summary-select-article nil 'force)
8127       (let ((deps gnus-newsgroup-dependencies)
8128             head header lines)
8129         (save-excursion
8130           (set-buffer gnus-original-article-buffer)
8131           (save-restriction
8132             (message-narrow-to-head)
8133             (setq head (buffer-string))
8134             (goto-char (point-min))
8135             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8136               (goto-char (point-max))
8137               (widen)
8138               (setq lines (1- (count-lines (point) (point-max))))))
8139           (with-temp-buffer
8140             (insert (format "211 %d Article retrieved.\n"
8141                             (cdr gnus-article-current)))
8142             (insert head)
8143             (if lines (insert (format "Lines: %d\n" lines)))
8144             (insert ".\n")
8145             (let ((nntp-server-buffer (current-buffer)))
8146               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8147         (gnus-data-set-header
8148          (gnus-data-find (cdr gnus-article-current))
8149          header)
8150         (gnus-summary-update-article-line
8151          (cdr gnus-article-current) header)
8152         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8153           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8154    ((not arg)
8155     ;; Select the article the normal way.
8156     (gnus-summary-select-article nil 'force))
8157    (t
8158     ;; We have to require this here to make sure that the following
8159     ;; dynamic binding isn't shadowed by autoloading.
8160     (require 'gnus-async)
8161     (require 'gnus-art)
8162     ;; Bind the article treatment functions to nil.
8163     (let ((gnus-have-all-headers t)
8164           gnus-article-prepare-hook
8165           gnus-article-decode-hook
8166           gnus-break-pages
8167           gnus-show-mime
8168           (gnus-inhibit-treatment t))
8169       (gnus-summary-select-article nil 'force))))
8170   (gnus-summary-goto-subject gnus-current-article)
8171   (gnus-summary-position-point))
8172
8173 (defun gnus-summary-show-raw-article ()
8174   "Show the raw article without any article massaging functions being run."
8175   (interactive)
8176   (gnus-summary-show-article t))
8177
8178 (defun gnus-summary-verbose-headers (&optional arg)
8179   "Toggle permanent full header display.
8180 If ARG is a positive number, turn header display on.
8181 If ARG is a negative number, turn header display off."
8182   (interactive "P")
8183   (setq gnus-show-all-headers
8184         (cond ((or (not (numberp arg))
8185                    (zerop arg))
8186                (not gnus-show-all-headers))
8187               ((natnump arg)
8188                t)))
8189   (gnus-summary-show-article))
8190
8191 (defun gnus-summary-toggle-header (&optional arg)
8192   "Show the headers if they are hidden, or hide them if they are shown.
8193 If ARG is a positive number, show the entire header.
8194 If ARG is a negative number, hide the unwanted header lines."
8195   (interactive "P")
8196   (save-excursion
8197     (set-buffer gnus-article-buffer)
8198     (save-restriction
8199       (let* ((buffer-read-only nil)
8200              (inhibit-point-motion-hooks t)
8201              hidden e)
8202         (setq hidden
8203               (if (numberp arg)
8204                   (>= arg 0)
8205                 (save-restriction
8206                   (article-narrow-to-head)
8207                   (gnus-article-hidden-text-p 'headers))))
8208         (goto-char (point-min))
8209         (when (search-forward "\n\n" nil t)
8210           (delete-region (point-min) (1- (point))))
8211         (goto-char (point-min))
8212         (save-excursion
8213           (set-buffer gnus-original-article-buffer)
8214           (goto-char (point-min))
8215           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8216         (insert-buffer-substring gnus-original-article-buffer 1 e)
8217         (save-restriction
8218           (narrow-to-region (point-min) (point))
8219           (article-decode-encoded-words)
8220           (if  hidden
8221               (let ((gnus-treat-hide-headers nil)
8222                     (gnus-treat-hide-boring-headers nil))
8223                 (gnus-delete-wash-type 'headers)
8224                 (gnus-treat-article 'head))
8225             (gnus-treat-article 'head)))
8226         (gnus-set-mode-line 'article)))))
8227
8228 (defun gnus-summary-show-all-headers ()
8229   "Make all header lines visible."
8230   (interactive)
8231   (gnus-summary-toggle-header 1))
8232
8233 (defun gnus-summary-toggle-mime (&optional arg)
8234   "Toggle MIME processing.
8235 If ARG is a positive number, turn MIME processing on."
8236   (interactive "P")
8237   (setq gnus-show-mime
8238         (if (null arg)
8239             (not gnus-show-mime)
8240           (> (prefix-numeric-value arg) 0)))
8241   (gnus-summary-select-article t 'force))
8242
8243 (defun gnus-summary-caesar-message (&optional arg)
8244   "Caesar rotate the current article by 13.
8245 The numerical prefix specifies how many places to rotate each letter
8246 forward."
8247   (interactive "P")
8248   (gnus-summary-select-article)
8249   (let ((mail-header-separator ""))
8250     (gnus-eval-in-buffer-window gnus-article-buffer
8251       (save-restriction
8252         (widen)
8253         (let ((start (window-start))
8254               buffer-read-only)
8255           (message-caesar-buffer-body arg)
8256           (set-window-start (get-buffer-window (current-buffer)) start))))))
8257
8258 (defun gnus-summary-stop-page-breaking ()
8259   "Stop page breaking in the current article."
8260   (interactive)
8261   (gnus-summary-select-article)
8262   (gnus-eval-in-buffer-window gnus-article-buffer
8263     (widen)
8264     (when (gnus-visual-p 'page-marker)
8265       (let ((buffer-read-only nil))
8266         (gnus-remove-text-with-property 'gnus-prev)
8267         (gnus-remove-text-with-property 'gnus-next))
8268       (setq gnus-page-broken nil))))
8269
8270 (defun gnus-summary-move-article (&optional n to-newsgroup
8271                                             select-method action)
8272   "Move the current article to a different newsgroup.
8273 If N is a positive number, move the N next articles.
8274 If N is a negative number, move the N previous articles.
8275 If N is nil and any articles have been marked with the process mark,
8276 move those articles instead.
8277 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8278 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8279 re-spool using this method.
8280
8281 For this function to work, both the current newsgroup and the
8282 newsgroup that you want to move to have to support the `request-move'
8283 and `request-accept' functions.
8284
8285 ACTION can be either `move' (the default), `crosspost' or `copy'."
8286   (interactive "P")
8287   (unless action
8288     (setq action 'move))
8289   ;; Check whether the source group supports the required functions.
8290   (cond ((and (eq action 'move)
8291               (not (gnus-check-backend-function
8292                     'request-move-article gnus-newsgroup-name)))
8293          (error "The current group does not support article moving"))
8294         ((and (eq action 'crosspost)
8295               (not (gnus-check-backend-function
8296                     'request-replace-article gnus-newsgroup-name)))
8297          (error "The current group does not support article editing")))
8298   (let ((articles (gnus-summary-work-articles n))
8299         (prefix (if (gnus-check-backend-function
8300                      'request-move-article gnus-newsgroup-name)
8301                     (gnus-group-real-prefix gnus-newsgroup-name)
8302                   ""))
8303         (names '((move "Move" "Moving")
8304                  (copy "Copy" "Copying")
8305                  (crosspost "Crosspost" "Crossposting")))
8306         (copy-buf (save-excursion
8307                     (nnheader-set-temp-buffer " *copy article*")))
8308         (default-marks gnus-article-mark-lists)
8309         (no-expire-marks (delete '(expirable . expire)
8310                                  (copy-sequence gnus-article-mark-lists)))
8311         art-group to-method new-xref article to-groups)
8312     (unless (assq action names)
8313       (error "Unknown action %s" action))
8314     ;; We have to select an article to give
8315     ;; `gnus-read-move-group-name' an opportunity to suggest an
8316     ;; appropriate default.
8317     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8318       (gnus-summary-select-article nil nil nil (car articles)))
8319     ;; Read the newsgroup name.
8320     (when (and (not to-newsgroup)
8321                (not select-method))
8322       (setq to-newsgroup
8323             (gnus-read-move-group-name
8324              (cadr (assq action names))
8325              (symbol-value (intern (format "gnus-current-%s-group" action)))
8326              articles prefix))
8327       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8328     (setq to-method (or select-method
8329                         (gnus-server-to-method
8330                          (gnus-group-method to-newsgroup))))
8331     ;; Check the method we are to move this article to...
8332     (unless (gnus-check-backend-function
8333              'request-accept-article (car to-method))
8334       (error "%s does not support article copying" (car to-method)))
8335     (unless (gnus-check-server to-method)
8336       (error "Can't open server %s" (car to-method)))
8337     (gnus-message 6 "%s to %s: %s..."
8338                   (caddr (assq action names))
8339                   (or (car select-method) to-newsgroup) articles)
8340     (while articles
8341       (setq article (pop articles))
8342       (setq
8343        art-group
8344        (cond
8345         ;; Move the article.
8346         ((eq action 'move)
8347          ;; Remove this article from future suppression.
8348          (gnus-dup-unsuppress-article article)
8349          (gnus-request-move-article
8350           article                       ; Article to move
8351           gnus-newsgroup-name           ; From newsgroup
8352           (nth 1 (gnus-find-method-for-group
8353                   gnus-newsgroup-name)) ; Server
8354           (list 'gnus-request-accept-article
8355                 to-newsgroup (list 'quote select-method)
8356                 (not articles) t)       ; Accept form
8357           (not articles)))              ; Only save nov last time
8358         ;; Copy the article.
8359         ((eq action 'copy)
8360          (save-excursion
8361            (set-buffer copy-buf)
8362            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8363              (gnus-request-accept-article
8364               to-newsgroup select-method (not articles) t))))
8365         ;; Crosspost the article.
8366         ((eq action 'crosspost)
8367          (let ((xref (message-tokenize-header
8368                       (mail-header-xref (gnus-summary-article-header article))
8369                       " ")))
8370            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8371                                   ":" (number-to-string article)))
8372            (unless xref
8373              (setq xref (list (system-name))))
8374            (setq new-xref
8375                  (concat
8376                   (mapconcat 'identity
8377                              (delete "Xref:" (delete new-xref xref))
8378                              " ")
8379                   " " new-xref))
8380            (save-excursion
8381              (set-buffer copy-buf)
8382              ;; First put the article in the destination group.
8383              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8384              (when (consp (setq art-group
8385                                 (gnus-request-accept-article
8386                                  to-newsgroup select-method (not articles))))
8387                (setq new-xref (concat new-xref " " (car art-group)
8388                                       ":"
8389                                       (number-to-string (cdr art-group))))
8390                ;; Now we have the new Xrefs header, so we insert
8391                ;; it and replace the new article.
8392                (nnheader-replace-header "Xref" new-xref)
8393                (gnus-request-replace-article
8394                 (cdr art-group) to-newsgroup (current-buffer))
8395                art-group))))))
8396       (cond
8397        ((not art-group)
8398         (gnus-message 1 "Couldn't %s article %s: %s"
8399                       (cadr (assq action names)) article
8400                       (nnheader-get-report (car to-method))))
8401        ((eq art-group 'junk)
8402         (when (eq action 'move)
8403           (gnus-summary-mark-article article gnus-canceled-mark)
8404           (gnus-message 4 "Deleted article %s" article)))
8405        (t
8406         (let* ((pto-group (gnus-group-prefixed-name
8407                            (car art-group) to-method))
8408                (entry
8409                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8410                (info (nth 2 entry))
8411                (to-group (gnus-info-group info))
8412                to-marks)
8413           ;; Update the group that has been moved to.
8414           (when (and info
8415                      (memq action '(move copy)))
8416             (unless (member to-group to-groups)
8417               (push to-group to-groups))
8418
8419             (unless (memq article gnus-newsgroup-unreads)
8420               (push 'read to-marks)
8421               (gnus-info-set-read
8422                info (gnus-add-to-range (gnus-info-read info)
8423                                        (list (cdr art-group)))))
8424
8425             ;; See whether the article is to be put in the cache.
8426             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8427                              default-marks
8428                            no-expire-marks))
8429                   (to-article (cdr art-group)))
8430
8431               ;; Enter the article into the cache in the new group,
8432               ;; if that is required.
8433               (when gnus-use-cache
8434                 (gnus-cache-possibly-enter-article
8435                  to-group to-article
8436                  (let ((header (copy-sequence
8437                                 (gnus-summary-article-header article))))
8438                    (mail-header-set-number header to-article)
8439                    header)
8440                  (memq article gnus-newsgroup-marked)
8441                  (memq article gnus-newsgroup-dormant)
8442                  (memq article gnus-newsgroup-unreads)))
8443
8444               (when gnus-preserve-marks
8445                 ;; Copy any marks over to the new group.
8446                 (when (and (equal to-group gnus-newsgroup-name)
8447                            (not (memq article gnus-newsgroup-unreads)))
8448                   ;; Mark this article as read in this group.
8449                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8450                   (setcdr (gnus-active to-group) to-article)
8451                   (setcdr gnus-newsgroup-active to-article))
8452
8453                 (while marks
8454                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8455                     (when (memq article (symbol-value
8456                                          (intern (format "gnus-newsgroup-%s"
8457                                                          (caar marks)))))
8458                       (push (cdar marks) to-marks)
8459                       ;; If the other group is the same as this group,
8460                       ;; then we have to add the mark to the list.
8461                       (when (equal to-group gnus-newsgroup-name)
8462                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8463                              (cons to-article
8464                                    (symbol-value
8465                                     (intern (format "gnus-newsgroup-%s"
8466                                                     (caar marks)))))))
8467                       ;; Copy the marks to other group.
8468                       (gnus-add-marked-articles
8469                        to-group (cdar marks) (list to-article) info)))
8470                   (setq marks (cdr marks)))
8471
8472                 (gnus-request-set-mark to-group (list (list (list to-article)
8473                                                             'add
8474                                                             to-marks))))
8475
8476               (gnus-dribble-enter
8477                (concat "(gnus-group-set-info '"
8478                        (gnus-prin1-to-string (gnus-get-info to-group))
8479                        ")"))))
8480
8481           ;; Update the Xref header in this article to point to
8482           ;; the new crossposted article we have just created.
8483           (when (eq action 'crosspost)
8484             (save-excursion
8485               (set-buffer copy-buf)
8486               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8487               (nnheader-replace-header "Xref" new-xref)
8488               (gnus-request-replace-article
8489                article gnus-newsgroup-name (current-buffer)))))
8490
8491         ;;;!!!Why is this necessary?
8492         (set-buffer gnus-summary-buffer)
8493
8494         (gnus-summary-goto-subject article)
8495         (when (eq action 'move)
8496           (gnus-summary-mark-article article gnus-canceled-mark))))
8497       (gnus-summary-remove-process-mark article))
8498     ;; Re-activate all groups that have been moved to.
8499     (save-excursion
8500       (set-buffer gnus-group-buffer)
8501       (let ((gnus-group-marked to-groups))
8502         (gnus-group-get-new-news-this-group nil t)))
8503
8504     (gnus-kill-buffer copy-buf)
8505     (gnus-summary-position-point)
8506     (gnus-set-mode-line 'summary)))
8507
8508 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8509   "Move the current article to a different newsgroup.
8510 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8511 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8512 re-spool using this method."
8513   (interactive "P")
8514   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8515
8516 (defun gnus-summary-crosspost-article (&optional n)
8517   "Crosspost the current article to some other group."
8518   (interactive "P")
8519   (gnus-summary-move-article n nil nil 'crosspost))
8520
8521 (defcustom gnus-summary-respool-default-method nil
8522   "Default method type for respooling an article.
8523 If nil, use to the current newsgroup method."
8524   :type 'symbol
8525   :group 'gnus-summary-mail)
8526
8527 (defun gnus-summary-respool-article (&optional n method)
8528   "Respool the current article.
8529 The article will be squeezed through the mail spooling process again,
8530 which means that it will be put in some mail newsgroup or other
8531 depending on `nnmail-split-methods'.
8532 If N is a positive number, respool the N next articles.
8533 If N is a negative number, respool the N previous articles.
8534 If N is nil and any articles have been marked with the process mark,
8535 respool those articles instead.
8536
8537 Respooling can be done both from mail groups and \"real\" newsgroups.
8538 In the former case, the articles in question will be moved from the
8539 current group into whatever groups they are destined to.  In the
8540 latter case, they will be copied into the relevant groups."
8541   (interactive
8542    (list current-prefix-arg
8543          (let* ((methods (gnus-methods-using 'respool))
8544                 (methname
8545                  (symbol-name (or gnus-summary-respool-default-method
8546                                   (car (gnus-find-method-for-group
8547                                         gnus-newsgroup-name)))))
8548                 (method
8549                  (gnus-completing-read
8550                   methname "What backend do you want to use when respooling?"
8551                   methods nil t nil 'gnus-mail-method-history))
8552                 ms)
8553            (cond
8554             ((zerop (length (setq ms (gnus-servers-using-backend
8555                                       (intern method)))))
8556              (list (intern method) ""))
8557             ((= 1 (length ms))
8558              (car ms))
8559             (t
8560              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8561                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8562                            ms-alist))))))))
8563   (unless method
8564     (error "No method given for respooling"))
8565   (if (assoc (symbol-name
8566               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8567              (gnus-methods-using 'respool))
8568       (gnus-summary-move-article n nil method)
8569     (gnus-summary-copy-article n nil method)))
8570
8571 (defun gnus-summary-import-article (file &optional edit)
8572   "Import an arbitrary file into a mail newsgroup."
8573   (interactive "fImport file: \nP")
8574   (let ((group gnus-newsgroup-name)
8575         (now (current-time))
8576         atts lines group-art)
8577     (unless (gnus-check-backend-function 'request-accept-article group)
8578       (error "%s does not support article importing" group))
8579     (or (file-readable-p file)
8580         (not (file-regular-p file))
8581         (error "Can't read %s" file))
8582     (save-excursion
8583       (set-buffer (gnus-get-buffer-create " *import file*"))
8584       (erase-buffer)
8585       (nnheader-insert-file-contents file)
8586       (goto-char (point-min))
8587       (if (nnheader-article-p)
8588           (save-restriction
8589             (goto-char (point-min))
8590             (search-forward "\n\n" nil t)
8591             (narrow-to-region (point-min) (1- (point)))
8592             (goto-char (point-min))
8593             (unless (re-search-forward "^date:" nil t)
8594               (goto-char (point-max))
8595               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8596         ;; This doesn't look like an article, so we fudge some headers.
8597         (setq atts (file-attributes file)
8598               lines (count-lines (point-min) (point-max)))
8599         (insert "From: " (read-string "From: ") "\n"
8600                 "Subject: " (read-string "Subject: ") "\n"
8601                 "Date: " (message-make-date (nth 5 atts)) "\n"
8602                 "Message-ID: " (message-make-message-id) "\n"
8603                 "Lines: " (int-to-string lines) "\n"
8604                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8605       (setq group-art (gnus-request-accept-article group nil t))
8606       (kill-buffer (current-buffer)))
8607     (setq gnus-newsgroup-active (gnus-activate-group group))
8608     (forward-line 1)
8609     (gnus-summary-goto-article (cdr group-art) nil t)
8610     (when edit
8611       (gnus-summary-edit-article))))
8612
8613 (defun gnus-summary-create-article ()
8614   "Create an article in a mail newsgroup."
8615   (interactive)
8616   (let ((group gnus-newsgroup-name)
8617         (now (current-time))
8618         group-art)
8619     (unless (gnus-check-backend-function 'request-accept-article group)
8620       (error "%s does not support article importing" group))
8621     (save-excursion
8622       (set-buffer (gnus-get-buffer-create " *import file*"))
8623       (erase-buffer)
8624       (goto-char (point-min))
8625       ;; This doesn't look like an article, so we fudge some headers.
8626       (insert "From: " (read-string "From: ") "\n"
8627               "Subject: " (read-string "Subject: ") "\n"
8628               "Date: " (message-make-date now) "\n"
8629               "Message-ID: " (message-make-message-id) "\n")
8630       (setq group-art (gnus-request-accept-article group nil t))
8631       (kill-buffer (current-buffer)))
8632     (setq gnus-newsgroup-active (gnus-activate-group group))
8633     (forward-line 1)
8634     (gnus-summary-goto-article (cdr group-art) nil t)
8635     (gnus-summary-edit-article)))
8636
8637 (defun gnus-summary-article-posted-p ()
8638   "Say whether the current (mail) article is available from news as well.
8639 This will be the case if the article has both been mailed and posted."
8640   (interactive)
8641   (let ((id (mail-header-references (gnus-summary-article-header)))
8642         (gnus-override-method (car (gnus-refer-article-methods))))
8643     (if (gnus-request-head id "")
8644         (gnus-message 2 "The current message was found on %s"
8645                       gnus-override-method)
8646       (gnus-message 2 "The current message couldn't be found on %s"
8647                     gnus-override-method)
8648       nil)))
8649
8650 (defun gnus-summary-expire-articles (&optional now)
8651   "Expire all articles that are marked as expirable in the current group."
8652   (interactive)
8653   (when (gnus-check-backend-function
8654          'request-expire-articles gnus-newsgroup-name)
8655     ;; This backend supports expiry.
8656     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8657            (expirable (if total
8658                           (progn
8659                             ;; We need to update the info for
8660                             ;; this group for `gnus-list-of-read-articles'
8661                             ;; to give us the right answer.
8662                             (gnus-run-hooks 'gnus-exit-group-hook)
8663                             (gnus-summary-update-info)
8664                             (gnus-list-of-read-articles gnus-newsgroup-name))
8665                         (setq gnus-newsgroup-expirable
8666                               (sort gnus-newsgroup-expirable '<))))
8667            (expiry-wait (if now 'immediate
8668                           (gnus-group-find-parameter
8669                            gnus-newsgroup-name 'expiry-wait)))
8670            (nnmail-expiry-target
8671             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8672                 nnmail-expiry-target))
8673            es)
8674       (when expirable
8675         ;; There are expirable articles in this group, so we run them
8676         ;; through the expiry process.
8677         (gnus-message 6 "Expiring articles...")
8678         (unless (gnus-check-group gnus-newsgroup-name)
8679           (error "Can't open server for %s" gnus-newsgroup-name))
8680         ;; The list of articles that weren't expired is returned.
8681         (save-excursion
8682           (if expiry-wait
8683               (let ((nnmail-expiry-wait-function nil)
8684                     (nnmail-expiry-wait expiry-wait))
8685                 (setq es (gnus-request-expire-articles
8686                           expirable gnus-newsgroup-name)))
8687             (setq es (gnus-request-expire-articles
8688                       expirable gnus-newsgroup-name)))
8689           (unless total
8690             (setq gnus-newsgroup-expirable es))
8691           ;; We go through the old list of expirable, and mark all
8692           ;; really expired articles as nonexistent.
8693           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8694             (let ((gnus-use-cache nil))
8695               (while expirable
8696                 (unless (memq (car expirable) es)
8697                   (when (gnus-data-find (car expirable))
8698                     (gnus-summary-mark-article
8699                      (car expirable) gnus-canceled-mark)))
8700                 (setq expirable (cdr expirable))))))
8701         (gnus-message 6 "Expiring articles...done")))))
8702
8703 (defun gnus-summary-expire-articles-now ()
8704   "Expunge all expirable articles in the current group.
8705 This means that *all* articles that are marked as expirable will be
8706 deleted forever, right now."
8707   (interactive)
8708   (or gnus-expert-user
8709       (gnus-yes-or-no-p
8710        "Are you really, really, really sure you want to delete all these messages? ")
8711       (error "Phew!"))
8712   (gnus-summary-expire-articles t))
8713
8714 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8715 (defun gnus-summary-delete-article (&optional n)
8716   "Delete the N next (mail) articles.
8717 This command actually deletes articles.  This is not a marking
8718 command.  The article will disappear forever from your life, never to
8719 return.
8720 If N is negative, delete backwards.
8721 If N is nil and articles have been marked with the process mark,
8722 delete these instead."
8723   (interactive "P")
8724   (unless (gnus-check-backend-function 'request-expire-articles
8725                                        gnus-newsgroup-name)
8726     (error "The current newsgroup does not support article deletion"))
8727   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8728     (error "Couldn't open server"))
8729   ;; Compute the list of articles to delete.
8730   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8731         not-deleted)
8732     (if (and gnus-novice-user
8733              (not (gnus-yes-or-no-p
8734                    (format "Do you really want to delete %s forever? "
8735                            (if (> (length articles) 1)
8736                                (format "these %s articles" (length articles))
8737                              "this article")))))
8738         ()
8739       ;; Delete the articles.
8740       (setq not-deleted (gnus-request-expire-articles
8741                          articles gnus-newsgroup-name 'force))
8742       (while articles
8743         (gnus-summary-remove-process-mark (car articles))
8744         ;; The backend might not have been able to delete the article
8745         ;; after all.
8746         (unless (memq (car articles) not-deleted)
8747           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8748         (setq articles (cdr articles)))
8749       (when not-deleted
8750         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8751     (gnus-summary-position-point)
8752     (gnus-set-mode-line 'summary)
8753     not-deleted))
8754
8755 (defun gnus-summary-edit-article (&optional force)
8756   "Edit the current article.
8757 This will have permanent effect only in mail groups.
8758 If FORCE is non-nil, allow editing of articles even in read-only
8759 groups."
8760   (interactive "P")
8761   (save-excursion
8762     (set-buffer gnus-summary-buffer)
8763     (let ((mail-parse-charset gnus-newsgroup-charset)
8764           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8765       (gnus-set-global-variables)
8766       (when (and (not force)
8767                  (gnus-group-read-only-p))
8768         (error "The current newsgroup does not support article editing"))
8769       (gnus-summary-show-article t)
8770       (gnus-article-edit-article
8771        'ignore
8772        `(lambda (no-highlight)
8773           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8774                 (message-options message-options)
8775                 (message-options-set-recipient)
8776                 (mail-parse-ignored-charsets
8777                  ',gnus-newsgroup-ignored-charsets))
8778             (gnus-summary-edit-article-done
8779              ,(or (mail-header-references gnus-current-headers) "")
8780              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8781
8782 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8783
8784 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8785                                                  no-highlight)
8786   "Make edits to the current article permanent."
8787   (interactive)
8788   (save-excursion
8789     ;; The buffer restriction contains the entire article if it exists.
8790     (when (article-goto-body)
8791       (let ((lines (count-lines (point) (point-max)))
8792             (length (- (point-max) (point)))
8793             (case-fold-search t)
8794             (body (copy-marker (point))))
8795         (goto-char (point-min))
8796         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8797           (delete-region (match-beginning 1) (match-end 1))
8798           (insert (number-to-string length)))
8799         (goto-char (point-min))
8800         (when (re-search-forward
8801                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8802           (delete-region (match-beginning 1) (match-end 1))
8803           (insert (number-to-string length)))
8804         (goto-char (point-min))
8805         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8806           (delete-region (match-beginning 1) (match-end 1))
8807           (insert (number-to-string lines))))))
8808   ;; Replace the article.
8809   (let ((buf (current-buffer)))
8810     (with-temp-buffer
8811       (insert-buffer-substring buf)
8812
8813       (if (and (not read-only)
8814                (not (gnus-request-replace-article
8815                      (cdr gnus-article-current) (car gnus-article-current)
8816                      (current-buffer) t)))
8817           (error "Couldn't replace article")
8818         ;; Update the summary buffer.
8819         (if (and references
8820                  (equal (message-tokenize-header references " ")
8821                         (message-tokenize-header
8822                          (or (message-fetch-field "references") "") " ")))
8823             ;; We only have to update this line.
8824             (save-excursion
8825               (save-restriction
8826                 (message-narrow-to-head)
8827                 (let ((head (buffer-string))
8828                       header)
8829                   (with-temp-buffer
8830                     (insert (format "211 %d Article retrieved.\n"
8831                                     (cdr gnus-article-current)))
8832                     (insert head)
8833                     (insert ".\n")
8834                     (let ((nntp-server-buffer (current-buffer)))
8835                       (setq header (car (gnus-get-newsgroup-headers
8836                                          (save-excursion
8837                                            (set-buffer gnus-summary-buffer)
8838                                            gnus-newsgroup-dependencies)
8839                                          t))))
8840                     (save-excursion
8841                       (set-buffer gnus-summary-buffer)
8842                       (gnus-data-set-header
8843                        (gnus-data-find (cdr gnus-article-current))
8844                        header)
8845                       (gnus-summary-update-article-line
8846                        (cdr gnus-article-current) header)
8847                       (if (gnus-summary-goto-subject
8848                            (cdr gnus-article-current) nil t)
8849                           (gnus-summary-update-secondary-mark
8850                            (cdr gnus-article-current))))))))
8851           ;; Update threads.
8852           (set-buffer (or buffer gnus-summary-buffer))
8853           (gnus-summary-update-article (cdr gnus-article-current))
8854           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8855               (gnus-summary-update-secondary-mark
8856                (cdr gnus-article-current))))
8857         ;; Prettify the article buffer again.
8858         (unless no-highlight
8859           (save-excursion
8860             (set-buffer gnus-article-buffer)
8861             ;;;!!! Fix this -- article should be rehighlighted.
8862             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8863             (set-buffer gnus-original-article-buffer)
8864             (gnus-request-article
8865              (cdr gnus-article-current)
8866              (car gnus-article-current) (current-buffer))))
8867         ;; Prettify the summary buffer line.
8868         (when (gnus-visual-p 'summary-highlight 'highlight)
8869           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8870
8871 (defun gnus-summary-edit-wash (key)
8872   "Perform editing command KEY in the article buffer."
8873   (interactive
8874    (list
8875     (progn
8876       (message "%s" (concat (this-command-keys) "- "))
8877       (read-char))))
8878   (message "")
8879   (gnus-summary-edit-article)
8880   (execute-kbd-macro (concat (this-command-keys) key))
8881   (gnus-article-edit-done))
8882
8883 (defun gnus-summary-toggle-smiley (&optional arg)
8884   "Toggle the display of smilies as small graphical icons."
8885   (interactive "P")
8886   (save-excursion
8887     (set-buffer gnus-article-buffer)
8888     (gnus-article-smiley-display arg)))
8889
8890 ;;; Respooling
8891
8892 (defun gnus-summary-respool-query (&optional silent trace)
8893   "Query where the respool algorithm would put this article."
8894   (interactive)
8895   (let (gnus-mark-article-hook)
8896     (gnus-summary-select-article)
8897     (save-excursion
8898       (set-buffer gnus-original-article-buffer)
8899       (save-restriction
8900         (message-narrow-to-head)
8901         (let ((groups (nnmail-article-group 'identity trace)))
8902           (unless silent
8903             (if groups
8904                 (message "This message would go to %s"
8905                          (mapconcat 'car groups ", "))
8906               (message "This message would go to no groups"))
8907             groups))))))
8908
8909 (defun gnus-summary-respool-trace ()
8910   "Trace where the respool algorithm would put this article.
8911 Display a buffer showing all fancy splitting patterns which matched."
8912   (interactive)
8913   (gnus-summary-respool-query nil t))
8914
8915 ;; Summary marking commands.
8916
8917 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8918   "Mark articles which has the same subject as read, and then select the next.
8919 If UNMARK is positive, remove any kind of mark.
8920 If UNMARK is negative, tick articles."
8921   (interactive "P")
8922   (when unmark
8923     (setq unmark (prefix-numeric-value unmark)))
8924   (let ((count
8925          (gnus-summary-mark-same-subject
8926           (gnus-summary-article-subject) unmark)))
8927     ;; Select next unread article.  If auto-select-same mode, should
8928     ;; select the first unread article.
8929     (gnus-summary-next-article t (and gnus-auto-select-same
8930                                       (gnus-summary-article-subject)))
8931     (gnus-message 7 "%d article%s marked as %s"
8932                   count (if (= count 1) " is" "s are")
8933                   (if unmark "unread" "read"))))
8934
8935 (defun gnus-summary-kill-same-subject (&optional unmark)
8936   "Mark articles which has the same subject as read.
8937 If UNMARK is positive, remove any kind of mark.
8938 If UNMARK is negative, tick articles."
8939   (interactive "P")
8940   (when unmark
8941     (setq unmark (prefix-numeric-value unmark)))
8942   (let ((count
8943          (gnus-summary-mark-same-subject
8944           (gnus-summary-article-subject) unmark)))
8945     ;; If marked as read, go to next unread subject.
8946     (when (null unmark)
8947       ;; Go to next unread subject.
8948       (gnus-summary-next-subject 1 t))
8949     (gnus-message 7 "%d articles are marked as %s"
8950                   count (if unmark "unread" "read"))))
8951
8952 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8953   "Mark articles with same SUBJECT as read, and return marked number.
8954 If optional argument UNMARK is positive, remove any kinds of marks.
8955 If optional argument UNMARK is negative, mark articles as unread instead."
8956   (let ((count 1))
8957     (save-excursion
8958       (cond
8959        ((null unmark)                   ; Mark as read.
8960         (while (and
8961                 (progn
8962                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8963                   (gnus-summary-show-thread) t)
8964                 (gnus-summary-find-subject subject))
8965           (setq count (1+ count))))
8966        ((> unmark 0)                    ; Tick.
8967         (while (and
8968                 (progn
8969                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8970                   (gnus-summary-show-thread) t)
8971                 (gnus-summary-find-subject subject))
8972           (setq count (1+ count))))
8973        (t                               ; Mark as unread.
8974         (while (and
8975                 (progn
8976                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8977                   (gnus-summary-show-thread) t)
8978                 (gnus-summary-find-subject subject))
8979           (setq count (1+ count)))))
8980       (gnus-set-mode-line 'summary)
8981       ;; Return the number of marked articles.
8982       count)))
8983
8984 (defun gnus-summary-mark-as-processable (n &optional unmark)
8985   "Set the process mark on the next N articles.
8986 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8987 the process mark instead.  The difference between N and the actual
8988 number of articles marked is returned."
8989   (interactive "P")
8990   (if (and (null n) (gnus-region-active-p))
8991       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8992     (setq n (prefix-numeric-value n))
8993     (let ((backward (< n 0))
8994           (n (abs n)))
8995       (while (and
8996               (> n 0)
8997               (if unmark
8998                   (gnus-summary-remove-process-mark
8999                    (gnus-summary-article-number))
9000                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9001               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9002         (setq n (1- n)))
9003       (when (/= 0 n)
9004         (gnus-message 7 "No more articles"))
9005       (gnus-summary-recenter)
9006       (gnus-summary-position-point)
9007       n)))
9008
9009 (defun gnus-summary-unmark-as-processable (n)
9010   "Remove the process mark from the next N articles.
9011 If N is negative, unmark backward instead.  The difference between N and
9012 the actual number of articles unmarked is returned."
9013   (interactive "P")
9014   (gnus-summary-mark-as-processable n t))
9015
9016 (defun gnus-summary-unmark-all-processable ()
9017   "Remove the process mark from all articles."
9018   (interactive)
9019   (save-excursion
9020     (while gnus-newsgroup-processable
9021       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9022   (gnus-summary-position-point))
9023
9024 (defun gnus-summary-add-mark (article type)
9025   "Mark ARTICLE with a mark of TYPE."
9026   (let ((vtype (car (assq type gnus-article-mark-lists)))
9027         var)
9028     (if (not vtype)
9029         (error "No such mark type: %s" type)
9030       (setq var (intern (format "gnus-newsgroup-%s" type)))
9031       (set var (cons article (symbol-value var)))
9032       (if (memq type '(processable cached replied forwarded recent saved))
9033           (gnus-summary-update-secondary-mark article)
9034         ;;; !!! This is bogus.  We should find out what primary
9035         ;;; !!! mark we want to set.
9036         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9037
9038 (defun gnus-summary-mark-as-expirable (n)
9039   "Mark N articles forward as expirable.
9040 If N is negative, mark backward instead.  The difference between N and
9041 the actual number of articles marked is returned."
9042   (interactive "p")
9043   (gnus-summary-mark-forward n gnus-expirable-mark))
9044
9045 (defun gnus-summary-mark-article-as-replied (article)
9046   "Mark ARTICLE as replied to and update the summary line.
9047 ARTICLE can also be a list of articles."
9048   (interactive (list (gnus-summary-article-number)))
9049   (let ((articles (if (listp article) article (list article))))
9050     (dolist (article articles)
9051       (push article gnus-newsgroup-replied)
9052       (let ((buffer-read-only nil))
9053         (when (gnus-summary-goto-subject article nil t)
9054           (gnus-summary-update-secondary-mark article))))))
9055
9056 (defun gnus-summary-mark-article-as-forwarded (article)
9057   "Mark ARTICLE as forwarded and update the summary line.
9058 ARTICLE can also be a list of articles."
9059   (let ((articles (if (listp article) article (list article))))
9060     (dolist (article articles)
9061       (push article gnus-newsgroup-forwarded)
9062       (let ((buffer-read-only nil))
9063         (when (gnus-summary-goto-subject article nil t)
9064           (gnus-summary-update-secondary-mark article))))))
9065
9066 (defun gnus-summary-set-bookmark (article)
9067   "Set a bookmark in current article."
9068   (interactive (list (gnus-summary-article-number)))
9069   (when (or (not (get-buffer gnus-article-buffer))
9070             (not gnus-current-article)
9071             (not gnus-article-current)
9072             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9073     (error "No current article selected"))
9074   ;; Remove old bookmark, if one exists.
9075   (let ((old (assq article gnus-newsgroup-bookmarks)))
9076     (when old
9077       (setq gnus-newsgroup-bookmarks
9078             (delq old gnus-newsgroup-bookmarks))))
9079   ;; Set the new bookmark, which is on the form
9080   ;; (article-number . line-number-in-body).
9081   (push
9082    (cons article
9083          (save-excursion
9084            (set-buffer gnus-article-buffer)
9085            (count-lines
9086             (min (point)
9087                  (save-excursion
9088                    (goto-char (point-min))
9089                    (search-forward "\n\n" nil t)
9090                    (point)))
9091             (point))))
9092    gnus-newsgroup-bookmarks)
9093   (gnus-message 6 "A bookmark has been added to the current article."))
9094
9095 (defun gnus-summary-remove-bookmark (article)
9096   "Remove the bookmark from the current article."
9097   (interactive (list (gnus-summary-article-number)))
9098   ;; Remove old bookmark, if one exists.
9099   (let ((old (assq article gnus-newsgroup-bookmarks)))
9100     (if old
9101         (progn
9102           (setq gnus-newsgroup-bookmarks
9103                 (delq old gnus-newsgroup-bookmarks))
9104           (gnus-message 6 "Removed bookmark."))
9105       (gnus-message 6 "No bookmark in current article."))))
9106
9107 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9108 (defun gnus-summary-mark-as-dormant (n)
9109   "Mark N articles forward as dormant.
9110 If N is negative, mark backward instead.  The difference between N and
9111 the actual number of articles marked is returned."
9112   (interactive "p")
9113   (gnus-summary-mark-forward n gnus-dormant-mark))
9114
9115 (defun gnus-summary-set-process-mark (article)
9116   "Set the process mark on ARTICLE and update the summary line."
9117   (setq gnus-newsgroup-processable
9118         (cons article
9119               (delq article gnus-newsgroup-processable)))
9120   (when (gnus-summary-goto-subject article)
9121     (gnus-summary-show-thread)
9122     (gnus-summary-goto-subject article)
9123     (gnus-summary-update-secondary-mark article)))
9124
9125 (defun gnus-summary-remove-process-mark (article)
9126   "Remove the process mark from ARTICLE and update the summary line."
9127   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9128   (when (gnus-summary-goto-subject article)
9129     (gnus-summary-show-thread)
9130     (gnus-summary-goto-subject article)
9131     (gnus-summary-update-secondary-mark article)))
9132
9133 (defun gnus-summary-set-saved-mark (article)
9134   "Set the process mark on ARTICLE and update the summary line."
9135   (push article gnus-newsgroup-saved)
9136   (when (gnus-summary-goto-subject article)
9137     (gnus-summary-update-secondary-mark article)))
9138
9139 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9140   "Mark N articles as read forwards.
9141 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9142 The difference between N and the actual number of articles marked is
9143 returned.
9144 Iff NO-EXPIRE, auto-expiry will be inhibited."
9145   (interactive "p")
9146   (gnus-summary-show-thread)
9147   (let ((backward (< n 0))
9148         (gnus-summary-goto-unread
9149          (and gnus-summary-goto-unread
9150               (not (eq gnus-summary-goto-unread 'never))
9151               (not (memq mark (list gnus-unread-mark
9152                                     gnus-ticked-mark gnus-dormant-mark)))))
9153         (n (abs n))
9154         (mark (or mark gnus-del-mark)))
9155     (while (and (> n 0)
9156                 (gnus-summary-mark-article nil mark no-expire)
9157                 (zerop (gnus-summary-next-subject
9158                         (if backward -1 1)
9159                         (and gnus-summary-goto-unread
9160                              (not (eq gnus-summary-goto-unread 'never)))
9161                         t)))
9162       (setq n (1- n)))
9163     (when (/= 0 n)
9164       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9165     (gnus-summary-recenter)
9166     (gnus-summary-position-point)
9167     (gnus-set-mode-line 'summary)
9168     n))
9169
9170 (defun gnus-summary-mark-article-as-read (mark)
9171   "Mark the current article quickly as read with MARK."
9172   (let ((article (gnus-summary-article-number)))
9173     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9174     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9175     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9176     (push (cons article mark) gnus-newsgroup-reads)
9177     ;; Possibly remove from cache, if that is used.
9178     (when gnus-use-cache
9179       (gnus-cache-enter-remove-article article))
9180     ;; Allow the backend to change the mark.
9181     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9182     ;; Check for auto-expiry.
9183     (when (and gnus-newsgroup-auto-expire
9184                (memq mark gnus-auto-expirable-marks))
9185       (setq mark gnus-expirable-mark)
9186       ;; Let the backend know about the mark change.
9187       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9188       (push article gnus-newsgroup-expirable))
9189     ;; Set the mark in the buffer.
9190     (gnus-summary-update-mark mark 'unread)
9191     t))
9192
9193 (defun gnus-summary-mark-article-as-unread (mark)
9194   "Mark the current article quickly as unread with MARK."
9195   (let* ((article (gnus-summary-article-number))
9196          (old-mark (gnus-summary-article-mark article)))
9197     ;; Allow the backend to change the mark.
9198     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9199     (if (eq mark old-mark)
9200         t
9201       (if (<= article 0)
9202           (progn
9203             (gnus-error 1 "Can't mark negative article numbers")
9204             nil)
9205         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9206         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9207         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9208         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9209         (cond ((= mark gnus-ticked-mark)
9210                (push article gnus-newsgroup-marked))
9211               ((= mark gnus-dormant-mark)
9212                (push article gnus-newsgroup-dormant))
9213               (t
9214                (push article gnus-newsgroup-unreads)))
9215         (gnus-pull article gnus-newsgroup-reads)
9216
9217         ;; See whether the article is to be put in the cache.
9218         (and gnus-use-cache
9219              (vectorp (gnus-summary-article-header article))
9220              (save-excursion
9221                (gnus-cache-possibly-enter-article
9222                 gnus-newsgroup-name article
9223                 (gnus-summary-article-header article)
9224                 (= mark gnus-ticked-mark)
9225                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9226
9227         ;; Fix the mark.
9228         (gnus-summary-update-mark mark 'unread)
9229         t))))
9230
9231 (defun gnus-summary-mark-article (&optional article mark no-expire)
9232   "Mark ARTICLE with MARK.  MARK can be any character.
9233 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9234 `??' (dormant) and `?E' (expirable).
9235 If MARK is nil, then the default character `?r' is used.
9236 If ARTICLE is nil, then the article on the current line will be
9237 marked.
9238 Iff NO-EXPIRE, auto-expiry will be inhibited."
9239   ;; The mark might be a string.
9240   (when (stringp mark)
9241     (setq mark (aref mark 0)))
9242   ;; If no mark is given, then we check auto-expiring.
9243   (when (null mark)
9244     (setq mark gnus-del-mark))
9245   (when (and (not no-expire)
9246              gnus-newsgroup-auto-expire
9247              (memq mark gnus-auto-expirable-marks))
9248     (setq mark gnus-expirable-mark))
9249   (let ((article (or article (gnus-summary-article-number)))
9250         (old-mark (gnus-summary-article-mark article)))
9251     ;; Allow the backend to change the mark.
9252     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9253     (if (eq mark old-mark)
9254         t
9255       (unless article
9256         (error "No article on current line"))
9257       (if (not (if (or (= mark gnus-unread-mark)
9258                        (= mark gnus-ticked-mark)
9259                        (= mark gnus-dormant-mark))
9260                    (gnus-mark-article-as-unread article mark)
9261                  (gnus-mark-article-as-read article mark)))
9262           t
9263         ;; See whether the article is to be put in the cache.
9264         (and gnus-use-cache
9265              (not (= mark gnus-canceled-mark))
9266              (vectorp (gnus-summary-article-header article))
9267              (save-excursion
9268                (gnus-cache-possibly-enter-article
9269                 gnus-newsgroup-name article
9270                 (gnus-summary-article-header article)
9271                 (= mark gnus-ticked-mark)
9272                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9273
9274         (when (gnus-summary-goto-subject article nil t)
9275           (let ((buffer-read-only nil))
9276             (gnus-summary-show-thread)
9277             ;; Fix the mark.
9278             (gnus-summary-update-mark mark 'unread)
9279             t))))))
9280
9281 (defun gnus-summary-update-secondary-mark (article)
9282   "Update the secondary (read, process, cache) mark."
9283   (gnus-summary-update-mark
9284    (cond ((memq article gnus-newsgroup-processable)
9285           gnus-process-mark)
9286          ((memq article gnus-newsgroup-cached)
9287           gnus-cached-mark)
9288          ((memq article gnus-newsgroup-replied)
9289           gnus-replied-mark)
9290          ((memq article gnus-newsgroup-forwarded)
9291           gnus-forwarded-mark)
9292          ((memq article gnus-newsgroup-saved)
9293           gnus-saved-mark)
9294          ((memq article gnus-newsgroup-recent)
9295           gnus-recent-mark)
9296          ((memq article gnus-newsgroup-unseen)
9297           gnus-unseen-mark)
9298          (t gnus-no-mark))
9299    'replied)
9300   (when (gnus-visual-p 'summary-highlight 'highlight)
9301     (gnus-run-hooks 'gnus-summary-update-hook))
9302   t)
9303
9304 (defun gnus-summary-update-mark (mark type)
9305   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9306         (buffer-read-only nil))
9307     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9308     (when forward
9309       (when (looking-at "\r")
9310         (incf forward))
9311       (when (<= (+ forward (point)) (point-max))
9312         ;; Go to the right position on the line.
9313         (goto-char (+ forward (point)))
9314         ;; Replace the old mark with the new mark.
9315         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9316         ;; Optionally update the marks by some user rule.
9317         (when (eq type 'unread)
9318           (gnus-data-set-mark
9319            (gnus-data-find (gnus-summary-article-number)) mark)
9320           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9321
9322 (defun gnus-mark-article-as-read (article &optional mark)
9323   "Enter ARTICLE in the pertinent lists and remove it from others."
9324   ;; Make the article expirable.
9325   (let ((mark (or mark gnus-del-mark)))
9326     (if (= mark gnus-expirable-mark)
9327         (push article gnus-newsgroup-expirable)
9328       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9329     ;; Remove from unread and marked lists.
9330     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9331     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9332     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9333     (push (cons article mark) gnus-newsgroup-reads)
9334     ;; Possibly remove from cache, if that is used.
9335     (when gnus-use-cache
9336       (gnus-cache-enter-remove-article article))
9337     t))
9338
9339 (defun gnus-mark-article-as-unread (article &optional mark)
9340   "Enter ARTICLE in the pertinent lists and remove it from others."
9341   (let ((mark (or mark gnus-ticked-mark)))
9342     (if (<= article 0)
9343         (progn
9344           (gnus-error 1 "Can't mark negative article numbers")
9345           nil)
9346       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9347             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9348             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9349             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9350
9351       ;; Unsuppress duplicates?
9352       (when gnus-suppress-duplicates
9353         (gnus-dup-unsuppress-article article))
9354
9355       (cond ((= mark gnus-ticked-mark)
9356              (push article gnus-newsgroup-marked))
9357             ((= mark gnus-dormant-mark)
9358              (push article gnus-newsgroup-dormant))
9359             (t
9360              (push article gnus-newsgroup-unreads)))
9361       (gnus-pull article gnus-newsgroup-reads)
9362       t)))
9363
9364 (defalias 'gnus-summary-mark-as-unread-forward
9365   'gnus-summary-tick-article-forward)
9366 (make-obsolete 'gnus-summary-mark-as-unread-forward
9367                'gnus-summary-tick-article-forward)
9368 (defun gnus-summary-tick-article-forward (n)
9369   "Tick N articles forwards.
9370 If N is negative, tick backwards instead.
9371 The difference between N and the number of articles ticked is returned."
9372   (interactive "p")
9373   (gnus-summary-mark-forward n gnus-ticked-mark))
9374
9375 (defalias 'gnus-summary-mark-as-unread-backward
9376   'gnus-summary-tick-article-backward)
9377 (make-obsolete 'gnus-summary-mark-as-unread-backward
9378                'gnus-summary-tick-article-backward)
9379 (defun gnus-summary-tick-article-backward (n)
9380   "Tick N articles backwards.
9381 The difference between N and the number of articles ticked is returned."
9382   (interactive "p")
9383   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9384
9385 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9386 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9387 (defun gnus-summary-tick-article (&optional article clear-mark)
9388   "Mark current article as unread.
9389 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9390 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9391   (interactive)
9392   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9393                                        gnus-ticked-mark)))
9394
9395 (defun gnus-summary-mark-as-read-forward (n)
9396   "Mark N articles as read forwards.
9397 If N is negative, mark backwards instead.
9398 The difference between N and the actual number of articles marked is
9399 returned."
9400   (interactive "p")
9401   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9402
9403 (defun gnus-summary-mark-as-read-backward (n)
9404   "Mark the N articles as read backwards.
9405 The difference between N and the actual number of articles marked is
9406 returned."
9407   (interactive "p")
9408   (gnus-summary-mark-forward
9409    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9410
9411 (defun gnus-summary-mark-as-read (&optional article mark)
9412   "Mark current article as read.
9413 ARTICLE specifies the article to be marked as read.
9414 MARK specifies a string to be inserted at the beginning of the line."
9415   (gnus-summary-mark-article article mark))
9416
9417 (defun gnus-summary-clear-mark-forward (n)
9418   "Clear marks from N articles forward.
9419 If N is negative, clear backward instead.
9420 The difference between N and the number of marks cleared is returned."
9421   (interactive "p")
9422   (gnus-summary-mark-forward n gnus-unread-mark))
9423
9424 (defun gnus-summary-clear-mark-backward (n)
9425   "Clear marks from N articles backward.
9426 The difference between N and the number of marks cleared is returned."
9427   (interactive "p")
9428   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9429
9430 (defun gnus-summary-mark-unread-as-read ()
9431   "Intended to be used by `gnus-summary-mark-article-hook'."
9432   (when (memq gnus-current-article gnus-newsgroup-unreads)
9433     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9434
9435 (defun gnus-summary-mark-read-and-unread-as-read ()
9436   "Intended to be used by `gnus-summary-mark-article-hook'."
9437   (let ((mark (gnus-summary-article-mark)))
9438     (when (or (gnus-unread-mark-p mark)
9439               (gnus-read-mark-p mark))
9440       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9441
9442 (defun gnus-summary-mark-unread-as-ticked ()
9443   "Intended to be used by `gnus-summary-mark-article-hook'."
9444   (when (memq gnus-current-article gnus-newsgroup-unreads)
9445     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9446
9447 (defun gnus-summary-mark-region-as-read (point mark all)
9448   "Mark all unread articles between point and mark as read.
9449 If given a prefix, mark all articles between point and mark as read,
9450 even ticked and dormant ones."
9451   (interactive "r\nP")
9452   (save-excursion
9453     (let (article)
9454       (goto-char point)
9455       (beginning-of-line)
9456       (while (and
9457               (< (point) mark)
9458               (progn
9459                 (when (or all
9460                           (memq (setq article (gnus-summary-article-number))
9461                                 gnus-newsgroup-unreads))
9462                   (gnus-summary-mark-article article gnus-del-mark))
9463                 t)
9464               (gnus-summary-find-next))))))
9465
9466 (defun gnus-summary-mark-below (score mark)
9467   "Mark articles with score less than SCORE with MARK."
9468   (interactive "P\ncMark: ")
9469   (setq score (if score
9470                   (prefix-numeric-value score)
9471                 (or gnus-summary-default-score 0)))
9472   (save-excursion
9473     (set-buffer gnus-summary-buffer)
9474     (goto-char (point-min))
9475     (while
9476         (progn
9477           (and (< (gnus-summary-article-score) score)
9478                (gnus-summary-mark-article nil mark))
9479           (gnus-summary-find-next)))))
9480
9481 (defun gnus-summary-kill-below (&optional score)
9482   "Mark articles with score below SCORE as read."
9483   (interactive "P")
9484   (gnus-summary-mark-below score gnus-killed-mark))
9485
9486 (defun gnus-summary-clear-above (&optional score)
9487   "Clear all marks from articles with score above SCORE."
9488   (interactive "P")
9489   (gnus-summary-mark-above score gnus-unread-mark))
9490
9491 (defun gnus-summary-tick-above (&optional score)
9492   "Tick all articles with score above SCORE."
9493   (interactive "P")
9494   (gnus-summary-mark-above score gnus-ticked-mark))
9495
9496 (defun gnus-summary-mark-above (score mark)
9497   "Mark articles with score over SCORE with MARK."
9498   (interactive "P\ncMark: ")
9499   (setq score (if score
9500                   (prefix-numeric-value score)
9501                 (or gnus-summary-default-score 0)))
9502   (save-excursion
9503     (set-buffer gnus-summary-buffer)
9504     (goto-char (point-min))
9505     (while (and (progn
9506                   (when (> (gnus-summary-article-score) score)
9507                     (gnus-summary-mark-article nil mark))
9508                   t)
9509                 (gnus-summary-find-next)))))
9510
9511 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9512 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9513 (defun gnus-summary-limit-include-expunged (&optional no-error)
9514   "Display all the hidden articles that were expunged for low scores."
9515   (interactive)
9516   (let ((buffer-read-only nil))
9517     (let ((scored gnus-newsgroup-scored)
9518           headers h)
9519       (while scored
9520         (unless (gnus-summary-article-header (caar scored))
9521           (and (setq h (gnus-number-to-header (caar scored)))
9522                (< (cdar scored) gnus-summary-expunge-below)
9523                (push h headers)))
9524         (setq scored (cdr scored)))
9525       (if (not headers)
9526           (when (not no-error)
9527             (error "No expunged articles hidden"))
9528         (goto-char (point-min))
9529         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9530         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9531         (mapcar (lambda (x) (push (mail-header-number x)
9532                                   gnus-newsgroup-limit))
9533                 headers)
9534         (gnus-summary-prepare-unthreaded (nreverse headers))
9535         (goto-char (point-min))
9536         (gnus-summary-position-point)
9537         t))))
9538
9539 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9540   "Mark all unread articles in this newsgroup as read.
9541 If prefix argument ALL is non-nil, ticked and dormant articles will
9542 also be marked as read.
9543 If QUIETLY is non-nil, no questions will be asked.
9544 If TO-HERE is non-nil, it should be a point in the buffer.  All
9545 articles before (after, if REVERSE is set) this point will be marked as read.
9546 Note that this function will only catch up the unread article
9547 in the current summary buffer limitation.
9548 The number of articles marked as read is returned."
9549   (interactive "P")
9550   (prog1
9551       (save-excursion
9552         (when (or quietly
9553                   (not gnus-interactive-catchup) ;Without confirmation?
9554                   gnus-expert-user
9555                   (gnus-y-or-n-p
9556                    (if all
9557                        "Mark absolutely all articles as read? "
9558                      "Mark all unread articles as read? ")))
9559           (if (and not-mark
9560                    (not gnus-newsgroup-adaptive)
9561                    (not gnus-newsgroup-auto-expire)
9562                    (not gnus-suppress-duplicates)
9563                    (or (not gnus-use-cache)
9564                        (eq gnus-use-cache 'passive)))
9565               (progn
9566                 (when all
9567                   (setq gnus-newsgroup-marked nil
9568                         gnus-newsgroup-dormant nil))
9569                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9570             ;; We actually mark all articles as canceled, which we
9571             ;; have to do when using auto-expiry or adaptive scoring.
9572             (gnus-summary-show-all-threads)
9573             (if (and to-here reverse)
9574                 (progn
9575                   (goto-char to-here)
9576                   (while (and
9577                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9578                           (gnus-summary-find-next (not all) nil nil t))))
9579               (when (gnus-summary-first-subject (not all) t)
9580                 (while (and
9581                         (if to-here (< (point) to-here) t)
9582                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9583                         (gnus-summary-find-next (not all) nil nil t)))))
9584             (gnus-set-mode-line 'summary))
9585           t))
9586     (gnus-summary-position-point)))
9587
9588 (defun gnus-summary-catchup-to-here (&optional all)
9589   "Mark all unticked articles before the current one as read.
9590 If ALL is non-nil, also mark ticked and dormant articles as read."
9591   (interactive "P")
9592   (save-excursion
9593     (gnus-save-hidden-threads
9594       (let ((beg (point)))
9595         ;; We check that there are unread articles.
9596         (when (or all (gnus-summary-find-prev))
9597           (gnus-summary-catchup all t beg)))))
9598   (gnus-summary-position-point))
9599
9600 (defun gnus-summary-catchup-from-here (&optional all)
9601   "Mark all unticked articles after the current one as read.
9602 If ALL is non-nil, also mark ticked and dormant articles as read."
9603   (interactive "P")
9604   (save-excursion
9605     (gnus-save-hidden-threads
9606       (let ((beg (point)))
9607         ;; We check that there are unread articles.
9608         (when (or all (gnus-summary-find-next))
9609           (gnus-summary-catchup all t beg nil t)))))
9610   (gnus-summary-position-point))
9611
9612 (defun gnus-summary-catchup-all (&optional quietly)
9613   "Mark all articles in this newsgroup as read."
9614   (interactive "P")
9615   (gnus-summary-catchup t quietly))
9616
9617 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9618   "Mark all unread articles in this group as read, then exit.
9619 If prefix argument ALL is non-nil, all articles are marked as read.
9620 If QUIETLY is non-nil, no questions will be asked."
9621   (interactive "P")
9622   (when (gnus-summary-catchup all quietly nil 'fast)
9623     ;; Select next newsgroup or exit.
9624     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9625              (eq gnus-auto-select-next 'quietly))
9626         (gnus-summary-next-group nil)
9627       (gnus-summary-exit))))
9628
9629 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9630   "Mark all articles in this newsgroup as read, and then exit."
9631   (interactive "P")
9632   (gnus-summary-catchup-and-exit t quietly))
9633
9634 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9635   "Mark all articles in this group as read and select the next group.
9636 If given a prefix, mark all articles, unread as well as ticked, as
9637 read."
9638   (interactive "P")
9639   (save-excursion
9640     (gnus-summary-catchup all))
9641   (gnus-summary-next-group))
9642
9643 ;;;
9644 ;;; with article
9645 ;;;
9646
9647 (defmacro gnus-with-article (article &rest forms)
9648   "Select ARTICLE and perform FORMS in the original article buffer.
9649 Then replace the article with the result."
9650   `(progn
9651      ;; We don't want the article to be marked as read.
9652      (let (gnus-mark-article-hook)
9653        (gnus-summary-select-article t t nil ,article))
9654      (set-buffer gnus-original-article-buffer)
9655      ,@forms
9656      (if (not (gnus-check-backend-function
9657                'request-replace-article (car gnus-article-current)))
9658          (gnus-message 5 "Read-only group; not replacing")
9659        (unless (gnus-request-replace-article
9660                 ,article (car gnus-article-current)
9661                 (current-buffer) t)
9662          (error "Couldn't replace article")))
9663      ;; The cache and backlog have to be flushed somewhat.
9664      (when gnus-keep-backlog
9665        (gnus-backlog-remove-article
9666         (car gnus-article-current) (cdr gnus-article-current)))
9667      (when gnus-use-cache
9668        (gnus-cache-update-article
9669         (car gnus-article-current) (cdr gnus-article-current)))))
9670
9671 (put 'gnus-with-article 'lisp-indent-function 1)
9672 (put 'gnus-with-article 'edebug-form-spec '(form body))
9673
9674 ;; Thread-based commands.
9675
9676 (defun gnus-summary-articles-in-thread (&optional article)
9677   "Return a list of all articles in the current thread.
9678 If ARTICLE is non-nil, return all articles in the thread that starts
9679 with that article."
9680   (let* ((article (or article (gnus-summary-article-number)))
9681          (data (gnus-data-find-list article))
9682          (top-level (gnus-data-level (car data)))
9683          (top-subject
9684           (cond ((null gnus-thread-operation-ignore-subject)
9685                  (gnus-simplify-subject-re
9686                   (mail-header-subject (gnus-data-header (car data)))))
9687                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9688                  (gnus-simplify-subject-fuzzy
9689                   (mail-header-subject (gnus-data-header (car data)))))
9690                 (t nil)))
9691          (end-point (save-excursion
9692                       (if (gnus-summary-go-to-next-thread)
9693                           (point) (point-max))))
9694          articles)
9695     (while (and data
9696                 (< (gnus-data-pos (car data)) end-point))
9697       (when (or (not top-subject)
9698                 (string= top-subject
9699                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9700                              (gnus-simplify-subject-fuzzy
9701                               (mail-header-subject
9702                                (gnus-data-header (car data))))
9703                            (gnus-simplify-subject-re
9704                             (mail-header-subject
9705                              (gnus-data-header (car data)))))))
9706         (push (gnus-data-number (car data)) articles))
9707       (unless (and (setq data (cdr data))
9708                    (> (gnus-data-level (car data)) top-level))
9709         (setq data nil)))
9710     ;; Return the list of articles.
9711     (nreverse articles)))
9712
9713 (defun gnus-summary-rethread-current ()
9714   "Rethread the thread the current article is part of."
9715   (interactive)
9716   (let* ((gnus-show-threads t)
9717          (article (gnus-summary-article-number))
9718          (id (mail-header-id (gnus-summary-article-header)))
9719          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9720     (unless id
9721       (error "No article on the current line"))
9722     (gnus-rebuild-thread id)
9723     (gnus-summary-goto-subject article)))
9724
9725 (defun gnus-summary-reparent-thread ()
9726   "Make the current article child of the marked (or previous) article.
9727
9728 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9729 is non-nil or the Subject: of both articles are the same."
9730   (interactive)
9731   (unless (not (gnus-group-read-only-p))
9732     (error "The current newsgroup does not support article editing"))
9733   (unless (<= (length gnus-newsgroup-processable) 1)
9734     (error "No more than one article may be marked"))
9735   (save-window-excursion
9736     (let ((gnus-article-buffer " *reparent*")
9737           (current-article (gnus-summary-article-number))
9738           ;; First grab the marked article, otherwise one line up.
9739           (parent-article (if (not (null gnus-newsgroup-processable))
9740                               (car gnus-newsgroup-processable)
9741                             (save-excursion
9742                               (if (eq (forward-line -1) 0)
9743                                   (gnus-summary-article-number)
9744                                 (error "Beginning of summary buffer"))))))
9745       (unless (not (eq current-article parent-article))
9746         (error "An article may not be self-referential"))
9747       (let ((message-id (mail-header-id
9748                          (gnus-summary-article-header parent-article))))
9749         (unless (and message-id (not (equal message-id "")))
9750           (error "No message-id in desired parent"))
9751         (gnus-with-article current-article
9752           (save-restriction
9753             (goto-char (point-min))
9754             (message-narrow-to-head)
9755             (if (re-search-forward "^References: " nil t)
9756                 (progn
9757                   (re-search-forward "^[^ \t]" nil t)
9758                   (forward-line -1)
9759                   (end-of-line)
9760                   (insert " " message-id))
9761               (insert "References: " message-id "\n"))))
9762         (set-buffer gnus-summary-buffer)
9763         (gnus-summary-unmark-all-processable)
9764         (gnus-summary-update-article current-article)
9765         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9766             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9767         (gnus-summary-rethread-current)
9768         (gnus-message 3 "Article %d is now the child of article %d"
9769                       current-article parent-article)))))
9770
9771 (defun gnus-summary-toggle-threads (&optional arg)
9772   "Toggle showing conversation threads.
9773 If ARG is positive number, turn showing conversation threads on."
9774   (interactive "P")
9775   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9776     (setq gnus-show-threads
9777           (if (null arg) (not gnus-show-threads)
9778             (> (prefix-numeric-value arg) 0)))
9779     (gnus-summary-prepare)
9780     (gnus-summary-goto-subject current)
9781     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9782     (gnus-summary-position-point)))
9783
9784 (defun gnus-summary-show-all-threads ()
9785   "Show all threads."
9786   (interactive)
9787   (save-excursion
9788     (let ((buffer-read-only nil))
9789       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9790   (gnus-summary-position-point))
9791
9792 (defun gnus-summary-show-thread ()
9793   "Show thread subtrees.
9794 Returns nil if no thread was there to be shown."
9795   (interactive)
9796   (let ((buffer-read-only nil)
9797         (orig (point))
9798         ;; first goto end then to beg, to have point at beg after let
9799         (end (progn (end-of-line) (point)))
9800         (beg (progn (beginning-of-line) (point))))
9801     (prog1
9802         ;; Any hidden lines here?
9803         (search-forward "\r" end t)
9804       (subst-char-in-region beg end ?\^M ?\n t)
9805       (goto-char orig)
9806       (gnus-summary-position-point))))
9807
9808 (defun gnus-summary-hide-all-threads ()
9809   "Hide all thread subtrees."
9810   (interactive)
9811   (save-excursion
9812     (goto-char (point-min))
9813     (gnus-summary-hide-thread)
9814     (while (zerop (gnus-summary-next-thread 1 t))
9815       (gnus-summary-hide-thread)))
9816   (gnus-summary-position-point))
9817
9818 (defun gnus-summary-hide-thread ()
9819   "Hide thread subtrees.
9820 Returns nil if no threads were there to be hidden."
9821   (interactive)
9822   (let ((buffer-read-only nil)
9823         (start (point))
9824         (article (gnus-summary-article-number)))
9825     (goto-char start)
9826     ;; Go forward until either the buffer ends or the subthread
9827     ;; ends.
9828     (when (and (not (eobp))
9829                (or (zerop (gnus-summary-next-thread 1 t))
9830                    (goto-char (point-max))))
9831       (prog1
9832           (if (and (> (point) start)
9833                    (search-backward "\n" start t))
9834               (progn
9835                 (subst-char-in-region start (point) ?\n ?\^M)
9836                 (gnus-summary-goto-subject article))
9837             (goto-char start)
9838             nil)))))
9839
9840 (defun gnus-summary-go-to-next-thread (&optional previous)
9841   "Go to the same level (or less) next thread.
9842 If PREVIOUS is non-nil, go to previous thread instead.
9843 Return the article number moved to, or nil if moving was impossible."
9844   (let ((level (gnus-summary-thread-level))
9845         (way (if previous -1 1))
9846         (beg (point)))
9847     (forward-line way)
9848     (while (and (not (eobp))
9849                 (< level (gnus-summary-thread-level)))
9850       (forward-line way))
9851     (if (eobp)
9852         (progn
9853           (goto-char beg)
9854           nil)
9855       (setq beg (point))
9856       (prog1
9857           (gnus-summary-article-number)
9858         (goto-char beg)))))
9859
9860 (defun gnus-summary-next-thread (n &optional silent)
9861   "Go to the same level next N'th thread.
9862 If N is negative, search backward instead.
9863 Returns the difference between N and the number of skips actually
9864 done.
9865
9866 If SILENT, don't output messages."
9867   (interactive "p")
9868   (let ((backward (< n 0))
9869         (n (abs n)))
9870     (while (and (> n 0)
9871                 (gnus-summary-go-to-next-thread backward))
9872       (decf n))
9873     (unless silent
9874       (gnus-summary-position-point))
9875     (when (and (not silent) (/= 0 n))
9876       (gnus-message 7 "No more threads"))
9877     n))
9878
9879 (defun gnus-summary-prev-thread (n)
9880   "Go to the same level previous N'th thread.
9881 Returns the difference between N and the number of skips actually
9882 done."
9883   (interactive "p")
9884   (gnus-summary-next-thread (- n)))
9885
9886 (defun gnus-summary-go-down-thread ()
9887   "Go down one level in the current thread."
9888   (let ((children (gnus-summary-article-children)))
9889     (when children
9890       (gnus-summary-goto-subject (car children)))))
9891
9892 (defun gnus-summary-go-up-thread ()
9893   "Go up one level in the current thread."
9894   (let ((parent (gnus-summary-article-parent)))
9895     (when parent
9896       (gnus-summary-goto-subject parent))))
9897
9898 (defun gnus-summary-down-thread (n)
9899   "Go down thread N steps.
9900 If N is negative, go up instead.
9901 Returns the difference between N and how many steps down that were
9902 taken."
9903   (interactive "p")
9904   (let ((up (< n 0))
9905         (n (abs n)))
9906     (while (and (> n 0)
9907                 (if up (gnus-summary-go-up-thread)
9908                   (gnus-summary-go-down-thread)))
9909       (setq n (1- n)))
9910     (gnus-summary-position-point)
9911     (when (/= 0 n)
9912       (gnus-message 7 "Can't go further"))
9913     n))
9914
9915 (defun gnus-summary-up-thread (n)
9916   "Go up thread N steps.
9917 If N is negative, go down instead.
9918 Returns the difference between N and how many steps down that were
9919 taken."
9920   (interactive "p")
9921   (gnus-summary-down-thread (- n)))
9922
9923 (defun gnus-summary-top-thread ()
9924   "Go to the top of the thread."
9925   (interactive)
9926   (while (gnus-summary-go-up-thread))
9927   (gnus-summary-article-number))
9928
9929 (defun gnus-summary-kill-thread (&optional unmark)
9930   "Mark articles under current thread as read.
9931 If the prefix argument is positive, remove any kinds of marks.
9932 If the prefix argument is negative, tick articles instead."
9933   (interactive "P")
9934   (when unmark
9935     (setq unmark (prefix-numeric-value unmark)))
9936   (let ((articles (gnus-summary-articles-in-thread)))
9937     (save-excursion
9938       ;; Expand the thread.
9939       (gnus-summary-show-thread)
9940       ;; Mark all the articles.
9941       (while articles
9942         (gnus-summary-goto-subject (car articles))
9943         (cond ((null unmark)
9944                (gnus-summary-mark-article-as-read gnus-killed-mark))
9945               ((> unmark 0)
9946                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9947               (t
9948                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9949         (setq articles (cdr articles))))
9950     ;; Hide killed subtrees.
9951     (and (null unmark)
9952          gnus-thread-hide-killed
9953          (gnus-summary-hide-thread))
9954     ;; If marked as read, go to next unread subject.
9955     (when (null unmark)
9956       ;; Go to next unread subject.
9957       (gnus-summary-next-subject 1 t)))
9958   (gnus-set-mode-line 'summary))
9959
9960 ;; Summary sorting commands
9961
9962 (defun gnus-summary-sort-by-number (&optional reverse)
9963   "Sort the summary buffer by article number.
9964 Argument REVERSE means reverse order."
9965   (interactive "P")
9966   (gnus-summary-sort 'number reverse))
9967
9968 (defun gnus-summary-sort-by-author (&optional reverse)
9969   "Sort the summary buffer by author name alphabetically.
9970 If `case-fold-search' is non-nil, case of letters is ignored.
9971 Argument REVERSE means reverse order."
9972   (interactive "P")
9973   (gnus-summary-sort 'author reverse))
9974
9975 (defun gnus-summary-sort-by-subject (&optional reverse)
9976   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9977 If `case-fold-search' is non-nil, case of letters is ignored.
9978 Argument REVERSE means reverse order."
9979   (interactive "P")
9980   (gnus-summary-sort 'subject reverse))
9981
9982 (defun gnus-summary-sort-by-date (&optional reverse)
9983   "Sort the summary buffer by date.
9984 Argument REVERSE means reverse order."
9985   (interactive "P")
9986   (gnus-summary-sort 'date reverse))
9987
9988 (defun gnus-summary-sort-by-score (&optional reverse)
9989   "Sort the summary buffer by score.
9990 Argument REVERSE means reverse order."
9991   (interactive "P")
9992   (gnus-summary-sort 'score reverse))
9993
9994 (defun gnus-summary-sort-by-lines (&optional reverse)
9995   "Sort the summary buffer by the number of lines.
9996 Argument REVERSE means reverse order."
9997   (interactive "P")
9998   (gnus-summary-sort 'lines reverse))
9999
10000 (defun gnus-summary-sort-by-chars (&optional reverse)
10001   "Sort the summary buffer by article length.
10002 Argument REVERSE means reverse order."
10003   (interactive "P")
10004   (gnus-summary-sort 'chars reverse))
10005
10006 (defun gnus-summary-sort-by-original (&optional reverse)
10007   "Sort the summary buffer using the default sorting method.
10008 Argument REVERSE means reverse order."
10009   (interactive "P")
10010   (let* ((buffer-read-only)
10011          (gnus-summary-prepare-hook nil))
10012     ;; We do the sorting by regenerating the threads.
10013     (gnus-summary-prepare)
10014     ;; Hide subthreads if needed.
10015     (when (and gnus-show-threads gnus-thread-hide-subtree)
10016       (gnus-summary-hide-all-threads))))
10017
10018 (defun gnus-summary-sort (predicate reverse)
10019   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10020   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10021          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10022          (gnus-thread-sort-functions
10023           (if (not reverse)
10024               thread
10025             `(lambda (t1 t2)
10026                (,thread t2 t1))))
10027          (gnus-sort-gathered-threads-function
10028           gnus-thread-sort-functions)
10029          (gnus-article-sort-functions
10030           (if (not reverse)
10031               article
10032             `(lambda (t1 t2)
10033                (,article t2 t1))))
10034          (buffer-read-only)
10035          (gnus-summary-prepare-hook nil))
10036     ;; We do the sorting by regenerating the threads.
10037     (gnus-summary-prepare)
10038     ;; Hide subthreads if needed.
10039     (when (and gnus-show-threads gnus-thread-hide-subtree)
10040       (gnus-summary-hide-all-threads))))
10041
10042 ;; Summary saving commands.
10043
10044 (defun gnus-summary-save-article (&optional n not-saved)
10045   "Save the current article using the default saver function.
10046 If N is a positive number, save the N next articles.
10047 If N is a negative number, save the N previous articles.
10048 If N is nil and any articles have been marked with the process mark,
10049 save those articles instead.
10050 The variable `gnus-default-article-saver' specifies the saver function."
10051   (interactive "P")
10052   (let* ((articles (gnus-summary-work-articles n))
10053          (save-buffer (save-excursion
10054                         (nnheader-set-temp-buffer " *Gnus Save*")))
10055          (num (length articles))
10056          header file)
10057     (dolist (article articles)
10058       (setq header (gnus-summary-article-header article))
10059       (if (not (vectorp header))
10060           ;; This is a pseudo-article.
10061           (if (assq 'name header)
10062               (gnus-copy-file (cdr (assq 'name header)))
10063             (gnus-message 1 "Article %d is unsaveable" article))
10064         ;; This is a real article.
10065         (save-window-excursion
10066           (let ((gnus-display-mime-function nil)
10067                 (gnus-article-prepare-hook nil))
10068             (gnus-summary-select-article t nil nil article)))
10069         (save-excursion
10070           (set-buffer save-buffer)
10071           (erase-buffer)
10072           (insert-buffer-substring gnus-original-article-buffer))
10073         (setq file (gnus-article-save save-buffer file num))
10074         (gnus-summary-remove-process-mark article)
10075         (unless not-saved
10076           (gnus-summary-set-saved-mark article))))
10077     (gnus-kill-buffer save-buffer)
10078     (gnus-summary-position-point)
10079     (gnus-set-mode-line 'summary)
10080     n))
10081
10082 (defun gnus-summary-pipe-output (&optional arg)
10083   "Pipe the current article to a subprocess.
10084 If N is a positive number, pipe the N next articles.
10085 If N is a negative number, pipe the N previous articles.
10086 If N is nil and any articles have been marked with the process mark,
10087 pipe those articles instead."
10088   (interactive "P")
10089   (require 'gnus-art)
10090   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10091     (gnus-summary-save-article arg t))
10092   (let ((buffer (get-buffer "*Shell Command Output*")))
10093     (if (and buffer
10094              (with-current-buffer buffer (> (point-max) (point-min))))
10095         (gnus-configure-windows 'pipe))))
10096
10097 (defun gnus-summary-save-article-mail (&optional arg)
10098   "Append the current article to an mail file.
10099 If N is a positive number, save the N next articles.
10100 If N is a negative number, save the N previous articles.
10101 If N is nil and any articles have been marked with the process mark,
10102 save those articles instead."
10103   (interactive "P")
10104   (require 'gnus-art)
10105   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10106     (gnus-summary-save-article arg)))
10107
10108 (defun gnus-summary-save-article-rmail (&optional arg)
10109   "Append the current article to an rmail file.
10110 If N is a positive number, save the N next articles.
10111 If N is a negative number, save the N previous articles.
10112 If N is nil and any articles have been marked with the process mark,
10113 save those articles instead."
10114   (interactive "P")
10115   (require 'gnus-art)
10116   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10117     (gnus-summary-save-article arg)))
10118
10119 (defun gnus-summary-save-article-file (&optional arg)
10120   "Append the current article to a file.
10121 If N is a positive number, save the N next articles.
10122 If N is a negative number, save the N previous articles.
10123 If N is nil and any articles have been marked with the process mark,
10124 save those articles instead."
10125   (interactive "P")
10126   (require 'gnus-art)
10127   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10128     (gnus-summary-save-article arg)))
10129
10130 (defun gnus-summary-write-article-file (&optional arg)
10131   "Write the current article to a file, deleting the previous file.
10132 If N is a positive number, save the N next articles.
10133 If N is a negative number, save the N previous articles.
10134 If N is nil and any articles have been marked with the process mark,
10135 save those articles instead."
10136   (interactive "P")
10137   (require 'gnus-art)
10138   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10139     (gnus-summary-save-article arg)))
10140
10141 (defun gnus-summary-save-article-body-file (&optional arg)
10142   "Append the current article body to a file.
10143 If N is a positive number, save the N next articles.
10144 If N is a negative number, save the N previous articles.
10145 If N is nil and any articles have been marked with the process mark,
10146 save those articles instead."
10147   (interactive "P")
10148   (require 'gnus-art)
10149   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10150     (gnus-summary-save-article arg)))
10151
10152 (defun gnus-summary-muttprint (&optional arg)
10153   "Print the current article using Muttprint.
10154 If N is a positive number, save the N next articles.
10155 If N is a negative number, save the N previous articles.
10156 If N is nil and any articles have been marked with the process mark,
10157 save those articles instead."
10158   (interactive "P")
10159   (require 'gnus-art)
10160   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10161     (gnus-summary-save-article arg t)))
10162
10163 (defun gnus-summary-pipe-message (program)
10164   "Pipe the current article through PROGRAM."
10165   (interactive "sProgram: ")
10166   (gnus-summary-select-article)
10167   (let ((mail-header-separator ""))
10168     (gnus-eval-in-buffer-window gnus-article-buffer
10169       (save-restriction
10170         (widen)
10171         (let ((start (window-start))
10172               buffer-read-only)
10173           (message-pipe-buffer-body program)
10174           (set-window-start (get-buffer-window (current-buffer)) start))))))
10175
10176 (defun gnus-get-split-value (methods)
10177   "Return a value based on the split METHODS."
10178   (let (split-name method result match)
10179     (when methods
10180       (save-excursion
10181         (set-buffer gnus-original-article-buffer)
10182         (save-restriction
10183           (nnheader-narrow-to-headers)
10184           (while (and methods (not split-name))
10185             (goto-char (point-min))
10186             (setq method (pop methods))
10187             (setq match (car method))
10188             (when (cond
10189                    ((stringp match)
10190                     ;; Regular expression.
10191                     (ignore-errors
10192                       (re-search-forward match nil t)))
10193                    ((gnus-functionp match)
10194                     ;; Function.
10195                     (save-restriction
10196                       (widen)
10197                       (setq result (funcall match gnus-newsgroup-name))))
10198                    ((consp match)
10199                     ;; Form.
10200                     (save-restriction
10201                       (widen)
10202                       (setq result (eval match)))))
10203               (setq split-name (cdr method))
10204               (cond ((stringp result)
10205                      (push (expand-file-name
10206                             result gnus-article-save-directory)
10207                            split-name))
10208                     ((consp result)
10209                      (setq split-name (append result split-name)))))))))
10210     (nreverse split-name)))
10211
10212 (defun gnus-valid-move-group-p (group)
10213   (and (boundp group)
10214        (symbol-name group)
10215        (symbol-value group)
10216        (gnus-get-function (gnus-find-method-for-group
10217                            (symbol-name group)) 'request-accept-article t)))
10218
10219 (defun gnus-read-move-group-name (prompt default articles prefix)
10220   "Read a group name."
10221   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10222          (minibuffer-confirm-incomplete nil) ; XEmacs
10223          (prom
10224           (format "%s %s to:"
10225                   prompt
10226                   (if (> (length articles) 1)
10227                       (format "these %d articles" (length articles))
10228                     "this article")))
10229          (to-newsgroup
10230           (cond
10231            ((null split-name)
10232             (gnus-completing-read default prom
10233                                   gnus-active-hashtb
10234                                   'gnus-valid-move-group-p
10235                                   nil prefix
10236                                   'gnus-group-history))
10237            ((= 1 (length split-name))
10238             (gnus-completing-read (car split-name) prom
10239                                   gnus-active-hashtb
10240                                   'gnus-valid-move-group-p
10241                                   nil nil
10242                                   'gnus-group-history))
10243            (t
10244             (gnus-completing-read nil prom
10245                                   (mapcar (lambda (el) (list el))
10246                                           (nreverse split-name))
10247                                   nil nil nil
10248                                   'gnus-group-history))))
10249          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10250     (when to-newsgroup
10251       (if (or (string= to-newsgroup "")
10252               (string= to-newsgroup prefix))
10253           (setq to-newsgroup default))
10254       (unless to-newsgroup
10255         (error "No group name entered"))
10256       (or (gnus-active to-newsgroup)
10257           (gnus-activate-group to-newsgroup nil nil to-method)
10258           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10259                                      to-newsgroup))
10260               (or (and (gnus-request-create-group to-newsgroup to-method)
10261                        (gnus-activate-group
10262                         to-newsgroup nil nil to-method)
10263                        (gnus-subscribe-group to-newsgroup))
10264                   (error "Couldn't create group %s" to-newsgroup)))
10265           (error "No such group: %s" to-newsgroup)))
10266     to-newsgroup))
10267
10268 (defun gnus-summary-save-parts (type dir n &optional reverse)
10269   "Save parts matching TYPE to DIR.
10270 If REVERSE, save parts that do not match TYPE."
10271   (interactive
10272    (list (read-string "Save parts of type: "
10273                       (or (car gnus-summary-save-parts-type-history)
10274                           gnus-summary-save-parts-default-mime)
10275                       'gnus-summary-save-parts-type-history)
10276          (setq gnus-summary-save-parts-last-directory
10277                (read-file-name "Save to directory: "
10278                                gnus-summary-save-parts-last-directory
10279                                nil t))
10280          current-prefix-arg))
10281   (gnus-summary-iterate n
10282     (let ((gnus-display-mime-function nil)
10283           (gnus-inhibit-treatment t))
10284       (gnus-summary-select-article))
10285     (save-excursion
10286       (set-buffer gnus-article-buffer)
10287       (let ((handles (or gnus-article-mime-handles
10288                          (mm-dissect-buffer) (mm-uu-dissect))))
10289         (when handles
10290           (gnus-summary-save-parts-1 type dir handles reverse)
10291           (unless gnus-article-mime-handles ;; Don't destroy this case.
10292             (mm-destroy-parts handles)))))))
10293
10294 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10295   (if (stringp (car handle))
10296       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10297               (cdr handle))
10298     (when (if reverse
10299               (not (string-match type (mm-handle-media-type handle)))
10300             (string-match type (mm-handle-media-type handle)))
10301       (let ((file (expand-file-name
10302                    (file-name-nondirectory
10303                     (or
10304                      (mail-content-type-get
10305                       (mm-handle-disposition handle) 'filename)
10306                      (concat gnus-newsgroup-name
10307                              "." (number-to-string
10308                                   (cdr gnus-article-current)))))
10309                    dir)))
10310         (unless (file-exists-p file)
10311           (mm-save-part-to-file handle file))))))
10312
10313 ;; Summary extract commands
10314
10315 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10316   (let ((buffer-read-only nil)
10317         (article (gnus-summary-article-number))
10318         after-article b e)
10319     (unless (gnus-summary-goto-subject article)
10320       (error "No such article: %d" article))
10321     (gnus-summary-position-point)
10322     ;; If all commands are to be bunched up on one line, we collect
10323     ;; them here.
10324     (unless gnus-view-pseudos-separately
10325       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10326             files action)
10327         (while ps
10328           (setq action (cdr (assq 'action (car ps))))
10329           (setq files (list (cdr (assq 'name (car ps)))))
10330           (while (and ps (cdr ps)
10331                       (string= (or action "1")
10332                                (or (cdr (assq 'action (cadr ps))) "2")))
10333             (push (cdr (assq 'name (cadr ps))) files)
10334             (setcdr ps (cddr ps)))
10335           (when files
10336             (when (not (string-match "%s" action))
10337               (push " " files))
10338             (push " " files)
10339             (when (assq 'execute (car ps))
10340               (setcdr (assq 'execute (car ps))
10341                       (funcall (if (string-match "%s" action)
10342                                    'format 'concat)
10343                                action
10344                                (mapconcat
10345                                 (lambda (f)
10346                                   (if (equal f " ")
10347                                       f
10348                                     (gnus-quote-arg-for-sh-or-csh f)))
10349                                 files " ")))))
10350           (setq ps (cdr ps)))))
10351     (if (and gnus-view-pseudos (not not-view))
10352         (while pslist
10353           (when (assq 'execute (car pslist))
10354             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10355                                   (eq gnus-view-pseudos 'not-confirm)))
10356           (setq pslist (cdr pslist)))
10357       (save-excursion
10358         (while pslist
10359           (setq after-article (or (cdr (assq 'article (car pslist)))
10360                                   (gnus-summary-article-number)))
10361           (gnus-summary-goto-subject after-article)
10362           (forward-line 1)
10363           (setq b (point))
10364           (insert "    " (file-name-nondirectory
10365                           (cdr (assq 'name (car pslist))))
10366                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10367           (setq e (point))
10368           (forward-line -1)             ; back to `b'
10369           (gnus-add-text-properties
10370            b (1- e) (list 'gnus-number gnus-reffed-article-number
10371                           gnus-mouse-face-prop gnus-mouse-face))
10372           (gnus-data-enter
10373            after-article gnus-reffed-article-number
10374            gnus-unread-mark b (car pslist) 0 (- e b))
10375           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10376           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10377           (setq pslist (cdr pslist)))))))
10378
10379 (defun gnus-pseudos< (p1 p2)
10380   (let ((c1 (cdr (assq 'action p1)))
10381         (c2 (cdr (assq 'action p2))))
10382     (and c1 c2 (string< c1 c2))))
10383
10384 (defun gnus-request-pseudo-article (props)
10385   (cond ((assq 'execute props)
10386          (gnus-execute-command (cdr (assq 'execute props)))))
10387   (let ((gnus-current-article (gnus-summary-article-number)))
10388     (gnus-run-hooks 'gnus-mark-article-hook)))
10389
10390 (defun gnus-execute-command (command &optional automatic)
10391   (save-excursion
10392     (gnus-article-setup-buffer)
10393     (set-buffer gnus-article-buffer)
10394     (setq buffer-read-only nil)
10395     (let ((command (if automatic command
10396                      (read-string "Command: " (cons command 0)))))
10397       (erase-buffer)
10398       (insert "$ " command "\n\n")
10399       (if gnus-view-pseudo-asynchronously
10400           (start-process "gnus-execute" (current-buffer) shell-file-name
10401                          shell-command-switch command)
10402         (call-process shell-file-name nil t nil
10403                       shell-command-switch command)))))
10404
10405 ;; Summary kill commands.
10406
10407 (defun gnus-summary-edit-global-kill (article)
10408   "Edit the \"global\" kill file."
10409   (interactive (list (gnus-summary-article-number)))
10410   (gnus-group-edit-global-kill article))
10411
10412 (defun gnus-summary-edit-local-kill ()
10413   "Edit a local kill file applied to the current newsgroup."
10414   (interactive)
10415   (setq gnus-current-headers (gnus-summary-article-header))
10416   (gnus-group-edit-local-kill
10417    (gnus-summary-article-number) gnus-newsgroup-name))
10418
10419 ;;; Header reading.
10420
10421 (defun gnus-read-header (id &optional header)
10422   "Read the headers of article ID and enter them into the Gnus system."
10423   (let ((group gnus-newsgroup-name)
10424         (gnus-override-method
10425          (or
10426           gnus-override-method
10427           (and (gnus-news-group-p gnus-newsgroup-name)
10428                (car (gnus-refer-article-methods)))))
10429         where)
10430     ;; First we check to see whether the header in question is already
10431     ;; fetched.
10432     (if (stringp id)
10433         ;; This is a Message-ID.
10434         (setq header (or header (gnus-id-to-header id)))
10435       ;; This is an article number.
10436       (setq header (or header (gnus-summary-article-header id))))
10437     (if (and header
10438              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10439         ;; We have found the header.
10440         header
10441       ;; If this is a sparse article, we have to nix out its
10442       ;; previous entry in the thread hashtb.
10443       (when (and header
10444                  (gnus-summary-article-sparse-p (mail-header-number header)))
10445         (let* ((parent (gnus-parent-id (mail-header-references header)))
10446                (thread (and parent (gnus-id-to-thread parent))))
10447           (when thread
10448             (delq (assq header thread) thread))))
10449       ;; We have to really fetch the header to this article.
10450       (save-excursion
10451         (set-buffer nntp-server-buffer)
10452         (when (setq where (gnus-request-head id group))
10453           (nnheader-fold-continuation-lines)
10454           (goto-char (point-max))
10455           (insert ".\n")
10456           (goto-char (point-min))
10457           (insert "211 ")
10458           (princ (cond
10459                   ((numberp id) id)
10460                   ((cdr where) (cdr where))
10461                   (header (mail-header-number header))
10462                   (t gnus-reffed-article-number))
10463                  (current-buffer))
10464           (insert " Article retrieved.\n"))
10465         (if (or (not where)
10466                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10467             ()                          ; Malformed head.
10468           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10469             (when (and (stringp id)
10470                        (not (string= (gnus-group-real-name group)
10471                                      (car where))))
10472               ;; If we fetched by Message-ID and the article came
10473               ;; from a different group, we fudge some bogus article
10474               ;; numbers for this article.
10475               (mail-header-set-number header gnus-reffed-article-number))
10476             (save-excursion
10477               (set-buffer gnus-summary-buffer)
10478               (decf gnus-reffed-article-number)
10479               (gnus-remove-header (mail-header-number header))
10480               (push header gnus-newsgroup-headers)
10481               (setq gnus-current-headers header)
10482               (push (mail-header-number header) gnus-newsgroup-limit)))
10483           header)))))
10484
10485 (defun gnus-remove-header (number)
10486   "Remove header NUMBER from `gnus-newsgroup-headers'."
10487   (if (and gnus-newsgroup-headers
10488            (= number (mail-header-number (car gnus-newsgroup-headers))))
10489       (pop gnus-newsgroup-headers)
10490     (let ((headers gnus-newsgroup-headers))
10491       (while (and (cdr headers)
10492                   (not (= number (mail-header-number (cadr headers)))))
10493         (pop headers))
10494       (when (cdr headers)
10495         (setcdr headers (cddr headers))))))
10496
10497 ;;;
10498 ;;; summary highlights
10499 ;;;
10500
10501 (defun gnus-highlight-selected-summary ()
10502   "Highlight selected article in summary buffer."
10503   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10504   (when gnus-summary-selected-face
10505     (save-excursion
10506       (let* ((beg (progn (beginning-of-line) (point)))
10507              (end (progn (end-of-line) (point)))
10508              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10509              (from (if (get-text-property beg gnus-mouse-face-prop)
10510                        beg
10511                      (or (next-single-property-change
10512                           beg gnus-mouse-face-prop nil end)
10513                          beg)))
10514              (to
10515               (if (= from end)
10516                   (- from 2)
10517                 (or (next-single-property-change
10518                      from gnus-mouse-face-prop nil end)
10519                     end))))
10520         ;; If no mouse-face prop on line we will have to = from = end,
10521         ;; so we highlight the entire line instead.
10522         (when (= (+ to 2) from)
10523           (setq from beg)
10524           (setq to end))
10525         (if gnus-newsgroup-selected-overlay
10526             ;; Move old overlay.
10527             (gnus-move-overlay
10528              gnus-newsgroup-selected-overlay from to (current-buffer))
10529           ;; Create new overlay.
10530           (gnus-overlay-put
10531            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10532            'face gnus-summary-selected-face))))))
10533
10534 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10535 (defun gnus-summary-highlight-line ()
10536   "Highlight current line according to `gnus-summary-highlight'."
10537   (let* ((list gnus-summary-highlight)
10538          (p (point))
10539          (end (progn (end-of-line) (point)))
10540          ;; now find out where the line starts and leave point there.
10541          (beg (progn (beginning-of-line) (point)))
10542          (article (gnus-summary-article-number))
10543          (score (or (cdr (assq (or article gnus-current-article)
10544                                gnus-newsgroup-scored))
10545                     gnus-summary-default-score 0))
10546          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10547          (inhibit-read-only t))
10548     ;; Eval the cars of the lists until we find a match.
10549     (let ((default gnus-summary-default-score)
10550           (default-high gnus-summary-default-high-score)
10551           (default-low gnus-summary-default-low-score))
10552       (while (and list
10553                   (not (eval (caar list))))
10554         (setq list (cdr list))))
10555     (let ((face (cdar list)))
10556       (unless (eq face (get-text-property beg 'face))
10557         (gnus-put-text-property-excluding-characters-with-faces
10558          beg end 'face
10559          (setq face (if (boundp face) (symbol-value face) face)))
10560         (when gnus-summary-highlight-line-function
10561           (funcall gnus-summary-highlight-line-function article face))))
10562     (goto-char p)))
10563
10564 (defun gnus-update-read-articles (group unread &optional compute)
10565   "Update the list of read articles in GROUP."
10566   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10567          (entry (gnus-gethash group gnus-newsrc-hashtb))
10568          (info (nth 2 entry))
10569          (prev 1)
10570          (unread (sort (copy-sequence unread) '<))
10571          read)
10572     (if (or (not info) (not active))
10573         ;; There is no info on this group if it was, in fact,
10574         ;; killed.  Gnus stores no information on killed groups, so
10575         ;; there's nothing to be done.
10576         ;; One could store the information somewhere temporarily,
10577         ;; perhaps...  Hmmm...
10578         ()
10579       ;; Remove any negative articles numbers.
10580       (while (and unread (< (car unread) 0))
10581         (setq unread (cdr unread)))
10582       ;; Remove any expired article numbers
10583       (while (and unread (< (car unread) (car active)))
10584         (setq unread (cdr unread)))
10585       ;; Compute the ranges of read articles by looking at the list of
10586       ;; unread articles.
10587       (while unread
10588         (when (/= (car unread) prev)
10589           (push (if (= prev (1- (car unread))) prev
10590                   (cons prev (1- (car unread))))
10591                 read))
10592         (setq prev (1+ (car unread)))
10593         (setq unread (cdr unread)))
10594       (when (<= prev (cdr active))
10595         (push (cons prev (cdr active)) read))
10596       (setq read (if (> (length read) 1) (nreverse read) read))
10597       (if compute
10598           read
10599         (save-excursion
10600           (let (setmarkundo)
10601             ;; Propagate the read marks to the backend.
10602             (when (gnus-check-backend-function 'request-set-mark group)
10603               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10604                     (add (gnus-remove-from-range read (gnus-info-read info))))
10605                 (when (or add del)
10606                   (unless (gnus-check-group group)
10607                     (error "Can't open server for %s" group))
10608                   (gnus-request-set-mark
10609                    group (delq nil (list (if add (list add 'add '(read)))
10610                                          (if del (list del 'del '(read))))))
10611                   (setq setmarkundo
10612                         `(gnus-request-set-mark
10613                           ,group
10614                           ',(delq nil (list
10615                                        (if del (list del 'add '(read)))
10616                                        (if add (list add 'del '(read))))))))))
10617             (set-buffer gnus-group-buffer)
10618             (gnus-undo-register
10619               `(progn
10620                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10621                  (gnus-info-set-read ',info ',(gnus-info-read info))
10622                  (gnus-get-unread-articles-in-group ',info
10623                                                     (gnus-active ,group))
10624                  (gnus-group-update-group ,group t)
10625                  ,setmarkundo))))
10626         ;; Enter this list into the group info.
10627         (gnus-info-set-read info read)
10628         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10629         (gnus-get-unread-articles-in-group info (gnus-active group))
10630         t))))
10631
10632 (defun gnus-offer-save-summaries ()
10633   "Offer to save all active summary buffers."
10634   (let (buffers)
10635     ;; Go through all buffers and find all summaries.
10636     (dolist (buffer (buffer-list))
10637       (when (and (setq buffer (buffer-name buffer))
10638                  (string-match "Summary" buffer)
10639                  (save-excursion
10640                    (set-buffer buffer)
10641                    ;; We check that this is, indeed, a summary buffer.
10642                    (and (eq major-mode 'gnus-summary-mode)
10643                         ;; Also make sure this isn't bogus.
10644                         gnus-newsgroup-prepared
10645                         ;; Also make sure that this isn't a
10646                         ;; dead summary buffer.
10647                         (not gnus-dead-summary-mode))))
10648         (push buffer buffers)))
10649     ;; Go through all these summary buffers and offer to save them.
10650     (when buffers
10651       (save-excursion
10652         (map-y-or-n-p
10653          "Update summary buffer %s? "
10654          (lambda (buf)
10655            (switch-to-buffer buf)
10656            (gnus-summary-exit))
10657          buffers)))))
10658
10659
10660 ;;; @ for mime-partial
10661 ;;;
10662
10663 (defun gnus-request-partial-message ()
10664   (save-excursion
10665     (let ((number (gnus-summary-article-number))
10666           (group gnus-newsgroup-name)
10667           (mother gnus-article-buffer))
10668       (set-buffer (get-buffer-create " *Partial Article*"))
10669       (erase-buffer)
10670       (setq mime-preview-buffer mother)
10671       (gnus-request-article-this-buffer number group)
10672       (mime-parse-buffer)
10673       )))
10674
10675 (autoload 'mime-combine-message/partial-pieces-automatically
10676   "mime-partial"
10677   "Internal method to combine message/partial messages automatically.")
10678
10679 (mime-add-condition
10680  'action '((type . message)(subtype . partial)
10681            (major-mode . gnus-original-article-mode)
10682            (method . mime-combine-message/partial-pieces-automatically)
10683            (summary-buffer-exp . gnus-summary-buffer)
10684            (request-partial-message-method . gnus-request-partial-message)
10685            ))
10686
10687
10688 ;;; @ for message/rfc822
10689 ;;;
10690
10691 (defun gnus-mime-extract-message/rfc822 (entity situation)
10692   (let (group article num cwin swin cur)
10693     (with-temp-buffer
10694       (mime-insert-entity-content entity)
10695       (setq group (or (cdr (assq 'group situation))
10696                       (completing-read "Group: "
10697                                        gnus-active-hashtb
10698                                        nil
10699                                        (gnus-read-active-file-p)
10700                                        gnus-newsgroup-name))
10701             article (gnus-request-accept-article group)))
10702     (when (and (consp article)
10703                (numberp (setq article (cdr article))))
10704       (setq num (1+ (or (cdr (assq 'number situation)) 0))
10705             cwin (get-buffer-window (current-buffer) t))
10706       (save-window-excursion
10707         (if (setq swin (get-buffer-window gnus-summary-buffer t))
10708             (select-window swin)
10709           (set-buffer gnus-summary-buffer))
10710         (setq cur gnus-current-article)
10711         (forward-line num)
10712         (let (gnus-show-threads)
10713           (gnus-summary-goto-subject article t))
10714         (gnus-summary-clear-mark-forward 1)
10715         (gnus-summary-goto-subject cur))
10716       (when (and cwin (window-frame cwin))
10717         (select-frame (window-frame cwin)))
10718       (when (boundp 'mime-acting-situation-to-override)
10719         (set-alist 'mime-acting-situation-to-override
10720                    'group
10721                    group)
10722         (set-alist 'mime-acting-situation-to-override
10723                    'after-method
10724                    `(progn
10725                       (save-current-buffer
10726                         (set-buffer gnus-group-buffer)
10727                         (gnus-activate-group ,group))
10728                       (gnus-summary-goto-article ,cur
10729                                                  gnus-show-all-headers)))
10730         (set-alist 'mime-acting-situation-to-override
10731                    'number num)))))
10732
10733 (mime-add-condition
10734  'action '((type . message)(subtype . rfc822)
10735            (major-mode . gnus-original-article-mode)
10736            (method . gnus-mime-extract-message/rfc822)
10737            (mode . "extract")
10738            ))
10739
10740 (mime-add-condition
10741  'action '((type . message)(subtype . news)
10742            (major-mode . gnus-original-article-mode)
10743            (method . gnus-mime-extract-message/rfc822)
10744            (mode . "extract")
10745            ))
10746
10747 (defun gnus-mime-extract-multipart (entity situation)
10748   (let ((children (mime-entity-children entity))
10749         mime-acting-situation-to-override
10750         f)
10751     (while children
10752       (mime-play-entity (car children)
10753                         (cons (assq 'mode situation)
10754                               mime-acting-situation-to-override))
10755       (setq children (cdr children)))
10756     (if (setq f (cdr (assq 'after-method
10757                            mime-acting-situation-to-override)))
10758         (eval f)
10759       )))
10760
10761 (mime-add-condition
10762  'action '((type . multipart)
10763            (method . gnus-mime-extract-multipart)
10764            (mode . "extract")
10765            )
10766  'with-default)
10767
10768
10769 ;;; @ end
10770 ;;;
10771
10772 (defun gnus-summary-setup-default-charset ()
10773   "Setup newsgroup default charset."
10774   (if (equal gnus-newsgroup-name "nndraft:drafts")
10775       (setq gnus-newsgroup-charset nil)
10776     (let* ((ignored-charsets
10777             (or gnus-newsgroup-ephemeral-ignored-charsets
10778                 (append
10779                  (and gnus-newsgroup-name
10780                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10781                  gnus-newsgroup-ignored-charsets))))
10782       (setq gnus-newsgroup-charset
10783             (or gnus-newsgroup-ephemeral-charset
10784                 (and gnus-newsgroup-name
10785                      (gnus-parameter-charset gnus-newsgroup-name))
10786                 gnus-default-charset))
10787       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10788            ignored-charsets))))
10789
10790 ;;;
10791 ;;; Mime Commands
10792 ;;;
10793
10794 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10795   "Display the current article buffer fully MIME-buttonized.
10796 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10797 treated as multipart/mixed."
10798   (interactive "P")
10799   (require 'gnus-art)
10800   (let ((gnus-unbuttonized-mime-types nil)
10801         (gnus-mime-display-multipart-as-mixed show-all-parts))
10802     (gnus-summary-show-article)))
10803
10804 (defun gnus-summary-repair-multipart (article)
10805   "Add a Content-Type header to a multipart article without one."
10806   (interactive (list (gnus-summary-article-number)))
10807   (gnus-with-article article
10808     (message-narrow-to-head)
10809     (message-remove-header "Mime-Version")
10810     (goto-char (point-max))
10811     (insert "Mime-Version: 1.0\n")
10812     (widen)
10813     (when (search-forward "\n--" nil t)
10814       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10815         (message-narrow-to-head)
10816         (message-remove-header "Content-Type")
10817         (goto-char (point-max))
10818         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10819                         separator))
10820         (widen))))
10821   (let (gnus-mark-article-hook)
10822     (gnus-summary-select-article t t nil article)))
10823
10824 (defun gnus-summary-toggle-display-buttonized ()
10825   "Toggle the buttonizing of the article buffer."
10826   (interactive)
10827   (require 'gnus-art)
10828   (if (setq gnus-inhibit-mime-unbuttonizing
10829             (not gnus-inhibit-mime-unbuttonizing))
10830       (let ((gnus-unbuttonized-mime-types nil))
10831         (gnus-summary-show-article))
10832     (gnus-summary-show-article)))
10833
10834 ;;;
10835 ;;; Intelli-mouse commmands
10836 ;;;
10837
10838 (defun gnus-wheel-summary-scroll (event)
10839   (interactive "e")
10840   (let ((amount (if (memq 'shift (event-modifiers event))
10841                     (car gnus-wheel-scroll-amount)
10842                   (cdr gnus-wheel-scroll-amount)))
10843         (direction (- (* (static-if (featurep 'xemacs)
10844                              (event-button event)
10845                            (cond ((eq 'mouse-4 (event-basic-type event))
10846                                   4)
10847                                  ((eq 'mouse-5 (event-basic-type event))
10848                                   5)))
10849                          2) 9))
10850         edge)
10851     (gnus-summary-scroll-up (* amount direction))
10852     (when (gnus-eval-in-buffer-window gnus-article-buffer
10853             (save-restriction
10854               (widen)
10855               (and (if (< 0 direction)
10856                        (gnus-article-next-page 0)
10857                      (gnus-article-prev-page 0)
10858                      (bobp))
10859                    (if (setq edge (get-text-property
10860                                    (point-min) 'gnus-wheel-edge))
10861                        (setq edge (* edge direction))
10862                      (setq edge -1))
10863                    (or (plusp edge)
10864                        (let ((buffer-read-only nil)
10865                              (inhibit-read-only t))
10866                          (put-text-property (point-min) (point-max)
10867                                             'gnus-wheel-edge direction)
10868                          nil))
10869                    (or (> edge gnus-wheel-edge-resistance)
10870                        (let ((buffer-read-only nil)
10871                              (inhibit-read-only t))
10872                          (put-text-property (point-min) (point-max)
10873                                             'gnus-wheel-edge
10874                                             (* (1+ edge) direction))
10875                          nil))
10876                    (eq last-command 'gnus-wheel-summary-scroll))))
10877       (gnus-summary-next-article nil nil (minusp direction)))))
10878
10879 (defun gnus-wheel-install ()
10880   "Enable mouse wheel support on summary window."
10881   (when gnus-use-wheel
10882     (let ((keys
10883            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10884       (dolist (key keys)
10885         (define-key gnus-summary-mode-map key
10886           'gnus-wheel-summary-scroll)))))
10887
10888 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10889
10890 ;;;
10891 ;;; Traditional PGP commmands
10892 ;;;
10893
10894 (defun gnus-summary-decrypt-article (&optional force)
10895   "Decrypt the current article in traditional PGP way.
10896 This will have permanent effect only in mail groups.
10897 If FORCE is non-nil, allow editing of articles even in read-only
10898 groups."
10899   (interactive "P")
10900   (gnus-summary-select-article t)
10901   (gnus-eval-in-buffer-window gnus-article-buffer
10902     (save-excursion
10903       (save-restriction
10904         (widen)
10905         (goto-char (point-min))
10906         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10907           (error "Not a traditional PGP message!"))
10908         (let ((armor-start (match-beginning 0)))
10909           (if (and (pgg-decrypt-region armor-start (point-max))
10910                    (or force (not (gnus-group-read-only-p))))
10911               (let ((inhibit-read-only t)
10912                     buffer-read-only)
10913                 (delete-region armor-start
10914                                (progn
10915                                  (re-search-forward "^-+END PGP" nil t)
10916                                  (beginning-of-line 2)
10917                                  (point)))
10918                 (insert-buffer-substring pgg-output-buffer))))))))
10919
10920 (defun gnus-summary-verify-article ()
10921   "Verify the current article in traditional PGP way."
10922   (interactive)
10923   (save-excursion
10924     (set-buffer gnus-original-article-buffer)
10925     (goto-char (point-min))
10926     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10927       (error "Not a traditional PGP message!"))
10928     (re-search-forward "^-+END PGP" nil t)
10929     (beginning-of-line 2)
10930     (call-interactively (function pgg-verify-region))))
10931
10932 ;;;
10933 ;;; Generic summary marking commands
10934 ;;;
10935
10936 (defvar gnus-summary-marking-alist
10937   '((read gnus-del-mark "d")
10938     (unread gnus-unread-mark "u")
10939     (ticked gnus-ticked-mark "!")
10940     (dormant gnus-dormant-mark "?")
10941     (expirable gnus-expirable-mark "e"))
10942   "An alist of names/marks/keystrokes.")
10943
10944 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10945 (defvar gnus-summary-mark-map)
10946
10947 (defun gnus-summary-make-all-marking-commands ()
10948   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10949   (dolist (elem gnus-summary-marking-alist)
10950     (apply 'gnus-summary-make-marking-command elem)))
10951
10952 (defun gnus-summary-make-marking-command (name mark keystroke)
10953   (let ((map (make-sparse-keymap)))
10954     (define-key gnus-summary-generic-mark-map keystroke map)
10955     (dolist (lway `((next "next" next nil "n")
10956                     (next-unread "next unread" next t "N")
10957                     (prev "previous" prev nil "p")
10958                     (prev-unread "previous unread" prev t "P")
10959                     (nomove "" nil nil ,keystroke)))
10960       (let ((func (gnus-summary-make-marking-command-1
10961                    mark (car lway) lway name)))
10962         (setq func (eval func))
10963         (define-key map (nth 4 lway) func)))))
10964
10965 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10966   `(defun ,(intern
10967             (format "gnus-summary-put-mark-as-%s%s"
10968                     name (if (eq way 'nomove)
10969                              ""
10970                            (concat "-" (symbol-name way)))))
10971      (n)
10972      ,(format
10973        "Mark the current article as %s%s.
10974 If N, the prefix, then repeat N times.
10975 If N is negative, move in reverse order.
10976 The difference between N and the actual number of articles marked is
10977 returned."
10978        name (car (cdr lway)))
10979      (interactive "p")
10980      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10981
10982 (defun gnus-summary-generic-mark (n mark move unread)
10983   "Mark N articles with MARK."
10984   (unless (eq major-mode 'gnus-summary-mode)
10985     (error "This command can only be used in the summary buffer"))
10986   (gnus-summary-show-thread)
10987   (let ((nummove
10988          (cond
10989           ((eq move 'next) 1)
10990           ((eq move 'prev) -1)
10991           (t 0))))
10992     (if (zerop nummove)
10993         (setq n 1)
10994       (when (< n 0)
10995         (setq n (abs n)
10996               nummove (* -1 nummove))))
10997     (while (and (> n 0)
10998                 (gnus-summary-mark-article nil mark)
10999                 (zerop (gnus-summary-next-subject nummove unread t)))
11000       (setq n (1- n)))
11001     (when (/= 0 n)
11002       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11003     (gnus-summary-recenter)
11004     (gnus-summary-position-point)
11005     (gnus-set-mode-line 'summary)
11006     n))
11007
11008 (defun gnus-summary-insert-articles (articles)
11009   (when (setq articles
11010               (gnus-set-difference articles
11011                                    (mapcar (lambda (h) (mail-header-number h))
11012                                            gnus-newsgroup-headers)))
11013     (setq gnus-newsgroup-headers
11014           (merge 'list
11015                  gnus-newsgroup-headers
11016                  (gnus-fetch-headers articles)
11017                  'gnus-article-sort-by-number))
11018     ;; Suppress duplicates?
11019     (when gnus-suppress-duplicates
11020       (gnus-dup-suppress-articles))
11021
11022     ;; We might want to build some more threads first.
11023     (when (and gnus-fetch-old-headers
11024                (eq gnus-headers-retrieved-by 'nov))
11025       (if (eq gnus-fetch-old-headers 'invisible)
11026           (gnus-build-all-threads)
11027         (gnus-build-old-threads)))
11028     ;; Let the Gnus agent mark articles as read.
11029     (when gnus-agent
11030       (gnus-agent-get-undownloaded-list))
11031     ;; Remove list identifiers from subject
11032     (when gnus-list-identifiers
11033       (gnus-summary-remove-list-identifiers))
11034     ;; First and last article in this newsgroup.
11035     (when gnus-newsgroup-headers
11036       (setq gnus-newsgroup-begin
11037             (mail-header-number (car gnus-newsgroup-headers))
11038             gnus-newsgroup-end
11039             (mail-header-number
11040              (gnus-last-element gnus-newsgroup-headers))))
11041     (when gnus-use-scoring
11042       (gnus-possibly-score-headers))))
11043
11044 (defun gnus-summary-insert-old-articles (&optional all)
11045   "Insert all old articles in this group.
11046 If ALL is non-nil, already read articles become readable.
11047 If ALL is a number, fetch this number of articles."
11048   (interactive "P")
11049   (prog1
11050       (let ((old (mapcar 'car gnus-newsgroup-data))
11051             (i (car gnus-newsgroup-active))
11052             older len)
11053         (while (<= i (cdr gnus-newsgroup-active))
11054           (or (memq i old) (push i older))
11055           (incf i))
11056         (setq len (length older))
11057         (cond
11058          ((null older) nil)
11059          ((numberp all)
11060           (if (< all len)
11061               (setq older (subseq older 0 all))))
11062          (all nil)
11063          (t
11064           (if (and (numberp gnus-large-newsgroup)
11065                    (> len gnus-large-newsgroup))
11066               (let ((input
11067                      (read-string
11068                       (format
11069                        "How many articles from %s (default %d): "
11070                        (gnus-limit-string
11071                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
11072                        len))))
11073                 (unless (string-match "^[ \t]*$" input)
11074                   (setq all (string-to-number input))
11075                   (if (< all len)
11076                       (setq older (subseq older 0 all))))))))
11077         (if (not older)
11078             (message "No old news.")
11079           (gnus-summary-insert-articles older)
11080           (gnus-summary-limit (gnus-union older old))))
11081     (gnus-summary-position-point)))
11082
11083 (defun gnus-summary-insert-new-articles ()
11084   "Insert all new articles in this group."
11085   (interactive)
11086   (prog1
11087       (let ((old (mapcar 'car gnus-newsgroup-data))
11088             (old-active gnus-newsgroup-active)
11089             (nnmail-fetched-sources (list t))
11090             i new)
11091         (setq gnus-newsgroup-active
11092               (gnus-activate-group gnus-newsgroup-name 'scan))
11093         (setq i (1+ (cdr old-active)))
11094         (while (<= i (cdr gnus-newsgroup-active))
11095           (push i new)
11096           (incf i))
11097         (if (not new)
11098             (message "No gnus is bad news.")
11099           (setq new (nreverse new))
11100           (gnus-summary-insert-articles new)
11101           (setq gnus-newsgroup-unreads
11102                 (append gnus-newsgroup-unreads new))
11103           (gnus-summary-limit (gnus-union old new))))
11104     (gnus-summary-position-point)))
11105
11106 (gnus-summary-make-all-marking-commands)
11107
11108 (gnus-ems-redefine)
11109
11110 (provide 'gnus-sum)
11111
11112 (run-hooks 'gnus-sum-load-hook)
11113
11114 ;;; gnus-sum.el ends here