Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify" 
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61
62 (defcustom gnus-kill-summary-on-exit t
63   "*If non-nil, kill the summary buffer when you exit from it.
64 If nil, the summary will become a \"*Dead Summary*\" buffer, and
65 it will be killed sometime later."
66   :group 'gnus-summary-exit
67   :type 'boolean)
68
69 (defcustom gnus-fetch-old-headers nil
70   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
71 If an unread article in the group refers to an older, already read (or
72 just marked as read) article, the old article will not normally be
73 displayed in the Summary buffer.  If this variable is non-nil, Gnus
74 will attempt to grab the headers to the old articles, and thereby
75 build complete threads.  If it has the value `some', only enough
76 headers to connect otherwise loose threads will be displayed.  This
77 variable can also be a number.  In that case, no more than that number
78 of old headers will be fetched.  If it has the value `invisible', all
79 old headers will be fetched, but none will be displayed.
80
81 The server has to support NOV for any of this to work."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const some)
85                  number
86                  (sexp :menu-tag "other" t)))
87
88 (defcustom gnus-refer-thread-limit 200
89   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
90 If t, fetch all the available old headers."
91   :group 'gnus-thread
92   :type '(choice number
93                  (sexp :menu-tag "other" t)))
94
95 (defcustom gnus-summary-make-false-root 'adopt
96   "*nil means that Gnus won't gather loose threads.
97 If the root of a thread has expired or been read in a previous
98 session, the information necessary to build a complete thread has been
99 lost.  Instead of having many small sub-threads from this original thread
100 scattered all over the summary buffer, Gnus can gather them.
101
102 If non-nil, Gnus will try to gather all loose sub-threads from an
103 original thread into one large thread.
104
105 If this variable is non-nil, it should be one of `none', `adopt',
106 `dummy' or `empty'.
107
108 If this variable is `none', Gnus will not make a false root, but just
109 present the sub-threads after another.
110 If this variable is `dummy', Gnus will create a dummy root that will
111 have all the sub-threads as children.
112 If this variable is `adopt', Gnus will make one of the \"children\"
113 the parent and mark all the step-children as such.
114 If this variable is `empty', the \"children\" are printed with empty
115 subject fields.  (Or rather, they will be printed with a string
116 given by the `gnus-summary-same-subject' variable.)"
117   :group 'gnus-thread
118   :type '(choice (const :tag "off" nil)
119                  (const none)
120                  (const dummy)
121                  (const adopt)
122                  (const empty)))
123
124 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
125   "*A regexp to match subjects to be excluded from loose thread gathering.
126 As loose thread gathering is done on subjects only, that means that
127 there can be many false gatherings performed.  By rooting out certain
128 common subjects, gathering might become saner."
129   :group 'gnus-thread
130   :type 'regexp)
131
132 (defcustom gnus-summary-gather-subject-limit nil
133   "*Maximum length of subject comparisons when gathering loose threads.
134 Use nil to compare full subjects.  Setting this variable to a low
135 number will help gather threads that have been corrupted by
136 newsreaders chopping off subject lines, but it might also mean that
137 unrelated articles that have subject that happen to begin with the
138 same few characters will be incorrectly gathered.
139
140 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
141 comparing subjects."
142   :group 'gnus-thread
143   :type '(choice (const :tag "off" nil)
144                  (const fuzzy)
145                  (sexp :menu-tag "on" t)))
146
147 (defcustom gnus-simplify-subject-functions nil
148   "List of functions taking a string argument that simplify subjects.
149 The functions are applied recursively.
150
151 Useful functions to put in this list include: `gnus-simplify-subject-re',
152 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
153   :group 'gnus-thread
154   :type '(repeat function))
155
156 (defcustom gnus-simplify-ignored-prefixes nil
157   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  regexp))
161
162 (defcustom gnus-build-sparse-threads nil
163   "*If non-nil, fill in the gaps in threads.
164 If `some', only fill in the gaps that are needed to tie loose threads
165 together.  If `more', fill in all leaf nodes that Gnus can find.  If
166 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  (const some)
170                  (const more)
171                  (sexp :menu-tag "all" t)))
172
173 (defcustom gnus-summary-thread-gathering-function
174   'gnus-gather-threads-by-subject
175   "*Function used for gathering loose threads.
176 There are two pre-defined functions: `gnus-gather-threads-by-subject',
177 which only takes Subjects into consideration; and
178 `gnus-gather-threads-by-references', which compared the References
179 headers of the articles to find matches."
180   :group 'gnus-thread
181   :type '(radio (function-item gnus-gather-threads-by-subject)
182                 (function-item gnus-gather-threads-by-references)
183                 (function :tag "other")))
184
185 (defcustom gnus-summary-same-subject ""
186   "*String indicating that the current article has the same subject as the previous.
187 This variable will only be used if the value of
188 `gnus-summary-make-false-root' is `empty'."
189   :group 'gnus-summary-format
190   :type 'string)
191
192 (defcustom gnus-summary-goto-unread t
193   "*If t, many commands will go to the next unread article.
194 This applies to marking commands as well as other commands that
195 \"naturally\" select the next article, like, for instance, `SPC' at
196 the end of an article.
197
198 If nil, the marking commands do NOT go to the next unread article
199 (they go to the next article instead).  If `never', commands that
200 usually go to the next unread article, will go to the next article,
201 whether it is read or not."
202   :group 'gnus-summary-marks
203   :link '(custom-manual "(gnus)Setting Marks")
204   :type '(choice (const :tag "off" nil)
205                  (const never)
206                  (sexp :menu-tag "on" t)))
207
208 (defcustom gnus-summary-default-score 0
209   "*Default article score level.
210 All scores generated by the score files will be added to this score.
211 If this variable is nil, scoring will be disabled."
212   :group 'gnus-score-default
213   :type '(choice (const :tag "disable")
214                  integer))
215
216 (defcustom gnus-summary-default-high-score 0
217   "*Default threshold for a high scored article.
218 An article will be highlighted as high scored if its score is greater
219 than this score."
220   :group 'gnus-score-default
221   :type 'integer)
222
223 (defcustom gnus-summary-default-low-score 0
224   "*Default threshold for a low scored article.
225 An article will be highlighted as low scored if its score is smaller
226 than this score."
227   :group 'gnus-score-default
228   :type 'integer)
229
230 (defcustom gnus-summary-zcore-fuzz 0
231   "*Fuzziness factor for the zcore in the summary buffer.
232 Articles with scores closer than this to `gnus-summary-default-score'
233 will not be marked."
234   :group 'gnus-summary-format
235   :type 'integer)
236
237 (defcustom gnus-simplify-subject-fuzzy-regexp nil
238   "*Strings to be removed when doing fuzzy matches.
239 This can either be a regular expression or list of regular expressions
240 that will be removed from subject strings if fuzzy subject
241 simplification is selected."
242   :group 'gnus-thread
243   :type '(repeat regexp))
244
245 (defcustom gnus-show-threads t
246   "*If non-nil, display threads in summary mode."
247   :group 'gnus-thread
248   :type 'boolean)
249
250 (defcustom gnus-thread-hide-subtree nil
251   "*If non-nil, hide all threads initially.
252 This can be a predicate specifier which says which threads to hide.
253 If threads are hidden, you have to run the command
254 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
255 to expose hidden threads."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-killed t
260   "*If non-nil, hide killed threads automatically."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-ignore-subject t
265   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
266 If nil, articles that have different subjects from their parents will
267 start separate threads."
268   :group 'gnus-thread
269   :type 'boolean)
270
271 (defcustom gnus-thread-operation-ignore-subject t
272   "*If non-nil, subjects will be ignored when doing thread commands.
273 This affects commands like `gnus-summary-kill-thread' and
274 `gnus-summary-lower-thread'.
275
276 If this variable is nil, articles in the same thread with different
277 subjects will not be included in the operation in question.  If this
278 variable is `fuzzy', only articles that have subjects that are fuzzily
279 equal will be included."
280   :group 'gnus-thread
281   :type '(choice (const :tag "off" nil)
282                  (const fuzzy)
283                  (sexp :tag "on" t)))
284
285 (defcustom gnus-thread-indent-level 4
286   "*Number that says how much each sub-thread should be indented."
287   :group 'gnus-thread
288   :type 'integer)
289
290 (defcustom gnus-auto-extend-newsgroup t
291   "*If non-nil, extend newsgroup forward and backward when requested."
292   :group 'gnus-summary-choose
293   :type 'boolean)
294
295 (defcustom gnus-auto-select-first t
296   "*If non-nil, select the article under point.
297 Which article this is is controlled by the `gnus-auto-select-subject'
298 variable.
299
300 If you want to prevent automatic selection of articles in some
301 newsgroups, set the variable to nil in `gnus-select-group-hook'."
302   :group 'gnus-group-select
303   :type '(choice (const :tag "none" nil)
304                  (sexp :menu-tag "first" t)))
305
306 (defcustom gnus-auto-select-subject 'unread
307   "*Says what subject to place under point when entering a group.
308
309 This variable can either be the symbols `first' (place point on the
310 first subject), `unread' (place point on the subject line of the first
311 unread article), `best' (place point on the subject line of the
312 higest-scored article), `unseen' (place point on the subject line of
313 the first unseen article), 'unseen-or-unread' (place point on the subject
314 line of the first unseen article or, if all article have been seen, on the
315 subject line of the first unread article), or a function to be called to
316 place point on some subject line."
317   :group 'gnus-group-select
318   :type '(choice (const best)
319                  (const unread)
320                  (const first)
321                  (const unseen)
322                  (const unseen-or-unread)))
323
324 (defcustom gnus-dont-select-after-jump-to-other-group nil
325   "If non-nil, don't select the first unread article after entering the
326 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
327 it is depend on the value of `gnus-auto-select-first' whether to select
328 or not."
329   :group 'gnus-group-select
330   :type 'boolean)
331
332 (defcustom gnus-auto-select-next t
333   "*If non-nil, offer to go to the next group from the end of the previous.
334 If the value is t and the next newsgroup is empty, Gnus will exit
335 summary mode and go back to group mode.  If the value is neither nil
336 nor t, Gnus will select the following unread newsgroup.  In
337 particular, if the value is the symbol `quietly', the next unread
338 newsgroup will be selected without any confirmation, and if it is
339 `almost-quietly', the next group will be selected without any
340 confirmation if you are located on the last article in the group.
341 Finally, if this variable is `slightly-quietly', the `Z n' command
342 will go to the next group without confirmation."
343   :group 'gnus-summary-maneuvering
344   :type '(choice (const :tag "off" nil)
345                  (const quietly)
346                  (const almost-quietly)
347                  (const slightly-quietly)
348                  (sexp :menu-tag "on" t)))
349
350 (defcustom gnus-auto-select-same nil
351   "*If non-nil, select the next article with the same subject.
352 If there are no more articles with the same subject, go to
353 the first unread article."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-summary-check-current nil
358   "*If non-nil, consider the current article when moving.
359 The \"unread\" movement commands will stay on the same line if the
360 current article is unread."
361   :group 'gnus-summary-maneuvering
362   :type 'boolean)
363
364 (defcustom gnus-auto-center-summary t
365   "*If non-nil, always center the current summary buffer.
366 In particular, if `vertical' do only vertical recentering.  If non-nil
367 and non-`vertical', do both horizontal and vertical recentering."
368   :group 'gnus-summary-maneuvering
369   :type '(choice (const :tag "none" nil)
370                  (const vertical)
371                  (integer :tag "height")
372                  (sexp :menu-tag "both" t)))
373
374 (defcustom gnus-show-all-headers nil
375   "*If non-nil, don't hide any headers."
376   :group 'gnus-article-hiding
377   :group 'gnus-article-headers
378   :type 'boolean)
379
380 (defcustom gnus-summary-ignore-duplicates nil
381   "*If non-nil, ignore articles with identical Message-ID headers."
382   :group 'gnus-summary
383   :type 'boolean)
384
385 (defcustom gnus-single-article-buffer t
386   "*If non-nil, display all articles in the same buffer.
387 If nil, each group will get its own article buffer."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-break-pages t
392   "*If non-nil, do page breaking on articles.
393 The page delimiter is specified by the `gnus-page-delimiter'
394 variable."
395   :group 'gnus-article-various
396   :type 'boolean)
397
398 (defcustom gnus-show-mime t
399   "*If non-nil, do mime processing of articles.
400 The articles will simply be fed to the function given by
401 `gnus-article-display-method-for-mime'."
402   :group 'gnus-article-mime
403   :type 'boolean)
404
405 (defcustom gnus-move-split-methods nil
406   "*Variable used to suggest where articles are to be moved to.
407 It uses the same syntax as the `gnus-split-methods' variable.
408 However, whereas `gnus-split-methods' specifies file names as targets,
409 this variable specifies group names."
410   :group 'gnus-summary-mail
411   :type '(repeat (choice (list :value (fun) function)
412                          (cons :value ("" "") regexp (repeat string))
413                          (sexp :value nil))))
414
415 (defcustom gnus-unread-mark ?\ ;;;Whitespace
416   "*Mark used for unread articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-ticked-mark ?!
421   "*Mark used for ticked articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-dormant-mark ??
426   "*Mark used for dormant articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-del-mark ?r
431   "*Mark used for del'd articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-read-mark ?R
436   "*Mark used for read articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-expirable-mark ?E
441   "*Mark used for expirable articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-killed-mark ?K
446   "*Mark used for killed articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-souped-mark ?F
451   "*Mark used for souped articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-kill-file-mark ?X
456   "*Mark used for articles killed by kill files."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-low-score-mark ?Y
461   "*Mark used for articles with a low score."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-catchup-mark ?C
466   "*Mark used for articles that are caught up."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-replied-mark ?A
471   "*Mark used for articles that have been replied to."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-forwarded-mark ?F
476   "*Mark used for articles that have been forwarded."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-recent-mark ?N
481   "*Mark used for articles that are recent."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-cached-mark ?*
486   "*Mark used for articles that are in the cache."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-saved-mark ?S
491   "*Mark used for articles that have been saved."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-unseen-mark ?.
496   "*Mark used for articles that haven't been seen."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-no-mark ?\ ;;;Whitespace
501   "*Mark used for articles that have no other secondary mark."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-ancient-mark ?O
506   "*Mark used for ancient articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-sparse-mark ?Q
511   "*Mark used for sparsely reffed articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-canceled-mark ?G
516   "*Mark used for canceled articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-duplicate-mark ?M
521   "*Mark used for duplicate articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-undownloaded-mark ?@
526   "*Mark used for articles that weren't downloaded."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-downloadable-mark ?%
531   "*Mark used for articles that are to be downloaded."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unsendable-mark ?=
536   "*Mark used for articles that won't be sent."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-score-over-mark ?+
541   "*Score mark used for articles with high scores."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-score-below-mark ?-
546   "*Score mark used for articles with low scores."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
551   "*There is no thread under the article."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-not-empty-thread-mark ?=
556   "*There is a thread under the article."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-view-pseudo-asynchronously nil
561   "*If non-nil, Gnus will view pseudo-articles asynchronously."
562   :group 'gnus-extract-view
563   :type 'boolean)
564
565 (defcustom gnus-auto-expirable-marks
566   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
567         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
568         gnus-souped-mark gnus-duplicate-mark)
569   "*The list of marks converted into expiration if a group is auto-expirable."
570   :version "21.1"
571   :group 'gnus-summary
572   :type '(repeat character))
573
574 (defcustom gnus-inhibit-user-auto-expire t
575   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
576   :version "21.1"
577   :group 'gnus-summary
578   :type 'boolean)
579
580 (defcustom gnus-view-pseudos nil
581   "*If `automatic', pseudo-articles will be viewed automatically.
582 If `not-confirm', pseudos will be viewed automatically, and the user
583 will not be asked to confirm the command."
584   :group 'gnus-extract-view
585   :type '(choice (const :tag "off" nil)
586                  (const automatic)
587                  (const not-confirm)))
588
589 (defcustom gnus-view-pseudos-separately t
590   "*If non-nil, one pseudo-article will be created for each file to be viewed.
591 If nil, all files that use the same viewing command will be given as a
592 list of parameters to that command."
593   :group 'gnus-extract-view
594   :type 'boolean)
595
596 (defcustom gnus-insert-pseudo-articles t
597   "*If non-nil, insert pseudo-articles when decoding articles."
598   :group 'gnus-extract-view
599   :type 'boolean)
600
601 (defcustom gnus-summary-dummy-line-format
602   "  %(:                          :%) %S\n"
603   "*The format specification for the dummy roots in the summary buffer.
604 It works along the same lines as a normal formatting string,
605 with some simple extensions.
606
607 %S  The subject
608
609 General format specifiers can also be used.
610 See (gnus)Formatting Variables."
611   :link '(custom-manual "(gnus)Formatting Variables")
612   :group 'gnus-threading
613   :type 'string)
614
615 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
616   "*The format specification for the summary mode line.
617 It works along the same lines as a normal formatting string,
618 with some simple extensions:
619
620 %G  Group name
621 %p  Unprefixed group name
622 %A  Current article number
623 %z  Current article score
624 %V  Gnus version
625 %U  Number of unread articles in the group
626 %e  Number of unselected articles in the group
627 %Z  A string with unread/unselected article counts
628 %g  Shortish group name
629 %S  Subject of the current article
630 %u  User-defined spec
631 %s  Current score file name
632 %d  Number of dormant articles
633 %r  Number of articles that have been marked as read in this session
634 %E  Number of articles expunged by the score files"
635   :group 'gnus-summary-format
636   :type 'string)
637
638 (defcustom gnus-list-identifiers nil
639   "Regexp that matches list identifiers to be removed from subject.
640 This can also be a list of regexps."
641   :version "21.1"
642   :group 'gnus-summary-format
643   :group 'gnus-article-hiding
644   :type '(choice (const :tag "none" nil)
645                  (regexp :value ".*")
646                  (repeat :value (".*") regexp)))
647
648 (defcustom gnus-summary-mark-below 0
649   "*Mark all articles with a score below this variable as read.
650 This variable is local to each summary buffer and usually set by the
651 score file."
652   :group 'gnus-score-default
653   :type 'integer)
654
655 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
656   "*List of functions used for sorting articles in the summary buffer.
657
658 Each function takes two articles and returns non-nil if the first
659 article should be sorted before the other.  If you use more than one
660 function, the primary sort function should be the last.  You should
661 probably always include `gnus-article-sort-by-number' in the list of
662 sorting functions -- preferably first.  Also note that sorting by date
663 is often much slower than sorting by number, and the sorting order is
664 very similar.  (Sorting by date means sorting by the time the message
665 was sent, sorting by number means sorting by arrival time.)
666
667 Ready-made functions include `gnus-article-sort-by-number',
668 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
669 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
670
671 When threading is turned on, the variable `gnus-thread-sort-functions'
672 controls how articles are sorted."
673   :group 'gnus-summary-sort
674   :type '(repeat (choice (function-item gnus-article-sort-by-number)
675                          (function-item gnus-article-sort-by-author)
676                          (function-item gnus-article-sort-by-subject)
677                          (function-item gnus-article-sort-by-date)
678                          (function-item gnus-article-sort-by-score)
679                          (function :tag "other"))))
680
681 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
682   "*List of functions used for sorting threads in the summary buffer.
683 By default, threads are sorted by article number.
684
685 Each function takes two threads and returns non-nil if the first
686 thread should be sorted before the other.  If you use more than one
687 function, the primary sort function should be the last.  You should
688 probably always include `gnus-thread-sort-by-number' in the list of
689 sorting functions -- preferably first.  Also note that sorting by date
690 is often much slower than sorting by number, and the sorting order is
691 very similar.  (Sorting by date means sorting by the time the message
692 was sent, sorting by number means sorting by arrival time.)
693
694 Ready-made functions include `gnus-thread-sort-by-number',
695 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
696 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
697 `gnus-thread-sort-by-most-recent-number',
698 `gnus-thread-sort-by-most-recent-date', and
699 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
700
701 When threading is turned off, the variable
702 `gnus-article-sort-functions' controls how articles are sorted."
703   :group 'gnus-summary-sort
704   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
705                          (function-item gnus-thread-sort-by-author)
706                          (function-item gnus-thread-sort-by-subject)
707                          (function-item gnus-thread-sort-by-date)
708                          (function-item gnus-thread-sort-by-score)
709                          (function-item gnus-thread-sort-by-total-score)
710                          (function :tag "other"))))
711
712 (defcustom gnus-thread-score-function '+
713   "*Function used for calculating the total score of a thread.
714
715 The function is called with the scores of the article and each
716 subthread and should then return the score of the thread.
717
718 Some functions you can use are `+', `max', or `min'."
719   :group 'gnus-summary-sort
720   :type 'function)
721
722 (defcustom gnus-summary-expunge-below nil
723   "All articles that have a score less than this variable will be expunged.
724 This variable is local to the summary buffers."
725   :group 'gnus-score-default
726   :type '(choice (const :tag "off" nil)
727                  integer))
728
729 (defcustom gnus-thread-expunge-below nil
730   "All threads that have a total score less than this variable will be expunged.
731 See `gnus-thread-score-function' for en explanation of what a
732 \"thread score\" is.
733
734 This variable is local to the summary buffers."
735   :group 'gnus-threading
736   :group 'gnus-score-default
737   :type '(choice (const :tag "off" nil)
738                  integer))
739
740 (defcustom gnus-summary-mode-hook nil
741   "*A hook for Gnus summary mode.
742 This hook is run before any variables are set in the summary buffer."
743   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
744   :group 'gnus-summary-various
745   :type 'hook)
746
747 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
748 (when (featurep 'xemacs)
749   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
750   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
751   (add-hook 'gnus-summary-mode-hook
752             'gnus-xmas-switch-horizontal-scrollbar-off))
753
754 (defcustom gnus-summary-menu-hook nil
755   "*Hook run after the creation of the summary mode menu."
756   :group 'gnus-summary-visual
757   :type 'hook)
758
759 (defcustom gnus-summary-exit-hook nil
760   "*A hook called on exit from the summary buffer.
761 It will be called with point in the group buffer."
762   :group 'gnus-summary-exit
763   :type 'hook)
764
765 (defcustom gnus-summary-prepare-hook nil
766   "*A hook called after the summary buffer has been generated.
767 If you want to modify the summary buffer, you can use this hook."
768   :group 'gnus-summary-various
769   :type 'hook)
770
771 (defcustom gnus-summary-prepared-hook nil
772   "*A hook called as the last thing after the summary buffer has been generated."
773   :group 'gnus-summary-various
774   :type 'hook)
775
776 (defcustom gnus-summary-generate-hook nil
777   "*A hook run just before generating the summary buffer.
778 This hook is commonly used to customize threading variables and the
779 like."
780   :group 'gnus-summary-various
781   :type 'hook)
782
783 (defcustom gnus-select-group-hook nil
784   "*A hook called when a newsgroup is selected.
785
786 If you'd like to simplify subjects like the
787 `gnus-summary-next-same-subject' command does, you can use the
788 following hook:
789
790  (add-hook gnus-select-group-hook
791            (lambda ()
792              (mapcar (lambda (header)
793                        (mail-header-set-subject
794                         header
795                         (gnus-simplify-subject
796                          (mail-header-subject header) 're-only)))
797                      gnus-newsgroup-headers)))"
798   :group 'gnus-group-select
799   :type 'hook)
800
801 (defcustom gnus-select-article-hook nil
802   "*A hook called when an article is selected."
803   :group 'gnus-summary-choose
804   :type 'hook)
805
806 (defcustom gnus-visual-mark-article-hook
807   (list 'gnus-highlight-selected-summary)
808   "*Hook run after selecting an article in the summary buffer.
809 It is meant to be used for highlighting the article in some way.  It
810 is not run if `gnus-visual' is nil."
811   :group 'gnus-summary-visual
812   :type 'hook)
813
814 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
815   "*A hook called before parsing the headers."
816   :group 'gnus-various
817   :type 'hook)
818
819 (defcustom gnus-exit-group-hook nil
820   "*A hook called when exiting summary mode.
821 This hook is not called from the non-updating exit commands like `Q'."
822   :group 'gnus-various
823   :type 'hook)
824
825 (defcustom gnus-summary-update-hook
826   (list 'gnus-summary-highlight-line)
827   "*A hook called when a summary line is changed.
828 The hook will not be called if `gnus-visual' is nil.
829
830 The default function `gnus-summary-highlight-line' will
831 highlight the line according to the `gnus-summary-highlight'
832 variable."
833   :group 'gnus-summary-visual
834   :type 'hook)
835
836 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
837   "*A hook called when an article is selected for the first time.
838 The hook is intended to mark an article as read (or unread)
839 automatically when it is selected."
840   :group 'gnus-summary-choose
841   :type 'hook)
842
843 (defcustom gnus-group-no-more-groups-hook nil
844   "*A hook run when returning to group mode having no more (unread) groups."
845   :group 'gnus-group-select
846   :type 'hook)
847
848 (defcustom gnus-ps-print-hook nil
849   "*A hook run before ps-printing something from Gnus."
850   :group 'gnus-summary
851   :type 'hook)
852
853 (defcustom gnus-summary-display-arrow
854   (and (fboundp 'display-graphic-p)
855        (display-graphic-p))
856   "*If non-nil, display an arrow highlighting the current article."
857   :version "21.1"
858   :group 'gnus-summary
859   :type 'boolean)
860
861 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
862   "Face used for highlighting the current article in the summary buffer."
863   :group 'gnus-summary-visual
864   :type 'face)
865
866 (defcustom gnus-summary-highlight
867   '(((= mark gnus-canceled-mark)
868      . gnus-summary-cancelled-face)
869     ((and (> score default-high)
870           (or (= mark gnus-dormant-mark)
871               (= mark gnus-ticked-mark)))
872      . gnus-summary-high-ticked-face)
873     ((and (< score default-low)
874           (or (= mark gnus-dormant-mark)
875               (= mark gnus-ticked-mark)))
876      . gnus-summary-low-ticked-face)
877     ((or (= mark gnus-dormant-mark)
878          (= mark gnus-ticked-mark))
879      . gnus-summary-normal-ticked-face)
880     ((and (> score default-high) (= mark gnus-ancient-mark))
881      . gnus-summary-high-ancient-face)
882     ((and (< score default-low) (= mark gnus-ancient-mark))
883      . gnus-summary-low-ancient-face)
884     ((= mark gnus-ancient-mark)
885      . gnus-summary-normal-ancient-face)
886     ((and (> score default-high) (= mark gnus-unread-mark))
887      . gnus-summary-high-unread-face)
888     ((and (< score default-low) (= mark gnus-unread-mark))
889      . gnus-summary-low-unread-face)
890     ((= mark gnus-unread-mark)
891      . gnus-summary-normal-unread-face)
892     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
893                                                   gnus-undownloaded-mark)))
894      . gnus-summary-high-unread-face)
895     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
896                                                  gnus-undownloaded-mark)))
897      . gnus-summary-low-unread-face)
898     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
899           (memq article gnus-newsgroup-unreads))
900      . gnus-summary-normal-unread-face)
901     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
902      . gnus-summary-normal-read-face)
903     ((> score default-high)
904      . gnus-summary-high-read-face)
905     ((< score default-low)
906      . gnus-summary-low-read-face)
907     (t
908      . gnus-summary-normal-read-face))
909   "*Controls the highlighting of summary buffer lines.
910
911 A list of (FORM . FACE) pairs.  When deciding how a a particular
912 summary line should be displayed, each form is evaluated.  The content
913 of the face field after the first true form is used.  You can change
914 how those summary lines are displayed, by editing the face field.
915
916 You can use the following variables in the FORM field.
917
918 score:        The article's score
919 default:      The default article score.
920 default-high: The default score for high scored articles.
921 default-low:  The default score for low scored articles.
922 below:        The score below which articles are automatically marked as read.
923 mark:         The articles mark."
924   :group 'gnus-summary-visual
925   :type '(repeat (cons (sexp :tag "Form" nil)
926                        face)))
927
928 (defcustom gnus-alter-header-function nil
929   "Function called to allow alteration of article header structures.
930 The function is called with one parameter, the article header vector,
931 which it may alter in any way.")
932
933 (defvar gnus-decode-encoded-word-function
934   (mime-find-field-decoder 'From 'nov)
935   "Variable that says which function should be used to decode a string with encoded words.")
936
937 (defcustom gnus-extra-headers '(To Newsgroups)
938   "*Extra headers to parse."
939   :version "21.1"
940   :group 'gnus-summary
941   :type '(repeat symbol))
942
943 (defcustom gnus-ignored-from-addresses
944   (and user-mail-address (regexp-quote user-mail-address))
945   "*Regexp of From headers that may be suppressed in favor of To headers."
946   :version "21.1"
947   :group 'gnus-summary
948   :type 'regexp)
949
950 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
951   "List of charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954   :version "21.1"
955   :type '(repeat symbol)
956   :group 'gnus-charset)
957
958 (gnus-define-group-parameter
959  ignored-charsets
960  :type list
961  :function-document
962  "Return the ignored charsets of GROUP."
963  :variable gnus-group-ignored-charsets-alist
964  :variable-default
965  '(("alt\\.chinese\\.text" iso-8859-1))
966  :variable-document
967  "Alist of regexps (to match group names) and charsets that should be ignored.
968 When these charsets are used in the \"charset\" parameter, the
969 default charset will be used instead."
970  :variable-group gnus-charset
971  :variable-type '(repeat (cons (regexp :tag "Group")
972                                (repeat symbol)))
973  :parameter-type '(choice :tag "Ignored charsets"
974                           :value nil
975                           (repeat (symbol)))
976  :parameter-document       "\
977 List of charsets that should be ignored.
978
979 When these charsets are used in the \"charset\" parameter, the
980 default charset will be used instead.")
981
982 (defcustom gnus-group-highlight-words-alist nil
983   "Alist of group regexps and highlight regexps.
984 This variable uses the same syntax as `gnus-emphasis-alist'."
985   :version "21.1"
986   :type '(repeat (cons (regexp :tag "Group")
987                        (repeat (list (regexp :tag "Highlight regexp")
988                                      (number :tag "Group for entire word" 0)
989                                      (number :tag "Group for displayed part" 0)
990                                      (symbol :tag "Face"
991                                              gnus-emphasis-highlight-words)))))
992   :group 'gnus-summary-visual)
993
994 (defcustom gnus-use-wheel nil
995   "Use Intelli-mouse on summary movement"
996   :type 'boolean
997   :group 'gnus-summary-maneuvering)
998
999 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1000   "Amount to scroll messages by spinning the mouse wheel.
1001 This is actually a cons cell, where the first item is the amount to scroll
1002 on a normal wheel event, and the second is the amount to scroll when the
1003 wheel is moved with the shift key depressed."
1004   :type '(cons (integer :tag "Shift") integer)
1005   :group 'gnus-summary-maneuvering)
1006
1007 (defcustom gnus-wheel-edge-resistance 2
1008   "How hard it should be to change the current article
1009 by moving the mouse over the edge of the article window."
1010   :type 'integer
1011   :group 'gnus-summary-maneuvering)
1012
1013 (defcustom gnus-summary-show-article-charset-alist
1014   nil
1015   "Alist of number and charset.
1016 The article will be shown with the charset corresponding to the
1017 numbered argument.
1018 For example: ((1 . cn-gb-2312) (2 . big5))."
1019   :version "21.1"
1020   :type '(repeat (cons (number :tag "Argument" 1)
1021                        (symbol :tag "Charset")))
1022   :group 'gnus-charset)
1023
1024 (defcustom gnus-preserve-marks t
1025   "Whether marks are preserved when moving, copying and respooling messages."
1026   :version "21.1"
1027   :type 'boolean
1028   :group 'gnus-summary-marks)
1029
1030 (defcustom gnus-alter-articles-to-read-function nil
1031   "Function to be called to alter the list of articles to be selected."
1032   :type '(choice (const nil) function)
1033   :group 'gnus-summary)
1034
1035 (defcustom gnus-orphan-score nil
1036   "*All orphans get this score added.  Set in the score file."
1037   :group 'gnus-score-default
1038   :type '(choice (const nil)
1039                  integer))
1040
1041 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1042   "*A regexp to match MIME parts when saving multiple parts of a message
1043 with gnus-summary-save-parts (X m). This regexp will be used by default
1044 when prompting the user for which type of files to save."
1045   :group 'gnus-summary
1046   :type 'regexp)
1047
1048
1049 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1050   "*A regexp to match MIME parts when saving multiple parts of a message
1051 with gnus-summary-save-parts (X m). This regexp will be used by default
1052 when prompting the user for which type of files to save."
1053   :group 'gnus-summary
1054   :type 'regexp)
1055
1056 (defcustom gnus-read-all-available-headers nil
1057   "Whether Gnus should parse all headers made available to it.
1058 This is mostly relevant for slow backends where the user may
1059 wish to widen the summary buffer to include all headers
1060 that were fetched.  Say, for nnultimate groups."
1061   :group 'gnus-summary
1062   :type '(choice boolean regexp))
1063
1064 (defcustom gnus-summary-muttprint-program "muttprint"
1065   "Command (and optional arguments) used to run Muttprint."
1066   :version "21.3"
1067   :group 'gnus-summary
1068   :type 'string)
1069
1070 (defcustom gnus-article-loose-mime nil
1071   "If non-nil, don't require MIME-Version header.
1072 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1073 supply the MIME-Version header or deliberately strip it From the mail.
1074 Set it to non-nil, Gnus will treat some articles as MIME even if
1075 the MIME-Version header is missed."
1076   :version "21.3"
1077   :type 'boolean
1078   :group 'gnus-article)
1079
1080 ;;; Internal variables
1081
1082 (defvar gnus-summary-display-cache nil)
1083 (defvar gnus-article-mime-handles nil)
1084 (defvar gnus-article-decoded-p nil)
1085 (defvar gnus-article-charset nil)
1086 (defvar gnus-article-ignored-charsets nil)
1087 (defvar gnus-scores-exclude-files nil)
1088 (defvar gnus-page-broken nil)
1089 (defvar gnus-inhibit-mime-unbuttonizing nil)
1090
1091 (defvar gnus-original-article nil)
1092 (defvar gnus-article-internal-prepare-hook nil)
1093 (defvar gnus-newsgroup-process-stack nil)
1094
1095 (defvar gnus-thread-indent-array nil)
1096 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1097 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1098   "Function called to sort the articles within a thread after it has been gathered together.")
1099
1100 (defvar gnus-summary-save-parts-type-history nil)
1101 (defvar gnus-summary-save-parts-last-directory nil)
1102
1103 (defvar gnus-summary-save-parts-type-history nil)
1104 (defvar gnus-summary-save-parts-last-directory nil)
1105
1106 ;; Avoid highlighting in kill files.
1107 (defvar gnus-summary-inhibit-highlight nil)
1108 (defvar gnus-newsgroup-selected-overlay nil)
1109 (defvar gnus-inhibit-limiting nil)
1110 (defvar gnus-newsgroup-adaptive-score-file nil)
1111 (defvar gnus-current-score-file nil)
1112 (defvar gnus-current-move-group nil)
1113 (defvar gnus-current-copy-group nil)
1114 (defvar gnus-current-crosspost-group nil)
1115 (defvar gnus-newsgroup-display nil)
1116
1117 (defvar gnus-newsgroup-dependencies nil)
1118 (defvar gnus-newsgroup-adaptive nil)
1119 (defvar gnus-summary-display-article-function nil)
1120 (defvar gnus-summary-highlight-line-function nil
1121   "Function called after highlighting a summary line.")
1122
1123 (defvar gnus-summary-line-format-alist
1124   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1125     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1126     (?s gnus-tmp-subject-or-nil ?s)
1127     (?n gnus-tmp-name ?s)
1128     (?A (std11-address-string
1129          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1130     (?a (or (std11-full-name-string
1131              (car (mime-entity-read-field gnus-tmp-header 'From)))
1132             gnus-tmp-from) ?s)
1133     (?F gnus-tmp-from ?s)
1134     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1135     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1136     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1137     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1138     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1139     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1140     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1141     (?L gnus-tmp-lines ?s)
1142     (?I gnus-tmp-indentation ?s)
1143     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1144     (?R gnus-tmp-replied ?c)
1145     (?\[ gnus-tmp-opening-bracket ?c)
1146     (?\] gnus-tmp-closing-bracket ?c)
1147     (?\> (make-string gnus-tmp-level ? ) ?s)
1148     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1149     (?i gnus-tmp-score ?d)
1150     (?z gnus-tmp-score-char ?c)
1151     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1152     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1153     (?U gnus-tmp-unread ?c)
1154     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1155         ?s)
1156     (?t (gnus-summary-number-of-articles-in-thread
1157          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1158         ?d)
1159     (?e (gnus-summary-number-of-articles-in-thread
1160          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1161         ?c)
1162     (?u gnus-tmp-user-defined ?s)
1163     (?P (gnus-pick-line-number) ?d)
1164     (?B gnus-tmp-thread-tree-header-string ?s)
1165     (user-date (gnus-user-date
1166                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1167   "An alist of format specifications that can appear in summary lines.
1168 These are paired with what variables they correspond with, along with
1169 the type of the variable (string, integer, character, etc).")
1170
1171 (defvar gnus-summary-dummy-line-format-alist
1172   `((?S gnus-tmp-subject ?s)
1173     (?N gnus-tmp-number ?d)
1174     (?u gnus-tmp-user-defined ?s)))
1175
1176 (defvar gnus-summary-mode-line-format-alist
1177   `((?G gnus-tmp-group-name ?s)
1178     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1179     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1180     (?A gnus-tmp-article-number ?d)
1181     (?Z gnus-tmp-unread-and-unselected ?s)
1182     (?V gnus-version ?s)
1183     (?U gnus-tmp-unread-and-unticked ?d)
1184     (?S gnus-tmp-subject ?s)
1185     (?e gnus-tmp-unselected ?d)
1186     (?u gnus-tmp-user-defined ?s)
1187     (?d (length gnus-newsgroup-dormant) ?d)
1188     (?t (length gnus-newsgroup-marked) ?d)
1189     (?r (length gnus-newsgroup-reads) ?d)
1190     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1191     (?E gnus-newsgroup-expunged-tally ?d)
1192     (?s (gnus-current-score-file-nondirectory) ?s)))
1193
1194 (defvar gnus-last-search-regexp nil
1195   "Default regexp for article search command.")
1196
1197 (defvar gnus-summary-search-article-matched-data nil
1198   "Last matched data of article search command.  It is the local variable
1199 in `gnus-article-buffer' which consists of the list of start position,
1200 end position and text.")
1201
1202 (defvar gnus-last-shell-command nil
1203   "Default shell command on article.")
1204
1205 (defvar gnus-newsgroup-begin nil)
1206 (defvar gnus-newsgroup-end nil)
1207 (defvar gnus-newsgroup-last-rmail nil)
1208 (defvar gnus-newsgroup-last-mail nil)
1209 (defvar gnus-newsgroup-last-folder nil)
1210 (defvar gnus-newsgroup-last-file nil)
1211 (defvar gnus-newsgroup-auto-expire nil)
1212 (defvar gnus-newsgroup-active nil)
1213
1214 (defvar gnus-newsgroup-data nil)
1215 (defvar gnus-newsgroup-data-reverse nil)
1216 (defvar gnus-newsgroup-limit nil)
1217 (defvar gnus-newsgroup-limits nil)
1218
1219 (defvar gnus-newsgroup-unreads nil
1220   "Sorted list of unread articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-unselected nil
1223   "Sorted list of unselected unread articles in the current newsgroup.")
1224
1225 (defvar gnus-newsgroup-reads nil
1226   "Alist of read articles and article marks in the current newsgroup.")
1227
1228 (defvar gnus-newsgroup-expunged-tally nil)
1229
1230 (defvar gnus-newsgroup-marked nil
1231   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1232
1233 (defvar gnus-newsgroup-killed nil
1234   "List of ranges of articles that have been through the scoring process.")
1235
1236 (defvar gnus-newsgroup-cached nil
1237   "Sorted list of articles that come from the article cache.")
1238
1239 (defvar gnus-newsgroup-saved nil
1240   "List of articles that have been saved.")
1241
1242 (defvar gnus-newsgroup-kill-headers nil)
1243
1244 (defvar gnus-newsgroup-replied nil
1245   "List of articles that have been replied to in the current newsgroup.")
1246
1247 (defvar gnus-newsgroup-forwarded nil
1248   "List of articles that have been forwarded in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-recent nil
1251   "List of articles that have are recent in the current newsgroup.")
1252
1253 (defvar gnus-newsgroup-expirable nil
1254   "Sorted list of articles in the current newsgroup that can be expired.")
1255
1256 (defvar gnus-newsgroup-processable nil
1257   "List of articles in the current newsgroup that can be processed.")
1258
1259 (defvar gnus-newsgroup-downloadable nil
1260   "Sorted list of articles in the current newsgroup that can be processed.")
1261
1262 (defvar gnus-newsgroup-undownloaded nil
1263   "List of articles in the current newsgroup that haven't been downloaded..")
1264
1265 (defvar gnus-newsgroup-unsendable nil
1266   "List of articles in the current newsgroup that won't be sent.")
1267
1268 (defvar gnus-newsgroup-bookmarks nil
1269   "List of articles in the current newsgroup that have bookmarks.")
1270
1271 (defvar gnus-newsgroup-dormant nil
1272   "Sorted list of dormant articles in the current newsgroup.")
1273
1274 (defvar gnus-newsgroup-unseen nil
1275   "List of unseen articles in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-seen nil
1278   "Range of seen articles in the current newsgroup.")
1279
1280 (defvar gnus-newsgroup-articles nil
1281   "List of articles in the current newsgroup.")
1282
1283 (defvar gnus-newsgroup-scored nil
1284   "List of scored articles in the current newsgroup.")
1285
1286 (defvar gnus-newsgroup-incorporated nil
1287   "List of incorporated articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-headers nil
1290   "List of article headers in the current newsgroup.")
1291
1292 (defvar gnus-newsgroup-threads nil)
1293
1294 (defvar gnus-newsgroup-prepared nil
1295   "Whether the current group has been prepared properly.")
1296
1297 (defvar gnus-newsgroup-ancient nil
1298   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1299
1300 (defvar gnus-newsgroup-sparse nil)
1301
1302 (defvar gnus-current-article nil)
1303 (defvar gnus-article-current nil)
1304 (defvar gnus-current-headers nil)
1305 (defvar gnus-have-all-headers nil)
1306 (defvar gnus-last-article nil)
1307 (defvar gnus-newsgroup-history nil)
1308 (defvar gnus-newsgroup-charset nil)
1309 (defvar gnus-newsgroup-ephemeral-charset nil)
1310 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1311
1312 (defvar gnus-article-before-search nil)
1313
1314 (defconst gnus-summary-local-variables
1315   '(gnus-newsgroup-name
1316     gnus-newsgroup-begin gnus-newsgroup-end
1317     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1318     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1319     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1320     gnus-newsgroup-unselected gnus-newsgroup-marked
1321     gnus-newsgroup-reads gnus-newsgroup-saved
1322     gnus-newsgroup-replied gnus-newsgroup-forwarded
1323     gnus-newsgroup-recent
1324     gnus-newsgroup-expirable
1325     gnus-newsgroup-processable gnus-newsgroup-killed
1326     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1327     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1328     gnus-newsgroup-seen gnus-newsgroup-articles
1329     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1330     gnus-newsgroup-headers gnus-newsgroup-threads
1331     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1332     gnus-current-article gnus-current-headers gnus-have-all-headers
1333     gnus-last-article gnus-article-internal-prepare-hook
1334     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1335     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1336     gnus-thread-expunge-below
1337     gnus-score-alist gnus-current-score-file
1338     (gnus-summary-expunge-below . global)
1339     (gnus-summary-mark-below . global)
1340     (gnus-orphan-score . global)
1341     gnus-newsgroup-active gnus-scores-exclude-files
1342     gnus-newsgroup-history gnus-newsgroup-ancient
1343     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1344     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1345     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1346     (gnus-newsgroup-expunged-tally . 0)
1347     gnus-cache-removable-articles gnus-newsgroup-cached
1348     gnus-newsgroup-data gnus-newsgroup-data-reverse
1349     gnus-newsgroup-limit gnus-newsgroup-limits
1350     gnus-newsgroup-charset gnus-newsgroup-display
1351     gnus-newsgroup-incorporated)
1352   "Variables that are buffer-local to the summary buffers.")
1353
1354 (defvar gnus-newsgroup-variables nil
1355   "A list of variables that have separate values in different newsgroups.
1356 A list of newsgroup (summary buffer) local variables, or cons of
1357 variables and their default values (when the default values are not
1358 nil), that should be made global while the summary buffer is active.
1359 These variables can be used to set variables in the group parameters
1360 while still allowing them to affect operations done in other
1361 buffers. For example:
1362
1363 \(setq gnus-newsgroup-variables
1364      '(message-use-followup-to
1365        (gnus-visible-headers .
1366          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1367 ")
1368
1369 ;; Byte-compiler warning.
1370 (eval-when-compile (defvar gnus-article-mode-map))
1371
1372 ;; Subject simplification.
1373
1374 (defun gnus-simplify-whitespace (str)
1375   "Remove excessive whitespace from STR."
1376   (let ((mystr str))
1377     ;; Multiple spaces.
1378     (while (string-match "[ \t][ \t]+" mystr)
1379       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1380                           " "
1381                           (substring mystr (match-end 0)))))
1382     ;; Leading spaces.
1383     (when (string-match "^[ \t]+" mystr)
1384       (setq mystr (substring mystr (match-end 0))))
1385     ;; Trailing spaces.
1386     (when (string-match "[ \t]+$" mystr)
1387       (setq mystr (substring mystr 0 (match-beginning 0))))
1388     mystr))
1389
1390 (defsubst gnus-simplify-subject-re (subject)
1391   "Remove \"Re:\" from subject lines."
1392   (if (string-match message-subject-re-regexp subject)
1393       (substring subject (match-end 0))
1394     subject))
1395
1396 (defun gnus-simplify-subject (subject &optional re-only)
1397   "Remove `Re:' and words in parentheses.
1398 If RE-ONLY is non-nil, strip leading `Re:'s only."
1399   (let ((case-fold-search t))           ;Ignore case.
1400     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1401     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1402       (setq subject (substring subject (match-end 0))))
1403     ;; Remove uninteresting prefixes.
1404     (when (and (not re-only)
1405                gnus-simplify-ignored-prefixes
1406                (string-match gnus-simplify-ignored-prefixes subject))
1407       (setq subject (substring subject (match-end 0))))
1408     ;; Remove words in parentheses from end.
1409     (unless re-only
1410       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1411         (setq subject (substring subject 0 (match-beginning 0)))))
1412     ;; Return subject string.
1413     subject))
1414
1415 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1416 ;; all whitespace.
1417 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1418   (goto-char (point-min))
1419   (while (re-search-forward regexp nil t)
1420     (replace-match (or newtext ""))))
1421
1422 (defun gnus-simplify-buffer-fuzzy ()
1423   "Simplify string in the buffer fuzzily.
1424 The string in the accessible portion of the current buffer is simplified.
1425 It is assumed to be a single-line subject.
1426 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1427 matter is removed.  Additional things can be deleted by setting
1428 `gnus-simplify-subject-fuzzy-regexp'."
1429   (let ((case-fold-search t)
1430         (modified-tick))
1431     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1432
1433     (while (not (eq modified-tick (buffer-modified-tick)))
1434       (setq modified-tick (buffer-modified-tick))
1435       (cond
1436        ((listp gnus-simplify-subject-fuzzy-regexp)
1437         (mapcar 'gnus-simplify-buffer-fuzzy-step
1438                 gnus-simplify-subject-fuzzy-regexp))
1439        (gnus-simplify-subject-fuzzy-regexp
1440         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1441       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1442       (gnus-simplify-buffer-fuzzy-step
1443        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1444       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1445
1446     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1447     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1448     (gnus-simplify-buffer-fuzzy-step " $")
1449     (gnus-simplify-buffer-fuzzy-step "^ +")))
1450
1451 (defun gnus-simplify-subject-fuzzy (subject)
1452   "Simplify a subject string fuzzily.
1453 See `gnus-simplify-buffer-fuzzy' for details."
1454   (save-excursion
1455     (gnus-set-work-buffer)
1456     (let ((case-fold-search t))
1457       ;; Remove uninteresting prefixes.
1458       (when (and gnus-simplify-ignored-prefixes
1459                  (string-match gnus-simplify-ignored-prefixes subject))
1460         (setq subject (substring subject (match-end 0))))
1461       (insert subject)
1462       (inline (gnus-simplify-buffer-fuzzy))
1463       (buffer-string))))
1464
1465 (defsubst gnus-simplify-subject-fully (subject)
1466   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1467   (cond
1468    (gnus-simplify-subject-functions
1469     (gnus-map-function gnus-simplify-subject-functions subject))
1470    ((null gnus-summary-gather-subject-limit)
1471     (gnus-simplify-subject-re subject))
1472    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1473     (gnus-simplify-subject-fuzzy subject))
1474    ((numberp gnus-summary-gather-subject-limit)
1475     (gnus-limit-string (gnus-simplify-subject-re subject)
1476                        gnus-summary-gather-subject-limit))
1477    (t
1478     subject)))
1479
1480 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1481   "Check whether two subjects are equal.
1482 If optional argument simple-first is t, first argument is already
1483 simplified."
1484   (cond
1485    ((null simple-first)
1486     (equal (gnus-simplify-subject-fully s1)
1487            (gnus-simplify-subject-fully s2)))
1488    (t
1489     (equal s1
1490            (gnus-simplify-subject-fully s2)))))
1491
1492 (defun gnus-summary-bubble-group ()
1493   "Increase the score of the current group.
1494 This is a handy function to add to `gnus-summary-exit-hook' to
1495 increase the score of each group you read."
1496   (gnus-group-add-score gnus-newsgroup-name))
1497
1498 \f
1499 ;;;
1500 ;;; Gnus summary mode
1501 ;;;
1502
1503 (put 'gnus-summary-mode 'mode-class 'special)
1504
1505 (defvar gnus-article-commands-menu)
1506
1507 (when t
1508   ;; Non-orthogonal keys
1509
1510   (gnus-define-keys gnus-summary-mode-map
1511     " " gnus-summary-next-page
1512     "\177" gnus-summary-prev-page
1513     [delete] gnus-summary-prev-page
1514     [backspace] gnus-summary-prev-page
1515     "\r" gnus-summary-scroll-up
1516     "\M-\r" gnus-summary-scroll-down
1517     "n" gnus-summary-next-unread-article
1518     "p" gnus-summary-prev-unread-article
1519     "N" gnus-summary-next-article
1520     "P" gnus-summary-prev-article
1521     "\M-\C-n" gnus-summary-next-same-subject
1522     "\M-\C-p" gnus-summary-prev-same-subject
1523     "\M-n" gnus-summary-next-unread-subject
1524     "\M-p" gnus-summary-prev-unread-subject
1525     "." gnus-summary-first-unread-article
1526     "," gnus-summary-best-unread-article
1527     "\M-s" gnus-summary-search-article-forward
1528     "\M-r" gnus-summary-search-article-backward
1529     "<" gnus-summary-beginning-of-article
1530     ">" gnus-summary-end-of-article
1531     "j" gnus-summary-goto-article
1532     "^" gnus-summary-refer-parent-article
1533     "\M-^" gnus-summary-refer-article
1534     "u" gnus-summary-tick-article-forward
1535     "!" gnus-summary-tick-article-forward
1536     "U" gnus-summary-tick-article-backward
1537     "d" gnus-summary-mark-as-read-forward
1538     "D" gnus-summary-mark-as-read-backward
1539     "E" gnus-summary-mark-as-expirable
1540     "\M-u" gnus-summary-clear-mark-forward
1541     "\M-U" gnus-summary-clear-mark-backward
1542     "k" gnus-summary-kill-same-subject-and-select
1543     "\C-k" gnus-summary-kill-same-subject
1544     "\M-\C-k" gnus-summary-kill-thread
1545     "\M-\C-l" gnus-summary-lower-thread
1546     "e" gnus-summary-edit-article
1547     "#" gnus-summary-mark-as-processable
1548     "\M-#" gnus-summary-unmark-as-processable
1549     "\M-\C-t" gnus-summary-toggle-threads
1550     "\M-\C-s" gnus-summary-show-thread
1551     "\M-\C-h" gnus-summary-hide-thread
1552     "\M-\C-f" gnus-summary-next-thread
1553     "\M-\C-b" gnus-summary-prev-thread
1554     [(meta down)] gnus-summary-next-thread
1555     [(meta up)] gnus-summary-prev-thread
1556     "\M-\C-u" gnus-summary-up-thread
1557     "\M-\C-d" gnus-summary-down-thread
1558     "&" gnus-summary-execute-command
1559     "c" gnus-summary-catchup-and-exit
1560     "\C-w" gnus-summary-mark-region-as-read
1561     "\C-t" gnus-summary-toggle-truncation
1562     "?" gnus-summary-mark-as-dormant
1563     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1564     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1565     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1566     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1567     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1568     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1569     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1570     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1571     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1572     "=" gnus-summary-expand-window
1573     "\C-x\C-s" gnus-summary-reselect-current-group
1574     "\M-g" gnus-summary-rescan-group
1575     "w" gnus-summary-stop-page-breaking
1576     "\C-c\C-r" gnus-summary-caesar-message
1577     "\M-t" gnus-summary-toggle-mime
1578     "f" gnus-summary-followup
1579     "F" gnus-summary-followup-with-original
1580     "C" gnus-summary-cancel-article
1581     "r" gnus-summary-reply
1582     "R" gnus-summary-reply-with-original
1583     "\C-c\C-f" gnus-summary-mail-forward
1584     "o" gnus-summary-save-article
1585     "\C-o" gnus-summary-save-article-mail
1586     "|" gnus-summary-pipe-output
1587     "\M-k" gnus-summary-edit-local-kill
1588     "\M-K" gnus-summary-edit-global-kill
1589     ;; "V" gnus-version
1590     "\C-c\C-d" gnus-summary-describe-group
1591     "q" gnus-summary-exit
1592     "Q" gnus-summary-exit-no-update
1593     "\C-c\C-i" gnus-info-find-node
1594     gnus-mouse-2 gnus-mouse-pick-article
1595     "m" gnus-summary-mail-other-window
1596     "a" gnus-summary-post-news
1597     "i" gnus-summary-news-other-window
1598     "x" gnus-summary-limit-to-unread
1599     "s" gnus-summary-isearch-article
1600     "t" gnus-article-toggle-headers
1601     "g" gnus-summary-show-article
1602     "l" gnus-summary-goto-last-article
1603     "v" gnus-summary-preview-mime-message
1604     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1605     "\C-d" gnus-summary-enter-digest-group
1606     "\M-\C-d" gnus-summary-read-document
1607     "\M-\C-e" gnus-summary-edit-parameters
1608     "\M-\C-a" gnus-summary-customize-parameters
1609     "\C-c\C-b" gnus-bug
1610     "\C-c\C-n" gnus-namazu-search
1611     "*" gnus-cache-enter-article
1612     "\M-*" gnus-cache-remove-article
1613     "\M-&" gnus-summary-universal-argument
1614     "\C-l" gnus-recenter
1615     "I" gnus-summary-increase-score
1616     "L" gnus-summary-lower-score
1617     "\M-i" gnus-symbolic-argument
1618     "h" gnus-summary-select-article-buffer
1619
1620     "V" gnus-summary-score-map
1621     "X" gnus-uu-extract-map
1622     "S" gnus-summary-send-map)
1623
1624   ;; Sort of orthogonal keymap
1625   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1626     "t" gnus-summary-tick-article-forward
1627     "!" gnus-summary-tick-article-forward
1628     "d" gnus-summary-mark-as-read-forward
1629     "r" gnus-summary-mark-as-read-forward
1630     "c" gnus-summary-clear-mark-forward
1631     " " gnus-summary-clear-mark-forward
1632     "e" gnus-summary-mark-as-expirable
1633     "x" gnus-summary-mark-as-expirable
1634     "?" gnus-summary-mark-as-dormant
1635     "b" gnus-summary-set-bookmark
1636     "B" gnus-summary-remove-bookmark
1637     "#" gnus-summary-mark-as-processable
1638     "\M-#" gnus-summary-unmark-as-processable
1639     "S" gnus-summary-limit-include-expunged
1640     "C" gnus-summary-catchup
1641     "H" gnus-summary-catchup-to-here
1642     "h" gnus-summary-catchup-from-here
1643     "\C-c" gnus-summary-catchup-all
1644     "k" gnus-summary-kill-same-subject-and-select
1645     "K" gnus-summary-kill-same-subject
1646     "P" gnus-uu-mark-map)
1647
1648   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1649     "c" gnus-summary-clear-above
1650     "u" gnus-summary-tick-above
1651     "m" gnus-summary-mark-above
1652     "k" gnus-summary-kill-below)
1653
1654   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1655     "/" gnus-summary-limit-to-subject
1656     "n" gnus-summary-limit-to-articles
1657     "w" gnus-summary-pop-limit
1658     "s" gnus-summary-limit-to-subject
1659     "a" gnus-summary-limit-to-author
1660     "u" gnus-summary-limit-to-unread
1661     "m" gnus-summary-limit-to-marks
1662     "M" gnus-summary-limit-exclude-marks
1663     "v" gnus-summary-limit-to-score
1664     "*" gnus-summary-limit-include-cached
1665     "D" gnus-summary-limit-include-dormant
1666     "T" gnus-summary-limit-include-thread
1667     "d" gnus-summary-limit-exclude-dormant
1668     "t" gnus-summary-limit-to-age
1669     "x" gnus-summary-limit-to-extra
1670     "p" gnus-summary-limit-to-display-predicate
1671     "E" gnus-summary-limit-include-expunged
1672     "c" gnus-summary-limit-exclude-childless-dormant
1673     "C" gnus-summary-limit-mark-excluded-as-read
1674     "o" gnus-summary-insert-old-articles
1675     "N" gnus-summary-insert-new-articles)
1676
1677   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1678     "n" gnus-summary-next-unread-article
1679     "p" gnus-summary-prev-unread-article
1680     "N" gnus-summary-next-article
1681     "P" gnus-summary-prev-article
1682     "\C-n" gnus-summary-next-same-subject
1683     "\C-p" gnus-summary-prev-same-subject
1684     "\M-n" gnus-summary-next-unread-subject
1685     "\M-p" gnus-summary-prev-unread-subject
1686     "f" gnus-summary-first-unread-article
1687     "b" gnus-summary-best-unread-article
1688     "j" gnus-summary-goto-article
1689     "g" gnus-summary-goto-subject
1690     "l" gnus-summary-goto-last-article
1691     "o" gnus-summary-pop-article)
1692
1693   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1694     "k" gnus-summary-kill-thread
1695     "l" gnus-summary-lower-thread
1696     "i" gnus-summary-raise-thread
1697     "T" gnus-summary-toggle-threads
1698     "t" gnus-summary-rethread-current
1699     "^" gnus-summary-reparent-thread
1700     "s" gnus-summary-show-thread
1701     "S" gnus-summary-show-all-threads
1702     "h" gnus-summary-hide-thread
1703     "H" gnus-summary-hide-all-threads
1704     "n" gnus-summary-next-thread
1705     "p" gnus-summary-prev-thread
1706     "u" gnus-summary-up-thread
1707     "o" gnus-summary-top-thread
1708     "d" gnus-summary-down-thread
1709     "#" gnus-uu-mark-thread
1710     "\M-#" gnus-uu-unmark-thread)
1711
1712   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1713     "g" gnus-summary-prepare
1714     "c" gnus-summary-insert-cached-articles)
1715
1716   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1717     "c" gnus-summary-catchup-and-exit
1718     "C" gnus-summary-catchup-all-and-exit
1719     "E" gnus-summary-exit-no-update
1720     "J" gnus-summary-jump-to-other-group
1721     "Q" gnus-summary-exit
1722     "Z" gnus-summary-exit
1723     "n" gnus-summary-catchup-and-goto-next-group
1724     "R" gnus-summary-reselect-current-group
1725     "G" gnus-summary-rescan-group
1726     "N" gnus-summary-next-group
1727     "s" gnus-summary-save-newsrc
1728     "P" gnus-summary-prev-group)
1729
1730   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1731     " " gnus-summary-next-page
1732     "n" gnus-summary-next-page
1733     "\177" gnus-summary-prev-page
1734     [delete] gnus-summary-prev-page
1735     "p" gnus-summary-prev-page
1736     "\r" gnus-summary-scroll-up
1737     "\M-\r" gnus-summary-scroll-down
1738     "<" gnus-summary-beginning-of-article
1739     ">" gnus-summary-end-of-article
1740     "b" gnus-summary-beginning-of-article
1741     "e" gnus-summary-end-of-article
1742     "^" gnus-summary-refer-parent-article
1743     "r" gnus-summary-refer-parent-article
1744     "D" gnus-summary-enter-digest-group
1745     "R" gnus-summary-refer-references
1746     "T" gnus-summary-refer-thread
1747     "g" gnus-summary-show-article
1748     "s" gnus-summary-isearch-article
1749     "P" gnus-summary-print-article
1750     "M" gnus-mailing-list-insinuate
1751     "t" gnus-article-babel)
1752
1753   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1754     "b" gnus-article-add-buttons
1755     "B" gnus-article-add-buttons-to-head
1756     "o" gnus-article-treat-overstrike
1757     "e" gnus-article-emphasize
1758     "w" gnus-article-fill-cited-article
1759     "Q" gnus-article-fill-long-lines
1760     "C" gnus-article-capitalize-sentences
1761     "c" gnus-article-remove-cr
1762     "Z" gnus-article-decode-HZ
1763     "h" gnus-article-wash-html
1764     "u" gnus-article-unsplit-urls
1765     "f" gnus-article-display-x-face
1766     "l" gnus-summary-stop-page-breaking
1767     "r" gnus-summary-caesar-message
1768     "t" gnus-article-toggle-headers
1769     "g" gnus-treat-smiley
1770     "v" gnus-summary-verbose-headers
1771     "m" gnus-summary-toggle-mime
1772     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1773     "p" gnus-article-verify-x-pgp-sig
1774     "d" gnus-article-treat-dumbquotes
1775     "k" gnus-article-outlook-deuglify-article)
1776
1777   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1778     "a" gnus-article-hide
1779     "h" gnus-article-toggle-headers
1780     "b" gnus-article-hide-boring-headers
1781     "s" gnus-article-hide-signature
1782     "c" gnus-article-hide-citation
1783     "C" gnus-article-hide-citation-in-followups
1784     "l" gnus-article-hide-list-identifiers
1785     "p" gnus-article-hide-pgp
1786     "B" gnus-article-strip-banner
1787     "P" gnus-article-hide-pem
1788     "\C-c" gnus-article-hide-citation-maybe)
1789
1790   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1791     "a" gnus-article-highlight
1792     "h" gnus-article-highlight-headers
1793     "c" gnus-article-highlight-citation
1794     "s" gnus-article-highlight-signature)
1795
1796   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1797     "f" gnus-article-treat-fold-headers
1798     "u" gnus-article-treat-unfold-headers
1799     "n" gnus-article-treat-fold-newsgroups)
1800
1801   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1802     "x" gnus-article-display-x-face
1803     "s" gnus-treat-smiley
1804     "D" gnus-article-remove-images
1805     "f" gnus-treat-from-picon
1806     "m" gnus-treat-mail-picon
1807     "n" gnus-treat-newsgroups-picon)
1808
1809   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1810     "z" gnus-article-date-ut
1811     "u" gnus-article-date-ut
1812     "l" gnus-article-date-local
1813     "p" gnus-article-date-english
1814     "e" gnus-article-date-lapsed
1815     "o" gnus-article-date-original
1816     "i" gnus-article-date-iso8601
1817     "s" gnus-article-date-user)
1818
1819   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1820     "t" gnus-article-remove-trailing-blank-lines
1821     "l" gnus-article-strip-leading-blank-lines
1822     "m" gnus-article-strip-multiple-blank-lines
1823     "a" gnus-article-strip-blank-lines
1824     "A" gnus-article-strip-all-blank-lines
1825     "s" gnus-article-strip-leading-space
1826     "e" gnus-article-strip-trailing-space
1827     "w" gnus-article-remove-leading-whitespace)
1828
1829   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1830     "v" gnus-version
1831     "f" gnus-summary-fetch-faq
1832     "d" gnus-summary-describe-group
1833     "h" gnus-summary-describe-briefly
1834     "i" gnus-info-find-node)
1835
1836   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1837     "e" gnus-summary-expire-articles
1838     "\M-\C-e" gnus-summary-expire-articles-now
1839     "\177" gnus-summary-delete-article
1840     [delete] gnus-summary-delete-article
1841     [backspace] gnus-summary-delete-article
1842     "m" gnus-summary-move-article
1843     "r" gnus-summary-respool-article
1844     "w" gnus-summary-edit-article
1845     "c" gnus-summary-copy-article
1846     "B" gnus-summary-crosspost-article
1847     "q" gnus-summary-respool-query
1848     "t" gnus-summary-respool-trace
1849     "i" gnus-summary-import-article
1850     "I" gnus-summary-create-article
1851     "p" gnus-summary-article-posted-p)
1852
1853   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1854     "o" gnus-summary-save-article
1855     "m" gnus-summary-save-article-mail
1856     "F" gnus-summary-write-article-file
1857     "r" gnus-summary-save-article-rmail
1858     "f" gnus-summary-save-article-file
1859     "b" gnus-summary-save-article-body-file
1860     "h" gnus-summary-save-article-folder
1861     "v" gnus-summary-save-article-vm
1862     "p" gnus-summary-pipe-output
1863     "P" gnus-summary-muttprint
1864     "s" gnus-soup-add-article)
1865
1866   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1867     "b" gnus-summary-display-buttonized
1868     "m" gnus-summary-repair-multipart
1869     "v" gnus-article-view-part
1870     "o" gnus-article-save-part
1871     "c" gnus-article-copy-part
1872     "C" gnus-article-view-part-as-charset
1873     "e" gnus-article-view-part-externally
1874     "E" gnus-article-encrypt-body
1875     "i" gnus-article-inline-part
1876     "|" gnus-article-pipe-part)
1877
1878   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1879     "p" gnus-summary-mark-as-processable
1880     "u" gnus-summary-unmark-as-processable
1881     "U" gnus-summary-unmark-all-processable
1882     "v" gnus-uu-mark-over
1883     "s" gnus-uu-mark-series
1884     "r" gnus-uu-mark-region
1885     "g" gnus-uu-unmark-region
1886     "R" gnus-uu-mark-by-regexp
1887     "G" gnus-uu-unmark-by-regexp
1888     "t" gnus-uu-mark-thread
1889     "T" gnus-uu-unmark-thread
1890     "a" gnus-uu-mark-all
1891     "b" gnus-uu-mark-buffer
1892     "S" gnus-uu-mark-sparse
1893     "k" gnus-summary-kill-process-mark
1894     "y" gnus-summary-yank-process-mark
1895     "w" gnus-summary-save-process-mark
1896     "i" gnus-uu-invert-processable)
1897
1898   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1899     ;;"x" gnus-uu-extract-any
1900     "m" gnus-summary-save-parts
1901     "u" gnus-uu-decode-uu
1902     "U" gnus-uu-decode-uu-and-save
1903     "s" gnus-uu-decode-unshar
1904     "S" gnus-uu-decode-unshar-and-save
1905     "o" gnus-uu-decode-save
1906     "O" gnus-uu-decode-save
1907     "b" gnus-uu-decode-binhex
1908     "B" gnus-uu-decode-binhex
1909     "p" gnus-uu-decode-postscript
1910     "P" gnus-uu-decode-postscript-and-save)
1911
1912   (gnus-define-keys
1913       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1914     "u" gnus-uu-decode-uu-view
1915     "U" gnus-uu-decode-uu-and-save-view
1916     "s" gnus-uu-decode-unshar-view
1917     "S" gnus-uu-decode-unshar-and-save-view
1918     "o" gnus-uu-decode-save-view
1919     "O" gnus-uu-decode-save-view
1920     "b" gnus-uu-decode-binhex-view
1921     "B" gnus-uu-decode-binhex-view
1922     "p" gnus-uu-decode-postscript-view
1923     "P" gnus-uu-decode-postscript-and-save-view))
1924
1925 (defvar gnus-article-post-menu nil)
1926
1927 (defun gnus-summary-make-menu-bar ()
1928   (gnus-turn-off-edit-menu 'summary)
1929
1930   (unless (boundp 'gnus-summary-misc-menu)
1931
1932     (easy-menu-define
1933      gnus-summary-kill-menu gnus-summary-mode-map ""
1934      (cons
1935       "Score"
1936       (nconc
1937        (list
1938         ["Customize" gnus-score-customize t])
1939        (gnus-make-score-map 'increase)
1940        (gnus-make-score-map 'lower)
1941        '(("Mark"
1942           ["Kill below" gnus-summary-kill-below t]
1943           ["Mark above" gnus-summary-mark-above t]
1944           ["Tick above" gnus-summary-tick-above t]
1945           ["Clear above" gnus-summary-clear-above t])
1946          ["Current score" gnus-summary-current-score t]
1947          ["Set score" gnus-summary-set-score t]
1948          ["Switch current score file..." gnus-score-change-score-file t]
1949          ["Set mark below..." gnus-score-set-mark-below t]
1950          ["Set expunge below..." gnus-score-set-expunge-below t]
1951          ["Edit current score file" gnus-score-edit-current-scores t]
1952          ["Edit score file" gnus-score-edit-file t]
1953          ["Trace score" gnus-score-find-trace t]
1954          ["Find words" gnus-score-find-favourite-words t]
1955          ["Rescore buffer" gnus-summary-rescore t]
1956          ["Increase score..." gnus-summary-increase-score t]
1957          ["Lower score..." gnus-summary-lower-score t]))))
1958
1959     ;; Define both the Article menu in the summary buffer and the
1960     ;; equivalent Commands menu in the article buffer here for
1961     ;; consistency.
1962     (let ((innards
1963            `(("Hide"
1964               ["All" gnus-article-hide t]
1965               ["Headers" gnus-article-toggle-headers t]
1966               ["Signature" gnus-article-hide-signature t]
1967               ["Citation" gnus-article-hide-citation t]
1968               ["List identifiers" gnus-article-hide-list-identifiers t]
1969               ["PGP" gnus-article-hide-pgp t]
1970               ["Banner" gnus-article-strip-banner t]
1971               ["Boring headers" gnus-article-hide-boring-headers t])
1972              ("Highlight"
1973               ["All" gnus-article-highlight t]
1974               ["Headers" gnus-article-highlight-headers t]
1975               ["Signature" gnus-article-highlight-signature t]
1976               ["Citation" gnus-article-highlight-citation t])
1977              ("Date"
1978               ["Local" gnus-article-date-local t]
1979               ["ISO8601" gnus-article-date-iso8601 t]
1980               ["UT" gnus-article-date-ut t]
1981               ["Original" gnus-article-date-original t]
1982               ["Lapsed" gnus-article-date-lapsed t]
1983               ["User-defined" gnus-article-date-user t])
1984              ("Display"
1985               ["Remove images" gnus-article-remove-images t]
1986               ["Toggle smiley" gnus-treat-smiley t]
1987               ["Show X-Face" gnus-article-display-x-face t]
1988               ["Show picons in From" gnus-treat-from-picon t]
1989               ["Show picons in mail headers" gnus-treat-mail-picon t]
1990               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1991              ("Washing"
1992               ("Remove Blanks"
1993                ["Leading" gnus-article-strip-leading-blank-lines t]
1994                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1995                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1996                ["All of the above" gnus-article-strip-blank-lines t]
1997                ["All" gnus-article-strip-all-blank-lines t]
1998                ["Leading space" gnus-article-strip-leading-space t]
1999                ["Trailing space" gnus-article-strip-trailing-space t]
2000                ["Leading space in headers"
2001                 gnus-article-remove-leading-whitespace t])
2002               ["Overstrike" gnus-article-treat-overstrike t]
2003               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2004               ["Emphasis" gnus-article-emphasize t]
2005               ["Word wrap" gnus-article-fill-cited-article t]
2006               ["Fill long lines" gnus-article-fill-long-lines t]
2007               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2008               ["CR" gnus-article-remove-cr t]
2009               ["Rot 13" gnus-summary-caesar-message
2010                ,@(if (featurep 'xemacs) '(t)
2011                    '(:help "\"Caesar rotate\" article by 13"))]
2012               ["Unix pipe" gnus-summary-pipe-message t]
2013               ["Add buttons" gnus-article-add-buttons t]
2014               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2015               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2016               ["Toggle MIME" gnus-summary-toggle-mime t]
2017               ["Verbose header" gnus-summary-verbose-headers t]
2018               ["Toggle header" gnus-summary-toggle-header t]
2019               ["Unfold headers" gnus-article-treat-unfold-headers t]
2020               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2021               ["Html" gnus-article-wash-html t]
2022               ["URLs" gnus-article-unsplit-urls t]
2023               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2024               ["HZ" gnus-article-decode-HZ t]
2025               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2026               )
2027              ("Output"
2028               ["Save in default format" gnus-summary-save-article
2029                ,@(if (featurep 'xemacs) '(t)
2030                    '(:help "Save article using default method"))]
2031               ["Save in file" gnus-summary-save-article-file
2032                ,@(if (featurep 'xemacs) '(t)
2033                    '(:help "Save article in file"))]
2034               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2035               ["Save in MH folder" gnus-summary-save-article-folder t]
2036               ["Save in VM folder" gnus-summary-save-article-vm t]
2037               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2038               ["Save body in file" gnus-summary-save-article-body-file t]
2039               ["Pipe through a filter" gnus-summary-pipe-output t]
2040               ["Add to SOUP packet" gnus-soup-add-article t]
2041               ["Print with Muttprint" gnus-summary-muttprint t]
2042               ["Print" gnus-summary-print-article t])
2043              ("Backend"
2044               ["Respool article..." gnus-summary-respool-article t]
2045               ["Move article..." gnus-summary-move-article
2046                (gnus-check-backend-function
2047                 'request-move-article gnus-newsgroup-name)]
2048               ["Copy article..." gnus-summary-copy-article t]
2049               ["Crosspost article..." gnus-summary-crosspost-article
2050                (gnus-check-backend-function
2051                 'request-replace-article gnus-newsgroup-name)]
2052               ["Import file..." gnus-summary-import-article t]
2053               ["Create article..." gnus-summary-create-article t]
2054               ["Check if posted" gnus-summary-article-posted-p t]
2055               ["Edit article" gnus-summary-edit-article
2056                (not (gnus-group-read-only-p))]
2057               ["Delete article" gnus-summary-delete-article
2058                (gnus-check-backend-function
2059                 'request-expire-articles gnus-newsgroup-name)]
2060               ["Query respool" gnus-summary-respool-query t]
2061               ["Trace respool" gnus-summary-respool-trace t]
2062               ["Delete expirable articles" gnus-summary-expire-articles-now
2063                (gnus-check-backend-function
2064                 'request-expire-articles gnus-newsgroup-name)])
2065              ("Extract"
2066               ["Uudecode" gnus-uu-decode-uu
2067                ,@(if (featurep 'xemacs) '(t)
2068                    '(:help "Decode uuencoded article(s)"))]
2069               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2070               ["Unshar" gnus-uu-decode-unshar t]
2071               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2072               ["Save" gnus-uu-decode-save t]
2073               ["Binhex" gnus-uu-decode-binhex t]
2074               ["Postscript" gnus-uu-decode-postscript t])
2075              ("Cache"
2076               ["Enter article" gnus-cache-enter-article t]
2077               ["Remove article" gnus-cache-remove-article t])
2078              ["Translate" gnus-article-babel t]
2079              ["Select article buffer" gnus-summary-select-article-buffer t]
2080              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2081              ["Isearch article..." gnus-summary-isearch-article t]
2082              ["Beginning of the article" gnus-summary-beginning-of-article t]
2083              ["End of the article" gnus-summary-end-of-article t]
2084              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2085              ["Fetch referenced articles" gnus-summary-refer-references t]
2086              ["Fetch current thread" gnus-summary-refer-thread t]
2087              ["Fetch article with id..." gnus-summary-refer-article t]
2088              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2089              ["Redisplay" gnus-summary-show-article t]
2090              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2091       (easy-menu-define
2092        gnus-summary-article-menu gnus-summary-mode-map ""
2093        (cons "Article" innards))
2094
2095       (if (not (keymapp gnus-summary-article-menu))
2096           (easy-menu-define
2097            gnus-article-commands-menu gnus-article-mode-map ""
2098            (cons "Commands" innards))
2099         ;; in Emacs, don't share menu.
2100         (setq gnus-article-commands-menu
2101               (copy-keymap gnus-summary-article-menu))
2102         (define-key gnus-article-mode-map [menu-bar commands]
2103           (cons "Commands" gnus-article-commands-menu))))
2104
2105     (easy-menu-define
2106      gnus-summary-thread-menu gnus-summary-mode-map ""
2107      '("Threads"
2108        ["Toggle threading" gnus-summary-toggle-threads t]
2109        ["Hide threads" gnus-summary-hide-all-threads t]
2110        ["Show threads" gnus-summary-show-all-threads t]
2111        ["Hide thread" gnus-summary-hide-thread t]
2112        ["Show thread" gnus-summary-show-thread t]
2113        ["Go to next thread" gnus-summary-next-thread t]
2114        ["Go to previous thread" gnus-summary-prev-thread t]
2115        ["Go down thread" gnus-summary-down-thread t]
2116        ["Go up thread" gnus-summary-up-thread t]
2117        ["Top of thread" gnus-summary-top-thread t]
2118        ["Mark thread as read" gnus-summary-kill-thread t]
2119        ["Lower thread score" gnus-summary-lower-thread t]
2120        ["Raise thread score" gnus-summary-raise-thread t]
2121        ["Rethread current" gnus-summary-rethread-current t]))
2122
2123     (easy-menu-define
2124      gnus-summary-post-menu gnus-summary-mode-map ""
2125      `("Post"
2126        ["Send a message (mail or news)" gnus-summary-post-news
2127         ,@(if (featurep 'xemacs) '(t)
2128             '(:help "Post an article"))]
2129        ["Followup" gnus-summary-followup
2130         ,@(if (featurep 'xemacs) '(t)
2131             '(:help "Post followup to this article"))]
2132        ["Followup and yank" gnus-summary-followup-with-original
2133         ,@(if (featurep 'xemacs) '(t)
2134             '(:help "Post followup to this article, quoting its contents"))]
2135        ["Supersede article" gnus-summary-supersede-article t]
2136        ["Cancel article" gnus-summary-cancel-article
2137         ,@(if (featurep 'xemacs) '(t)
2138             '(:help "Cancel an article you posted"))]
2139        ["Reply" gnus-summary-reply t]
2140        ["Reply and yank" gnus-summary-reply-with-original t]
2141        ["Wide reply" gnus-summary-wide-reply t]
2142        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2143         ,@(if (featurep 'xemacs) '(t)
2144             '(:help "Mail a reply, quoting this article"))]
2145        ["Very wide reply" gnus-summary-very-wide-reply t]
2146        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2147         ,@(if (featurep 'xemacs) '(t)
2148             '(:help "Mail a very wide reply, quoting this article"))]
2149        ["Mail forward" gnus-summary-mail-forward t]
2150        ["Post forward" gnus-summary-post-forward t]
2151        ["Digest and mail" gnus-summary-digest-mail-forward t]
2152        ["Digest and post" gnus-summary-digest-post-forward t]
2153        ["Resend message" gnus-summary-resend-message t]
2154        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2155        ["Send a mail" gnus-summary-mail-other-window t]
2156        ["Create a local message" gnus-summary-news-other-window t]
2157        ["Uuencode and post" gnus-uu-post-news
2158         ,@(if (featurep 'xemacs) '(t)
2159             '(:help "Post a uuencoded article"))]
2160        ["Followup via news" gnus-summary-followup-to-mail t]
2161        ["Followup via news and yank"
2162         gnus-summary-followup-to-mail-with-original t]
2163        ;;("Draft"
2164        ;;["Send" gnus-summary-send-draft t]
2165        ;;["Send bounced" gnus-resend-bounced-mail t])
2166        ))
2167
2168     (cond
2169      ((not (keymapp gnus-summary-post-menu))
2170       (setq gnus-article-post-menu gnus-summary-post-menu))
2171      ((not gnus-article-post-menu)
2172       ;; Don't share post menu.
2173       (setq gnus-article-post-menu
2174             (copy-keymap gnus-summary-post-menu))))
2175     (define-key gnus-article-mode-map [menu-bar post]
2176       (cons "Post" gnus-article-post-menu))
2177
2178     (easy-menu-define
2179      gnus-summary-misc-menu gnus-summary-mode-map ""
2180      `("Gnus"
2181        ("Mark Read"
2182         ["Mark as read" gnus-summary-mark-as-read-forward t]
2183         ["Mark same subject and select"
2184          gnus-summary-kill-same-subject-and-select t]
2185         ["Mark same subject" gnus-summary-kill-same-subject t]
2186         ["Catchup" gnus-summary-catchup
2187          ,@(if (featurep 'xemacs) '(t)
2188              '(:help "Mark unread articles in this group as read"))]
2189         ["Catchup all" gnus-summary-catchup-all t]
2190         ["Catchup to here" gnus-summary-catchup-to-here t]
2191         ["Catchup from here" gnus-summary-catchup-from-here t]
2192         ["Catchup region" gnus-summary-mark-region-as-read t]
2193         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2194        ("Mark Various"
2195         ["Tick" gnus-summary-tick-article-forward t]
2196         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2197         ["Remove marks" gnus-summary-clear-mark-forward t]
2198         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2199         ["Set bookmark" gnus-summary-set-bookmark t]
2200         ["Remove bookmark" gnus-summary-remove-bookmark t])
2201        ("Limit to"
2202         ["Marks..." gnus-summary-limit-to-marks t]
2203         ["Subject..." gnus-summary-limit-to-subject t]
2204         ["Author..." gnus-summary-limit-to-author t]
2205         ["Age..." gnus-summary-limit-to-age t]
2206         ["Extra..." gnus-summary-limit-to-extra t]
2207         ["Score" gnus-summary-limit-to-score t]
2208         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2209         ["Unread" gnus-summary-limit-to-unread t]
2210         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2211         ["Articles" gnus-summary-limit-to-articles t]
2212         ["Pop limit" gnus-summary-pop-limit t]
2213         ["Show dormant" gnus-summary-limit-include-dormant t]
2214         ["Hide childless dormant"
2215          gnus-summary-limit-exclude-childless-dormant t]
2216         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2217         ["Hide marked" gnus-summary-limit-exclude-marks t]
2218         ["Show expunged" gnus-summary-limit-include-expunged t])
2219        ("Process Mark"
2220         ["Set mark" gnus-summary-mark-as-processable t]
2221         ["Remove mark" gnus-summary-unmark-as-processable t]
2222         ["Remove all marks" gnus-summary-unmark-all-processable t]
2223         ["Mark above" gnus-uu-mark-over t]
2224         ["Mark series" gnus-uu-mark-series t]
2225         ["Mark region" gnus-uu-mark-region t]
2226         ["Unmark region" gnus-uu-unmark-region t]
2227         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2228         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2229         ["Mark all" gnus-uu-mark-all t]
2230         ["Mark buffer" gnus-uu-mark-buffer t]
2231         ["Mark sparse" gnus-uu-mark-sparse t]
2232         ["Mark thread" gnus-uu-mark-thread t]
2233         ["Unmark thread" gnus-uu-unmark-thread t]
2234         ("Process Mark Sets"
2235          ["Kill" gnus-summary-kill-process-mark t]
2236          ["Yank" gnus-summary-yank-process-mark
2237           gnus-newsgroup-process-stack]
2238          ["Save" gnus-summary-save-process-mark t]))
2239        ("Scroll article"
2240         ["Page forward" gnus-summary-next-page
2241          ,@(if (featurep 'xemacs) '(t)
2242              '(:help "Show next page of article"))]
2243         ["Page backward" gnus-summary-prev-page
2244          ,@(if (featurep 'xemacs) '(t)
2245              '(:help "Show previous page of article"))]
2246         ["Line forward" gnus-summary-scroll-up t])
2247        ("Move"
2248         ["Next unread article" gnus-summary-next-unread-article t]
2249         ["Previous unread article" gnus-summary-prev-unread-article t]
2250         ["Next article" gnus-summary-next-article t]
2251         ["Previous article" gnus-summary-prev-article t]
2252         ["Next unread subject" gnus-summary-next-unread-subject t]
2253         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2254         ["Next article same subject" gnus-summary-next-same-subject t]
2255         ["Previous article same subject" gnus-summary-prev-same-subject t]
2256         ["First unread article" gnus-summary-first-unread-article t]
2257         ["Best unread article" gnus-summary-best-unread-article t]
2258         ["Go to subject number..." gnus-summary-goto-subject t]
2259         ["Go to article number..." gnus-summary-goto-article t]
2260         ["Go to the last article" gnus-summary-goto-last-article t]
2261         ["Pop article off history" gnus-summary-pop-article t])
2262        ("Sort"
2263         ["Sort by number" gnus-summary-sort-by-number t]
2264         ["Sort by author" gnus-summary-sort-by-author t]
2265         ["Sort by subject" gnus-summary-sort-by-subject t]
2266         ["Sort by date" gnus-summary-sort-by-date t]
2267         ["Sort by score" gnus-summary-sort-by-score t]
2268         ["Sort by lines" gnus-summary-sort-by-lines t]
2269         ["Sort by characters" gnus-summary-sort-by-chars t]
2270         ["Original sort" gnus-summary-sort-by-original t])
2271        ("Help"
2272         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2273         ["Describe group" gnus-summary-describe-group t]
2274         ["Read manual" gnus-info-find-node t])
2275        ("Modes"
2276         ["Pick and read" gnus-pick-mode t]
2277         ["Binary" gnus-binary-mode t])
2278        ("Regeneration"
2279         ["Regenerate" gnus-summary-prepare t]
2280         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2281         ["Toggle threading" gnus-summary-toggle-threads t])
2282        ["See old articles" gnus-summary-insert-old-articles t]
2283        ["See new articles" gnus-summary-insert-new-articles t]
2284        ["Filter articles..." gnus-summary-execute-command t]
2285        ["Run command on subjects..." gnus-summary-universal-argument t]
2286        ["Search articles forward..." gnus-summary-search-article-forward t]
2287        ["Search articles backward..." gnus-summary-search-article-backward t]
2288        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2289        ["Expand window" gnus-summary-expand-window t]
2290        ["Expire expirable articles" gnus-summary-expire-articles
2291         (gnus-check-backend-function
2292          'request-expire-articles gnus-newsgroup-name)]
2293        ["Edit local kill file" gnus-summary-edit-local-kill t]
2294        ["Edit main kill file" gnus-summary-edit-global-kill t]
2295        ["Edit group parameters" gnus-summary-edit-parameters t]
2296        ["Customize group parameters" gnus-summary-customize-parameters t]
2297        ["Send a bug report" gnus-bug t]
2298        ("Exit"
2299         ["Catchup and exit" gnus-summary-catchup-and-exit
2300          ,@(if (featurep 'xemacs) '(t)
2301              '(:help "Mark unread articles in this group as read, then exit"))]
2302         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2303         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2304         ["Exit group" gnus-summary-exit
2305          ,@(if (featurep 'xemacs) '(t)
2306              '(:help "Exit current group, return to group selection mode"))]
2307         ["Exit group without updating" gnus-summary-exit-no-update t]
2308         ["Exit and goto next group" gnus-summary-next-group t]
2309         ["Exit and goto prev group" gnus-summary-prev-group t]
2310         ["Reselect group" gnus-summary-reselect-current-group t]
2311         ["Rescan group" gnus-summary-rescan-group t]
2312         ["Update dribble" gnus-summary-save-newsrc t])))
2313
2314     (gnus-run-hooks 'gnus-summary-menu-hook)))
2315
2316 (defvar gnus-summary-tool-bar-map nil)
2317
2318 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2319 (defun gnus-summary-make-tool-bar ()
2320   (if (and (fboundp 'tool-bar-add-item-from-menu)
2321            (default-value 'tool-bar-mode)
2322            (not gnus-summary-tool-bar-map))
2323       (setq gnus-summary-tool-bar-map
2324             (let ((tool-bar-map (make-sparse-keymap))
2325                   (load-path (mm-image-load-path)))
2326               (tool-bar-add-item-from-menu
2327                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2328               (tool-bar-add-item-from-menu
2329                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2330               (tool-bar-add-item-from-menu
2331                'gnus-summary-post-news "post" gnus-summary-mode-map)
2332               (tool-bar-add-item-from-menu
2333                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2334               (tool-bar-add-item-from-menu
2335                'gnus-summary-followup "followup" gnus-summary-mode-map)
2336               (tool-bar-add-item-from-menu
2337                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2338               (tool-bar-add-item-from-menu
2339                'gnus-summary-reply "reply" gnus-summary-mode-map)
2340               (tool-bar-add-item-from-menu
2341                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2342               (tool-bar-add-item-from-menu
2343                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2344               (tool-bar-add-item-from-menu
2345                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2346               (tool-bar-add-item-from-menu
2347                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2348               (tool-bar-add-item-from-menu
2349                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2350               (tool-bar-add-item-from-menu
2351                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2352               (tool-bar-add-item-from-menu
2353                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2354               (tool-bar-add-item-from-menu
2355                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2356               tool-bar-map)))
2357   (if gnus-summary-tool-bar-map
2358       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2359
2360 (defun gnus-score-set-default (var value)
2361   "A version of set that updates the GNU Emacs menu-bar."
2362   (set var value)
2363   ;; It is the message that forces the active status to be updated.
2364   (message ""))
2365
2366 (defun gnus-make-score-map (type)
2367   "Make a summary score map of type TYPE."
2368   (if t
2369       nil
2370     (let ((headers '(("author" "from" string)
2371                      ("subject" "subject" string)
2372                      ("article body" "body" string)
2373                      ("article head" "head" string)
2374                      ("xref" "xref" string)
2375                      ("extra header" "extra" string)
2376                      ("lines" "lines" number)
2377                      ("followups to author" "followup" string)))
2378           (types '((number ("less than" <)
2379                            ("greater than" >)
2380                            ("equal" =))
2381                    (string ("substring" s)
2382                            ("exact string" e)
2383                            ("fuzzy string" f)
2384                            ("regexp" r))))
2385           (perms '(("temporary" (current-time-string))
2386                    ("permanent" nil)
2387                    ("immediate" now)))
2388           header)
2389       (list
2390        (apply
2391         'nconc
2392         (list
2393          (if (eq type 'lower)
2394              "Lower score"
2395            "Increase score"))
2396         (let (outh)
2397           (while headers
2398             (setq header (car headers))
2399             (setq outh
2400                   (cons
2401                    (apply
2402                     'nconc
2403                     (list (car header))
2404                     (let ((ts (cdr (assoc (nth 2 header) types)))
2405                           outt)
2406                       (while ts
2407                         (setq outt
2408                               (cons
2409                                (apply
2410                                 'nconc
2411                                 (list (caar ts))
2412                                 (let ((ps perms)
2413                                       outp)
2414                                   (while ps
2415                                     (setq outp
2416                                           (cons
2417                                            (vector
2418                                             (caar ps)
2419                                             (list
2420                                              'gnus-summary-score-entry
2421                                              (nth 1 header)
2422                                              (if (or (string= (nth 1 header)
2423                                                               "head")
2424                                                      (string= (nth 1 header)
2425                                                               "body"))
2426                                                  ""
2427                                                (list 'gnus-summary-header
2428                                                      (nth 1 header)))
2429                                              (list 'quote (nth 1 (car ts)))
2430                                              (list 'gnus-score-delta-default
2431                                                    nil)
2432                                              (nth 1 (car ps))
2433                                              t)
2434                                             t)
2435                                            outp))
2436                                     (setq ps (cdr ps)))
2437                                   (list (nreverse outp))))
2438                                outt))
2439                         (setq ts (cdr ts)))
2440                       (list (nreverse outt))))
2441                    outh))
2442             (setq headers (cdr headers)))
2443           (list (nreverse outh))))))))
2444
2445 \f
2446
2447 (defun gnus-summary-mode (&optional group)
2448   "Major mode for reading articles.
2449
2450 All normal editing commands are switched off.
2451 \\<gnus-summary-mode-map>
2452 Each line in this buffer represents one article.  To read an
2453 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2454 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2455 respectively.
2456
2457 You can also post articles and send mail from this buffer.  To
2458 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2459 of an article, type `\\[gnus-summary-reply]'.
2460
2461 There are approx. one gazillion commands you can execute in this
2462 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2463
2464 The following commands are available:
2465
2466 \\{gnus-summary-mode-map}"
2467   (interactive)
2468   (kill-all-local-variables)
2469   (when (gnus-visual-p 'summary-menu 'menu)
2470     (gnus-summary-make-menu-bar)
2471     (gnus-summary-make-tool-bar))
2472   (gnus-summary-make-local-variables)
2473   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2474     (gnus-summary-make-local-variables))
2475   (gnus-make-thread-indent-array)
2476   (gnus-simplify-mode-line)
2477   (setq major-mode 'gnus-summary-mode)
2478   (setq mode-name "Summary")
2479   (make-local-variable 'minor-mode-alist)
2480   (use-local-map gnus-summary-mode-map)
2481   (buffer-disable-undo)
2482   (setq buffer-read-only t)             ;Disable modification
2483   (setq truncate-lines t)
2484   (setq selective-display t)
2485   (setq selective-display-ellipses t)   ;Display `...'
2486   (gnus-summary-set-display-table)
2487   (gnus-set-default-directory)
2488   (setq gnus-newsgroup-name group)
2489   (unless (gnus-news-group-p group)
2490     (setq gnus-newsgroup-incorporated
2491           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2492   (make-local-variable 'gnus-summary-line-format)
2493   (make-local-variable 'gnus-summary-line-format-spec)
2494   (make-local-variable 'gnus-summary-dummy-line-format)
2495   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2496   (make-local-variable 'gnus-summary-mark-positions)
2497   (make-local-hook 'pre-command-hook)
2498   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2499   (gnus-run-hooks 'gnus-summary-mode-hook)
2500   (turn-on-gnus-mailing-list-mode)
2501   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2502   (gnus-update-summary-mark-positions))
2503
2504 (defun gnus-summary-make-local-variables ()
2505   "Make all the local summary buffer variables."
2506   (let (global)
2507     (dolist (local gnus-summary-local-variables)
2508       (if (consp local)
2509           (progn
2510             (if (eq (cdr local) 'global)
2511                 ;; Copy the global value of the variable.
2512                 (setq global (symbol-value (car local)))
2513               ;; Use the value from the list.
2514               (setq global (eval (cdr local))))
2515             (set (make-local-variable (car local)) global))
2516         ;; Simple nil-valued local variable.
2517         (set (make-local-variable local) nil)))))
2518
2519 (defun gnus-summary-clear-local-variables ()
2520   (let ((locals gnus-summary-local-variables))
2521     (while locals
2522       (if (consp (car locals))
2523           (and (vectorp (caar locals))
2524                (set (caar locals) nil))
2525         (and (vectorp (car locals))
2526              (set (car locals) nil)))
2527       (setq locals (cdr locals)))))
2528
2529 ;; Summary data functions.
2530
2531 (defmacro gnus-data-number (data)
2532   `(car ,data))
2533
2534 (defmacro gnus-data-set-number (data number)
2535   `(setcar ,data ,number))
2536
2537 (defmacro gnus-data-mark (data)
2538   `(nth 1 ,data))
2539
2540 (defmacro gnus-data-set-mark (data mark)
2541   `(setcar (nthcdr 1 ,data) ,mark))
2542
2543 (defmacro gnus-data-pos (data)
2544   `(nth 2 ,data))
2545
2546 (defmacro gnus-data-set-pos (data pos)
2547   `(setcar (nthcdr 2 ,data) ,pos))
2548
2549 (defmacro gnus-data-header (data)
2550   `(nth 3 ,data))
2551
2552 (defmacro gnus-data-set-header (data header)
2553   `(setcar (nthcdr 3 ,data) ,header))
2554
2555 (defmacro gnus-data-level (data)
2556   `(nth 4 ,data))
2557
2558 (defmacro gnus-data-unread-p (data)
2559   `(= (nth 1 ,data) gnus-unread-mark))
2560
2561 (defmacro gnus-data-read-p (data)
2562   `(/= (nth 1 ,data) gnus-unread-mark))
2563
2564 (defmacro gnus-data-pseudo-p (data)
2565   `(consp (nth 3 ,data)))
2566
2567 (defmacro gnus-data-find (number)
2568   `(assq ,number gnus-newsgroup-data))
2569
2570 (defmacro gnus-data-find-list (number &optional data)
2571   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2572      (memq (assq ,number bdata)
2573            bdata)))
2574
2575 (defmacro gnus-data-make (number mark pos header level)
2576   `(list ,number ,mark ,pos ,header ,level))
2577
2578 (defun gnus-data-enter (after-article number mark pos header level offset)
2579   (let ((data (gnus-data-find-list after-article)))
2580     (unless data
2581       (error "No such article: %d" after-article))
2582     (setcdr data (cons (gnus-data-make number mark pos header level)
2583                        (cdr data)))
2584     (setq gnus-newsgroup-data-reverse nil)
2585     (gnus-data-update-list (cddr data) offset)))
2586
2587 (defun gnus-data-enter-list (after-article list &optional offset)
2588   (when list
2589     (let ((data (and after-article (gnus-data-find-list after-article)))
2590           (ilist list))
2591       (if (not (or data
2592                    after-article))
2593           (let ((odata gnus-newsgroup-data))
2594             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2595             (when offset
2596               (gnus-data-update-list odata offset)))
2597         ;; Find the last element in the list to be spliced into the main
2598         ;; list.
2599         (while (cdr list)
2600           (setq list (cdr list)))
2601         (if (not data)
2602             (progn
2603               (setcdr list gnus-newsgroup-data)
2604               (setq gnus-newsgroup-data ilist)
2605               (when offset
2606                 (gnus-data-update-list (cdr list) offset)))
2607           (setcdr list (cdr data))
2608           (setcdr data ilist)
2609           (when offset
2610             (gnus-data-update-list (cdr list) offset))))
2611       (setq gnus-newsgroup-data-reverse nil))))
2612
2613 (defun gnus-data-remove (article &optional offset)
2614   (let ((data gnus-newsgroup-data))
2615     (if (= (gnus-data-number (car data)) article)
2616         (progn
2617           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2618                 gnus-newsgroup-data-reverse nil)
2619           (when offset
2620             (gnus-data-update-list gnus-newsgroup-data offset)))
2621       (while (cdr data)
2622         (when (= (gnus-data-number (cadr data)) article)
2623           (setcdr data (cddr data))
2624           (when offset
2625             (gnus-data-update-list (cdr data) offset))
2626           (setq data nil
2627                 gnus-newsgroup-data-reverse nil))
2628         (setq data (cdr data))))))
2629
2630 (defmacro gnus-data-list (backward)
2631   `(if ,backward
2632        (or gnus-newsgroup-data-reverse
2633            (setq gnus-newsgroup-data-reverse
2634                  (reverse gnus-newsgroup-data)))
2635      gnus-newsgroup-data))
2636
2637 (defun gnus-data-update-list (data offset)
2638   "Add OFFSET to the POS of all data entries in DATA."
2639   (setq gnus-newsgroup-data-reverse nil)
2640   (while data
2641     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2642     (setq data (cdr data))))
2643
2644 (defun gnus-summary-article-pseudo-p (article)
2645   "Say whether this article is a pseudo article or not."
2646   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2647
2648 (defmacro gnus-summary-article-sparse-p (article)
2649   "Say whether this article is a sparse article or not."
2650   `(memq ,article gnus-newsgroup-sparse))
2651
2652 (defmacro gnus-summary-article-ancient-p (article)
2653   "Say whether this article is a sparse article or not."
2654   `(memq ,article gnus-newsgroup-ancient))
2655
2656 (defun gnus-article-parent-p (number)
2657   "Say whether this article is a parent or not."
2658   (let ((data (gnus-data-find-list number)))
2659     (and (cdr data)                     ; There has to be an article after...
2660          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2661             (gnus-data-level (nth 1 data))))))
2662
2663 (defun gnus-article-children (number)
2664   "Return a list of all children to NUMBER."
2665   (let* ((data (gnus-data-find-list number))
2666          (level (gnus-data-level (car data)))
2667          children)
2668     (setq data (cdr data))
2669     (while (and data
2670                 (= (gnus-data-level (car data)) (1+ level)))
2671       (push (gnus-data-number (car data)) children)
2672       (setq data (cdr data)))
2673     children))
2674
2675 (defmacro gnus-summary-skip-intangible ()
2676   "If the current article is intangible, then jump to a different article."
2677   '(let ((to (get-text-property (point) 'gnus-intangible)))
2678      (and to (gnus-summary-goto-subject to))))
2679
2680 (defmacro gnus-summary-article-intangible-p ()
2681   "Say whether this article is intangible or not."
2682   '(get-text-property (point) 'gnus-intangible))
2683
2684 (defun gnus-article-read-p (article)
2685   "Say whether ARTICLE is read or not."
2686   (not (or (memq article gnus-newsgroup-marked)
2687            (memq article gnus-newsgroup-unreads)
2688            (memq article gnus-newsgroup-unselected)
2689            (memq article gnus-newsgroup-dormant))))
2690
2691 ;; Some summary mode macros.
2692
2693 (defmacro gnus-summary-article-number ()
2694   "The article number of the article on the current line.
2695 If there isn's an article number here, then we return the current
2696 article number."
2697   '(progn
2698      (gnus-summary-skip-intangible)
2699      (or (get-text-property (point) 'gnus-number)
2700          (gnus-summary-last-subject))))
2701
2702 (defmacro gnus-summary-article-header (&optional number)
2703   "Return the header of article NUMBER."
2704   `(gnus-data-header (gnus-data-find
2705                       ,(or number '(gnus-summary-article-number)))))
2706
2707 (defmacro gnus-summary-thread-level (&optional number)
2708   "Return the level of thread that starts with article NUMBER."
2709   `(if (and (eq gnus-summary-make-false-root 'dummy)
2710             (get-text-property (point) 'gnus-intangible))
2711        0
2712      (gnus-data-level (gnus-data-find
2713                        ,(or number '(gnus-summary-article-number))))))
2714
2715 (defmacro gnus-summary-article-mark (&optional number)
2716   "Return the mark of article NUMBER."
2717   `(gnus-data-mark (gnus-data-find
2718                     ,(or number '(gnus-summary-article-number)))))
2719
2720 (defmacro gnus-summary-article-pos (&optional number)
2721   "Return the position of the line of article NUMBER."
2722   `(gnus-data-pos (gnus-data-find
2723                    ,(or number '(gnus-summary-article-number)))))
2724
2725 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2726 (defmacro gnus-summary-article-subject (&optional number)
2727   "Return current subject string or nil if nothing."
2728   `(let ((headers
2729           ,(if number
2730                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2731              '(gnus-data-header (assq (gnus-summary-article-number)
2732                                       gnus-newsgroup-data)))))
2733      (and headers
2734           (vectorp headers)
2735           (mail-header-subject headers))))
2736
2737 (defmacro gnus-summary-article-score (&optional number)
2738   "Return current article score."
2739   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2740                   gnus-newsgroup-scored))
2741        gnus-summary-default-score 0))
2742
2743 (defun gnus-summary-article-children (&optional number)
2744   "Return a list of article numbers that are children of article NUMBER."
2745   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2746          (level (gnus-data-level (car data)))
2747          l children)
2748     (while (and (setq data (cdr data))
2749                 (> (setq l (gnus-data-level (car data))) level))
2750       (and (= (1+ level) l)
2751            (push (gnus-data-number (car data))
2752                  children)))
2753     (nreverse children)))
2754
2755 (defun gnus-summary-article-parent (&optional number)
2756   "Return the article number of the parent of article NUMBER."
2757   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2758                                     (gnus-data-list t)))
2759          (level (gnus-data-level (car data))))
2760     (if (zerop level)
2761         ()                              ; This is a root.
2762       ;; We search until we find an article with a level less than
2763       ;; this one.  That function has to be the parent.
2764       (while (and (setq data (cdr data))
2765                   (not (< (gnus-data-level (car data)) level))))
2766       (and data (gnus-data-number (car data))))))
2767
2768 (defun gnus-unread-mark-p (mark)
2769   "Say whether MARK is the unread mark."
2770   (= mark gnus-unread-mark))
2771
2772 (defun gnus-read-mark-p (mark)
2773   "Say whether MARK is one of the marks that mark as read.
2774 This is all marks except unread, ticked, dormant, and expirable."
2775   (not (or (= mark gnus-unread-mark)
2776            (= mark gnus-ticked-mark)
2777            (= mark gnus-dormant-mark)
2778            (= mark gnus-expirable-mark))))
2779
2780 (defmacro gnus-article-mark (number)
2781   "Return the MARK of article NUMBER.
2782 This macro should only be used when computing the mark the \"first\"
2783 time; i.e., when generating the summary lines.  After that,
2784 `gnus-summary-article-mark' should be used to examine the
2785 marks of articles."
2786   `(cond
2787     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2788     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2789     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2790     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2791     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2792     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2793     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2794     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2795            gnus-ancient-mark))))
2796
2797 ;; Saving hidden threads.
2798
2799 (defmacro gnus-save-hidden-threads (&rest forms)
2800   "Save hidden threads, eval FORMS, and restore the hidden threads."
2801   (let ((config (make-symbol "config")))
2802     `(let ((,config (gnus-hidden-threads-configuration)))
2803        (unwind-protect
2804            (save-excursion
2805              ,@forms)
2806          (gnus-restore-hidden-threads-configuration ,config)))))
2807 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2808 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2809
2810 (defun gnus-data-compute-positions ()
2811   "Compute the positions of all articles."
2812   (setq gnus-newsgroup-data-reverse nil)
2813   (let ((data gnus-newsgroup-data))
2814     (save-excursion
2815       (gnus-save-hidden-threads
2816         (gnus-summary-show-all-threads)
2817         (goto-char (point-min))
2818         (while data
2819           (while (get-text-property (point) 'gnus-intangible)
2820             (forward-line 1))
2821           (gnus-data-set-pos (car data) (+ (point) 3))
2822           (setq data (cdr data))
2823           (forward-line 1))))))
2824
2825 (defun gnus-hidden-threads-configuration ()
2826   "Return the current hidden threads configuration."
2827   (save-excursion
2828     (let (config)
2829       (goto-char (point-min))
2830       (while (search-forward "\r" nil t)
2831         (push (1- (point)) config))
2832       config)))
2833
2834 (defun gnus-restore-hidden-threads-configuration (config)
2835   "Restore hidden threads configuration from CONFIG."
2836   (save-excursion
2837     (let (point buffer-read-only)
2838       (while (setq point (pop config))
2839         (when (and (< point (point-max))
2840                    (goto-char point)
2841                    (eq (char-after) ?\n))
2842           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2843
2844 ;; Various summary mode internalish functions.
2845
2846 (defun gnus-mouse-pick-article (e)
2847   (interactive "e")
2848   (mouse-set-point e)
2849   (gnus-summary-next-page nil t))
2850
2851 (defun gnus-summary-set-display-table ()
2852   "Change the display table.
2853 Odd characters have a tendency to mess
2854 up nicely formatted displays - we make all possible glyphs
2855 display only a single character."
2856
2857   ;; We start from the standard display table, if any.
2858   (let ((table (or (copy-sequence standard-display-table)
2859                    (make-display-table)))
2860         (i 32))
2861     ;; Nix out all the control chars...
2862     (while (>= (setq i (1- i)) 0)
2863       (aset table i [??]))
2864     ;; ... but not newline and cr, of course.  (cr is necessary for the
2865     ;; selective display).
2866     (aset table ?\n nil)
2867     (aset table ?\r nil)
2868     ;; We keep TAB as well.
2869     (aset table ?\t nil)
2870     ;; We nix out any glyphs over 126 that are not set already.
2871     (let ((i 256))
2872       (while (>= (setq i (1- i)) 127)
2873         ;; Only modify if the entry is nil.
2874         (unless (aref table i)
2875           (aset table i [??]))))
2876     (setq buffer-display-table table)))
2877
2878 (defun gnus-summary-set-article-display-arrow (pos)
2879   "Update the overlay arrow to point to line at position POS."
2880   (when (and gnus-summary-display-arrow
2881              (boundp 'overlay-arrow-position)
2882              (boundp 'overlay-arrow-string))
2883     (save-excursion
2884       (goto-char pos)
2885       (beginning-of-line)
2886       (unless overlay-arrow-position
2887         (setq overlay-arrow-position (make-marker)))
2888       (setq overlay-arrow-string "=>"
2889             overlay-arrow-position (set-marker overlay-arrow-position
2890                                                (point)
2891                                                (current-buffer))))))
2892
2893 (defun gnus-summary-buffer-name (group)
2894   "Return the summary buffer name of GROUP."
2895   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2896
2897 (defun gnus-summary-setup-buffer (group)
2898   "Initialize summary buffer."
2899   (let ((buffer (gnus-summary-buffer-name group))
2900         (dead-name (concat "*Dead Summary "
2901                            (gnus-group-decoded-name group) "*")))
2902     ;; If a dead summary buffer exists, we kill it.
2903     (when (gnus-buffer-live-p dead-name)
2904       (gnus-kill-buffer dead-name))
2905     (if (get-buffer buffer)
2906         (progn
2907           (set-buffer buffer)
2908           (setq gnus-summary-buffer (current-buffer))
2909           (not gnus-newsgroup-prepared))
2910       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2911       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2912       (gnus-summary-mode group)
2913       (when gnus-carpal
2914         (gnus-carpal-setup-buffer 'summary))
2915       (unless gnus-single-article-buffer
2916         (make-local-variable 'gnus-article-buffer)
2917         (make-local-variable 'gnus-article-current)
2918         (make-local-variable 'gnus-original-article-buffer))
2919       (setq gnus-newsgroup-name group)
2920       ;; Set any local variables in the group parameters.
2921       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2922       t)))
2923
2924 (defun gnus-set-global-variables ()
2925   "Set the global equivalents of the buffer-local variables.
2926 They are set to the latest values they had.  These reflect the summary
2927 buffer that was in action when the last article was fetched."
2928   (when (eq major-mode 'gnus-summary-mode)
2929     (setq gnus-summary-buffer (current-buffer))
2930     (let ((name gnus-newsgroup-name)
2931           (marked gnus-newsgroup-marked)
2932           (unread gnus-newsgroup-unreads)
2933           (headers gnus-current-headers)
2934           (data gnus-newsgroup-data)
2935           (summary gnus-summary-buffer)
2936           (article-buffer gnus-article-buffer)
2937           (original gnus-original-article-buffer)
2938           (gac gnus-article-current)
2939           (reffed gnus-reffed-article-number)
2940           (score-file gnus-current-score-file)
2941           (default-charset gnus-newsgroup-charset)
2942           vlist)
2943       (let ((locals gnus-newsgroup-variables))
2944         (while locals
2945           (if (consp (car locals))
2946               (push (eval (caar locals)) vlist)
2947             (push (eval (car locals)) vlist))
2948           (setq locals (cdr locals)))
2949         (setq vlist (nreverse vlist)))
2950       (save-excursion
2951         (set-buffer gnus-group-buffer)
2952         (setq gnus-newsgroup-name name
2953               gnus-newsgroup-marked marked
2954               gnus-newsgroup-unreads unread
2955               gnus-current-headers headers
2956               gnus-newsgroup-data data
2957               gnus-article-current gac
2958               gnus-summary-buffer summary
2959               gnus-article-buffer article-buffer
2960               gnus-original-article-buffer original
2961               gnus-reffed-article-number reffed
2962               gnus-current-score-file score-file
2963               gnus-newsgroup-charset default-charset)
2964         (let ((locals gnus-newsgroup-variables))
2965           (while locals
2966             (if (consp (car locals))
2967                 (set (caar locals) (pop vlist))
2968               (set (car locals) (pop vlist)))
2969             (setq locals (cdr locals))))
2970         ;; The article buffer also has local variables.
2971         (when (gnus-buffer-live-p gnus-article-buffer)
2972           (set-buffer gnus-article-buffer)
2973           (setq gnus-summary-buffer summary))))))
2974
2975 (defun gnus-summary-article-unread-p (article)
2976   "Say whether ARTICLE is unread or not."
2977   (memq article gnus-newsgroup-unreads))
2978
2979 (defun gnus-summary-first-article-p (&optional article)
2980   "Return whether ARTICLE is the first article in the buffer."
2981   (if (not (setq article (or article (gnus-summary-article-number))))
2982       nil
2983     (eq article (caar gnus-newsgroup-data))))
2984
2985 (defun gnus-summary-last-article-p (&optional article)
2986   "Return whether ARTICLE is the last article in the buffer."
2987   (if (not (setq article (or article (gnus-summary-article-number))))
2988       ;; All non-existent numbers are the last article.  :-)
2989       t
2990     (not (cdr (gnus-data-find-list article)))))
2991
2992 (defun gnus-make-thread-indent-array ()
2993   (let ((n 200))
2994     (unless (and gnus-thread-indent-array
2995                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2996       (setq gnus-thread-indent-array (make-vector 201 "")
2997             gnus-thread-indent-array-level gnus-thread-indent-level)
2998       (while (>= n 0)
2999         (aset gnus-thread-indent-array n
3000               (make-string (* n gnus-thread-indent-level) ? ))
3001         (setq n (1- n))))))
3002
3003 (defun gnus-update-summary-mark-positions ()
3004   "Compute where the summary marks are to go."
3005   (save-excursion
3006     (when (gnus-buffer-exists-p gnus-summary-buffer)
3007       (set-buffer gnus-summary-buffer))
3008     (let ((gnus-replied-mark 129)
3009           (gnus-score-below-mark 130)
3010           (gnus-score-over-mark 130)
3011           (gnus-download-mark 131)
3012           (spec gnus-summary-line-format-spec)
3013           gnus-visual pos)
3014       (save-excursion
3015         (gnus-set-work-buffer)
3016         (let ((gnus-summary-line-format-spec spec)
3017               (gnus-newsgroup-downloadable '((0 . t))))
3018           (gnus-summary-insert-line
3019            (make-full-mail-header 0 "" "nobody"
3020                                   "05 Apr 2001 23:33:09 +0400"
3021                                   "" "" 0 0 "" nil)
3022            0 nil 128 t nil "" nil 1)
3023           (goto-char (point-min))
3024           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3025                                              (- (point) 2)))))
3026           (goto-char (point-min))
3027           (push (cons 'replied (and (search-forward "\201" nil t)
3028                                     (- (point) 2)))
3029                 pos)
3030           (goto-char (point-min))
3031           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
3032                 pos)
3033           (goto-char (point-min))
3034           (push (cons 'download
3035                       (and (search-forward "\203" nil t) (- (point) 2)))
3036                 pos)))
3037       (setq gnus-summary-mark-positions pos))))
3038
3039 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3040   "Insert a dummy root in the summary buffer."
3041   (beginning-of-line)
3042   (gnus-add-text-properties
3043    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3044    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3045
3046 (defun gnus-summary-extract-address-component (from)
3047   (or (car (funcall gnus-extract-address-components from))
3048       from))
3049
3050 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3051   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3052                                 default-mime-charset)))
3053     ;; Is it really necessary to do this next part for each summary line?
3054     ;; Luckily, doesn't seem to slow things down much.
3055     (or
3056      (and gnus-ignored-from-addresses
3057           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3058           (let ((extra-headers (mail-header-extra header))
3059                 to
3060                 newsgroups)
3061             (cond
3062              ((setq to (cdr (assq 'To extra-headers)))
3063               (concat "-> "
3064                       (inline
3065                         (gnus-summary-extract-address-component
3066                          (funcall gnus-decode-encoded-word-function to)))))
3067              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3068               (concat "=> " newsgroups)))))
3069      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3070
3071 (defun gnus-summary-insert-line (gnus-tmp-header
3072                                  gnus-tmp-level gnus-tmp-current
3073                                  gnus-tmp-unread gnus-tmp-replied
3074                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3075                                  &optional gnus-tmp-dummy gnus-tmp-score
3076                                  gnus-tmp-process)
3077   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3078          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3079          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3080          (gnus-tmp-score-char
3081           (if (or (null gnus-summary-default-score)
3082                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3083                       gnus-summary-zcore-fuzz))
3084               ?\ ;;;Whitespace
3085             (if (< gnus-tmp-score gnus-summary-default-score)
3086                 gnus-score-below-mark gnus-score-over-mark)))
3087          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3088          (gnus-tmp-replied
3089           (cond (gnus-tmp-process gnus-process-mark)
3090                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3091                  gnus-cached-mark)
3092                 (gnus-tmp-replied gnus-replied-mark)
3093                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3094                  gnus-forwarded-mark)
3095                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3096                  gnus-saved-mark)
3097                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3098                  gnus-recent-mark)
3099                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3100                  gnus-unseen-mark)
3101                 (t gnus-no-mark)))
3102          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3103          (gnus-tmp-name
3104           (cond
3105            ((string-match "<[^>]+> *$" gnus-tmp-from)
3106             (let ((beg (match-beginning 0)))
3107               (or (and (string-match "^\".+\"" gnus-tmp-from)
3108                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3109                   (substring gnus-tmp-from 0 beg))))
3110            ((string-match "(.+)" gnus-tmp-from)
3111             (substring gnus-tmp-from
3112                        (1+ (match-beginning 0)) (1- (match-end 0))))
3113            (t gnus-tmp-from)))
3114          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3115          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3116          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3117          (buffer-read-only nil))
3118     (when (string= gnus-tmp-name "")
3119       (setq gnus-tmp-name gnus-tmp-from))
3120     (unless (numberp gnus-tmp-lines)
3121       (setq gnus-tmp-lines -1))
3122     (if (= gnus-tmp-lines -1)
3123         (setq gnus-tmp-lines "?")
3124       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3125     (gnus-put-text-property-excluding-characters-with-faces
3126      (point)
3127      (progn (eval gnus-summary-line-format-spec) (point))
3128      'gnus-number gnus-tmp-number)
3129     (when (gnus-visual-p 'summary-highlight 'highlight)
3130       (forward-line -1)
3131       (gnus-run-hooks 'gnus-summary-update-hook)
3132       (forward-line 1))))
3133
3134 (defun gnus-summary-update-line (&optional dont-update)
3135   "Update summary line after change."
3136   (when (and gnus-summary-default-score
3137              (not gnus-summary-inhibit-highlight))
3138     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3139            (article (gnus-summary-article-number))
3140            (score (gnus-summary-article-score article)))
3141       (unless dont-update
3142         (if (and gnus-summary-mark-below
3143                  (< (gnus-summary-article-score)
3144                     gnus-summary-mark-below))
3145             ;; This article has a low score, so we mark it as read.
3146             (when (memq article gnus-newsgroup-unreads)
3147               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3148           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3149             ;; This article was previously marked as read on account
3150             ;; of a low score, but now it has risen, so we mark it as
3151             ;; unread.
3152             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3153         (gnus-summary-update-mark
3154          (if (or (null gnus-summary-default-score)
3155                  (<= (abs (- score gnus-summary-default-score))
3156                      gnus-summary-zcore-fuzz))
3157              ?\ ;;;Whitespace
3158            (if (< score gnus-summary-default-score)
3159                gnus-score-below-mark gnus-score-over-mark))
3160          'score))
3161       ;; Do visual highlighting.
3162       (when (gnus-visual-p 'summary-highlight 'highlight)
3163         (gnus-run-hooks 'gnus-summary-update-hook)))))
3164
3165 (defvar gnus-tmp-new-adopts nil)
3166
3167 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3168   "Return the number of articles in THREAD.
3169 This may be 0 in some cases -- if none of the articles in
3170 the thread are to be displayed."
3171   (let* ((number
3172           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3173           (cond
3174            ((not (listp thread))
3175             1)
3176            ((and (consp thread) (cdr thread))
3177             (apply
3178              '+ 1 (mapcar
3179                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3180            ((null thread)
3181             1)
3182            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3183             1)
3184            (t 0))))
3185     (when (and level (zerop level) gnus-tmp-new-adopts)
3186       (incf number
3187             (apply '+ (mapcar
3188                        'gnus-summary-number-of-articles-in-thread
3189                        gnus-tmp-new-adopts))))
3190     (if char
3191         (if (> number 1) gnus-not-empty-thread-mark
3192           gnus-empty-thread-mark)
3193       number)))
3194
3195 (defun gnus-summary-set-local-parameters (group)
3196   "Go through the local params of GROUP and set all variable specs in that list."
3197   (let ((params (gnus-group-find-parameter group))
3198         (vars '(quit-config))           ; Ignore quit-config.
3199         elem)
3200     (while params
3201       (setq elem (car params)
3202             params (cdr params))
3203       (and (consp elem)                 ; Has to be a cons.
3204            (consp (cdr elem))           ; The cdr has to be a list.
3205            (symbolp (car elem))         ; Has to be a symbol in there.
3206            (not (memq (car elem) vars))
3207            (ignore-errors               ; So we set it.
3208              (push (car elem) vars)
3209              (make-local-variable (car elem))
3210              (set (car elem) (eval (nth 1 elem))))))))
3211
3212 (defun gnus-summary-read-group (group &optional show-all no-article
3213                                       kill-buffer no-display backward
3214                                       select-articles)
3215   "Start reading news in newsgroup GROUP.
3216 If SHOW-ALL is non-nil, already read articles are also listed.
3217 If NO-ARTICLE is non-nil, no article is selected initially.
3218 If NO-DISPLAY, don't generate a summary buffer."
3219   (let (result)
3220     (while (and group
3221                 (null (setq result
3222                             (let ((gnus-auto-select-next nil))
3223                               (or (gnus-summary-read-group-1
3224                                    group show-all no-article
3225                                    kill-buffer no-display
3226                                    select-articles)
3227                                   (setq show-all nil
3228                                         select-articles nil)))))
3229                 (eq gnus-auto-select-next 'quietly))
3230       (set-buffer gnus-group-buffer)
3231       ;; The entry function called above goes to the next
3232       ;; group automatically, so we go two groups back
3233       ;; if we are searching for the previous group.
3234       (when backward
3235         (gnus-group-prev-unread-group 2))
3236       (if (not (equal group (gnus-group-group-name)))
3237           (setq group (gnus-group-group-name))
3238         (setq group nil)))
3239     result))
3240
3241 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3242   "Directly jump to the other GROUP from summary buffer.
3243 If SHOW-ALL is non-nil, already read articles are also listed."
3244   (interactive
3245    (if (eq gnus-summary-buffer (current-buffer))
3246        (list (completing-read
3247               "Group: " gnus-active-hashtb nil t
3248               (when (and gnus-newsgroup-name
3249                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3250                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3251               'gnus-group-history)
3252              current-prefix-arg)
3253      (error "%s must be invoked from a gnus summary buffer." this-command)))
3254   (unless (or (zerop (length group))
3255               (and gnus-newsgroup-name
3256                    (string-equal gnus-newsgroup-name group)))
3257     (gnus-summary-exit)
3258     (gnus-summary-read-group group show-all
3259                              gnus-dont-select-after-jump-to-other-group)))
3260
3261 (defun gnus-summary-read-group-1 (group show-all no-article
3262                                         kill-buffer no-display
3263                                         &optional select-articles)
3264   ;; Killed foreign groups can't be entered.
3265   ;;  (when (and (not (gnus-group-native-p group))
3266   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3267   ;;    (error "Dead non-native groups can't be entered"))
3268   (gnus-message 5 "Retrieving newsgroup: %s..."
3269                 (gnus-group-decoded-name group))
3270   (let* ((new-group (gnus-summary-setup-buffer group))
3271          (quit-config (gnus-group-quit-config group))
3272          (did-select (and new-group (gnus-select-newsgroup
3273                                      group show-all select-articles))))
3274     (cond
3275      ;; This summary buffer exists already, so we just select it.
3276      ((not new-group)
3277       (gnus-set-global-variables)
3278       (when kill-buffer
3279         (gnus-kill-or-deaden-summary kill-buffer))
3280       (gnus-configure-windows 'summary 'force)
3281       (gnus-set-mode-line 'summary)
3282       (gnus-summary-position-point)
3283       (message "")
3284       t)
3285      ;; We couldn't select this group.
3286      ((null did-select)
3287       (when (and (eq major-mode 'gnus-summary-mode)
3288                  (not (equal (current-buffer) kill-buffer)))
3289         (kill-buffer (current-buffer))
3290         (if (not quit-config)
3291             (progn
3292               ;; Update the info -- marks might need to be removed,
3293               ;; for instance.
3294               (gnus-summary-update-info)
3295               (set-buffer gnus-group-buffer)
3296               (gnus-group-jump-to-group group)
3297               (gnus-group-next-unread-group 1))
3298           (gnus-handle-ephemeral-exit quit-config)))
3299       (let ((grpinfo (gnus-get-info group)))
3300         (if (null (gnus-info-read grpinfo))
3301             (gnus-message 3 "Group %s contains no messages"
3302                           (gnus-group-decoded-name group))
3303           (gnus-message 3 "Can't select group")))
3304       nil)
3305      ;; The user did a `C-g' while prompting for number of articles,
3306      ;; so we exit this group.
3307      ((eq did-select 'quit)
3308       (and (eq major-mode 'gnus-summary-mode)
3309            (not (equal (current-buffer) kill-buffer))
3310            (kill-buffer (current-buffer)))
3311       (when kill-buffer
3312         (gnus-kill-or-deaden-summary kill-buffer))
3313       (if (not quit-config)
3314           (progn
3315             (set-buffer gnus-group-buffer)
3316             (gnus-group-jump-to-group group)
3317             (gnus-group-next-unread-group 1)
3318             (gnus-configure-windows 'group 'force))
3319         (gnus-handle-ephemeral-exit quit-config))
3320       ;; Finally signal the quit.
3321       (signal 'quit nil))
3322      ;; The group was successfully selected.
3323      (t
3324       (gnus-set-global-variables)
3325       ;; Save the active value in effect when the group was entered.
3326       (setq gnus-newsgroup-active
3327             (gnus-copy-sequence
3328              (gnus-active gnus-newsgroup-name)))
3329       ;; You can change the summary buffer in some way with this hook.
3330       (gnus-run-hooks 'gnus-select-group-hook)
3331       (gnus-update-format-specifications
3332        nil 'summary 'summary-mode 'summary-dummy)
3333       (gnus-update-summary-mark-positions)
3334       ;; Do score processing.
3335       (when gnus-use-scoring
3336         (gnus-possibly-score-headers))
3337       ;; Check whether to fill in the gaps in the threads.
3338       (when gnus-build-sparse-threads
3339         (gnus-build-sparse-threads))
3340       ;; Find the initial limit.
3341       (if gnus-show-threads
3342           (if show-all
3343               (let ((gnus-newsgroup-dormant nil))
3344                 (gnus-summary-initial-limit show-all))
3345             (gnus-summary-initial-limit show-all))
3346         ;; When untreaded, all articles are always shown.
3347         (setq gnus-newsgroup-limit
3348               (mapcar
3349                (lambda (header) (mail-header-number header))
3350                gnus-newsgroup-headers)))
3351       ;; Generate the summary buffer.
3352       (unless no-display
3353         (gnus-summary-prepare))
3354       (when gnus-use-trees
3355         (gnus-tree-open group)
3356         (setq gnus-summary-highlight-line-function
3357               'gnus-tree-highlight-article))
3358       ;; If the summary buffer is empty, but there are some low-scored
3359       ;; articles or some excluded dormants, we include these in the
3360       ;; buffer.
3361       (when (and (zerop (buffer-size))
3362                  (not no-display))
3363         (cond (gnus-newsgroup-dormant
3364                (gnus-summary-limit-include-dormant))
3365               ((and gnus-newsgroup-scored show-all)
3366                (gnus-summary-limit-include-expunged t))))
3367       ;; Function `gnus-apply-kill-file' must be called in this hook.
3368       (gnus-run-hooks 'gnus-apply-kill-hook)
3369       (if (and (zerop (buffer-size))
3370                (not no-display))
3371           (progn
3372             ;; This newsgroup is empty.
3373             (gnus-summary-catchup-and-exit nil t)
3374             (gnus-message 6 "No unread news")
3375             (when kill-buffer
3376               (gnus-kill-or-deaden-summary kill-buffer))
3377             ;; Return nil from this function.
3378             nil)
3379         ;; Hide conversation thread subtrees.  We cannot do this in
3380         ;; gnus-summary-prepare-hook since kill processing may not
3381         ;; work with hidden articles.
3382         (gnus-summary-maybe-hide-threads)
3383         (when kill-buffer
3384           (gnus-kill-or-deaden-summary kill-buffer))
3385         (gnus-summary-auto-select-subject)
3386         ;; Show first unread article if requested.
3387         (if (and (not no-article)
3388                  (not no-display)
3389                  gnus-newsgroup-unreads
3390                  gnus-auto-select-first)
3391             (progn
3392               (gnus-configure-windows 'summary)
3393               (let ((art (gnus-summary-article-number)))
3394                 (unless (or (memq art gnus-newsgroup-undownloaded)
3395                             (memq art gnus-newsgroup-downloadable))
3396                   (gnus-summary-goto-article art))))
3397           ;; Don't select any articles.
3398           (gnus-summary-position-point)
3399           (gnus-configure-windows 'summary 'force)
3400           (gnus-set-mode-line 'summary))
3401         (when (get-buffer-window gnus-group-buffer t)
3402           ;; Gotta use windows, because recenter does weird stuff if
3403           ;; the current buffer ain't the displayed window.
3404           (let ((owin (selected-window)))
3405             (select-window (get-buffer-window gnus-group-buffer t))
3406             (when (gnus-group-goto-group group)
3407               (recenter))
3408             (select-window owin)))
3409         ;; Mark this buffer as "prepared".
3410         (setq gnus-newsgroup-prepared t)
3411         (gnus-run-hooks 'gnus-summary-prepared-hook)
3412         t)))))
3413
3414 (defun gnus-summary-auto-select-subject ()
3415   "Select the subject line on initial group entry."
3416   (goto-char (point-min))
3417   (cond
3418    ((eq gnus-auto-select-subject 'best)
3419     (gnus-summary-best-unread-subject))
3420    ((eq gnus-auto-select-subject 'unread)
3421     (gnus-summary-first-unread-subject))
3422    ((eq gnus-auto-select-subject 'unseen)
3423     (gnus-summary-first-unseen-subject))
3424    ((eq gnus-auto-select-subject 'unseen-or-unread)
3425     (gnus-summary-first-unseen-or-unread-subject))
3426    ((eq gnus-auto-select-subject 'first)
3427     ;; Do nothing.
3428     )
3429    ((gnus-functionp gnus-auto-select-subject)
3430     (funcall gnus-auto-select-subject))))
3431
3432 (defun gnus-summary-prepare ()
3433   "Generate the summary buffer."
3434   (interactive)
3435   (let ((buffer-read-only nil))
3436     (erase-buffer)
3437     (setq gnus-newsgroup-data nil
3438           gnus-newsgroup-data-reverse nil)
3439     (gnus-run-hooks 'gnus-summary-generate-hook)
3440     ;; Generate the buffer, either with threads or without.
3441     (when gnus-newsgroup-headers
3442       (gnus-summary-prepare-threads
3443        (if gnus-show-threads
3444            (gnus-sort-gathered-threads
3445             (funcall gnus-summary-thread-gathering-function
3446                      (gnus-sort-threads
3447                       (gnus-cut-threads (gnus-make-threads)))))
3448          ;; Unthreaded display.
3449          (gnus-sort-articles gnus-newsgroup-headers))))
3450     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3451     ;; Call hooks for modifying summary buffer.
3452     (goto-char (point-min))
3453     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3454
3455 (defsubst gnus-general-simplify-subject (subject)
3456   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3457   (setq subject
3458         (cond
3459          ;; Truncate the subject.
3460          (gnus-simplify-subject-functions
3461           (gnus-map-function gnus-simplify-subject-functions subject))
3462          ((numberp gnus-summary-gather-subject-limit)
3463           (setq subject (gnus-simplify-subject-re subject))
3464           (if (> (length subject) gnus-summary-gather-subject-limit)
3465               (substring subject 0 gnus-summary-gather-subject-limit)
3466             subject))
3467          ;; Fuzzily simplify it.
3468          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3469           (gnus-simplify-subject-fuzzy subject))
3470          ;; Just remove the leading "Re:".
3471          (t
3472           (gnus-simplify-subject-re subject))))
3473
3474   (if (and gnus-summary-gather-exclude-subject
3475            (string-match gnus-summary-gather-exclude-subject subject))
3476       nil                               ; This article shouldn't be gathered
3477     subject))
3478
3479 (defun gnus-summary-simplify-subject-query ()
3480   "Query where the respool algorithm would put this article."
3481   (interactive)
3482   (gnus-summary-select-article)
3483   (message "%s"
3484            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3485
3486 (defun gnus-gather-threads-by-subject (threads)
3487   "Gather threads by looking at Subject headers."
3488   (if (not gnus-summary-make-false-root)
3489       threads
3490     (let ((hashtb (gnus-make-hashtable 1024))
3491           (prev threads)
3492           (result threads)
3493           subject hthread whole-subject)
3494       (while threads
3495         (setq subject (gnus-general-simplify-subject
3496                        (setq whole-subject (mail-header-subject
3497                                             (caar threads)))))
3498         (when subject
3499           (if (setq hthread (gnus-gethash subject hashtb))
3500               (progn
3501                 ;; We enter a dummy root into the thread, if we
3502                 ;; haven't done that already.
3503                 (unless (stringp (caar hthread))
3504                   (setcar hthread (list whole-subject (car hthread))))
3505                 ;; We add this new gathered thread to this gathered
3506                 ;; thread.
3507                 (setcdr (car hthread)
3508                         (nconc (cdar hthread) (list (car threads))))
3509                 ;; Remove it from the list of threads.
3510                 (setcdr prev (cdr threads))
3511                 (setq threads prev))
3512             ;; Enter this thread into the hash table.
3513             (gnus-sethash subject threads hashtb)))
3514         (setq prev threads)
3515         (setq threads (cdr threads)))
3516       result)))
3517
3518 (defun gnus-gather-threads-by-references (threads)
3519   "Gather threads by looking at References headers."
3520   (let ((idhashtb (gnus-make-hashtable 1024))
3521         (thhashtb (gnus-make-hashtable 1024))
3522         (prev threads)
3523         (result threads)
3524         ids references id gthread gid entered ref)
3525     (while threads
3526       (when (setq references (mail-header-references (caar threads)))
3527         (setq id (mail-header-id (caar threads))
3528               ids (inline (gnus-split-references references))
3529               entered nil)
3530         (while (setq ref (pop ids))
3531           (setq ids (delete ref ids))
3532           (if (not (setq gid (gnus-gethash ref idhashtb)))
3533               (progn
3534                 (gnus-sethash ref id idhashtb)
3535                 (gnus-sethash id threads thhashtb))
3536             (setq gthread (gnus-gethash gid thhashtb))
3537             (unless entered
3538               ;; We enter a dummy root into the thread, if we
3539               ;; haven't done that already.
3540               (unless (stringp (caar gthread))
3541                 (setcar gthread (list (mail-header-subject (caar gthread))
3542                                       (car gthread))))
3543               ;; We add this new gathered thread to this gathered
3544               ;; thread.
3545               (setcdr (car gthread)
3546                       (nconc (cdar gthread) (list (car threads)))))
3547             ;; Add it into the thread hash table.
3548             (gnus-sethash id gthread thhashtb)
3549             (setq entered t)
3550             ;; Remove it from the list of threads.
3551             (setcdr prev (cdr threads))
3552             (setq threads prev))))
3553       (setq prev threads)
3554       (setq threads (cdr threads)))
3555     result))
3556
3557 (defun gnus-sort-gathered-threads (threads)
3558   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3559   (let ((result threads))
3560     (while threads
3561       (when (stringp (caar threads))
3562         (setcdr (car threads)
3563                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3564       (setq threads (cdr threads)))
3565     result))
3566
3567 (defun gnus-thread-loop-p (root thread)
3568   "Say whether ROOT is in THREAD."
3569   (let ((stack (list thread))
3570         (infloop 0)
3571         th)
3572     (while (setq thread (pop stack))
3573       (setq th (cdr thread))
3574       (while (and th
3575                   (not (eq (caar th) root)))
3576         (pop th))
3577       (if th
3578           ;; We have found a loop.
3579           (let (ref-dep)
3580             (setcdr thread (delq (car th) (cdr thread)))
3581             (if (boundp (setq ref-dep (intern "none"
3582                                               gnus-newsgroup-dependencies)))
3583                 (setcdr (symbol-value ref-dep)
3584                         (nconc (cdr (symbol-value ref-dep))
3585                                (list (car th))))
3586               (set ref-dep (list nil (car th))))
3587             (setq infloop 1
3588                   stack nil))
3589         ;; Push all the subthreads onto the stack.
3590         (push (cdr thread) stack)))
3591     infloop))
3592
3593 (defun gnus-make-threads ()
3594   "Go through the dependency hashtb and find the roots.  Return all threads."
3595   (let (threads)
3596     (while (catch 'infloop
3597              (mapatoms
3598               (lambda (refs)
3599                 ;; Deal with self-referencing References loops.
3600                 (when (and (car (symbol-value refs))
3601                            (not (zerop
3602                                  (apply
3603                                   '+
3604                                   (mapcar
3605                                    (lambda (thread)
3606                                      (gnus-thread-loop-p
3607                                       (car (symbol-value refs)) thread))
3608                                    (cdr (symbol-value refs)))))))
3609                   (setq threads nil)
3610                   (throw 'infloop t))
3611                 (unless (car (symbol-value refs))
3612                   ;; These threads do not refer back to any other articles,
3613                   ;; so they're roots.
3614                   (setq threads (append (cdr (symbol-value refs)) threads))))
3615               gnus-newsgroup-dependencies)))
3616     threads))
3617
3618 ;; Build the thread tree.
3619 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3620   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3621
3622 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3623 if it was already present.
3624
3625 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3626 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3627 Message-IDs will be renamed to a unique Message-ID before being
3628 entered.
3629
3630 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3631   (let* ((id (mail-header-id header))
3632          (id-dep (and id (intern id dependencies)))
3633          ref ref-dep ref-header replaced)
3634     ;; Enter this `header' in the `dependencies' table.
3635     (cond
3636      ((not id-dep)
3637       (setq header nil))
3638      ;; The first two cases do the normal part: enter a new `header'
3639      ;; in the `dependencies' table.
3640      ((not (boundp id-dep))
3641       (set id-dep (list header)))
3642      ((null (car (symbol-value id-dep)))
3643       (setcar (symbol-value id-dep) header))
3644
3645      ;; From here the `header' was already present in the
3646      ;; `dependencies' table.
3647      (force-new
3648       ;; Overrides an existing entry;
3649       ;; just set the header part of the entry.
3650       (setcar (symbol-value id-dep) header)
3651       (setq replaced t))
3652
3653      ;; Renames the existing `header' to a unique Message-ID.
3654      ((not gnus-summary-ignore-duplicates)
3655       ;; An article with this Message-ID has already been seen.
3656       ;; We rename the Message-ID.
3657       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3658            (list header))
3659       (mail-header-set-id header id))
3660
3661      ;; The last case ignores an existing entry, except it adds any
3662      ;; additional Xrefs (in case the two articles came from different
3663      ;; servers.
3664      ;; Also sets `header' to `nil' meaning that the `dependencies'
3665      ;; table was *not* modified.
3666      (t
3667       (mail-header-set-xref
3668        (car (symbol-value id-dep))
3669        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3670                    "")
3671                (or (mail-header-xref header) "")))
3672       (setq header nil)))
3673
3674     (when (and header (not replaced))
3675       ;; First check that we are not creating a References loop.
3676       (setq ref (gnus-parent-id (mail-header-references header)))
3677       (while (and ref
3678                   (setq ref-dep (intern-soft ref dependencies))
3679                   (boundp ref-dep)
3680                   (setq ref-header (car (symbol-value ref-dep))))
3681         (if (string= id ref)
3682             ;; Yuk!  This is a reference loop.  Make the article be a
3683             ;; root article.
3684             (progn
3685               (mail-header-set-references (car (symbol-value id-dep)) "none")
3686               (setq ref nil))
3687           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3688       (setq ref (gnus-parent-id (mail-header-references header)))
3689       (setq ref-dep (intern (or ref "none") dependencies))
3690       (if (boundp ref-dep)
3691           (setcdr (symbol-value ref-dep)
3692                   (nconc (cdr (symbol-value ref-dep))
3693                          (list (symbol-value id-dep))))
3694         (set ref-dep (list nil (symbol-value id-dep)))))
3695     header))
3696
3697 (defun gnus-extract-message-id-from-in-reply-to (string)
3698   (if (string-match "<[^>]+>" string)
3699       (substring string (match-beginning 0) (match-end 0))
3700     nil))
3701
3702 (defun gnus-build-sparse-threads ()
3703   (let ((headers gnus-newsgroup-headers)
3704         (mail-parse-charset gnus-newsgroup-charset)
3705         (gnus-summary-ignore-duplicates t)
3706         header references generation relations
3707         subject child end new-child date)
3708     ;; First we create an alist of generations/relations, where
3709     ;; generations is how much we trust the relation, and the relation
3710     ;; is parent/child.
3711     (gnus-message 7 "Making sparse threads...")
3712     (save-excursion
3713       (nnheader-set-temp-buffer " *gnus sparse threads*")
3714       (while (setq header (pop headers))
3715         (when (and (setq references (mail-header-references header))
3716                    (not (string= references "")))
3717           (insert references)
3718           (setq child (mail-header-id header)
3719                 subject (mail-header-subject header)
3720                 date (mail-header-date header)
3721                 generation 0)
3722           (while (search-backward ">" nil t)
3723             (setq end (1+ (point)))
3724             (when (search-backward "<" nil t)
3725               (setq new-child (buffer-substring (point) end))
3726               (push (list (incf generation)
3727                           child (setq child new-child)
3728                           subject date)
3729                     relations)))
3730           (when child
3731             (push (list (1+ generation) child nil subject) relations))
3732           (erase-buffer)))
3733       (kill-buffer (current-buffer)))
3734     ;; Sort over trustworthiness.
3735     (mapcar
3736      (lambda (relation)
3737        (when (gnus-dependencies-add-header
3738               (make-full-mail-header-from-decoded-header
3739                gnus-reffed-article-number
3740                (nth 3 relation) "" (or (nth 4 relation) "")
3741                (nth 1 relation)
3742                (or (nth 2 relation) "") 0 0 "")
3743               gnus-newsgroup-dependencies nil)
3744          (push gnus-reffed-article-number gnus-newsgroup-limit)
3745          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3746          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3747                gnus-newsgroup-reads)
3748          (decf gnus-reffed-article-number)))
3749      (sort relations 'car-less-than-car))
3750     (gnus-message 7 "Making sparse threads...done")))
3751
3752 (defun gnus-build-old-threads ()
3753   ;; Look at all the articles that refer back to old articles, and
3754   ;; fetch the headers for the articles that aren't there.  This will
3755   ;; build complete threads - if the roots haven't been expired by the
3756   ;; server, that is.
3757   (let ((mail-parse-charset gnus-newsgroup-charset)
3758         id heads)
3759     (mapatoms
3760      (lambda (refs)
3761        (when (not (car (symbol-value refs)))
3762          (setq heads (cdr (symbol-value refs)))
3763          (while heads
3764            (if (memq (mail-header-number (caar heads))
3765                      gnus-newsgroup-dormant)
3766                (setq heads (cdr heads))
3767              (setq id (symbol-name refs))
3768              (while (and (setq id (gnus-build-get-header id))
3769                          (not (car (gnus-id-to-thread id)))))
3770              (setq heads nil)))))
3771      gnus-newsgroup-dependencies)))
3772
3773 ;; This function has to be called with point after the article number
3774 ;; on the beginning of the line.
3775 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3776   (let ((eol (gnus-point-at-eol))
3777         (buffer (current-buffer))
3778         header references in-reply-to)
3779
3780     ;; overview: [num subject from date id refs chars lines misc]
3781     (unwind-protect
3782         (progn
3783           (narrow-to-region (point) eol)
3784           (unless (eobp)
3785             (forward-char))
3786
3787           (setq header
3788                 (make-full-mail-header
3789                  number                         ; number
3790                  (nnheader-nov-field)           ; subject
3791                  (nnheader-nov-field)           ; from
3792                  (nnheader-nov-field)           ; date
3793                  (nnheader-nov-read-message-id) ; id
3794                  (nnheader-nov-field)           ; refs
3795                  (nnheader-nov-read-integer)    ; chars
3796                  (nnheader-nov-read-integer)    ; lines
3797                  (unless (eobp)
3798                    (if (looking-at "Xref: ")
3799                        (goto-char (match-end 0)))
3800                    (nnheader-nov-field))        ; Xref
3801                  (nnheader-nov-parse-extra))))  ; extra
3802
3803       (widen))
3804
3805     (when (and (string= references "")
3806                (setq in-reply-to (mail-header-extra header))
3807                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3808       (mail-header-set-references
3809        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3810
3811     (when gnus-alter-header-function
3812       (funcall gnus-alter-header-function header))
3813     (gnus-dependencies-add-header header dependencies force-new)))
3814
3815 (defun gnus-build-get-header (id)
3816   "Look through the buffer of NOV lines and find the header to ID.
3817 Enter this line into the dependencies hash table, and return
3818 the id of the parent article (if any)."
3819   (let ((deps gnus-newsgroup-dependencies)
3820         found header)
3821     (prog1
3822         (save-excursion
3823           (set-buffer nntp-server-buffer)
3824           (let ((case-fold-search nil))
3825             (goto-char (point-min))
3826             (while (and (not found)
3827                         (search-forward id nil t))
3828               (beginning-of-line)
3829               (setq found (looking-at
3830                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3831                                    (regexp-quote id))))
3832               (or found (beginning-of-line 2)))
3833             (when found
3834               (beginning-of-line)
3835               (and
3836                (setq header (gnus-nov-parse-line
3837                              (read (current-buffer)) deps))
3838                (gnus-parent-id (mail-header-references header))))))
3839       (when header
3840         (let ((number (mail-header-number header)))
3841           (push number gnus-newsgroup-limit)
3842           (push header gnus-newsgroup-headers)
3843           (if (memq number gnus-newsgroup-unselected)
3844               (progn
3845                 (setq gnus-newsgroup-unreads
3846                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3847                                                number))
3848                 (setq gnus-newsgroup-unselected
3849                       (delq number gnus-newsgroup-unselected)))
3850             (push number gnus-newsgroup-ancient)))))))
3851
3852 (defun gnus-build-all-threads ()
3853   "Read all the headers."
3854   (let ((gnus-summary-ignore-duplicates t)
3855         (mail-parse-charset gnus-newsgroup-charset)
3856         (dependencies gnus-newsgroup-dependencies)
3857         header article)
3858     (save-excursion
3859       (set-buffer nntp-server-buffer)
3860       (let ((case-fold-search nil))
3861         (goto-char (point-min))
3862         (while (not (eobp))
3863           (ignore-errors
3864             (setq article (read (current-buffer))
3865                   header (gnus-nov-parse-line article dependencies)))
3866           (when header
3867             (save-excursion
3868               (set-buffer gnus-summary-buffer)
3869               (push header gnus-newsgroup-headers)
3870               (if (memq (setq article (mail-header-number header))
3871                         gnus-newsgroup-unselected)
3872                   (progn
3873                     (setq gnus-newsgroup-unreads
3874                           (gnus-add-to-sorted-list
3875                            gnus-newsgroup-unreads article))
3876                     (setq gnus-newsgroup-unselected
3877                           (delq article gnus-newsgroup-unselected)))
3878                 (push article gnus-newsgroup-ancient)))
3879             (forward-line 1)))))))
3880
3881 (defun gnus-summary-update-article-line (article header)
3882   "Update the line for ARTICLE using HEADERS."
3883   (let* ((id (mail-header-id header))
3884          (thread (gnus-id-to-thread id)))
3885     (unless thread
3886       (error "Article in no thread"))
3887     ;; Update the thread.
3888     (setcar thread header)
3889     (gnus-summary-goto-subject article)
3890     (let* ((datal (gnus-data-find-list article))
3891            (data (car datal))
3892            (length (when (cdr datal)
3893                      (- (gnus-data-pos data)
3894                         (gnus-data-pos (cadr datal)))))
3895            (buffer-read-only nil)
3896            (level (gnus-summary-thread-level)))
3897       (gnus-delete-line)
3898       (gnus-summary-insert-line
3899        header level nil (gnus-article-mark article)
3900        (memq article gnus-newsgroup-replied)
3901        (memq article gnus-newsgroup-expirable)
3902        ;; Only insert the Subject string when it's different
3903        ;; from the previous Subject string.
3904        (if (and
3905             gnus-show-threads
3906             (gnus-subject-equal
3907              (condition-case ()
3908                  (mail-header-subject
3909                   (gnus-data-header
3910                    (cadr
3911                     (gnus-data-find-list
3912                      article
3913                      (gnus-data-list t)))))
3914                ;; Error on the side of excessive subjects.
3915                (error ""))
3916              (mail-header-subject header)))
3917            ""
3918          (mail-header-subject header))
3919        nil (cdr (assq article gnus-newsgroup-scored))
3920        (memq article gnus-newsgroup-processable))
3921       (when length
3922         (gnus-data-update-list
3923          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3924
3925 (defun gnus-summary-update-article (article &optional iheader)
3926   "Update ARTICLE in the summary buffer."
3927   (set-buffer gnus-summary-buffer)
3928   (let* ((header (gnus-summary-article-header article))
3929          (id (mail-header-id header))
3930          (data (gnus-data-find article))
3931          (thread (gnus-id-to-thread id))
3932          (references (mail-header-references header))
3933          (parent
3934           (gnus-id-to-thread
3935            (or (gnus-parent-id
3936                 (when (and references
3937                            (not (equal "" references)))
3938                   references))
3939                "none")))
3940          (buffer-read-only nil)
3941          (old (car thread)))
3942     (when thread
3943       (unless iheader
3944         (setcar thread nil)
3945         (when parent
3946           (delq thread parent)))
3947       (if (gnus-summary-insert-subject id header)
3948           ;; Set the (possibly) new article number in the data structure.
3949           (gnus-data-set-number data (gnus-id-to-article id))
3950         (setcar thread old)
3951         nil))))
3952
3953 (defun gnus-rebuild-thread (id &optional line)
3954   "Rebuild the thread containing ID.
3955 If LINE, insert the rebuilt thread starting on line LINE."
3956   (let ((buffer-read-only nil)
3957         old-pos current thread data)
3958     (if (not gnus-show-threads)
3959         (setq thread (list (car (gnus-id-to-thread id))))
3960       ;; Get the thread this article is part of.
3961       (setq thread (gnus-remove-thread id)))
3962     (setq old-pos (gnus-point-at-bol))
3963     (setq current (save-excursion
3964                     (and (re-search-backward "[\r\n]" nil t)
3965                          (gnus-summary-article-number))))
3966     ;; If this is a gathered thread, we have to go some re-gathering.
3967     (when (stringp (car thread))
3968       (let ((subject (car thread))
3969             roots thr)
3970         (setq thread (cdr thread))
3971         (while thread
3972           (unless (memq (setq thr (gnus-id-to-thread
3973                                    (gnus-root-id
3974                                     (mail-header-id (caar thread)))))
3975                         roots)
3976             (push thr roots))
3977           (setq thread (cdr thread)))
3978         ;; We now have all (unique) roots.
3979         (if (= (length roots) 1)
3980             ;; All the loose roots are now one solid root.
3981             (setq thread (car roots))
3982           (setq thread (cons subject (gnus-sort-threads roots))))))
3983     (let (threads)
3984       ;; We then insert this thread into the summary buffer.
3985       (when line
3986         (goto-char (point-min))
3987         (forward-line (1- line)))
3988       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3989         (if gnus-show-threads
3990             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3991           (gnus-summary-prepare-unthreaded thread))
3992         (setq data (nreverse gnus-newsgroup-data))
3993         (setq threads gnus-newsgroup-threads))
3994       ;; We splice the new data into the data structure.
3995       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3996       ;;!!! then we want to insert at the beginning of the buffer.
3997       ;;!!! That happens to be true with Gnus now, but that may
3998       ;;!!! change in the future.  Perhaps.
3999       (gnus-data-enter-list
4000        (if line nil current) data (- (point) old-pos))
4001       (setq gnus-newsgroup-threads
4002             (nconc threads gnus-newsgroup-threads))
4003       (gnus-data-compute-positions))))
4004
4005 (defun gnus-number-to-header (number)
4006   "Return the header for article NUMBER."
4007   (let ((headers gnus-newsgroup-headers))
4008     (while (and headers
4009                 (not (= number (mail-header-number (car headers)))))
4010       (pop headers))
4011     (when headers
4012       (car headers))))
4013
4014 (defun gnus-parent-headers (in-headers &optional generation)
4015   "Return the headers of the GENERATIONeth parent of HEADERS."
4016   (unless generation
4017     (setq generation 1))
4018   (let ((parent t)
4019         (headers in-headers)
4020         references)
4021     (while (and parent
4022                 (not (zerop generation))
4023                 (setq references (mail-header-references headers)))
4024       (setq headers (if (and references
4025                              (setq parent (gnus-parent-id references)))
4026                         (car (gnus-id-to-thread parent))
4027                       nil))
4028       (decf generation))
4029     (and (not (eq headers in-headers))
4030          headers)))
4031
4032 (defun gnus-id-to-thread (id)
4033   "Return the (sub-)thread where ID appears."
4034   (gnus-gethash id gnus-newsgroup-dependencies))
4035
4036 (defun gnus-id-to-article (id)
4037   "Return the article number of ID."
4038   (let ((thread (gnus-id-to-thread id)))
4039     (when (and thread
4040                (car thread))
4041       (mail-header-number (car thread)))))
4042
4043 (defun gnus-id-to-header (id)
4044   "Return the article headers of ID."
4045   (car (gnus-id-to-thread id)))
4046
4047 (defun gnus-article-displayed-root-p (article)
4048   "Say whether ARTICLE is a root(ish) article."
4049   (let ((level (gnus-summary-thread-level article))
4050         (refs (mail-header-references  (gnus-summary-article-header article)))
4051         particle)
4052     (cond
4053      ((null level) nil)
4054      ((zerop level) t)
4055      ((null refs) t)
4056      ((null (gnus-parent-id refs)) t)
4057      ((and (= 1 level)
4058            (null (setq particle (gnus-id-to-article
4059                                  (gnus-parent-id refs))))
4060            (null (gnus-summary-thread-level particle)))))))
4061
4062 (defun gnus-root-id (id)
4063   "Return the id of the root of the thread where ID appears."
4064   (let (last-id prev)
4065     (while (and id (setq prev (car (gnus-id-to-thread id))))
4066       (setq last-id id
4067             id (gnus-parent-id (mail-header-references prev))))
4068     last-id))
4069
4070 (defun gnus-articles-in-thread (thread)
4071   "Return the list of articles in THREAD."
4072   (cons (mail-header-number (car thread))
4073         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4074
4075 (defun gnus-remove-thread (id &optional dont-remove)
4076   "Remove the thread that has ID in it."
4077   (let (headers thread last-id)
4078     ;; First go up in this thread until we find the root.
4079     (setq last-id (gnus-root-id id)
4080           headers (message-flatten-list (gnus-id-to-thread last-id)))
4081     ;; We have now found the real root of this thread.  It might have
4082     ;; been gathered into some loose thread, so we have to search
4083     ;; through the threads to find the thread we wanted.
4084     (let ((threads gnus-newsgroup-threads)
4085           sub)
4086       (while threads
4087         (setq sub (car threads))
4088         (if (stringp (car sub))
4089             ;; This is a gathered thread, so we look at the roots
4090             ;; below it to find whether this article is in this
4091             ;; gathered root.
4092             (progn
4093               (setq sub (cdr sub))
4094               (while sub
4095                 (when (member (caar sub) headers)
4096                   (setq thread (car threads)
4097                         threads nil
4098                         sub nil))
4099                 (setq sub (cdr sub))))
4100           ;; It's an ordinary thread, so we check it.
4101           (when (eq (car sub) (car headers))
4102             (setq thread sub
4103                   threads nil)))
4104         (setq threads (cdr threads)))
4105       ;; If this article is in no thread, then it's a root.
4106       (if thread
4107           (unless dont-remove
4108             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4109         (setq thread (gnus-id-to-thread last-id)))
4110       (when thread
4111         (prog1
4112             thread                      ; We return this thread.
4113           (unless dont-remove
4114             (if (stringp (car thread))
4115                 (progn
4116                   ;; If we use dummy roots, then we have to remove the
4117                   ;; dummy root as well.
4118                   (when (eq gnus-summary-make-false-root 'dummy)
4119                     ;; We go to the dummy root by going to
4120                     ;; the first sub-"thread", and then one line up.
4121                     (gnus-summary-goto-article
4122                      (mail-header-number (caadr thread)))
4123                     (forward-line -1)
4124                     (gnus-delete-line)
4125                     (gnus-data-compute-positions))
4126                   (setq thread (cdr thread))
4127                   (while thread
4128                     (gnus-remove-thread-1 (car thread))
4129                     (setq thread (cdr thread))))
4130               (gnus-remove-thread-1 thread))))))))
4131
4132 (defun gnus-remove-thread-1 (thread)
4133   "Remove the thread THREAD recursively."
4134   (let ((number (mail-header-number (pop thread)))
4135         d)
4136     (setq thread (reverse thread))
4137     (while thread
4138       (gnus-remove-thread-1 (pop thread)))
4139     (when (setq d (gnus-data-find number))
4140       (goto-char (gnus-data-pos d))
4141       (gnus-summary-show-thread)
4142       (gnus-data-remove
4143        number
4144        (- (gnus-point-at-bol)
4145           (prog1
4146               (1+ (gnus-point-at-eol))
4147             (gnus-delete-line)))))))
4148
4149 (defun gnus-sort-threads-1 (threads func)
4150   (sort (mapcar (lambda (thread)
4151                   (cons (car thread)
4152                         (and (cdr thread)
4153                              (gnus-sort-threads-1 (cdr thread) func))))
4154                 threads) func))
4155
4156 (defun gnus-sort-threads (threads)
4157   "Sort THREADS."
4158   (if (not gnus-thread-sort-functions)
4159       threads
4160     (gnus-message 8 "Sorting threads...")
4161     (prog1
4162         (gnus-sort-threads-1
4163          threads
4164          (gnus-make-sort-function gnus-thread-sort-functions))
4165       (gnus-message 8 "Sorting threads...done"))))
4166
4167 (defun gnus-sort-articles (articles)
4168   "Sort ARTICLES."
4169   (when gnus-article-sort-functions
4170     (gnus-message 7 "Sorting articles...")
4171     (prog1
4172         (setq gnus-newsgroup-headers
4173               (sort articles (gnus-make-sort-function
4174                               gnus-article-sort-functions)))
4175       (gnus-message 7 "Sorting articles...done"))))
4176
4177 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4178 (defmacro gnus-thread-header (thread)
4179   "Return header of first article in THREAD.
4180 Note that THREAD must never, ever be anything else than a variable -
4181 using some other form will lead to serious barfage."
4182   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4183   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4184   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4185         (vector thread) 2))
4186
4187 (defsubst gnus-article-sort-by-number (h1 h2)
4188   "Sort articles by article number."
4189   (< (mail-header-number h1)
4190      (mail-header-number h2)))
4191
4192 (defun gnus-thread-sort-by-number (h1 h2)
4193   "Sort threads by root article number."
4194   (gnus-article-sort-by-number
4195    (gnus-thread-header h1) (gnus-thread-header h2)))
4196
4197 (defsubst gnus-article-sort-by-lines (h1 h2)
4198   "Sort articles by article Lines header."
4199   (< (mail-header-lines h1)
4200      (mail-header-lines h2)))
4201
4202 (defun gnus-thread-sort-by-lines (h1 h2)
4203   "Sort threads by root article Lines header."
4204   (gnus-article-sort-by-lines
4205    (gnus-thread-header h1) (gnus-thread-header h2)))
4206
4207 (defsubst gnus-article-sort-by-chars (h1 h2)
4208   "Sort articles by octet length."
4209   (< (mail-header-chars h1)
4210      (mail-header-chars h2)))
4211
4212 (defun gnus-thread-sort-by-chars (h1 h2)
4213   "Sort threads by root article octet length."
4214   (gnus-article-sort-by-chars
4215    (gnus-thread-header h1) (gnus-thread-header h2)))
4216
4217 (defsubst gnus-article-sort-by-author (h1 h2)
4218   "Sort articles by root author."
4219   (string-lessp
4220    (let ((addr (car (mime-entity-read-field h1 'From))))
4221      (or (std11-full-name-string addr)
4222          (std11-address-string addr)
4223          ""))
4224    (let ((addr (car (mime-entity-read-field h2 'From))))
4225      (or (std11-full-name-string addr)
4226          (std11-address-string addr)
4227          ""))
4228    ))
4229
4230 (defun gnus-thread-sort-by-author (h1 h2)
4231   "Sort threads by root author."
4232   (gnus-article-sort-by-author
4233    (gnus-thread-header h1)  (gnus-thread-header h2)))
4234
4235 (defsubst gnus-article-sort-by-subject (h1 h2)
4236   "Sort articles by root subject."
4237   (string-lessp
4238    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4239    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4240
4241 (defun gnus-thread-sort-by-subject (h1 h2)
4242   "Sort threads by root subject."
4243   (gnus-article-sort-by-subject
4244    (gnus-thread-header h1) (gnus-thread-header h2)))
4245
4246 (defsubst gnus-article-sort-by-date (h1 h2)
4247   "Sort articles by root article date."
4248   (time-less-p
4249    (gnus-date-get-time (mail-header-date h1))
4250    (gnus-date-get-time (mail-header-date h2))))
4251
4252 (defun gnus-thread-sort-by-date (h1 h2)
4253   "Sort threads by root article date."
4254   (gnus-article-sort-by-date
4255    (gnus-thread-header h1) (gnus-thread-header h2)))
4256
4257 (defsubst gnus-article-sort-by-score (h1 h2)
4258   "Sort articles by root article score.
4259 Unscored articles will be counted as having a score of zero."
4260   (> (or (cdr (assq (mail-header-number h1)
4261                     gnus-newsgroup-scored))
4262          gnus-summary-default-score 0)
4263      (or (cdr (assq (mail-header-number h2)
4264                     gnus-newsgroup-scored))
4265          gnus-summary-default-score 0)))
4266
4267 (defun gnus-thread-sort-by-score (h1 h2)
4268   "Sort threads by root article score."
4269   (gnus-article-sort-by-score
4270    (gnus-thread-header h1) (gnus-thread-header h2)))
4271
4272 (defun gnus-thread-sort-by-total-score (h1 h2)
4273   "Sort threads by the sum of all scores in the thread.
4274 Unscored articles will be counted as having a score of zero."
4275   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4276
4277 (defun gnus-thread-total-score (thread)
4278   ;; This function find the total score of THREAD.
4279   (cond
4280    ((null thread)
4281     0)
4282    ((consp thread)
4283     (if (stringp (car thread))
4284         (apply gnus-thread-score-function 0
4285                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4286       (gnus-thread-total-score-1 thread)))
4287    (t
4288     (gnus-thread-total-score-1 (list thread)))))
4289
4290 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4291   "Sort threads such that the thread with the most recently arrived article comes first."
4292   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4293
4294 (defun gnus-thread-highest-number (thread)
4295   "Return the highest article number in THREAD."
4296   (apply 'max (mapcar (lambda (header)
4297                         (mail-header-number header))
4298                       (message-flatten-list thread))))
4299
4300 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4301   "Sort threads such that the thread with the most recently dated article comes first."
4302   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4303
4304 (defun gnus-thread-latest-date (thread)
4305   "Return the highest article date in THREAD."
4306   (let ((previous-time 0))
4307     (apply 'max (mapcar
4308                  (lambda (header)
4309                    (setq previous-time
4310                          (time-to-seconds
4311                           (mail-header-parse-date
4312                            (condition-case ()
4313                                (mail-header-date header)
4314                              (error previous-time))))))
4315                  (sort
4316                   (message-flatten-list thread)
4317                   (lambda (h1 h2)
4318                     (< (mail-header-number h1)
4319                        (mail-header-number h2))))))))
4320
4321 (defun gnus-thread-total-score-1 (root)
4322   ;; This function find the total score of the thread below ROOT.
4323   (setq root (car root))
4324   (apply gnus-thread-score-function
4325          (or (append
4326               (mapcar 'gnus-thread-total-score
4327                       (cdr (gnus-id-to-thread (mail-header-id root))))
4328               (when (> (mail-header-number root) 0)
4329                 (list (or (cdr (assq (mail-header-number root)
4330                                      gnus-newsgroup-scored))
4331                           gnus-summary-default-score 0))))
4332              (list gnus-summary-default-score)
4333              '(0))))
4334
4335 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4336 (defvar gnus-tmp-prev-subject nil)
4337 (defvar gnus-tmp-false-parent nil)
4338 (defvar gnus-tmp-root-expunged nil)
4339 (defvar gnus-tmp-dummy-line nil)
4340
4341 (eval-when-compile (defvar gnus-tmp-header))
4342 (defun gnus-extra-header (type &optional header)
4343   "Return the extra header of TYPE."
4344   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4345       ""))
4346
4347 (defvar gnus-tmp-thread-tree-header-string "")
4348
4349 (defvar gnus-sum-thread-tree-root "> "
4350   "With %B spec, used for the root of a thread.
4351 If nil, use subject instead.")
4352 (defvar gnus-sum-thread-tree-single-indent ""
4353   "With %B spec, used for a thread with just one message.
4354 If nil, use subject instead.")
4355 (defvar gnus-sum-thread-tree-vertical "| "
4356   "With %B spec, used for drawing a vertical line.")
4357 (defvar gnus-sum-thread-tree-indent "  "
4358   "With %B spec, used for indenting.")
4359 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4360   "With %B spec, used for a leaf with brothers.")
4361 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4362   "With %B spec, used for a leaf without brothers.")
4363
4364 (defun gnus-summary-prepare-threads (threads)
4365   "Prepare summary buffer from THREADS and indentation LEVEL.
4366 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4367 or a straight list of headers."
4368   (gnus-message 7 "Generating summary...")
4369
4370   (setq gnus-newsgroup-threads threads)
4371   (beginning-of-line)
4372
4373   (let ((gnus-tmp-level 0)
4374         (default-score (or gnus-summary-default-score 0))
4375         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4376         thread number subject stack state gnus-tmp-gathered beg-match
4377         new-roots gnus-tmp-new-adopts thread-end
4378         gnus-tmp-header gnus-tmp-unread
4379         gnus-tmp-replied gnus-tmp-subject-or-nil
4380         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4381         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4382         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4383         tree-stack)
4384
4385     (setq gnus-tmp-prev-subject nil)
4386
4387     (if (vectorp (car threads))
4388         ;; If this is a straight (sic) list of headers, then a
4389         ;; threaded summary display isn't required, so we just create
4390         ;; an unthreaded one.
4391         (gnus-summary-prepare-unthreaded threads)
4392
4393       ;; Do the threaded display.
4394
4395       (while (or threads stack gnus-tmp-new-adopts new-roots)
4396
4397         (if (and (= gnus-tmp-level 0)
4398                  (or (not stack)
4399                      (= (caar stack) 0))
4400                  (not gnus-tmp-false-parent)
4401                  (or gnus-tmp-new-adopts new-roots))
4402             (if gnus-tmp-new-adopts
4403                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4404                       thread (list (car gnus-tmp-new-adopts))
4405                       gnus-tmp-header (caar thread)
4406                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4407               (when new-roots
4408                 (setq thread (list (car new-roots))
4409                       gnus-tmp-header (caar thread)
4410                       new-roots (cdr new-roots))))
4411
4412           (if threads
4413               ;; If there are some threads, we do them before the
4414               ;; threads on the stack.
4415               (setq thread threads
4416                     gnus-tmp-header (caar thread))
4417             ;; There were no current threads, so we pop something off
4418             ;; the stack.
4419             (setq state (car stack)
4420                   gnus-tmp-level (car state)
4421                   tree-stack (cadr state)
4422                   thread (caddr state)
4423                   stack (cdr stack)
4424                   gnus-tmp-header (caar thread))))
4425
4426         (setq gnus-tmp-false-parent nil)
4427         (setq gnus-tmp-root-expunged nil)
4428         (setq thread-end nil)
4429
4430         (if (stringp gnus-tmp-header)
4431             ;; The header is a dummy root.
4432             (cond
4433              ((eq gnus-summary-make-false-root 'adopt)
4434               ;; We let the first article adopt the rest.
4435               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4436                                                (cddar thread)))
4437               (setq gnus-tmp-gathered
4438                     (nconc (mapcar
4439                             (lambda (h) (mail-header-number (car h)))
4440                             (cddar thread))
4441                            gnus-tmp-gathered))
4442               (setq thread (cons (list (caar thread)
4443                                        (cadar thread))
4444                                  (cdr thread)))
4445               (setq gnus-tmp-level -1
4446                     gnus-tmp-false-parent t))
4447              ((eq gnus-summary-make-false-root 'empty)
4448               ;; We print adopted articles with empty subject fields.
4449               (setq gnus-tmp-gathered
4450                     (nconc (mapcar
4451                             (lambda (h) (mail-header-number (car h)))
4452                             (cddar thread))
4453                            gnus-tmp-gathered))
4454               (setq gnus-tmp-level -1))
4455              ((eq gnus-summary-make-false-root 'dummy)
4456               ;; We remember that we probably want to output a dummy
4457               ;; root.
4458               (setq gnus-tmp-dummy-line gnus-tmp-header)
4459               (setq gnus-tmp-prev-subject gnus-tmp-header))
4460              (t
4461               ;; We do not make a root for the gathered
4462               ;; sub-threads at all.
4463               (setq gnus-tmp-level -1)))
4464
4465           (setq number (mail-header-number gnus-tmp-header)
4466                 subject (mail-header-subject gnus-tmp-header))
4467
4468           (cond
4469            ;; If the thread has changed subject, we might want to make
4470            ;; this subthread into a root.
4471            ((and (null gnus-thread-ignore-subject)
4472                  (not (zerop gnus-tmp-level))
4473                  gnus-tmp-prev-subject
4474                  (not (inline
4475                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4476             (setq new-roots (nconc new-roots (list (car thread)))
4477                   thread-end t
4478                   gnus-tmp-header nil))
4479            ;; If the article lies outside the current limit,
4480            ;; then we do not display it.
4481            ((not (memq number gnus-newsgroup-limit))
4482             (setq gnus-tmp-gathered
4483                   (nconc (mapcar
4484                           (lambda (h) (mail-header-number (car h)))
4485                           (cdar thread))
4486                          gnus-tmp-gathered))
4487             (setq gnus-tmp-new-adopts (if (cdar thread)
4488                                           (append gnus-tmp-new-adopts
4489                                                   (cdar thread))
4490                                         gnus-tmp-new-adopts)
4491                   thread-end t
4492                   gnus-tmp-header nil)
4493             (when (zerop gnus-tmp-level)
4494               (setq gnus-tmp-root-expunged t)))
4495            ;; Perhaps this article is to be marked as read?
4496            ((and gnus-summary-mark-below
4497                  (< (or (cdr (assq number gnus-newsgroup-scored))
4498                         default-score)
4499                     gnus-summary-mark-below)
4500                  ;; Don't touch sparse articles.
4501                  (not (gnus-summary-article-sparse-p number))
4502                  (not (gnus-summary-article-ancient-p number)))
4503             (setq gnus-newsgroup-unreads
4504                   (delq number gnus-newsgroup-unreads))
4505             (if gnus-newsgroup-auto-expire
4506                 (setq gnus-newsgroup-expirable
4507                       (gnus-add-to-sorted-list
4508                        gnus-newsgroup-expirable number))
4509               (push (cons number gnus-low-score-mark)
4510                     gnus-newsgroup-reads))))
4511
4512           (when gnus-tmp-header
4513             ;; We may have an old dummy line to output before this
4514             ;; article.
4515             (when (and gnus-tmp-dummy-line
4516                        (gnus-subject-equal
4517                         gnus-tmp-dummy-line
4518                         (mail-header-subject gnus-tmp-header)))
4519               (gnus-summary-insert-dummy-line
4520                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4521               (setq gnus-tmp-dummy-line nil))
4522
4523             ;; Compute the mark.
4524             (setq gnus-tmp-unread (gnus-article-mark number))
4525
4526             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4527                                   gnus-tmp-header gnus-tmp-level)
4528                   gnus-newsgroup-data)
4529
4530             ;; Actually insert the line.
4531             (setq
4532              gnus-tmp-subject-or-nil
4533              (cond
4534               ((and gnus-thread-ignore-subject
4535                     gnus-tmp-prev-subject
4536                     (not (inline (gnus-subject-equal
4537                                   gnus-tmp-prev-subject subject))))
4538                subject)
4539               ((zerop gnus-tmp-level)
4540                (if (and (eq gnus-summary-make-false-root 'empty)
4541                         (memq number gnus-tmp-gathered)
4542                         gnus-tmp-prev-subject
4543                         (inline (gnus-subject-equal
4544                                  gnus-tmp-prev-subject subject)))
4545                    gnus-summary-same-subject
4546                  subject))
4547               (t gnus-summary-same-subject)))
4548             (if (and (eq gnus-summary-make-false-root 'adopt)
4549                      (= gnus-tmp-level 1)
4550                      (memq number gnus-tmp-gathered))
4551                 (setq gnus-tmp-opening-bracket ?\<
4552                       gnus-tmp-closing-bracket ?\>)
4553               (setq gnus-tmp-opening-bracket ?\[
4554                     gnus-tmp-closing-bracket ?\]))
4555             (setq
4556              gnus-tmp-indentation
4557              (aref gnus-thread-indent-array gnus-tmp-level)
4558              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4559              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4560                                 gnus-summary-default-score 0)
4561              gnus-tmp-score-char
4562              (if (or (null gnus-summary-default-score)
4563                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4564                          gnus-summary-zcore-fuzz))
4565                  ?\ ;;;Whitespace
4566                (if (< gnus-tmp-score gnus-summary-default-score)
4567                    gnus-score-below-mark gnus-score-over-mark))
4568              gnus-tmp-replied
4569              (cond ((memq number gnus-newsgroup-processable)
4570                     gnus-process-mark)
4571                    ((memq number gnus-newsgroup-cached)
4572                     gnus-cached-mark)
4573                    ((memq number gnus-newsgroup-replied)
4574                     gnus-replied-mark)
4575                    ((memq number gnus-newsgroup-forwarded)
4576                     gnus-forwarded-mark)
4577                    ((memq number gnus-newsgroup-saved)
4578                     gnus-saved-mark)
4579                    ((memq number gnus-newsgroup-recent)
4580                     gnus-recent-mark)
4581                    ((memq number gnus-newsgroup-unseen)
4582                     gnus-unseen-mark)
4583                    (t gnus-no-mark))
4584              gnus-tmp-from (mail-header-from gnus-tmp-header)
4585              gnus-tmp-name
4586              (cond
4587               ((string-match "<[^>]+> *$" gnus-tmp-from)
4588                (setq beg-match (match-beginning 0))
4589                (or (and (string-match "^\".+\"" gnus-tmp-from)
4590                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4591                    (substring gnus-tmp-from 0 beg-match)))
4592               ((string-match "(.+)" gnus-tmp-from)
4593                (substring gnus-tmp-from
4594                           (1+ (match-beginning 0)) (1- (match-end 0))))
4595               (t gnus-tmp-from))
4596              gnus-tmp-thread-tree-header-string
4597              (cond
4598               ((not gnus-show-threads) "")
4599               ((zerop gnus-tmp-level)
4600                (if (cdar thread)
4601                    (or gnus-sum-thread-tree-root subject)
4602                  (or gnus-sum-thread-tree-single-indent subject)))
4603               (t
4604                (concat (apply 'concat
4605                               (mapcar (lambda (item)
4606                                         (if (= item 1)
4607                                             gnus-sum-thread-tree-vertical
4608                                           gnus-sum-thread-tree-indent))
4609                                       (cdr (reverse tree-stack))))
4610                        (if (nth 1 thread)
4611                            gnus-sum-thread-tree-leaf-with-other
4612                          gnus-sum-thread-tree-single-leaf)))))
4613             (when (string= gnus-tmp-name "")
4614               (setq gnus-tmp-name gnus-tmp-from))
4615             (unless (numberp gnus-tmp-lines)
4616               (setq gnus-tmp-lines -1))
4617             (if (= gnus-tmp-lines -1)
4618                 (setq gnus-tmp-lines "?")
4619               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4620             (gnus-put-text-property
4621              (point)
4622              (progn (eval gnus-summary-line-format-spec) (point))
4623              'gnus-number number)
4624             (when gnus-visual-p
4625               (forward-line -1)
4626               (gnus-run-hooks 'gnus-summary-update-hook)
4627               (forward-line 1))
4628
4629             (setq gnus-tmp-prev-subject subject)))
4630
4631         (when (nth 1 thread)
4632           (push (list (max 0 gnus-tmp-level)
4633                       (copy-list tree-stack)
4634                       (nthcdr 1 thread))
4635                 stack))
4636         (push (if (nth 1 thread) 1 0) tree-stack)
4637         (incf gnus-tmp-level)
4638         (setq threads (if thread-end nil (cdar thread)))
4639         (unless threads
4640           (setq gnus-tmp-level 0)))))
4641   (gnus-message 7 "Generating summary...done"))
4642
4643 (defun gnus-summary-prepare-unthreaded (headers)
4644   "Generate an unthreaded summary buffer based on HEADERS."
4645   (let (header number mark)
4646
4647     (beginning-of-line)
4648
4649     (while headers
4650       ;; We may have to root out some bad articles...
4651       (when (memq (setq number (mail-header-number
4652                                 (setq header (pop headers))))
4653                   gnus-newsgroup-limit)
4654         ;; Mark article as read when it has a low score.
4655         (when (and gnus-summary-mark-below
4656                    (< (or (cdr (assq number gnus-newsgroup-scored))
4657                           gnus-summary-default-score 0)
4658                       gnus-summary-mark-below)
4659                    (not (gnus-summary-article-ancient-p number)))
4660           (setq gnus-newsgroup-unreads
4661                 (delq number gnus-newsgroup-unreads))
4662           (if gnus-newsgroup-auto-expire
4663               (push number gnus-newsgroup-expirable)
4664             (push (cons number gnus-low-score-mark)
4665                   gnus-newsgroup-reads)))
4666
4667         (setq mark (gnus-article-mark number))
4668         (push (gnus-data-make number mark (1+ (point)) header 0)
4669               gnus-newsgroup-data)
4670         (gnus-summary-insert-line
4671          header 0 number
4672          mark (memq number gnus-newsgroup-replied)
4673          (memq number gnus-newsgroup-expirable)
4674          (mail-header-subject header) nil
4675          (cdr (assq number gnus-newsgroup-scored))
4676          (memq number gnus-newsgroup-processable))))))
4677
4678 (defun gnus-summary-remove-list-identifiers ()
4679   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4680   (let ((regexp (if (consp gnus-list-identifiers)
4681                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4682                   gnus-list-identifiers))
4683         changed subject)
4684     (when regexp
4685       (dolist (header gnus-newsgroup-headers)
4686         (setq subject (mail-header-subject header)
4687               changed nil)
4688         (while (string-match
4689                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4690                 subject)
4691           (setq subject
4692                 (concat (substring subject 0 (match-beginning 2))
4693                         (substring subject (match-end 0)))
4694                 changed t))
4695         (when (and changed
4696                    (string-match
4697                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4698           (setq subject
4699                 (concat (substring subject 0 (match-beginning 1))
4700                         (substring subject (match-end 1)))))
4701         (when changed
4702           (mail-header-set-subject header subject))))))
4703
4704 (defun gnus-fetch-headers (articles)
4705   "Fetch headers of ARTICLES."
4706   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4707     (gnus-message 5 "Fetching headers for %s..." name)
4708     (prog1
4709         (if (eq 'nov
4710                 (setq gnus-headers-retrieved-by
4711                       (gnus-retrieve-headers
4712                        articles gnus-newsgroup-name
4713                        ;; We might want to fetch old headers, but
4714                        ;; not if there is only 1 article.
4715                        (and (or (and
4716                                  (not (eq gnus-fetch-old-headers 'some))
4717                                  (not (numberp gnus-fetch-old-headers)))
4718                                 (> (length articles) 1))
4719                             gnus-fetch-old-headers))))
4720             (gnus-get-newsgroup-headers-xover
4721              articles nil nil gnus-newsgroup-name t)
4722           (gnus-get-newsgroup-headers))
4723       (gnus-message 5 "Fetching headers for %s...done" name))))
4724
4725 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4726   "Select newsgroup GROUP.
4727 If READ-ALL is non-nil, all articles in the group are selected.
4728 If SELECT-ARTICLES, only select those articles from GROUP."
4729   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4730          ;;!!! Dirty hack; should be removed.
4731          (gnus-summary-ignore-duplicates
4732           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4733               t
4734             gnus-summary-ignore-duplicates))
4735          (info (nth 2 entry))
4736          articles fetched-articles cached)
4737
4738     (unless (gnus-check-server
4739              (set (make-local-variable 'gnus-current-select-method)
4740                   (gnus-find-method-for-group group)))
4741       (error "Couldn't open server"))
4742
4743     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4744         (gnus-activate-group group)     ; Or we can activate it...
4745         (progn                          ; Or we bug out.
4746           (when (equal major-mode 'gnus-summary-mode)
4747             (kill-buffer (current-buffer)))
4748           (error "Couldn't activate group %s: %s"
4749                  group (gnus-status-message group))))
4750
4751     (unless (gnus-request-group group t)
4752       (when (equal major-mode 'gnus-summary-mode)
4753         (kill-buffer (current-buffer)))
4754       (error "Couldn't request group %s: %s"
4755              group (gnus-status-message group)))
4756
4757     (setq gnus-newsgroup-name group
4758           gnus-newsgroup-unselected nil
4759           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4760
4761     (let ((display (gnus-group-find-parameter group 'display)))
4762       (setq gnus-newsgroup-display
4763             (cond
4764              ((not (zerop (or (car-safe read-all) 0)))
4765               ;; The user entered the group with C-u SPC/RET, let's show
4766               ;; all articles.
4767               'gnus-not-ignore)
4768              ((eq display 'all)
4769               'gnus-not-ignore)
4770              ((arrayp display)
4771               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4772              ((numberp display)
4773               ;; The following is probably the "correct" solution, but
4774               ;; it makes Gnus fetch all headers and then limit the
4775               ;; articles (which is slow), so instead we hack the
4776               ;; select-articles parameter instead. -- Simon Josefsson
4777               ;; <jas@kth.se>
4778               ;;
4779               ;; (gnus-byte-compile
4780               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4781               ;;                         display)))))
4782               (setq select-articles
4783                     (gnus-uncompress-range
4784                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4785                              (if (> tmp 0)
4786                                  tmp
4787                                1))
4788                            (cdr (gnus-active group)))))
4789               nil)
4790              (t
4791               nil))))
4792
4793     (gnus-summary-setup-default-charset)
4794
4795     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4796     (when (gnus-virtual-group-p group)
4797       (setq cached gnus-newsgroup-cached))
4798
4799     (setq gnus-newsgroup-unreads
4800           (gnus-sorted-ndifference
4801            (gnus-sorted-ndifference gnus-newsgroup-unreads
4802                                     gnus-newsgroup-marked)
4803            gnus-newsgroup-dormant))
4804
4805     (setq gnus-newsgroup-processable nil)
4806
4807     (gnus-update-read-articles group gnus-newsgroup-unreads)
4808
4809     ;; Adjust and set lists of article marks.
4810     (when info
4811       (gnus-adjust-marked-articles info))
4812
4813     (if (setq articles select-articles)
4814         (setq gnus-newsgroup-unselected
4815               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4816       (setq articles (gnus-articles-to-read group read-all)))
4817
4818     (cond
4819      ((null articles)
4820       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4821       'quit)
4822      ((eq articles 0) nil)
4823      (t
4824       ;; Init the dependencies hash table.
4825       (setq gnus-newsgroup-dependencies
4826             (gnus-make-hashtable (length articles)))
4827       (gnus-set-global-variables)
4828       ;; Retrieve the headers and read them in.
4829       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4830
4831       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4832       (when cached
4833         (setq gnus-newsgroup-cached cached))
4834
4835       ;; Suppress duplicates?
4836       (when gnus-suppress-duplicates
4837         (gnus-dup-suppress-articles))
4838
4839       ;; Set the initial limit.
4840       (setq gnus-newsgroup-limit (copy-sequence articles))
4841       ;; Remove canceled articles from the list of unread articles.
4842       (setq fetched-articles
4843             (mapcar (lambda (headers) (mail-header-number headers))
4844                     gnus-newsgroup-headers))
4845       (setq gnus-newsgroup-articles fetched-articles)
4846       (setq gnus-newsgroup-unreads
4847             (gnus-sorted-nintersection
4848              gnus-newsgroup-unreads fetched-articles))
4849       (gnus-compute-unseen-list)
4850
4851       ;; Removed marked articles that do not exist.
4852       (gnus-update-missing-marks
4853        (gnus-sorted-difference articles fetched-articles))
4854       ;; We might want to build some more threads first.
4855       (when (and gnus-fetch-old-headers
4856                  (eq gnus-headers-retrieved-by 'nov))
4857         (if (eq gnus-fetch-old-headers 'invisible)
4858             (gnus-build-all-threads)
4859           (gnus-build-old-threads)))
4860       ;; Let the Gnus agent mark articles as read.
4861       (when gnus-agent
4862         (gnus-agent-get-undownloaded-list))
4863       ;; Remove list identifiers from subject
4864       (when gnus-list-identifiers
4865         (gnus-summary-remove-list-identifiers))
4866       ;; Check whether auto-expire is to be done in this group.
4867       (setq gnus-newsgroup-auto-expire
4868             (gnus-group-auto-expirable-p group))
4869       ;; Set up the article buffer now, if necessary.
4870       (unless gnus-single-article-buffer
4871         (gnus-article-setup-buffer))
4872       ;; First and last article in this newsgroup.
4873       (when gnus-newsgroup-headers
4874         (setq gnus-newsgroup-begin
4875               (mail-header-number (car gnus-newsgroup-headers))
4876               gnus-newsgroup-end
4877               (mail-header-number
4878                (gnus-last-element gnus-newsgroup-headers))))
4879       ;; GROUP is successfully selected.
4880       (or gnus-newsgroup-headers t)))))
4881
4882 (defun gnus-compute-unseen-list ()
4883   ;; The `seen' marks are treated specially.
4884   (if (not gnus-newsgroup-seen)
4885       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4886     (setq gnus-newsgroup-unseen
4887           (gnus-inverse-list-range-intersection
4888            gnus-newsgroup-articles gnus-newsgroup-seen))))
4889
4890 (defun gnus-summary-display-make-predicate (display)
4891   (require 'gnus-agent)
4892   (when (= (length display) 1)
4893     (setq display (car display)))
4894   (unless gnus-summary-display-cache
4895     (dolist (elem (append '((unread . unread)
4896                             (read . read)
4897                             (unseen . unseen))
4898                           gnus-article-mark-lists))
4899       (push (cons (cdr elem)
4900                   (gnus-byte-compile
4901                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4902             gnus-summary-display-cache)))
4903   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4904         (gnus-category-predicate-cache gnus-summary-display-cache))
4905     (gnus-get-predicate display)))
4906
4907 ;; Uses the dynamically bound `number' variable.
4908 (defvar number)
4909 (defun gnus-article-marked-p (type &optional article)
4910   (let ((article (or article number)))
4911     (cond
4912      ((eq type 'tick)
4913       (memq article gnus-newsgroup-marked))
4914      ((eq type 'unsend)
4915       (memq article gnus-newsgroup-unsendable))
4916      ((eq type 'undownload)
4917       (memq article gnus-newsgroup-undownloaded))
4918      ((eq type 'download)
4919       (memq article gnus-newsgroup-downloadable))
4920      ((eq type 'unread)
4921       (memq article gnus-newsgroup-unreads))
4922      ((eq type 'read)
4923       (memq article gnus-newsgroup-reads))
4924      ((eq type 'dormant)
4925       (memq article gnus-newsgroup-dormant) )
4926      ((eq type 'expire)
4927       (memq article gnus-newsgroup-expirable))
4928      ((eq type 'reply)
4929       (memq article gnus-newsgroup-replied))
4930      ((eq type 'killed)
4931       (memq article gnus-newsgroup-killed))
4932      ((eq type 'bookmark)
4933       (assq article gnus-newsgroup-bookmarks))
4934      ((eq type 'score)
4935       (assq article gnus-newsgroup-scored))
4936      ((eq type 'save)
4937       (memq article gnus-newsgroup-saved))
4938      ((eq type 'cache)
4939       (memq article gnus-newsgroup-cached))
4940      ((eq type 'forward)
4941       (memq article gnus-newsgroup-forwarded))
4942      ((eq type 'seen)
4943       (not (memq article gnus-newsgroup-unseen)))
4944      ((eq type 'recent)
4945       (memq article gnus-newsgroup-recent))
4946      (t t))))
4947
4948 (defun gnus-articles-to-read (group &optional read-all)
4949   "Find out what articles the user wants to read."
4950   (let* ((articles
4951           ;; Select all articles if `read-all' is non-nil, or if there
4952           ;; are no unread articles.
4953           (if (or read-all
4954                   (and (zerop (length gnus-newsgroup-marked))
4955                        (zerop (length gnus-newsgroup-unreads)))
4956                   ;; Fetch all if the predicate is non-nil.
4957                   gnus-newsgroup-display)
4958               ;; We want to select the headers for all the articles in
4959               ;; the group, so we select either all the active
4960               ;; articles in the group, or (if that's nil), the
4961               ;; articles in the cache.
4962               (or
4963                (gnus-uncompress-range (gnus-active group))
4964                (gnus-cache-articles-in-group group))
4965             ;; Select only the "normal" subset of articles.
4966             (gnus-sorted-nunion
4967              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4968              gnus-newsgroup-unreads)))
4969          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4970          (scored (length scored-list))
4971          (number (length articles))
4972          (marked (+ (length gnus-newsgroup-marked)
4973                     (length gnus-newsgroup-dormant)))
4974          (select
4975           (cond
4976            ((numberp read-all)
4977             read-all)
4978            ((numberp gnus-newsgroup-display)
4979             gnus-newsgroup-display)
4980            (t
4981             (condition-case ()
4982                 (cond
4983                  ((and (or (<= scored marked) (= scored number))
4984                        (numberp gnus-large-newsgroup)
4985                        (> number gnus-large-newsgroup))
4986                   (let* ((cursor-in-echo-area nil)
4987                          (initial (gnus-parameter-large-newsgroup-initial
4988                                    gnus-newsgroup-name))
4989                          (input
4990                           (read-string
4991                            (format
4992                             "How many articles from %s (%s %d): "
4993                             (gnus-limit-string
4994                              (gnus-group-decoded-name gnus-newsgroup-name)
4995                              35)
4996                             (if initial "max" "default")
4997                             number)
4998                            (if initial
4999                                (cons (number-to-string initial)
5000                                      0)))))
5001                     (if (string-match "^[ \t]*$" input) number input)))
5002                  ((and (> scored marked) (< scored number)
5003                        (> (- scored number) 20))
5004                   (let ((input
5005                          (read-string
5006                           (format "%s %s (%d scored, %d total): "
5007                                   "How many articles from"
5008                                   (gnus-group-decoded-name group)
5009                                   scored number))))
5010                     (if (string-match "^[ \t]*$" input)
5011                         number input)))
5012                  (t number))
5013               (quit
5014                (message "Quit getting the articles to read")
5015                nil))))))
5016     (setq select (if (stringp select) (string-to-number select) select))
5017     (if (or (null select) (zerop select))
5018         select
5019       (if (and (not (zerop scored)) (<= (abs select) scored))
5020           (progn
5021             (setq articles (sort scored-list '<))
5022             (setq number (length articles)))
5023         (setq articles (copy-sequence articles)))
5024
5025       (when (< (abs select) number)
5026         (if (< select 0)
5027             ;; Select the N oldest articles.
5028             (setcdr (nthcdr (1- (abs select)) articles) nil)
5029           ;; Select the N most recent articles.
5030           (setq articles (nthcdr (- number select) articles))))
5031       (setq gnus-newsgroup-unselected
5032             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5033       (when gnus-alter-articles-to-read-function
5034         (setq gnus-newsgroup-unreads
5035               (sort
5036                (funcall gnus-alter-articles-to-read-function
5037                         gnus-newsgroup-name gnus-newsgroup-unreads)
5038                '<)))
5039       articles)))
5040
5041 (defun gnus-killed-articles (killed articles)
5042   (let (out)
5043     (while articles
5044       (when (inline (gnus-member-of-range (car articles) killed))
5045         (push (car articles) out))
5046       (setq articles (cdr articles)))
5047     out))
5048
5049 (defun gnus-uncompress-marks (marks)
5050   "Uncompress the mark ranges in MARKS."
5051   (let ((uncompressed '(score bookmark))
5052         out)
5053     (while marks
5054       (if (memq (caar marks) uncompressed)
5055           (push (car marks) out)
5056         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5057       (setq marks (cdr marks)))
5058     out))
5059
5060 (defun gnus-article-mark-to-type (mark)
5061   "Return the type of MARK."
5062   (or (cadr (assq mark gnus-article-special-mark-lists))
5063       'list))
5064
5065 (defun gnus-article-unpropagatable-p (mark)
5066   "Return whether MARK should be propagated to backend."
5067   (memq mark gnus-article-unpropagated-mark-lists))
5068
5069 (defun gnus-adjust-marked-articles (info)
5070   "Set all article lists and remove all marks that are no longer valid."
5071   (let* ((marked-lists (gnus-info-marks info))
5072          (active (gnus-active (gnus-info-group info)))
5073          (min (car active))
5074          (max (cdr active))
5075          (types gnus-article-mark-lists)
5076          marks var articles article mark mark-type)
5077
5078     (dolist (marks marked-lists)
5079       (setq mark (car marks)
5080             mark-type (gnus-article-mark-to-type mark)
5081             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5082
5083       ;; We set the variable according to the type of the marks list,
5084       ;; and then adjust the marks to a subset of the active articles.
5085       (cond
5086        ;; Adjust "simple" lists.
5087        ((eq mark-type 'list)
5088         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5089         (when (memq mark '(tick dormant expire reply save))
5090           (while articles
5091             (when (or (< (setq article (pop articles)) min) (> article max))
5092               (set var (delq article (symbol-value var)))))))
5093        ;; Adjust assocs.
5094        ((eq mark-type 'tuple)
5095         (set var (setq articles (cdr marks)))
5096         (when (not (listp (cdr (symbol-value var))))
5097           (set var (list (symbol-value var))))
5098         (when (not (listp (cdr articles)))
5099           (setq articles (list articles)))
5100         (while articles
5101           (when (or (not (consp (setq article (pop articles))))
5102                     (< (car article) min)
5103                     (> (car article) max))
5104             (set var (delq article (symbol-value var))))))
5105        ;; Adjust ranges (sloppily).
5106        ((eq mark-type 'range)
5107         (cond
5108          ((eq mark 'seen)
5109           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5110           ;; It should be (seen (NUM1 . NUM2)).
5111           (when (numberp (cddr marks))
5112             (setcdr marks (list (cdr marks))))
5113           (setq articles (cdr marks))
5114           (while (and articles
5115                       (or (and (consp (car articles))
5116                                (> min (cdar articles)))
5117                           (and (numberp (car articles))
5118                                (> min (car articles)))))
5119             (pop articles))
5120           (set var articles))))))))
5121
5122 (defun gnus-update-missing-marks (missing)
5123   "Go through the list of MISSING articles and remove them from the mark lists."
5124   (when missing
5125     (let (var m)
5126       ;; Go through all types.
5127       (dolist (elem gnus-article-mark-lists)
5128         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5129           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5130           (when (symbol-value var)
5131             ;; This list has articles.  So we delete all missing
5132             ;; articles from it.
5133             (setq m missing)
5134             (while m
5135               (set var (delq (pop m) (symbol-value var))))))))))
5136
5137 (defun gnus-update-marks ()
5138   "Enter the various lists of marked articles into the newsgroup info list."
5139   (let ((types gnus-article-mark-lists)
5140         (info (gnus-get-info gnus-newsgroup-name))
5141         type list newmarked symbol delta-marks)
5142     (when info
5143       ;; Add all marks lists to the list of marks lists.
5144       (while (setq type (pop types))
5145         (setq list (symbol-value
5146                     (setq symbol
5147                           (intern (format "gnus-newsgroup-%s" (car type))))))
5148
5149         (when list
5150           ;; Get rid of the entries of the articles that have the
5151           ;; default score.
5152           (when (and (eq (cdr type) 'score)
5153                      gnus-save-score
5154                      list)
5155             (let* ((arts list)
5156                    (prev (cons nil list))
5157                    (all prev))
5158               (while arts
5159                 (if (or (not (consp (car arts)))
5160                         (= (cdar arts) gnus-summary-default-score))
5161                     (setcdr prev (cdr arts))
5162                   (setq prev arts))
5163                 (setq arts (cdr arts)))
5164               (setq list (cdr all)))))
5165
5166         (when (eq (cdr type) 'seen)
5167           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5168
5169         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5170           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5171
5172         (when (and (gnus-check-backend-function
5173                     'request-set-mark gnus-newsgroup-name)
5174                    (not (gnus-article-unpropagatable-p (cdr type))))
5175           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5176                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5177                  (add (gnus-remove-from-range
5178                        (gnus-copy-sequence list) old)))
5179             (when add
5180               (push (list add 'add (list (cdr type))) delta-marks))
5181             (when del
5182               (push (list del 'del (list (cdr type))) delta-marks))))
5183
5184         (when list
5185           (push (cons (cdr type) list) newmarked)))
5186
5187       (when delta-marks
5188         (unless (gnus-check-group gnus-newsgroup-name)
5189           (error "Can't open server for %s" gnus-newsgroup-name))
5190         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5191
5192       ;; Enter these new marks into the info of the group.
5193       (if (nthcdr 3 info)
5194           (setcar (nthcdr 3 info) newmarked)
5195         ;; Add the marks lists to the end of the info.
5196         (when newmarked
5197           (setcdr (nthcdr 2 info) (list newmarked))))
5198
5199       ;; Cut off the end of the info if there's nothing else there.
5200       (let ((i 5))
5201         (while (and (> i 2)
5202                     (not (nth i info)))
5203           (when (nthcdr (decf i) info)
5204             (setcdr (nthcdr i info) nil)))))))
5205
5206 (defun gnus-set-mode-line (where)
5207   "Set the mode line of the article or summary buffers.
5208 If WHERE is `summary', the summary mode line format will be used."
5209   ;; Is this mode line one we keep updated?
5210   (when (and (memq where gnus-updated-mode-lines)
5211              (symbol-value
5212               (intern (format "gnus-%s-mode-line-format-spec" where))))
5213     (let (mode-string)
5214       (save-excursion
5215         ;; We evaluate this in the summary buffer since these
5216         ;; variables are buffer-local to that buffer.
5217         (set-buffer gnus-summary-buffer)
5218         ;; We bind all these variables that are used in the `eval' form
5219         ;; below.
5220         (let* ((mformat (symbol-value
5221                          (intern
5222                           (format "gnus-%s-mode-line-format-spec" where))))
5223                (gnus-tmp-group-name (gnus-group-decoded-name
5224                                      gnus-newsgroup-name))
5225                (gnus-tmp-article-number (or gnus-current-article 0))
5226                (gnus-tmp-unread gnus-newsgroup-unreads)
5227                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5228                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5229                (gnus-tmp-unread-and-unselected
5230                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5231                             (zerop gnus-tmp-unselected))
5232                        "")
5233                       ((zerop gnus-tmp-unselected)
5234                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5235                       (t (format "{%d(+%d) more}"
5236                                  gnus-tmp-unread-and-unticked
5237                                  gnus-tmp-unselected))))
5238                (gnus-tmp-subject
5239                 (if (and gnus-current-headers
5240                          (vectorp gnus-current-headers))
5241                     (gnus-mode-string-quote
5242                      (mail-header-subject gnus-current-headers))
5243                   ""))
5244                bufname-length max-len
5245                gnus-tmp-header);; passed as argument to any user-format-funcs
5246           (setq mode-string (eval mformat))
5247           (setq bufname-length (if (string-match "%b" mode-string)
5248                                    (- (length
5249                                        (buffer-name
5250                                         (if (eq where 'summary)
5251                                             nil
5252                                           (get-buffer gnus-article-buffer))))
5253                                       2)
5254                                  0))
5255           (setq max-len (max 4 (if gnus-mode-non-string-length
5256                                    (- (window-width)
5257                                       gnus-mode-non-string-length
5258                                       bufname-length)
5259                                  (length mode-string))))
5260           ;; We might have to chop a bit of the string off...
5261           (when (> (length mode-string) max-len)
5262             (setq mode-string
5263                   (concat (gnus-truncate-string mode-string (- max-len 3))
5264                           "...")))
5265           ;; Pad the mode string a bit.
5266           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5267       ;; Update the mode line.
5268       (setq mode-line-buffer-identification
5269             (gnus-mode-line-buffer-identification (list mode-string)))
5270       (set-buffer-modified-p t))))
5271
5272 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5273   "Go through the HEADERS list and add all Xrefs to a hash table.
5274 The resulting hash table is returned, or nil if no Xrefs were found."
5275   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5276          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5277          (xref-hashtb (gnus-make-hashtable))
5278          start group entry number xrefs header)
5279     (while headers
5280       (setq header (pop headers))
5281       (when (and (setq xrefs (mail-header-xref header))
5282                  (not (memq (setq number (mail-header-number header))
5283                             unreads)))
5284         (setq start 0)
5285         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5286           (setq start (match-end 0))
5287           (setq group (if prefix
5288                           (concat prefix (substring xrefs (match-beginning 1)
5289                                                     (match-end 1)))
5290                         (substring xrefs (match-beginning 1) (match-end 1))))
5291           (setq number
5292                 (string-to-int (substring xrefs (match-beginning 2)
5293                                           (match-end 2))))
5294           (if (setq entry (gnus-gethash group xref-hashtb))
5295               (setcdr entry (cons number (cdr entry)))
5296             (gnus-sethash group (cons number nil) xref-hashtb)))))
5297     (and start xref-hashtb)))
5298
5299 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5300   "Look through all the headers and mark the Xrefs as read."
5301   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5302         name entry info xref-hashtb idlist method nth4)
5303     (save-excursion
5304       (set-buffer gnus-group-buffer)
5305       (when (setq xref-hashtb
5306                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5307         (mapatoms
5308          (lambda (group)
5309            (unless (string= from-newsgroup (setq name (symbol-name group)))
5310              (setq idlist (symbol-value group))
5311              ;; Dead groups are not updated.
5312              (and (prog1
5313                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5314                             info (nth 2 entry))
5315                     (when (stringp (setq nth4 (gnus-info-method info)))
5316                       (setq nth4 (gnus-server-to-method nth4))))
5317                   ;; Only do the xrefs if the group has the same
5318                   ;; select method as the group we have just read.
5319                   (or (gnus-methods-equal-p
5320                        nth4 (gnus-find-method-for-group from-newsgroup))
5321                       virtual
5322                       (equal nth4 (setq method (gnus-find-method-for-group
5323                                                 from-newsgroup)))
5324                       (and (equal (car nth4) (car method))
5325                            (equal (nth 1 nth4) (nth 1 method))))
5326                   gnus-use-cross-reference
5327                   (or (not (eq gnus-use-cross-reference t))
5328                       virtual
5329                       ;; Only do cross-references on subscribed
5330                       ;; groups, if that is what is wanted.
5331                       (<= (gnus-info-level info) gnus-level-subscribed))
5332                   (gnus-group-make-articles-read name idlist))))
5333          xref-hashtb)))))
5334
5335 (defun gnus-compute-read-articles (group articles)
5336   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5337          (info (nth 2 entry))
5338          (active (gnus-active group))
5339          ninfo)
5340     (when entry
5341       ;; First peel off all invalid article numbers.
5342       (when active
5343         (let ((ids articles)
5344               id first)
5345           (while (setq id (pop ids))
5346             (when (and first (> id (cdr active)))
5347               ;; We'll end up in this situation in one particular
5348               ;; obscure situation.  If you re-scan a group and get
5349               ;; a new article that is cross-posted to a different
5350               ;; group that has not been re-scanned, you might get
5351               ;; crossposted article that has a higher number than
5352               ;; Gnus believes possible.  So we re-activate this
5353               ;; group as well.  This might mean doing the
5354               ;; crossposting thingy will *increase* the number
5355               ;; of articles in some groups.  Tsk, tsk.
5356               (setq active (or (gnus-activate-group group) active)))
5357             (when (or (> id (cdr active))
5358                       (< id (car active)))
5359               (setq articles (delq id articles))))))
5360       ;; If the read list is nil, we init it.
5361       (if (and active
5362                (null (gnus-info-read info))
5363                (> (car active) 1))
5364           (setq ninfo (cons 1 (1- (car active))))
5365         (setq ninfo (gnus-info-read info)))
5366       ;; Then we add the read articles to the range.
5367       (gnus-add-to-range
5368        ninfo (setq articles (sort articles '<))))))
5369
5370 (defun gnus-group-make-articles-read (group articles)
5371   "Update the info of GROUP to say that ARTICLES are read."
5372   (let* ((num 0)
5373          (entry (gnus-gethash group gnus-newsrc-hashtb))
5374          (info (nth 2 entry))
5375          (active (gnus-active group))
5376          range)
5377     (when entry
5378       (setq range (gnus-compute-read-articles group articles))
5379       (save-excursion
5380         (set-buffer gnus-group-buffer)
5381         (gnus-undo-register
5382           `(progn
5383              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5384              (gnus-info-set-read ',info ',(gnus-info-read info))
5385              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5386              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5387              (gnus-group-update-group ,group t))))
5388       ;; Add the read articles to the range.
5389       (gnus-info-set-read info range)
5390       (gnus-request-set-mark group (list (list range 'add '(read))))
5391       ;; Then we have to re-compute how many unread
5392       ;; articles there are in this group.
5393       (when active
5394         (cond
5395          ((not range)
5396           (setq num (- (1+ (cdr active)) (car active))))
5397          ((not (listp (cdr range)))
5398           (setq num (- (cdr active) (- (1+ (cdr range))
5399                                        (car range)))))
5400          (t
5401           (while range
5402             (if (numberp (car range))
5403                 (setq num (1+ num))
5404               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5405             (setq range (cdr range)))
5406           (setq num (- (cdr active) num))))
5407         ;; Update the number of unread articles.
5408         (setcar entry num)
5409         ;; Update the group buffer.
5410         (gnus-group-update-group group t)))))
5411
5412 (defvar gnus-newsgroup-none-id 0)
5413
5414 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5415   (let ((cur nntp-server-buffer)
5416         (dependencies
5417          (or dependencies
5418              (save-excursion (set-buffer gnus-summary-buffer)
5419                              gnus-newsgroup-dependencies)))
5420         headers id end ref
5421         (mail-parse-charset gnus-newsgroup-charset)
5422         (mail-parse-ignored-charsets
5423          (save-excursion (condition-case nil
5424                              (set-buffer gnus-summary-buffer)
5425                            (error))
5426                          gnus-newsgroup-ignored-charsets)))
5427     (save-excursion
5428       (set-buffer nntp-server-buffer)
5429       ;; Translate all TAB characters into SPACE characters.
5430       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5431       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5432       (gnus-run-hooks 'gnus-parse-headers-hook)
5433       (let ((case-fold-search t)
5434             in-reply-to header p lines chars ctype)
5435         (goto-char (point-min))
5436         ;; Search to the beginning of the next header.  Error messages
5437         ;; do not begin with 2 or 3.
5438         (while (re-search-forward "^[23][0-9]+ " nil t)
5439           (setq id nil
5440                 ref nil)
5441           ;; This implementation of this function, with nine
5442           ;; search-forwards instead of the one re-search-forward and
5443           ;; a case (which basically was the old function) is actually
5444           ;; about twice as fast, even though it looks messier.  You
5445           ;; can't have everything, I guess.  Speed and elegance
5446           ;; doesn't always go hand in hand.
5447           (setq
5448            header
5449            (make-full-mail-header
5450             ;; Number.
5451             (prog1
5452                 (read cur)
5453               (end-of-line)
5454               (setq p (point))
5455               (narrow-to-region (point)
5456                                 (or (and (search-forward "\n.\n" nil t)
5457                                          (- (point) 2))
5458                                     (point))))
5459             ;; Subject.
5460             (progn
5461               (goto-char p)
5462               (if (search-forward "\nsubject:" nil t)
5463                   (nnheader-header-value)
5464                 "(none)"))
5465             ;; From.
5466             (progn
5467               (goto-char p)
5468               (if (search-forward "\nfrom:" nil t)
5469                   (nnheader-header-value)
5470                 "(nobody)"))
5471             ;; Date.
5472             (progn
5473               (goto-char p)
5474               (if (search-forward "\ndate:" nil t)
5475                   (nnheader-header-value) ""))
5476             ;; Message-ID.
5477             (progn
5478               (goto-char p)
5479               (setq id (if (re-search-forward
5480                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5481                            ;; We do it this way to make sure the Message-ID
5482                            ;; is (somewhat) syntactically valid.
5483                            (buffer-substring (match-beginning 1)
5484                                              (match-end 1))
5485                          ;; If there was no message-id, we just fake one
5486                          ;; to make subsequent routines simpler.
5487                          (nnheader-generate-fake-message-id))))
5488             ;; References.
5489             (progn
5490               (goto-char p)
5491               (if (search-forward "\nreferences:" nil t)
5492                   (progn
5493                     (setq end (point))
5494                     (prog1
5495                         (nnheader-header-value)
5496                       (setq ref
5497                             (buffer-substring
5498                              (progn
5499                                ;; (end-of-line)
5500                                (search-backward ">" end t)
5501                                (1+ (point)))
5502                              (progn
5503                                (search-backward "<" end t)
5504                                (point))))))
5505                 ;; Get the references from the in-reply-to header if there
5506                 ;; were no references and the in-reply-to header looks
5507                 ;; promising.
5508                 (if (and (search-forward "\nin-reply-to:" nil t)
5509                          (setq in-reply-to (nnheader-header-value))
5510                          (string-match "<[^>]+>" in-reply-to))
5511                     (let (ref2)
5512                       (setq ref (substring in-reply-to (match-beginning 0)
5513                                            (match-end 0)))
5514                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5515                         (setq ref2 (substring in-reply-to (match-beginning 0)
5516                                               (match-end 0)))
5517                         (when (> (length ref2) (length ref))
5518                           (setq ref ref2)))
5519                       ref)
5520                   (setq ref nil))))
5521             ;; Chars.
5522             (progn
5523               (goto-char p)
5524               (if (search-forward "\nchars: " nil t)
5525                   (if (numberp (setq chars (ignore-errors (read cur))))
5526                       chars -1)
5527                 -1))
5528             ;; Lines.
5529             (progn
5530               (goto-char p)
5531               (if (search-forward "\nlines: " nil t)
5532                   (if (numberp (setq lines (ignore-errors (read cur))))
5533                       lines -1)
5534                 -1))
5535             ;; Xref.
5536             (progn
5537               (goto-char p)
5538               (and (search-forward "\nxref:" nil t)
5539                    (nnheader-header-value)))
5540             ;; Extra.
5541             (when gnus-extra-headers
5542               (let ((extra gnus-extra-headers)
5543                     out)
5544                 (while extra
5545                   (goto-char p)
5546                   (when (search-forward
5547                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5548                     (push (cons (car extra) (nnheader-header-value)) out))
5549                   (pop extra))
5550                 out))))
5551           (goto-char p)
5552           (if (and (search-forward "\ncontent-type: " nil t)
5553                    (setq ctype (nnheader-header-value)))
5554               (mime-entity-set-content-type-internal
5555                header (mime-parse-Content-Type ctype)))
5556           (when (equal id ref)
5557             (setq ref nil))
5558
5559           (when gnus-alter-header-function
5560             (funcall gnus-alter-header-function header)
5561             (setq id (mail-header-id header)
5562                   ref (gnus-parent-id (mail-header-references header))))
5563
5564           (when (setq header
5565                       (gnus-dependencies-add-header
5566                        header dependencies force-new))
5567             (push header headers))
5568           (goto-char (point-max))
5569           (widen))
5570         (nreverse headers)))))
5571
5572 ;; Goes through the xover lines and returns a list of vectors
5573 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5574                                                   force-new dependencies
5575                                                   group also-fetch-heads)
5576   "Parse the news overview data in the server buffer.
5577 Return a list of headers that match SEQUENCE (see
5578 `nntp-retrieve-headers')."
5579   ;; Get the Xref when the users reads the articles since most/some
5580   ;; NNTP servers do not include Xrefs when using XOVER.
5581   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5582   (let ((mail-parse-charset gnus-newsgroup-charset)
5583         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5584         (cur nntp-server-buffer)
5585         (dependencies (or dependencies gnus-newsgroup-dependencies))
5586         (allp (cond
5587                ((eq gnus-read-all-available-headers t)
5588                 t)
5589                ((stringp gnus-read-all-available-headers)
5590                 (string-match gnus-read-all-available-headers group))
5591                (t
5592                 nil)))
5593         number headers header)
5594     (save-excursion
5595       (set-buffer nntp-server-buffer)
5596       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5597       ;; Allow the user to mangle the headers before parsing them.
5598       (gnus-run-hooks 'gnus-parse-headers-hook)
5599       (goto-char (point-min))
5600       (gnus-parse-without-error
5601         (while (and (or sequence allp)
5602                     (not (eobp)))
5603           (setq number (read cur))
5604           (when (not allp)
5605             (while (and sequence
5606                         (< (car sequence) number))
5607               (setq sequence (cdr sequence))))
5608           (when (and (or allp
5609                          (and sequence
5610                               (eq number (car sequence))))
5611                      (progn
5612                        (setq sequence (cdr sequence))
5613                        (setq header (inline
5614                                       (gnus-nov-parse-line
5615                                        number dependencies force-new)))))
5616             (push header headers))
5617           (forward-line 1)))
5618       ;; A common bug in inn is that if you have posted an article and
5619       ;; then retrieves the active file, it will answer correctly --
5620       ;; the new article is included.  However, a NOV entry for the
5621       ;; article may not have been generated yet, so this may fail.
5622       ;; We work around this problem by retrieving the last few
5623       ;; headers using HEAD.
5624       (if (or (not also-fetch-heads)
5625               (not sequence))
5626           ;; We (probably) got all the headers.
5627           (nreverse headers)
5628         (let ((gnus-nov-is-evil t))
5629           (nconc
5630            (nreverse headers)
5631            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5632              (gnus-get-newsgroup-headers))))))))
5633
5634 (defun gnus-article-get-xrefs ()
5635   "Fill in the Xref value in `gnus-current-headers', if necessary.
5636 This is meant to be called in `gnus-article-internal-prepare-hook'."
5637   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5638                                  gnus-current-headers)))
5639     (or (not gnus-use-cross-reference)
5640         (not headers)
5641         (and (mail-header-xref headers)
5642              (not (string= (mail-header-xref headers) "")))
5643         (let ((case-fold-search t)
5644               xref)
5645           (save-restriction
5646             (nnheader-narrow-to-headers)
5647             (goto-char (point-min))
5648             (when (or (and (not (eobp))
5649                            (eq (downcase (char-after)) ?x)
5650                            (looking-at "Xref:"))
5651                       (search-forward "\nXref:" nil t))
5652               (goto-char (1+ (match-end 0)))
5653               (setq xref (buffer-substring (point)
5654                                            (progn (end-of-line) (point))))
5655               (mail-header-set-xref headers xref)))))))
5656
5657 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5658   "Find article ID and insert the summary line for that article.
5659 OLD-HEADER can either be a header or a line number to insert
5660 the subject line on."
5661   (let* ((line (and (numberp old-header) old-header))
5662          (old-header (and (vectorp old-header) old-header))
5663          (header (cond ((and old-header use-old-header)
5664                         old-header)
5665                        ((and (numberp id)
5666                              (gnus-number-to-header id))
5667                         (gnus-number-to-header id))
5668                        (t
5669                         (gnus-read-header id))))
5670          (number (and (numberp id) id))
5671          d)
5672     (when header
5673       ;; Rebuild the thread that this article is part of and go to the
5674       ;; article we have fetched.
5675       (when (and (not gnus-show-threads)
5676                  old-header)
5677         (when (and number
5678                    (setq d (gnus-data-find (mail-header-number old-header))))
5679           (goto-char (gnus-data-pos d))
5680           (gnus-data-remove
5681            number
5682            (- (gnus-point-at-bol)
5683               (prog1
5684                   (1+ (gnus-point-at-eol))
5685                 (gnus-delete-line))))))
5686       (when old-header
5687         (mail-header-set-number header (mail-header-number old-header)))
5688       (setq gnus-newsgroup-sparse
5689             (delq (setq number (mail-header-number header))
5690                   gnus-newsgroup-sparse))
5691       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5692       (push number gnus-newsgroup-limit)
5693       (gnus-rebuild-thread (mail-header-id header) line)
5694       (gnus-summary-goto-subject number nil t))
5695     (when (and (numberp number)
5696                (> number 0))
5697       ;; We have to update the boundaries even if we can't fetch the
5698       ;; article if ID is a number -- so that the next `P' or `N'
5699       ;; command will fetch the previous (or next) article even
5700       ;; if the one we tried to fetch this time has been canceled.
5701       (when (> number gnus-newsgroup-end)
5702         (setq gnus-newsgroup-end number))
5703       (when (< number gnus-newsgroup-begin)
5704         (setq gnus-newsgroup-begin number))
5705       (setq gnus-newsgroup-unselected
5706             (delq number gnus-newsgroup-unselected)))
5707     ;; Report back a success?
5708     (and header (mail-header-number header))))
5709
5710 ;;; Process/prefix in the summary buffer
5711
5712 (defun gnus-summary-work-articles (n)
5713   "Return a list of articles to be worked upon.
5714 The prefix argument, the list of process marked articles, and the
5715 current article will be taken into consideration."
5716   (save-excursion
5717     (set-buffer gnus-summary-buffer)
5718     (cond
5719      (n
5720       ;; A numerical prefix has been given.
5721       (setq n (prefix-numeric-value n))
5722       (let ((backward (< n 0))
5723             (n (abs (prefix-numeric-value n)))
5724             articles article)
5725         (save-excursion
5726           (while
5727               (and (> n 0)
5728                    (push (setq article (gnus-summary-article-number))
5729                          articles)
5730                    (if backward
5731                        (gnus-summary-find-prev nil article)
5732                      (gnus-summary-find-next nil article)))
5733             (decf n)))
5734         (nreverse articles)))
5735      ((and (gnus-region-active-p) (mark))
5736       (message "region active")
5737       ;; Work on the region between point and mark.
5738       (let ((max (max (point) (mark)))
5739             articles article)
5740         (save-excursion
5741           (goto-char (min (point) (mark)))
5742           (while
5743               (and
5744                (push (setq article (gnus-summary-article-number)) articles)
5745                (gnus-summary-find-next nil article)
5746                (< (point) max)))
5747           (nreverse articles))))
5748      (gnus-newsgroup-processable
5749       ;; There are process-marked articles present.
5750       ;; Save current state.
5751       (gnus-summary-save-process-mark)
5752       ;; Return the list.
5753       (reverse gnus-newsgroup-processable))
5754      (t
5755       ;; Just return the current article.
5756       (list (gnus-summary-article-number))))))
5757
5758 (defmacro gnus-summary-iterate (arg &rest forms)
5759   "Iterate over the process/prefixed articles and do FORMS.
5760 ARG is the interactive prefix given to the command.  FORMS will be
5761 executed with point over the summary line of the articles."
5762   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5763     `(let ((,articles (gnus-summary-work-articles ,arg)))
5764        (while ,articles
5765          (gnus-summary-goto-subject (car ,articles))
5766          ,@forms
5767          (pop ,articles)))))
5768
5769 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5770 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5771
5772 (defun gnus-summary-save-process-mark ()
5773   "Push the current set of process marked articles on the stack."
5774   (interactive)
5775   (push (copy-sequence gnus-newsgroup-processable)
5776         gnus-newsgroup-process-stack))
5777
5778 (defun gnus-summary-kill-process-mark ()
5779   "Push the current set of process marked articles on the stack and unmark."
5780   (interactive)
5781   (gnus-summary-save-process-mark)
5782   (gnus-summary-unmark-all-processable))
5783
5784 (defun gnus-summary-yank-process-mark ()
5785   "Pop the last process mark state off the stack and restore it."
5786   (interactive)
5787   (unless gnus-newsgroup-process-stack
5788     (error "Empty mark stack"))
5789   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5790
5791 (defun gnus-summary-process-mark-set (set)
5792   "Make SET into the current process marked articles."
5793   (gnus-summary-unmark-all-processable)
5794   (while set
5795     (gnus-summary-set-process-mark (pop set))))
5796
5797 ;;; Searching and stuff
5798
5799 (defun gnus-summary-search-group (&optional backward use-level)
5800   "Search for next unread newsgroup.
5801 If optional argument BACKWARD is non-nil, search backward instead."
5802   (save-excursion
5803     (set-buffer gnus-group-buffer)
5804     (when (gnus-group-search-forward
5805            backward nil (if use-level (gnus-group-group-level) nil))
5806       (gnus-group-group-name))))
5807
5808 (defun gnus-summary-best-group (&optional exclude-group)
5809   "Find the name of the best unread group.
5810 If EXCLUDE-GROUP, do not go to this group."
5811   (save-excursion
5812     (set-buffer gnus-group-buffer)
5813     (save-excursion
5814       (gnus-group-best-unread-group exclude-group))))
5815
5816 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5817   (if backward (gnus-summary-find-prev)
5818     (let* ((dummy (gnus-summary-article-intangible-p))
5819            (article (or article (gnus-summary-article-number)))
5820            (arts (gnus-data-find-list article))
5821            result)
5822       (when (and (not dummy)
5823                  (or (not gnus-summary-check-current)
5824                      (not unread)
5825                      (not (gnus-data-unread-p (car arts)))))
5826         (setq arts (cdr arts)))
5827       (when (setq result
5828                   (if unread
5829                       (progn
5830                         (while arts
5831                           (when (or (and undownloaded
5832                                          (eq gnus-undownloaded-mark
5833                                              (gnus-data-mark (car arts))))
5834                                     (gnus-data-unread-p (car arts)))
5835                             (setq result (car arts)
5836                                   arts nil))
5837                           (setq arts (cdr arts)))
5838                         result)
5839                     (car arts)))
5840         (goto-char (gnus-data-pos result))
5841         (gnus-data-number result)))))
5842
5843 (defun gnus-summary-find-prev (&optional unread article)
5844   (let* ((eobp (eobp))
5845          (article (or article (gnus-summary-article-number)))
5846          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5847          result)
5848     (when (and (not eobp)
5849                (or (not gnus-summary-check-current)
5850                    (not unread)
5851                    (not (gnus-data-unread-p (car arts)))))
5852       (setq arts (cdr arts)))
5853     (when (setq result
5854                 (if unread
5855                     (progn
5856                       (while arts
5857                         (when (gnus-data-unread-p (car arts))
5858                           (setq result (car arts)
5859                                 arts nil))
5860                         (setq arts (cdr arts)))
5861                       result)
5862                   (car arts)))
5863       (goto-char (gnus-data-pos result))
5864       (gnus-data-number result))))
5865
5866 (defun gnus-summary-find-subject (subject &optional unread backward article)
5867   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5868          (article (or article (gnus-summary-article-number)))
5869          (articles (gnus-data-list backward))
5870          (arts (gnus-data-find-list article articles))
5871          result)
5872     (when (or (not gnus-summary-check-current)
5873               (not unread)
5874               (not (gnus-data-unread-p (car arts))))
5875       (setq arts (cdr arts)))
5876     (while arts
5877       (and (or (not unread)
5878                (gnus-data-unread-p (car arts)))
5879            (vectorp (gnus-data-header (car arts)))
5880            (gnus-subject-equal
5881             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5882            (setq result (car arts)
5883                  arts nil))
5884       (setq arts (cdr arts)))
5885     (and result
5886          (goto-char (gnus-data-pos result))
5887          (gnus-data-number result))))
5888
5889 (defun gnus-summary-search-forward (&optional unread subject backward)
5890   "Search forward for an article.
5891 If UNREAD, look for unread articles.  If SUBJECT, look for
5892 articles with that subject.  If BACKWARD, search backward instead."
5893   (cond (subject (gnus-summary-find-subject subject unread backward))
5894         (backward (gnus-summary-find-prev unread))
5895         (t (gnus-summary-find-next unread))))
5896
5897 (defun gnus-recenter (&optional n)
5898   "Center point in window and redisplay frame.
5899 Also do horizontal recentering."
5900   (interactive "P")
5901   (when (and gnus-auto-center-summary
5902              (not (eq gnus-auto-center-summary 'vertical)))
5903     (gnus-horizontal-recenter))
5904   (recenter n))
5905
5906 (defun gnus-summary-recenter ()
5907   "Center point in the summary window.
5908 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5909 displayed, no centering will be performed."
5910   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5911   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5912   (interactive)
5913   (let* ((top (cond ((< (window-height) 4) 0)
5914                     ((< (window-height) 7) 1)
5915                     (t (if (numberp gnus-auto-center-summary)
5916                            gnus-auto-center-summary
5917                          2))))
5918          (height (1- (window-height)))
5919          (bottom (save-excursion (goto-char (point-max))
5920                                  (forward-line (- height))
5921                                  (point)))
5922          (window (get-buffer-window (current-buffer))))
5923     ;; The user has to want it.
5924     (when gnus-auto-center-summary
5925       (when (get-buffer-window gnus-article-buffer)
5926         ;; Only do recentering when the article buffer is displayed,
5927         ;; Set the window start to either `bottom', which is the biggest
5928         ;; possible valid number, or the second line from the top,
5929         ;; whichever is the least.
5930         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5931           (if (> bottom top-pos)
5932               ;; Keep the second line from the top visible
5933               (set-window-start window top-pos t)
5934             ;; Try to keep the bottom line visible; if it's partially
5935             ;; obscured, either scroll one more line to make it fully
5936             ;; visible, or revert to using TOP-POS.
5937             (save-excursion
5938               (goto-char (point-max))
5939               (forward-line -1)
5940               (let ((last-line-start (point)))
5941                 (goto-char bottom)
5942                 (set-window-start window (point) t)
5943                 (when (not (pos-visible-in-window-p last-line-start window))
5944                   (forward-line 1)
5945                   (set-window-start window (min (point) top-pos) t)))))))
5946       ;; Do horizontal recentering while we're at it.
5947       (when (and (get-buffer-window (current-buffer) t)
5948                  (not (eq gnus-auto-center-summary 'vertical)))
5949         (let ((selected (selected-window)))
5950           (select-window (get-buffer-window (current-buffer) t))
5951           (gnus-summary-position-point)
5952           (gnus-horizontal-recenter)
5953           (select-window selected))))))
5954
5955 (defun gnus-summary-jump-to-group (newsgroup)
5956   "Move point to NEWSGROUP in group mode buffer."
5957   ;; Keep update point of group mode buffer if visible.
5958   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5959       (save-window-excursion
5960         ;; Take care of tree window mode.
5961         (when (get-buffer-window gnus-group-buffer)
5962           (pop-to-buffer gnus-group-buffer))
5963         (gnus-group-jump-to-group newsgroup))
5964     (save-excursion
5965       ;; Take care of tree window mode.
5966       (if (get-buffer-window gnus-group-buffer)
5967           (pop-to-buffer gnus-group-buffer)
5968         (set-buffer gnus-group-buffer))
5969       (gnus-group-jump-to-group newsgroup))))
5970
5971 ;; This function returns a list of article numbers based on the
5972 ;; difference between the ranges of read articles in this group and
5973 ;; the range of active articles.
5974 (defun gnus-list-of-unread-articles (group)
5975   (let* ((read (gnus-info-read (gnus-get-info group)))
5976          (active (or (gnus-active group) (gnus-activate-group group)))
5977          (last (cdr active))
5978          first nlast unread)
5979     ;; If none are read, then all are unread.
5980     (if (not read)
5981         (setq first (car active))
5982       ;; If the range of read articles is a single range, then the
5983       ;; first unread article is the article after the last read
5984       ;; article.  Sounds logical, doesn't it?
5985       (if (and (not (listp (cdr read)))
5986                (or (< (car read) (car active))
5987                    (progn (setq read (list read))
5988                           nil)))
5989           (setq first (max (car active) (1+ (cdr read))))
5990         ;; `read' is a list of ranges.
5991         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5992                                   (caar read)))
5993                   1)
5994           (setq first (car active)))
5995         (while read
5996           (when first
5997             (while (< first nlast)
5998               (push first unread)
5999               (setq first (1+ first))))
6000           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6001           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6002           (setq read (cdr read)))))
6003     ;; And add the last unread articles.
6004     (while (<= first last)
6005       (push first unread)
6006       (setq first (1+ first)))
6007     ;; Return the list of unread articles.
6008     (delq 0 (nreverse unread))))
6009
6010 (defun gnus-list-of-read-articles (group)
6011   "Return a list of unread, unticked and non-dormant articles."
6012   (let* ((info (gnus-get-info group))
6013          (marked (gnus-info-marks info))
6014          (active (gnus-active group)))
6015     (and info active
6016          (gnus-list-range-difference
6017           (gnus-list-range-difference
6018            (gnus-sorted-complement
6019             (gnus-uncompress-range active)
6020             (gnus-list-of-unread-articles group))
6021            (cdr (assq 'dormant marked)))
6022           (cdr (assq 'tick marked))))))
6023
6024 ;; Various summary commands
6025
6026 (defun gnus-summary-select-article-buffer ()
6027   "Reconfigure windows to show article buffer."
6028   (interactive)
6029   (if (not (gnus-buffer-live-p gnus-article-buffer))
6030       (error "There is no article buffer for this summary buffer")
6031     (gnus-configure-windows 'article)
6032     (select-window (get-buffer-window gnus-article-buffer))))
6033
6034 (defun gnus-summary-universal-argument (arg)
6035   "Perform any operation on all articles that are process/prefixed."
6036   (interactive "P")
6037   (let ((articles (gnus-summary-work-articles arg))
6038         func article)
6039     (if (eq
6040          (setq
6041           func
6042           (key-binding
6043            (read-key-sequence
6044             (substitute-command-keys
6045              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6046          'undefined)
6047         (gnus-error 1 "Undefined key")
6048       (save-excursion
6049         (while articles
6050           (gnus-summary-goto-subject (setq article (pop articles)))
6051           (let (gnus-newsgroup-processable)
6052             (command-execute func))
6053           (gnus-summary-remove-process-mark article)))))
6054   (gnus-summary-position-point))
6055
6056 (defun gnus-summary-toggle-truncation (&optional arg)
6057   "Toggle truncation of summary lines.
6058 With arg, turn line truncation on iff arg is positive."
6059   (interactive "P")
6060   (setq truncate-lines
6061         (if (null arg) (not truncate-lines)
6062           (> (prefix-numeric-value arg) 0)))
6063   (redraw-display))
6064
6065 (defun gnus-summary-reselect-current-group (&optional all rescan)
6066   "Exit and then reselect the current newsgroup.
6067 The prefix argument ALL means to select all articles."
6068   (interactive "P")
6069   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6070     (error "Ephemeral groups can't be reselected"))
6071   (let ((current-subject (gnus-summary-article-number))
6072         (group gnus-newsgroup-name))
6073     (setq gnus-newsgroup-begin nil)
6074     (gnus-summary-exit)
6075     ;; We have to adjust the point of group mode buffer because
6076     ;; point was moved to the next unread newsgroup by exiting.
6077     (gnus-summary-jump-to-group group)
6078     (when rescan
6079       (save-excursion
6080         (save-window-excursion
6081           ;; Don't show group contents.
6082           (set-window-start (selected-window) (point-max))
6083           (gnus-group-get-new-news-this-group 1))))
6084     (gnus-group-read-group all t)
6085     (gnus-summary-goto-subject current-subject nil t)))
6086
6087 (defun gnus-summary-rescan-group (&optional all)
6088   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6089   (interactive "P")
6090   (gnus-summary-reselect-current-group all t))
6091
6092 (defun gnus-summary-update-info (&optional non-destructive)
6093   (save-excursion
6094     (let ((group gnus-newsgroup-name))
6095       (when group
6096         (when gnus-newsgroup-kill-headers
6097           (setq gnus-newsgroup-killed
6098                 (gnus-compress-sequence
6099                  (gnus-sorted-union
6100                   (gnus-list-range-intersection
6101                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6102                   gnus-newsgroup-unreads)
6103                  t)))
6104         (unless (listp (cdr gnus-newsgroup-killed))
6105           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6106         (let ((headers gnus-newsgroup-headers))
6107           ;; Set the new ranges of read articles.
6108           (save-excursion
6109             (set-buffer gnus-group-buffer)
6110             (gnus-undo-force-boundary))
6111           (gnus-update-read-articles
6112            group (gnus-sorted-union
6113                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6114           ;; Set the current article marks.
6115           (let ((gnus-newsgroup-scored
6116                  (if (and (not gnus-save-score)
6117                           (not non-destructive))
6118                      nil
6119                    gnus-newsgroup-scored)))
6120             (save-excursion
6121               (gnus-update-marks)))
6122           ;; Do the cross-ref thing.
6123           (when gnus-use-cross-reference
6124             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6125           ;; Do not switch windows but change the buffer to work.
6126           (set-buffer gnus-group-buffer)
6127           (unless (gnus-ephemeral-group-p group)
6128             (gnus-group-update-group group)))))))
6129
6130 (defun gnus-summary-save-newsrc (&optional force)
6131   "Save the current number of read/marked articles in the dribble buffer.
6132 The dribble buffer will then be saved.
6133 If FORCE (the prefix), also save the .newsrc file(s)."
6134   (interactive "P")
6135   (gnus-summary-update-info t)
6136   (if force
6137       (gnus-save-newsrc-file)
6138     (gnus-dribble-save)))
6139
6140 (defun gnus-summary-exit (&optional temporary)
6141   "Exit reading current newsgroup, and then return to group selection mode.
6142 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6143   (interactive)
6144   (gnus-set-global-variables)
6145   (gnus-kill-save-kill-buffer)
6146   (gnus-async-halt-prefetch)
6147   (let* ((group gnus-newsgroup-name)
6148          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6149          (mode major-mode)
6150          (group-point nil)
6151          (buf (current-buffer)))
6152     (unless quit-config
6153       ;; Do adaptive scoring, and possibly save score files.
6154       (when gnus-newsgroup-adaptive
6155         (gnus-score-adaptive))
6156       (when gnus-use-scoring
6157         (gnus-score-save)))
6158     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6159     ;; If we have several article buffers, we kill them at exit.
6160     (unless gnus-single-article-buffer
6161       (gnus-kill-buffer gnus-original-article-buffer)
6162       (setq gnus-article-current nil))
6163     (when gnus-use-cache
6164       (gnus-cache-possibly-remove-articles)
6165       (gnus-cache-save-buffers))
6166     (gnus-async-prefetch-remove-group group)
6167     (when gnus-suppress-duplicates
6168       (gnus-dup-enter-articles))
6169     (when gnus-use-trees
6170       (gnus-tree-close group))
6171     (when gnus-use-cache
6172       (gnus-cache-write-active))
6173     ;; Remove entries for this group.
6174     (nnmail-purge-split-history (gnus-group-real-name group))
6175     ;; Make all changes in this group permanent.
6176     (unless quit-config
6177       (gnus-run-hooks 'gnus-exit-group-hook)
6178       (gnus-summary-update-info))
6179     (gnus-close-group group)
6180     ;; Make sure where we were, and go to next newsgroup.
6181     (set-buffer gnus-group-buffer)
6182     (unless quit-config
6183       (gnus-group-jump-to-group group))
6184     (gnus-run-hooks 'gnus-summary-exit-hook)
6185     (unless (or quit-config
6186                 ;; If this group has disappeared from the summary
6187                 ;; buffer, don't skip forwards.
6188                 (not (string= group (gnus-group-group-name))))
6189       (gnus-group-next-unread-group 1))
6190     (setq group-point (point))
6191     (if temporary
6192         nil                             ;Nothing to do.
6193       ;; If we have several article buffers, we kill them at exit.
6194       (unless gnus-single-article-buffer
6195         (gnus-kill-buffer gnus-article-buffer)
6196         (gnus-kill-buffer gnus-original-article-buffer)
6197         (setq gnus-article-current nil))
6198       (set-buffer buf)
6199       (if (not gnus-kill-summary-on-exit)
6200           (progn
6201             (gnus-deaden-summary)
6202             (setq mode nil))
6203         ;; We set all buffer-local variables to nil.  It is unclear why
6204         ;; this is needed, but if we don't, buffer-local variables are
6205         ;; not garbage-collected, it seems.  This would the lead to en
6206         ;; ever-growing Emacs.
6207         (gnus-summary-clear-local-variables)
6208         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6209           (gnus-summary-clear-local-variables))
6210         (when (get-buffer gnus-article-buffer)
6211           (bury-buffer gnus-article-buffer))
6212         ;; We clear the global counterparts of the buffer-local
6213         ;; variables as well, just to be on the safe side.
6214         (set-buffer gnus-group-buffer)
6215         (gnus-summary-clear-local-variables)
6216         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6217           (gnus-summary-clear-local-variables)))
6218       (setq gnus-current-select-method gnus-select-method)
6219       (pop-to-buffer gnus-group-buffer)
6220       (if (not quit-config)
6221           (progn
6222             (goto-char group-point)
6223             (gnus-configure-windows 'group 'force)
6224             (unless (pos-visible-in-window-p)
6225               (forward-line (/ (static-if (featurep 'xemacs)
6226                                    (window-displayed-height)
6227                                  (1- (window-height)))
6228                                -2))
6229               (set-window-start (selected-window) (point))
6230               (goto-char group-point)))
6231         (gnus-handle-ephemeral-exit quit-config))
6232       ;; Return to group mode buffer.
6233       (when (eq mode 'gnus-summary-mode)
6234         (gnus-kill-buffer buf))
6235       ;; Clear the current group name.
6236       (unless quit-config
6237         (setq gnus-newsgroup-name nil)))))
6238
6239 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6240 (defun gnus-summary-exit-no-update (&optional no-questions)
6241   "Quit reading current newsgroup without updating read article info."
6242   (interactive)
6243   (let* ((group gnus-newsgroup-name)
6244          (quit-config (gnus-group-quit-config group)))
6245     (when (or no-questions
6246               gnus-expert-user
6247               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6248       (gnus-async-halt-prefetch)
6249       (mapcar 'funcall
6250               (delq 'gnus-summary-expire-articles
6251                     (copy-sequence gnus-summary-prepare-exit-hook)))
6252       ;; If we have several article buffers, we kill them at exit.
6253       (unless gnus-single-article-buffer
6254         (gnus-kill-buffer gnus-article-buffer)
6255         (gnus-kill-buffer gnus-original-article-buffer)
6256         (setq gnus-article-current nil))
6257       (if (not gnus-kill-summary-on-exit)
6258           (gnus-deaden-summary)
6259         (gnus-close-group group)
6260         (gnus-summary-clear-local-variables)
6261         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6262           (gnus-summary-clear-local-variables))
6263         (set-buffer gnus-group-buffer)
6264         (gnus-summary-clear-local-variables)
6265         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6266           (gnus-summary-clear-local-variables))
6267         (when (get-buffer gnus-summary-buffer)
6268           (kill-buffer gnus-summary-buffer)))
6269       (unless gnus-single-article-buffer
6270         (setq gnus-article-current nil))
6271       (when gnus-use-trees
6272         (gnus-tree-close group))
6273       (gnus-async-prefetch-remove-group group)
6274       (when (get-buffer gnus-article-buffer)
6275         (bury-buffer gnus-article-buffer))
6276       ;; Return to the group buffer.
6277       (gnus-configure-windows 'group 'force)
6278       ;; Clear the current group name.
6279       (setq gnus-newsgroup-name nil)
6280       (when (equal (gnus-group-group-name) group)
6281         (gnus-group-next-unread-group 1))
6282       (when quit-config
6283         (gnus-handle-ephemeral-exit quit-config)))))
6284
6285 (defun gnus-handle-ephemeral-exit (quit-config)
6286   "Handle movement when leaving an ephemeral group.
6287 The state which existed when entering the ephemeral is reset."
6288   (if (not (buffer-name (car quit-config)))
6289       (gnus-configure-windows 'group 'force)
6290     (set-buffer (car quit-config))
6291     (cond ((eq major-mode 'gnus-summary-mode)
6292            (gnus-set-global-variables))
6293           ((eq major-mode 'gnus-article-mode)
6294            (save-excursion
6295              ;; The `gnus-summary-buffer' variable may point
6296              ;; to the old summary buffer when using a single
6297              ;; article buffer.
6298              (unless (gnus-buffer-live-p gnus-summary-buffer)
6299                (set-buffer gnus-group-buffer))
6300              (set-buffer gnus-summary-buffer)
6301              (gnus-set-global-variables))))
6302     (if (or (eq (cdr quit-config) 'article)
6303             (eq (cdr quit-config) 'pick))
6304         (progn
6305           ;; The current article may be from the ephemeral group
6306           ;; thus it is best that we reload this article
6307           (gnus-summary-show-article)
6308           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6309               (gnus-configure-windows 'pick 'force)
6310             (gnus-configure-windows (cdr quit-config) 'force)))
6311       (gnus-configure-windows (cdr quit-config) 'force))
6312     (when (eq major-mode 'gnus-summary-mode)
6313       (gnus-summary-next-subject 1 nil t)
6314       (gnus-summary-recenter)
6315       (gnus-summary-position-point))))
6316
6317 (defun gnus-summary-preview-mime-message ()
6318   "MIME decode and play this message."
6319   (interactive)
6320   (let ((gnus-break-pages nil)
6321         (gnus-show-mime t))
6322     (gnus-summary-select-article gnus-show-all-headers t))
6323   (let ((w (get-buffer-window gnus-article-buffer)))
6324     (when w
6325       (select-window (get-buffer-window gnus-article-buffer)))))
6326
6327 ;;; Dead summaries.
6328
6329 (defvar gnus-dead-summary-mode-map nil)
6330
6331 (unless gnus-dead-summary-mode-map
6332   (setq gnus-dead-summary-mode-map (make-keymap))
6333   (suppress-keymap gnus-dead-summary-mode-map)
6334   (substitute-key-definition
6335    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6336   (dolist (key '("\C-d" "\r" "\177" [delete]))
6337     (define-key gnus-dead-summary-mode-map
6338       key 'gnus-summary-wake-up-the-dead))
6339   (dolist (key '("q" "Q"))
6340     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6341
6342 (defvar gnus-dead-summary-mode nil
6343   "Minor mode for Gnus summary buffers.")
6344
6345 (defun gnus-dead-summary-mode (&optional arg)
6346   "Minor mode for Gnus summary buffers."
6347   (interactive "P")
6348   (when (eq major-mode 'gnus-summary-mode)
6349     (make-local-variable 'gnus-dead-summary-mode)
6350     (setq gnus-dead-summary-mode
6351           (if (null arg) (not gnus-dead-summary-mode)
6352             (> (prefix-numeric-value arg) 0)))
6353     (when gnus-dead-summary-mode
6354       (gnus-add-minor-mode
6355        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6356
6357 (defun gnus-deaden-summary ()
6358   "Make the current summary buffer into a dead summary buffer."
6359   ;; Kill any previous dead summary buffer.
6360   (when (and gnus-dead-summary
6361              (buffer-name gnus-dead-summary))
6362     (save-excursion
6363       (set-buffer gnus-dead-summary)
6364       (when gnus-dead-summary-mode
6365         (kill-buffer (current-buffer)))))
6366   ;; Make this the current dead summary.
6367   (setq gnus-dead-summary (current-buffer))
6368   (gnus-dead-summary-mode 1)
6369   (let ((name (buffer-name)))
6370     (when (string-match "Summary" name)
6371       (rename-buffer
6372        (concat (substring name 0 (match-beginning 0)) "Dead "
6373                (substring name (match-beginning 0)))
6374        t)
6375       (bury-buffer))))
6376
6377 (defun gnus-kill-or-deaden-summary (buffer)
6378   "Kill or deaden the summary BUFFER."
6379   (save-excursion
6380     (when (and (buffer-name buffer)
6381                (not gnus-single-article-buffer))
6382       (save-excursion
6383         (set-buffer buffer)
6384         (gnus-kill-buffer gnus-article-buffer)
6385         (gnus-kill-buffer gnus-original-article-buffer)))
6386     (cond
6387      ;; Kill the buffer.
6388      (gnus-kill-summary-on-exit
6389       (when (and gnus-use-trees
6390                  (gnus-buffer-exists-p buffer))
6391         (save-excursion
6392           (set-buffer buffer)
6393           (gnus-tree-close gnus-newsgroup-name)))
6394       (gnus-kill-buffer buffer))
6395      ;; Deaden the buffer.
6396      ((gnus-buffer-exists-p buffer)
6397       (save-excursion
6398         (set-buffer buffer)
6399         (gnus-deaden-summary))))))
6400
6401 (defun gnus-summary-wake-up-the-dead (&rest args)
6402   "Wake up the dead summary buffer."
6403   (interactive)
6404   (gnus-dead-summary-mode -1)
6405   (let ((name (buffer-name)))
6406     (when (string-match "Dead " name)
6407       (rename-buffer
6408        (concat (substring name 0 (match-beginning 0))
6409                (substring name (match-end 0)))
6410        t)))
6411   (gnus-message 3 "This dead summary is now alive again"))
6412
6413 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6414 (defun gnus-summary-fetch-faq (&optional faq-dir)
6415   "Fetch the FAQ for the current group.
6416 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6417 in."
6418   (interactive
6419    (list
6420     (when current-prefix-arg
6421       (completing-read
6422        "Faq dir: " (and (listp gnus-group-faq-directory)
6423                         (mapcar (lambda (file) (list file))
6424                                 gnus-group-faq-directory))))))
6425   (let (gnus-faq-buffer)
6426     (when (setq gnus-faq-buffer
6427                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6428       (gnus-configure-windows 'summary-faq))))
6429
6430 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6431 (defun gnus-summary-describe-group (&optional force)
6432   "Describe the current newsgroup."
6433   (interactive "P")
6434   (gnus-group-describe-group force gnus-newsgroup-name))
6435
6436 (defun gnus-summary-describe-briefly ()
6437   "Describe summary mode commands briefly."
6438   (interactive)
6439   (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")))
6440
6441 ;; Walking around group mode buffer from summary mode.
6442
6443 (defun gnus-summary-next-group (&optional no-article target-group backward)
6444   "Exit current newsgroup and then select next unread newsgroup.
6445 If prefix argument NO-ARTICLE is non-nil, no article is selected
6446 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6447 previous group instead."
6448   (interactive "P")
6449   ;; Stop pre-fetching.
6450   (gnus-async-halt-prefetch)
6451   (let ((current-group gnus-newsgroup-name)
6452         (current-buffer (current-buffer))
6453         entered)
6454     ;; First we semi-exit this group to update Xrefs and all variables.
6455     ;; We can't do a real exit, because the window conf must remain
6456     ;; the same in case the user is prompted for info, and we don't
6457     ;; want the window conf to change before that...
6458     (gnus-summary-exit t)
6459     (while (not entered)
6460       ;; Then we find what group we are supposed to enter.
6461       (set-buffer gnus-group-buffer)
6462       (gnus-group-jump-to-group current-group)
6463       (setq target-group
6464             (or target-group
6465                 (if (eq gnus-keep-same-level 'best)
6466                     (gnus-summary-best-group gnus-newsgroup-name)
6467                   (gnus-summary-search-group backward gnus-keep-same-level))))
6468       (if (not target-group)
6469           ;; There are no further groups, so we return to the group
6470           ;; buffer.
6471           (progn
6472             (gnus-message 5 "Returning to the group buffer")
6473             (setq entered t)
6474             (when (gnus-buffer-live-p current-buffer)
6475               (set-buffer current-buffer)
6476               (gnus-summary-exit))
6477             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6478         ;; We try to enter the target group.
6479         (gnus-group-jump-to-group target-group)
6480         (let ((unreads (gnus-group-group-unread)))
6481           (if (and (or (eq t unreads)
6482                        (and unreads (not (zerop unreads))))
6483                    (gnus-summary-read-group
6484                     target-group nil no-article
6485                     (and (buffer-name current-buffer) current-buffer)
6486                     nil backward))
6487               (setq entered t)
6488             (setq current-group target-group
6489                   target-group nil)))))))
6490
6491 (defun gnus-summary-prev-group (&optional no-article)
6492   "Exit current newsgroup and then select previous unread newsgroup.
6493 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6494   (interactive "P")
6495   (gnus-summary-next-group no-article nil t))
6496
6497 ;; Walking around summary lines.
6498
6499 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6500   "Go to the first unread subject.
6501 If UNREAD is non-nil, go to the first unread article.
6502 Returns the article selected or nil if there are no unread articles."
6503   (interactive "P")
6504   (prog1
6505       (cond
6506        ;; Empty summary.
6507        ((null gnus-newsgroup-data)
6508         (gnus-message 3 "No articles in the group")
6509         nil)
6510        ;; Pick the first article.
6511        ((not unread)
6512         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6513         (gnus-data-number (car gnus-newsgroup-data)))
6514        ;; No unread articles.
6515        ((null gnus-newsgroup-unreads)
6516         (gnus-message 3 "No more unread articles")
6517         nil)
6518        ;; Find the first unread article.
6519        (t
6520         (let ((data gnus-newsgroup-data))
6521           (while (and data
6522                       (and (not (and undownloaded
6523                                      (eq gnus-undownloaded-mark
6524                                          (gnus-data-mark (car data)))))
6525                            (if unseen
6526                                (or (not (memq
6527                                          (gnus-data-number (car data))
6528                                          gnus-newsgroup-unseen))
6529                                    (not (gnus-data-unread-p (car data))))
6530                              (not (gnus-data-unread-p (car data))))))
6531             (setq data (cdr data)))
6532           (when data
6533             (goto-char (gnus-data-pos (car data)))
6534             (gnus-data-number (car data))))))
6535     (gnus-summary-position-point)))
6536
6537 (defun gnus-summary-next-subject (n &optional unread dont-display)
6538   "Go to next N'th summary line.
6539 If N is negative, go to the previous N'th subject line.
6540 If UNREAD is non-nil, only unread articles are selected.
6541 The difference between N and the actual number of steps taken is
6542 returned."
6543   (interactive "p")
6544   (let ((backward (< n 0))
6545         (n (abs n)))
6546     (while (and (> n 0)
6547                 (if backward
6548                     (gnus-summary-find-prev unread)
6549                   (gnus-summary-find-next unread)))
6550       (unless (zerop (setq n (1- n)))
6551         (gnus-summary-show-thread)))
6552     (when (/= 0 n)
6553       (gnus-message 7 "No more%s articles"
6554                     (if unread " unread" "")))
6555     (unless dont-display
6556       (gnus-summary-recenter)
6557       (gnus-summary-position-point))
6558     n))
6559
6560 (defun gnus-summary-next-unread-subject (n)
6561   "Go to next N'th unread summary line."
6562   (interactive "p")
6563   (gnus-summary-next-subject n t))
6564
6565 (defun gnus-summary-prev-subject (n &optional unread)
6566   "Go to previous N'th summary line.
6567 If optional argument UNREAD is non-nil, only unread article is selected."
6568   (interactive "p")
6569   (gnus-summary-next-subject (- n) unread))
6570
6571 (defun gnus-summary-prev-unread-subject (n)
6572   "Go to previous N'th unread summary line."
6573   (interactive "p")
6574   (gnus-summary-next-subject (- n) t))
6575
6576 (defun gnus-summary-goto-subject (article &optional force silent)
6577   "Go the subject line of ARTICLE.
6578 If FORCE, also allow jumping to articles not currently shown."
6579   (interactive "nArticle number: ")
6580   (unless (numberp article)
6581     (error "Article %s is not a number" article))
6582   (let ((b (point))
6583         (data (gnus-data-find article)))
6584     ;; We read in the article if we have to.
6585     (and (not data)
6586          force
6587          (gnus-summary-insert-subject
6588           article
6589           (if (or (numberp force) (vectorp force)) force)
6590           t)
6591          (setq data (gnus-data-find article)))
6592     (goto-char b)
6593     (if (not data)
6594         (progn
6595           (unless silent
6596             (gnus-message 3 "Can't find article %d" article))
6597           nil)
6598       (let ((pt (gnus-data-pos data)))
6599         (goto-char pt)
6600         (gnus-summary-set-article-display-arrow pt))
6601       (gnus-summary-position-point)
6602       article)))
6603
6604 ;; Walking around summary lines with displaying articles.
6605
6606 (defun gnus-summary-expand-window (&optional arg)
6607   "Make the summary buffer take up the entire Emacs frame.
6608 Given a prefix, will force an `article' buffer configuration."
6609   (interactive "P")
6610   (if arg
6611       (gnus-configure-windows 'article 'force)
6612     (gnus-configure-windows 'summary 'force)))
6613
6614 (defun gnus-summary-display-article (article &optional all-header)
6615   "Display ARTICLE in article buffer."
6616   (when (gnus-buffer-live-p gnus-article-buffer)
6617     (with-current-buffer gnus-article-buffer
6618       (set-buffer-multibyte t)))
6619   (gnus-set-global-variables)
6620   (when (gnus-buffer-live-p gnus-article-buffer)
6621     (with-current-buffer gnus-article-buffer
6622       (setq gnus-article-charset gnus-newsgroup-charset)
6623       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6624       (set-buffer-multibyte t)))
6625   (if (null article)
6626       nil
6627     (prog1
6628         (if gnus-summary-display-article-function
6629             (funcall gnus-summary-display-article-function article all-header)
6630           (gnus-article-prepare article all-header))
6631       (with-current-buffer gnus-article-buffer
6632         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6633              nil))
6634       (gnus-run-hooks 'gnus-select-article-hook)
6635       (when (and gnus-current-article
6636                  (not (zerop gnus-current-article)))
6637         (gnus-summary-goto-subject gnus-current-article))
6638       (gnus-summary-recenter)
6639       (when (and gnus-use-trees gnus-show-threads)
6640         (gnus-possibly-generate-tree article)
6641         (gnus-highlight-selected-tree article))
6642       ;; Successfully display article.
6643       (gnus-article-set-window-start
6644        (cdr (assq article gnus-newsgroup-bookmarks))))))
6645
6646 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6647   "Select the current article.
6648 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6649 non-nil, the article will be re-fetched even if it already present in
6650 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6651 be displayed."
6652   ;; Make sure we are in the summary buffer to work around bbdb bug.
6653   (unless (eq major-mode 'gnus-summary-mode)
6654     (set-buffer gnus-summary-buffer))
6655   (let ((article (or article (gnus-summary-article-number)))
6656         (all-headers (not (not all-headers))) ;Must be T or NIL.
6657         gnus-summary-display-article-function)
6658     (and (not pseudo)
6659          (gnus-summary-article-pseudo-p article)
6660          (error "This is a pseudo-article"))
6661     (save-excursion
6662       (set-buffer gnus-summary-buffer)
6663       (if (or (and gnus-single-article-buffer
6664                    (or (null gnus-current-article)
6665                        (null gnus-article-current)
6666                        (null (get-buffer gnus-article-buffer))
6667                        (not (eq article (cdr gnus-article-current)))
6668                        (not (equal (car gnus-article-current)
6669                                    gnus-newsgroup-name))))
6670               (and (not gnus-single-article-buffer)
6671                    (or (null gnus-current-article)
6672                        (not (eq gnus-current-article article))))
6673               force)
6674           ;; The requested article is different from the current article.
6675           (progn
6676             (gnus-summary-display-article article all-headers)
6677             (gnus-article-set-window-start
6678              (cdr (assq article gnus-newsgroup-bookmarks)))
6679             article)
6680         'old))))
6681
6682 (defun gnus-summary-force-verify-and-decrypt ()
6683   (interactive)
6684   (let ((mm-verify-option 'known)
6685         (mm-decrypt-option 'known))
6686     (gnus-summary-select-article nil 'force)))
6687
6688 (defun gnus-summary-set-current-mark (&optional current-mark)
6689   "Obsolete function."
6690   nil)
6691
6692 (defun gnus-summary-next-article (&optional unread subject backward push)
6693   "Select the next article.
6694 If UNREAD, only unread articles are selected.
6695 If SUBJECT, only articles with SUBJECT are selected.
6696 If BACKWARD, the previous article is selected instead of the next."
6697   (interactive "P")
6698   (cond
6699    ;; Is there such an article?
6700    ((and (gnus-summary-search-forward unread subject backward)
6701          (or (gnus-summary-display-article (gnus-summary-article-number))
6702              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6703     (gnus-summary-position-point))
6704    ;; If not, we try the first unread, if that is wanted.
6705    ((and subject
6706          gnus-auto-select-same
6707          (gnus-summary-first-unread-article))
6708     (gnus-summary-position-point)
6709     (gnus-message 6 "Wrapped"))
6710    ;; Try to get next/previous article not displayed in this group.
6711    ((and gnus-auto-extend-newsgroup
6712          (not unread) (not subject))
6713     (gnus-summary-goto-article
6714      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6715      nil (count-lines (point-min) (point))))
6716    ;; Go to next/previous group.
6717    (t
6718     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6719       (gnus-summary-jump-to-group gnus-newsgroup-name))
6720     (let ((cmd last-command-char)
6721           (point
6722            (save-excursion
6723              (set-buffer gnus-group-buffer)
6724              (point)))
6725           (group
6726            (if (eq gnus-keep-same-level 'best)
6727                (gnus-summary-best-group gnus-newsgroup-name)
6728              (gnus-summary-search-group backward gnus-keep-same-level))))
6729       ;; For some reason, the group window gets selected.  We change
6730       ;; it back.
6731       (select-window (get-buffer-window (current-buffer)))
6732       ;; Select next unread newsgroup automagically.
6733       (cond
6734        ((or (not gnus-auto-select-next)
6735             (not cmd))
6736         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6737        ((or (eq gnus-auto-select-next 'quietly)
6738             (and (eq gnus-auto-select-next 'slightly-quietly)
6739                  push)
6740             (and (eq gnus-auto-select-next 'almost-quietly)
6741                  (gnus-summary-last-article-p)))
6742         ;; Select quietly.
6743         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6744             (gnus-summary-exit)
6745           (gnus-message 7 "No more%s articles (%s)..."
6746                         (if unread " unread" "")
6747                         (if group (concat "selecting " group)
6748                           "exiting"))
6749           (gnus-summary-next-group nil group backward)))
6750        (t
6751         (when (gnus-key-press-event-p last-input-event)
6752           (gnus-summary-walk-group-buffer
6753            gnus-newsgroup-name cmd unread backward point))))))))
6754
6755 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6756   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6757                       (?\C-p (gnus-group-prev-unread-group 1))))
6758         (cursor-in-echo-area t)
6759         keve key group ended)
6760     (save-excursion
6761       (set-buffer gnus-group-buffer)
6762       (goto-char start)
6763       (setq group
6764             (if (eq gnus-keep-same-level 'best)
6765                 (gnus-summary-best-group gnus-newsgroup-name)
6766               (gnus-summary-search-group backward gnus-keep-same-level))))
6767     (while (not ended)
6768       (gnus-message
6769        5 "No more%s articles%s" (if unread " unread" "")
6770        (if (and group
6771                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6772            (format " (Type %s for %s [%s])"
6773                    (single-key-description cmd) group
6774                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6775          (format " (Type %s to exit %s)"
6776                  (single-key-description cmd)
6777                  gnus-newsgroup-name)))
6778       ;; Confirm auto selection.
6779       (setq key (car (setq keve (gnus-read-event-char))))
6780       (setq ended t)
6781       (cond
6782        ((assq key keystrokes)
6783         (let ((obuf (current-buffer)))
6784           (switch-to-buffer gnus-group-buffer)
6785           (when group
6786             (gnus-group-jump-to-group group))
6787           (eval (cadr (assq key keystrokes)))
6788           (setq group (gnus-group-group-name))
6789           (switch-to-buffer obuf))
6790         (setq ended nil))
6791        ((equal key cmd)
6792         (if (or (not group)
6793                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6794             (gnus-summary-exit)
6795           (gnus-summary-next-group nil group backward)))
6796        (t
6797         (push (cdr keve) unread-command-events))))))
6798
6799 (defun gnus-summary-next-unread-article ()
6800   "Select unread article after current one."
6801   (interactive)
6802   (gnus-summary-next-article
6803    (or (not (eq gnus-summary-goto-unread 'never))
6804        (gnus-summary-last-article-p (gnus-summary-article-number)))
6805    (and gnus-auto-select-same
6806         (gnus-summary-article-subject))))
6807
6808 (defun gnus-summary-prev-article (&optional unread subject)
6809   "Select the article after the current one.
6810 If UNREAD is non-nil, only unread articles are selected."
6811   (interactive "P")
6812   (gnus-summary-next-article unread subject t))
6813
6814 (defun gnus-summary-prev-unread-article ()
6815   "Select unread article before current one."
6816   (interactive)
6817   (gnus-summary-prev-article
6818    (or (not (eq gnus-summary-goto-unread 'never))
6819        (gnus-summary-first-article-p (gnus-summary-article-number)))
6820    (and gnus-auto-select-same
6821         (gnus-summary-article-subject))))
6822
6823 (defun gnus-summary-next-page (&optional lines circular)
6824   "Show next page of the selected article.
6825 If at the end of the current article, select the next article.
6826 LINES says how many lines should be scrolled up.
6827
6828 If CIRCULAR is non-nil, go to the start of the article instead of
6829 selecting the next article when reaching the end of the current
6830 article."
6831   (interactive "P")
6832   (setq gnus-summary-buffer (current-buffer))
6833   (gnus-set-global-variables)
6834   (let ((article (gnus-summary-article-number))
6835         (article-window (get-buffer-window gnus-article-buffer t))
6836         endp)
6837     ;; If the buffer is empty, we have no article.
6838     (unless article
6839       (error "No article to select"))
6840     (gnus-configure-windows 'article)
6841     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6842         (if (and (eq gnus-summary-goto-unread 'never)
6843                  (not (gnus-summary-last-article-p article)))
6844             (gnus-summary-next-article)
6845           (gnus-summary-next-unread-article))
6846       (if (or (null gnus-current-article)
6847               (null gnus-article-current)
6848               (/= article (cdr gnus-article-current))
6849               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6850           ;; Selected subject is different from current article's.
6851           (gnus-summary-display-article article)
6852         (when article-window
6853           (gnus-eval-in-buffer-window gnus-article-buffer
6854             (setq endp (gnus-article-next-page lines)))
6855           (when endp
6856             (cond (circular
6857                    (gnus-summary-beginning-of-article))
6858                   (lines
6859                    (gnus-message 3 "End of message"))
6860                   ((null lines)
6861                    (if (and (eq gnus-summary-goto-unread 'never)
6862                             (not (gnus-summary-last-article-p article)))
6863                        (gnus-summary-next-article)
6864                      (gnus-summary-next-unread-article))))))))
6865     (gnus-summary-recenter)
6866     (gnus-summary-position-point)))
6867
6868 (defun gnus-summary-prev-page (&optional lines move)
6869   "Show previous page of selected article.
6870 Argument LINES specifies lines to be scrolled down.
6871 If MOVE, move to the previous unread article if point is at
6872 the beginning of the buffer."
6873   (interactive "P")
6874   (let ((article (gnus-summary-article-number))
6875         (article-window (get-buffer-window gnus-article-buffer t))
6876         endp)
6877     (gnus-configure-windows 'article)
6878     (if (or (null gnus-current-article)
6879             (null gnus-article-current)
6880             (/= article (cdr gnus-article-current))
6881             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6882         ;; Selected subject is different from current article's.
6883         (gnus-summary-display-article article)
6884       (gnus-summary-recenter)
6885       (when article-window
6886         (gnus-eval-in-buffer-window gnus-article-buffer
6887           (setq endp (gnus-article-prev-page lines)))
6888         (when (and move endp)
6889           (cond (lines
6890                  (gnus-message 3 "Beginning of message"))
6891                 ((null lines)
6892                  (if (and (eq gnus-summary-goto-unread 'never)
6893                           (not (gnus-summary-first-article-p article)))
6894                      (gnus-summary-prev-article)
6895                    (gnus-summary-prev-unread-article))))))))
6896   (gnus-summary-position-point))
6897
6898 (defun gnus-summary-prev-page-or-article (&optional lines)
6899   "Show previous page of selected article.
6900 Argument LINES specifies lines to be scrolled down.
6901 If at the beginning of the article, go to the next article."
6902   (interactive "P")
6903   (gnus-summary-prev-page lines t))
6904
6905 (defun gnus-summary-scroll-up (lines)
6906   "Scroll up (or down) one line current article.
6907 Argument LINES specifies lines to be scrolled up (or down if negative)."
6908   (interactive "p")
6909   (gnus-configure-windows 'article)
6910   (gnus-summary-show-thread)
6911   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6912     (gnus-eval-in-buffer-window gnus-article-buffer
6913       (cond ((> lines 0)
6914              (when (gnus-article-next-page lines)
6915                (gnus-message 3 "End of message")))
6916             ((< lines 0)
6917              (gnus-article-prev-page (- lines))))))
6918   (gnus-summary-recenter)
6919   (gnus-summary-position-point))
6920
6921 (defun gnus-summary-scroll-down (lines)
6922   "Scroll down (or up) one line current article.
6923 Argument LINES specifies lines to be scrolled down (or up if negative)."
6924   (interactive "p")
6925   (gnus-summary-scroll-up (- lines)))
6926
6927 (defun gnus-summary-next-same-subject ()
6928   "Select next article which has the same subject as current one."
6929   (interactive)
6930   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6931
6932 (defun gnus-summary-prev-same-subject ()
6933   "Select previous article which has the same subject as current one."
6934   (interactive)
6935   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6936
6937 (defun gnus-summary-next-unread-same-subject ()
6938   "Select next unread article which has the same subject as current one."
6939   (interactive)
6940   (gnus-summary-next-article t (gnus-summary-article-subject)))
6941
6942 (defun gnus-summary-prev-unread-same-subject ()
6943   "Select previous unread article which has the same subject as current one."
6944   (interactive)
6945   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6946
6947 (defun gnus-summary-first-unread-article ()
6948   "Select the first unread article.
6949 Return nil if there are no unread articles."
6950   (interactive)
6951   (prog1
6952       (when (gnus-summary-first-subject t)
6953         (gnus-summary-show-thread)
6954         (gnus-summary-first-subject t)
6955         (gnus-summary-display-article (gnus-summary-article-number)))
6956     (gnus-summary-position-point)))
6957
6958 (defun gnus-summary-first-unread-subject ()
6959   "Place the point on the subject line of the first unread article.
6960 Return nil if there are no unread articles."
6961   (interactive)
6962   (prog1
6963       (when (gnus-summary-first-subject t)
6964         (gnus-summary-show-thread)
6965         (gnus-summary-first-subject t))
6966     (gnus-summary-position-point)))
6967
6968 (defun gnus-summary-first-unseen-subject ()
6969   "Place the point on the subject line of the first unseen article.
6970 Return nil if there are no unseen articles."
6971   (interactive)
6972   (prog1
6973       (when (gnus-summary-first-subject t t t)
6974         (gnus-summary-show-thread)
6975         (gnus-summary-first-subject t t t))
6976     (gnus-summary-position-point)))
6977
6978 (defun gnus-summary-first-unseen-or-unread-subject ()
6979   "Place the point on the subject line of the first unseen article.
6980 Return nil if there are no unseen articles."
6981   (interactive)
6982   (prog1
6983       (unless (when (gnus-summary-first-subject t t t)
6984                 (gnus-summary-show-thread)
6985                 (gnus-summary-first-subject t t t))
6986         (when (gnus-summary-first-subject t)
6987           (gnus-summary-show-thread)
6988           (gnus-summary-first-subject t)))
6989     (gnus-summary-position-point)))
6990
6991 (defun gnus-summary-first-article ()
6992   "Select the first article.
6993 Return nil if there are no articles."
6994   (interactive)
6995   (prog1
6996       (when (gnus-summary-first-subject)
6997         (gnus-summary-show-thread)
6998         (gnus-summary-first-subject)
6999         (gnus-summary-display-article (gnus-summary-article-number)))
7000     (gnus-summary-position-point)))
7001
7002 (defun gnus-summary-best-unread-article (&optional arg)
7003   "Select the unread article with the highest score.
7004 If given a prefix argument, select the next unread article that has a
7005 score higher than the default score."
7006   (interactive "P")
7007   (let ((article (if arg
7008                      (gnus-summary-better-unread-subject)
7009                    (gnus-summary-best-unread-subject))))
7010     (if article
7011         (gnus-summary-goto-article article)
7012       (error "No unread articles"))))
7013
7014 (defun gnus-summary-best-unread-subject ()
7015   "Select the unread subject with the highest score."
7016   (interactive)
7017   (let ((best -1000000)
7018         (data gnus-newsgroup-data)
7019         article score)
7020     (while data
7021       (and (gnus-data-unread-p (car data))
7022            (> (setq score
7023                     (gnus-summary-article-score (gnus-data-number (car data))))
7024               best)
7025            (setq best score
7026                  article (gnus-data-number (car data))))
7027       (setq data (cdr data)))
7028     (when article
7029       (gnus-summary-goto-subject article))
7030     (gnus-summary-position-point)
7031     article))
7032
7033 (defun gnus-summary-better-unread-subject ()
7034   "Select the first unread subject that has a score over the default score."
7035   (interactive)
7036   (let ((data gnus-newsgroup-data)
7037         article score)
7038     (while (and (setq article (gnus-data-number (car data)))
7039                 (or (gnus-data-read-p (car data))
7040                     (not (> (gnus-summary-article-score article)
7041                             gnus-summary-default-score))))
7042       (setq data (cdr data)))
7043     (when article
7044       (gnus-summary-goto-subject article))
7045     (gnus-summary-position-point)
7046     article))
7047
7048 (defun gnus-summary-last-subject ()
7049   "Go to the last displayed subject line in the group."
7050   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7051     (when article
7052       (gnus-summary-goto-subject article))))
7053
7054 (defun gnus-summary-goto-article (article &optional all-headers force)
7055   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7056 If ALL-HEADERS is non-nil, no header lines are hidden.
7057 If FORCE, go to the article even if it isn't displayed.  If FORCE
7058 is a number, it is the line the article is to be displayed on."
7059   (interactive
7060    (list
7061     (completing-read
7062      "Article number or Message-ID: "
7063      (mapcar (lambda (number) (list (int-to-string number)))
7064              gnus-newsgroup-limit))
7065     current-prefix-arg
7066     t))
7067   (prog1
7068       (if (and (stringp article)
7069                (string-match "@" article))
7070           (gnus-summary-refer-article article)
7071         (when (stringp article)
7072           (setq article (string-to-number article)))
7073         (if (gnus-summary-goto-subject article force)
7074             (gnus-summary-display-article article all-headers)
7075           (gnus-message 4 "Couldn't go to article %s" article) nil))
7076     (gnus-summary-position-point)))
7077
7078 (defun gnus-summary-goto-last-article ()
7079   "Go to the previously read article."
7080   (interactive)
7081   (prog1
7082       (when gnus-last-article
7083         (gnus-summary-goto-article gnus-last-article nil t))
7084     (gnus-summary-position-point)))
7085
7086 (defun gnus-summary-pop-article (number)
7087   "Pop one article off the history and go to the previous.
7088 NUMBER articles will be popped off."
7089   (interactive "p")
7090   (let (to)
7091     (setq gnus-newsgroup-history
7092           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7093     (if to
7094         (gnus-summary-goto-article (car to) nil t)
7095       (error "Article history empty")))
7096   (gnus-summary-position-point))
7097
7098 ;; Summary commands and functions for limiting the summary buffer.
7099
7100 (defun gnus-summary-limit-to-articles (n)
7101   "Limit the summary buffer to the next N articles.
7102 If not given a prefix, use the process marked articles instead."
7103   (interactive "P")
7104   (prog1
7105       (let ((articles (gnus-summary-work-articles n)))
7106         (setq gnus-newsgroup-processable nil)
7107         (gnus-summary-limit articles))
7108     (gnus-summary-position-point)))
7109
7110 (defun gnus-summary-pop-limit (&optional total)
7111   "Restore the previous limit.
7112 If given a prefix, remove all limits."
7113   (interactive "P")
7114   (when total
7115     (setq gnus-newsgroup-limits
7116           (list (mapcar (lambda (h) (mail-header-number h))
7117                         gnus-newsgroup-headers))))
7118   (unless gnus-newsgroup-limits
7119     (error "No limit to pop"))
7120   (prog1
7121       (gnus-summary-limit nil 'pop)
7122     (gnus-summary-position-point)))
7123
7124 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7125   "Limit the summary buffer to articles that have subjects that match a regexp.
7126 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7127   (interactive
7128    (list (read-string (if current-prefix-arg
7129                           "Exclude subject (regexp): "
7130                         "Limit to subject (regexp): "))
7131          nil current-prefix-arg))
7132   (unless header
7133     (setq header "subject"))
7134   (when (not (equal "" subject))
7135     (prog1
7136         (let ((articles (gnus-summary-find-matching
7137                          (or header "subject") subject 'all nil nil
7138                          not-matching)))
7139           (unless articles
7140             (error "Found no matches for \"%s\"" subject))
7141           (gnus-summary-limit articles))
7142       (gnus-summary-position-point))))
7143
7144 (defun gnus-summary-limit-to-author (from &optional not-matching)
7145   "Limit the summary buffer to articles that have authors that match a regexp.
7146 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7147   (interactive
7148    (list (read-string (if current-prefix-arg
7149                           "Exclude author (regexp): "
7150                         "Limit to author (regexp): "))
7151          current-prefix-arg))
7152   (gnus-summary-limit-to-subject from "from" not-matching))
7153
7154 (defun gnus-summary-limit-to-age (age &optional younger-p)
7155   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7156 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7157 articles that are younger than AGE days."
7158   (interactive
7159    (let ((younger current-prefix-arg)
7160          (days-got nil)
7161          days)
7162      (while (not days-got)
7163        (setq days (if younger
7164                       (read-string "Limit to articles within (in days): ")
7165                     (read-string "Limit to articles older than (in days): ")))
7166        (when (> (length days) 0)
7167          (setq days (read days)))
7168        (if (numberp days)
7169            (progn
7170              (setq days-got t)
7171              (if (< days 0)
7172                  (progn
7173                    (setq younger (not younger))
7174                    (setq days (* days -1)))))
7175          (message "Please enter a number.")
7176          (sleep-for 1)))
7177      (list days younger)))
7178   (prog1
7179       (let ((data gnus-newsgroup-data)
7180             (cutoff (days-to-time age))
7181             articles d date is-younger)
7182         (while (setq d (pop data))
7183           (when (and (vectorp (gnus-data-header d))
7184                      (setq date (mail-header-date (gnus-data-header d))))
7185             (setq is-younger (time-less-p
7186                               (time-since (condition-case ()
7187                                               (date-to-time date)
7188                                             (error '(0 0))))
7189                               cutoff))
7190             (when (if younger-p
7191                       is-younger
7192                     (not is-younger))
7193               (push (gnus-data-number d) articles))))
7194         (gnus-summary-limit (nreverse articles)))
7195     (gnus-summary-position-point)))
7196
7197 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7198   "Limit the summary buffer to articles that match an 'extra' header."
7199   (interactive
7200    (let ((header
7201           (intern
7202            (gnus-completing-read-with-default
7203             (symbol-name (car gnus-extra-headers))
7204             (if current-prefix-arg
7205                 "Exclude extra header:"
7206               "Limit extra header:")
7207             (mapcar (lambda (x)
7208                       (cons (symbol-name x) x))
7209                     gnus-extra-headers)
7210             nil
7211             t))))
7212      (list header
7213            (read-string (format "%s header %s (regexp): "
7214                                 (if current-prefix-arg "Exclude" "Limit to")
7215                                 header))
7216            current-prefix-arg)))
7217   (when (not (equal "" regexp))
7218     (prog1
7219         (let ((articles (gnus-summary-find-matching
7220                          (cons 'extra header) regexp 'all nil nil
7221                          not-matching)))
7222           (unless articles
7223             (error "Found no matches for \"%s\"" regexp))
7224           (gnus-summary-limit articles))
7225       (gnus-summary-position-point))))
7226
7227 (defun gnus-summary-limit-to-display-predicate ()
7228   "Limit the summary buffer to the predicated in the `display' group parameter."
7229   (interactive)
7230   (unless gnus-newsgroup-display
7231     (error "There is no `display' group parameter"))
7232   (let (articles)
7233     (dolist (number gnus-newsgroup-articles)
7234       (when (funcall gnus-newsgroup-display)
7235         (push number articles)))
7236     (gnus-summary-limit articles))
7237   (gnus-summary-position-point))
7238
7239 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7240 (make-obsolete
7241  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7242
7243 (defun gnus-summary-limit-to-unread (&optional all)
7244   "Limit the summary buffer to articles that are not marked as read.
7245 If ALL is non-nil, limit strictly to unread articles."
7246   (interactive "P")
7247   (if all
7248       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7249     (gnus-summary-limit-to-marks
7250      ;; Concat all the marks that say that an article is read and have
7251      ;; those removed.
7252      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7253            gnus-killed-mark gnus-kill-file-mark
7254            gnus-low-score-mark gnus-expirable-mark
7255            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7256            gnus-duplicate-mark gnus-souped-mark)
7257      'reverse)))
7258
7259 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7260 (make-obsolete 'gnus-summary-delete-marked-with
7261                'gnus-summary-limit-exlude-marks)
7262
7263 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7264   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7265 If REVERSE, limit the summary buffer to articles that are marked
7266 with MARKS.  MARKS can either be a string of marks or a list of marks.
7267 Returns how many articles were removed."
7268   (interactive "sMarks: ")
7269   (gnus-summary-limit-to-marks marks t))
7270
7271 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7272   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7273 If REVERSE (the prefix), limit the summary buffer to articles that are
7274 not marked with MARKS.  MARKS can either be a string of marks or a
7275 list of marks.
7276 Returns how many articles were removed."
7277   (interactive "sMarks: \nP")
7278   (prog1
7279       (let ((data gnus-newsgroup-data)
7280             (marks (if (listp marks) marks
7281                      (append marks nil))) ; Transform to list.
7282             articles)
7283         (while data
7284           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7285                   (memq (gnus-data-mark (car data)) marks))
7286             (push (gnus-data-number (car data)) articles))
7287           (setq data (cdr data)))
7288         (gnus-summary-limit articles))
7289     (gnus-summary-position-point)))
7290
7291 (defun gnus-summary-limit-to-score (score)
7292   "Limit to articles with score at or above SCORE."
7293   (interactive "NLimit to articles with score of at least: ")
7294   (let ((data gnus-newsgroup-data)
7295         articles)
7296     (while data
7297       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7298                 score)
7299         (push (gnus-data-number (car data)) articles))
7300       (setq data (cdr data)))
7301     (prog1
7302         (gnus-summary-limit articles)
7303       (gnus-summary-position-point))))
7304
7305 (defun gnus-summary-limit-include-thread (id)
7306   "Display all the hidden articles that is in the thread with ID in it.
7307 When called interactively, ID is the Message-ID of the current
7308 article."
7309   (interactive (list (mail-header-id (gnus-summary-article-header))))
7310   (let ((articles (gnus-articles-in-thread
7311                    (gnus-id-to-thread (gnus-root-id id)))))
7312     (prog1
7313         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7314       (gnus-summary-limit-include-matching-articles
7315        "subject"
7316        (regexp-quote (gnus-simplify-subject-re
7317                       (mail-header-subject (gnus-id-to-header id)))))
7318       (gnus-summary-position-point))))
7319
7320 (defun gnus-summary-limit-include-matching-articles (header regexp)
7321   "Display all the hidden articles that have HEADERs that match REGEXP."
7322   (interactive (list (read-string "Match on header: ")
7323                      (read-string "Regexp: ")))
7324   (let ((articles (gnus-find-matching-articles header regexp)))
7325     (prog1
7326         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7327       (gnus-summary-position-point))))
7328
7329 (defun gnus-summary-limit-include-dormant ()
7330   "Display all the hidden articles that are marked as dormant.
7331 Note that this command only works on a subset of the articles currently
7332 fetched for this group."
7333   (interactive)
7334   (unless gnus-newsgroup-dormant
7335     (error "There are no dormant articles in this group"))
7336   (prog1
7337       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7338     (gnus-summary-position-point)))
7339
7340 (defun gnus-summary-limit-exclude-dormant ()
7341   "Hide all dormant articles."
7342   (interactive)
7343   (prog1
7344       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7345     (gnus-summary-position-point)))
7346
7347 (defun gnus-summary-limit-exclude-childless-dormant ()
7348   "Hide all dormant articles that have no children."
7349   (interactive)
7350   (let ((data (gnus-data-list t))
7351         articles d children)
7352     ;; Find all articles that are either not dormant or have
7353     ;; children.
7354     (while (setq d (pop data))
7355       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7356                 (and (setq children
7357                            (gnus-article-children (gnus-data-number d)))
7358                      (let (found)
7359                        (while children
7360                          (when (memq (car children) articles)
7361                            (setq children nil
7362                                  found t))
7363                          (pop children))
7364                        found)))
7365         (push (gnus-data-number d) articles)))
7366     ;; Do the limiting.
7367     (prog1
7368         (gnus-summary-limit articles)
7369       (gnus-summary-position-point))))
7370
7371 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7372   "Mark all unread excluded articles as read.
7373 If ALL, mark even excluded ticked and dormants as read."
7374   (interactive "P")
7375   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7376   (let ((articles (gnus-sorted-ndifference
7377                    (sort
7378                     (mapcar (lambda (h) (mail-header-number h))
7379                             gnus-newsgroup-headers)
7380                     '<)
7381                    gnus-newsgroup-limit))
7382         article)
7383     (setq gnus-newsgroup-unreads
7384           (gnus-sorted-intersection gnus-newsgroup-unreads
7385                                     gnus-newsgroup-limit))
7386     (if all
7387         (setq gnus-newsgroup-dormant nil
7388               gnus-newsgroup-marked nil
7389               gnus-newsgroup-reads
7390               (nconc
7391                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7392                gnus-newsgroup-reads))
7393       (while (setq article (pop articles))
7394         (unless (or (memq article gnus-newsgroup-dormant)
7395                     (memq article gnus-newsgroup-marked))
7396           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7397
7398 (defun gnus-summary-limit (articles &optional pop)
7399   (if pop
7400       ;; We pop the previous limit off the stack and use that.
7401       (setq articles (car gnus-newsgroup-limits)
7402             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7403     ;; We use the new limit, so we push the old limit on the stack.
7404     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7405   ;; Set the limit.
7406   (setq gnus-newsgroup-limit articles)
7407   (let ((total (length gnus-newsgroup-data))
7408         (data (gnus-data-find-list (gnus-summary-article-number)))
7409         (gnus-summary-mark-below nil)   ; Inhibit this.
7410         found)
7411     ;; This will do all the work of generating the new summary buffer
7412     ;; according to the new limit.
7413     (gnus-summary-prepare)
7414     ;; Hide any threads, possibly.
7415     (gnus-summary-maybe-hide-threads)
7416     ;; Try to return to the article you were at, or one in the
7417     ;; neighborhood.
7418     (when data
7419       ;; We try to find some article after the current one.
7420       (while data
7421         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7422           (setq data nil
7423                 found t))
7424         (setq data (cdr data))))
7425     (unless found
7426       ;; If there is no data, that means that we were after the last
7427       ;; article.  The same goes when we can't find any articles
7428       ;; after the current one.
7429       (goto-char (point-max))
7430       (gnus-summary-find-prev))
7431     (gnus-set-mode-line 'summary)
7432     ;; We return how many articles were removed from the summary
7433     ;; buffer as a result of the new limit.
7434     (- total (length gnus-newsgroup-data))))
7435
7436 (defsubst gnus-invisible-cut-children (threads)
7437   (let ((num 0))
7438     (while threads
7439       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7440         (incf num))
7441       (pop threads))
7442     (< num 2)))
7443
7444 (defsubst gnus-cut-thread (thread)
7445   "Go forwards in the thread until we find an article that we want to display."
7446   (when (or (eq gnus-fetch-old-headers 'some)
7447             (eq gnus-fetch-old-headers 'invisible)
7448             (numberp gnus-fetch-old-headers)
7449             (eq gnus-build-sparse-threads 'some)
7450             (eq gnus-build-sparse-threads 'more))
7451     ;; Deal with old-fetched headers and sparse threads.
7452     (while (and
7453             thread
7454             (or
7455              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7456              (gnus-summary-article-ancient-p
7457               (mail-header-number (car thread))))
7458             (if (or (<= (length (cdr thread)) 1)
7459                     (eq gnus-fetch-old-headers 'invisible))
7460                 (setq gnus-newsgroup-limit
7461                       (delq (mail-header-number (car thread))
7462                             gnus-newsgroup-limit)
7463                       thread (cadr thread))
7464               (when (gnus-invisible-cut-children (cdr thread))
7465                 (let ((th (cdr thread)))
7466                   (while th
7467                     (if (memq (mail-header-number (caar th))
7468                               gnus-newsgroup-limit)
7469                         (setq thread (car th)
7470                               th nil)
7471                       (setq th (cdr th))))))))))
7472   thread)
7473
7474 (defun gnus-cut-threads (threads)
7475   "Cut off all uninteresting articles from the beginning of threads."
7476   (when (or (eq gnus-fetch-old-headers 'some)
7477             (eq gnus-fetch-old-headers 'invisible)
7478             (numberp gnus-fetch-old-headers)
7479             (eq gnus-build-sparse-threads 'some)
7480             (eq gnus-build-sparse-threads 'more))
7481     (let ((th threads))
7482       (while th
7483         (setcar th (gnus-cut-thread (car th)))
7484         (setq th (cdr th)))))
7485   ;; Remove nixed out threads.
7486   (delq nil threads))
7487
7488 (defun gnus-summary-initial-limit (&optional show-if-empty)
7489   "Figure out what the initial limit is supposed to be on group entry.
7490 This entails weeding out unwanted dormants, low-scored articles,
7491 fetch-old-headers verbiage, and so on."
7492   ;; Most groups have nothing to remove.
7493   (if (or gnus-inhibit-limiting
7494           (and (null gnus-newsgroup-dormant)
7495                (eq gnus-newsgroup-display 'gnus-not-ignore)
7496                (not (eq gnus-fetch-old-headers 'some))
7497                (not (numberp gnus-fetch-old-headers))
7498                (not (eq gnus-fetch-old-headers 'invisible))
7499                (null gnus-summary-expunge-below)
7500                (not (eq gnus-build-sparse-threads 'some))
7501                (not (eq gnus-build-sparse-threads 'more))
7502                (null gnus-thread-expunge-below)
7503                (not gnus-use-nocem)))
7504       ()                                ; Do nothing.
7505     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7506     (setq gnus-newsgroup-limit nil)
7507     (mapatoms
7508      (lambda (node)
7509        (unless (car (symbol-value node))
7510          ;; These threads have no parents -- they are roots.
7511          (let ((nodes (cdr (symbol-value node)))
7512                thread)
7513            (while nodes
7514              (if (and gnus-thread-expunge-below
7515                       (< (gnus-thread-total-score (car nodes))
7516                          gnus-thread-expunge-below))
7517                  (gnus-expunge-thread (pop nodes))
7518                (setq thread (pop nodes))
7519                (gnus-summary-limit-children thread))))))
7520      gnus-newsgroup-dependencies)
7521     ;; If this limitation resulted in an empty group, we might
7522     ;; pop the previous limit and use it instead.
7523     (when (and (not gnus-newsgroup-limit)
7524                show-if-empty)
7525       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7526     gnus-newsgroup-limit))
7527
7528 (defun gnus-summary-limit-children (thread)
7529   "Return 1 if this subthread is visible and 0 if it is not."
7530   ;; First we get the number of visible children to this thread.  This
7531   ;; is done by recursing down the thread using this function, so this
7532   ;; will really go down to a leaf article first, before slowly
7533   ;; working its way up towards the root.
7534   (when thread
7535     (let ((children
7536            (if (cdr thread)
7537                (apply '+ (mapcar 'gnus-summary-limit-children
7538                                  (cdr thread)))
7539              0))
7540           (number (mail-header-number (car thread)))
7541           score)
7542       (if (and
7543            (not (memq number gnus-newsgroup-marked))
7544            (or
7545             ;; If this article is dormant and has absolutely no visible
7546             ;; children, then this article isn't visible.
7547             (and (memq number gnus-newsgroup-dormant)
7548                  (zerop children))
7549             ;; If this is "fetch-old-headered" and there is no
7550             ;; visible children, then we don't want this article.
7551             (and (or (eq gnus-fetch-old-headers 'some)
7552                      (numberp gnus-fetch-old-headers))
7553                  (gnus-summary-article-ancient-p number)
7554                  (zerop children))
7555             ;; If this is "fetch-old-headered" and `invisible', then
7556             ;; we don't want this article.
7557             (and (eq gnus-fetch-old-headers 'invisible)
7558                  (gnus-summary-article-ancient-p number))
7559             ;; If this is a sparsely inserted article with no children,
7560             ;; we don't want it.
7561             (and (eq gnus-build-sparse-threads 'some)
7562                  (gnus-summary-article-sparse-p number)
7563                  (zerop children))
7564             ;; If we use expunging, and this article is really
7565             ;; low-scored, then we don't want this article.
7566             (when (and gnus-summary-expunge-below
7567                        (< (setq score
7568                                 (or (cdr (assq number gnus-newsgroup-scored))
7569                                     gnus-summary-default-score))
7570                           gnus-summary-expunge-below))
7571               ;; We increase the expunge-tally here, but that has
7572               ;; nothing to do with the limits, really.
7573               (incf gnus-newsgroup-expunged-tally)
7574               ;; We also mark as read here, if that's wanted.
7575               (when (and gnus-summary-mark-below
7576                          (< score gnus-summary-mark-below))
7577                 (setq gnus-newsgroup-unreads
7578                       (delq number gnus-newsgroup-unreads))
7579                 (if gnus-newsgroup-auto-expire
7580                     (push number gnus-newsgroup-expirable)
7581                   (push (cons number gnus-low-score-mark)
7582                         gnus-newsgroup-reads)))
7583               t)
7584             ;; Do the `display' group parameter.
7585             (and gnus-newsgroup-display
7586                  (not (funcall gnus-newsgroup-display)))
7587             ;; Check NoCeM things.
7588             (if (and gnus-use-nocem
7589                      (gnus-nocem-unwanted-article-p
7590                       (mail-header-id (car thread))))
7591                 (progn
7592                   (setq gnus-newsgroup-unreads
7593                         (delq number gnus-newsgroup-unreads))
7594                   t))))
7595           ;; Nope, invisible article.
7596           0
7597         ;; Ok, this article is to be visible, so we add it to the limit
7598         ;; and return 1.
7599         (push number gnus-newsgroup-limit)
7600         1))))
7601
7602 (defun gnus-expunge-thread (thread)
7603   "Mark all articles in THREAD as read."
7604   (let* ((number (mail-header-number (car thread))))
7605     (incf gnus-newsgroup-expunged-tally)
7606     ;; We also mark as read here, if that's wanted.
7607     (setq gnus-newsgroup-unreads
7608           (delq number gnus-newsgroup-unreads))
7609     (if gnus-newsgroup-auto-expire
7610         (push number gnus-newsgroup-expirable)
7611       (push (cons number gnus-low-score-mark)
7612             gnus-newsgroup-reads)))
7613   ;; Go recursively through all subthreads.
7614   (mapcar 'gnus-expunge-thread (cdr thread)))
7615
7616 ;; Summary article oriented commands
7617
7618 (defun gnus-summary-refer-parent-article (n)
7619   "Refer parent article N times.
7620 If N is negative, go to ancestor -N instead.
7621 The difference between N and the number of articles fetched is returned."
7622   (interactive "p")
7623   (let ((skip 1)
7624         error header ref)
7625     (when (not (natnump n))
7626       (setq skip (abs n)
7627             n 1))
7628     (while (and (> n 0)
7629                 (not error))
7630       (setq header (gnus-summary-article-header))
7631       (if (and (eq (mail-header-number header)
7632                    (cdr gnus-article-current))
7633                (equal gnus-newsgroup-name
7634                       (car gnus-article-current)))
7635           ;; If we try to find the parent of the currently
7636           ;; displayed article, then we take a look at the actual
7637           ;; References header, since this is slightly more
7638           ;; reliable than the References field we got from the
7639           ;; server.
7640           (save-excursion
7641             (set-buffer gnus-original-article-buffer)
7642             (nnheader-narrow-to-headers)
7643             (unless (setq ref (message-fetch-field "references"))
7644               (setq ref (message-fetch-field "in-reply-to")))
7645             (widen))
7646         (setq ref
7647               ;; It's not the current article, so we take a bet on
7648               ;; the value we got from the server.
7649               (mail-header-references header)))
7650       (if (and ref
7651                (not (equal ref "")))
7652           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7653             (gnus-message 1 "Couldn't find parent"))
7654         (gnus-message 1 "No references in article %d"
7655                       (gnus-summary-article-number))
7656         (setq error t))
7657       (decf n))
7658     (gnus-summary-position-point)
7659     n))
7660
7661 (defun gnus-summary-refer-references ()
7662   "Fetch all articles mentioned in the References header.
7663 Return the number of articles fetched."
7664   (interactive)
7665   (let ((ref (mail-header-references (gnus-summary-article-header)))
7666         (current (gnus-summary-article-number))
7667         (n 0))
7668     (if (or (not ref)
7669             (equal ref ""))
7670         (error "No References in the current article")
7671       ;; For each Message-ID in the References header...
7672       (while (string-match "<[^>]*>" ref)
7673         (incf n)
7674         ;; ... fetch that article.
7675         (gnus-summary-refer-article
7676          (prog1 (match-string 0 ref)
7677            (setq ref (substring ref (match-end 0))))))
7678       (gnus-summary-goto-subject current)
7679       (gnus-summary-position-point)
7680       n)))
7681
7682 (defun gnus-summary-refer-thread (&optional limit)
7683   "Fetch all articles in the current thread.
7684 If LIMIT (the numerical prefix), fetch that many old headers instead
7685 of what's specified by the `gnus-refer-thread-limit' variable."
7686   (interactive "P")
7687   (let ((id (mail-header-id (gnus-summary-article-header)))
7688         (limit (if limit (prefix-numeric-value limit)
7689                  gnus-refer-thread-limit)))
7690     ;; We want to fetch LIMIT *old* headers, but we also have to
7691     ;; re-fetch all the headers in the current buffer, because many of
7692     ;; them may be undisplayed.  So we adjust LIMIT.
7693     (when (numberp limit)
7694       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7695     (unless (eq gnus-fetch-old-headers 'invisible)
7696       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7697       ;; Retrieve the headers and read them in.
7698       (if (eq (gnus-retrieve-headers
7699                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7700               'nov)
7701           (gnus-build-all-threads)
7702         (error "Can't fetch thread from backends that don't support NOV"))
7703       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7704     (gnus-summary-limit-include-thread id)))
7705
7706 (defun gnus-summary-refer-article (message-id)
7707   "Fetch an article specified by MESSAGE-ID."
7708   (interactive "sMessage-ID: ")
7709   (when (and (stringp message-id)
7710              (not (zerop (length message-id))))
7711     ;; Construct the correct Message-ID if necessary.
7712     ;; Suggested by tale@pawl.rpi.edu.
7713     (unless (string-match "^<" message-id)
7714       (setq message-id (concat "<" message-id)))
7715     (unless (string-match ">$" message-id)
7716       (setq message-id (concat message-id ">")))
7717     (let* ((header (gnus-id-to-header message-id))
7718            (sparse (and header
7719                         (gnus-summary-article-sparse-p
7720                          (mail-header-number header))
7721                         (memq (mail-header-number header)
7722                               gnus-newsgroup-limit)))
7723            number)
7724       (cond
7725        ;; If the article is present in the buffer we just go to it.
7726        ((and header
7727              (or (not (gnus-summary-article-sparse-p
7728                        (mail-header-number header)))
7729                  sparse))
7730         (prog1
7731             (gnus-summary-goto-article
7732              (mail-header-number header) nil t)
7733           (when sparse
7734             (gnus-summary-update-article (mail-header-number header)))))
7735        (t
7736         ;; We fetch the article.
7737         (catch 'found
7738           (dolist (gnus-override-method (gnus-refer-article-methods))
7739             (gnus-check-server gnus-override-method)
7740             ;; Fetch the header, and display the article.
7741             (when (setq number (gnus-summary-insert-subject message-id))
7742               (gnus-summary-select-article nil nil nil number)
7743               (throw 'found t)))
7744           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7745
7746 (defun gnus-refer-article-methods ()
7747   "Return a list of referrable methods."
7748   (cond
7749    ;; No method, so we default to current and native.
7750    ((null gnus-refer-article-method)
7751     (list gnus-current-select-method gnus-select-method))
7752    ;; Current.
7753    ((eq 'current gnus-refer-article-method)
7754     (list gnus-current-select-method))
7755    ;; List of select methods.
7756    ((not (and (symbolp (car gnus-refer-article-method))
7757               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7758     (let (out)
7759       (dolist (method gnus-refer-article-method)
7760         (push (if (eq 'current method)
7761                   gnus-current-select-method
7762                 method)
7763               out))
7764       (nreverse out)))
7765    ;; One single select method.
7766    (t
7767     (list gnus-refer-article-method))))
7768
7769 (defun gnus-summary-edit-parameters ()
7770   "Edit the group parameters of the current group."
7771   (interactive)
7772   (gnus-group-edit-group gnus-newsgroup-name 'params))
7773
7774 (defun gnus-summary-customize-parameters ()
7775   "Customize the group parameters of the current group."
7776   (interactive)
7777   (gnus-group-customize gnus-newsgroup-name))
7778
7779 (defun gnus-summary-enter-digest-group (&optional force)
7780   "Enter an nndoc group based on the current article.
7781 If FORCE, force a digest interpretation.  If not, try
7782 to guess what the document format is."
7783   (interactive "P")
7784   (let ((conf gnus-current-window-configuration))
7785     (save-excursion
7786       (gnus-summary-select-article))
7787     (setq gnus-current-window-configuration conf)
7788     (let* ((name (format "%s-%d"
7789                          (gnus-group-prefixed-name
7790                           gnus-newsgroup-name (list 'nndoc ""))
7791                          (save-excursion
7792                            (set-buffer gnus-summary-buffer)
7793                            gnus-current-article)))
7794            (ogroup gnus-newsgroup-name)
7795            (params (append (gnus-info-params (gnus-get-info ogroup))
7796                            (list (cons 'to-group ogroup))
7797                            (list (cons 'save-article-group ogroup))))
7798            (case-fold-search t)
7799            (buf (current-buffer))
7800            dig to-address)
7801       (save-excursion
7802         (set-buffer gnus-original-article-buffer)
7803         ;; Have the digest group inherit the main mail address of
7804         ;; the parent article.
7805         (when (setq to-address (or (message-fetch-field "reply-to")
7806                                    (message-fetch-field "from")))
7807           (setq params (append
7808                         (list (cons 'to-address
7809                                     (funcall gnus-decode-encoded-word-function
7810                                              to-address))))))
7811         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7812         (insert-buffer-substring gnus-original-article-buffer)
7813         ;; Remove lines that may lead nndoc to misinterpret the
7814         ;; document type.
7815         (narrow-to-region
7816          (goto-char (point-min))
7817          (or (search-forward "\n\n" nil t) (point)))
7818         (goto-char (point-min))
7819         (delete-matching-lines "^Path:\\|^From ")
7820         (widen))
7821       (unwind-protect
7822           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7823                     (gnus-newsgroup-ephemeral-ignored-charsets
7824                      gnus-newsgroup-ignored-charsets))
7825                 (gnus-group-read-ephemeral-group
7826                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7827                               (nndoc-article-type
7828                                ,(if force 'mbox 'guess)))
7829                  t nil nil nil
7830                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7831                                                         "ADAPT")))))
7832               ;; Make all postings to this group go to the parent group.
7833               (nconc (gnus-info-params (gnus-get-info name))
7834                      params)
7835             ;; Couldn't select this doc group.
7836             (switch-to-buffer buf)
7837             (gnus-set-global-variables)
7838             (gnus-configure-windows 'summary)
7839             (gnus-message 3 "Article couldn't be entered?"))
7840         (kill-buffer dig)))))
7841
7842 (defun gnus-summary-read-document (n)
7843   "Open a new group based on the current article(s).
7844 This will allow you to read digests and other similar
7845 documents as newsgroups.
7846 Obeys the standard process/prefix convention."
7847   (interactive "P")
7848   (let* ((articles (gnus-summary-work-articles n))
7849          (ogroup gnus-newsgroup-name)
7850          (params (append (gnus-info-params (gnus-get-info ogroup))
7851                          (list (cons 'to-group ogroup))))
7852          article group egroup groups vgroup)
7853     (while (setq article (pop articles))
7854       (setq group (format "%s-%d" gnus-newsgroup-name article))
7855       (gnus-summary-remove-process-mark article)
7856       (when (gnus-summary-display-article article)
7857         (save-excursion
7858           (with-temp-buffer
7859             (insert-buffer-substring gnus-original-article-buffer)
7860             ;; Remove some headers that may lead nndoc to make
7861             ;; the wrong guess.
7862             (message-narrow-to-head)
7863             (goto-char (point-min))
7864             (delete-matching-lines "^\\(Path\\):\\|^From ")
7865             (widen)
7866             (if (setq egroup
7867                       (gnus-group-read-ephemeral-group
7868                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7869                                      (nndoc-article-type guess))
7870                        t nil t))
7871                 (progn
7872                   ;; Make all postings to this group go to the parent group.
7873                   (nconc (gnus-info-params (gnus-get-info egroup))
7874                          params)
7875                   (push egroup groups))
7876               ;; Couldn't select this doc group.
7877               (gnus-error 3 "Article couldn't be entered"))))))
7878     ;; Now we have selected all the documents.
7879     (cond
7880      ((not groups)
7881       (error "None of the articles could be interpreted as documents"))
7882      ((gnus-group-read-ephemeral-group
7883        (setq vgroup (format
7884                      "nnvirtual:%s-%s" gnus-newsgroup-name
7885                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7886        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7887        t
7888        (cons (current-buffer) 'summary)))
7889      (t
7890       (error "Couldn't select virtual nndoc group")))))
7891
7892 (defun gnus-summary-isearch-article (&optional regexp-p)
7893   "Do incremental search forward on the current article.
7894 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7895   (interactive "P")
7896   (let* ((gnus-inhibit-treatment t)
7897          (old (gnus-summary-select-article)))
7898     (gnus-configure-windows 'article)
7899     (gnus-eval-in-buffer-window gnus-article-buffer
7900       (save-restriction
7901         (widen)
7902         (when (eq 'old old)
7903           (gnus-article-show-all-headers))
7904         (goto-char (point-min))
7905         (isearch-forward regexp-p)))))
7906
7907 (defun gnus-summary-search-article-forward (regexp &optional backward)
7908   "Search for an article containing REGEXP forward.
7909 If BACKWARD, search backward instead."
7910   (interactive
7911    (list (read-string
7912           (format "Search article %s (regexp%s): "
7913                   (if current-prefix-arg "backward" "forward")
7914                   (if gnus-last-search-regexp
7915                       (concat ", default " gnus-last-search-regexp)
7916                     "")))
7917          current-prefix-arg))
7918   (if (string-equal regexp "")
7919       (setq regexp (or gnus-last-search-regexp ""))
7920     (setq gnus-last-search-regexp regexp)
7921     (setq gnus-article-before-search gnus-current-article))
7922   ;; Intentionally set gnus-last-article.
7923   (setq gnus-last-article gnus-article-before-search)
7924   (let ((gnus-last-article gnus-last-article))
7925     (if (gnus-summary-search-article regexp backward)
7926         (gnus-summary-show-thread)
7927       (error "Search failed: \"%s\"" regexp))))
7928
7929 (defun gnus-summary-search-article-backward (regexp)
7930   "Search for an article containing REGEXP backward."
7931   (interactive
7932    (list (read-string
7933           (format "Search article backward (regexp%s): "
7934                   (if gnus-last-search-regexp
7935                       (concat ", default " gnus-last-search-regexp)
7936                     "")))))
7937   (gnus-summary-search-article-forward regexp 'backward))
7938
7939 (eval-when-compile
7940   (defmacro gnus-summary-search-article-position-point (regexp backward)
7941     "Dehighlight the last matched text and goto the beginning position."
7942     (` (if (and gnus-summary-search-article-matched-data
7943                 (let ((text (caddr gnus-summary-search-article-matched-data))
7944                       (inhibit-read-only t)
7945                       buffer-read-only)
7946                   (delete-region
7947                    (goto-char (car gnus-summary-search-article-matched-data))
7948                    (cadr gnus-summary-search-article-matched-data))
7949                   (insert text)
7950                   (string-match (, regexp) text)))
7951            (if (, backward) (beginning-of-line) (end-of-line))
7952          (goto-char (if (, backward) (point-max) (point-min))))))
7953
7954   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7955     "Place point where X-Face image is displayed."
7956     (if (featurep 'xemacs)
7957         (` (let ((end (if (search-forward "\n\n" nil t)
7958                           (goto-char (1- (point)))
7959                         (point-min)))
7960                  extent)
7961              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7962              (unless (and (re-search-forward "^From:" end t)
7963                           (setq extent (extent-at (point)))
7964                           (extent-begin-glyph extent))
7965                (goto-char (, opoint)))))
7966       (` (let ((end (if (search-forward "\n\n" nil t)
7967                         (goto-char (1- (point)))
7968                       (point-min)))
7969                (start (or (search-backward "\n\n" nil t) (point-min))))
7970            (goto-char
7971             (or (text-property-any start end 'x-face-image t);; x-face-e21
7972                 (text-property-any start end 'x-face-mule-bitmap-image t)
7973                 (, opoint)))))))
7974
7975   (defmacro gnus-summary-search-article-highlight-matched-text
7976     (backward treated x-face)
7977     "Highlight matched text in the function `gnus-summary-search-article'."
7978     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7979              (end (set-marker (make-marker) (match-end 0)))
7980              (inhibit-read-only t)
7981              buffer-read-only)
7982          (unless treated
7983            (let ((,@
7984                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7985                     (mapcar
7986                      (lambda (item) (setq items (delq item items)))
7987                      '(gnus-treat-buttonize
7988                        gnus-treat-fill-article
7989                        gnus-treat-fill-long-lines
7990                        gnus-treat-emphasize
7991                        gnus-treat-highlight-headers
7992                        gnus-treat-highlight-citation
7993                        gnus-treat-highlight-signature
7994                        gnus-treat-overstrike
7995                        gnus-treat-display-xface
7996                        gnus-treat-buttonize-head
7997                        gnus-treat-decode-article-as-default-mime-charset))
7998                     (static-if (featurep 'xemacs)
7999                         items
8000                       (cons '(x-face-mule-delete-x-face-field
8001                               (quote never))
8002                             items))))
8003                  (gnus-treat-display-xface
8004                   (when (, x-face) gnus-treat-display-xface)))
8005              (gnus-article-prepare-mime-display)))
8006          (goto-char (if (, backward) start end))
8007          (when (, x-face)
8008            (gnus-summary-search-article-highlight-goto-x-face (point)))
8009          (setq gnus-summary-search-article-matched-data
8010                (list start end (buffer-substring start end)))
8011          (unless (eq start end);; matched text has been deleted. :-<
8012            (put-text-property start end 'face
8013                               (or (find-face 'isearch)
8014                                   'secondary-selection))))))
8015   )
8016
8017 (defun gnus-summary-search-article (regexp &optional backward)
8018   "Search for an article containing REGEXP.
8019 Optional argument BACKWARD means do search for backward.
8020 `gnus-select-article-hook' is not called during the search."
8021   ;; We have to require this here to make sure that the following
8022   ;; dynamic binding isn't shadowed by autoloading.
8023   (require 'gnus-async)
8024   (require 'gnus-art)
8025   (let ((gnus-select-article-hook nil)  ;Disable hook.
8026         (gnus-article-prepare-hook nil)
8027         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8028         (gnus-use-article-prefetch nil)
8029         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8030         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8031         (sum (current-buffer))
8032         (found nil)
8033         point treated)
8034     (gnus-save-hidden-threads
8035       (static-if (featurep 'xemacs)
8036           (let ((gnus-inhibit-treatment t))
8037             (setq treated (eq 'old (gnus-summary-select-article)))
8038             (when (and treated
8039                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8040                                  (window-live-p (get-buffer-window
8041                                                  gnus-article-buffer t)))))
8042               (gnus-summary-select-article nil t)
8043               (setq treated nil)))
8044         (let ((gnus-inhibit-treatment t)
8045               (x-face-mule-delete-x-face-field 'never))
8046           (setq treated (eq 'old (gnus-summary-select-article)))
8047           (when (and treated
8048                      (not
8049                       (and (gnus-buffer-live-p gnus-article-buffer)
8050                            (window-live-p (get-buffer-window
8051                                            gnus-article-buffer t))
8052                            (or (not (string-match "^\\^X-Face:" regexp))
8053                                (with-current-buffer gnus-article-buffer
8054                                  gnus-summary-search-article-matched-data)))))
8055             (gnus-summary-select-article nil t)
8056             (setq treated nil))))
8057       (set-buffer gnus-article-buffer)
8058       (widen)
8059       (if treated
8060           (progn
8061             (gnus-article-show-all-headers)
8062             (gnus-summary-search-article-position-point regexp backward))
8063         (goto-char (if backward (point-max) (point-min))))
8064       (while (not found)
8065         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8066         (if (if backward
8067                 (re-search-backward regexp nil t)
8068               (re-search-forward regexp nil t))
8069             ;; We found the regexp.
8070             (progn
8071               (gnus-summary-search-article-highlight-matched-text
8072                backward treated (string-match "^\\^X-Face:" regexp))
8073               (setq found 'found)
8074               (forward-line
8075                (/ (- 2 (window-height
8076                         (get-buffer-window gnus-article-buffer t)))
8077                   2))
8078               (set-window-start
8079                (get-buffer-window (current-buffer))
8080                (point))
8081               (set-buffer sum)
8082               (setq point (point)))
8083           ;; We didn't find it, so we go to the next article.
8084           (set-buffer sum)
8085           (setq found 'not)
8086           (while (eq found 'not)
8087             (if (not (if backward (gnus-summary-find-prev)
8088                        (gnus-summary-find-next)))
8089                 ;; No more articles.
8090                 (setq found t)
8091               ;; Select the next article and adjust point.
8092               (unless (gnus-summary-article-sparse-p
8093                        (gnus-summary-article-number))
8094                 (setq found nil)
8095                 (let ((gnus-inhibit-treatment t))
8096                   (gnus-summary-select-article))
8097                 (setq treated nil)
8098                 (set-buffer gnus-article-buffer)
8099                 (widen)
8100                 (goto-char (if backward (point-max) (point-min))))))))
8101       (gnus-message 7 ""))
8102     ;; Return whether we found the regexp.
8103     (when (eq found 'found)
8104       (goto-char point)
8105       (gnus-summary-show-thread)
8106       (gnus-summary-goto-subject gnus-current-article)
8107       (gnus-summary-position-point)
8108       t)))
8109
8110 (defun gnus-find-matching-articles (header regexp)
8111   "Return a list of all articles that match REGEXP on HEADER.
8112 This search includes all articles in the current group that Gnus has
8113 fetched headers for, whether they are displayed or not."
8114   (let ((articles nil)
8115         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8116         (case-fold-search t))
8117     (dolist (header gnus-newsgroup-headers)
8118       (when (string-match regexp (funcall func header))
8119         (push (mail-header-number header) articles)))
8120     (nreverse articles)))
8121
8122 (defun gnus-summary-find-matching (header regexp &optional backward unread
8123                                           not-case-fold not-matching)
8124   "Return a list of all articles that match REGEXP on HEADER.
8125 The search stars on the current article and goes forwards unless
8126 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8127 If UNREAD is non-nil, only unread articles will
8128 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8129 in the comparisons. If NOT-MATCHING, return a list of all articles that
8130 not match REGEXP on HEADER."
8131   (let ((case-fold-search (not not-case-fold))
8132         articles d func)
8133     (if (consp header)
8134         (if (eq (car header) 'extra)
8135             (setq func
8136                   `(lambda (h)
8137                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8138                          "")))
8139           (error "%s is an invalid header" header))
8140       (unless (fboundp (intern (concat "mail-header-" header)))
8141         (error "%s is not a valid header" header))
8142       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8143     (dolist (d (if (eq backward 'all)
8144                    gnus-newsgroup-data
8145                  (gnus-data-find-list
8146                   (gnus-summary-article-number)
8147                   (gnus-data-list backward))))
8148       (when (and (or (not unread)       ; We want all articles...
8149                      (gnus-data-unread-p d)) ; Or just unreads.
8150                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8151                  (if not-matching
8152                      (not (string-match
8153                            regexp
8154                            (funcall func (gnus-data-header d))))
8155                    (string-match regexp
8156                                  (funcall func (gnus-data-header d)))))
8157         (push (gnus-data-number d) articles))) ; Success!
8158     (nreverse articles)))
8159
8160 (defun gnus-summary-execute-command (header regexp command &optional backward)
8161   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8162 If HEADER is an empty string (or nil), the match is done on the entire
8163 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8164   (interactive
8165    (list (let ((completion-ignore-case t))
8166            (completing-read
8167             "Header name: "
8168             (mapcar (lambda (header) (list (format "%s" header)))
8169                     (append
8170                      '("Number" "Subject" "From" "Lines" "Date"
8171                        "Message-ID" "Xref" "References" "Body")
8172                      gnus-extra-headers))
8173             nil 'require-match))
8174          (read-string "Regexp: ")
8175          (read-key-sequence "Command: ")
8176          current-prefix-arg))
8177   (when (equal header "Body")
8178     (setq header ""))
8179   ;; Hidden thread subtrees must be searched as well.
8180   (gnus-summary-show-all-threads)
8181   ;; We don't want to change current point nor window configuration.
8182   (save-excursion
8183     (save-window-excursion
8184       (gnus-message 6 "Executing %s..." (key-description command))
8185       ;; We'd like to execute COMMAND interactively so as to give arguments.
8186       (gnus-execute header regexp
8187                     `(call-interactively ',(key-binding command))
8188                     backward)
8189       (gnus-message 6 "Executing %s...done" (key-description command)))))
8190
8191 (defun gnus-summary-beginning-of-article ()
8192   "Scroll the article back to the beginning."
8193   (interactive)
8194   (gnus-summary-select-article)
8195   (gnus-configure-windows 'article)
8196   (gnus-eval-in-buffer-window gnus-article-buffer
8197     (widen)
8198     (goto-char (point-min))
8199     (when gnus-page-broken
8200       (gnus-narrow-to-page))))
8201
8202 (defun gnus-summary-end-of-article ()
8203   "Scroll to the end of the article."
8204   (interactive)
8205   (gnus-summary-select-article)
8206   (gnus-configure-windows 'article)
8207   (gnus-eval-in-buffer-window gnus-article-buffer
8208     (widen)
8209     (goto-char (point-max))
8210     (recenter -3)
8211     (when gnus-page-broken
8212       (gnus-narrow-to-page))))
8213
8214 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8215   "Truncate to LEN and quote all \"(\"'s in STRING."
8216   (gnus-replace-in-string (if (and len (> (length string) len))
8217                               (substring string 0 len)
8218                             string)
8219                           "[()]" "\\\\\\&"))
8220
8221 (defun gnus-summary-print-article (&optional filename n)
8222   "Generate and print a PostScript image of the N next (mail) articles.
8223
8224 If N is negative, print the N previous articles.  If N is nil and articles
8225 have been marked with the process mark, print these instead.
8226
8227 If the optional first argument FILENAME is nil, send the image to the
8228 printer.  If FILENAME is a string, save the PostScript image in a file with
8229 that name.  If FILENAME is a number, prompt the user for the name of the file
8230 to save in."
8231   (interactive (list (ps-print-preprint current-prefix-arg)))
8232   (dolist (article (gnus-summary-work-articles n))
8233     (gnus-summary-select-article nil nil 'pseudo article)
8234     (gnus-eval-in-buffer-window gnus-article-buffer
8235       (gnus-print-buffer))
8236     (gnus-summary-remove-process-mark article))
8237   (ps-despool filename))
8238
8239 (defun gnus-print-buffer ()
8240   (let ((buffer (generate-new-buffer " *print*")))
8241     (unwind-protect
8242         (progn
8243           (copy-to-buffer buffer (point-min) (point-max))
8244           (set-buffer buffer)
8245           (gnus-article-delete-invisible-text)
8246           (when (gnus-visual-p 'article-highlight 'highlight)
8247             ;; Copy-to-buffer doesn't copy overlay.  So redo
8248             ;; highlight.
8249             (let ((gnus-article-buffer buffer))
8250               (gnus-article-highlight-citation t)
8251               (gnus-article-highlight-signature)))
8252           (let ((ps-left-header
8253                  (list
8254                   (concat "("
8255                           (gnus-summary-print-truncate-and-quote
8256                            (mail-header-subject gnus-current-headers)
8257                            66) ")")
8258                   (concat "("
8259                           (gnus-summary-print-truncate-and-quote
8260                            (mail-header-from gnus-current-headers)
8261                            45) ")")))
8262                 (ps-right-header
8263                  (list
8264                   "/pagenumberstring load"
8265                   (concat "("
8266                           (mail-header-date gnus-current-headers) ")"))))
8267             (gnus-run-hooks 'gnus-ps-print-hook)
8268             (save-excursion
8269               (if window-system
8270                   (ps-spool-buffer-with-faces)
8271                 (ps-spool-buffer)))))
8272       (kill-buffer buffer))))
8273
8274 (defun gnus-summary-show-article (&optional arg)
8275   "Force redisplaying of the current article.
8276 If ARG (the prefix) is a number, show the article with the charset
8277 defined in `gnus-summary-show-article-charset-alist', or the charset
8278 input.
8279 If ARG (the prefix) is non-nil and not a number, show the raw article
8280 without any article massaging functions being run.  Normally, the key strokes
8281 are `C-u g'."
8282   (interactive "P")
8283   (cond
8284    ((numberp arg)
8285     (gnus-summary-show-article t)
8286     (let* ((gnus-newsgroup-charset
8287             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8288                 (mm-read-coding-system
8289                  "View as charset: " ;; actually it is coding system.
8290                  (save-excursion
8291                    (set-buffer gnus-article-buffer)
8292                    (mm-detect-coding-region (point) (point-max))))))
8293            (default-mime-charset gnus-newsgroup-charset)
8294            (gnus-newsgroup-ignored-charsets 'gnus-all))
8295       (gnus-summary-select-article nil 'force)
8296       (let ((deps gnus-newsgroup-dependencies)
8297             head header lines)
8298         (save-excursion
8299           (set-buffer gnus-original-article-buffer)
8300           (save-restriction
8301             (message-narrow-to-head)
8302             (setq head (buffer-string))
8303             (goto-char (point-min))
8304             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8305               (goto-char (point-max))
8306               (widen)
8307               (setq lines (1- (count-lines (point) (point-max))))))
8308           (with-temp-buffer
8309             (insert (format "211 %d Article retrieved.\n"
8310                             (cdr gnus-article-current)))
8311             (insert head)
8312             (if lines (insert (format "Lines: %d\n" lines)))
8313             (insert ".\n")
8314             (let ((nntp-server-buffer (current-buffer)))
8315               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8316         (gnus-data-set-header
8317          (gnus-data-find (cdr gnus-article-current))
8318          header)
8319         (gnus-summary-update-article-line
8320          (cdr gnus-article-current) header)
8321         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8322           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8323    ((not arg)
8324     ;; Select the article the normal way.
8325     (gnus-summary-select-article nil 'force))
8326    (t
8327     ;; We have to require this here to make sure that the following
8328     ;; dynamic binding isn't shadowed by autoloading.
8329     (require 'gnus-async)
8330     (require 'gnus-art)
8331     ;; Bind the article treatment functions to nil.
8332     (let ((gnus-have-all-headers t)
8333           gnus-article-prepare-hook
8334           gnus-article-decode-hook
8335           gnus-break-pages
8336           gnus-show-mime
8337           (gnus-inhibit-treatment t))
8338       (gnus-summary-select-article nil 'force))))
8339   (gnus-summary-goto-subject gnus-current-article)
8340   (gnus-summary-position-point))
8341
8342 (defun gnus-summary-show-raw-article ()
8343   "Show the raw article without any article massaging functions being run."
8344   (interactive)
8345   (gnus-summary-show-article t))
8346
8347 (defun gnus-summary-verbose-headers (&optional arg)
8348   "Toggle permanent full header display.
8349 If ARG is a positive number, turn header display on.
8350 If ARG is a negative number, turn header display off."
8351   (interactive "P")
8352   (setq gnus-show-all-headers
8353         (cond ((or (not (numberp arg))
8354                    (zerop arg))
8355                (not gnus-show-all-headers))
8356               ((natnump arg)
8357                t)))
8358   (gnus-summary-show-article))
8359
8360 (defun gnus-summary-toggle-header (&optional arg)
8361   "Show the headers if they are hidden, or hide them if they are shown.
8362 If ARG is a positive number, show the entire header.
8363 If ARG is a negative number, hide the unwanted header lines."
8364   (interactive "P")
8365   (save-excursion
8366     (set-buffer gnus-article-buffer)
8367     (save-restriction
8368       (let* ((buffer-read-only nil)
8369              (inhibit-point-motion-hooks t)
8370              hidden e)
8371         (save-restriction
8372           (article-narrow-to-head)
8373           (setq e (point-max)
8374                 hidden (if (numberp arg)
8375                            (>= arg 0)
8376                          (gnus-article-hidden-text-p 'headers))))
8377         (delete-region (point-min) e)
8378         (goto-char (point-min))
8379         (save-excursion
8380           (set-buffer gnus-original-article-buffer)
8381           (goto-char (point-min))
8382           (setq e (search-forward "\n\n" nil t)
8383                 e (if e (1- e) (point-max))))
8384         (insert-buffer-substring gnus-original-article-buffer 1 e)
8385         (save-restriction
8386           (narrow-to-region (point-min) (point))
8387           (article-decode-encoded-words)
8388           (if  hidden
8389               (let ((gnus-treat-hide-headers nil)
8390                     (gnus-treat-hide-boring-headers nil))
8391                 (gnus-delete-wash-type 'headers)
8392                 (gnus-treat-article 'head))
8393             (gnus-treat-article 'head)))
8394         (gnus-set-mode-line 'article)))))
8395
8396 (defun gnus-summary-show-all-headers ()
8397   "Make all header lines visible."
8398   (interactive)
8399   (gnus-summary-toggle-header 1))
8400
8401 (defun gnus-summary-toggle-mime (&optional arg)
8402   "Toggle MIME processing.
8403 If ARG is a positive number, turn MIME processing on."
8404   (interactive "P")
8405   (setq gnus-show-mime
8406         (if (null arg)
8407             (not gnus-show-mime)
8408           (> (prefix-numeric-value arg) 0)))
8409   (gnus-summary-select-article t 'force))
8410
8411 (defun gnus-summary-caesar-message (&optional arg)
8412   "Caesar rotate the current article by 13.
8413 The numerical prefix specifies how many places to rotate each letter
8414 forward."
8415   (interactive "P")
8416   (gnus-summary-select-article)
8417   (let ((mail-header-separator ""))
8418     (gnus-eval-in-buffer-window gnus-article-buffer
8419       (save-restriction
8420         (widen)
8421         (let ((start (window-start))
8422               buffer-read-only)
8423           (message-caesar-buffer-body arg)
8424           (set-window-start (get-buffer-window (current-buffer)) start))))))
8425
8426 (defun gnus-summary-stop-page-breaking ()
8427   "Stop page breaking in the current article."
8428   (interactive)
8429   (gnus-summary-select-article)
8430   (gnus-eval-in-buffer-window gnus-article-buffer
8431     (widen)
8432     (when (gnus-visual-p 'page-marker)
8433       (let ((buffer-read-only nil))
8434         (gnus-remove-text-with-property 'gnus-prev)
8435         (gnus-remove-text-with-property 'gnus-next))
8436       (setq gnus-page-broken nil))))
8437
8438 (defun gnus-summary-move-article (&optional n to-newsgroup
8439                                             select-method action)
8440   "Move the current article to a different newsgroup.
8441 If N is a positive number, move the N next articles.
8442 If N is a negative number, move the N previous articles.
8443 If N is nil and any articles have been marked with the process mark,
8444 move those articles instead.
8445 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8446 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8447 re-spool using this method.
8448
8449 For this function to work, both the current newsgroup and the
8450 newsgroup that you want to move to have to support the `request-move'
8451 and `request-accept' functions.
8452
8453 ACTION can be either `move' (the default), `crosspost' or `copy'."
8454   (interactive "P")
8455   (unless action
8456     (setq action 'move))
8457   ;; Check whether the source group supports the required functions.
8458   (cond ((and (eq action 'move)
8459               (not (gnus-check-backend-function
8460                     'request-move-article gnus-newsgroup-name)))
8461          (error "The current group does not support article moving"))
8462         ((and (eq action 'crosspost)
8463               (not (gnus-check-backend-function
8464                     'request-replace-article gnus-newsgroup-name)))
8465          (error "The current group does not support article editing")))
8466   (let ((articles (gnus-summary-work-articles n))
8467         (prefix (if (gnus-check-backend-function
8468                      'request-move-article gnus-newsgroup-name)
8469                     (gnus-group-real-prefix gnus-newsgroup-name)
8470                   ""))
8471         (names '((move "Move" "Moving")
8472                  (copy "Copy" "Copying")
8473                  (crosspost "Crosspost" "Crossposting")))
8474         (copy-buf (save-excursion
8475                     (nnheader-set-temp-buffer " *copy article*")))
8476         (default-marks gnus-article-mark-lists)
8477         (no-expire-marks (delete '(expirable . expire)
8478                                  (copy-sequence gnus-article-mark-lists)))
8479         art-group to-method new-xref article to-groups)
8480     (unless (assq action names)
8481       (error "Unknown action %s" action))
8482     ;; Read the newsgroup name.
8483     (when (and (not to-newsgroup)
8484                (not select-method))
8485       (if (and gnus-move-split-methods
8486                (not
8487                 (and (memq gnus-current-article articles)
8488                      (gnus-buffer-live-p gnus-original-article-buffer))))
8489           ;; When `gnus-move-split-methods' is non-nil, we have to
8490           ;; select an article to give `gnus-read-move-group-name' an
8491           ;; opportunity to suggest an appropriate default.  However,
8492           ;; we needn't render or mark the article.
8493           (let ((gnus-display-mime-function nil)
8494                 (gnus-article-prepare-hook nil)
8495                 (gnus-mark-article-hook nil))
8496             (gnus-summary-select-article nil nil nil (car articles))))
8497       (setq to-newsgroup
8498             (gnus-read-move-group-name
8499              (cadr (assq action names))
8500              (symbol-value (intern (format "gnus-current-%s-group" action)))
8501              articles prefix))
8502       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8503     (setq to-method (or select-method
8504                         (gnus-server-to-method
8505                          (gnus-group-method to-newsgroup))))
8506     ;; Check the method we are to move this article to...
8507     (unless (gnus-check-backend-function
8508              'request-accept-article (car to-method))
8509       (error "%s does not support article copying" (car to-method)))
8510     (unless (gnus-check-server to-method)
8511       (error "Can't open server %s" (car to-method)))
8512     (gnus-message 6 "%s to %s: %s..."
8513                   (caddr (assq action names))
8514                   (or (car select-method) to-newsgroup) articles)
8515     (while articles
8516       (setq article (pop articles))
8517       (setq
8518        art-group
8519        (cond
8520         ;; Move the article.
8521         ((eq action 'move)
8522          ;; Remove this article from future suppression.
8523          (gnus-dup-unsuppress-article article)
8524          (gnus-request-move-article
8525           article                       ; Article to move
8526           gnus-newsgroup-name           ; From newsgroup
8527           (nth 1 (gnus-find-method-for-group
8528                   gnus-newsgroup-name)) ; Server
8529           (list 'gnus-request-accept-article
8530                 to-newsgroup (list 'quote select-method)
8531                 (not articles) t)       ; Accept form
8532           (not articles)))              ; Only save nov last time
8533         ;; Copy the article.
8534         ((eq action 'copy)
8535          (save-excursion
8536            (set-buffer copy-buf)
8537            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8538              (gnus-request-accept-article
8539               to-newsgroup select-method (not articles) t))))
8540         ;; Crosspost the article.
8541         ((eq action 'crosspost)
8542          (let ((xref (message-tokenize-header
8543                       (mail-header-xref (gnus-summary-article-header article))
8544                       " ")))
8545            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8546                                   ":" (number-to-string article)))
8547            (unless xref
8548              (setq xref (list (system-name))))
8549            (setq new-xref
8550                  (concat
8551                   (mapconcat 'identity
8552                              (delete "Xref:" (delete new-xref xref))
8553                              " ")
8554                   " " new-xref))
8555            (save-excursion
8556              (set-buffer copy-buf)
8557              ;; First put the article in the destination group.
8558              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8559              (when (consp (setq art-group
8560                                 (gnus-request-accept-article
8561                                  to-newsgroup select-method (not articles))))
8562                (setq new-xref (concat new-xref " " (car art-group)
8563                                       ":"
8564                                       (number-to-string (cdr art-group))))
8565                ;; Now we have the new Xrefs header, so we insert
8566                ;; it and replace the new article.
8567                (nnheader-replace-header "Xref" new-xref)
8568                (gnus-request-replace-article
8569                 (cdr art-group) to-newsgroup (current-buffer))
8570                art-group))))))
8571       (cond
8572        ((not art-group)
8573         (gnus-message 1 "Couldn't %s article %s: %s"
8574                       (cadr (assq action names)) article
8575                       (nnheader-get-report (car to-method))))
8576        ((eq art-group 'junk)
8577         (when (eq action 'move)
8578           (gnus-summary-mark-article article gnus-canceled-mark)
8579           (gnus-message 4 "Deleted article %s" article)))
8580        (t
8581         (let* ((pto-group (gnus-group-prefixed-name
8582                            (car art-group) to-method))
8583                (entry
8584                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8585                (info (nth 2 entry))
8586                (to-group (gnus-info-group info))
8587                to-marks)
8588           ;; Update the group that has been moved to.
8589           (when (and info
8590                      (memq action '(move copy)))
8591             (unless (member to-group to-groups)
8592               (push to-group to-groups))
8593
8594             (unless (memq article gnus-newsgroup-unreads)
8595               (push 'read to-marks)
8596               (gnus-info-set-read
8597                info (gnus-add-to-range (gnus-info-read info)
8598                                        (list (cdr art-group)))))
8599
8600             ;; See whether the article is to be put in the cache.
8601             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8602                              default-marks
8603                            no-expire-marks))
8604                   (to-article (cdr art-group)))
8605
8606               ;; Enter the article into the cache in the new group,
8607               ;; if that is required.
8608               (when gnus-use-cache
8609                 (gnus-cache-possibly-enter-article
8610                  to-group to-article
8611                  (let ((header (copy-sequence
8612                                 (gnus-summary-article-header article))))
8613                    (mail-header-set-number header to-article)
8614                    header)
8615                  (memq article gnus-newsgroup-marked)
8616                  (memq article gnus-newsgroup-dormant)
8617                  (memq article gnus-newsgroup-unreads)))
8618
8619               (when gnus-preserve-marks
8620                 ;; Copy any marks over to the new group.
8621                 (when (and (equal to-group gnus-newsgroup-name)
8622                            (not (memq article gnus-newsgroup-unreads)))
8623                   ;; Mark this article as read in this group.
8624                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8625                   (setcdr (gnus-active to-group) to-article)
8626                   (setcdr gnus-newsgroup-active to-article))
8627
8628                 (while marks
8629                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8630                     (when (memq article (symbol-value
8631                                          (intern (format "gnus-newsgroup-%s"
8632                                                          (caar marks)))))
8633                       (push (cdar marks) to-marks)
8634                       ;; If the other group is the same as this group,
8635                       ;; then we have to add the mark to the list.
8636                       (when (equal to-group gnus-newsgroup-name)
8637                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8638                              (cons to-article
8639                                    (symbol-value
8640                                     (intern (format "gnus-newsgroup-%s"
8641                                                     (caar marks)))))))
8642                       ;; Copy the marks to other group.
8643                       (gnus-add-marked-articles
8644                        to-group (cdar marks) (list to-article) info)))
8645                   (setq marks (cdr marks)))
8646
8647                 (gnus-request-set-mark to-group (list (list (list to-article)
8648                                                             'add
8649                                                             to-marks))))
8650
8651               (gnus-dribble-enter
8652                (concat "(gnus-group-set-info '"
8653                        (gnus-prin1-to-string (gnus-get-info to-group))
8654                        ")"))))
8655
8656           ;; Update the Xref header in this article to point to
8657           ;; the new crossposted article we have just created.
8658           (when (eq action 'crosspost)
8659             (save-excursion
8660               (set-buffer copy-buf)
8661               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8662               (nnheader-replace-header "Xref" new-xref)
8663               (gnus-request-replace-article
8664                article gnus-newsgroup-name (current-buffer)))))
8665
8666         ;;;!!!Why is this necessary?
8667         (set-buffer gnus-summary-buffer)
8668
8669         (gnus-summary-goto-subject article)
8670         (when (eq action 'move)
8671           (gnus-summary-mark-article article gnus-canceled-mark))))
8672       (gnus-summary-remove-process-mark article))
8673     ;; Re-activate all groups that have been moved to.
8674     (save-excursion
8675       (set-buffer gnus-group-buffer)
8676       (let ((gnus-group-marked to-groups))
8677         (gnus-group-get-new-news-this-group nil t)))
8678
8679     (gnus-kill-buffer copy-buf)
8680     (gnus-summary-position-point)
8681     (gnus-set-mode-line 'summary)))
8682
8683 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8684   "Move the current article to a different newsgroup.
8685 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8686 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8687 re-spool using this method."
8688   (interactive "P")
8689   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8690
8691 (defun gnus-summary-crosspost-article (&optional n)
8692   "Crosspost the current article to some other group."
8693   (interactive "P")
8694   (gnus-summary-move-article n nil nil 'crosspost))
8695
8696 (defcustom gnus-summary-respool-default-method nil
8697   "Default method type for respooling an article.
8698 If nil, use to the current newsgroup method."
8699   :type 'symbol
8700   :group 'gnus-summary-mail)
8701
8702 (defun gnus-summary-respool-article (&optional n method)
8703   "Respool the current article.
8704 The article will be squeezed through the mail spooling process again,
8705 which means that it will be put in some mail newsgroup or other
8706 depending on `nnmail-split-methods'.
8707 If N is a positive number, respool the N next articles.
8708 If N is a negative number, respool the N previous articles.
8709 If N is nil and any articles have been marked with the process mark,
8710 respool those articles instead.
8711
8712 Respooling can be done both from mail groups and \"real\" newsgroups.
8713 In the former case, the articles in question will be moved from the
8714 current group into whatever groups they are destined to.  In the
8715 latter case, they will be copied into the relevant groups."
8716   (interactive
8717    (list current-prefix-arg
8718          (let* ((methods (gnus-methods-using 'respool))
8719                 (methname
8720                  (symbol-name (or gnus-summary-respool-default-method
8721                                   (car (gnus-find-method-for-group
8722                                         gnus-newsgroup-name)))))
8723                 (method
8724                  (gnus-completing-read-with-default
8725                   methname "What backend do you want to use when respooling?"
8726                   methods nil t nil 'gnus-mail-method-history))
8727                 ms)
8728            (cond
8729             ((zerop (length (setq ms (gnus-servers-using-backend
8730                                       (intern method)))))
8731              (list (intern method) ""))
8732             ((= 1 (length ms))
8733              (car ms))
8734             (t
8735              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8736                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8737                            ms-alist))))))))
8738   (unless method
8739     (error "No method given for respooling"))
8740   (if (assoc (symbol-name
8741               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8742              (gnus-methods-using 'respool))
8743       (gnus-summary-move-article n nil method)
8744     (gnus-summary-copy-article n nil method)))
8745
8746 (defun gnus-summary-import-article (file &optional edit)
8747   "Import an arbitrary file into a mail newsgroup."
8748   (interactive "fImport file: \nP")
8749   (let ((group gnus-newsgroup-name)
8750         (now (current-time))
8751         atts lines group-art)
8752     (unless (gnus-check-backend-function 'request-accept-article group)
8753       (error "%s does not support article importing" group))
8754     (or (file-readable-p file)
8755         (not (file-regular-p file))
8756         (error "Can't read %s" file))
8757     (save-excursion
8758       (set-buffer (gnus-get-buffer-create " *import file*"))
8759       (erase-buffer)
8760       (nnheader-insert-file-contents file)
8761       (goto-char (point-min))
8762       (if (nnheader-article-p)
8763           (save-restriction
8764             (goto-char (point-min))
8765             (search-forward "\n\n" nil t)
8766             (narrow-to-region (point-min) (1- (point)))
8767             (goto-char (point-min))
8768             (unless (re-search-forward "^date:" nil t)
8769               (goto-char (point-max))
8770               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8771         ;; This doesn't look like an article, so we fudge some headers.
8772         (setq atts (file-attributes file)
8773               lines (count-lines (point-min) (point-max)))
8774         (insert "From: " (read-string "From: ") "\n"
8775                 "Subject: " (read-string "Subject: ") "\n"
8776                 "Date: " (message-make-date (nth 5 atts)) "\n"
8777                 "Message-ID: " (message-make-message-id) "\n"
8778                 "Lines: " (int-to-string lines) "\n"
8779                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8780       (setq group-art (gnus-request-accept-article group nil t))
8781       (kill-buffer (current-buffer)))
8782     (setq gnus-newsgroup-active (gnus-activate-group group))
8783     (forward-line 1)
8784     (gnus-summary-goto-article (cdr group-art) nil t)
8785     (when edit
8786       (gnus-summary-edit-article))))
8787
8788 (defun gnus-summary-create-article ()
8789   "Create an article in a mail newsgroup."
8790   (interactive)
8791   (let ((group gnus-newsgroup-name)
8792         (now (current-time))
8793         group-art)
8794     (unless (gnus-check-backend-function 'request-accept-article group)
8795       (error "%s does not support article importing" group))
8796     (save-excursion
8797       (set-buffer (gnus-get-buffer-create " *import file*"))
8798       (erase-buffer)
8799       (goto-char (point-min))
8800       ;; This doesn't look like an article, so we fudge some headers.
8801       (insert "From: " (read-string "From: ") "\n"
8802               "Subject: " (read-string "Subject: ") "\n"
8803               "Date: " (message-make-date now) "\n"
8804               "Message-ID: " (message-make-message-id) "\n")
8805       (setq group-art (gnus-request-accept-article group nil t))
8806       (kill-buffer (current-buffer)))
8807     (setq gnus-newsgroup-active (gnus-activate-group group))
8808     (forward-line 1)
8809     (gnus-summary-goto-article (cdr group-art) nil t)
8810     (gnus-summary-edit-article)))
8811
8812 (defun gnus-summary-article-posted-p ()
8813   "Say whether the current (mail) article is available from news as well.
8814 This will be the case if the article has both been mailed and posted."
8815   (interactive)
8816   (let ((id (mail-header-references (gnus-summary-article-header)))
8817         (gnus-override-method (car (gnus-refer-article-methods))))
8818     (if (gnus-request-head id "")
8819         (gnus-message 2 "The current message was found on %s"
8820                       gnus-override-method)
8821       (gnus-message 2 "The current message couldn't be found on %s"
8822                     gnus-override-method)
8823       nil)))
8824
8825 (defun gnus-summary-expire-articles (&optional now)
8826   "Expire all articles that are marked as expirable in the current group."
8827   (interactive)
8828   (when (gnus-check-backend-function
8829          'request-expire-articles gnus-newsgroup-name)
8830     ;; This backend supports expiry.
8831     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8832            (expirable (if total
8833                           (progn
8834                             ;; We need to update the info for
8835                             ;; this group for `gnus-list-of-read-articles'
8836                             ;; to give us the right answer.
8837                             (gnus-run-hooks 'gnus-exit-group-hook)
8838                             (gnus-summary-update-info)
8839                             (gnus-list-of-read-articles gnus-newsgroup-name))
8840                         (setq gnus-newsgroup-expirable
8841                               (sort gnus-newsgroup-expirable '<))))
8842            (expiry-wait (if now 'immediate
8843                           (gnus-group-find-parameter
8844                            gnus-newsgroup-name 'expiry-wait)))
8845            (nnmail-expiry-target
8846             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8847                 nnmail-expiry-target))
8848            es)
8849       (when expirable
8850         ;; There are expirable articles in this group, so we run them
8851         ;; through the expiry process.
8852         (gnus-message 6 "Expiring articles...")
8853         (unless (gnus-check-group gnus-newsgroup-name)
8854           (error "Can't open server for %s" gnus-newsgroup-name))
8855         ;; The list of articles that weren't expired is returned.
8856         (save-excursion
8857           (if expiry-wait
8858               (let ((nnmail-expiry-wait-function nil)
8859                     (nnmail-expiry-wait expiry-wait))
8860                 (setq es (gnus-request-expire-articles
8861                           expirable gnus-newsgroup-name)))
8862             (setq es (gnus-request-expire-articles
8863                       expirable gnus-newsgroup-name)))
8864           (unless total
8865             (setq gnus-newsgroup-expirable es))
8866           ;; We go through the old list of expirable, and mark all
8867           ;; really expired articles as nonexistent.
8868           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8869             (let ((gnus-use-cache nil))
8870               (dolist (article expirable)
8871                 (when (and (not (memq article es))
8872                            (gnus-data-find article))
8873                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8874         (gnus-message 6 "Expiring articles...done")))))
8875
8876 (defun gnus-summary-expire-articles-now ()
8877   "Expunge all expirable articles in the current group.
8878 This means that *all* articles that are marked as expirable will be
8879 deleted forever, right now."
8880   (interactive)
8881   (or gnus-expert-user
8882       (gnus-yes-or-no-p
8883        "Are you really, really, really sure you want to delete all these messages? ")
8884       (error "Phew!"))
8885   (gnus-summary-expire-articles t))
8886
8887 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8888 (defun gnus-summary-delete-article (&optional n)
8889   "Delete the N next (mail) articles.
8890 This command actually deletes articles.  This is not a marking
8891 command.  The article will disappear forever from your life, never to
8892 return.
8893 If N is negative, delete backwards.
8894 If N is nil and articles have been marked with the process mark,
8895 delete these instead."
8896   (interactive "P")
8897   (unless (gnus-check-backend-function 'request-expire-articles
8898                                        gnus-newsgroup-name)
8899     (error "The current newsgroup does not support article deletion"))
8900   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8901     (error "Couldn't open server"))
8902   ;; Compute the list of articles to delete.
8903   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8904         not-deleted)
8905     (if (and gnus-novice-user
8906              (not (gnus-yes-or-no-p
8907                    (format "Do you really want to delete %s forever? "
8908                            (if (> (length articles) 1)
8909                                (format "these %s articles" (length articles))
8910                              "this article")))))
8911         ()
8912       ;; Delete the articles.
8913       (setq not-deleted (gnus-request-expire-articles
8914                          articles gnus-newsgroup-name 'force))
8915       (while articles
8916         (gnus-summary-remove-process-mark (car articles))
8917         ;; The backend might not have been able to delete the article
8918         ;; after all.
8919         (unless (memq (car articles) not-deleted)
8920           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8921         (setq articles (cdr articles)))
8922       (when not-deleted
8923         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8924     (gnus-summary-position-point)
8925     (gnus-set-mode-line 'summary)
8926     not-deleted))
8927
8928 (defun gnus-summary-edit-article (&optional force)
8929   "Edit the current article.
8930 This will have permanent effect only in mail groups.
8931 If FORCE is non-nil, allow editing of articles even in read-only
8932 groups."
8933   (interactive "P")
8934   (save-excursion
8935     (set-buffer gnus-summary-buffer)
8936     (let ((mail-parse-charset gnus-newsgroup-charset)
8937           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8938       (gnus-set-global-variables)
8939       (when (and (not force)
8940                  (gnus-group-read-only-p))
8941         (error "The current newsgroup does not support article editing"))
8942       (gnus-summary-show-article t)
8943       (gnus-article-edit-article
8944        'ignore
8945        `(lambda (no-highlight)
8946           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8947                 (message-options message-options)
8948                 (message-options-set-recipient)
8949                 (mail-parse-ignored-charsets
8950                  ',gnus-newsgroup-ignored-charsets))
8951             (gnus-summary-edit-article-done
8952              ,(or (mail-header-references gnus-current-headers) "")
8953              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8954
8955 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8956
8957 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8958                                                  no-highlight)
8959   "Make edits to the current article permanent."
8960   (interactive)
8961   (save-excursion
8962     ;; The buffer restriction contains the entire article if it exists.
8963     (when (article-goto-body)
8964       (let ((lines (count-lines (point) (point-max)))
8965             (length (- (point-max) (point)))
8966             (case-fold-search t)
8967             (body (copy-marker (point))))
8968         (goto-char (point-min))
8969         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8970           (delete-region (match-beginning 1) (match-end 1))
8971           (insert (number-to-string length)))
8972         (goto-char (point-min))
8973         (when (re-search-forward
8974                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8975           (delete-region (match-beginning 1) (match-end 1))
8976           (insert (number-to-string length)))
8977         (goto-char (point-min))
8978         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8979           (delete-region (match-beginning 1) (match-end 1))
8980           (insert (number-to-string lines))))))
8981   ;; Replace the article.
8982   (let ((buf (current-buffer)))
8983     (with-temp-buffer
8984       (insert-buffer-substring buf)
8985
8986       (if (and (not read-only)
8987                (not (gnus-request-replace-article
8988                      (cdr gnus-article-current) (car gnus-article-current)
8989                      (current-buffer) t)))
8990           (error "Couldn't replace article")
8991         ;; Update the summary buffer.
8992         (if (and references
8993                  (equal (message-tokenize-header references " ")
8994                         (message-tokenize-header
8995                          (or (message-fetch-field "references") "") " ")))
8996             ;; We only have to update this line.
8997             (save-excursion
8998               (save-restriction
8999                 (message-narrow-to-head)
9000                 (let ((head (buffer-string))
9001                       header)
9002                   (with-temp-buffer
9003                     (insert (format "211 %d Article retrieved.\n"
9004                                     (cdr gnus-article-current)))
9005                     (insert head)
9006                     (insert ".\n")
9007                     (let ((nntp-server-buffer (current-buffer)))
9008                       (setq header (car (gnus-get-newsgroup-headers
9009                                          nil t))))
9010                     (save-excursion
9011                       (set-buffer gnus-summary-buffer)
9012                       (gnus-data-set-header
9013                        (gnus-data-find (cdr gnus-article-current))
9014                        header)
9015                       (gnus-summary-update-article-line
9016                        (cdr gnus-article-current) header)
9017                       (if (gnus-summary-goto-subject
9018                            (cdr gnus-article-current) nil t)
9019                           (gnus-summary-update-secondary-mark
9020                            (cdr gnus-article-current))))))))
9021           ;; Update threads.
9022           (set-buffer (or buffer gnus-summary-buffer))
9023           (gnus-summary-update-article (cdr gnus-article-current))
9024           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9025               (gnus-summary-update-secondary-mark
9026                (cdr gnus-article-current))))
9027         ;; Prettify the article buffer again.
9028         (unless no-highlight
9029           (save-excursion
9030             (set-buffer gnus-article-buffer)
9031             ;;;!!! Fix this -- article should be rehighlighted.
9032             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9033             (set-buffer gnus-original-article-buffer)
9034             (gnus-request-article
9035              (cdr gnus-article-current)
9036              (car gnus-article-current) (current-buffer))))
9037         ;; Prettify the summary buffer line.
9038         (when (gnus-visual-p 'summary-highlight 'highlight)
9039           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9040
9041 (defun gnus-summary-edit-wash (key)
9042   "Perform editing command KEY in the article buffer."
9043   (interactive
9044    (list
9045     (progn
9046       (message "%s" (concat (this-command-keys) "- "))
9047       (read-char))))
9048   (message "")
9049   (gnus-summary-edit-article)
9050   (execute-kbd-macro (concat (this-command-keys) key))
9051   (gnus-article-edit-done))
9052
9053 ;;; Respooling
9054
9055 (defun gnus-summary-respool-query (&optional silent trace)
9056   "Query where the respool algorithm would put this article."
9057   (interactive)
9058   (let (gnus-mark-article-hook)
9059     (gnus-summary-select-article)
9060     (save-excursion
9061       (set-buffer gnus-original-article-buffer)
9062       (save-restriction
9063         (message-narrow-to-head)
9064         (let ((groups (nnmail-article-group 'identity trace)))
9065           (unless silent
9066             (if groups
9067                 (message "This message would go to %s"
9068                          (mapconcat 'car groups ", "))
9069               (message "This message would go to no groups"))
9070             groups))))))
9071
9072 (defun gnus-summary-respool-trace ()
9073   "Trace where the respool algorithm would put this article.
9074 Display a buffer showing all fancy splitting patterns which matched."
9075   (interactive)
9076   (gnus-summary-respool-query nil t))
9077
9078 ;; Summary marking commands.
9079
9080 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9081   "Mark articles which has the same subject as read, and then select the next.
9082 If UNMARK is positive, remove any kind of mark.
9083 If UNMARK is negative, tick articles."
9084   (interactive "P")
9085   (when unmark
9086     (setq unmark (prefix-numeric-value unmark)))
9087   (let ((count
9088          (gnus-summary-mark-same-subject
9089           (gnus-summary-article-subject) unmark)))
9090     ;; Select next unread article.  If auto-select-same mode, should
9091     ;; select the first unread article.
9092     (gnus-summary-next-article t (and gnus-auto-select-same
9093                                       (gnus-summary-article-subject)))
9094     (gnus-message 7 "%d article%s marked as %s"
9095                   count (if (= count 1) " is" "s are")
9096                   (if unmark "unread" "read"))))
9097
9098 (defun gnus-summary-kill-same-subject (&optional unmark)
9099   "Mark articles which has the same subject as read.
9100 If UNMARK is positive, remove any kind of mark.
9101 If UNMARK is negative, tick articles."
9102   (interactive "P")
9103   (when unmark
9104     (setq unmark (prefix-numeric-value unmark)))
9105   (let ((count
9106          (gnus-summary-mark-same-subject
9107           (gnus-summary-article-subject) unmark)))
9108     ;; If marked as read, go to next unread subject.
9109     (when (null unmark)
9110       ;; Go to next unread subject.
9111       (gnus-summary-next-subject 1 t))
9112     (gnus-message 7 "%d articles are marked as %s"
9113                   count (if unmark "unread" "read"))))
9114
9115 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9116   "Mark articles with same SUBJECT as read, and return marked number.
9117 If optional argument UNMARK is positive, remove any kinds of marks.
9118 If optional argument UNMARK is negative, mark articles as unread instead."
9119   (let ((count 1))
9120     (save-excursion
9121       (cond
9122        ((null unmark)                   ; Mark as read.
9123         (while (and
9124                 (progn
9125                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9126                   (gnus-summary-show-thread) t)
9127                 (gnus-summary-find-subject subject))
9128           (setq count (1+ count))))
9129        ((> unmark 0)                    ; Tick.
9130         (while (and
9131                 (progn
9132                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9133                   (gnus-summary-show-thread) t)
9134                 (gnus-summary-find-subject subject))
9135           (setq count (1+ count))))
9136        (t                               ; Mark as unread.
9137         (while (and
9138                 (progn
9139                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9140                   (gnus-summary-show-thread) t)
9141                 (gnus-summary-find-subject subject))
9142           (setq count (1+ count)))))
9143       (gnus-set-mode-line 'summary)
9144       ;; Return the number of marked articles.
9145       count)))
9146
9147 (defun gnus-summary-mark-as-processable (n &optional unmark)
9148   "Set the process mark on the next N articles.
9149 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9150 the process mark instead.  The difference between N and the actual
9151 number of articles marked is returned."
9152   (interactive "P")
9153   (if (and (null n) (gnus-region-active-p))
9154       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9155     (setq n (prefix-numeric-value n))
9156     (let ((backward (< n 0))
9157           (n (abs n)))
9158       (while (and
9159               (> n 0)
9160               (if unmark
9161                   (gnus-summary-remove-process-mark
9162                    (gnus-summary-article-number))
9163                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9164               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9165         (setq n (1- n)))
9166       (when (/= 0 n)
9167         (gnus-message 7 "No more articles"))
9168       (gnus-summary-recenter)
9169       (gnus-summary-position-point)
9170       n)))
9171
9172 (defun gnus-summary-unmark-as-processable (n)
9173   "Remove the process mark from the next N articles.
9174 If N is negative, unmark backward instead.  The difference between N and
9175 the actual number of articles unmarked is returned."
9176   (interactive "P")
9177   (gnus-summary-mark-as-processable n t))
9178
9179 (defun gnus-summary-unmark-all-processable ()
9180   "Remove the process mark from all articles."
9181   (interactive)
9182   (save-excursion
9183     (while gnus-newsgroup-processable
9184       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9185   (gnus-summary-position-point))
9186
9187 (defun gnus-summary-add-mark (article type)
9188   "Mark ARTICLE with a mark of TYPE."
9189   (let ((vtype (car (assq type gnus-article-mark-lists)))
9190         var)
9191     (if (not vtype)
9192         (error "No such mark type: %s" type)
9193       (setq var (intern (format "gnus-newsgroup-%s" type)))
9194       (set var (cons article (symbol-value var)))
9195       (if (memq type '(processable cached replied forwarded recent saved))
9196           (gnus-summary-update-secondary-mark article)
9197         ;;; !!! This is bogus.  We should find out what primary
9198         ;;; !!! mark we want to set.
9199         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9200
9201 (defun gnus-summary-mark-as-expirable (n)
9202   "Mark N articles forward as expirable.
9203 If N is negative, mark backward instead.  The difference between N and
9204 the actual number of articles marked is returned."
9205   (interactive "p")
9206   (gnus-summary-mark-forward n gnus-expirable-mark))
9207
9208 (defun gnus-summary-mark-article-as-replied (article)
9209   "Mark ARTICLE as replied to and update the summary line.
9210 ARTICLE can also be a list of articles."
9211   (interactive (list (gnus-summary-article-number)))
9212   (let ((articles (if (listp article) article (list article))))
9213     (dolist (article articles)
9214       (push article gnus-newsgroup-replied)
9215       (let ((buffer-read-only nil))
9216         (when (gnus-summary-goto-subject article nil t)
9217           (gnus-summary-update-secondary-mark article))))))
9218
9219 (defun gnus-summary-mark-article-as-forwarded (article)
9220   "Mark ARTICLE as forwarded and update the summary line.
9221 ARTICLE can also be a list of articles."
9222   (let ((articles (if (listp article) article (list article))))
9223     (dolist (article articles)
9224       (push article gnus-newsgroup-forwarded)
9225       (let ((buffer-read-only nil))
9226         (when (gnus-summary-goto-subject article nil t)
9227           (gnus-summary-update-secondary-mark article))))))
9228
9229 (defun gnus-summary-set-bookmark (article)
9230   "Set a bookmark in current article."
9231   (interactive (list (gnus-summary-article-number)))
9232   (when (or (not (get-buffer gnus-article-buffer))
9233             (not gnus-current-article)
9234             (not gnus-article-current)
9235             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9236     (error "No current article selected"))
9237   ;; Remove old bookmark, if one exists.
9238   (let ((old (assq article gnus-newsgroup-bookmarks)))
9239     (when old
9240       (setq gnus-newsgroup-bookmarks
9241             (delq old gnus-newsgroup-bookmarks))))
9242   ;; Set the new bookmark, which is on the form
9243   ;; (article-number . line-number-in-body).
9244   (push
9245    (cons article
9246          (save-excursion
9247            (set-buffer gnus-article-buffer)
9248            (count-lines
9249             (min (point)
9250                  (save-excursion
9251                    (goto-char (point-min))
9252                    (search-forward "\n\n" nil t)
9253                    (point)))
9254             (point))))
9255    gnus-newsgroup-bookmarks)
9256   (gnus-message 6 "A bookmark has been added to the current article."))
9257
9258 (defun gnus-summary-remove-bookmark (article)
9259   "Remove the bookmark from the current article."
9260   (interactive (list (gnus-summary-article-number)))
9261   ;; Remove old bookmark, if one exists.
9262   (let ((old (assq article gnus-newsgroup-bookmarks)))
9263     (if old
9264         (progn
9265           (setq gnus-newsgroup-bookmarks
9266                 (delq old gnus-newsgroup-bookmarks))
9267           (gnus-message 6 "Removed bookmark."))
9268       (gnus-message 6 "No bookmark in current article."))))
9269
9270 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9271 (defun gnus-summary-mark-as-dormant (n)
9272   "Mark N articles forward as dormant.
9273 If N is negative, mark backward instead.  The difference between N and
9274 the actual number of articles marked is returned."
9275   (interactive "p")
9276   (gnus-summary-mark-forward n gnus-dormant-mark))
9277
9278 (defun gnus-summary-set-process-mark (article)
9279   "Set the process mark on ARTICLE and update the summary line."
9280   (setq gnus-newsgroup-processable
9281         (cons article
9282               (delq article gnus-newsgroup-processable)))
9283   (when (gnus-summary-goto-subject article)
9284     (gnus-summary-show-thread)
9285     (gnus-summary-goto-subject article)
9286     (gnus-summary-update-secondary-mark article)))
9287
9288 (defun gnus-summary-remove-process-mark (article)
9289   "Remove the process mark from ARTICLE and update the summary line."
9290   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9291   (when (gnus-summary-goto-subject article)
9292     (gnus-summary-show-thread)
9293     (gnus-summary-goto-subject article)
9294     (gnus-summary-update-secondary-mark article)))
9295
9296 (defun gnus-summary-set-saved-mark (article)
9297   "Set the process mark on ARTICLE and update the summary line."
9298   (push article gnus-newsgroup-saved)
9299   (when (gnus-summary-goto-subject article)
9300     (gnus-summary-update-secondary-mark article)))
9301
9302 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9303   "Mark N articles as read forwards.
9304 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9305 The difference between N and the actual number of articles marked is
9306 returned.
9307 Iff NO-EXPIRE, auto-expiry will be inhibited."
9308   (interactive "p")
9309   (gnus-summary-show-thread)
9310   (let ((backward (< n 0))
9311         (gnus-summary-goto-unread
9312          (and gnus-summary-goto-unread
9313               (not (eq gnus-summary-goto-unread 'never))
9314               (not (memq mark (list gnus-unread-mark
9315                                     gnus-ticked-mark gnus-dormant-mark)))))
9316         (n (abs n))
9317         (mark (or mark gnus-del-mark)))
9318     (while (and (> n 0)
9319                 (gnus-summary-mark-article nil mark no-expire)
9320                 (zerop (gnus-summary-next-subject
9321                         (if backward -1 1)
9322                         (and gnus-summary-goto-unread
9323                              (not (eq gnus-summary-goto-unread 'never)))
9324                         t)))
9325       (setq n (1- n)))
9326     (when (/= 0 n)
9327       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9328     (gnus-summary-recenter)
9329     (gnus-summary-position-point)
9330     (gnus-set-mode-line 'summary)
9331     n))
9332
9333 (defun gnus-summary-mark-article-as-read (mark)
9334   "Mark the current article quickly as read with MARK."
9335   (let ((article (gnus-summary-article-number)))
9336     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9337     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9338     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9339     (push (cons article mark) gnus-newsgroup-reads)
9340     ;; Possibly remove from cache, if that is used.
9341     (when gnus-use-cache
9342       (gnus-cache-enter-remove-article article))
9343     ;; Allow the backend to change the mark.
9344     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9345     ;; Check for auto-expiry.
9346     (when (and gnus-newsgroup-auto-expire
9347                (memq mark gnus-auto-expirable-marks))
9348       (setq mark gnus-expirable-mark)
9349       ;; Let the backend know about the mark change.
9350       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9351       (push article gnus-newsgroup-expirable))
9352     ;; Set the mark in the buffer.
9353     (gnus-summary-update-mark mark 'unread)
9354     t))
9355
9356 (defun gnus-summary-mark-article-as-unread (mark)
9357   "Mark the current article quickly as unread with MARK."
9358   (let* ((article (gnus-summary-article-number))
9359          (old-mark (gnus-summary-article-mark article)))
9360     ;; Allow the backend to change the mark.
9361     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9362     (if (eq mark old-mark)
9363         t
9364       (if (<= article 0)
9365           (progn
9366             (gnus-error 1 "Can't mark negative article numbers")
9367             nil)
9368         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9369         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9370         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9371         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9372         (cond ((= mark gnus-ticked-mark)
9373                (setq gnus-newsgroup-marked
9374                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9375                                               article)))
9376               ((= mark gnus-dormant-mark)
9377                (setq gnus-newsgroup-dormant
9378                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9379                                               article)))
9380               (t
9381                (setq gnus-newsgroup-unreads
9382                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9383                                               article))))
9384         (gnus-pull article gnus-newsgroup-reads)
9385
9386         ;; See whether the article is to be put in the cache.
9387         (and gnus-use-cache
9388              (vectorp (gnus-summary-article-header article))
9389              (save-excursion
9390                (gnus-cache-possibly-enter-article
9391                 gnus-newsgroup-name article
9392                 (gnus-summary-article-header article)
9393                 (= mark gnus-ticked-mark)
9394                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9395
9396         ;; Fix the mark.
9397         (gnus-summary-update-mark mark 'unread)
9398         t))))
9399
9400 (defun gnus-summary-mark-article (&optional article mark no-expire)
9401   "Mark ARTICLE with MARK.  MARK can be any character.
9402 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9403 `??' (dormant) and `?E' (expirable).
9404 If MARK is nil, then the default character `?r' is used.
9405 If ARTICLE is nil, then the article on the current line will be
9406 marked.
9407 Iff NO-EXPIRE, auto-expiry will be inhibited."
9408   ;; The mark might be a string.
9409   (when (stringp mark)
9410     (setq mark (aref mark 0)))
9411   ;; If no mark is given, then we check auto-expiring.
9412   (when (null mark)
9413     (setq mark gnus-del-mark))
9414   (when (and (not no-expire)
9415              gnus-newsgroup-auto-expire
9416              (memq mark gnus-auto-expirable-marks))
9417     (setq mark gnus-expirable-mark))
9418   (let ((article (or article (gnus-summary-article-number)))
9419         (old-mark (gnus-summary-article-mark article)))
9420     ;; Allow the backend to change the mark.
9421     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9422     (if (eq mark old-mark)
9423         t
9424       (unless article
9425         (error "No article on current line"))
9426       (if (not (if (or (= mark gnus-unread-mark)
9427                        (= mark gnus-ticked-mark)
9428                        (= mark gnus-dormant-mark))
9429                    (gnus-mark-article-as-unread article mark)
9430                  (gnus-mark-article-as-read article mark)))
9431           t
9432         ;; See whether the article is to be put in the cache.
9433         (and gnus-use-cache
9434              (not (= mark gnus-canceled-mark))
9435              (vectorp (gnus-summary-article-header article))
9436              (save-excursion
9437                (gnus-cache-possibly-enter-article
9438                 gnus-newsgroup-name article
9439                 (gnus-summary-article-header article)
9440                 (= mark gnus-ticked-mark)
9441                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9442
9443         (when (gnus-summary-goto-subject article nil t)
9444           (let ((buffer-read-only nil))
9445             (gnus-summary-show-thread)
9446             ;; Fix the mark.
9447             (gnus-summary-update-mark mark 'unread)
9448             t))))))
9449
9450 (defun gnus-summary-update-secondary-mark (article)
9451   "Update the secondary (read, process, cache) mark."
9452   (gnus-summary-update-mark
9453    (cond ((memq article gnus-newsgroup-processable)
9454           gnus-process-mark)
9455          ((memq article gnus-newsgroup-cached)
9456           gnus-cached-mark)
9457          ((memq article gnus-newsgroup-replied)
9458           gnus-replied-mark)
9459          ((memq article gnus-newsgroup-forwarded)
9460           gnus-forwarded-mark)
9461          ((memq article gnus-newsgroup-saved)
9462           gnus-saved-mark)
9463          ((memq article gnus-newsgroup-recent)
9464           gnus-recent-mark)
9465          ((memq article gnus-newsgroup-unseen)
9466           gnus-unseen-mark)
9467          (t gnus-no-mark))
9468    'replied)
9469   (when (gnus-visual-p 'summary-highlight 'highlight)
9470     (gnus-run-hooks 'gnus-summary-update-hook))
9471   t)
9472
9473 (defun gnus-summary-update-mark (mark type)
9474   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9475         (buffer-read-only nil))
9476     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9477     (when forward
9478       (when (looking-at "\r")
9479         (incf forward))
9480       (when (<= (+ forward (point)) (point-max))
9481         ;; Go to the right position on the line.
9482         (goto-char (+ forward (point)))
9483         ;; Replace the old mark with the new mark.
9484         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9485         ;; Optionally update the marks by some user rule.
9486         (when (eq type 'unread)
9487           (gnus-data-set-mark
9488            (gnus-data-find (gnus-summary-article-number)) mark)
9489           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9490
9491 (defun gnus-mark-article-as-read (article &optional mark)
9492   "Enter ARTICLE in the pertinent lists and remove it from others."
9493   ;; Make the article expirable.
9494   (let ((mark (or mark gnus-del-mark)))
9495     (setq gnus-newsgroup-expirable
9496           (if (= mark gnus-expirable-mark)
9497               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9498             (delq article gnus-newsgroup-expirable)))
9499     ;; Remove from unread and marked lists.
9500     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9501     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9502     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9503     (push (cons article mark) gnus-newsgroup-reads)
9504     ;; Possibly remove from cache, if that is used.
9505     (when gnus-use-cache
9506       (gnus-cache-enter-remove-article article))
9507     t))
9508
9509 (defun gnus-mark-article-as-unread (article &optional mark)
9510   "Enter ARTICLE in the pertinent lists and remove it from others."
9511   (let ((mark (or mark gnus-ticked-mark)))
9512     (if (<= article 0)
9513         (progn
9514           (gnus-error 1 "Can't mark negative article numbers")
9515           nil)
9516       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9517             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9518             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9519             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9520
9521       ;; Unsuppress duplicates?
9522       (when gnus-suppress-duplicates
9523         (gnus-dup-unsuppress-article article))
9524
9525       (cond ((= mark gnus-ticked-mark)
9526              (setq gnus-newsgroup-marked
9527                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9528             ((= mark gnus-dormant-mark)
9529              (setq gnus-newsgroup-dormant
9530                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9531             (t
9532              (setq gnus-newsgroup-unreads
9533                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9534       (gnus-pull article gnus-newsgroup-reads)
9535       t)))
9536
9537 (defalias 'gnus-summary-mark-as-unread-forward
9538   'gnus-summary-tick-article-forward)
9539 (make-obsolete 'gnus-summary-mark-as-unread-forward
9540                'gnus-summary-tick-article-forward)
9541 (defun gnus-summary-tick-article-forward (n)
9542   "Tick N articles forwards.
9543 If N is negative, tick backwards instead.
9544 The difference between N and the number of articles ticked is returned."
9545   (interactive "p")
9546   (gnus-summary-mark-forward n gnus-ticked-mark))
9547
9548 (defalias 'gnus-summary-mark-as-unread-backward
9549   'gnus-summary-tick-article-backward)
9550 (make-obsolete 'gnus-summary-mark-as-unread-backward
9551                'gnus-summary-tick-article-backward)
9552 (defun gnus-summary-tick-article-backward (n)
9553   "Tick N articles backwards.
9554 The difference between N and the number of articles ticked is returned."
9555   (interactive "p")
9556   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9557
9558 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9559 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9560 (defun gnus-summary-tick-article (&optional article clear-mark)
9561   "Mark current article as unread.
9562 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9563 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9564   (interactive)
9565   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9566                                        gnus-ticked-mark)))
9567
9568 (defun gnus-summary-mark-as-read-forward (n)
9569   "Mark N articles as read forwards.
9570 If N is negative, mark backwards instead.
9571 The difference between N and the actual number of articles marked is
9572 returned."
9573   (interactive "p")
9574   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9575
9576 (defun gnus-summary-mark-as-read-backward (n)
9577   "Mark the N articles as read backwards.
9578 The difference between N and the actual number of articles marked is
9579 returned."
9580   (interactive "p")
9581   (gnus-summary-mark-forward
9582    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9583
9584 (defun gnus-summary-mark-as-read (&optional article mark)
9585   "Mark current article as read.
9586 ARTICLE specifies the article to be marked as read.
9587 MARK specifies a string to be inserted at the beginning of the line."
9588   (gnus-summary-mark-article article mark))
9589
9590 (defun gnus-summary-clear-mark-forward (n)
9591   "Clear marks from N articles forward.
9592 If N is negative, clear backward instead.
9593 The difference between N and the number of marks cleared is returned."
9594   (interactive "p")
9595   (gnus-summary-mark-forward n gnus-unread-mark))
9596
9597 (defun gnus-summary-clear-mark-backward (n)
9598   "Clear marks from N articles backward.
9599 The difference between N and the number of marks cleared is returned."
9600   (interactive "p")
9601   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9602
9603 (defun gnus-summary-mark-unread-as-read ()
9604   "Intended to be used by `gnus-summary-mark-article-hook'."
9605   (when (memq gnus-current-article gnus-newsgroup-unreads)
9606     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9607
9608 (defun gnus-summary-mark-read-and-unread-as-read ()
9609   "Intended to be used by `gnus-summary-mark-article-hook'."
9610   (let ((mark (gnus-summary-article-mark)))
9611     (when (or (gnus-unread-mark-p mark)
9612               (gnus-read-mark-p mark))
9613       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9614
9615 (defun gnus-summary-mark-unread-as-ticked ()
9616   "Intended to be used by `gnus-summary-mark-article-hook'."
9617   (when (memq gnus-current-article gnus-newsgroup-unreads)
9618     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9619
9620 (defun gnus-summary-mark-region-as-read (point mark all)
9621   "Mark all unread articles between point and mark as read.
9622 If given a prefix, mark all articles between point and mark as read,
9623 even ticked and dormant ones."
9624   (interactive "r\nP")
9625   (save-excursion
9626     (let (article)
9627       (goto-char point)
9628       (beginning-of-line)
9629       (while (and
9630               (< (point) mark)
9631               (progn
9632                 (when (or all
9633                           (memq (setq article (gnus-summary-article-number))
9634                                 gnus-newsgroup-unreads))
9635                   (gnus-summary-mark-article article gnus-del-mark))
9636                 t)
9637               (gnus-summary-find-next))))))
9638
9639 (defun gnus-summary-mark-below (score mark)
9640   "Mark articles with score less than SCORE with MARK."
9641   (interactive "P\ncMark: ")
9642   (setq score (if score
9643                   (prefix-numeric-value score)
9644                 (or gnus-summary-default-score 0)))
9645   (save-excursion
9646     (set-buffer gnus-summary-buffer)
9647     (goto-char (point-min))
9648     (while
9649         (progn
9650           (and (< (gnus-summary-article-score) score)
9651                (gnus-summary-mark-article nil mark))
9652           (gnus-summary-find-next)))))
9653
9654 (defun gnus-summary-kill-below (&optional score)
9655   "Mark articles with score below SCORE as read."
9656   (interactive "P")
9657   (gnus-summary-mark-below score gnus-killed-mark))
9658
9659 (defun gnus-summary-clear-above (&optional score)
9660   "Clear all marks from articles with score above SCORE."
9661   (interactive "P")
9662   (gnus-summary-mark-above score gnus-unread-mark))
9663
9664 (defun gnus-summary-tick-above (&optional score)
9665   "Tick all articles with score above SCORE."
9666   (interactive "P")
9667   (gnus-summary-mark-above score gnus-ticked-mark))
9668
9669 (defun gnus-summary-mark-above (score mark)
9670   "Mark articles with score over SCORE with MARK."
9671   (interactive "P\ncMark: ")
9672   (setq score (if score
9673                   (prefix-numeric-value score)
9674                 (or gnus-summary-default-score 0)))
9675   (save-excursion
9676     (set-buffer gnus-summary-buffer)
9677     (goto-char (point-min))
9678     (while (and (progn
9679                   (when (> (gnus-summary-article-score) score)
9680                     (gnus-summary-mark-article nil mark))
9681                   t)
9682                 (gnus-summary-find-next)))))
9683
9684 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9685 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9686 (defun gnus-summary-limit-include-expunged (&optional no-error)
9687   "Display all the hidden articles that were expunged for low scores."
9688   (interactive)
9689   (let ((buffer-read-only nil))
9690     (let ((scored gnus-newsgroup-scored)
9691           headers h)
9692       (while scored
9693         (unless (gnus-summary-article-header (caar scored))
9694           (and (setq h (gnus-number-to-header (caar scored)))
9695                (< (cdar scored) gnus-summary-expunge-below)
9696                (push h headers)))
9697         (setq scored (cdr scored)))
9698       (if (not headers)
9699           (when (not no-error)
9700             (error "No expunged articles hidden"))
9701         (goto-char (point-min))
9702         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9703         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9704         (mapcar (lambda (x) (push (mail-header-number x)
9705                                   gnus-newsgroup-limit))
9706                 headers)
9707         (gnus-summary-prepare-unthreaded (nreverse headers))
9708         (goto-char (point-min))
9709         (gnus-summary-position-point)
9710         t))))
9711
9712 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9713   "Mark all unread articles in this newsgroup as read.
9714 If prefix argument ALL is non-nil, ticked and dormant articles will
9715 also be marked as read.
9716 If QUIETLY is non-nil, no questions will be asked.
9717 If TO-HERE is non-nil, it should be a point in the buffer.  All
9718 articles before (after, if REVERSE is set) this point will be marked as read.
9719 Note that this function will only catch up the unread article
9720 in the current summary buffer limitation.
9721 The number of articles marked as read is returned."
9722   (interactive "P")
9723   (prog1
9724       (save-excursion
9725         (when (or quietly
9726                   (not gnus-interactive-catchup) ;Without confirmation?
9727                   gnus-expert-user
9728                   (gnus-y-or-n-p
9729                    (if all
9730                        "Mark absolutely all articles as read? "
9731                      "Mark all unread articles as read? ")))
9732           (if (and not-mark
9733                    (not gnus-newsgroup-adaptive)
9734                    (not gnus-newsgroup-auto-expire)
9735                    (not gnus-suppress-duplicates)
9736                    (or (not gnus-use-cache)
9737                        (eq gnus-use-cache 'passive)))
9738               (progn
9739                 (when all
9740                   (setq gnus-newsgroup-marked nil
9741                         gnus-newsgroup-dormant nil))
9742                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9743             ;; We actually mark all articles as canceled, which we
9744             ;; have to do when using auto-expiry or adaptive scoring.
9745             (gnus-summary-show-all-threads)
9746             (if (and to-here reverse)
9747                 (progn
9748                   (goto-char to-here)
9749                   (while (and
9750                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9751                           (gnus-summary-find-next (not all) nil nil t))))
9752               (when (gnus-summary-first-subject (not all) t)
9753                 (while (and
9754                         (if to-here (< (point) to-here) t)
9755                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9756                         (gnus-summary-find-next (not all) nil nil t)))))
9757             (gnus-set-mode-line 'summary))
9758           t))
9759     (gnus-summary-position-point)))
9760
9761 (defun gnus-summary-catchup-to-here (&optional all)
9762   "Mark all unticked articles before the current one as read.
9763 If ALL is non-nil, also mark ticked and dormant articles as read."
9764   (interactive "P")
9765   (save-excursion
9766     (gnus-save-hidden-threads
9767       (let ((beg (point)))
9768         ;; We check that there are unread articles.
9769         (when (or all (gnus-summary-find-prev))
9770           (gnus-summary-catchup all t beg)))))
9771   (gnus-summary-position-point))
9772
9773 (defun gnus-summary-catchup-from-here (&optional all)
9774   "Mark all unticked articles after the current one as read.
9775 If ALL is non-nil, also mark ticked and dormant articles as read."
9776   (interactive "P")
9777   (save-excursion
9778     (gnus-save-hidden-threads
9779       (let ((beg (point)))
9780         ;; We check that there are unread articles.
9781         (when (or all (gnus-summary-find-next))
9782           (gnus-summary-catchup all t beg nil t)))))
9783   (gnus-summary-position-point))
9784
9785 (defun gnus-summary-catchup-all (&optional quietly)
9786   "Mark all articles in this newsgroup as read."
9787   (interactive "P")
9788   (gnus-summary-catchup t quietly))
9789
9790 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9791   "Mark all unread articles in this group as read, then exit.
9792 If prefix argument ALL is non-nil, all articles are marked as read.
9793 If QUIETLY is non-nil, no questions will be asked."
9794   (interactive "P")
9795   (when (gnus-summary-catchup all quietly nil 'fast)
9796     ;; Select next newsgroup or exit.
9797     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9798              (eq gnus-auto-select-next 'quietly))
9799         (gnus-summary-next-group nil)
9800       (gnus-summary-exit))))
9801
9802 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9803   "Mark all articles in this newsgroup as read, and then exit."
9804   (interactive "P")
9805   (gnus-summary-catchup-and-exit t quietly))
9806
9807 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9808   "Mark all articles in this group as read and select the next group.
9809 If given a prefix, mark all articles, unread as well as ticked, as
9810 read."
9811   (interactive "P")
9812   (save-excursion
9813     (gnus-summary-catchup all))
9814   (gnus-summary-next-group))
9815
9816 ;;;
9817 ;;; with article
9818 ;;;
9819
9820 (defmacro gnus-with-article (article &rest forms)
9821   "Select ARTICLE and perform FORMS in the original article buffer.
9822 Then replace the article with the result."
9823   `(progn
9824      ;; We don't want the article to be marked as read.
9825      (let (gnus-mark-article-hook)
9826        (gnus-summary-select-article t t nil ,article))
9827      (set-buffer gnus-original-article-buffer)
9828      ,@forms
9829      (if (not (gnus-check-backend-function
9830                'request-replace-article (car gnus-article-current)))
9831          (gnus-message 5 "Read-only group; not replacing")
9832        (unless (gnus-request-replace-article
9833                 ,article (car gnus-article-current)
9834                 (current-buffer) t)
9835          (error "Couldn't replace article")))
9836      ;; The cache and backlog have to be flushed somewhat.
9837      (when gnus-keep-backlog
9838        (gnus-backlog-remove-article
9839         (car gnus-article-current) (cdr gnus-article-current)))
9840      (when gnus-use-cache
9841        (gnus-cache-update-article
9842         (car gnus-article-current) (cdr gnus-article-current)))))
9843
9844 (put 'gnus-with-article 'lisp-indent-function 1)
9845 (put 'gnus-with-article 'edebug-form-spec '(form body))
9846
9847 ;; Thread-based commands.
9848
9849 (defun gnus-summary-articles-in-thread (&optional article)
9850   "Return a list of all articles in the current thread.
9851 If ARTICLE is non-nil, return all articles in the thread that starts
9852 with that article."
9853   (let* ((article (or article (gnus-summary-article-number)))
9854          (data (gnus-data-find-list article))
9855          (top-level (gnus-data-level (car data)))
9856          (top-subject
9857           (cond ((null gnus-thread-operation-ignore-subject)
9858                  (gnus-simplify-subject-re
9859                   (mail-header-subject (gnus-data-header (car data)))))
9860                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9861                  (gnus-simplify-subject-fuzzy
9862                   (mail-header-subject (gnus-data-header (car data)))))
9863                 (t nil)))
9864          (end-point (save-excursion
9865                       (if (gnus-summary-go-to-next-thread)
9866                           (point) (point-max))))
9867          articles)
9868     (while (and data
9869                 (< (gnus-data-pos (car data)) end-point))
9870       (when (or (not top-subject)
9871                 (string= top-subject
9872                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9873                              (gnus-simplify-subject-fuzzy
9874                               (mail-header-subject
9875                                (gnus-data-header (car data))))
9876                            (gnus-simplify-subject-re
9877                             (mail-header-subject
9878                              (gnus-data-header (car data)))))))
9879         (push (gnus-data-number (car data)) articles))
9880       (unless (and (setq data (cdr data))
9881                    (> (gnus-data-level (car data)) top-level))
9882         (setq data nil)))
9883     ;; Return the list of articles.
9884     (nreverse articles)))
9885
9886 (defun gnus-summary-rethread-current ()
9887   "Rethread the thread the current article is part of."
9888   (interactive)
9889   (let* ((gnus-show-threads t)
9890          (article (gnus-summary-article-number))
9891          (id (mail-header-id (gnus-summary-article-header)))
9892          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9893     (unless id
9894       (error "No article on the current line"))
9895     (gnus-rebuild-thread id)
9896     (gnus-summary-goto-subject article)))
9897
9898 (defun gnus-summary-reparent-thread ()
9899   "Make the current article child of the marked (or previous) article.
9900
9901 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9902 is non-nil or the Subject: of both articles are the same."
9903   (interactive)
9904   (unless (not (gnus-group-read-only-p))
9905     (error "The current newsgroup does not support article editing"))
9906   (unless (<= (length gnus-newsgroup-processable) 1)
9907     (error "No more than one article may be marked"))
9908   (save-window-excursion
9909     (let ((gnus-article-buffer " *reparent*")
9910           (current-article (gnus-summary-article-number))
9911           ;; First grab the marked article, otherwise one line up.
9912           (parent-article (if (not (null gnus-newsgroup-processable))
9913                               (car gnus-newsgroup-processable)
9914                             (save-excursion
9915                               (if (eq (forward-line -1) 0)
9916                                   (gnus-summary-article-number)
9917                                 (error "Beginning of summary buffer"))))))
9918       (unless (not (eq current-article parent-article))
9919         (error "An article may not be self-referential"))
9920       (let ((message-id (mail-header-id
9921                          (gnus-summary-article-header parent-article))))
9922         (unless (and message-id (not (equal message-id "")))
9923           (error "No message-id in desired parent"))
9924         (gnus-with-article current-article
9925           (save-restriction
9926             (goto-char (point-min))
9927             (message-narrow-to-head)
9928             (if (re-search-forward "^References: " nil t)
9929                 (progn
9930                   (re-search-forward "^[^ \t]" nil t)
9931                   (forward-line -1)
9932                   (end-of-line)
9933                   (insert " " message-id))
9934               (insert "References: " message-id "\n"))))
9935         (set-buffer gnus-summary-buffer)
9936         (gnus-summary-unmark-all-processable)
9937         (gnus-summary-update-article current-article)
9938         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9939             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9940         (gnus-summary-rethread-current)
9941         (gnus-message 3 "Article %d is now the child of article %d"
9942                       current-article parent-article)))))
9943
9944 (defun gnus-summary-toggle-threads (&optional arg)
9945   "Toggle showing conversation threads.
9946 If ARG is positive number, turn showing conversation threads on."
9947   (interactive "P")
9948   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9949     (setq gnus-show-threads
9950           (if (null arg) (not gnus-show-threads)
9951             (> (prefix-numeric-value arg) 0)))
9952     (gnus-summary-prepare)
9953     (gnus-summary-goto-subject current)
9954     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9955     (gnus-summary-position-point)))
9956
9957 (defun gnus-summary-show-all-threads ()
9958   "Show all threads."
9959   (interactive)
9960   (save-excursion
9961     (let ((buffer-read-only nil))
9962       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9963   (gnus-summary-position-point))
9964
9965 (defun gnus-summary-show-thread ()
9966   "Show thread subtrees.
9967 Returns nil if no thread was there to be shown."
9968   (interactive)
9969   (let ((buffer-read-only nil)
9970         (orig (point))
9971         ;; first goto end then to beg, to have point at beg after let
9972         (end (progn (end-of-line) (point)))
9973         (beg (progn (beginning-of-line) (point))))
9974     (prog1
9975         ;; Any hidden lines here?
9976         (search-forward "\r" end t)
9977       (subst-char-in-region beg end ?\^M ?\n t)
9978       (goto-char orig)
9979       (gnus-summary-position-point))))
9980
9981 (defun gnus-summary-maybe-hide-threads ()
9982   "If requested, hide the threads that should be hidden."
9983   (when (and gnus-show-threads
9984              gnus-thread-hide-subtree)
9985     (gnus-summary-hide-all-threads
9986      (if (or (consp gnus-thread-hide-subtree)
9987              (gnus-functionp gnus-thread-hide-subtree))
9988          (gnus-make-predicate gnus-thread-hide-subtree)
9989        nil))))
9990
9991 ;;; Hiding predicates.
9992
9993 (defun gnus-article-unread-p (header)
9994   (memq (mail-header-number header) gnus-newsgroup-unreads))
9995
9996 (defun gnus-article-unseen-p (header)
9997   (memq (mail-header-number header) gnus-newsgroup-unseen))
9998
9999 (defun gnus-map-articles (predicate articles)
10000   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10001   (apply 'gnus-or (mapcar predicate
10002                           (mapcar 'gnus-summary-article-header articles))))
10003
10004 (defun gnus-summary-hide-all-threads (&optional predicate)
10005   "Hide all thread subtrees.
10006 If PREDICATE is supplied, threads that satisfy this predicate
10007 will not be hidden."
10008   (interactive)
10009   (save-excursion
10010     (goto-char (point-min))
10011     (let ((end nil))
10012       (while (not end)
10013         (when (or (not predicate)
10014                   (gnus-map-articles
10015                    predicate (gnus-summary-article-children)))
10016             (gnus-summary-hide-thread))
10017         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10018   (gnus-summary-position-point))
10019
10020 (defun gnus-summary-hide-thread ()
10021   "Hide thread subtrees.
10022 If PREDICATE is supplied, threads that satisfy this predicate
10023 will not be hidden.
10024 Returns nil if no threads were there to be hidden."
10025   (interactive)
10026   (let ((buffer-read-only nil)
10027         (start (point))
10028         (article (gnus-summary-article-number)))
10029     (goto-char start)
10030     ;; Go forward until either the buffer ends or the subthread
10031     ;; ends.
10032     (when (and (not (eobp))
10033                (or (zerop (gnus-summary-next-thread 1 t))
10034                    (goto-char (point-max))))
10035       (prog1
10036           (if (and (> (point) start)
10037                    (search-backward "\n" start t))
10038               (progn
10039                 (subst-char-in-region start (point) ?\n ?\^M)
10040                 (gnus-summary-goto-subject article))
10041             (goto-char start)
10042             nil)))))
10043
10044 (defun gnus-summary-go-to-next-thread (&optional previous)
10045   "Go to the same level (or less) next thread.
10046 If PREVIOUS is non-nil, go to previous thread instead.
10047 Return the article number moved to, or nil if moving was impossible."
10048   (let ((level (gnus-summary-thread-level))
10049         (way (if previous -1 1))
10050         (beg (point)))
10051     (forward-line way)
10052     (while (and (not (eobp))
10053                 (< level (gnus-summary-thread-level)))
10054       (forward-line way))
10055     (if (eobp)
10056         (progn
10057           (goto-char beg)
10058           nil)
10059       (setq beg (point))
10060       (prog1
10061           (gnus-summary-article-number)
10062         (goto-char beg)))))
10063
10064 (defun gnus-summary-next-thread (n &optional silent)
10065   "Go to the same level next N'th thread.
10066 If N is negative, search backward instead.
10067 Returns the difference between N and the number of skips actually
10068 done.
10069
10070 If SILENT, don't output messages."
10071   (interactive "p")
10072   (let ((backward (< n 0))
10073         (n (abs n)))
10074     (while (and (> n 0)
10075                 (gnus-summary-go-to-next-thread backward))
10076       (decf n))
10077     (unless silent
10078       (gnus-summary-position-point))
10079     (when (and (not silent) (/= 0 n))
10080       (gnus-message 7 "No more threads"))
10081     n))
10082
10083 (defun gnus-summary-prev-thread (n)
10084   "Go to the same level previous N'th thread.
10085 Returns the difference between N and the number of skips actually
10086 done."
10087   (interactive "p")
10088   (gnus-summary-next-thread (- n)))
10089
10090 (defun gnus-summary-go-down-thread ()
10091   "Go down one level in the current thread."
10092   (let ((children (gnus-summary-article-children)))
10093     (when children
10094       (gnus-summary-goto-subject (car children)))))
10095
10096 (defun gnus-summary-go-up-thread ()
10097   "Go up one level in the current thread."
10098   (let ((parent (gnus-summary-article-parent)))
10099     (when parent
10100       (gnus-summary-goto-subject parent))))
10101
10102 (defun gnus-summary-down-thread (n)
10103   "Go down thread N steps.
10104 If N is negative, go up instead.
10105 Returns the difference between N and how many steps down that were
10106 taken."
10107   (interactive "p")
10108   (let ((up (< n 0))
10109         (n (abs n)))
10110     (while (and (> n 0)
10111                 (if up (gnus-summary-go-up-thread)
10112                   (gnus-summary-go-down-thread)))
10113       (setq n (1- n)))
10114     (gnus-summary-position-point)
10115     (when (/= 0 n)
10116       (gnus-message 7 "Can't go further"))
10117     n))
10118
10119 (defun gnus-summary-up-thread (n)
10120   "Go up thread N steps.
10121 If N is negative, go down instead.
10122 Returns the difference between N and how many steps down that were
10123 taken."
10124   (interactive "p")
10125   (gnus-summary-down-thread (- n)))
10126
10127 (defun gnus-summary-top-thread ()
10128   "Go to the top of the thread."
10129   (interactive)
10130   (while (gnus-summary-go-up-thread))
10131   (gnus-summary-article-number))
10132
10133 (defun gnus-summary-kill-thread (&optional unmark)
10134   "Mark articles under current thread as read.
10135 If the prefix argument is positive, remove any kinds of marks.
10136 If the prefix argument is negative, tick articles instead."
10137   (interactive "P")
10138   (when unmark
10139     (setq unmark (prefix-numeric-value unmark)))
10140   (let ((articles (gnus-summary-articles-in-thread)))
10141     (save-excursion
10142       ;; Expand the thread.
10143       (gnus-summary-show-thread)
10144       ;; Mark all the articles.
10145       (while articles
10146         (gnus-summary-goto-subject (car articles))
10147         (cond ((null unmark)
10148                (gnus-summary-mark-article-as-read gnus-killed-mark))
10149               ((> unmark 0)
10150                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10151               (t
10152                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10153         (setq articles (cdr articles))))
10154     ;; Hide killed subtrees.
10155     (and (null unmark)
10156          gnus-thread-hide-killed
10157          (gnus-summary-hide-thread))
10158     ;; If marked as read, go to next unread subject.
10159     (when (null unmark)
10160       ;; Go to next unread subject.
10161       (gnus-summary-next-subject 1 t)))
10162   (gnus-set-mode-line 'summary))
10163
10164 ;; Summary sorting commands
10165
10166 (defun gnus-summary-sort-by-number (&optional reverse)
10167   "Sort the summary buffer by article number.
10168 Argument REVERSE means reverse order."
10169   (interactive "P")
10170   (gnus-summary-sort 'number reverse))
10171
10172 (defun gnus-summary-sort-by-author (&optional reverse)
10173   "Sort the summary buffer by author name alphabetically.
10174 If `case-fold-search' is non-nil, case of letters is ignored.
10175 Argument REVERSE means reverse order."
10176   (interactive "P")
10177   (gnus-summary-sort 'author reverse))
10178
10179 (defun gnus-summary-sort-by-subject (&optional reverse)
10180   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10181 If `case-fold-search' is non-nil, case of letters is ignored.
10182 Argument REVERSE means reverse order."
10183   (interactive "P")
10184   (gnus-summary-sort 'subject reverse))
10185
10186 (defun gnus-summary-sort-by-date (&optional reverse)
10187   "Sort the summary buffer by date.
10188 Argument REVERSE means reverse order."
10189   (interactive "P")
10190   (gnus-summary-sort 'date reverse))
10191
10192 (defun gnus-summary-sort-by-score (&optional reverse)
10193   "Sort the summary buffer by score.
10194 Argument REVERSE means reverse order."
10195   (interactive "P")
10196   (gnus-summary-sort 'score reverse))
10197
10198 (defun gnus-summary-sort-by-lines (&optional reverse)
10199   "Sort the summary buffer by the number of lines.
10200 Argument REVERSE means reverse order."
10201   (interactive "P")
10202   (gnus-summary-sort 'lines reverse))
10203
10204 (defun gnus-summary-sort-by-chars (&optional reverse)
10205   "Sort the summary buffer by article length.
10206 Argument REVERSE means reverse order."
10207   (interactive "P")
10208   (gnus-summary-sort 'chars reverse))
10209
10210 (defun gnus-summary-sort-by-original (&optional reverse)
10211   "Sort the summary buffer using the default sorting method.
10212 Argument REVERSE means reverse order."
10213   (interactive "P")
10214   (let* ((buffer-read-only)
10215          (gnus-summary-prepare-hook nil))
10216     ;; We do the sorting by regenerating the threads.
10217     (gnus-summary-prepare)
10218     ;; Hide subthreads if needed.
10219     (gnus-summary-maybe-hide-threads)))
10220
10221 (defun gnus-summary-sort (predicate reverse)
10222   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10223   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10224          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10225          (gnus-thread-sort-functions
10226           (if (not reverse)
10227               thread
10228             `(lambda (t1 t2)
10229                (,thread t2 t1))))
10230          (gnus-sort-gathered-threads-function
10231           gnus-thread-sort-functions)
10232          (gnus-article-sort-functions
10233           (if (not reverse)
10234               article
10235             `(lambda (t1 t2)
10236                (,article t2 t1))))
10237          (buffer-read-only)
10238          (gnus-summary-prepare-hook nil))
10239     ;; We do the sorting by regenerating the threads.
10240     (gnus-summary-prepare)
10241     ;; Hide subthreads if needed.
10242     (gnus-summary-maybe-hide-threads)))
10243
10244 ;; Summary saving commands.
10245
10246 (defun gnus-summary-save-article (&optional n not-saved)
10247   "Save the current article using the default saver function.
10248 If N is a positive number, save the N next articles.
10249 If N is a negative number, save the N previous articles.
10250 If N is nil and any articles have been marked with the process mark,
10251 save those articles instead.
10252 The variable `gnus-default-article-saver' specifies the saver function."
10253   (interactive "P")
10254   (let* ((articles (gnus-summary-work-articles n))
10255          (save-buffer (save-excursion
10256                         (nnheader-set-temp-buffer " *Gnus Save*")))
10257          (num (length articles))
10258          header file)
10259     (dolist (article articles)
10260       (setq header (gnus-summary-article-header article))
10261       (if (not (vectorp header))
10262           ;; This is a pseudo-article.
10263           (if (assq 'name header)
10264               (gnus-copy-file (cdr (assq 'name header)))
10265             (gnus-message 1 "Article %d is unsaveable" article))
10266         ;; This is a real article.
10267         (save-window-excursion
10268           (let ((gnus-display-mime-function nil)
10269                 (gnus-article-prepare-hook nil))
10270             (gnus-summary-select-article t nil nil article)))
10271         (save-excursion
10272           (set-buffer save-buffer)
10273           (erase-buffer)
10274           (insert-buffer-substring gnus-original-article-buffer))
10275         (setq file (gnus-article-save save-buffer file num))
10276         (gnus-summary-remove-process-mark article)
10277         (unless not-saved
10278           (gnus-summary-set-saved-mark article))))
10279     (gnus-kill-buffer save-buffer)
10280     (gnus-summary-position-point)
10281     (gnus-set-mode-line 'summary)
10282     n))
10283
10284 (defun gnus-summary-pipe-output (&optional arg)
10285   "Pipe the current article to a subprocess.
10286 If N is a positive number, pipe the N next articles.
10287 If N is a negative number, pipe the N previous articles.
10288 If N is nil and any articles have been marked with the process mark,
10289 pipe those articles instead."
10290   (interactive "P")
10291   (require 'gnus-art)
10292   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10293     (gnus-summary-save-article arg t))
10294   (let ((buffer (get-buffer "*Shell Command Output*")))
10295     (if (and buffer
10296              (with-current-buffer buffer (> (point-max) (point-min))))
10297         (gnus-configure-windows 'pipe))))
10298
10299 (defun gnus-summary-save-article-mail (&optional arg)
10300   "Append the current article to an mail file.
10301 If N is a positive number, save the N next articles.
10302 If N is a negative number, save the N previous articles.
10303 If N is nil and any articles have been marked with the process mark,
10304 save those articles instead."
10305   (interactive "P")
10306   (require 'gnus-art)
10307   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10308     (gnus-summary-save-article arg)))
10309
10310 (defun gnus-summary-save-article-rmail (&optional arg)
10311   "Append the current article to an rmail file.
10312 If N is a positive number, save the N next articles.
10313 If N is a negative number, save the N previous articles.
10314 If N is nil and any articles have been marked with the process mark,
10315 save those articles instead."
10316   (interactive "P")
10317   (require 'gnus-art)
10318   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10319     (gnus-summary-save-article arg)))
10320
10321 (defun gnus-summary-save-article-file (&optional arg)
10322   "Append the current article to a file.
10323 If N is a positive number, save the N next articles.
10324 If N is a negative number, save the N previous articles.
10325 If N is nil and any articles have been marked with the process mark,
10326 save those articles instead."
10327   (interactive "P")
10328   (require 'gnus-art)
10329   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10330     (gnus-summary-save-article arg)))
10331
10332 (defun gnus-summary-write-article-file (&optional arg)
10333   "Write the current article to a file, deleting the previous file.
10334 If N is a positive number, save the N next articles.
10335 If N is a negative number, save the N previous articles.
10336 If N is nil and any articles have been marked with the process mark,
10337 save those articles instead."
10338   (interactive "P")
10339   (require 'gnus-art)
10340   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10341     (gnus-summary-save-article arg)))
10342
10343 (defun gnus-summary-save-article-body-file (&optional arg)
10344   "Append the current article body to a file.
10345 If N is a positive number, save the N next articles.
10346 If N is a negative number, save the N previous articles.
10347 If N is nil and any articles have been marked with the process mark,
10348 save those articles instead."
10349   (interactive "P")
10350   (require 'gnus-art)
10351   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10352     (gnus-summary-save-article arg)))
10353
10354 (defun gnus-summary-muttprint (&optional arg)
10355   "Print the current article using Muttprint.
10356 If N is a positive number, save the N next articles.
10357 If N is a negative number, save the N previous articles.
10358 If N is nil and any articles have been marked with the process mark,
10359 save those articles instead."
10360   (interactive "P")
10361   (require 'gnus-art)
10362   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10363     (gnus-summary-save-article arg t)))
10364
10365 (defun gnus-summary-pipe-message (program)
10366   "Pipe the current article through PROGRAM."
10367   (interactive "sProgram: ")
10368   (gnus-summary-select-article)
10369   (let ((mail-header-separator ""))
10370     (gnus-eval-in-buffer-window gnus-article-buffer
10371       (save-restriction
10372         (widen)
10373         (let ((start (window-start))
10374               buffer-read-only)
10375           (message-pipe-buffer-body program)
10376           (set-window-start (get-buffer-window (current-buffer)) start))))))
10377
10378 (defun gnus-get-split-value (methods)
10379   "Return a value based on the split METHODS."
10380   (let (split-name method result match)
10381     (when methods
10382       (save-excursion
10383         (set-buffer gnus-original-article-buffer)
10384         (save-restriction
10385           (nnheader-narrow-to-headers)
10386           (while (and methods (not split-name))
10387             (goto-char (point-min))
10388             (setq method (pop methods))
10389             (setq match (car method))
10390             (when (cond
10391                    ((stringp match)
10392                     ;; Regular expression.
10393                     (ignore-errors
10394                       (re-search-forward match nil t)))
10395                    ((gnus-functionp match)
10396                     ;; Function.
10397                     (save-restriction
10398                       (widen)
10399                       (setq result (funcall match gnus-newsgroup-name))))
10400                    ((consp match)
10401                     ;; Form.
10402                     (save-restriction
10403                       (widen)
10404                       (setq result (eval match)))))
10405               (setq split-name (cdr method))
10406               (cond ((stringp result)
10407                      (push (expand-file-name
10408                             result gnus-article-save-directory)
10409                            split-name))
10410                     ((consp result)
10411                      (setq split-name (append result split-name)))))))))
10412     (nreverse split-name)))
10413
10414 (defun gnus-valid-move-group-p (group)
10415   (and (boundp group)
10416        (symbol-name group)
10417        (symbol-value group)
10418        (gnus-get-function (gnus-find-method-for-group
10419                            (symbol-name group)) 'request-accept-article t)))
10420
10421 (defun gnus-read-move-group-name (prompt default articles prefix)
10422   "Read a group name."
10423   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10424          (minibuffer-confirm-incomplete nil) ; XEmacs
10425          (prom
10426           (format "%s %s to:"
10427                   prompt
10428                   (if (> (length articles) 1)
10429                       (format "these %d articles" (length articles))
10430                     "this article")))
10431          (to-newsgroup
10432           (cond
10433            ((null split-name)
10434             (gnus-completing-read-with-default
10435              default prom
10436              gnus-active-hashtb
10437              'gnus-valid-move-group-p
10438              nil prefix
10439              'gnus-group-history))
10440            ((= 1 (length split-name))
10441             (gnus-completing-read-with-default
10442              (car split-name) prom
10443              gnus-active-hashtb
10444              'gnus-valid-move-group-p
10445              nil nil
10446              'gnus-group-history))
10447            (t
10448             (gnus-completing-read-with-default
10449              nil prom
10450              (mapcar (lambda (el) (list el))
10451                      (nreverse split-name))
10452              nil nil nil
10453              'gnus-group-history))))
10454          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10455     (when to-newsgroup
10456       (if (or (string= to-newsgroup "")
10457               (string= to-newsgroup prefix))
10458           (setq to-newsgroup default))
10459       (unless to-newsgroup
10460         (error "No group name entered"))
10461       (or (gnus-active to-newsgroup)
10462           (gnus-activate-group to-newsgroup nil nil to-method)
10463           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10464                                      to-newsgroup))
10465               (or (and (gnus-request-create-group to-newsgroup to-method)
10466                        (gnus-activate-group
10467                         to-newsgroup nil nil to-method)
10468                        (gnus-subscribe-group to-newsgroup))
10469                   (error "Couldn't create group %s" to-newsgroup)))
10470           (error "No such group: %s" to-newsgroup)))
10471     to-newsgroup))
10472
10473 (defun gnus-summary-save-parts (type dir n &optional reverse)
10474   "Save parts matching TYPE to DIR.
10475 If REVERSE, save parts that do not match TYPE."
10476   (interactive
10477    (list (read-string "Save parts of type: "
10478                       (or (car gnus-summary-save-parts-type-history)
10479                           gnus-summary-save-parts-default-mime)
10480                       'gnus-summary-save-parts-type-history)
10481          (setq gnus-summary-save-parts-last-directory
10482                (read-file-name "Save to directory: "
10483                                gnus-summary-save-parts-last-directory
10484                                nil t))
10485          current-prefix-arg))
10486   (gnus-summary-iterate n
10487     (let ((gnus-display-mime-function nil)
10488           (gnus-inhibit-treatment t))
10489       (gnus-summary-select-article))
10490     (save-excursion
10491       (set-buffer gnus-article-buffer)
10492       (let ((handles (or gnus-article-mime-handles
10493                          (mm-dissect-buffer nil gnus-article-loose-mime)
10494                          (mm-uu-dissect))))
10495         (when handles
10496           (gnus-summary-save-parts-1 type dir handles reverse)
10497           (unless gnus-article-mime-handles ;; Don't destroy this case.
10498             (mm-destroy-parts handles)))))))
10499
10500 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10501   (if (stringp (car handle))
10502       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10503               (cdr handle))
10504     (when (if reverse
10505               (not (string-match type (mm-handle-media-type handle)))
10506             (string-match type (mm-handle-media-type handle)))
10507       (let ((file (expand-file-name
10508                    (file-name-nondirectory
10509                     (or
10510                      (mail-content-type-get
10511                       (mm-handle-disposition handle) 'filename)
10512                      (concat gnus-newsgroup-name
10513                              "." (number-to-string
10514                                   (cdr gnus-article-current)))))
10515                    dir)))
10516         (unless (file-exists-p file)
10517           (mm-save-part-to-file handle file))))))
10518
10519 ;; Summary extract commands
10520
10521 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10522   (let ((buffer-read-only nil)
10523         (article (gnus-summary-article-number))
10524         after-article b e)
10525     (unless (gnus-summary-goto-subject article)
10526       (error "No such article: %d" article))
10527     (gnus-summary-position-point)
10528     ;; If all commands are to be bunched up on one line, we collect
10529     ;; them here.
10530     (unless gnus-view-pseudos-separately
10531       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10532             files action)
10533         (while ps
10534           (setq action (cdr (assq 'action (car ps))))
10535           (setq files (list (cdr (assq 'name (car ps)))))
10536           (while (and ps (cdr ps)
10537                       (string= (or action "1")
10538                                (or (cdr (assq 'action (cadr ps))) "2")))
10539             (push (cdr (assq 'name (cadr ps))) files)
10540             (setcdr ps (cddr ps)))
10541           (when files
10542             (when (not (string-match "%s" action))
10543               (push " " files))
10544             (push " " files)
10545             (when (assq 'execute (car ps))
10546               (setcdr (assq 'execute (car ps))
10547                       (funcall (if (string-match "%s" action)
10548                                    'format 'concat)
10549                                action
10550                                (mapconcat
10551                                 (lambda (f)
10552                                   (if (equal f " ")
10553                                       f
10554                                     (gnus-quote-arg-for-sh-or-csh f)))
10555                                 files " ")))))
10556           (setq ps (cdr ps)))))
10557     (if (and gnus-view-pseudos (not not-view))
10558         (while pslist
10559           (when (assq 'execute (car pslist))
10560             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10561                                   (eq gnus-view-pseudos 'not-confirm)))
10562           (setq pslist (cdr pslist)))
10563       (save-excursion
10564         (while pslist
10565           (setq after-article (or (cdr (assq 'article (car pslist)))
10566                                   (gnus-summary-article-number)))
10567           (gnus-summary-goto-subject after-article)
10568           (forward-line 1)
10569           (setq b (point))
10570           (insert "    " (file-name-nondirectory
10571                           (cdr (assq 'name (car pslist))))
10572                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10573           (setq e (point))
10574           (forward-line -1)             ; back to `b'
10575           (gnus-add-text-properties
10576            b (1- e) (list 'gnus-number gnus-reffed-article-number
10577                           gnus-mouse-face-prop gnus-mouse-face))
10578           (gnus-data-enter
10579            after-article gnus-reffed-article-number
10580            gnus-unread-mark b (car pslist) 0 (- e b))
10581           (setq gnus-newsgroup-unreads
10582                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10583                                          gnus-reffed-article-number))
10584           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10585           (setq pslist (cdr pslist)))))))
10586
10587 (defun gnus-pseudos< (p1 p2)
10588   (let ((c1 (cdr (assq 'action p1)))
10589         (c2 (cdr (assq 'action p2))))
10590     (and c1 c2 (string< c1 c2))))
10591
10592 (defun gnus-request-pseudo-article (props)
10593   (cond ((assq 'execute props)
10594          (gnus-execute-command (cdr (assq 'execute props)))))
10595   (let ((gnus-current-article (gnus-summary-article-number)))
10596     (gnus-run-hooks 'gnus-mark-article-hook)))
10597
10598 (defun gnus-execute-command (command &optional automatic)
10599   (save-excursion
10600     (gnus-article-setup-buffer)
10601     (set-buffer gnus-article-buffer)
10602     (setq buffer-read-only nil)
10603     (let ((command (if automatic command
10604                      (read-string "Command: " (cons command 0)))))
10605       (erase-buffer)
10606       (insert "$ " command "\n\n")
10607       (if gnus-view-pseudo-asynchronously
10608           (start-process "gnus-execute" (current-buffer) shell-file-name
10609                          shell-command-switch command)
10610         (call-process shell-file-name nil t nil
10611                       shell-command-switch command)))))
10612
10613 ;; Summary kill commands.
10614
10615 (defun gnus-summary-edit-global-kill (article)
10616   "Edit the \"global\" kill file."
10617   (interactive (list (gnus-summary-article-number)))
10618   (gnus-group-edit-global-kill article))
10619
10620 (defun gnus-summary-edit-local-kill ()
10621   "Edit a local kill file applied to the current newsgroup."
10622   (interactive)
10623   (setq gnus-current-headers (gnus-summary-article-header))
10624   (gnus-group-edit-local-kill
10625    (gnus-summary-article-number) gnus-newsgroup-name))
10626
10627 ;;; Header reading.
10628
10629 (defun gnus-read-header (id &optional header)
10630   "Read the headers of article ID and enter them into the Gnus system."
10631   (let ((group gnus-newsgroup-name)
10632         (gnus-override-method
10633          (or
10634           gnus-override-method
10635           (and (gnus-news-group-p gnus-newsgroup-name)
10636                (car (gnus-refer-article-methods)))))
10637         where)
10638     ;; First we check to see whether the header in question is already
10639     ;; fetched.
10640     (if (stringp id)
10641         ;; This is a Message-ID.
10642         (setq header (or header (gnus-id-to-header id)))
10643       ;; This is an article number.
10644       (setq header (or header (gnus-summary-article-header id))))
10645     (if (and header
10646              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10647         ;; We have found the header.
10648         header
10649       ;; If this is a sparse article, we have to nix out its
10650       ;; previous entry in the thread hashtb.
10651       (when (and header
10652                  (gnus-summary-article-sparse-p (mail-header-number header)))
10653         (let* ((parent (gnus-parent-id (mail-header-references header)))
10654                (thread (and parent (gnus-id-to-thread parent))))
10655           (when thread
10656             (delq (assq header thread) thread))))
10657       ;; We have to really fetch the header to this article.
10658       (save-excursion
10659         (set-buffer nntp-server-buffer)
10660         (when (setq where (gnus-request-head id group))
10661           (nnheader-fold-continuation-lines)
10662           (goto-char (point-max))
10663           (insert ".\n")
10664           (goto-char (point-min))
10665           (insert "211 ")
10666           (princ (cond
10667                   ((numberp id) id)
10668                   ((cdr where) (cdr where))
10669                   (header (mail-header-number header))
10670                   (t gnus-reffed-article-number))
10671                  (current-buffer))
10672           (insert " Article retrieved.\n"))
10673         (if (or (not where)
10674                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10675             ()                          ; Malformed head.
10676           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10677             (when (and (stringp id)
10678                        (not (string= (gnus-group-real-name group)
10679                                      (car where))))
10680               ;; If we fetched by Message-ID and the article came
10681               ;; from a different group, we fudge some bogus article
10682               ;; numbers for this article.
10683               (mail-header-set-number header gnus-reffed-article-number))
10684             (save-excursion
10685               (set-buffer gnus-summary-buffer)
10686               (decf gnus-reffed-article-number)
10687               (gnus-remove-header (mail-header-number header))
10688               (push header gnus-newsgroup-headers)
10689               (setq gnus-current-headers header)
10690               (push (mail-header-number header) gnus-newsgroup-limit)))
10691           header)))))
10692
10693 (defun gnus-remove-header (number)
10694   "Remove header NUMBER from `gnus-newsgroup-headers'."
10695   (if (and gnus-newsgroup-headers
10696            (= number (mail-header-number (car gnus-newsgroup-headers))))
10697       (pop gnus-newsgroup-headers)
10698     (let ((headers gnus-newsgroup-headers))
10699       (while (and (cdr headers)
10700                   (not (= number (mail-header-number (cadr headers)))))
10701         (pop headers))
10702       (when (cdr headers)
10703         (setcdr headers (cddr headers))))))
10704
10705 ;;;
10706 ;;; summary highlights
10707 ;;;
10708
10709 (defun gnus-highlight-selected-summary ()
10710   "Highlight selected article in summary buffer."
10711   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10712   (when gnus-summary-selected-face
10713     (save-excursion
10714       (let* ((beg (progn (beginning-of-line) (point)))
10715              (end (progn (end-of-line) (point)))
10716              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10717              (from (if (get-text-property beg gnus-mouse-face-prop)
10718                        beg
10719                      (or (next-single-property-change
10720                           beg gnus-mouse-face-prop nil end)
10721                          beg)))
10722              (to
10723               (if (= from end)
10724                   (- from 2)
10725                 (or (next-single-property-change
10726                      from gnus-mouse-face-prop nil end)
10727                     end))))
10728         ;; If no mouse-face prop on line we will have to = from = end,
10729         ;; so we highlight the entire line instead.
10730         (when (= (+ to 2) from)
10731           (setq from beg)
10732           (setq to end))
10733         (if gnus-newsgroup-selected-overlay
10734             ;; Move old overlay.
10735             (gnus-move-overlay
10736              gnus-newsgroup-selected-overlay from to (current-buffer))
10737           ;; Create new overlay.
10738           (gnus-overlay-put
10739            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10740            'face gnus-summary-selected-face))))))
10741
10742 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10743 (defun gnus-summary-highlight-line ()
10744   "Highlight current line according to `gnus-summary-highlight'."
10745   (let* ((list gnus-summary-highlight)
10746          (p (point))
10747          (end (progn (end-of-line) (point)))
10748          ;; now find out where the line starts and leave point there.
10749          (beg (progn (beginning-of-line) (point)))
10750          (article (gnus-summary-article-number))
10751          (score (or (cdr (assq (or article gnus-current-article)
10752                                gnus-newsgroup-scored))
10753                     gnus-summary-default-score 0))
10754          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10755          (inhibit-read-only t))
10756     ;; Eval the cars of the lists until we find a match.
10757     (let ((default gnus-summary-default-score)
10758           (default-high gnus-summary-default-high-score)
10759           (default-low gnus-summary-default-low-score))
10760       (while (and list
10761                   (not (eval (caar list))))
10762         (setq list (cdr list))))
10763     (let ((face (cdar list)))
10764       (unless (eq face (get-text-property beg 'face))
10765         (gnus-put-text-property-excluding-characters-with-faces
10766          beg end 'face
10767          (setq face (if (boundp face) (symbol-value face) face)))
10768         (when gnus-summary-highlight-line-function
10769           (funcall gnus-summary-highlight-line-function article face))))
10770     (goto-char p)))
10771
10772 (defun gnus-update-read-articles (group unread &optional compute)
10773   "Update the list of read articles in GROUP.
10774 UNREAD is a sorted list."
10775   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10776          (entry (gnus-gethash group gnus-newsrc-hashtb))
10777          (info (nth 2 entry))
10778          (prev 1)
10779          read)
10780     (if (or (not info) (not active))
10781         ;; There is no info on this group if it was, in fact,
10782         ;; killed.  Gnus stores no information on killed groups, so
10783         ;; there's nothing to be done.
10784         ;; One could store the information somewhere temporarily,
10785         ;; perhaps...  Hmmm...
10786         ()
10787       ;; Remove any negative articles numbers.
10788       (while (and unread (< (car unread) 0))
10789         (setq unread (cdr unread)))
10790       ;; Remove any expired article numbers
10791       (while (and unread (< (car unread) (car active)))
10792         (setq unread (cdr unread)))
10793       ;; Compute the ranges of read articles by looking at the list of
10794       ;; unread articles.
10795       (while unread
10796         (when (/= (car unread) prev)
10797           (push (if (= prev (1- (car unread))) prev
10798                   (cons prev (1- (car unread))))
10799                 read))
10800         (setq prev (1+ (car unread)))
10801         (setq unread (cdr unread)))
10802       (when (<= prev (cdr active))
10803         (push (cons prev (cdr active)) read))
10804       (setq read (if (> (length read) 1) (nreverse read) read))
10805       (if compute
10806           read
10807         (save-excursion
10808           (let (setmarkundo)
10809             ;; Propagate the read marks to the backend.
10810             (when (gnus-check-backend-function 'request-set-mark group)
10811               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10812                     (add (gnus-remove-from-range read (gnus-info-read info))))
10813                 (when (or add del)
10814                   (unless (gnus-check-group group)
10815                     (error "Can't open server for %s" group))
10816                   (gnus-request-set-mark
10817                    group (delq nil (list (if add (list add 'add '(read)))
10818                                          (if del (list del 'del '(read))))))
10819                   (setq setmarkundo
10820                         `(gnus-request-set-mark
10821                           ,group
10822                           ',(delq nil (list
10823                                        (if del (list del 'add '(read)))
10824                                        (if add (list add 'del '(read))))))))))
10825             (set-buffer gnus-group-buffer)
10826             (gnus-undo-register
10827               `(progn
10828                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10829                  (gnus-info-set-read ',info ',(gnus-info-read info))
10830                  (gnus-get-unread-articles-in-group ',info
10831                                                     (gnus-active ,group))
10832                  (gnus-group-update-group ,group t)
10833                  ,setmarkundo))))
10834         ;; Enter this list into the group info.
10835         (gnus-info-set-read info read)
10836         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10837         (gnus-get-unread-articles-in-group info (gnus-active group))
10838         t))))
10839
10840 (defun gnus-offer-save-summaries ()
10841   "Offer to save all active summary buffers."
10842   (let (buffers)
10843     ;; Go through all buffers and find all summaries.
10844     (dolist (buffer (buffer-list))
10845       (when (and (setq buffer (buffer-name buffer))
10846                  (string-match "Summary" buffer)
10847                  (save-excursion
10848                    (set-buffer buffer)
10849                    ;; We check that this is, indeed, a summary buffer.
10850                    (and (eq major-mode 'gnus-summary-mode)
10851                         ;; Also make sure this isn't bogus.
10852                         gnus-newsgroup-prepared
10853                         ;; Also make sure that this isn't a
10854                         ;; dead summary buffer.
10855                         (not gnus-dead-summary-mode))))
10856         (push buffer buffers)))
10857     ;; Go through all these summary buffers and offer to save them.
10858     (when buffers
10859       (save-excursion
10860         (map-y-or-n-p
10861          "Update summary buffer %s? "
10862          (lambda (buf)
10863            (switch-to-buffer buf)
10864            (gnus-summary-exit))
10865          buffers)))))
10866
10867
10868 ;;; @ for mime-partial
10869 ;;;
10870
10871 (defun gnus-request-partial-message ()
10872   (save-excursion
10873     (let ((number (gnus-summary-article-number))
10874           (group gnus-newsgroup-name)
10875           (mother gnus-article-buffer))
10876       (set-buffer (get-buffer-create " *Partial Article*"))
10877       (erase-buffer)
10878       (setq mime-preview-buffer mother)
10879       (gnus-request-article-this-buffer number group)
10880       (mime-parse-buffer)
10881       )))
10882
10883 (autoload 'mime-combine-message/partial-pieces-automatically
10884   "mime-partial"
10885   "Internal method to combine message/partial messages automatically.")
10886
10887 (mime-add-condition
10888  'action '((type . message)(subtype . partial)
10889            (major-mode . gnus-original-article-mode)
10890            (method . mime-combine-message/partial-pieces-automatically)
10891            (summary-buffer-exp . gnus-summary-buffer)
10892            (request-partial-message-method . gnus-request-partial-message)
10893            ))
10894
10895
10896 ;;; @ for message/rfc822
10897 ;;;
10898
10899 (defun gnus-mime-extract-message/rfc822 (entity situation)
10900   "Burst a forwarded article."
10901   (save-excursion
10902     (set-buffer gnus-summary-buffer)
10903     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10904                                    gnus-newsgroup-name 'gnus-group-history))
10905            (gnus-group-marked (list group))
10906            article info)
10907       (with-temp-buffer
10908         (mime-insert-entity-content entity)
10909         (setq article (gnus-request-accept-article group)))
10910       (when (and (consp article)
10911                  (numberp (setq article (cdr article))))
10912         (setq info (gnus-get-info group))
10913         (gnus-info-set-read info
10914                             (gnus-remove-from-range (gnus-info-read info)
10915                                                     (list article)))
10916         (when (string-equal group gnus-newsgroup-name)
10917           (forward-line 1)
10918           (let (gnus-show-threads)
10919             (gnus-summary-goto-subject article t))
10920           (gnus-summary-clear-mark-forward 1))
10921         (set-buffer gnus-group-buffer)
10922         (gnus-group-get-new-news-this-group nil t)))))
10923
10924 (mime-add-condition
10925  'action '((type . message)(subtype . rfc822)
10926            (major-mode . gnus-original-article-mode)
10927            (method . gnus-mime-extract-message/rfc822)
10928            (mode . "extract")
10929            ))
10930
10931 (mime-add-condition
10932  'action '((type . message)(subtype . news)
10933            (major-mode . gnus-original-article-mode)
10934            (method . gnus-mime-extract-message/rfc822)
10935            (mode . "extract")
10936            ))
10937
10938 (defun gnus-mime-extract-multipart (entity situation)
10939   (let ((children (mime-entity-children entity))
10940         mime-acting-situation-to-override
10941         f)
10942     (while children
10943       (mime-play-entity (car children)
10944                         (cons (assq 'mode situation)
10945                               mime-acting-situation-to-override))
10946       (setq children (cdr children)))
10947     (if (setq f (cdr (assq 'after-method
10948                            mime-acting-situation-to-override)))
10949         (eval f)
10950       )))
10951
10952 (mime-add-condition
10953  'action '((type . multipart)
10954            (method . gnus-mime-extract-multipart)
10955            (mode . "extract")
10956            )
10957  'with-default)
10958
10959
10960 ;;; @ end
10961 ;;;
10962
10963 (defun gnus-summary-setup-default-charset ()
10964   "Setup newsgroup default charset."
10965   (if (equal gnus-newsgroup-name "nndraft:drafts")
10966       (setq gnus-newsgroup-charset nil)
10967     (let* ((ignored-charsets
10968             (or gnus-newsgroup-ephemeral-ignored-charsets
10969                 (append
10970                  (and gnus-newsgroup-name
10971                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10972                  gnus-newsgroup-ignored-charsets))))
10973       (setq gnus-newsgroup-charset
10974             (or gnus-newsgroup-ephemeral-charset
10975                 (and gnus-newsgroup-name
10976                      (gnus-parameter-charset gnus-newsgroup-name))
10977                 gnus-default-charset))
10978       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10979            ignored-charsets))))
10980
10981 ;;;
10982 ;;; Mime Commands
10983 ;;;
10984
10985 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10986   "Display the current article buffer fully MIME-buttonized.
10987 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10988 treated as multipart/mixed."
10989   (interactive "P")
10990   (require 'gnus-art)
10991   (let ((gnus-unbuttonized-mime-types nil)
10992         (gnus-mime-display-multipart-as-mixed show-all-parts))
10993     (gnus-summary-show-article)))
10994
10995 (defun gnus-summary-repair-multipart (article)
10996   "Add a Content-Type header to a multipart article without one."
10997   (interactive (list (gnus-summary-article-number)))
10998   (gnus-with-article article
10999     (message-narrow-to-head)
11000     (message-remove-header "Mime-Version")
11001     (goto-char (point-max))
11002     (insert "Mime-Version: 1.0\n")
11003     (widen)
11004     (when (search-forward "\n--" nil t)
11005       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11006         (message-narrow-to-head)
11007         (message-remove-header "Content-Type")
11008         (goto-char (point-max))
11009         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11010                         separator))
11011         (widen))))
11012   (let (gnus-mark-article-hook)
11013     (gnus-summary-select-article t t nil article)))
11014
11015 (defun gnus-summary-toggle-display-buttonized ()
11016   "Toggle the buttonizing of the article buffer."
11017   (interactive)
11018   (require 'gnus-art)
11019   (if (setq gnus-inhibit-mime-unbuttonizing
11020             (not gnus-inhibit-mime-unbuttonizing))
11021       (let ((gnus-unbuttonized-mime-types nil))
11022         (gnus-summary-show-article))
11023     (gnus-summary-show-article)))
11024
11025 ;;;
11026 ;;; Intelli-mouse commmands
11027 ;;;
11028
11029 (defun gnus-wheel-summary-scroll (event)
11030   (interactive "e")
11031   (let ((amount (if (memq 'shift (event-modifiers event))
11032                     (car gnus-wheel-scroll-amount)
11033                   (cdr gnus-wheel-scroll-amount)))
11034         (direction (- (* (static-if (featurep 'xemacs)
11035                              (event-button event)
11036                            (cond ((eq 'mouse-4 (event-basic-type event))
11037                                   4)
11038                                  ((eq 'mouse-5 (event-basic-type event))
11039                                   5)))
11040                          2) 9))
11041         edge)
11042     (gnus-summary-scroll-up (* amount direction))
11043     (when (gnus-eval-in-buffer-window gnus-article-buffer
11044             (save-restriction
11045               (widen)
11046               (and (if (< 0 direction)
11047                        (gnus-article-next-page 0)
11048                      (gnus-article-prev-page 0)
11049                      (bobp))
11050                    (if (setq edge (get-text-property
11051                                    (point-min) 'gnus-wheel-edge))
11052                        (setq edge (* edge direction))
11053                      (setq edge -1))
11054                    (or (plusp edge)
11055                        (let ((buffer-read-only nil)
11056                              (inhibit-read-only t))
11057                          (put-text-property (point-min) (point-max)
11058                                             'gnus-wheel-edge direction)
11059                          nil))
11060                    (or (> edge gnus-wheel-edge-resistance)
11061                        (let ((buffer-read-only nil)
11062                              (inhibit-read-only t))
11063                          (put-text-property (point-min) (point-max)
11064                                             'gnus-wheel-edge
11065                                             (* (1+ edge) direction))
11066                          nil))
11067                    (eq last-command 'gnus-wheel-summary-scroll))))
11068       (gnus-summary-next-article nil nil (minusp direction)))))
11069
11070 (defun gnus-wheel-install ()
11071   "Enable mouse wheel support on summary window."
11072   (when gnus-use-wheel
11073     (let ((keys
11074            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11075       (dolist (key keys)
11076         (define-key gnus-summary-mode-map key
11077           'gnus-wheel-summary-scroll)))))
11078
11079 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11080
11081 ;;;
11082 ;;; Traditional PGP commmands
11083 ;;;
11084
11085 (defun gnus-summary-decrypt-article (&optional force)
11086   "Decrypt the current article in traditional PGP way.
11087 This will have permanent effect only in mail groups.
11088 If FORCE is non-nil, allow editing of articles even in read-only
11089 groups."
11090   (interactive "P")
11091   (gnus-summary-select-article t)
11092   (gnus-eval-in-buffer-window gnus-article-buffer
11093     (save-excursion
11094       (save-restriction
11095         (widen)
11096         (goto-char (point-min))
11097         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11098           (error "Not a traditional PGP message!"))
11099         (let ((armor-start (match-beginning 0)))
11100           (if (and (pgg-decrypt-region armor-start (point-max))
11101                    (or force (not (gnus-group-read-only-p))))
11102               (let ((inhibit-read-only t)
11103                     buffer-read-only)
11104                 (delete-region armor-start
11105                                (progn
11106                                  (re-search-forward "^-+END PGP" nil t)
11107                                  (beginning-of-line 2)
11108                                  (point)))
11109                 (insert-buffer-substring pgg-output-buffer))))))))
11110
11111 (defun gnus-summary-verify-article ()
11112   "Verify the current article in traditional PGP way."
11113   (interactive)
11114   (save-excursion
11115     (set-buffer gnus-original-article-buffer)
11116     (goto-char (point-min))
11117     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11118       (error "Not a traditional PGP message!"))
11119     (re-search-forward "^-+END PGP" nil t)
11120     (beginning-of-line 2)
11121     (call-interactively (function pgg-verify-region))))
11122
11123 ;;;
11124 ;;; Generic summary marking commands
11125 ;;;
11126
11127 (defvar gnus-summary-marking-alist
11128   '((read gnus-del-mark "d")
11129     (unread gnus-unread-mark "u")
11130     (ticked gnus-ticked-mark "!")
11131     (dormant gnus-dormant-mark "?")
11132     (expirable gnus-expirable-mark "e"))
11133   "An alist of names/marks/keystrokes.")
11134
11135 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11136 (defvar gnus-summary-mark-map)
11137
11138 (defun gnus-summary-make-all-marking-commands ()
11139   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11140   (dolist (elem gnus-summary-marking-alist)
11141     (apply 'gnus-summary-make-marking-command elem)))
11142
11143 (defun gnus-summary-make-marking-command (name mark keystroke)
11144   (let ((map (make-sparse-keymap)))
11145     (define-key gnus-summary-generic-mark-map keystroke map)
11146     (dolist (lway `((next "next" next nil "n")
11147                     (next-unread "next unread" next t "N")
11148                     (prev "previous" prev nil "p")
11149                     (prev-unread "previous unread" prev t "P")
11150                     (nomove "" nil nil ,keystroke)))
11151       (let ((func (gnus-summary-make-marking-command-1
11152                    mark (car lway) lway name)))
11153         (setq func (eval func))
11154         (define-key map (nth 4 lway) func)))))
11155
11156 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11157   `(defun ,(intern
11158             (format "gnus-summary-put-mark-as-%s%s"
11159                     name (if (eq way 'nomove)
11160                              ""
11161                            (concat "-" (symbol-name way)))))
11162      (n)
11163      ,(format
11164        "Mark the current article as %s%s.
11165 If N, the prefix, then repeat N times.
11166 If N is negative, move in reverse order.
11167 The difference between N and the actual number of articles marked is
11168 returned."
11169        name (car (cdr lway)))
11170      (interactive "p")
11171      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11172
11173 (defun gnus-summary-generic-mark (n mark move unread)
11174   "Mark N articles with MARK."
11175   (unless (eq major-mode 'gnus-summary-mode)
11176     (error "This command can only be used in the summary buffer"))
11177   (gnus-summary-show-thread)
11178   (let ((nummove
11179          (cond
11180           ((eq move 'next) 1)
11181           ((eq move 'prev) -1)
11182           (t 0))))
11183     (if (zerop nummove)
11184         (setq n 1)
11185       (when (< n 0)
11186         (setq n (abs n)
11187               nummove (* -1 nummove))))
11188     (while (and (> n 0)
11189                 (gnus-summary-mark-article nil mark)
11190                 (zerop (gnus-summary-next-subject nummove unread t)))
11191       (setq n (1- n)))
11192     (when (/= 0 n)
11193       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11194     (gnus-summary-recenter)
11195     (gnus-summary-position-point)
11196     (gnus-set-mode-line 'summary)
11197     n))
11198
11199 (defun gnus-summary-insert-articles (articles)
11200   (when (setq articles
11201               (gnus-sorted-difference articles
11202                                       (mapcar (lambda (h)
11203                                                 (mail-header-number h))
11204                                               gnus-newsgroup-headers)))
11205     (setq gnus-newsgroup-headers
11206           (merge 'list
11207                  gnus-newsgroup-headers
11208                  (gnus-fetch-headers articles)
11209                  'gnus-article-sort-by-number))
11210     ;; Suppress duplicates?
11211     (when gnus-suppress-duplicates
11212       (gnus-dup-suppress-articles))
11213
11214     ;; We might want to build some more threads first.
11215     (when (and gnus-fetch-old-headers
11216                (eq gnus-headers-retrieved-by 'nov))
11217       (if (eq gnus-fetch-old-headers 'invisible)
11218           (gnus-build-all-threads)
11219         (gnus-build-old-threads)))
11220     ;; Let the Gnus agent mark articles as read.
11221     (when gnus-agent
11222       (gnus-agent-get-undownloaded-list))
11223     ;; Remove list identifiers from subject
11224     (when gnus-list-identifiers
11225       (gnus-summary-remove-list-identifiers))
11226     ;; First and last article in this newsgroup.
11227     (when gnus-newsgroup-headers
11228       (setq gnus-newsgroup-begin
11229             (mail-header-number (car gnus-newsgroup-headers))
11230             gnus-newsgroup-end
11231             (mail-header-number
11232              (gnus-last-element gnus-newsgroup-headers))))
11233     (when gnus-use-scoring
11234       (gnus-possibly-score-headers))))
11235
11236 (defun gnus-summary-insert-old-articles (&optional all)
11237   "Insert all old articles in this group.
11238 If ALL is non-nil, already read articles become readable.
11239 If ALL is a number, fetch this number of articles."
11240   (interactive "P")
11241   (prog1
11242       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11243             older len)
11244         (setq older
11245               (gnus-sorted-difference
11246                (gnus-uncompress-range (list gnus-newsgroup-active))
11247                old))
11248         (setq len (length older))
11249         (cond
11250          ((null older) nil)
11251          ((numberp all)
11252           (if (< all len)
11253               (setq older (last older all))))
11254          (all nil)
11255          (t
11256           (if (and (numberp gnus-large-newsgroup)
11257                    (> len gnus-large-newsgroup))
11258               (let* ((cursor-in-echo-area nil)
11259                      (initial (gnus-parameter-large-newsgroup-initial 
11260                                gnus-newsgroup-name))
11261                      (input
11262                       (read-string
11263                        (format
11264                         "How many articles from %s (%s %d): "
11265                         (gnus-limit-string
11266                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11267                         (if initial "max" "default")
11268                         len)
11269                        (if initial
11270                            (cons (number-to-string initial)
11271                                  0)))))
11272                 (unless (string-match "^[ \t]*$" input)
11273                   (setq all (string-to-number input))
11274                   (if (< all len)
11275                       (setq older (last older all))))))))
11276         (if (not older)
11277             (message "No old news.")
11278           (gnus-summary-insert-articles older)
11279           (gnus-summary-limit (gnus-sorted-nunion old older))))
11280     (gnus-summary-position-point)))
11281
11282 (defun gnus-summary-insert-new-articles ()
11283   "Insert all new articles in this group."
11284   (interactive)
11285   (prog1
11286       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11287             (old-active gnus-newsgroup-active)
11288             (nnmail-fetched-sources (list t))
11289             i new)
11290         (setq gnus-newsgroup-active
11291               (gnus-activate-group gnus-newsgroup-name 'scan))
11292         (setq i (1+ (cdr old-active)))
11293         (while (<= i (cdr gnus-newsgroup-active))
11294           (push i new)
11295           (incf i))
11296         (if (not new)
11297             (message "No gnus is bad news.")
11298           (setq new (nreverse new))
11299           (gnus-summary-insert-articles new)
11300           (setq gnus-newsgroup-unreads
11301                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11302           (gnus-summary-limit (gnus-sorted-nunion old new))))
11303     (gnus-summary-position-point)))
11304
11305 (gnus-summary-make-all-marking-commands)
11306
11307 (gnus-ems-redefine)
11308
11309 (provide 'gnus-sum)
11310
11311 (run-hooks 'gnus-sum-load-hook)
11312
11313 ;;; gnus-sum.el ends here