Sync up with Pterodactyl Gnus v0.52.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mime-view)
39
40 ;; Avoid byte-compile warnings.
41 (eval-when-compile
42   (defvar gnus-article-decoded-p)
43   (defvar gnus-decode-encoded-word-function)
44   )
45
46 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
47 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
48
49 (defcustom gnus-kill-summary-on-exit t
50   "*If non-nil, kill the summary buffer when you exit from it.
51 If nil, the summary will become a \"*Dead Summary*\" buffer, and
52 it will be killed sometime later."
53   :group 'gnus-summary-exit
54   :type 'boolean)
55
56 (defcustom gnus-fetch-old-headers nil
57   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
58 If an unread article in the group refers to an older, already read (or
59 just marked as read) article, the old article will not normally be
60 displayed in the Summary buffer.  If this variable is non-nil, Gnus
61 will attempt to grab the headers to the old articles, and thereby
62 build complete threads.  If it has the value `some', only enough
63 headers to connect otherwise loose threads will be displayed.  This
64 variable can also be a number.  In that case, no more than that number
65 of old headers will be fetched.  If it has the value `invisible', all
66 old headers will be fetched, but none will be displayed.
67
68 The server has to support NOV for any of this to work."
69   :group 'gnus-thread
70   :type '(choice (const :tag "off" nil)
71                  (const some)
72                  number
73                  (sexp :menu-tag "other" t)))
74
75 (defcustom gnus-refer-thread-limit 200
76   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
77 If t, fetch all the available old headers."
78   :group 'gnus-thread
79   :type '(choice number
80                  (sexp :menu-tag "other" t)))
81
82 (defcustom gnus-summary-make-false-root 'adopt
83   "*nil means that Gnus won't gather loose threads.
84 If the root of a thread has expired or been read in a previous
85 session, the information necessary to build a complete thread has been
86 lost.  Instead of having many small sub-threads from this original thread
87 scattered all over the summary buffer, Gnus can gather them.
88
89 If non-nil, Gnus will try to gather all loose sub-threads from an
90 original thread into one large thread.
91
92 If this variable is non-nil, it should be one of `none', `adopt',
93 `dummy' or `empty'.
94
95 If this variable is `none', Gnus will not make a false root, but just
96 present the sub-threads after another.
97 If this variable is `dummy', Gnus will create a dummy root that will
98 have all the sub-threads as children.
99 If this variable is `adopt', Gnus will make one of the \"children\"
100 the parent and mark all the step-children as such.
101 If this variable is `empty', the \"children\" are printed with empty
102 subject fields.  (Or rather, they will be printed with a string
103 given by the `gnus-summary-same-subject' variable.)"
104   :group 'gnus-thread
105   :type '(choice (const :tag "off" nil)
106                  (const none)
107                  (const dummy)
108                  (const adopt)
109                  (const empty)))
110
111 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
112   "*A regexp to match subjects to be excluded from loose thread gathering.
113 As loose thread gathering is done on subjects only, that means that
114 there can be many false gatherings performed.  By rooting out certain
115 common subjects, gathering might become saner."
116   :group 'gnus-thread
117   :type 'regexp)
118
119 (defcustom gnus-summary-gather-subject-limit nil
120   "*Maximum length of subject comparisons when gathering loose threads.
121 Use nil to compare full subjects.  Setting this variable to a low
122 number will help gather threads that have been corrupted by
123 newsreaders chopping off subject lines, but it might also mean that
124 unrelated articles that have subject that happen to begin with the
125 same few characters will be incorrectly gathered.
126
127 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
128 comparing subjects."
129   :group 'gnus-thread
130   :type '(choice (const :tag "off" nil)
131                  (const fuzzy)
132                  (sexp :menu-tag "on" t)))
133
134 (defcustom gnus-simplify-subject-functions nil
135   "List of functions taking a string argument that simplify subjects.
136 The functions are applied recursively.
137
138 Useful functions to put in this list include: `gnus-simplify-subject-re',
139 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
140   :group 'gnus-thread
141   :type '(repeat function))
142
143 (defcustom gnus-simplify-ignored-prefixes nil
144   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
145   :group 'gnus-thread
146   :type '(choice (const :tag "off" nil)
147                  regexp))
148
149 (defcustom gnus-build-sparse-threads nil
150   "*If non-nil, fill in the gaps in threads.
151 If `some', only fill in the gaps that are needed to tie loose threads
152 together.  If `more', fill in all leaf nodes that Gnus can find.  If
153 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
154   :group 'gnus-thread
155   :type '(choice (const :tag "off" nil)
156                  (const some)
157                  (const more)
158                  (sexp :menu-tag "all" t)))
159
160 (defcustom gnus-summary-thread-gathering-function
161   'gnus-gather-threads-by-subject
162   "*Function used for gathering loose threads.
163 There are two pre-defined functions: `gnus-gather-threads-by-subject',
164 which only takes Subjects into consideration; and
165 `gnus-gather-threads-by-references', which compared the References
166 headers of the articles to find matches."
167   :group 'gnus-thread
168   :type '(radio (function-item gnus-gather-threads-by-subject)
169                 (function-item gnus-gather-threads-by-references)
170                 (function :tag "other")))
171
172 (defcustom gnus-summary-same-subject ""
173   "*String indicating that the current article has the same subject as the previous.
174 This variable will only be used if the value of
175 `gnus-summary-make-false-root' is `empty'."
176   :group 'gnus-summary-format
177   :type 'string)
178
179 (defcustom gnus-summary-goto-unread t
180   "*If t, marking commands will go to the next unread article.
181 If `never', commands that usually go to the next unread article, will
182 go to the next article, whether it is read or not.
183 If nil, only the marking commands will go to the next (un)read article."
184   :group 'gnus-summary-marks
185   :link '(custom-manual "(gnus)Setting Marks")
186   :type '(choice (const :tag "off" nil)
187                  (const never)
188                  (sexp :menu-tag "on" t)))
189
190 (defcustom gnus-summary-default-score 0
191   "*Default article score level.
192 All scores generated by the score files will be added to this score.
193 If this variable is nil, scoring will be disabled."
194   :group 'gnus-score-default
195   :type '(choice (const :tag "disable")
196                  integer))
197
198 (defcustom gnus-summary-zcore-fuzz 0
199   "*Fuzziness factor for the zcore in the summary buffer.
200 Articles with scores closer than this to `gnus-summary-default-score'
201 will not be marked."
202   :group 'gnus-summary-format
203   :type 'integer)
204
205 (defcustom gnus-simplify-subject-fuzzy-regexp nil
206   "*Strings to be removed when doing fuzzy matches.
207 This can either be a regular expression or list of regular expressions
208 that will be removed from subject strings if fuzzy subject
209 simplification is selected."
210   :group 'gnus-thread
211   :type '(repeat regexp))
212
213 (defcustom gnus-show-threads t
214   "*If non-nil, display threads in summary mode."
215   :group 'gnus-thread
216   :type 'boolean)
217
218 (defcustom gnus-thread-hide-subtree nil
219   "*If non-nil, hide all threads initially.
220 If threads are hidden, you have to run the command
221 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
222 to expose hidden threads."
223   :group 'gnus-thread
224   :type 'boolean)
225
226 (defcustom gnus-thread-hide-killed t
227   "*If non-nil, hide killed threads automatically."
228   :group 'gnus-thread
229   :type 'boolean)
230
231 (defcustom gnus-thread-ignore-subject t
232   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
233 If nil, articles that have different subjects from their parents will
234 start separate threads."
235   :group 'gnus-thread
236   :type 'boolean)
237
238 (defcustom gnus-thread-operation-ignore-subject t
239   "*If non-nil, subjects will be ignored when doing thread commands.
240 This affects commands like `gnus-summary-kill-thread' and
241 `gnus-summary-lower-thread'.
242
243 If this variable is nil, articles in the same thread with different
244 subjects will not be included in the operation in question.  If this
245 variable is `fuzzy', only articles that have subjects that are fuzzily
246 equal will be included."
247   :group 'gnus-thread
248   :type '(choice (const :tag "off" nil)
249                  (const fuzzy)
250                  (sexp :tag "on" t)))
251
252 (defcustom gnus-thread-indent-level 4
253   "*Number that says how much each sub-thread should be indented."
254   :group 'gnus-thread
255   :type 'integer)
256
257 (defcustom gnus-auto-extend-newsgroup t
258   "*If non-nil, extend newsgroup forward and backward when requested."
259   :group 'gnus-summary-choose
260   :type 'boolean)
261
262 (defcustom gnus-auto-select-first t
263   "*If nil, don't select the first unread article when entering a group.
264 If this variable is `best', select the highest-scored unread article
265 in the group.  If t, select the first unread article.
266
267 This variable can also be a function to place point on a likely
268 subject line.  Useful values include `gnus-summary-first-unread-subject', 
269 `gnus-summary-first-unread-article' and 
270 `gnus-summary-best-unread-article'.
271
272 If you want to prevent automatic selection of the first unread article
273 in some newsgroups, set the variable to nil in
274 `gnus-select-group-hook'."
275   :group 'gnus-group-select
276   :type '(choice (const :tag "none" nil)
277                  (const best)
278                  (sexp :menu-tag "first" t)
279                  (function-item gnus-summary-first-unread-subject)
280                  (function-item gnus-summary-first-unread-article)
281                  (function-item gnus-summary-best-unread-article)))
282
283 (defcustom gnus-auto-select-next t
284   "*If non-nil, offer to go to the next group from the end of the previous.
285 If the value is t and the next newsgroup is empty, Gnus will exit
286 summary mode and go back to group mode.  If the value is neither nil
287 nor t, Gnus will select the following unread newsgroup.  In
288 particular, if the value is the symbol `quietly', the next unread
289 newsgroup will be selected without any confirmation, and if it is
290 `almost-quietly', the next group will be selected without any
291 confirmation if you are located on the last article in the group.
292 Finally, if this variable is `slightly-quietly', the `Z n' command
293 will go to the next group without confirmation."
294   :group 'gnus-summary-maneuvering
295   :type '(choice (const :tag "off" nil)
296                  (const quietly)
297                  (const almost-quietly)
298                  (const slightly-quietly)
299                  (sexp :menu-tag "on" t)))
300
301 (defcustom gnus-auto-select-same nil
302   "*If non-nil, select the next article with the same subject.
303 If there are no more articles with the same subject, go to
304 the first unread article."
305   :group 'gnus-summary-maneuvering
306   :type 'boolean)
307
308 (defcustom gnus-summary-check-current nil
309   "*If non-nil, consider the current article when moving.
310 The \"unread\" movement commands will stay on the same line if the
311 current article is unread."
312   :group 'gnus-summary-maneuvering
313   :type 'boolean)
314
315 (defcustom gnus-auto-center-summary t
316   "*If non-nil, always center the current summary buffer.
317 In particular, if `vertical' do only vertical recentering.  If non-nil
318 and non-`vertical', do both horizontal and vertical recentering."
319   :group 'gnus-summary-maneuvering
320   :type '(choice (const :tag "none" nil)
321                  (const vertical)
322                  (integer :tag "height")
323                  (sexp :menu-tag "both" t)))
324
325 (defcustom gnus-show-all-headers nil
326   "*If non-nil, don't hide any headers."
327   :group 'gnus-article-hiding
328   :group 'gnus-article-headers
329   :type 'boolean)
330
331 (defcustom gnus-summary-ignore-duplicates nil
332   "*If non-nil, ignore articles with identical Message-ID headers."
333   :group 'gnus-summary
334   :type 'boolean)
335
336 (defcustom gnus-single-article-buffer t
337   "*If non-nil, display all articles in the same buffer.
338 If nil, each group will get its own article buffer."
339   :group 'gnus-article-various
340   :type 'boolean)
341
342 (defcustom gnus-break-pages t
343   "*If non-nil, do page breaking on articles.
344 The page delimiter is specified by the `gnus-page-delimiter'
345 variable."
346   :group 'gnus-article-various
347   :type 'boolean)
348
349 (defcustom gnus-show-mime t
350   "*If non-nil, do mime processing of articles.
351 The articles will simply be fed to the function given by
352 `gnus-article-display-method-for-mime'."
353   :group 'gnus-article-mime
354   :type 'boolean)
355
356 (defcustom gnus-move-split-methods nil
357   "*Variable used to suggest where articles are to be moved to.
358 It uses the same syntax as the `gnus-split-methods' variable."
359   :group 'gnus-summary-mail
360   :type '(repeat (choice (list :value (fun) function)
361                          (cons :value ("" "") regexp (repeat string))
362                          (sexp :value nil))))
363
364 (defcustom gnus-unread-mark ? 
365   "*Mark used for unread articles."
366   :group 'gnus-summary-marks
367   :type 'character)
368
369 (defcustom gnus-ticked-mark ?!
370   "*Mark used for ticked articles."
371   :group 'gnus-summary-marks
372   :type 'character)
373
374 (defcustom gnus-dormant-mark ??
375   "*Mark used for dormant articles."
376   :group 'gnus-summary-marks
377   :type 'character)
378
379 (defcustom gnus-del-mark ?r
380   "*Mark used for del'd articles."
381   :group 'gnus-summary-marks
382   :type 'character)
383
384 (defcustom gnus-read-mark ?R
385   "*Mark used for read articles."
386   :group 'gnus-summary-marks
387   :type 'character)
388
389 (defcustom gnus-expirable-mark ?E
390   "*Mark used for expirable articles."
391   :group 'gnus-summary-marks
392   :type 'character)
393
394 (defcustom gnus-killed-mark ?K
395   "*Mark used for killed articles."
396   :group 'gnus-summary-marks
397   :type 'character)
398
399 (defcustom gnus-souped-mark ?F
400   "*Mark used for killed articles."
401   :group 'gnus-summary-marks
402   :type 'character)
403
404 (defcustom gnus-kill-file-mark ?X
405   "*Mark used for articles killed by kill files."
406   :group 'gnus-summary-marks
407   :type 'character)
408
409 (defcustom gnus-low-score-mark ?Y
410   "*Mark used for articles with a low score."
411   :group 'gnus-summary-marks
412   :type 'character)
413
414 (defcustom gnus-catchup-mark ?C
415   "*Mark used for articles that are caught up."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-replied-mark ?A
420   "*Mark used for articles that have been replied to."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-cached-mark ?*
425   "*Mark used for articles that are in the cache."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-saved-mark ?S
430   "*Mark used for articles that have been saved to."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-ancient-mark ?O
435   "*Mark used for ancient articles."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-sparse-mark ?Q
440   "*Mark used for sparsely reffed articles."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-canceled-mark ?G
445   "*Mark used for canceled articles."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-duplicate-mark ?M
450   "*Mark used for duplicate articles."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-undownloaded-mark ?@
455   "*Mark used for articles that weren't downloaded."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-downloadable-mark ?%
460   "*Mark used for articles that are to be downloaded."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-unsendable-mark ?=
465   "*Mark used for articles that won't be sent."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-score-over-mark ?+
470   "*Score mark used for articles with high scores."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-score-below-mark ?-
475   "*Score mark used for articles with low scores."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-empty-thread-mark ? 
480   "*There is no thread under the article."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-not-empty-thread-mark ?=
485   "*There is a thread under the article."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-view-pseudo-asynchronously nil
490   "*If non-nil, Gnus will view pseudo-articles asynchronously."
491   :group 'gnus-extract-view
492   :type 'boolean)
493
494 (defcustom gnus-auto-expirable-marks
495   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
496         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
497         gnus-souped-mark gnus-duplicate-mark)
498   "*The list of marks converted into expiration if a group is auto-expirable."
499   :group 'gnus-summary
500   :type '(repeat character))
501
502 (defcustom gnus-inhibit-user-auto-expire t
503   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
504   :group 'gnus-summary
505   :type 'boolean)
506
507 (defcustom gnus-view-pseudos nil
508   "*If `automatic', pseudo-articles will be viewed automatically.
509 If `not-confirm', pseudos will be viewed automatically, and the user
510 will not be asked to confirm the command."
511   :group 'gnus-extract-view
512   :type '(choice (const :tag "off" nil)
513                  (const automatic)
514                  (const not-confirm)))
515
516 (defcustom gnus-view-pseudos-separately t
517   "*If non-nil, one pseudo-article will be created for each file to be viewed.
518 If nil, all files that use the same viewing command will be given as a
519 list of parameters to that command."
520   :group 'gnus-extract-view
521   :type 'boolean)
522
523 (defcustom gnus-insert-pseudo-articles t
524   "*If non-nil, insert pseudo-articles when decoding articles."
525   :group 'gnus-extract-view
526   :type 'boolean)
527
528 (defcustom gnus-summary-dummy-line-format
529   "  %(:                          :%) %S\n"
530   "*The format specification for the dummy roots in the summary buffer.
531 It works along the same lines as a normal formatting string,
532 with some simple extensions.
533
534 %S  The subject"
535   :group 'gnus-threading
536   :type 'string)
537
538 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
539   "*The format specification for the summary mode line.
540 It works along the same lines as a normal formatting string,
541 with some simple extensions:
542
543 %G  Group name
544 %p  Unprefixed group name
545 %A  Current article number
546 %z  Current article score
547 %V  Gnus version
548 %U  Number of unread articles in the group
549 %e  Number of unselected articles in the group
550 %Z  A string with unread/unselected article counts
551 %g  Shortish group name
552 %S  Subject of the current article
553 %u  User-defined spec
554 %s  Current score file name
555 %d  Number of dormant articles
556 %r  Number of articles that have been marked as read in this session
557 %E  Number of articles expunged by the score files"
558   :group 'gnus-summary-format
559   :type 'string)
560
561 (defcustom gnus-summary-mark-below 0
562   "*Mark all articles with a score below this variable as read.
563 This variable is local to each summary buffer and usually set by the
564 score file."
565   :group 'gnus-score-default
566   :type 'integer)
567
568 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
569   "*List of functions used for sorting articles in the summary buffer.
570 This variable is only used when not using a threaded display."
571   :group 'gnus-summary-sort
572   :type '(repeat (choice (function-item gnus-article-sort-by-number)
573                          (function-item gnus-article-sort-by-author)
574                          (function-item gnus-article-sort-by-subject)
575                          (function-item gnus-article-sort-by-date)
576                          (function-item gnus-article-sort-by-score)
577                          (function :tag "other"))))
578
579 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
580   "*List of functions used for sorting threads in the summary buffer.
581 By default, threads are sorted by article number.
582
583 Each function takes two threads and return non-nil if the first thread
584 should be sorted before the other.  If you use more than one function,
585 the primary sort function should be the last.  You should probably
586 always include `gnus-thread-sort-by-number' in the list of sorting
587 functions -- preferably first.
588
589 Ready-made functions include `gnus-thread-sort-by-number',
590 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
591 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
592 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
593   :group 'gnus-summary-sort
594   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
595                          (function-item gnus-thread-sort-by-author)
596                          (function-item gnus-thread-sort-by-subject)
597                          (function-item gnus-thread-sort-by-date)
598                          (function-item gnus-thread-sort-by-score)
599                          (function-item gnus-thread-sort-by-total-score)
600                          (function :tag "other"))))
601
602 (defcustom gnus-thread-score-function '+
603   "*Function used for calculating the total score of a thread.
604
605 The function is called with the scores of the article and each
606 subthread and should then return the score of the thread.
607
608 Some functions you can use are `+', `max', or `min'."
609   :group 'gnus-summary-sort
610   :type 'function)
611
612 (defcustom gnus-summary-expunge-below nil
613   "All articles that have a score less than this variable will be expunged.
614 This variable is local to the summary buffers."
615   :group 'gnus-score-default
616   :type '(choice (const :tag "off" nil)
617                  integer))
618
619 (defcustom gnus-thread-expunge-below nil
620   "All threads that have a total score less than this variable will be expunged.
621 See `gnus-thread-score-function' for en explanation of what a
622 \"thread score\" is.
623
624 This variable is local to the summary buffers."
625   :group 'gnus-treading
626   :group 'gnus-score-default
627   :type '(choice (const :tag "off" nil)
628                  integer))
629
630 (defcustom gnus-summary-mode-hook nil
631   "*A hook for Gnus summary mode.
632 This hook is run before any variables are set in the summary buffer."
633   :group 'gnus-summary-various
634   :type 'hook)
635
636 (defcustom gnus-summary-menu-hook nil
637   "*Hook run after the creation of the summary mode menu."
638   :group 'gnus-summary-visual
639   :type 'hook)
640
641 (defcustom gnus-summary-exit-hook nil
642   "*A hook called on exit from the summary buffer.
643 It will be called with point in the group buffer."
644   :group 'gnus-summary-exit
645   :type 'hook)
646
647 (defcustom gnus-summary-prepare-hook nil
648   "*A hook called after the summary buffer has been generated.
649 If you want to modify the summary buffer, you can use this hook."
650   :group 'gnus-summary-various
651   :type 'hook)
652
653 (defcustom gnus-summary-prepared-hook nil
654   "*A hook called as the last thing after the summary buffer has been generated."
655   :group 'gnus-summary-various
656   :type 'hook)
657
658 (defcustom gnus-summary-generate-hook nil
659   "*A hook run just before generating the summary buffer.
660 This hook is commonly used to customize threading variables and the
661 like."
662   :group 'gnus-summary-various
663   :type 'hook)
664
665 (defcustom gnus-select-group-hook nil
666   "*A hook called when a newsgroup is selected.
667
668 If you'd like to simplify subjects like the
669 `gnus-summary-next-same-subject' command does, you can use the
670 following hook:
671
672  (setq gnus-select-group-hook
673       (list
674         (lambda ()
675           (mapcar (lambda (header)
676                      (mail-header-set-subject
677                       header
678                       (gnus-simplify-subject
679                        (mail-header-subject header) 're-only)))
680                   gnus-newsgroup-headers))))"
681   :group 'gnus-group-select
682   :type 'hook)
683
684 (defcustom gnus-select-article-hook nil
685   "*A hook called when an article is selected."
686   :group 'gnus-summary-choose
687   :type 'hook)
688
689 (defcustom gnus-visual-mark-article-hook
690   (list 'gnus-highlight-selected-summary)
691   "*Hook run after selecting an article in the summary buffer.
692 It is meant to be used for highlighting the article in some way.  It
693 is not run if `gnus-visual' is nil."
694   :group 'gnus-summary-visual
695   :type 'hook)
696
697 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
698   "*A hook called before parsing the headers."
699   :group 'gnus-various
700   :type 'hook)
701
702 (defcustom gnus-exit-group-hook nil
703   "*A hook called when exiting (not quitting) summary mode."
704   :group 'gnus-various
705   :type 'hook)
706
707 (defcustom gnus-summary-update-hook
708   (list 'gnus-summary-highlight-line)
709   "*A hook called when a summary line is changed.
710 The hook will not be called if `gnus-visual' is nil.
711
712 The default function `gnus-summary-highlight-line' will
713 highlight the line according to the `gnus-summary-highlight'
714 variable."
715   :group 'gnus-summary-visual
716   :type 'hook)
717
718 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
719   "*A hook called when an article is selected for the first time.
720 The hook is intended to mark an article as read (or unread)
721 automatically when it is selected."
722   :group 'gnus-summary-choose
723   :type 'hook)
724
725 (defcustom gnus-group-no-more-groups-hook nil
726   "*A hook run when returning to group mode having no more (unread) groups."
727   :group 'gnus-group-select
728   :type 'hook)
729
730 (defcustom gnus-ps-print-hook nil
731   "*A hook run before ps-printing something from Gnus."
732   :group 'gnus-summary
733   :type 'hook)
734
735 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
736   "Face used for highlighting the current article in the summary buffer."
737   :group 'gnus-summary-visual
738   :type 'face)
739
740 (defcustom gnus-summary-highlight
741   '(((= mark gnus-canceled-mark)
742      . gnus-summary-cancelled-face)
743     ((and (> score default)
744           (or (= mark gnus-dormant-mark)
745               (= mark gnus-ticked-mark)))
746      . gnus-summary-high-ticked-face)
747     ((and (< score default)
748           (or (= mark gnus-dormant-mark)
749               (= mark gnus-ticked-mark)))
750      . gnus-summary-low-ticked-face)
751     ((or (= mark gnus-dormant-mark)
752          (= mark gnus-ticked-mark))
753      . gnus-summary-normal-ticked-face)
754     ((and (> score default) (= mark gnus-ancient-mark))
755      . gnus-summary-high-ancient-face)
756     ((and (< score default) (= mark gnus-ancient-mark))
757      . gnus-summary-low-ancient-face)
758     ((= mark gnus-ancient-mark)
759      . gnus-summary-normal-ancient-face)
760     ((and (> score default) (= mark gnus-unread-mark))
761      . gnus-summary-high-unread-face)
762     ((and (< score default) (= mark gnus-unread-mark))
763      . gnus-summary-low-unread-face)
764     ((= mark gnus-unread-mark)
765      . gnus-summary-normal-unread-face)
766     ((and (> score default) (memq mark (list gnus-downloadable-mark
767                                              gnus-undownloaded-mark)))
768      . gnus-summary-high-unread-face)
769     ((and (< score default) (memq mark (list gnus-downloadable-mark
770                                              gnus-undownloaded-mark)))
771      . gnus-summary-low-unread-face)
772     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
773      . gnus-summary-normal-unread-face)
774     ((> score default)
775      . gnus-summary-high-read-face)
776     ((< score default)
777      . gnus-summary-low-read-face)
778     (t
779      . gnus-summary-normal-read-face))
780   "*Controls the highlighting of summary buffer lines.
781
782 A list of (FORM . FACE) pairs.  When deciding how a a particular
783 summary line should be displayed, each form is evaluated.  The content
784 of the face field after the first true form is used.  You can change
785 how those summary lines are displayed, by editing the face field.
786
787 You can use the following variables in the FORM field.
788
789 score:   The articles score
790 default: The default article score.
791 below:   The score below which articles are automatically marked as read.
792 mark:    The articles mark."
793   :group 'gnus-summary-visual
794   :type '(repeat (cons (sexp :tag "Form" nil)
795                        face)))
796
797 (defcustom gnus-alter-header-function nil
798   "Function called to allow alteration of article header structures.
799 The function is called with one parameter, the article header vector,
800 which it may alter in any way.")
801
802 (defcustom gnus-extra-headers nil
803   "*Extra headers to parse."
804   :group 'gnus-summary
805   :type '(repeat symbol))
806
807 (defcustom gnus-ignored-from-addresses
808   (and user-mail-address (regexp-quote user-mail-address))
809   "*Regexp of From headers that may be suppressed in favor of To headers."
810   :group 'gnus-summary
811   :type 'regexp)
812
813 ;;; Internal variables
814
815 (defvar gnus-scores-exclude-files nil)
816 (defvar gnus-page-broken nil)
817
818 (defvar gnus-original-article nil)
819 (defvar gnus-article-internal-prepare-hook nil)
820 (defvar gnus-newsgroup-process-stack nil)
821
822 (defvar gnus-thread-indent-array nil)
823 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
824
825 ;; Avoid highlighting in kill files.
826 (defvar gnus-summary-inhibit-highlight nil)
827 (defvar gnus-newsgroup-selected-overlay nil)
828 (defvar gnus-inhibit-limiting nil)
829 (defvar gnus-newsgroup-adaptive-score-file nil)
830 (defvar gnus-current-score-file nil)
831 (defvar gnus-current-move-group nil)
832 (defvar gnus-current-copy-group nil)
833 (defvar gnus-current-crosspost-group nil)
834
835 (defvar gnus-newsgroup-dependencies nil)
836 (defvar gnus-newsgroup-adaptive nil)
837 (defvar gnus-summary-display-article-function nil)
838 (defvar gnus-summary-highlight-line-function nil
839   "Function called after highlighting a summary line.")
840
841 (defvar gnus-summary-line-format-alist
842   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
843     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
844     (?s gnus-tmp-subject-or-nil ?s)
845     (?n gnus-tmp-name ?s)
846     (?A (std11-address-string
847          (car (mime-read-field 'From gnus-tmp-header))) ?s)
848     (?a (or (std11-full-name-string
849              (car (mime-read-field 'From gnus-tmp-header)))
850             gnus-tmp-from) ?s)
851     (?F gnus-tmp-from ?s)
852     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
853     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
854     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
855     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
856     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
857     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
858     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
859     (?L gnus-tmp-lines ?d)
860     (?I gnus-tmp-indentation ?s)
861     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
862     (?R gnus-tmp-replied ?c)
863     (?\[ gnus-tmp-opening-bracket ?c)
864     (?\] gnus-tmp-closing-bracket ?c)
865     (?\> (make-string gnus-tmp-level ? ) ?s)
866     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
867     (?i gnus-tmp-score ?d)
868     (?z gnus-tmp-score-char ?c)
869     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
870     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
871     (?U gnus-tmp-unread ?c)
872     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
873     (?t (gnus-summary-number-of-articles-in-thread
874          (and (boundp 'thread) (car thread)) gnus-tmp-level)
875         ?d)
876     (?e (gnus-summary-number-of-articles-in-thread
877          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
878         ?c)
879     (?u gnus-tmp-user-defined ?s)
880     (?P (gnus-pick-line-number) ?d))
881   "An alist of format specifications that can appear in summary lines,
882 and what variables they correspond with, along with the type of the
883 variable (string, integer, character, etc).")
884
885 (defvar gnus-summary-dummy-line-format-alist
886   `((?S gnus-tmp-subject ?s)
887     (?N gnus-tmp-number ?d)
888     (?u gnus-tmp-user-defined ?s)))
889
890 (defvar gnus-summary-mode-line-format-alist
891   `((?G gnus-tmp-group-name ?s)
892     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
893     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
894     (?A gnus-tmp-article-number ?d)
895     (?Z gnus-tmp-unread-and-unselected ?s)
896     (?V gnus-version ?s)
897     (?U gnus-tmp-unread-and-unticked ?d)
898     (?S gnus-tmp-subject ?s)
899     (?e gnus-tmp-unselected ?d)
900     (?u gnus-tmp-user-defined ?s)
901     (?d (length gnus-newsgroup-dormant) ?d)
902     (?t (length gnus-newsgroup-marked) ?d)
903     (?r (length gnus-newsgroup-reads) ?d)
904     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
905     (?E gnus-newsgroup-expunged-tally ?d)
906     (?s (gnus-current-score-file-nondirectory) ?s)))
907
908 (defvar gnus-last-search-regexp nil
909   "Default regexp for article search command.")
910
911 (defvar gnus-last-shell-command nil
912   "Default shell command on article.")
913
914 (defvar gnus-newsgroup-begin nil)
915 (defvar gnus-newsgroup-end nil)
916 (defvar gnus-newsgroup-last-rmail nil)
917 (defvar gnus-newsgroup-last-mail nil)
918 (defvar gnus-newsgroup-last-folder nil)
919 (defvar gnus-newsgroup-last-file nil)
920 (defvar gnus-newsgroup-auto-expire nil)
921 (defvar gnus-newsgroup-active nil)
922
923 (defvar gnus-newsgroup-data nil)
924 (defvar gnus-newsgroup-data-reverse nil)
925 (defvar gnus-newsgroup-limit nil)
926 (defvar gnus-newsgroup-limits nil)
927
928 (defvar gnus-newsgroup-unreads nil
929   "List of unread articles in the current newsgroup.")
930
931 (defvar gnus-newsgroup-unselected nil
932   "List of unselected unread articles in the current newsgroup.")
933
934 (defvar gnus-newsgroup-reads nil
935   "Alist of read articles and article marks in the current newsgroup.")
936
937 (defvar gnus-newsgroup-expunged-tally nil)
938
939 (defvar gnus-newsgroup-marked nil
940   "List of ticked articles in the current newsgroup (a subset of unread art).")
941
942 (defvar gnus-newsgroup-killed nil
943   "List of ranges of articles that have been through the scoring process.")
944
945 (defvar gnus-newsgroup-cached nil
946   "List of articles that come from the article cache.")
947
948 (defvar gnus-newsgroup-saved nil
949   "List of articles that have been saved.")
950
951 (defvar gnus-newsgroup-kill-headers nil)
952
953 (defvar gnus-newsgroup-replied nil
954   "List of articles that have been replied to in the current newsgroup.")
955
956 (defvar gnus-newsgroup-expirable nil
957   "List of articles in the current newsgroup that can be expired.")
958
959 (defvar gnus-newsgroup-processable nil
960   "List of articles in the current newsgroup that can be processed.")
961
962 (defvar gnus-newsgroup-downloadable nil
963   "List of articles in the current newsgroup that can be processed.")
964
965 (defvar gnus-newsgroup-undownloaded nil
966   "List of articles in the current newsgroup that haven't been downloaded..")
967
968 (defvar gnus-newsgroup-unsendable nil
969   "List of articles in the current newsgroup that won't be sent.")
970
971 (defvar gnus-newsgroup-bookmarks nil
972   "List of articles in the current newsgroup that have bookmarks.")
973
974 (defvar gnus-newsgroup-dormant nil
975   "List of dormant articles in the current newsgroup.")
976
977 (defvar gnus-newsgroup-scored nil
978   "List of scored articles in the current newsgroup.")
979
980 (defvar gnus-newsgroup-headers nil
981   "List of article headers in the current newsgroup.")
982
983 (defvar gnus-newsgroup-threads nil)
984
985 (defvar gnus-newsgroup-prepared nil
986   "Whether the current group has been prepared properly.")
987
988 (defvar gnus-newsgroup-ancient nil
989   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
990
991 (defvar gnus-newsgroup-sparse nil)
992
993 (defvar gnus-current-article nil)
994 (defvar gnus-article-current nil)
995 (defvar gnus-current-headers nil)
996 (defvar gnus-have-all-headers nil)
997 (defvar gnus-last-article nil)
998 (defvar gnus-newsgroup-history nil)
999
1000 (defconst gnus-summary-local-variables
1001   '(gnus-newsgroup-name
1002     gnus-newsgroup-begin gnus-newsgroup-end
1003     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1004     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1005     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1006     gnus-newsgroup-unselected gnus-newsgroup-marked
1007     gnus-newsgroup-reads gnus-newsgroup-saved
1008     gnus-newsgroup-replied gnus-newsgroup-expirable
1009     gnus-newsgroup-processable gnus-newsgroup-killed
1010     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1011     gnus-newsgroup-unsendable
1012     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1013     gnus-newsgroup-headers gnus-newsgroup-threads
1014     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1015     gnus-current-article gnus-current-headers gnus-have-all-headers
1016     gnus-last-article gnus-article-internal-prepare-hook
1017     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1018     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1019     gnus-thread-expunge-below
1020     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1021     (gnus-summary-mark-below . global)
1022     gnus-newsgroup-active gnus-scores-exclude-files
1023     gnus-newsgroup-history gnus-newsgroup-ancient
1024     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1025     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1026     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1027     (gnus-newsgroup-expunged-tally . 0)
1028     gnus-cache-removable-articles gnus-newsgroup-cached
1029     gnus-newsgroup-data gnus-newsgroup-data-reverse
1030     gnus-newsgroup-limit gnus-newsgroup-limits)
1031   "Variables that are buffer-local to the summary buffers.")
1032
1033 ;; Byte-compiler warning.
1034 (defvar gnus-article-mode-map)
1035
1036 ;; Subject simplification.
1037
1038 (defun gnus-simplify-whitespace (str)
1039   "Remove excessive whitespace."
1040   (let ((mystr str))
1041     ;; Multiple spaces.
1042     (while (string-match "[ \t][ \t]+" mystr)
1043       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1044                           " "
1045                           (substring mystr (match-end 0)))))
1046     ;; Leading spaces.
1047     (when (string-match "^[ \t]+" mystr)
1048       (setq mystr (substring mystr (match-end 0))))
1049     ;; Trailing spaces.
1050     (when (string-match "[ \t]+$" mystr)
1051       (setq mystr (substring mystr 0 (match-beginning 0))))
1052     mystr))
1053
1054 (defsubst gnus-simplify-subject-re (subject)
1055   "Remove \"Re:\" from subject lines."
1056   (if (string-match "^[Rr][Ee]: *" subject)
1057       (substring subject (match-end 0))
1058     subject))
1059
1060 (defun gnus-simplify-subject (subject &optional re-only)
1061   "Remove `Re:' and words in parentheses.
1062 If RE-ONLY is non-nil, strip leading `Re:'s only."
1063   (let ((case-fold-search t))           ;Ignore case.
1064     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1065     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1066       (setq subject (substring subject (match-end 0))))
1067     ;; Remove uninteresting prefixes.
1068     (when (and (not re-only)
1069                gnus-simplify-ignored-prefixes
1070                (string-match gnus-simplify-ignored-prefixes subject))
1071       (setq subject (substring subject (match-end 0))))
1072     ;; Remove words in parentheses from end.
1073     (unless re-only
1074       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1075         (setq subject (substring subject 0 (match-beginning 0)))))
1076     ;; Return subject string.
1077     subject))
1078
1079 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1080 ;; all whitespace.
1081 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1082   (goto-char (point-min))
1083   (while (re-search-forward regexp nil t)
1084       (replace-match (or newtext ""))))
1085
1086 (defun gnus-simplify-buffer-fuzzy ()
1087   "Simplify string in the buffer fuzzily.
1088 The string in the accessible portion of the current buffer is simplified.
1089 It is assumed to be a single-line subject.
1090 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1091 matter is removed.  Additional things can be deleted by setting
1092 gnus-simplify-subject-fuzzy-regexp."
1093   (let ((case-fold-search t)
1094         (modified-tick))
1095     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1096
1097     (while (not (eq modified-tick (buffer-modified-tick)))
1098       (setq modified-tick (buffer-modified-tick))
1099       (cond
1100        ((listp gnus-simplify-subject-fuzzy-regexp)
1101         (mapcar 'gnus-simplify-buffer-fuzzy-step
1102                 gnus-simplify-subject-fuzzy-regexp))
1103        (gnus-simplify-subject-fuzzy-regexp
1104         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1105       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1106       (gnus-simplify-buffer-fuzzy-step
1107        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1108       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1109
1110     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1111     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1112     (gnus-simplify-buffer-fuzzy-step " $")
1113     (gnus-simplify-buffer-fuzzy-step "^ +")))
1114
1115 (defun gnus-simplify-subject-fuzzy (subject)
1116   "Simplify a subject string fuzzily.
1117 See `gnus-simplify-buffer-fuzzy' for details."
1118   (save-excursion
1119     (gnus-set-work-buffer)
1120     (let ((case-fold-search t))
1121       ;; Remove uninteresting prefixes.
1122       (when (and gnus-simplify-ignored-prefixes
1123                  (string-match gnus-simplify-ignored-prefixes subject))
1124         (setq subject (substring subject (match-end 0))))
1125       (insert subject)
1126       (inline (gnus-simplify-buffer-fuzzy))
1127       (buffer-string))))
1128
1129 (defsubst gnus-simplify-subject-fully (subject)
1130   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1131   (cond
1132    (gnus-simplify-subject-functions
1133     (gnus-map-function gnus-simplify-subject-functions subject))
1134    ((null gnus-summary-gather-subject-limit)
1135     (gnus-simplify-subject-re subject))
1136    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1137     (gnus-simplify-subject-fuzzy subject))
1138    ((numberp gnus-summary-gather-subject-limit)
1139     (gnus-limit-string (gnus-simplify-subject-re subject)
1140                        gnus-summary-gather-subject-limit))
1141    (t
1142     subject)))
1143
1144 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1145   "Check whether two subjects are equal.
1146 If optional argument simple-first is t, first argument is already
1147 simplified."
1148   (cond
1149    ((null simple-first)
1150     (equal (gnus-simplify-subject-fully s1)
1151            (gnus-simplify-subject-fully s2)))
1152    (t
1153     (equal s1
1154            (gnus-simplify-subject-fully s2)))))
1155
1156 (defun gnus-summary-bubble-group ()
1157   "Increase the score of the current group.
1158 This is a handy function to add to `gnus-summary-exit-hook' to
1159 increase the score of each group you read."
1160   (gnus-group-add-score gnus-newsgroup-name))
1161
1162 \f
1163 ;;;
1164 ;;; Gnus summary mode
1165 ;;;
1166
1167 (put 'gnus-summary-mode 'mode-class 'special)
1168
1169 (when t
1170   ;; Non-orthogonal keys
1171
1172   (gnus-define-keys gnus-summary-mode-map
1173     " " gnus-summary-next-page
1174     "\177" gnus-summary-prev-page
1175     [delete] gnus-summary-prev-page
1176     [backspace] gnus-summary-prev-page
1177     "\r" gnus-summary-scroll-up
1178     "\M-\r" gnus-summary-scroll-down
1179     "n" gnus-summary-next-unread-article
1180     "p" gnus-summary-prev-unread-article
1181     "N" gnus-summary-next-article
1182     "P" gnus-summary-prev-article
1183     "\M-\C-n" gnus-summary-next-same-subject
1184     "\M-\C-p" gnus-summary-prev-same-subject
1185     "\M-n" gnus-summary-next-unread-subject
1186     "\M-p" gnus-summary-prev-unread-subject
1187     "." gnus-summary-first-unread-article
1188     "," gnus-summary-best-unread-article
1189     "\M-s" gnus-summary-search-article-forward
1190     "\M-r" gnus-summary-search-article-backward
1191     "<" gnus-summary-beginning-of-article
1192     ">" gnus-summary-end-of-article
1193     "j" gnus-summary-goto-article
1194     "^" gnus-summary-refer-parent-article
1195     "\M-^" gnus-summary-refer-article
1196     "u" gnus-summary-tick-article-forward
1197     "!" gnus-summary-tick-article-forward
1198     "U" gnus-summary-tick-article-backward
1199     "d" gnus-summary-mark-as-read-forward
1200     "D" gnus-summary-mark-as-read-backward
1201     "E" gnus-summary-mark-as-expirable
1202     "\M-u" gnus-summary-clear-mark-forward
1203     "\M-U" gnus-summary-clear-mark-backward
1204     "k" gnus-summary-kill-same-subject-and-select
1205     "\C-k" gnus-summary-kill-same-subject
1206     "\M-\C-k" gnus-summary-kill-thread
1207     "\M-\C-l" gnus-summary-lower-thread
1208     "e" gnus-summary-edit-article
1209     "#" gnus-summary-mark-as-processable
1210     "\M-#" gnus-summary-unmark-as-processable
1211     "\M-\C-t" gnus-summary-toggle-threads
1212     "\M-\C-s" gnus-summary-show-thread
1213     "\M-\C-h" gnus-summary-hide-thread
1214     "\M-\C-f" gnus-summary-next-thread
1215     "\M-\C-b" gnus-summary-prev-thread
1216     "\M-\C-u" gnus-summary-up-thread
1217     "\M-\C-d" gnus-summary-down-thread
1218     "&" gnus-summary-execute-command
1219     "c" gnus-summary-catchup-and-exit
1220     "\C-w" gnus-summary-mark-region-as-read
1221     "\C-t" gnus-summary-toggle-truncation
1222     "?" gnus-summary-mark-as-dormant
1223     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1224     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1225     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1226     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1227     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1228     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1229     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1230     "=" gnus-summary-expand-window
1231     "\C-x\C-s" gnus-summary-reselect-current-group
1232     "\M-g" gnus-summary-rescan-group
1233     "w" gnus-summary-stop-page-breaking
1234     "\C-c\C-r" gnus-summary-caesar-message
1235     "\M-t" gnus-summary-toggle-mime
1236     "f" gnus-summary-followup
1237     "F" gnus-summary-followup-with-original
1238     "C" gnus-summary-cancel-article
1239     "r" gnus-summary-reply
1240     "R" gnus-summary-reply-with-original
1241     "\C-c\C-f" gnus-summary-mail-forward
1242     "o" gnus-summary-save-article
1243     "\C-o" gnus-summary-save-article-mail
1244     "|" gnus-summary-pipe-output
1245     "\M-k" gnus-summary-edit-local-kill
1246     "\M-K" gnus-summary-edit-global-kill
1247     ;; "V" gnus-version
1248     "\C-c\C-d" gnus-summary-describe-group
1249     "q" gnus-summary-exit
1250     "Q" gnus-summary-exit-no-update
1251     "\C-c\C-i" gnus-info-find-node
1252     gnus-mouse-2 gnus-mouse-pick-article
1253     "m" gnus-summary-mail-other-window
1254     "a" gnus-summary-post-news
1255     "x" gnus-summary-limit-to-unread
1256     "s" gnus-summary-isearch-article
1257     "t" gnus-article-hide-headers
1258     "g" gnus-summary-show-article
1259     "l" gnus-summary-goto-last-article
1260     "v" gnus-summary-preview-mime-message
1261     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1262     "\C-d" gnus-summary-enter-digest-group
1263     "\M-\C-d" gnus-summary-read-document
1264     "\M-\C-e" gnus-summary-edit-parameters
1265     "\M-\C-g" gnus-summary-customize-parameters
1266     "\C-c\C-b" gnus-bug
1267     "*" gnus-cache-enter-article
1268     "\M-*" gnus-cache-remove-article
1269     "\M-&" gnus-summary-universal-argument
1270     "\C-l" gnus-recenter
1271     "I" gnus-summary-increase-score
1272     "L" gnus-summary-lower-score
1273     "\M-i" gnus-symbolic-argument
1274     "h" gnus-summary-select-article-buffer
1275     
1276     "V" gnus-summary-score-map
1277     "X" gnus-uu-extract-map
1278     "S" gnus-summary-send-map)
1279
1280   ;; Sort of orthogonal keymap
1281   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1282     "t" gnus-summary-tick-article-forward
1283     "!" gnus-summary-tick-article-forward
1284     "d" gnus-summary-mark-as-read-forward
1285     "r" gnus-summary-mark-as-read-forward
1286     "c" gnus-summary-clear-mark-forward
1287     " " gnus-summary-clear-mark-forward
1288     "e" gnus-summary-mark-as-expirable
1289     "x" gnus-summary-mark-as-expirable
1290     "?" gnus-summary-mark-as-dormant
1291     "b" gnus-summary-set-bookmark
1292     "B" gnus-summary-remove-bookmark
1293     "#" gnus-summary-mark-as-processable
1294     "\M-#" gnus-summary-unmark-as-processable
1295     "S" gnus-summary-limit-include-expunged
1296     "C" gnus-summary-catchup
1297     "H" gnus-summary-catchup-to-here
1298     "\C-c" gnus-summary-catchup-all
1299     "k" gnus-summary-kill-same-subject-and-select
1300     "K" gnus-summary-kill-same-subject
1301     "P" gnus-uu-mark-map)
1302
1303   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1304     "c" gnus-summary-clear-above
1305     "u" gnus-summary-tick-above
1306     "m" gnus-summary-mark-above
1307     "k" gnus-summary-kill-below)
1308
1309   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1310     "/" gnus-summary-limit-to-subject
1311     "n" gnus-summary-limit-to-articles
1312     "w" gnus-summary-pop-limit
1313     "s" gnus-summary-limit-to-subject
1314     "a" gnus-summary-limit-to-author
1315     "u" gnus-summary-limit-to-unread
1316     "m" gnus-summary-limit-to-marks
1317     "v" gnus-summary-limit-to-score
1318     "*" gnus-summary-limit-include-cached
1319     "D" gnus-summary-limit-include-dormant
1320     "T" gnus-summary-limit-include-thread
1321     "d" gnus-summary-limit-exclude-dormant
1322     "t" gnus-summary-limit-to-age
1323     "E" gnus-summary-limit-include-expunged
1324     "c" gnus-summary-limit-exclude-childless-dormant
1325     "C" gnus-summary-limit-mark-excluded-as-read)
1326
1327   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1328     "n" gnus-summary-next-unread-article
1329     "p" gnus-summary-prev-unread-article
1330     "N" gnus-summary-next-article
1331     "P" gnus-summary-prev-article
1332     "\C-n" gnus-summary-next-same-subject
1333     "\C-p" gnus-summary-prev-same-subject
1334     "\M-n" gnus-summary-next-unread-subject
1335     "\M-p" gnus-summary-prev-unread-subject
1336     "f" gnus-summary-first-unread-article
1337     "b" gnus-summary-best-unread-article
1338     "j" gnus-summary-goto-article
1339     "g" gnus-summary-goto-subject
1340     "l" gnus-summary-goto-last-article
1341     "o" gnus-summary-pop-article)
1342
1343   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1344     "k" gnus-summary-kill-thread
1345     "l" gnus-summary-lower-thread
1346     "i" gnus-summary-raise-thread
1347     "T" gnus-summary-toggle-threads
1348     "t" gnus-summary-rethread-current
1349     "^" gnus-summary-reparent-thread
1350     "s" gnus-summary-show-thread
1351     "S" gnus-summary-show-all-threads
1352     "h" gnus-summary-hide-thread
1353     "H" gnus-summary-hide-all-threads
1354     "n" gnus-summary-next-thread
1355     "p" gnus-summary-prev-thread
1356     "u" gnus-summary-up-thread
1357     "o" gnus-summary-top-thread
1358     "d" gnus-summary-down-thread
1359     "#" gnus-uu-mark-thread
1360     "\M-#" gnus-uu-unmark-thread)
1361
1362   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1363     "g" gnus-summary-prepare
1364     "c" gnus-summary-insert-cached-articles)
1365
1366   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1367     "c" gnus-summary-catchup-and-exit
1368     "C" gnus-summary-catchup-all-and-exit
1369     "E" gnus-summary-exit-no-update
1370     "Q" gnus-summary-exit
1371     "Z" gnus-summary-exit
1372     "n" gnus-summary-catchup-and-goto-next-group
1373     "R" gnus-summary-reselect-current-group
1374     "G" gnus-summary-rescan-group
1375     "N" gnus-summary-next-group
1376     "s" gnus-summary-save-newsrc
1377     "P" gnus-summary-prev-group)
1378
1379   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1380     " " gnus-summary-next-page
1381     "n" gnus-summary-next-page
1382     "\177" gnus-summary-prev-page
1383     [delete] gnus-summary-prev-page
1384     "p" gnus-summary-prev-page
1385     "\r" gnus-summary-scroll-up
1386     "\M-\r" gnus-summary-scroll-down
1387     "<" gnus-summary-beginning-of-article
1388     ">" gnus-summary-end-of-article
1389     "b" gnus-summary-beginning-of-article
1390     "e" gnus-summary-end-of-article
1391     "^" gnus-summary-refer-parent-article
1392     "r" gnus-summary-refer-parent-article
1393     "R" gnus-summary-refer-references
1394     "T" gnus-summary-refer-thread
1395     "g" gnus-summary-show-article
1396     "s" gnus-summary-isearch-article
1397     "P" gnus-summary-print-article)
1398
1399   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1400     "b" gnus-article-add-buttons
1401     "B" gnus-article-add-buttons-to-head
1402     "o" gnus-article-treat-overstrike
1403     "e" gnus-article-emphasize
1404     "w" gnus-article-fill-cited-article
1405     "c" gnus-article-remove-cr
1406     "f" gnus-article-display-x-face
1407     "l" gnus-summary-stop-page-breaking
1408     "r" gnus-summary-caesar-message
1409     "t" gnus-article-hide-headers
1410     "v" gnus-summary-verbose-headers
1411     "m" gnus-summary-toggle-mime
1412     "h" gnus-article-treat-html
1413     "d" gnus-article-treat-dumbquotes)
1414
1415   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1416     "a" gnus-article-hide
1417     "h" gnus-article-hide-headers
1418     "b" gnus-article-hide-boring-headers
1419     "s" gnus-article-hide-signature
1420     "c" gnus-article-hide-citation
1421     "C" gnus-article-hide-citation-in-followups
1422     "p" gnus-article-hide-pgp
1423     "P" gnus-article-hide-pem
1424     "\C-c" gnus-article-hide-citation-maybe)
1425
1426   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1427     "a" gnus-article-highlight
1428     "h" gnus-article-highlight-headers
1429     "c" gnus-article-highlight-citation
1430     "s" gnus-article-highlight-signature)
1431
1432   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1433     "z" gnus-article-date-ut
1434     "u" gnus-article-date-ut
1435     "l" gnus-article-date-local
1436     "e" gnus-article-date-lapsed
1437     "o" gnus-article-date-original
1438     "i" gnus-article-date-iso8601
1439     "s" gnus-article-date-user)
1440
1441   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1442     "t" gnus-article-remove-trailing-blank-lines
1443     "l" gnus-article-strip-leading-blank-lines
1444     "m" gnus-article-strip-multiple-blank-lines
1445     "a" gnus-article-strip-blank-lines
1446     "A" gnus-article-strip-all-blank-lines
1447     "s" gnus-article-strip-leading-space)
1448
1449   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1450     "v" gnus-version
1451     "f" gnus-summary-fetch-faq
1452     "d" gnus-summary-describe-group
1453     "h" gnus-summary-describe-briefly
1454     "i" gnus-info-find-node)
1455
1456   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1457     "e" gnus-summary-expire-articles
1458     "\M-\C-e" gnus-summary-expire-articles-now
1459     "\177" gnus-summary-delete-article
1460     [delete] gnus-summary-delete-article
1461     "m" gnus-summary-move-article
1462     "r" gnus-summary-respool-article
1463     "w" gnus-summary-edit-article
1464     "c" gnus-summary-copy-article
1465     "B" gnus-summary-crosspost-article
1466     "q" gnus-summary-respool-query
1467     "t" gnus-summary-respool-trace
1468     "i" gnus-summary-import-article
1469     "p" gnus-summary-article-posted-p)
1470
1471   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1472     "o" gnus-summary-save-article
1473     "m" gnus-summary-save-article-mail
1474     "F" gnus-summary-write-article-file
1475     "r" gnus-summary-save-article-rmail
1476     "f" gnus-summary-save-article-file
1477     "b" gnus-summary-save-article-body-file
1478     "h" gnus-summary-save-article-folder
1479     "v" gnus-summary-save-article-vm
1480     "p" gnus-summary-pipe-output
1481     "s" gnus-soup-add-article))
1482
1483 (defun gnus-summary-make-menu-bar ()
1484   (gnus-turn-off-edit-menu 'summary)
1485
1486   (unless (boundp 'gnus-summary-misc-menu)
1487
1488     (easy-menu-define
1489      gnus-summary-kill-menu gnus-summary-mode-map ""
1490      (cons
1491       "Score"
1492       (nconc
1493        (list
1494         ["Enter score..." gnus-summary-score-entry t]
1495         ["Customize" gnus-score-customize t])
1496        (gnus-make-score-map 'increase)
1497        (gnus-make-score-map 'lower)
1498        '(("Mark"
1499           ["Kill below" gnus-summary-kill-below t]
1500           ["Mark above" gnus-summary-mark-above t]
1501           ["Tick above" gnus-summary-tick-above t]
1502           ["Clear above" gnus-summary-clear-above t])
1503          ["Current score" gnus-summary-current-score t]
1504          ["Set score" gnus-summary-set-score t]
1505          ["Switch current score file..." gnus-score-change-score-file t]
1506          ["Set mark below..." gnus-score-set-mark-below t]
1507          ["Set expunge below..." gnus-score-set-expunge-below t]
1508          ["Edit current score file" gnus-score-edit-current-scores t]
1509          ["Edit score file" gnus-score-edit-file t]
1510          ["Trace score" gnus-score-find-trace t]
1511          ["Find words" gnus-score-find-favourite-words t]
1512          ["Rescore buffer" gnus-summary-rescore t]
1513          ["Increase score..." gnus-summary-increase-score t]
1514          ["Lower score..." gnus-summary-lower-score t]))))
1515
1516     ;; Define both the Article menu in the summary buffer and the equivalent
1517     ;; Commands menu in the article buffer here for consistency.
1518     (let ((innards
1519            '(("Hide"
1520               ["All" gnus-article-hide t]
1521               ["Headers" gnus-article-hide-headers t]
1522               ["Signature" gnus-article-hide-signature t]
1523               ["Citation" gnus-article-hide-citation t]
1524               ["PGP" gnus-article-hide-pgp t]
1525               ["Boring headers" gnus-article-hide-boring-headers t])
1526              ("Highlight"
1527               ["All" gnus-article-highlight t]
1528               ["Headers" gnus-article-highlight-headers t]
1529               ["Signature" gnus-article-highlight-signature t]
1530               ["Citation" gnus-article-highlight-citation t])
1531              ("Date"
1532               ["Local" gnus-article-date-local t]
1533               ["ISO8601" gnus-article-date-iso8601 t]
1534               ["UT" gnus-article-date-ut t]
1535               ["Original" gnus-article-date-original t]
1536               ["Lapsed" gnus-article-date-lapsed t]
1537               ["User-defined" gnus-article-date-user t])
1538              ("Washing"
1539               ("Remove Blanks"
1540                ["Leading" gnus-article-strip-leading-blank-lines t]
1541                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1542                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1543                ["All of the above" gnus-article-strip-blank-lines t]
1544                ["All" gnus-article-strip-all-blank-lines t]
1545                ["Leading space" gnus-article-strip-leading-space t])
1546               ["Overstrike" gnus-article-treat-overstrike t]
1547               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1548               ["Emphasis" gnus-article-emphasize t]
1549               ["Word wrap" gnus-article-fill-cited-article t]
1550               ["CR" gnus-article-remove-cr t]
1551               ["Show X-Face" gnus-article-display-x-face t]
1552               ["UnHTMLize" gnus-article-treat-html t]
1553               ["Rot 13" gnus-summary-caesar-message t]
1554               ["Unix pipe" gnus-summary-pipe-message t]
1555               ["Add buttons" gnus-article-add-buttons t]
1556               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1557               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1558               ["Toggle MIME" gnus-summary-toggle-mime t]
1559               ["Verbose header" gnus-summary-verbose-headers t]
1560               ["Toggle header" gnus-summary-toggle-header t])
1561              ("Output"
1562               ["Save in default format" gnus-summary-save-article t]
1563               ["Save in file" gnus-summary-save-article-file t]
1564               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1565               ["Save in MH folder" gnus-summary-save-article-folder t]
1566               ["Save in VM folder" gnus-summary-save-article-vm t]
1567               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1568               ["Save body in file" gnus-summary-save-article-body-file t]
1569               ["Pipe through a filter" gnus-summary-pipe-output t]
1570               ["Add to SOUP packet" gnus-soup-add-article t]
1571               ["Print" gnus-summary-print-article t])
1572              ("Backend"
1573               ["Respool article..." gnus-summary-respool-article t]
1574               ["Move article..." gnus-summary-move-article
1575                (gnus-check-backend-function
1576                 'request-move-article gnus-newsgroup-name)]
1577               ["Copy article..." gnus-summary-copy-article t]
1578               ["Crosspost article..." gnus-summary-crosspost-article
1579                (gnus-check-backend-function
1580                 'request-replace-article gnus-newsgroup-name)]
1581               ["Import file..." gnus-summary-import-article t]
1582               ["Check if posted" gnus-summary-article-posted-p t]
1583               ["Edit article" gnus-summary-edit-article
1584                (not (gnus-group-read-only-p))]
1585               ["Delete article" gnus-summary-delete-article
1586                (gnus-check-backend-function
1587                 'request-expire-articles gnus-newsgroup-name)]
1588               ["Query respool" gnus-summary-respool-query t]
1589               ["Trace respool" gnus-summary-respool-trace t]
1590               ["Delete expirable articles" gnus-summary-expire-articles-now
1591                (gnus-check-backend-function
1592                 'request-expire-articles gnus-newsgroup-name)])
1593              ("Extract"
1594               ["Uudecode" gnus-uu-decode-uu t]
1595               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1596               ["Unshar" gnus-uu-decode-unshar t]
1597               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1598               ["Save" gnus-uu-decode-save t]
1599               ["Binhex" gnus-uu-decode-binhex t]
1600               ["Postscript" gnus-uu-decode-postscript t])
1601              ("Cache"
1602               ["Enter article" gnus-cache-enter-article t]
1603               ["Remove article" gnus-cache-remove-article t])
1604              ["Select article buffer" gnus-summary-select-article-buffer t]
1605              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1606              ["Isearch article..." gnus-summary-isearch-article t]
1607              ["Beginning of the article" gnus-summary-beginning-of-article t]
1608              ["End of the article" gnus-summary-end-of-article t]
1609              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1610              ["Fetch referenced articles" gnus-summary-refer-references t]
1611              ["Fetch current thread" gnus-summary-refer-thread t]
1612              ["Fetch article with id..." gnus-summary-refer-article t]
1613              ["Redisplay" gnus-summary-show-article t])))
1614       (easy-menu-define
1615        gnus-summary-article-menu gnus-summary-mode-map ""
1616        (cons "Article" innards))
1617
1618       (easy-menu-define
1619        gnus-article-commands-menu gnus-article-mode-map ""
1620        (cons "Commands" innards)))
1621
1622     (easy-menu-define
1623      gnus-summary-thread-menu gnus-summary-mode-map ""
1624      '("Threads"
1625        ["Toggle threading" gnus-summary-toggle-threads t]
1626        ["Hide threads" gnus-summary-hide-all-threads t]
1627        ["Show threads" gnus-summary-show-all-threads t]
1628        ["Hide thread" gnus-summary-hide-thread t]
1629        ["Show thread" gnus-summary-show-thread t]
1630        ["Go to next thread" gnus-summary-next-thread t]
1631        ["Go to previous thread" gnus-summary-prev-thread t]
1632        ["Go down thread" gnus-summary-down-thread t]
1633        ["Go up thread" gnus-summary-up-thread t]
1634        ["Top of thread" gnus-summary-top-thread t]
1635        ["Mark thread as read" gnus-summary-kill-thread t]
1636        ["Lower thread score" gnus-summary-lower-thread t]
1637        ["Raise thread score" gnus-summary-raise-thread t]
1638        ["Rethread current" gnus-summary-rethread-current t]
1639        ))
1640
1641     (easy-menu-define
1642      gnus-summary-post-menu gnus-summary-mode-map ""
1643      '("Post"
1644        ["Post an article" gnus-summary-post-news t]
1645        ["Followup" gnus-summary-followup t]
1646        ["Followup and yank" gnus-summary-followup-with-original t]
1647        ["Supersede article" gnus-summary-supersede-article t]
1648        ["Cancel article" gnus-summary-cancel-article t]
1649        ["Reply" gnus-summary-reply t]
1650        ["Reply and yank" gnus-summary-reply-with-original t]
1651        ["Wide reply" gnus-summary-wide-reply t]
1652        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
1653        ["Mail forward" gnus-summary-mail-forward t]
1654        ["Post forward" gnus-summary-post-forward t]
1655        ["Digest and mail" gnus-summary-mail-digest t]
1656        ["Digest and post" gnus-summary-post-digest t]
1657        ["Resend message" gnus-summary-resend-message t]
1658        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1659        ["Send a mail" gnus-summary-mail-other-window t]
1660        ["Uuencode and post" gnus-uu-post-news t]
1661        ["Followup via news" gnus-summary-followup-to-mail t]
1662        ["Followup via news and yank"
1663         gnus-summary-followup-to-mail-with-original t]
1664        ;;("Draft"
1665        ;;["Send" gnus-summary-send-draft t]
1666        ;;["Send bounced" gnus-resend-bounced-mail t])
1667        ))
1668
1669     (easy-menu-define
1670      gnus-summary-misc-menu gnus-summary-mode-map ""
1671      '("Misc"
1672        ("Mark Read"
1673         ["Mark as read" gnus-summary-mark-as-read-forward t]
1674         ["Mark same subject and select"
1675          gnus-summary-kill-same-subject-and-select t]
1676         ["Mark same subject" gnus-summary-kill-same-subject t]
1677         ["Catchup" gnus-summary-catchup t]
1678         ["Catchup all" gnus-summary-catchup-all t]
1679         ["Catchup to here" gnus-summary-catchup-to-here t]
1680         ["Catchup region" gnus-summary-mark-region-as-read t]
1681         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1682        ("Mark Various"
1683         ["Tick" gnus-summary-tick-article-forward t]
1684         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1685         ["Remove marks" gnus-summary-clear-mark-forward t]
1686         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1687         ["Set bookmark" gnus-summary-set-bookmark t]
1688         ["Remove bookmark" gnus-summary-remove-bookmark t])
1689        ("Mark Limit"
1690         ["Marks..." gnus-summary-limit-to-marks t]
1691         ["Subject..." gnus-summary-limit-to-subject t]
1692         ["Author..." gnus-summary-limit-to-author t]
1693         ["Age..." gnus-summary-limit-to-age t]
1694         ["Score" gnus-summary-limit-to-score t]
1695         ["Unread" gnus-summary-limit-to-unread t]
1696         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1697         ["Articles" gnus-summary-limit-to-articles t]
1698         ["Pop limit" gnus-summary-pop-limit t]
1699         ["Show dormant" gnus-summary-limit-include-dormant t]
1700         ["Hide childless dormant"
1701          gnus-summary-limit-exclude-childless-dormant t]
1702         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1703         ["Show expunged" gnus-summary-show-all-expunged t])
1704        ("Process Mark"
1705         ["Set mark" gnus-summary-mark-as-processable t]
1706         ["Remove mark" gnus-summary-unmark-as-processable t]
1707         ["Remove all marks" gnus-summary-unmark-all-processable t]
1708         ["Mark above" gnus-uu-mark-over t]
1709         ["Mark series" gnus-uu-mark-series t]
1710         ["Mark region" gnus-uu-mark-region t]
1711         ["Unmark region" gnus-uu-unmark-region t]
1712         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1713         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1714         ["Mark all" gnus-uu-mark-all t]
1715         ["Mark buffer" gnus-uu-mark-buffer t]
1716         ["Mark sparse" gnus-uu-mark-sparse t]
1717         ["Mark thread" gnus-uu-mark-thread t]
1718         ["Unmark thread" gnus-uu-unmark-thread t]
1719         ("Process Mark Sets"
1720          ["Kill" gnus-summary-kill-process-mark t]
1721          ["Yank" gnus-summary-yank-process-mark
1722           gnus-newsgroup-process-stack]
1723          ["Save" gnus-summary-save-process-mark t]))
1724        ("Scroll article"
1725         ["Page forward" gnus-summary-next-page t]
1726         ["Page backward" gnus-summary-prev-page t]
1727         ["Line forward" gnus-summary-scroll-up t])
1728        ("Move"
1729         ["Next unread article" gnus-summary-next-unread-article t]
1730         ["Previous unread article" gnus-summary-prev-unread-article t]
1731         ["Next article" gnus-summary-next-article t]
1732         ["Previous article" gnus-summary-prev-article t]
1733         ["Next unread subject" gnus-summary-next-unread-subject t]
1734         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1735         ["Next article same subject" gnus-summary-next-same-subject t]
1736         ["Previous article same subject" gnus-summary-prev-same-subject t]
1737         ["First unread article" gnus-summary-first-unread-article t]
1738         ["Best unread article" gnus-summary-best-unread-article t]
1739         ["Go to subject number..." gnus-summary-goto-subject t]
1740         ["Go to article number..." gnus-summary-goto-article t]
1741         ["Go to the last article" gnus-summary-goto-last-article t]
1742         ["Pop article off history" gnus-summary-pop-article t])
1743        ("Sort"
1744         ["Sort by number" gnus-summary-sort-by-number t]
1745         ["Sort by author" gnus-summary-sort-by-author t]
1746         ["Sort by subject" gnus-summary-sort-by-subject t]
1747         ["Sort by date" gnus-summary-sort-by-date t]
1748         ["Sort by score" gnus-summary-sort-by-score t]
1749         ["Sort by lines" gnus-summary-sort-by-lines t])
1750        ("Help"
1751         ["Fetch group FAQ" gnus-summary-fetch-faq t]
1752         ["Describe group" gnus-summary-describe-group t]
1753         ["Read manual" gnus-info-find-node t])
1754        ("Modes"
1755         ["Pick and read" gnus-pick-mode t]
1756         ["Binary" gnus-binary-mode t])
1757        ("Regeneration"
1758         ["Regenerate" gnus-summary-prepare t]
1759         ["Insert cached articles" gnus-summary-insert-cached-articles t]
1760         ["Toggle threading" gnus-summary-toggle-threads t])
1761        ["Filter articles..." gnus-summary-execute-command t]
1762        ["Run command on subjects..." gnus-summary-universal-argument t]
1763        ["Search articles forward..." gnus-summary-search-article-forward t]
1764        ["Search articles backward..." gnus-summary-search-article-backward t]
1765        ["Toggle line truncation" gnus-summary-toggle-truncation t]
1766        ["Expand window" gnus-summary-expand-window t]
1767        ["Expire expirable articles" gnus-summary-expire-articles
1768         (gnus-check-backend-function
1769          'request-expire-articles gnus-newsgroup-name)]
1770        ["Edit local kill file" gnus-summary-edit-local-kill t]
1771        ["Edit main kill file" gnus-summary-edit-global-kill t]
1772        ["Edit group parameters" gnus-summary-edit-parameters t]
1773        ["Customize group parameters" gnus-summary-customize-parameters t]
1774        ["Send a bug report" gnus-bug t]
1775        ("Exit"
1776         ["Catchup and exit" gnus-summary-catchup-and-exit t]
1777         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
1778         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
1779         ["Exit group" gnus-summary-exit t]
1780         ["Exit group without updating" gnus-summary-exit-no-update t]
1781         ["Exit and goto next group" gnus-summary-next-group t]
1782         ["Exit and goto prev group" gnus-summary-prev-group t]
1783         ["Reselect group" gnus-summary-reselect-current-group t]
1784         ["Rescan group" gnus-summary-rescan-group t]
1785         ["Update dribble" gnus-summary-save-newsrc t])))
1786
1787     (gnus-run-hooks 'gnus-summary-menu-hook)))
1788
1789 (defun gnus-score-set-default (var value)
1790   "A version of set that updates the GNU Emacs menu-bar."
1791   (set var value)
1792   ;; It is the message that forces the active status to be updated.
1793   (message ""))
1794
1795 (defun gnus-make-score-map (type)
1796   "Make a summary score map of type TYPE."
1797   (if t
1798       nil
1799     (let ((headers '(("author" "from" string)
1800                      ("subject" "subject" string)
1801                      ("article body" "body" string)
1802                      ("article head" "head" string)
1803                      ("xref" "xref" string)
1804                      ("extra header" "extra" string)
1805                      ("lines" "lines" number)
1806                      ("followups to author" "followup" string)))
1807           (types '((number ("less than" <)
1808                            ("greater than" >)
1809                            ("equal" =))
1810                    (string ("substring" s)
1811                            ("exact string" e)
1812                            ("fuzzy string" f)
1813                            ("regexp" r))))
1814           (perms '(("temporary" (current-time-string))
1815                    ("permanent" nil)
1816                    ("immediate" now)))
1817           header)
1818       (list
1819        (apply
1820         'nconc
1821         (list
1822          (if (eq type 'lower)
1823              "Lower score"
1824            "Increase score"))
1825         (let (outh)
1826           (while headers
1827             (setq header (car headers))
1828             (setq outh
1829                   (cons
1830                    (apply
1831                     'nconc
1832                     (list (car header))
1833                     (let ((ts (cdr (assoc (nth 2 header) types)))
1834                           outt)
1835                       (while ts
1836                         (setq outt
1837                               (cons
1838                                (apply
1839                                 'nconc
1840                                 (list (caar ts))
1841                                 (let ((ps perms)
1842                                       outp)
1843                                   (while ps
1844                                     (setq outp
1845                                           (cons
1846                                            (vector
1847                                             (caar ps)
1848                                             (list
1849                                              'gnus-summary-score-entry
1850                                              (nth 1 header)
1851                                              (if (or (string= (nth 1 header)
1852                                                               "head")
1853                                                      (string= (nth 1 header)
1854                                                               "body"))
1855                                                  ""
1856                                                (list 'gnus-summary-header
1857                                                      (nth 1 header)))
1858                                              (list 'quote (nth 1 (car ts)))
1859                                              (list 'gnus-score-default nil)
1860                                              (nth 1 (car ps))
1861                                              t)
1862                                             t)
1863                                            outp))
1864                                     (setq ps (cdr ps)))
1865                                   (list (nreverse outp))))
1866                                outt))
1867                         (setq ts (cdr ts)))
1868                       (list (nreverse outt))))
1869                    outh))
1870             (setq headers (cdr headers)))
1871           (list (nreverse outh))))))))
1872
1873 \f
1874
1875 (defun gnus-summary-mode (&optional group)
1876   "Major mode for reading articles.
1877
1878 All normal editing commands are switched off.
1879 \\<gnus-summary-mode-map>
1880 Each line in this buffer represents one article.  To read an
1881 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
1882 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
1883 respectively.
1884
1885 You can also post articles and send mail from this buffer.  To
1886 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
1887 of an article, type `\\[gnus-summary-reply]'.
1888
1889 There are approx. one gazillion commands you can execute in this
1890 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
1891
1892 The following commands are available:
1893
1894 \\{gnus-summary-mode-map}"
1895   (interactive)
1896   (when (gnus-visual-p 'summary-menu 'menu)
1897     (gnus-summary-make-menu-bar))
1898   (kill-all-local-variables)
1899   (gnus-summary-make-local-variables)
1900   (gnus-make-thread-indent-array)
1901   (gnus-simplify-mode-line)
1902   (setq major-mode 'gnus-summary-mode)
1903   (setq mode-name "Summary")
1904   (make-local-variable 'minor-mode-alist)
1905   (use-local-map gnus-summary-mode-map)
1906   (buffer-disable-undo)
1907   (setq buffer-read-only t)             ;Disable modification
1908   (setq truncate-lines t)
1909   (setq selective-display t)
1910   (setq selective-display-ellipses t)   ;Display `...'
1911   (gnus-summary-set-display-table)
1912   (gnus-set-default-directory)
1913   (setq gnus-newsgroup-name group)
1914   (make-local-variable 'gnus-summary-line-format)
1915   (make-local-variable 'gnus-summary-line-format-spec)
1916   (make-local-variable 'gnus-summary-dummy-line-format)
1917   (make-local-variable 'gnus-summary-dummy-line-format-spec)
1918   (make-local-variable 'gnus-summary-mark-positions)
1919   (make-local-hook 'post-command-hook)
1920   (add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
1921   (make-local-hook 'pre-command-hook)
1922   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
1923   (gnus-run-hooks 'gnus-summary-mode-hook)
1924   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
1925   (gnus-update-summary-mark-positions))
1926
1927 (defun gnus-summary-make-local-variables ()
1928   "Make all the local summary buffer variables."
1929   (let ((locals gnus-summary-local-variables)
1930         global local)
1931     (while (setq local (pop locals))
1932       (if (consp local)
1933           (progn
1934             (if (eq (cdr local) 'global)
1935                 ;; Copy the global value of the variable.
1936                 (setq global (symbol-value (car local)))
1937               ;; Use the value from the list.
1938               (setq global (eval (cdr local))))
1939             (make-local-variable (car local))
1940             (set (car local) global))
1941         ;; Simple nil-valued local variable.
1942         (make-local-variable local)
1943         (set local nil)))))
1944
1945 (defun gnus-summary-clear-local-variables ()
1946   (let ((locals gnus-summary-local-variables))
1947     (while locals
1948       (if (consp (car locals))
1949           (and (vectorp (caar locals))
1950                (set (caar locals) nil))
1951         (and (vectorp (car locals))
1952              (set (car locals) nil)))
1953       (setq locals (cdr locals)))))
1954
1955 ;; Summary data functions.
1956
1957 (defmacro gnus-data-number (data)
1958   `(car ,data))
1959
1960 (defmacro gnus-data-set-number (data number)
1961   `(setcar ,data ,number))
1962
1963 (defmacro gnus-data-mark (data)
1964   `(nth 1 ,data))
1965
1966 (defmacro gnus-data-set-mark (data mark)
1967   `(setcar (nthcdr 1 ,data) ,mark))
1968
1969 (defmacro gnus-data-pos (data)
1970   `(nth 2 ,data))
1971
1972 (defmacro gnus-data-set-pos (data pos)
1973   `(setcar (nthcdr 2 ,data) ,pos))
1974
1975 (defmacro gnus-data-header (data)
1976   `(nth 3 ,data))
1977
1978 (defmacro gnus-data-set-header (data header)
1979   `(setf (nth 3 ,data) ,header))
1980
1981 (defmacro gnus-data-level (data)
1982   `(nth 4 ,data))
1983
1984 (defmacro gnus-data-unread-p (data)
1985   `(= (nth 1 ,data) gnus-unread-mark))
1986
1987 (defmacro gnus-data-read-p (data)
1988   `(/= (nth 1 ,data) gnus-unread-mark))
1989
1990 (defmacro gnus-data-pseudo-p (data)
1991   `(consp (nth 3 ,data)))
1992
1993 (defmacro gnus-data-find (number)
1994   `(assq ,number gnus-newsgroup-data))
1995
1996 (defmacro gnus-data-find-list (number &optional data)
1997   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
1998      (memq (assq ,number bdata)
1999            bdata)))
2000
2001 (defmacro gnus-data-make (number mark pos header level)
2002   `(list ,number ,mark ,pos ,header ,level))
2003
2004 (defun gnus-data-enter (after-article number mark pos header level offset)
2005   (let ((data (gnus-data-find-list after-article)))
2006     (unless data
2007       (error "No such article: %d" after-article))
2008     (setcdr data (cons (gnus-data-make number mark pos header level)
2009                        (cdr data)))
2010     (setq gnus-newsgroup-data-reverse nil)
2011     (gnus-data-update-list (cddr data) offset)))
2012
2013 (defun gnus-data-enter-list (after-article list &optional offset)
2014   (when list
2015     (let ((data (and after-article (gnus-data-find-list after-article)))
2016           (ilist list))
2017       (if (not (or data
2018                    after-article))
2019           (let ((odata gnus-newsgroup-data))
2020             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2021             (when offset
2022               (gnus-data-update-list odata offset)))
2023         ;; Find the last element in the list to be spliced into the main
2024         ;; list.
2025         (while (cdr list)
2026           (setq list (cdr list)))
2027         (if (not data)
2028             (progn
2029               (setcdr list gnus-newsgroup-data)
2030               (setq gnus-newsgroup-data ilist)
2031               (when offset
2032                 (gnus-data-update-list (cdr list) offset)))
2033           (setcdr list (cdr data))
2034           (setcdr data ilist)
2035           (when offset
2036             (gnus-data-update-list (cdr list) offset))))
2037       (setq gnus-newsgroup-data-reverse nil))))
2038
2039 (defun gnus-data-remove (article &optional offset)
2040   (let ((data gnus-newsgroup-data))
2041     (if (= (gnus-data-number (car data)) article)
2042         (progn
2043           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2044                 gnus-newsgroup-data-reverse nil)
2045           (when offset
2046             (gnus-data-update-list gnus-newsgroup-data offset)))
2047       (while (cdr data)
2048         (when (= (gnus-data-number (cadr data)) article)
2049           (setcdr data (cddr data))
2050           (when offset
2051             (gnus-data-update-list (cdr data) offset))
2052           (setq data nil
2053                 gnus-newsgroup-data-reverse nil))
2054         (setq data (cdr data))))))
2055
2056 (defmacro gnus-data-list (backward)
2057   `(if ,backward
2058        (or gnus-newsgroup-data-reverse
2059            (setq gnus-newsgroup-data-reverse
2060                  (reverse gnus-newsgroup-data)))
2061      gnus-newsgroup-data))
2062
2063 (defun gnus-data-update-list (data offset)
2064   "Add OFFSET to the POS of all data entries in DATA."
2065   (setq gnus-newsgroup-data-reverse nil)
2066   (while data
2067     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2068     (setq data (cdr data))))
2069
2070 (defun gnus-summary-article-pseudo-p (article)
2071   "Say whether this article is a pseudo article or not."
2072   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2073
2074 (defmacro gnus-summary-article-sparse-p (article)
2075   "Say whether this article is a sparse article or not."
2076   `(memq ,article gnus-newsgroup-sparse))
2077
2078 (defmacro gnus-summary-article-ancient-p (article)
2079   "Say whether this article is a sparse article or not."
2080   `(memq ,article gnus-newsgroup-ancient))
2081
2082 (defun gnus-article-parent-p (number)
2083   "Say whether this article is a parent or not."
2084   (let ((data (gnus-data-find-list number)))
2085     (and (cdr data)                     ; There has to be an article after...
2086          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2087             (gnus-data-level (nth 1 data))))))
2088
2089 (defun gnus-article-children (number)
2090   "Return a list of all children to NUMBER."
2091   (let* ((data (gnus-data-find-list number))
2092          (level (gnus-data-level (car data)))
2093          children)
2094     (setq data (cdr data))
2095     (while (and data
2096                 (= (gnus-data-level (car data)) (1+ level)))
2097       (push (gnus-data-number (car data)) children)
2098       (setq data (cdr data)))
2099     children))
2100
2101 (defmacro gnus-summary-skip-intangible ()
2102   "If the current article is intangible, then jump to a different article."
2103   '(let ((to (get-text-property (point) 'gnus-intangible)))
2104      (and to (gnus-summary-goto-subject to))))
2105
2106 (defmacro gnus-summary-article-intangible-p ()
2107   "Say whether this article is intangible or not."
2108   '(get-text-property (point) 'gnus-intangible))
2109
2110 (defun gnus-article-read-p (article)
2111   "Say whether ARTICLE is read or not."
2112   (not (or (memq article gnus-newsgroup-marked)
2113            (memq article gnus-newsgroup-unreads)
2114            (memq article gnus-newsgroup-unselected)
2115            (memq article gnus-newsgroup-dormant))))
2116
2117 ;; Some summary mode macros.
2118
2119 (defmacro gnus-summary-article-number ()
2120   "The article number of the article on the current line.
2121 If there isn's an article number here, then we return the current
2122 article number."
2123   '(progn
2124      (gnus-summary-skip-intangible)
2125      (or (get-text-property (point) 'gnus-number)
2126          (gnus-summary-last-subject))))
2127
2128 (defmacro gnus-summary-article-header (&optional number)
2129   "Return the header of article NUMBER."
2130   `(gnus-data-header (gnus-data-find
2131                       ,(or number '(gnus-summary-article-number)))))
2132
2133 (defmacro gnus-summary-thread-level (&optional number)
2134   "Return the level of thread that starts with article NUMBER."
2135   `(if (and (eq gnus-summary-make-false-root 'dummy)
2136             (get-text-property (point) 'gnus-intangible))
2137        0
2138      (gnus-data-level (gnus-data-find
2139                        ,(or number '(gnus-summary-article-number))))))
2140
2141 (defmacro gnus-summary-article-mark (&optional number)
2142   "Return the mark of article NUMBER."
2143   `(gnus-data-mark (gnus-data-find
2144                     ,(or number '(gnus-summary-article-number)))))
2145
2146 (defmacro gnus-summary-article-pos (&optional number)
2147   "Return the position of the line of article NUMBER."
2148   `(gnus-data-pos (gnus-data-find
2149                    ,(or number '(gnus-summary-article-number)))))
2150
2151 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2152 (defmacro gnus-summary-article-subject (&optional number)
2153   "Return current subject string or nil if nothing."
2154   `(let ((headers
2155           ,(if number
2156                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2157              '(gnus-data-header (assq (gnus-summary-article-number)
2158                                       gnus-newsgroup-data)))))
2159      (and headers
2160           (vectorp headers)
2161           (mail-header-subject headers))))
2162
2163 (defmacro gnus-summary-article-score (&optional number)
2164   "Return current article score."
2165   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2166                   gnus-newsgroup-scored))
2167        gnus-summary-default-score 0))
2168
2169 (defun gnus-summary-article-children (&optional number)
2170   "Return a list of article numbers that are children of article NUMBER."
2171   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2172          (level (gnus-data-level (car data)))
2173          l children)
2174     (while (and (setq data (cdr data))
2175                 (> (setq l (gnus-data-level (car data))) level))
2176       (and (= (1+ level) l)
2177            (push (gnus-data-number (car data))
2178                  children)))
2179     (nreverse children)))
2180
2181 (defun gnus-summary-article-parent (&optional number)
2182   "Return the article number of the parent of article NUMBER."
2183   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2184                                     (gnus-data-list t)))
2185          (level (gnus-data-level (car data))))
2186     (if (zerop level)
2187         ()                              ; This is a root.
2188       ;; We search until we find an article with a level less than
2189       ;; this one.  That function has to be the parent.
2190       (while (and (setq data (cdr data))
2191                   (not (< (gnus-data-level (car data)) level))))
2192       (and data (gnus-data-number (car data))))))
2193
2194 (defun gnus-unread-mark-p (mark)
2195   "Say whether MARK is the unread mark."
2196   (= mark gnus-unread-mark))
2197
2198 (defun gnus-read-mark-p (mark)
2199   "Say whether MARK is one of the marks that mark as read.
2200 This is all marks except unread, ticked, dormant, and expirable."
2201   (not (or (= mark gnus-unread-mark)
2202            (= mark gnus-ticked-mark)
2203            (= mark gnus-dormant-mark)
2204            (= mark gnus-expirable-mark))))
2205
2206 (defmacro gnus-article-mark (number)
2207   "Return the MARK of article NUMBER.
2208 This macro should only be used when computing the mark the \"first\"
2209 time; i.e., when generating the summary lines.  After that,
2210 `gnus-summary-article-mark' should be used to examine the
2211 marks of articles."
2212   `(cond
2213     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2214     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2215     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2216     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2217     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2218     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2219     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2220     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2221            gnus-ancient-mark))))
2222
2223 ;; Saving hidden threads.
2224
2225 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2226 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2227
2228 (defmacro gnus-save-hidden-threads (&rest forms)
2229   "Save hidden threads, eval FORMS, and restore the hidden threads."
2230   (let ((config (make-symbol "config")))
2231     `(let ((,config (gnus-hidden-threads-configuration)))
2232        (unwind-protect
2233            (save-excursion
2234              ,@forms)
2235          (gnus-restore-hidden-threads-configuration ,config)))))
2236
2237 (defun gnus-data-compute-positions ()
2238   "Compute the positions of all articles."
2239   (setq gnus-newsgroup-data-reverse nil)
2240   (let ((data gnus-newsgroup-data))
2241     (save-excursion
2242       (gnus-save-hidden-threads
2243         (gnus-summary-show-all-threads)
2244         (goto-char (point-min))
2245         (while data
2246           (while (get-text-property (point) 'gnus-intangible)
2247             (forward-line 1))
2248           (gnus-data-set-pos (car data) (+ (point) 3))
2249           (setq data (cdr data))
2250           (forward-line 1))))))
2251
2252 (defun gnus-hidden-threads-configuration ()
2253   "Return the current hidden threads configuration."
2254   (save-excursion
2255     (let (config)
2256       (goto-char (point-min))
2257       (while (search-forward "\r" nil t)
2258         (push (1- (point)) config))
2259       config)))
2260
2261 (defun gnus-restore-hidden-threads-configuration (config)
2262   "Restore hidden threads configuration from CONFIG."
2263   (let (point buffer-read-only)
2264     (while (setq point (pop config))
2265       (when (and (< point (point-max))
2266                  (goto-char point)
2267                  (eq (char-after) ?\n))
2268         (subst-char-in-region point (1+ point) ?\n ?\r)))))
2269
2270 ;; Various summary mode internalish functions.
2271
2272 (defun gnus-mouse-pick-article (e)
2273   (interactive "e")
2274   (mouse-set-point e)
2275   (gnus-summary-next-page nil t))
2276
2277 (defun gnus-summary-set-display-table ()
2278   ;; Change the display table.  Odd characters have a tendency to mess
2279   ;; up nicely formatted displays - we make all possible glyphs
2280   ;; display only a single character.
2281
2282   ;; We start from the standard display table, if any.
2283   (let ((table (or (copy-sequence standard-display-table)
2284                    (make-display-table)))
2285         (i 32))
2286     ;; Nix out all the control chars...
2287     (while (>= (setq i (1- i)) 0)
2288       (aset table i [??]))
2289     ;; ... but not newline and cr, of course.  (cr is necessary for the
2290     ;; selective display).
2291     (aset table ?\n nil)
2292     (aset table ?\r nil)
2293     ;; We keep TAB as well.
2294     (aset table ?\t nil)
2295     ;; We nix out any glyphs over 126 that are not set already.
2296     (let ((i 256))
2297       (while (>= (setq i (1- i)) 127)
2298         ;; Only modify if the entry is nil.
2299         (unless (aref table i)
2300           (aset table i [??]))))
2301     (setq buffer-display-table table)))
2302
2303 (defun gnus-summary-setup-buffer (group)
2304   "Initialize summary buffer."
2305   (let ((buffer (concat "*Summary " group "*")))
2306     (if (get-buffer buffer)
2307         (progn
2308           (set-buffer buffer)
2309           (setq gnus-summary-buffer (current-buffer))
2310           (not gnus-newsgroup-prepared))
2311       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2312       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2313       (gnus-summary-mode group)
2314       (when gnus-carpal
2315         (gnus-carpal-setup-buffer 'summary))
2316       (unless gnus-single-article-buffer
2317         (make-local-variable 'gnus-article-buffer)
2318         (make-local-variable 'gnus-article-current)
2319         (make-local-variable 'gnus-original-article-buffer))
2320       (setq gnus-newsgroup-name group)
2321       t)))
2322
2323 (defun gnus-set-global-variables ()
2324   ;; Set the global equivalents of the summary buffer-local variables
2325   ;; to the latest values they had.  These reflect the summary buffer
2326   ;; that was in action when the last article was fetched.
2327   (when (eq major-mode 'gnus-summary-mode)
2328     (setq gnus-summary-buffer (current-buffer))
2329     (let ((name gnus-newsgroup-name)
2330           (marked gnus-newsgroup-marked)
2331           (unread gnus-newsgroup-unreads)
2332           (headers gnus-current-headers)
2333           (data gnus-newsgroup-data)
2334           (summary gnus-summary-buffer)
2335           (article-buffer gnus-article-buffer)
2336           (original gnus-original-article-buffer)
2337           (gac gnus-article-current)
2338           (reffed gnus-reffed-article-number)
2339           (score-file gnus-current-score-file))
2340       (save-excursion
2341         (set-buffer gnus-group-buffer)
2342         (setq gnus-newsgroup-name name
2343               gnus-newsgroup-marked marked
2344               gnus-newsgroup-unreads unread
2345               gnus-current-headers headers
2346               gnus-newsgroup-data data
2347               gnus-article-current gac
2348               gnus-summary-buffer summary
2349               gnus-article-buffer article-buffer
2350               gnus-original-article-buffer original
2351               gnus-reffed-article-number reffed
2352               gnus-current-score-file score-file)
2353         ;; The article buffer also has local variables.
2354         (when (gnus-buffer-live-p gnus-article-buffer)
2355           (set-buffer gnus-article-buffer)
2356           (setq gnus-summary-buffer summary))))))
2357
2358 (defun gnus-summary-article-unread-p (article)
2359   "Say whether ARTICLE is unread or not."
2360   (memq article gnus-newsgroup-unreads))
2361
2362 (defun gnus-summary-first-article-p (&optional article)
2363   "Return whether ARTICLE is the first article in the buffer."
2364   (if (not (setq article (or article (gnus-summary-article-number))))
2365       nil
2366     (eq article (caar gnus-newsgroup-data))))
2367
2368 (defun gnus-summary-last-article-p (&optional article)
2369   "Return whether ARTICLE is the last article in the buffer."
2370   (if (not (setq article (or article (gnus-summary-article-number))))
2371       t                                 ; All non-existent numbers are the last article.  :-)
2372     (not (cdr (gnus-data-find-list article)))))
2373
2374 (defun gnus-make-thread-indent-array ()
2375   (let ((n 200))
2376     (unless (and gnus-thread-indent-array
2377                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2378       (setq gnus-thread-indent-array (make-vector 201 "")
2379             gnus-thread-indent-array-level gnus-thread-indent-level)
2380       (while (>= n 0)
2381         (aset gnus-thread-indent-array n
2382               (make-string (* n gnus-thread-indent-level) ? ))
2383         (setq n (1- n))))))
2384
2385 (defun gnus-update-summary-mark-positions ()
2386   "Compute where the summary marks are to go."
2387   (save-excursion
2388     (when (gnus-buffer-exists-p gnus-summary-buffer)
2389       (set-buffer gnus-summary-buffer))
2390     (let ((gnus-replied-mark 129)
2391           (gnus-score-below-mark 130)
2392           (gnus-score-over-mark 130)
2393           (gnus-download-mark 131)
2394           (spec gnus-summary-line-format-spec)
2395           gnus-visual pos)
2396       (save-excursion
2397         (gnus-set-work-buffer)
2398         (let ((gnus-summary-line-format-spec spec)
2399               (gnus-newsgroup-downloadable '((0 . t))))
2400           (gnus-summary-insert-line
2401            (make-full-mail-header 0 "" "" "" "" "" 0 0 "" nil)
2402            0 nil 128 t nil "" nil 1)
2403           (goto-char (point-min))
2404           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2405                                              (- (point) 2)))))
2406           (goto-char (point-min))
2407           (push (cons 'replied (and (search-forward "\201" nil t)
2408                                     (- (point) 2)))
2409                 pos)
2410           (goto-char (point-min))
2411           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2412                 pos)
2413           (goto-char (point-min))
2414           (push (cons 'download
2415                       (and (search-forward "\203" nil t) (- (point) 2)))
2416                 pos)))
2417       (setq gnus-summary-mark-positions pos))))
2418
2419 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2420   "Insert a dummy root in the summary buffer."
2421   (beginning-of-line)
2422   (gnus-add-text-properties
2423    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2424    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2425
2426 (defun gnus-summary-from-or-to-or-newsgroups (header)
2427   (let ((to (cdr (assq 'To (mail-header-extra header))))
2428         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header)))))
2429     (cond
2430      ((and to
2431            gnus-ignored-from-addresses
2432            (string-match gnus-ignored-from-addresses
2433                          (mail-header-from header)))
2434       (concat "-> "
2435               (or (car (funcall gnus-extract-address-components
2436                                 (funcall
2437                                  gnus-decode-encoded-word-function to)))
2438                   (funcall gnus-decode-encoded-word-function to))))
2439      ((and newsgroups
2440            gnus-ignored-from-addresses
2441            (string-match gnus-ignored-from-addresses
2442                          (mail-header-from header)))
2443       (concat "=> " newsgroups))
2444      (t
2445       (or (car (funcall gnus-extract-address-components
2446                         (mail-header-from header)))
2447           (mail-header-from header))))))
2448
2449 (defun gnus-summary-insert-line (gnus-tmp-header
2450                                  gnus-tmp-level gnus-tmp-current
2451                                  gnus-tmp-unread gnus-tmp-replied
2452                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2453                                  &optional gnus-tmp-dummy gnus-tmp-score
2454                                  gnus-tmp-process)
2455   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2456          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2457          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2458          (gnus-tmp-score-char
2459           (if (or (null gnus-summary-default-score)
2460                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2461                       gnus-summary-zcore-fuzz))
2462               ? 
2463             (if (< gnus-tmp-score gnus-summary-default-score)
2464                 gnus-score-below-mark gnus-score-over-mark)))
2465          (gnus-tmp-replied
2466           (cond (gnus-tmp-process gnus-process-mark)
2467                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2468                  gnus-cached-mark)
2469                 (gnus-tmp-replied gnus-replied-mark)
2470                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2471                  gnus-saved-mark)
2472                 (t gnus-unread-mark)))
2473          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2474          (gnus-tmp-name
2475           (cond
2476            ((string-match "<[^>]+> *$" gnus-tmp-from)
2477             (let ((beg (match-beginning 0)))
2478               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2479                        (substring gnus-tmp-from (1+ (match-beginning 0))
2480                                   (1- (match-end 0))))
2481                   (substring gnus-tmp-from 0 beg))))
2482            ((string-match "(.+)" gnus-tmp-from)
2483             (substring gnus-tmp-from
2484                        (1+ (match-beginning 0)) (1- (match-end 0))))
2485            (t gnus-tmp-from)))
2486          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2487          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2488          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2489          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2490          (buffer-read-only nil))
2491     (when (string= gnus-tmp-name "")
2492       (setq gnus-tmp-name gnus-tmp-from))
2493     (unless (numberp gnus-tmp-lines)
2494       (setq gnus-tmp-lines 0))
2495     (gnus-put-text-property-excluding-characters-with-faces
2496      (point)
2497      (progn (eval gnus-summary-line-format-spec) (point))
2498      'gnus-number gnus-tmp-number)
2499     (when (gnus-visual-p 'summary-highlight 'highlight)
2500       (forward-line -1)
2501       (gnus-run-hooks 'gnus-summary-update-hook)
2502       (forward-line 1))))
2503
2504 (defun gnus-summary-update-line (&optional dont-update)
2505   ;; Update summary line after change.
2506   (when (and gnus-summary-default-score
2507              (not gnus-summary-inhibit-highlight))
2508     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2509            (article (gnus-summary-article-number))
2510            (score (gnus-summary-article-score article)))
2511       (unless dont-update
2512         (if (and gnus-summary-mark-below
2513                  (< (gnus-summary-article-score)
2514                     gnus-summary-mark-below))
2515             ;; This article has a low score, so we mark it as read.
2516             (when (memq article gnus-newsgroup-unreads)
2517               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2518           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2519             ;; This article was previously marked as read on account
2520             ;; of a low score, but now it has risen, so we mark it as
2521             ;; unread.
2522             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2523         (gnus-summary-update-mark
2524          (if (or (null gnus-summary-default-score)
2525                  (<= (abs (- score gnus-summary-default-score))
2526                      gnus-summary-zcore-fuzz))
2527              ? 
2528            (if (< score gnus-summary-default-score)
2529                gnus-score-below-mark gnus-score-over-mark))
2530          'score))
2531       ;; Do visual highlighting.
2532       (when (gnus-visual-p 'summary-highlight 'highlight)
2533         (gnus-run-hooks 'gnus-summary-update-hook)))))
2534
2535 (defvar gnus-tmp-new-adopts nil)
2536
2537 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2538   "Return the number of articles in THREAD.
2539 This may be 0 in some cases -- if none of the articles in
2540 the thread are to be displayed."
2541   (let* ((number
2542           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2543           (cond
2544            ((not (listp thread))
2545             1)
2546            ((and (consp thread) (cdr thread))
2547             (apply
2548              '+ 1 (mapcar
2549                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2550            ((null thread)
2551             1)
2552            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2553             1)
2554            (t 0))))
2555     (when (and level (zerop level) gnus-tmp-new-adopts)
2556       (incf number
2557             (apply '+ (mapcar
2558                        'gnus-summary-number-of-articles-in-thread
2559                        gnus-tmp-new-adopts))))
2560     (if char
2561         (if (> number 1) gnus-not-empty-thread-mark
2562           gnus-empty-thread-mark)
2563       number)))
2564
2565 (defun gnus-summary-set-local-parameters (group)
2566   "Go through the local params of GROUP and set all variable specs in that list."
2567   (let ((params (gnus-group-find-parameter group))
2568         elem)
2569     (while params
2570       (setq elem (car params)
2571             params (cdr params))
2572       (and (consp elem)                 ; Has to be a cons.
2573            (consp (cdr elem))           ; The cdr has to be a list.
2574            (symbolp (car elem))         ; Has to be a symbol in there.
2575            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2576            (ignore-errors               ; So we set it.
2577              (make-local-variable (car elem))
2578              (set (car elem) (eval (nth 1 elem))))))))
2579
2580 (defun gnus-summary-read-group (group &optional show-all no-article
2581                                       kill-buffer no-display backward
2582                                       select-articles)
2583   "Start reading news in newsgroup GROUP.
2584 If SHOW-ALL is non-nil, already read articles are also listed.
2585 If NO-ARTICLE is non-nil, no article is selected initially.
2586 If NO-DISPLAY, don't generate a summary buffer."
2587   (let (result)
2588     (while (and group
2589                 (null (setq result
2590                             (let ((gnus-auto-select-next nil))
2591                               (or (gnus-summary-read-group-1
2592                                    group show-all no-article
2593                                    kill-buffer no-display
2594                                    select-articles)
2595                                   (setq show-all nil
2596                                         select-articles nil)))))
2597                 (eq gnus-auto-select-next 'quietly))
2598       (set-buffer gnus-group-buffer)
2599       ;; The entry function called above goes to the next
2600       ;; group automatically, so we go two groups back
2601       ;; if we are searching for the previous group.
2602       (when backward
2603         (gnus-group-prev-unread-group 2))
2604       (if (not (equal group (gnus-group-group-name)))
2605           (setq group (gnus-group-group-name))
2606         (setq group nil)))
2607     result))
2608
2609 (defun gnus-summary-read-group-1 (group show-all no-article
2610                                         kill-buffer no-display
2611                                         &optional select-articles)
2612   ;; Killed foreign groups can't be entered.
2613   (when (and (not (gnus-group-native-p group))
2614              (not (gnus-gethash group gnus-newsrc-hashtb)))
2615     (error "Dead non-native groups can't be entered"))
2616   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2617   (let* ((new-group (gnus-summary-setup-buffer group))
2618          (quit-config (gnus-group-quit-config group))
2619          (did-select (and new-group (gnus-select-newsgroup
2620                                      group show-all select-articles))))
2621     (cond
2622      ;; This summary buffer exists already, so we just select it.
2623      ((not new-group)
2624       (gnus-set-global-variables)
2625       (when kill-buffer
2626         (gnus-kill-or-deaden-summary kill-buffer))
2627       (gnus-configure-windows 'summary 'force)
2628       (gnus-set-mode-line 'summary)
2629       (gnus-summary-position-point)
2630       (message "")
2631       t)
2632      ;; We couldn't select this group.
2633      ((null did-select)
2634       (when (and (eq major-mode 'gnus-summary-mode)
2635                  (not (equal (current-buffer) kill-buffer)))
2636         (kill-buffer (current-buffer))
2637         (if (not quit-config)
2638             (progn
2639               ;; Update the info -- marks might need to be removed,
2640               ;; for instance.
2641               (gnus-summary-update-info)
2642               (set-buffer gnus-group-buffer)
2643               (gnus-group-jump-to-group group)
2644               (gnus-group-next-unread-group 1))
2645           (gnus-handle-ephemeral-exit quit-config)))
2646       (gnus-message 3 "Can't select group")
2647       nil)
2648      ;; The user did a `C-g' while prompting for number of articles,
2649      ;; so we exit this group.
2650      ((eq did-select 'quit)
2651       (and (eq major-mode 'gnus-summary-mode)
2652            (not (equal (current-buffer) kill-buffer))
2653            (kill-buffer (current-buffer)))
2654       (when kill-buffer
2655         (gnus-kill-or-deaden-summary kill-buffer))
2656       (if (not quit-config)
2657           (progn
2658             (set-buffer gnus-group-buffer)
2659             (gnus-group-jump-to-group group)
2660             (gnus-group-next-unread-group 1)
2661             (gnus-configure-windows 'group 'force))
2662         (gnus-handle-ephemeral-exit quit-config))
2663       ;; Finally signal the quit.
2664       (signal 'quit nil))
2665      ;; The group was successfully selected.
2666      (t
2667       (gnus-set-global-variables)
2668       ;; Save the active value in effect when the group was entered.
2669       (setq gnus-newsgroup-active
2670             (gnus-copy-sequence
2671              (gnus-active gnus-newsgroup-name)))
2672       ;; You can change the summary buffer in some way with this hook.
2673       (gnus-run-hooks 'gnus-select-group-hook)
2674       ;; Set any local variables in the group parameters.
2675       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2676       (gnus-update-format-specifications
2677        nil 'summary 'summary-mode 'summary-dummy)
2678       ;; Do score processing.
2679       (when gnus-use-scoring
2680         (gnus-possibly-score-headers))
2681       ;; Check whether to fill in the gaps in the threads.
2682       (when gnus-build-sparse-threads
2683         (gnus-build-sparse-threads))
2684       ;; Find the initial limit.
2685       (if gnus-show-threads
2686           (if show-all
2687               (let ((gnus-newsgroup-dormant nil))
2688                 (gnus-summary-initial-limit show-all))
2689             (gnus-summary-initial-limit show-all))
2690         (setq gnus-newsgroup-limit
2691               (mapcar
2692                (lambda (header) (mail-header-number header))
2693                gnus-newsgroup-headers)))
2694       ;; Generate the summary buffer.
2695       (unless no-display
2696         (gnus-summary-prepare))
2697       (when gnus-use-trees
2698         (gnus-tree-open group)
2699         (setq gnus-summary-highlight-line-function
2700               'gnus-tree-highlight-article))
2701       ;; If the summary buffer is empty, but there are some low-scored
2702       ;; articles or some excluded dormants, we include these in the
2703       ;; buffer.
2704       (when (and (zerop (buffer-size))
2705                  (not no-display))
2706         (cond (gnus-newsgroup-dormant
2707                (gnus-summary-limit-include-dormant))
2708               ((and gnus-newsgroup-scored show-all)
2709                (gnus-summary-limit-include-expunged t))))
2710       ;; Function `gnus-apply-kill-file' must be called in this hook.
2711       (gnus-run-hooks 'gnus-apply-kill-hook)
2712       (if (and (zerop (buffer-size))
2713                (not no-display))
2714           (progn
2715             ;; This newsgroup is empty.
2716             (gnus-summary-catchup-and-exit nil t)
2717             (gnus-message 6 "No unread news")
2718             (when kill-buffer
2719               (gnus-kill-or-deaden-summary kill-buffer))
2720             ;; Return nil from this function.
2721             nil)
2722         ;; Hide conversation thread subtrees.  We cannot do this in
2723         ;; gnus-summary-prepare-hook since kill processing may not
2724         ;; work with hidden articles.
2725         (and gnus-show-threads
2726              gnus-thread-hide-subtree
2727              (gnus-summary-hide-all-threads))
2728         (when kill-buffer
2729           (gnus-kill-or-deaden-summary kill-buffer))
2730         ;; Show first unread article if requested.
2731         (if (and (not no-article)
2732                  (not no-display)
2733                  gnus-newsgroup-unreads
2734                  gnus-auto-select-first)
2735             (progn
2736               (gnus-configure-windows 'summary)
2737               (cond
2738                ((eq gnus-auto-select-first 'best)
2739                 (gnus-summary-best-unread-article))
2740                ((eq gnus-auto-select-first t)
2741                 (gnus-summary-first-unread-article))
2742                ((gnus-functionp gnus-auto-select-first)
2743                 (funcall gnus-auto-select-first))))
2744           ;; Don't select any articles, just move point to the first
2745           ;; article in the group.
2746           (goto-char (point-min))
2747           (gnus-summary-position-point)
2748           (gnus-configure-windows 'summary 'force)
2749           (gnus-set-mode-line 'summary))
2750         (when (get-buffer-window gnus-group-buffer t)
2751           ;; Gotta use windows, because recenter does weird stuff if
2752           ;; the current buffer ain't the displayed window.
2753           (let ((owin (selected-window)))
2754             (select-window (get-buffer-window gnus-group-buffer t))
2755             (when (gnus-group-goto-group group)
2756               (recenter))
2757             (select-window owin)))
2758         ;; Mark this buffer as "prepared".
2759         (setq gnus-newsgroup-prepared t)
2760         (gnus-run-hooks 'gnus-summary-prepared-hook)
2761         t)))))
2762
2763 (defun gnus-summary-prepare ()
2764   "Generate the summary buffer."
2765   (interactive)
2766   (let ((buffer-read-only nil))
2767     (erase-buffer)
2768     (setq gnus-newsgroup-data nil
2769           gnus-newsgroup-data-reverse nil)
2770     (gnus-run-hooks 'gnus-summary-generate-hook)
2771     ;; Generate the buffer, either with threads or without.
2772     (when gnus-newsgroup-headers
2773       (gnus-summary-prepare-threads
2774        (if gnus-show-threads
2775            (gnus-sort-gathered-threads
2776             (funcall gnus-summary-thread-gathering-function
2777                      (gnus-sort-threads
2778                       (gnus-cut-threads (gnus-make-threads)))))
2779          ;; Unthreaded display.
2780          (gnus-sort-articles gnus-newsgroup-headers))))
2781     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
2782     ;; Call hooks for modifying summary buffer.
2783     (goto-char (point-min))
2784     (gnus-run-hooks 'gnus-summary-prepare-hook)))
2785
2786 (defsubst gnus-general-simplify-subject (subject)
2787   "Simply subject by the same rules as gnus-gather-threads-by-subject."
2788   (setq subject
2789         (cond
2790          ;; Truncate the subject.
2791          (gnus-simplify-subject-functions
2792           (gnus-map-function gnus-simplify-subject-functions subject))
2793          ((numberp gnus-summary-gather-subject-limit)
2794           (setq subject (gnus-simplify-subject-re subject))
2795           (if (> (length subject) gnus-summary-gather-subject-limit)
2796               (substring subject 0 gnus-summary-gather-subject-limit)
2797             subject))
2798          ;; Fuzzily simplify it.
2799          ((eq 'fuzzy gnus-summary-gather-subject-limit)
2800           (gnus-simplify-subject-fuzzy subject))
2801          ;; Just remove the leading "Re:".
2802          (t
2803           (gnus-simplify-subject-re subject))))
2804
2805   (if (and gnus-summary-gather-exclude-subject
2806            (string-match gnus-summary-gather-exclude-subject subject))
2807       nil                               ; This article shouldn't be gathered
2808     subject))
2809
2810 (defun gnus-summary-simplify-subject-query ()
2811   "Query where the respool algorithm would put this article."
2812   (interactive)
2813   (gnus-summary-select-article)
2814   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
2815
2816 (defun gnus-gather-threads-by-subject (threads)
2817   "Gather threads by looking at Subject headers."
2818   (if (not gnus-summary-make-false-root)
2819       threads
2820     (let ((hashtb (gnus-make-hashtable 1024))
2821           (prev threads)
2822           (result threads)
2823           subject hthread whole-subject)
2824       (while threads
2825         (setq subject (gnus-general-simplify-subject
2826                        (setq whole-subject (mail-header-subject
2827                                             (caar threads)))))
2828         (when subject
2829           (if (setq hthread (gnus-gethash subject hashtb))
2830               (progn
2831                 ;; We enter a dummy root into the thread, if we
2832                 ;; haven't done that already.
2833                 (unless (stringp (caar hthread))
2834                   (setcar hthread (list whole-subject (car hthread))))
2835                 ;; We add this new gathered thread to this gathered
2836                 ;; thread.
2837                 (setcdr (car hthread)
2838                         (nconc (cdar hthread) (list (car threads))))
2839                 ;; Remove it from the list of threads.
2840                 (setcdr prev (cdr threads))
2841                 (setq threads prev))
2842             ;; Enter this thread into the hash table.
2843             (gnus-sethash subject threads hashtb)))
2844         (setq prev threads)
2845         (setq threads (cdr threads)))
2846       result)))
2847
2848 (defun gnus-gather-threads-by-references (threads)
2849   "Gather threads by looking at References headers."
2850   (let ((idhashtb (gnus-make-hashtable 1024))
2851         (thhashtb (gnus-make-hashtable 1024))
2852         (prev threads)
2853         (result threads)
2854         ids references id gthread gid entered ref)
2855     (while threads
2856       (when (setq references (mail-header-references (caar threads)))
2857         (setq id (mail-header-id (caar threads))
2858               ids (gnus-split-references references)
2859               entered nil)
2860         (while (setq ref (pop ids))
2861           (setq ids (delete ref ids))
2862           (if (not (setq gid (gnus-gethash ref idhashtb)))
2863               (progn
2864                 (gnus-sethash ref id idhashtb)
2865                 (gnus-sethash id threads thhashtb))
2866             (setq gthread (gnus-gethash gid thhashtb))
2867             (unless entered
2868               ;; We enter a dummy root into the thread, if we
2869               ;; haven't done that already.
2870               (unless (stringp (caar gthread))
2871                 (setcar gthread (list (mail-header-subject (caar gthread))
2872                                       (car gthread))))
2873               ;; We add this new gathered thread to this gathered
2874               ;; thread.
2875               (setcdr (car gthread)
2876                       (nconc (cdar gthread) (list (car threads)))))
2877             ;; Add it into the thread hash table.
2878             (gnus-sethash id gthread thhashtb)
2879             (setq entered t)
2880             ;; Remove it from the list of threads.
2881             (setcdr prev (cdr threads))
2882             (setq threads prev))))
2883       (setq prev threads)
2884       (setq threads (cdr threads)))
2885     result))
2886
2887 (defun gnus-sort-gathered-threads (threads)
2888   "Sort subtreads inside each gathered thread by article number."
2889   (let ((result threads))
2890     (while threads
2891       (when (stringp (caar threads))
2892         (setcdr (car threads)
2893                 (sort (cdar threads) 'gnus-thread-sort-by-number)))
2894       (setq threads (cdr threads)))
2895     result))
2896
2897 (defun gnus-thread-loop-p (root thread)
2898   "Say whether ROOT is in THREAD."
2899   (let ((stack (list thread))
2900         (infloop 0)
2901         th)
2902     (while (setq thread (pop stack))
2903       (setq th (cdr thread))
2904       (while (and th
2905                   (not (eq (caar th) root)))
2906         (pop th))
2907       (if th
2908           ;; We have found a loop.
2909           (let (ref-dep)
2910             (setcdr thread (delq (car th) (cdr thread)))
2911             (if (boundp (setq ref-dep (intern "none"
2912                                               gnus-newsgroup-dependencies)))
2913                 (setcdr (symbol-value ref-dep)
2914                         (nconc (cdr (symbol-value ref-dep))
2915                                (list (car th))))
2916               (set ref-dep (list nil (car th))))
2917             (setq infloop 1
2918                   stack nil))
2919         ;; Push all the subthreads onto the stack.
2920         (push (cdr thread) stack)))
2921     infloop))
2922
2923 (defun gnus-make-threads ()
2924   "Go through the dependency hashtb and find the roots.  Return all threads."
2925   (let (threads)
2926     (while (catch 'infloop
2927              (mapatoms
2928               (lambda (refs)
2929                 ;; Deal with self-referencing References loops.
2930                 (when (and (car (symbol-value refs))
2931                            (not (zerop
2932                                  (apply
2933                                   '+
2934                                   (mapcar
2935                                    (lambda (thread)
2936                                      (gnus-thread-loop-p
2937                                       (car (symbol-value refs)) thread))
2938                                    (cdr (symbol-value refs)))))))
2939                   (setq threads nil)
2940                   (throw 'infloop t))
2941                 (unless (car (symbol-value refs))
2942                   ;; These threads do not refer back to any other articles,
2943                   ;; so they're roots.
2944                   (setq threads (append (cdr (symbol-value refs)) threads))))
2945               gnus-newsgroup-dependencies)))
2946     threads))
2947
2948 ;; Build the thread tree.
2949 (defsubst gnus-dependencies-add-header (header dependencies force-new)
2950   "Enter HEADER into the DEPENDENCIES table if it is not already there.
2951
2952 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
2953 if it was already present.
2954
2955 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
2956 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
2957 Message-IDs will be renamed be renamed to a unique Message-ID before
2958 being entered.
2959
2960 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
2961   (let* ((id (mail-header-id header))
2962          (id-dep (and id (intern id dependencies)))
2963          ref ref-dep ref-header)
2964     ;; Enter this `header' in the `dependencies' table.
2965     (cond
2966      ((not id-dep)
2967       (setq header nil))
2968      ;; The first two cases do the normal part: enter a new `header'
2969      ;; in the `dependencies' table.
2970      ((not (boundp id-dep))
2971       (set id-dep (list header)))
2972      ((null (car (symbol-value id-dep)))
2973       (setcar (symbol-value id-dep) header))
2974
2975      ;; From here the `header' was already present in the
2976      ;; `dependencies' table.
2977      (force-new
2978       ;; Overrides an existing entry;
2979       ;; just set the header part of the entry.
2980       (setcar (symbol-value id-dep) header))
2981
2982      ;; Renames the existing `header' to a unique Message-ID.
2983      ((not gnus-summary-ignore-duplicates)
2984       ;; An article with this Message-ID has already been seen.
2985       ;; We rename the Message-ID.
2986       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
2987            (list header))
2988       (mail-header-set-id header id))
2989
2990      ;; The last case ignores an existing entry, except it adds any
2991      ;; additional Xrefs (in case the two articles came from different
2992      ;; servers.
2993      ;; Also sets `header' to `nil' meaning that the `dependencies'
2994      ;; table was *not* modified.
2995      (t
2996       (mail-header-set-xref
2997        (car (symbol-value id-dep))
2998        (concat (or (mail-header-xref (car (symbol-value id-dep)))
2999                    "")
3000                (or (mail-header-xref header) "")))
3001       (setq header nil)))
3002
3003     (when header
3004       ;; First check if that we are not creating a References loop.
3005       (setq ref (gnus-parent-id (mail-header-references header)))
3006       (while (and ref
3007                   (setq ref-dep (intern-soft ref dependencies))
3008                   (boundp ref-dep)
3009                   (setq ref-header (car (symbol-value ref-dep))))
3010         (if (string= id ref)
3011             ;; Yuk!  This is a reference loop.  Make the article be a
3012             ;; root article.
3013             (progn
3014               (mail-header-set-references (car (symbol-value id-dep)) "none")
3015               (setq ref nil))
3016           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3017       (setq ref (gnus-parent-id (mail-header-references header)))
3018       (setq ref-dep (intern (or ref "none") dependencies))
3019       (if (boundp ref-dep)
3020           (setcdr (symbol-value ref-dep)
3021                   (nconc (cdr (symbol-value ref-dep))
3022                          (list (symbol-value id-dep))))
3023         (set ref-dep (list nil (symbol-value id-dep)))))
3024     header))
3025
3026 (defun gnus-build-sparse-threads ()
3027   (let ((headers gnus-newsgroup-headers)
3028         (gnus-summary-ignore-duplicates t)
3029         header references generation relations
3030         subject child end new-child date)
3031     ;; First we create an alist of generations/relations, where
3032     ;; generations is how much we trust the relation, and the relation
3033     ;; is parent/child.
3034     (gnus-message 7 "Making sparse threads...")
3035     (save-excursion
3036       (nnheader-set-temp-buffer " *gnus sparse threads*")
3037       (while (setq header (pop headers))
3038         (when (and (setq references (mail-header-references header))
3039                    (not (string= references "")))
3040           (insert references)
3041           (setq child (mail-header-id header)
3042                 subject (mail-header-subject header)
3043                 date (mail-header-date header)
3044                 generation 0)
3045           (while (search-backward ">" nil t)
3046             (setq end (1+ (point)))
3047             (when (search-backward "<" nil t)
3048               (setq new-child (buffer-substring (point) end))
3049               (push (list (incf generation)
3050                           child (setq child new-child)
3051                           subject date)
3052                     relations)))
3053           (when child
3054             (push (list (1+ generation) child nil subject) relations))
3055           (erase-buffer)))
3056       (kill-buffer (current-buffer)))
3057     ;; Sort over trustworthiness.
3058     (mapcar
3059      (lambda (relation)
3060        (when (gnus-dependencies-add-header
3061               (make-full-mail-header
3062                gnus-reffed-article-number
3063                (nth 3 relation) "" (or (nth 4 relation) "")
3064                (nth 1 relation)
3065                (or (nth 2 relation) "") 0 0 "")
3066               gnus-newsgroup-dependencies nil)
3067          (push gnus-reffed-article-number gnus-newsgroup-limit)
3068          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3069          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3070                gnus-newsgroup-reads)
3071          (decf gnus-reffed-article-number)))
3072      (sort relations 'car-less-than-car))
3073     (gnus-message 7 "Making sparse threads...done")))
3074
3075 (defun gnus-build-old-threads ()
3076   ;; Look at all the articles that refer back to old articles, and
3077   ;; fetch the headers for the articles that aren't there.  This will
3078   ;; build complete threads - if the roots haven't been expired by the
3079   ;; server, that is.
3080   (let (id heads)
3081     (mapatoms
3082      (lambda (refs)
3083        (when (not (car (symbol-value refs)))
3084          (setq heads (cdr (symbol-value refs)))
3085          (while heads
3086            (if (memq (mail-header-number (caar heads))
3087                      gnus-newsgroup-dormant)
3088                (setq heads (cdr heads))
3089              (setq id (symbol-name refs))
3090              (while (and (setq id (gnus-build-get-header id))
3091                          (not (car (gnus-id-to-thread id)))))
3092              (setq heads nil)))))
3093      gnus-newsgroup-dependencies)))
3094
3095 (defmacro gnus-nov-read-integer ()
3096   '(prog1
3097        (if (eq (char-after) ?\t)
3098            0
3099          (let ((num (ignore-errors (read buffer))))
3100            (if (numberp num) num 0)))
3101      (unless (eobp)
3102        (search-forward "\t" eol 'move))))
3103
3104 (defmacro gnus-nov-skip-field ()
3105   '(search-forward "\t" eol 'move))
3106
3107 (defmacro gnus-nov-field ()
3108   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
3109
3110 (defmacro gnus-nov-parse-extra ()
3111   '(let (out string)
3112      (while (not (memq (char-after) '(?\n nil)))
3113        (setq string (gnus-nov-field))
3114        (when (string-match "^\\([^ :]+\\): " string)
3115          (push (cons (intern (match-string 1 string))
3116                      (substring string (match-end 0)))
3117                out)))
3118      out))
3119
3120 ;; This function has to be called with point after the article number
3121 ;; on the beginning of the line.
3122 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3123   (let ((eol (gnus-point-at-eol))
3124         (buffer (current-buffer))
3125         header)
3126
3127     ;; overview: [num subject from date id refs chars lines misc]
3128     (unwind-protect
3129         (progn
3130           (narrow-to-region (point) eol)
3131           (unless (eobp)
3132             (forward-char))
3133
3134           (setq header
3135                 (make-full-mail-header
3136                  number                 ; number
3137                  (gnus-nov-field)       ; subject
3138                  (gnus-nov-field)       ; from
3139                  (gnus-nov-field)       ; date
3140                  (or (gnus-nov-field)
3141                      (nnheader-generate-fake-message-id)) ; id
3142                  (gnus-nov-field)       ; refs
3143                  (gnus-nov-read-integer) ; chars
3144                  (gnus-nov-read-integer) ; lines
3145                  (unless (eq (char-after) ?\n)
3146                    (gnus-nov-field))    ; misc
3147                  (gnus-nov-parse-extra)))) ; extra
3148
3149       (widen))
3150
3151     (when gnus-alter-header-function
3152       (funcall gnus-alter-header-function header))
3153     (gnus-dependencies-add-header header dependencies force-new)))
3154
3155 (defun gnus-build-get-header (id)
3156   ;; Look through the buffer of NOV lines and find the header to
3157   ;; ID.  Enter this line into the dependencies hash table, and return
3158   ;; the id of the parent article (if any).
3159   (let ((deps gnus-newsgroup-dependencies)
3160         found header)
3161     (prog1
3162         (save-excursion
3163           (set-buffer nntp-server-buffer)
3164           (let ((case-fold-search nil))
3165             (goto-char (point-min))
3166             (while (and (not found)
3167                         (search-forward id nil t))
3168               (beginning-of-line)
3169               (setq found (looking-at
3170                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3171                                    (regexp-quote id))))
3172               (or found (beginning-of-line 2)))
3173             (when found
3174               (beginning-of-line)
3175               (and
3176                (setq header (gnus-nov-parse-line
3177                              (read (current-buffer)) deps))
3178                (gnus-parent-id (mail-header-references header))))))
3179       (when header
3180         (let ((number (mail-header-number header)))
3181           (push number gnus-newsgroup-limit)
3182           (push header gnus-newsgroup-headers)
3183           (if (memq number gnus-newsgroup-unselected)
3184               (progn
3185                 (push number gnus-newsgroup-unreads)
3186                 (setq gnus-newsgroup-unselected
3187                       (delq number gnus-newsgroup-unselected)))
3188             (push number gnus-newsgroup-ancient)))))))
3189
3190 (defun gnus-build-all-threads ()
3191   "Read all the headers."
3192   (let ((gnus-summary-ignore-duplicates t)
3193         (dependencies gnus-newsgroup-dependencies)
3194         header article)
3195     (save-excursion
3196       (set-buffer nntp-server-buffer)
3197       (let ((case-fold-search nil))
3198         (goto-char (point-min))
3199         (while (not (eobp))
3200           (ignore-errors
3201             (setq article (read (current-buffer))
3202                   header (gnus-nov-parse-line
3203                           article dependencies)))
3204           (when header
3205             (save-excursion
3206               (set-buffer gnus-summary-buffer)
3207               (push header gnus-newsgroup-headers)
3208               (if (memq (setq article (mail-header-number header))
3209                         gnus-newsgroup-unselected)
3210                   (progn
3211                     (push article gnus-newsgroup-unreads)
3212                     (setq gnus-newsgroup-unselected
3213                           (delq article gnus-newsgroup-unselected)))
3214                 (push article gnus-newsgroup-ancient)))
3215             (forward-line 1)))))))
3216
3217 (defun gnus-summary-update-article-line (article header)
3218   "Update the line for ARTICLE using HEADERS."
3219   (let* ((id (mail-header-id header))
3220          (thread (gnus-id-to-thread id)))
3221     (unless thread
3222       (error "Article in no thread"))
3223     ;; Update the thread.
3224     (setcar thread header)
3225     (gnus-summary-goto-subject article)
3226     (let* ((datal (gnus-data-find-list article))
3227            (data (car datal))
3228            (length (when (cdr datal)
3229                      (- (gnus-data-pos data)
3230                         (gnus-data-pos (cadr datal)))))
3231            (buffer-read-only nil)
3232            (level (gnus-summary-thread-level)))
3233       (gnus-delete-line)
3234       (gnus-summary-insert-line
3235        header level nil (gnus-article-mark article)
3236        (memq article gnus-newsgroup-replied)
3237        (memq article gnus-newsgroup-expirable)
3238        ;; Only insert the Subject string when it's different
3239        ;; from the previous Subject string.
3240        (if (gnus-subject-equal
3241             (condition-case ()
3242                 (mail-header-subject
3243                  (gnus-data-header
3244                   (cadr
3245                    (gnus-data-find-list
3246                     article
3247                     (gnus-data-list t)))))
3248               ;; Error on the side of excessive subjects.
3249               (error ""))
3250             (mail-header-subject header))
3251            ""
3252          (mail-header-subject header))
3253        nil (cdr (assq article gnus-newsgroup-scored))
3254        (memq article gnus-newsgroup-processable))
3255       (when length
3256         (gnus-data-update-list
3257          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3258
3259 (defun gnus-summary-update-article (article &optional iheader)
3260   "Update ARTICLE in the summary buffer."
3261   (set-buffer gnus-summary-buffer)
3262   (let* ((header (gnus-summary-article-header article))
3263          (id (mail-header-id header))
3264          (data (gnus-data-find article))
3265          (thread (gnus-id-to-thread id))
3266          (references (mail-header-references header))
3267          (parent
3268           (gnus-id-to-thread
3269            (or (gnus-parent-id
3270                 (when (and references
3271                            (not (equal "" references)))
3272                   references))
3273                "none")))
3274          (buffer-read-only nil)
3275          (old (car thread)))
3276     (when thread
3277       (unless iheader
3278         (setcar thread nil)
3279         (when parent
3280           (delq thread parent)))
3281       (if (gnus-summary-insert-subject id header)
3282           ;; Set the (possibly) new article number in the data structure.
3283           (gnus-data-set-number data (gnus-id-to-article id))
3284         (setcar thread old)
3285         nil))))
3286
3287 (defun gnus-rebuild-thread (id &optional line)
3288   "Rebuild the thread containing ID.
3289 If LINE, insert the rebuilt thread starting on line LINE."
3290   (let ((buffer-read-only nil)
3291         old-pos current thread data)
3292     (if (not gnus-show-threads)
3293         (setq thread (list (car (gnus-id-to-thread id))))
3294       ;; Get the thread this article is part of.
3295       (setq thread (gnus-remove-thread id)))
3296     (setq old-pos (gnus-point-at-bol))
3297     (setq current (save-excursion
3298                     (and (zerop (forward-line -1))
3299                          (gnus-summary-article-number))))
3300     ;; If this is a gathered thread, we have to go some re-gathering.
3301     (when (stringp (car thread))
3302       (let ((subject (car thread))
3303             roots thr)
3304         (setq thread (cdr thread))
3305         (while thread
3306           (unless (memq (setq thr (gnus-id-to-thread
3307                                    (gnus-root-id
3308                                     (mail-header-id (caar thread)))))
3309                         roots)
3310             (push thr roots))
3311           (setq thread (cdr thread)))
3312         ;; We now have all (unique) roots.
3313         (if (= (length roots) 1)
3314             ;; All the loose roots are now one solid root.
3315             (setq thread (car roots))
3316           (setq thread (cons subject (gnus-sort-threads roots))))))
3317     (let (threads)
3318       ;; We then insert this thread into the summary buffer.
3319       (when line
3320         (goto-char (point-min))
3321         (forward-line (1- line)))
3322       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3323         (if gnus-show-threads
3324             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3325           (gnus-summary-prepare-unthreaded thread))
3326         (setq data (nreverse gnus-newsgroup-data))
3327         (setq threads gnus-newsgroup-threads))
3328       ;; We splice the new data into the data structure.
3329       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3330       ;;!!! then we want to insert at the beginning of the buffer.
3331       ;;!!! That happens to be true with Gnus now, but that may
3332       ;;!!! change in the future.  Perhaps.
3333       (gnus-data-enter-list
3334        (if line nil current) data (- (point) old-pos))
3335       (setq gnus-newsgroup-threads
3336             (nconc threads gnus-newsgroup-threads))
3337       (gnus-data-compute-positions))))
3338
3339 (defun gnus-number-to-header (number)
3340   "Return the header for article NUMBER."
3341   (let ((headers gnus-newsgroup-headers))
3342     (while (and headers
3343                 (not (= number (mail-header-number (car headers)))))
3344       (pop headers))
3345     (when headers
3346       (car headers))))
3347
3348 (defun gnus-parent-headers (in-headers &optional generation)
3349   "Return the headers of the GENERATIONeth parent of HEADERS."
3350   (unless generation
3351     (setq generation 1))
3352   (let ((parent t)
3353         (headers in-headers)
3354         references)
3355     (while (and parent
3356                 (not (zerop generation))
3357                 (setq references (mail-header-references headers)))
3358       (setq headers (if (and references
3359                              (setq parent (gnus-parent-id references)))
3360                         (car (gnus-id-to-thread parent))
3361                       nil))
3362       (decf generation))
3363     (and (not (eq headers in-headers))
3364          headers)))
3365
3366 (defun gnus-id-to-thread (id)
3367   "Return the (sub-)thread where ID appears."
3368   (gnus-gethash id gnus-newsgroup-dependencies))
3369
3370 (defun gnus-id-to-article (id)
3371   "Return the article number of ID."
3372   (let ((thread (gnus-id-to-thread id)))
3373     (when (and thread
3374                (car thread))
3375       (mail-header-number (car thread)))))
3376
3377 (defun gnus-id-to-header (id)
3378   "Return the article headers of ID."
3379   (car (gnus-id-to-thread id)))
3380
3381 (defun gnus-article-displayed-root-p (article)
3382   "Say whether ARTICLE is a root(ish) article."
3383   (let ((level (gnus-summary-thread-level article))
3384         (refs (mail-header-references  (gnus-summary-article-header article)))
3385         particle)
3386     (cond
3387      ((null level) nil)
3388      ((zerop level) t)
3389      ((null refs) t)
3390      ((null (gnus-parent-id refs)) t)
3391      ((and (= 1 level)
3392            (null (setq particle (gnus-id-to-article
3393                                  (gnus-parent-id refs))))
3394            (null (gnus-summary-thread-level particle)))))))
3395
3396 (defun gnus-root-id (id)
3397   "Return the id of the root of the thread where ID appears."
3398   (let (last-id prev)
3399     (while (and id (setq prev (car (gnus-id-to-thread id))))
3400       (setq last-id id
3401             id (gnus-parent-id (mail-header-references prev))))
3402     last-id))
3403
3404 (defun gnus-articles-in-thread (thread)
3405   "Return the list of articles in THREAD."
3406   (cons (mail-header-number (car thread))
3407         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3408
3409 (defun gnus-remove-thread (id &optional dont-remove)
3410   "Remove the thread that has ID in it."
3411   (let (headers thread last-id)
3412     ;; First go up in this thread until we find the root.
3413     (setq last-id (gnus-root-id id)
3414           headers (message-flatten-list (gnus-id-to-thread last-id)))
3415     ;; We have now found the real root of this thread.  It might have
3416     ;; been gathered into some loose thread, so we have to search
3417     ;; through the threads to find the thread we wanted.
3418     (let ((threads gnus-newsgroup-threads)
3419           sub)
3420       (while threads
3421         (setq sub (car threads))
3422         (if (stringp (car sub))
3423             ;; This is a gathered thread, so we look at the roots
3424             ;; below it to find whether this article is in this
3425             ;; gathered root.
3426             (progn
3427               (setq sub (cdr sub))
3428               (while sub
3429                 (when (member (caar sub) headers)
3430                   (setq thread (car threads)
3431                         threads nil
3432                         sub nil))
3433                 (setq sub (cdr sub))))
3434           ;; It's an ordinary thread, so we check it.
3435           (when (eq (car sub) (car headers))
3436             (setq thread sub
3437                   threads nil)))
3438         (setq threads (cdr threads)))
3439       ;; If this article is in no thread, then it's a root.
3440       (if thread
3441           (unless dont-remove
3442             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3443         (setq thread (gnus-id-to-thread last-id)))
3444       (when thread
3445         (prog1
3446             thread                      ; We return this thread.
3447           (unless dont-remove
3448             (if (stringp (car thread))
3449                 (progn
3450                   ;; If we use dummy roots, then we have to remove the
3451                   ;; dummy root as well.
3452                   (when (eq gnus-summary-make-false-root 'dummy)
3453                     ;; We go to the dummy root by going to
3454                     ;; the first sub-"thread", and then one line up.
3455                     (gnus-summary-goto-article
3456                      (mail-header-number (caadr thread)))
3457                     (forward-line -1)
3458                     (gnus-delete-line)
3459                     (gnus-data-compute-positions))
3460                   (setq thread (cdr thread))
3461                   (while thread
3462                     (gnus-remove-thread-1 (car thread))
3463                     (setq thread (cdr thread))))
3464               (gnus-summary-show-all-threads)
3465               (gnus-remove-thread-1 thread))))))))
3466
3467 (defun gnus-remove-thread-1 (thread)
3468   "Remove the thread THREAD recursively."
3469   (let ((number (mail-header-number (pop thread)))
3470         d)
3471     (setq thread (reverse thread))
3472     (while thread
3473       (gnus-remove-thread-1 (pop thread)))
3474     (when (setq d (gnus-data-find number))
3475       (goto-char (gnus-data-pos d))
3476       (gnus-data-remove
3477        number
3478        (- (gnus-point-at-bol)
3479           (prog1
3480               (1+ (gnus-point-at-eol))
3481             (gnus-delete-line)))))))
3482
3483 (defun gnus-sort-threads (threads)
3484   "Sort THREADS."
3485   (if (not gnus-thread-sort-functions)
3486       threads
3487     (gnus-message 8 "Sorting threads...")
3488     (prog1
3489         (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
3490       (gnus-message 8 "Sorting threads...done"))))
3491
3492 (defun gnus-sort-articles (articles)
3493   "Sort ARTICLES."
3494   (when gnus-article-sort-functions
3495     (gnus-message 7 "Sorting articles...")
3496     (prog1
3497         (setq gnus-newsgroup-headers
3498               (sort articles (gnus-make-sort-function
3499                               gnus-article-sort-functions)))
3500       (gnus-message 7 "Sorting articles...done"))))
3501
3502 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3503 (defmacro gnus-thread-header (thread)
3504   ;; Return header of first article in THREAD.
3505   ;; Note that THREAD must never, ever be anything else than a variable -
3506   ;; using some other form will lead to serious barfage.
3507   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3508   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3509   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
3510         (vector thread) 2))
3511
3512 (defsubst gnus-article-sort-by-number (h1 h2)
3513   "Sort articles by article number."
3514   (< (mail-header-number h1)
3515      (mail-header-number h2)))
3516
3517 (defun gnus-thread-sort-by-number (h1 h2)
3518   "Sort threads by root article number."
3519   (gnus-article-sort-by-number
3520    (gnus-thread-header h1) (gnus-thread-header h2)))
3521
3522 (defsubst gnus-article-sort-by-lines (h1 h2)
3523   "Sort articles by article Lines header."
3524   (< (mail-header-lines h1)
3525      (mail-header-lines h2)))
3526
3527 (defun gnus-thread-sort-by-lines (h1 h2)
3528   "Sort threads by root article Lines header."
3529   (gnus-article-sort-by-lines
3530    (gnus-thread-header h1) (gnus-thread-header h2)))
3531
3532 (defsubst gnus-article-sort-by-author (h1 h2)
3533   "Sort articles by root author."
3534   (string-lessp
3535    (let ((addr (mime-read-field 'From h1)))
3536      (or (std11-full-name-string addr)
3537          (std11-address-string addr)
3538          ""))
3539    (let ((addr (mime-read-field 'From h2)))
3540      (or (std11-full-name-string addr)
3541          (std11-address-string addr)
3542          ""))
3543    ))
3544
3545 (defun gnus-thread-sort-by-author (h1 h2)
3546   "Sort threads by root author."
3547   (gnus-article-sort-by-author
3548    (gnus-thread-header h1)  (gnus-thread-header h2)))
3549
3550 (defsubst gnus-article-sort-by-subject (h1 h2)
3551   "Sort articles by root subject."
3552   (string-lessp
3553    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3554    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3555
3556 (defun gnus-thread-sort-by-subject (h1 h2)
3557   "Sort threads by root subject."
3558   (gnus-article-sort-by-subject
3559    (gnus-thread-header h1) (gnus-thread-header h2)))
3560
3561 (defsubst gnus-article-sort-by-date (h1 h2)
3562   "Sort articles by root article date."
3563   (time-less-p
3564    (gnus-date-get-time (mail-header-date h1))
3565    (gnus-date-get-time (mail-header-date h2))))
3566
3567 (defun gnus-thread-sort-by-date (h1 h2)
3568   "Sort threads by root article date."
3569   (gnus-article-sort-by-date
3570    (gnus-thread-header h1) (gnus-thread-header h2)))
3571
3572 (defsubst gnus-article-sort-by-score (h1 h2)
3573   "Sort articles by root article score.
3574 Unscored articles will be counted as having a score of zero."
3575   (> (or (cdr (assq (mail-header-number h1)
3576                     gnus-newsgroup-scored))
3577          gnus-summary-default-score 0)
3578      (or (cdr (assq (mail-header-number h2)
3579                     gnus-newsgroup-scored))
3580          gnus-summary-default-score 0)))
3581
3582 (defun gnus-thread-sort-by-score (h1 h2)
3583   "Sort threads by root article score."
3584   (gnus-article-sort-by-score
3585    (gnus-thread-header h1) (gnus-thread-header h2)))
3586
3587 (defun gnus-thread-sort-by-total-score (h1 h2)
3588   "Sort threads by the sum of all scores in the thread.
3589 Unscored articles will be counted as having a score of zero."
3590   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3591
3592 (defun gnus-thread-total-score (thread)
3593   ;;  This function find the total score of THREAD.
3594   (cond ((null thread)
3595          0)
3596         ((consp thread)
3597          (if (stringp (car thread))
3598              (apply gnus-thread-score-function 0
3599                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3600            (gnus-thread-total-score-1 thread)))
3601         (t
3602          (gnus-thread-total-score-1 (list thread)))))
3603
3604 (defun gnus-thread-total-score-1 (root)
3605   ;; This function find the total score of the thread below ROOT.
3606   (setq root (car root))
3607   (apply gnus-thread-score-function
3608          (or (append
3609               (mapcar 'gnus-thread-total-score
3610                       (cdr (gnus-id-to-thread (mail-header-id root))))
3611               (when (> (mail-header-number root) 0)
3612                 (list (or (cdr (assq (mail-header-number root)
3613                                      gnus-newsgroup-scored))
3614                           gnus-summary-default-score 0))))
3615              (list gnus-summary-default-score)
3616              '(0))))
3617
3618 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3619 (defvar gnus-tmp-prev-subject nil)
3620 (defvar gnus-tmp-false-parent nil)
3621 (defvar gnus-tmp-root-expunged nil)
3622 (defvar gnus-tmp-dummy-line nil)
3623
3624 (defvar gnus-tmp-header)
3625 (defun gnus-extra-header (type &optional header)
3626   "Return the extra header of TYPE."
3627   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3628       ""))
3629
3630 (defun gnus-summary-prepare-threads (threads)
3631   "Prepare summary buffer from THREADS and indentation LEVEL.
3632 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3633 or a straight list of headers."
3634   (gnus-message 7 "Generating summary...")
3635
3636   (setq gnus-newsgroup-threads threads)
3637   (beginning-of-line)
3638
3639   (let ((gnus-tmp-level 0)
3640         (default-score (or gnus-summary-default-score 0))
3641         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3642         thread number subject stack state gnus-tmp-gathered beg-match
3643         new-roots gnus-tmp-new-adopts thread-end
3644         gnus-tmp-header gnus-tmp-unread
3645         gnus-tmp-replied gnus-tmp-subject-or-nil
3646         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3647         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3648         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3649
3650     (setq gnus-tmp-prev-subject nil)
3651
3652     (if (vectorp (car threads))
3653         ;; If this is a straight (sic) list of headers, then a
3654         ;; threaded summary display isn't required, so we just create
3655         ;; an unthreaded one.
3656         (gnus-summary-prepare-unthreaded threads)
3657
3658       ;; Do the threaded display.
3659
3660       (while (or threads stack gnus-tmp-new-adopts new-roots)
3661
3662         (if (and (= gnus-tmp-level 0)
3663                  (or (not stack)
3664                      (= (caar stack) 0))
3665                  (not gnus-tmp-false-parent)
3666                  (or gnus-tmp-new-adopts new-roots))
3667             (if gnus-tmp-new-adopts
3668                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3669                       thread (list (car gnus-tmp-new-adopts))
3670                       gnus-tmp-header (caar thread)
3671                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3672               (when new-roots
3673                 (setq thread (list (car new-roots))
3674                       gnus-tmp-header (caar thread)
3675                       new-roots (cdr new-roots))))
3676
3677           (if threads
3678               ;; If there are some threads, we do them before the
3679               ;; threads on the stack.
3680               (setq thread threads
3681                     gnus-tmp-header (caar thread))
3682             ;; There were no current threads, so we pop something off
3683             ;; the stack.
3684             (setq state (car stack)
3685                   gnus-tmp-level (car state)
3686                   thread (cdr state)
3687                   stack (cdr stack)
3688                   gnus-tmp-header (caar thread))))
3689
3690         (setq gnus-tmp-false-parent nil)
3691         (setq gnus-tmp-root-expunged nil)
3692         (setq thread-end nil)
3693
3694         (if (stringp gnus-tmp-header)
3695             ;; The header is a dummy root.
3696             (cond
3697              ((eq gnus-summary-make-false-root 'adopt)
3698               ;; We let the first article adopt the rest.
3699               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3700                                                (cddar thread)))
3701               (setq gnus-tmp-gathered
3702                     (nconc (mapcar
3703                             (lambda (h) (mail-header-number (car h)))
3704                             (cddar thread))
3705                            gnus-tmp-gathered))
3706               (setq thread (cons (list (caar thread)
3707                                        (cadar thread))
3708                                  (cdr thread)))
3709               (setq gnus-tmp-level -1
3710                     gnus-tmp-false-parent t))
3711              ((eq gnus-summary-make-false-root 'empty)
3712               ;; We print adopted articles with empty subject fields.
3713               (setq gnus-tmp-gathered
3714                     (nconc (mapcar
3715                             (lambda (h) (mail-header-number (car h)))
3716                             (cddar thread))
3717                            gnus-tmp-gathered))
3718               (setq gnus-tmp-level -1))
3719              ((eq gnus-summary-make-false-root 'dummy)
3720               ;; We remember that we probably want to output a dummy
3721               ;; root.
3722               (setq gnus-tmp-dummy-line gnus-tmp-header)
3723               (setq gnus-tmp-prev-subject gnus-tmp-header))
3724              (t
3725               ;; We do not make a root for the gathered
3726               ;; sub-threads at all.
3727               (setq gnus-tmp-level -1)))
3728
3729           (setq number (mail-header-number gnus-tmp-header)
3730                 subject (mail-header-subject gnus-tmp-header))
3731
3732           (cond
3733            ;; If the thread has changed subject, we might want to make
3734            ;; this subthread into a root.
3735            ((and (null gnus-thread-ignore-subject)
3736                  (not (zerop gnus-tmp-level))
3737                  gnus-tmp-prev-subject
3738                  (not (inline
3739                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
3740             (setq new-roots (nconc new-roots (list (car thread)))
3741                   thread-end t
3742                   gnus-tmp-header nil))
3743            ;; If the article lies outside the current limit,
3744            ;; then we do not display it.
3745            ((not (memq number gnus-newsgroup-limit))
3746             (setq gnus-tmp-gathered
3747                   (nconc (mapcar
3748                           (lambda (h) (mail-header-number (car h)))
3749                           (cdar thread))
3750                          gnus-tmp-gathered))
3751             (setq gnus-tmp-new-adopts (if (cdar thread)
3752                                           (append gnus-tmp-new-adopts
3753                                                   (cdar thread))
3754                                         gnus-tmp-new-adopts)
3755                   thread-end t
3756                   gnus-tmp-header nil)
3757             (when (zerop gnus-tmp-level)
3758               (setq gnus-tmp-root-expunged t)))
3759            ;; Perhaps this article is to be marked as read?
3760            ((and gnus-summary-mark-below
3761                  (< (or (cdr (assq number gnus-newsgroup-scored))
3762                         default-score)
3763                     gnus-summary-mark-below)
3764                  ;; Don't touch sparse articles.
3765                  (not (gnus-summary-article-sparse-p number))
3766                  (not (gnus-summary-article-ancient-p number)))
3767             (setq gnus-newsgroup-unreads
3768                   (delq number gnus-newsgroup-unreads))
3769             (if gnus-newsgroup-auto-expire
3770                 (push number gnus-newsgroup-expirable)
3771               (push (cons number gnus-low-score-mark)
3772                     gnus-newsgroup-reads))))
3773
3774           (when gnus-tmp-header
3775             ;; We may have an old dummy line to output before this
3776             ;; article.
3777             (when (and gnus-tmp-dummy-line
3778                        (gnus-subject-equal
3779                         gnus-tmp-dummy-line
3780                         (mail-header-subject gnus-tmp-header)))
3781               (gnus-summary-insert-dummy-line
3782                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
3783               (setq gnus-tmp-dummy-line nil))
3784
3785             ;; Compute the mark.
3786             (setq gnus-tmp-unread (gnus-article-mark number))
3787
3788             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
3789                                   gnus-tmp-header gnus-tmp-level)
3790                   gnus-newsgroup-data)
3791
3792             ;; Actually insert the line.
3793             (setq
3794              gnus-tmp-subject-or-nil
3795              (cond
3796               ((and gnus-thread-ignore-subject
3797                     gnus-tmp-prev-subject
3798                     (not (inline (gnus-subject-equal
3799                                   gnus-tmp-prev-subject subject))))
3800                subject)
3801               ((zerop gnus-tmp-level)
3802                (if (and (eq gnus-summary-make-false-root 'empty)
3803                         (memq number gnus-tmp-gathered)
3804                         gnus-tmp-prev-subject
3805                         (inline (gnus-subject-equal
3806                                  gnus-tmp-prev-subject subject)))
3807                    gnus-summary-same-subject
3808                  subject))
3809               (t gnus-summary-same-subject)))
3810             (if (and (eq gnus-summary-make-false-root 'adopt)
3811                      (= gnus-tmp-level 1)
3812                      (memq number gnus-tmp-gathered))
3813                 (setq gnus-tmp-opening-bracket ?\<
3814                       gnus-tmp-closing-bracket ?\>)
3815               (setq gnus-tmp-opening-bracket ?\[
3816                     gnus-tmp-closing-bracket ?\]))
3817             (setq
3818              gnus-tmp-indentation
3819              (aref gnus-thread-indent-array gnus-tmp-level)
3820              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
3821              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
3822                                 gnus-summary-default-score 0)
3823              gnus-tmp-score-char
3824              (if (or (null gnus-summary-default-score)
3825                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3826                          gnus-summary-zcore-fuzz))
3827                  ? 
3828                (if (< gnus-tmp-score gnus-summary-default-score)
3829                    gnus-score-below-mark gnus-score-over-mark))
3830              gnus-tmp-replied
3831              (cond ((memq number gnus-newsgroup-processable)
3832                     gnus-process-mark)
3833                    ((memq number gnus-newsgroup-cached)
3834                     gnus-cached-mark)
3835                    ((memq number gnus-newsgroup-replied)
3836                     gnus-replied-mark)
3837                    ((memq number gnus-newsgroup-saved)
3838                     gnus-saved-mark)
3839                    (t gnus-unread-mark))
3840              gnus-tmp-from (mail-header-from gnus-tmp-header)
3841              gnus-tmp-name
3842              (cond
3843               ((string-match "<[^>]+> *$" gnus-tmp-from)
3844                (setq beg-match (match-beginning 0))
3845                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
3846                         (substring gnus-tmp-from (1+ (match-beginning 0))
3847                                    (1- (match-end 0))))
3848                    (substring gnus-tmp-from 0 beg-match)))
3849               ((string-match "(.+)" gnus-tmp-from)
3850                (substring gnus-tmp-from
3851                           (1+ (match-beginning 0)) (1- (match-end 0))))
3852               (t gnus-tmp-from)))
3853             (when (string= gnus-tmp-name "")
3854               (setq gnus-tmp-name gnus-tmp-from))
3855             (unless (numberp gnus-tmp-lines)
3856               (setq gnus-tmp-lines 0))
3857             (gnus-put-text-property
3858              (point)
3859              (progn (eval gnus-summary-line-format-spec) (point))
3860              'gnus-number number)
3861             (when gnus-visual-p
3862               (forward-line -1)
3863               (gnus-run-hooks 'gnus-summary-update-hook)
3864               (forward-line 1))
3865
3866             (setq gnus-tmp-prev-subject subject)))
3867
3868         (when (nth 1 thread)
3869           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
3870         (incf gnus-tmp-level)
3871         (setq threads (if thread-end nil (cdar thread)))
3872         (unless threads
3873           (setq gnus-tmp-level 0)))))
3874   (gnus-message 7 "Generating summary...done"))
3875
3876 (defun gnus-summary-prepare-unthreaded (headers)
3877   "Generate an unthreaded summary buffer based on HEADERS."
3878   (let (header number mark)
3879
3880     (beginning-of-line)
3881
3882     (while headers
3883       ;; We may have to root out some bad articles...
3884       (when (memq (setq number (mail-header-number
3885                                 (setq header (pop headers))))
3886                   gnus-newsgroup-limit)
3887         ;; Mark article as read when it has a low score.
3888         (when (and gnus-summary-mark-below
3889                    (< (or (cdr (assq number gnus-newsgroup-scored))
3890                           gnus-summary-default-score 0)
3891                       gnus-summary-mark-below)
3892                    (not (gnus-summary-article-ancient-p number)))
3893           (setq gnus-newsgroup-unreads
3894                 (delq number gnus-newsgroup-unreads))
3895           (if gnus-newsgroup-auto-expire
3896               (push number gnus-newsgroup-expirable)
3897             (push (cons number gnus-low-score-mark)
3898                   gnus-newsgroup-reads)))
3899
3900         (setq mark (gnus-article-mark number))
3901         (push (gnus-data-make number mark (1+ (point)) header 0)
3902               gnus-newsgroup-data)
3903         (gnus-summary-insert-line
3904          header 0 number
3905          mark (memq number gnus-newsgroup-replied)
3906          (memq number gnus-newsgroup-expirable)
3907          (mail-header-subject header) nil
3908          (cdr (assq number gnus-newsgroup-scored))
3909          (memq number gnus-newsgroup-processable))))))
3910
3911 (defun gnus-select-newsgroup (group &optional read-all select-articles)
3912   "Select newsgroup GROUP.
3913 If READ-ALL is non-nil, all articles in the group are selected.
3914 If SELECT-ARTICLES, only select those articles from GROUP."
3915   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
3916          ;;!!! Dirty hack; should be removed.
3917          (gnus-summary-ignore-duplicates
3918           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
3919               t
3920             gnus-summary-ignore-duplicates))
3921          (info (nth 2 entry))
3922          articles fetched-articles cached)
3923
3924     (unless (gnus-check-server
3925              (setq gnus-current-select-method
3926                    (gnus-find-method-for-group group)))
3927       (error "Couldn't open server"))
3928
3929     (or (and entry (not (eq (car entry) t))) ; Either it's active...
3930         (gnus-activate-group group)     ; Or we can activate it...
3931         (progn                          ; Or we bug out.
3932           (when (equal major-mode 'gnus-summary-mode)
3933             (kill-buffer (current-buffer)))
3934           (error "Couldn't request group %s: %s"
3935                  group (gnus-status-message group))))
3936
3937     (unless (gnus-request-group group t)
3938       (when (equal major-mode 'gnus-summary-mode)
3939         (kill-buffer (current-buffer)))
3940       (error "Couldn't request group %s: %s"
3941              group (gnus-status-message group)))
3942
3943     (setq gnus-newsgroup-name group)
3944     (setq gnus-newsgroup-unselected nil)
3945     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
3946
3947     ;; Adjust and set lists of article marks.
3948     (when info
3949       (gnus-adjust-marked-articles info))
3950
3951     ;; Kludge to avoid having cached articles nixed out in virtual groups.
3952     (when (gnus-virtual-group-p group)
3953       (setq cached gnus-newsgroup-cached))
3954
3955     (setq gnus-newsgroup-unreads
3956           (gnus-set-difference
3957            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
3958            gnus-newsgroup-dormant))
3959
3960     (setq gnus-newsgroup-processable nil)
3961
3962     (gnus-update-read-articles group gnus-newsgroup-unreads)
3963
3964     (if (setq articles select-articles)
3965         (setq gnus-newsgroup-unselected
3966               (gnus-sorted-intersection
3967                gnus-newsgroup-unreads
3968                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
3969       (setq articles (gnus-articles-to-read group read-all)))
3970
3971     (cond
3972      ((null articles)
3973       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
3974       'quit)
3975      ((eq articles 0) nil)
3976      (t
3977       ;; Init the dependencies hash table.
3978       (setq gnus-newsgroup-dependencies
3979             (gnus-make-hashtable (length articles)))
3980       (gnus-set-global-variables)
3981       ;; Retrieve the headers and read them in.
3982       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
3983       (setq gnus-newsgroup-headers
3984             (if (eq 'nov
3985                     (setq gnus-headers-retrieved-by
3986                           (gnus-retrieve-headers
3987                            articles gnus-newsgroup-name
3988                            ;; We might want to fetch old headers, but
3989                            ;; not if there is only 1 article.
3990                            (and (or (and
3991                                      (not (eq gnus-fetch-old-headers 'some))
3992                                      (not (numberp gnus-fetch-old-headers)))
3993                                     (> (length articles) 1))
3994                                 gnus-fetch-old-headers))))
3995                 (gnus-get-newsgroup-headers-xover
3996                  articles nil nil gnus-newsgroup-name t)
3997               (gnus-get-newsgroup-headers)))
3998       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
3999
4000       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4001       (when cached
4002         (setq gnus-newsgroup-cached cached))
4003
4004       ;; Suppress duplicates?
4005       (when gnus-suppress-duplicates
4006         (gnus-dup-suppress-articles))
4007
4008       ;; Set the initial limit.
4009       (setq gnus-newsgroup-limit (copy-sequence articles))
4010       ;; Remove canceled articles from the list of unread articles.
4011       (setq gnus-newsgroup-unreads
4012             (gnus-set-sorted-intersection
4013              gnus-newsgroup-unreads
4014              (setq fetched-articles
4015                    (mapcar (lambda (headers) (mail-header-number headers))
4016                            gnus-newsgroup-headers))))
4017       ;; Removed marked articles that do not exist.
4018       (gnus-update-missing-marks
4019        (gnus-sorted-complement fetched-articles articles))
4020       ;; We might want to build some more threads first.
4021       (when (and gnus-fetch-old-headers
4022                  (eq gnus-headers-retrieved-by 'nov))
4023         (if (eq gnus-fetch-old-headers 'invisible)
4024             (gnus-build-all-threads)
4025           (gnus-build-old-threads)))
4026       ;; Let the Gnus agent mark articles as read.
4027       (when gnus-agent
4028         (gnus-agent-get-undownloaded-list))
4029       ;; Check whether auto-expire is to be done in this group.
4030       (setq gnus-newsgroup-auto-expire
4031             (gnus-group-auto-expirable-p group))
4032       ;; Set up the article buffer now, if necessary.
4033       (unless gnus-single-article-buffer
4034         (gnus-article-setup-buffer))
4035       ;; First and last article in this newsgroup.
4036       (when gnus-newsgroup-headers
4037         (setq gnus-newsgroup-begin
4038               (mail-header-number (car gnus-newsgroup-headers))
4039               gnus-newsgroup-end
4040               (mail-header-number
4041                (gnus-last-element gnus-newsgroup-headers))))
4042       ;; GROUP is successfully selected.
4043       (or gnus-newsgroup-headers t)))))
4044
4045 (defun gnus-articles-to-read (group &optional read-all)
4046   ;; Find out what articles the user wants to read.
4047   (let* ((articles
4048           ;; Select all articles if `read-all' is non-nil, or if there
4049           ;; are no unread articles.
4050           (if (or read-all
4051                   (and (zerop (length gnus-newsgroup-marked))
4052                        (zerop (length gnus-newsgroup-unreads)))
4053                   (eq (gnus-group-find-parameter group 'display)
4054                       'all))
4055               (gnus-uncompress-range (gnus-active group))
4056             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4057                           (copy-sequence gnus-newsgroup-unreads))
4058                   '<)))
4059          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4060          (scored (length scored-list))
4061          (number (length articles))
4062          (marked (+ (length gnus-newsgroup-marked)
4063                     (length gnus-newsgroup-dormant)))
4064          (select
4065           (cond
4066            ((numberp read-all)
4067             read-all)
4068            (t
4069             (condition-case ()
4070                 (cond
4071                  ((and (or (<= scored marked) (= scored number))
4072                        (numberp gnus-large-newsgroup)
4073                        (> number gnus-large-newsgroup))
4074                   (let ((input
4075                          (read-string
4076                           (format
4077                            "How many articles from %s (default %d): "
4078                            (gnus-limit-string gnus-newsgroup-name 35)
4079                            number))))
4080                     (if (string-match "^[ \t]*$" input) number input)))
4081                  ((and (> scored marked) (< scored number)
4082                        (> (- scored number) 20))
4083                   (let ((input
4084                          (read-string
4085                           (format "%s %s (%d scored, %d total): "
4086                                   "How many articles from"
4087                                   group scored number))))
4088                     (if (string-match "^[ \t]*$" input)
4089                         number input)))
4090                  (t number))
4091               (quit nil))))))
4092     (setq select (if (stringp select) (string-to-number select) select))
4093     (if (or (null select) (zerop select))
4094         select
4095       (if (and (not (zerop scored)) (<= (abs select) scored))
4096           (progn
4097             (setq articles (sort scored-list '<))
4098             (setq number (length articles)))
4099         (setq articles (copy-sequence articles)))
4100
4101       (when (< (abs select) number)
4102         (if (< select 0)
4103             ;; Select the N oldest articles.
4104             (setcdr (nthcdr (1- (abs select)) articles) nil)
4105           ;; Select the N most recent articles.
4106           (setq articles (nthcdr (- number select) articles))))
4107       (setq gnus-newsgroup-unselected
4108             (gnus-sorted-intersection
4109              gnus-newsgroup-unreads
4110              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4111       articles)))
4112
4113 (defun gnus-killed-articles (killed articles)
4114   (let (out)
4115     (while articles
4116       (when (inline (gnus-member-of-range (car articles) killed))
4117         (push (car articles) out))
4118       (setq articles (cdr articles)))
4119     out))
4120
4121 (defun gnus-uncompress-marks (marks)
4122   "Uncompress the mark ranges in MARKS."
4123   (let ((uncompressed '(score bookmark))
4124         out)
4125     (while marks
4126       (if (memq (caar marks) uncompressed)
4127           (push (car marks) out)
4128         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4129       (setq marks (cdr marks)))
4130     out))
4131
4132 (defun gnus-adjust-marked-articles (info)
4133   "Set all article lists and remove all marks that are no longer legal."
4134   (let* ((marked-lists (gnus-info-marks info))
4135          (active (gnus-active (gnus-info-group info)))
4136          (min (car active))
4137          (max (cdr active))
4138          (types gnus-article-mark-lists)
4139          (uncompressed '(score bookmark killed))
4140          marks var articles article mark)
4141
4142     (while marked-lists
4143       (setq marks (pop marked-lists))
4144       (set (setq var (intern (format "gnus-newsgroup-%s"
4145                                      (car (rassq (setq mark (car marks))
4146                                                  types)))))
4147            (if (memq (car marks) uncompressed) (cdr marks)
4148              (gnus-uncompress-range (cdr marks))))
4149
4150       (setq articles (symbol-value var))
4151
4152       ;; All articles have to be subsets of the active articles.
4153       (cond
4154        ;; Adjust "simple" lists.
4155        ((memq mark '(tick dormant expire reply save))
4156         (while articles
4157           (when (or (< (setq article (pop articles)) min) (> article max))
4158             (set var (delq article (symbol-value var))))))
4159        ;; Adjust assocs.
4160        ((memq mark uncompressed)
4161         (when (not (listp (cdr (symbol-value var))))
4162           (set var (list (symbol-value var))))
4163         (when (not (listp (cdr articles)))
4164           (setq articles (list articles)))
4165         (while articles
4166           (when (or (not (consp (setq article (pop articles))))
4167                     (< (car article) min)
4168                     (> (car article) max))
4169             (set var (delq article (symbol-value var))))))))))
4170
4171 (defun gnus-update-missing-marks (missing)
4172   "Go through the list of MISSING articles and remove them from the mark lists."
4173   (when missing
4174     (let ((types gnus-article-mark-lists)
4175           var m)
4176       ;; Go through all types.
4177       (while types
4178         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4179         (when (symbol-value var)
4180           ;; This list has articles.  So we delete all missing articles
4181           ;; from it.
4182           (setq m missing)
4183           (while m
4184             (set var (delq (pop m) (symbol-value var)))))))))
4185
4186 (defun gnus-update-marks ()
4187   "Enter the various lists of marked articles into the newsgroup info list."
4188   (let ((types gnus-article-mark-lists)
4189         (info (gnus-get-info gnus-newsgroup-name))
4190         (uncompressed '(score bookmark killed))
4191         type list newmarked symbol delta-marks)
4192     (when info
4193       ;; Add all marks lists that are non-nil to the list of marks lists.
4194       (while (setq type (pop types))
4195         (when (setq list (symbol-value
4196                           (setq symbol
4197                                 (intern (format "gnus-newsgroup-%s"
4198                                                 (car type))))))
4199
4200           ;; Get rid of the entries of the articles that have the
4201           ;; default score.
4202           (when (and (eq (cdr type) 'score)
4203                      gnus-save-score
4204                      list)
4205             (let* ((arts list)
4206                    (prev (cons nil list))
4207                    (all prev))
4208               (while arts
4209                 (if (or (not (consp (car arts)))
4210                         (= (cdar arts) gnus-summary-default-score))
4211                     (setcdr prev (cdr arts))
4212                   (setq prev arts))
4213                 (setq arts (cdr arts)))
4214               (setq list (cdr all))))
4215
4216           (push (cons (cdr type)
4217                       (if (memq (cdr type) uncompressed) list
4218                         (gnus-compress-sequence
4219                          (set symbol (sort list '<)) t)))
4220                 newmarked)))
4221
4222       ;; Enter these new marks into the info of the group.
4223       (if (nthcdr 3 info)
4224           (setcar (nthcdr 3 info) newmarked)
4225         ;; Add the marks lists to the end of the info.
4226         (when newmarked
4227           (setcdr (nthcdr 2 info) (list newmarked))))
4228
4229       ;; Cut off the end of the info if there's nothing else there.
4230       (let ((i 5))
4231         (while (and (> i 2)
4232                     (not (nth i info)))
4233           (when (nthcdr (decf i) info)
4234             (setcdr (nthcdr i info) nil)))))))
4235
4236 (defun gnus-set-mode-line (where)
4237   "This function sets the mode line of the article or summary buffers.
4238 If WHERE is `summary', the summary mode line format will be used."
4239   ;; Is this mode line one we keep updated?
4240   (when (and (memq where gnus-updated-mode-lines)
4241              (symbol-value
4242               (intern (format "gnus-%s-mode-line-format-spec" where))))
4243     (let (mode-string)
4244       (save-excursion
4245         ;; We evaluate this in the summary buffer since these
4246         ;; variables are buffer-local to that buffer.
4247         (set-buffer gnus-summary-buffer)
4248         ;; We bind all these variables that are used in the `eval' form
4249         ;; below.
4250         (let* ((mformat (symbol-value
4251                          (intern
4252                           (format "gnus-%s-mode-line-format-spec" where))))
4253                (gnus-tmp-group-name gnus-newsgroup-name)
4254                (gnus-tmp-article-number (or gnus-current-article 0))
4255                (gnus-tmp-unread gnus-newsgroup-unreads)
4256                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4257                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4258                (gnus-tmp-unread-and-unselected
4259                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4260                             (zerop gnus-tmp-unselected))
4261                        "")
4262                       ((zerop gnus-tmp-unselected)
4263                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4264                       (t (format "{%d(+%d) more}"
4265                                  gnus-tmp-unread-and-unticked
4266                                  gnus-tmp-unselected))))
4267                (gnus-tmp-subject
4268                 (if (and gnus-current-headers
4269                          (vectorp gnus-current-headers))
4270                     (gnus-mode-string-quote
4271                      (mail-header-subject gnus-current-headers))
4272                   ""))
4273                bufname-length max-len
4274                gnus-tmp-header);; passed as argument to any user-format-funcs
4275           (setq mode-string (eval mformat))
4276           (setq bufname-length (if (string-match "%b" mode-string)
4277                                    (- (length
4278                                        (buffer-name
4279                                         (if (eq where 'summary)
4280                                             nil
4281                                           (get-buffer gnus-article-buffer))))
4282                                       2)
4283                                  0))
4284           (setq max-len (max 4 (if gnus-mode-non-string-length
4285                                    (- (window-width)
4286                                       gnus-mode-non-string-length
4287                                       bufname-length)
4288                                  (length mode-string))))
4289           ;; We might have to chop a bit of the string off...
4290           (when (> (length mode-string) max-len)
4291             (setq mode-string
4292                   (concat (gnus-truncate-string mode-string (- max-len 3))
4293                           "...")))
4294           ;; Pad the mode string a bit.
4295           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4296       ;; Update the mode line.
4297       (setq mode-line-buffer-identification
4298             (gnus-mode-line-buffer-identification (list mode-string)))
4299       (set-buffer-modified-p t))))
4300
4301 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4302   "Go through the HEADERS list and add all Xrefs to a hash table.
4303 The resulting hash table is returned, or nil if no Xrefs were found."
4304   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4305          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4306          (xref-hashtb (gnus-make-hashtable))
4307          start group entry number xrefs header)
4308     (while headers
4309       (setq header (pop headers))
4310       (when (and (setq xrefs (mail-header-xref header))
4311                  (not (memq (setq number (mail-header-number header))
4312                             unreads)))
4313         (setq start 0)
4314         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4315           (setq start (match-end 0))
4316           (setq group (if prefix
4317                           (concat prefix (substring xrefs (match-beginning 1)
4318                                                     (match-end 1)))
4319                         (substring xrefs (match-beginning 1) (match-end 1))))
4320           (setq number
4321                 (string-to-int (substring xrefs (match-beginning 2)
4322                                           (match-end 2))))
4323           (if (setq entry (gnus-gethash group xref-hashtb))
4324               (setcdr entry (cons number (cdr entry)))
4325             (gnus-sethash group (cons number nil) xref-hashtb)))))
4326     (and start xref-hashtb)))
4327
4328 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4329   "Look through all the headers and mark the Xrefs as read."
4330   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4331         name entry info xref-hashtb idlist method nth4)
4332     (save-excursion
4333       (set-buffer gnus-group-buffer)
4334       (when (setq xref-hashtb
4335                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4336         (mapatoms
4337          (lambda (group)
4338            (unless (string= from-newsgroup (setq name (symbol-name group)))
4339              (setq idlist (symbol-value group))
4340              ;; Dead groups are not updated.
4341              (and (prog1
4342                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4343                             info (nth 2 entry))
4344                     (when (stringp (setq nth4 (gnus-info-method info)))
4345                       (setq nth4 (gnus-server-to-method nth4))))
4346                   ;; Only do the xrefs if the group has the same
4347                   ;; select method as the group we have just read.
4348                   (or (gnus-methods-equal-p
4349                        nth4 (gnus-find-method-for-group from-newsgroup))
4350                       virtual
4351                       (equal nth4 (setq method (gnus-find-method-for-group
4352                                                 from-newsgroup)))
4353                       (and (equal (car nth4) (car method))
4354                            (equal (nth 1 nth4) (nth 1 method))))
4355                   gnus-use-cross-reference
4356                   (or (not (eq gnus-use-cross-reference t))
4357                       virtual
4358                       ;; Only do cross-references on subscribed
4359                       ;; groups, if that is what is wanted.
4360                       (<= (gnus-info-level info) gnus-level-subscribed))
4361                   (gnus-group-make-articles-read name idlist))))
4362          xref-hashtb)))))
4363
4364 (defun gnus-compute-read-articles (group articles)
4365   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4366          (info (nth 2 entry))
4367          (active (gnus-active group))
4368          ninfo)
4369     (when entry
4370       ;; First peel off all illegal article numbers.
4371       (when active
4372         (let ((ids articles)
4373               id first)
4374           (while (setq id (pop ids))
4375             (when (and first (> id (cdr active)))
4376               ;; We'll end up in this situation in one particular
4377               ;; obscure situation.  If you re-scan a group and get
4378               ;; a new article that is cross-posted to a different
4379               ;; group that has not been re-scanned, you might get
4380               ;; crossposted article that has a higher number than
4381               ;; Gnus believes possible.  So we re-activate this
4382               ;; group as well.  This might mean doing the
4383               ;; crossposting thingy will *increase* the number
4384               ;; of articles in some groups.  Tsk, tsk.
4385               (setq active (or (gnus-activate-group group) active)))
4386             (when (or (> id (cdr active))
4387                       (< id (car active)))
4388               (setq articles (delq id articles))))))
4389       ;; If the read list is nil, we init it.
4390       (if (and active
4391                (null (gnus-info-read info))
4392                (> (car active) 1))
4393           (setq ninfo (cons 1 (1- (car active))))
4394         (setq ninfo (gnus-info-read info)))
4395       ;; Then we add the read articles to the range.
4396       (gnus-add-to-range
4397        ninfo (setq articles (sort articles '<))))))
4398
4399 (defun gnus-group-make-articles-read (group articles)
4400   "Update the info of GROUP to say that ARTICLES are read."
4401   (let* ((num 0)
4402          (entry (gnus-gethash group gnus-newsrc-hashtb))
4403          (info (nth 2 entry))
4404          (active (gnus-active group))
4405          range)
4406     (when entry
4407       (setq range (gnus-compute-read-articles group articles))
4408       (save-excursion
4409         (set-buffer gnus-group-buffer)
4410         (gnus-undo-register
4411           `(progn
4412              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4413              (gnus-info-set-read ',info ',(gnus-info-read info))
4414              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4415              (gnus-group-update-group ,group t))))
4416       ;; Add the read articles to the range.
4417       (gnus-info-set-read info range)
4418       ;; Then we have to re-compute how many unread
4419       ;; articles there are in this group.
4420       (when active
4421         (cond
4422          ((not range)
4423           (setq num (- (1+ (cdr active)) (car active))))
4424          ((not (listp (cdr range)))
4425           (setq num (- (cdr active) (- (1+ (cdr range))
4426                                        (car range)))))
4427          (t
4428           (while range
4429             (if (numberp (car range))
4430                 (setq num (1+ num))
4431               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4432             (setq range (cdr range)))
4433           (setq num (- (cdr active) num))))
4434         ;; Update the number of unread articles.
4435         (setcar entry num)
4436         ;; Update the group buffer.
4437         (gnus-group-update-group group t)))))
4438
4439 (defun gnus-methods-equal-p (m1 m2)
4440   (let ((m1 (or m1 gnus-select-method))
4441         (m2 (or m2 gnus-select-method)))
4442     (or (equal m1 m2)
4443         (and (eq (car m1) (car m2))
4444              (or (not (memq 'address (assoc (symbol-name (car m1))
4445                                             gnus-valid-select-methods)))
4446                  (equal (nth 1 m1) (nth 1 m2)))))))
4447
4448 (defvar gnus-newsgroup-none-id 0)
4449
4450 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4451   (let ((cur nntp-server-buffer)
4452         (dependencies
4453          (or dependencies
4454              (save-excursion (set-buffer gnus-summary-buffer)
4455                              gnus-newsgroup-dependencies)))
4456         headers id end ref)
4457     (save-excursion
4458       (set-buffer nntp-server-buffer)
4459       ;; Translate all TAB characters into SPACE characters.
4460       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4461       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4462       (gnus-run-hooks 'gnus-parse-headers-hook)
4463       (let ((case-fold-search t)
4464             in-reply-to header p lines chars ctype)
4465         (goto-char (point-min))
4466         ;; Search to the beginning of the next header.  Error messages
4467         ;; do not begin with 2 or 3.
4468         (while (re-search-forward "^[23][0-9]+ " nil t)
4469           (setq id nil
4470                 ref nil)
4471           ;; This implementation of this function, with nine
4472           ;; search-forwards instead of the one re-search-forward and
4473           ;; a case (which basically was the old function) is actually
4474           ;; about twice as fast, even though it looks messier.  You
4475           ;; can't have everything, I guess.  Speed and elegance
4476           ;; doesn't always go hand in hand.
4477           (setq
4478            header
4479            (make-full-mail-header
4480             ;; Number.
4481             (prog1
4482                 (read cur)
4483               (end-of-line)
4484               (setq p (point))
4485               (narrow-to-region (point)
4486                                 (or (and (search-forward "\n.\n" nil t)
4487                                          (- (point) 2))
4488                                     (point))))
4489             ;; Subject.
4490             (progn
4491               (goto-char p)
4492               (if (search-forward "\nsubject: " nil t)
4493                   (buffer-substring (match-end 0) (std11-field-end))
4494                 "(none)"))
4495             ;; From.
4496             (progn
4497               (goto-char p)
4498               (if (search-forward "\nfrom: " nil t)
4499                   (buffer-substring (match-end 0) (std11-field-end))
4500                 "(nobody)"))
4501             ;; Date.
4502             (progn
4503               (goto-char p)
4504               (if (search-forward "\ndate: " nil t)
4505                   (buffer-substring (match-end 0) (std11-field-end))
4506                 ""))
4507             ;; Message-ID.
4508             (progn
4509               (goto-char p)
4510               (setq id (if (re-search-forward
4511                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4512                            ;; We do it this way to make sure the Message-ID
4513                            ;; is (somewhat) syntactically valid.
4514                            (buffer-substring (match-beginning 1)
4515                                              (match-end 1))
4516                          ;; If there was no message-id, we just fake one
4517                          ;; to make subsequent routines simpler.
4518                          (nnheader-generate-fake-message-id))))
4519             ;; References.
4520             (progn
4521               (goto-char p)
4522               (if (search-forward "\nreferences: " nil t)
4523                   (progn
4524                     (setq end (point))
4525                     (prog1
4526                         (buffer-substring (match-end 0) (std11-field-end))
4527                       (setq ref
4528                             (buffer-substring
4529                              (progn
4530                                ;; (end-of-line)
4531                                (search-backward ">" end t)
4532                                (1+ (point)))
4533                              (progn
4534                                (search-backward "<" end t)
4535                                (point))))))
4536                 ;; Get the references from the in-reply-to header if there
4537                 ;; were no references and the in-reply-to header looks
4538                 ;; promising.
4539                 (if (and (search-forward "\nin-reply-to: " nil t)
4540                          (setq in-reply-to
4541                                (buffer-substring (match-end 0)
4542                                                  (std11-field-end)))
4543                          (string-match "<[^>]+>" in-reply-to))
4544                     (let (ref2)
4545                       (setq ref (substring in-reply-to (match-beginning 0)
4546                                            (match-end 0)))
4547                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4548                         (setq ref2 (substring in-reply-to (match-beginning 0)
4549                                               (match-end 0)))
4550                         (when (> (length ref2) (length ref))
4551                           (setq ref ref2)))
4552                       ref)
4553                   (setq ref nil))))
4554             ;; Chars.
4555             (progn
4556               (goto-char p)
4557               (if (search-forward "\nchars: " nil t)
4558                   (if (numberp (setq chars (ignore-errors (read cur))))
4559                       chars 0)
4560                 0))
4561             ;; Lines.
4562             (progn
4563               (goto-char p)
4564               (if (search-forward "\nlines: " nil t)
4565                   (if (numberp (setq lines (ignore-errors (read cur))))
4566                       lines 0)
4567                 0))
4568             ;; Xref.
4569             (progn
4570               (goto-char p)
4571               (and (search-forward "\nxref: " nil t)
4572                    (buffer-substring (match-end 0) (std11-field-end))))
4573             ;; Extra.
4574             (when gnus-extra-headers
4575               (let ((extra gnus-extra-headers)
4576                     out)
4577                 (while extra
4578                   (goto-char p)
4579                   (when (search-forward
4580                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4581                     (push (cons (car extra)
4582                                 (buffer-substring (match-end 0)
4583                                                   (std11-field-end)))
4584                           out))
4585                   (pop extra))
4586                 out))))
4587           (goto-char p)
4588           (if (and (search-forward "\ncontent-type: " nil t)
4589                    (setq ctype
4590                          (buffer-substring (match-end 0) (std11-field-end))))
4591               (mime-entity-set-content-type-internal
4592                header (mime-parse-Content-Type ctype)))
4593           (when (equal id ref)
4594             (setq ref nil))
4595
4596           (when gnus-alter-header-function
4597             (funcall gnus-alter-header-function header)
4598             (setq id (mail-header-id header)
4599                   ref (gnus-parent-id (mail-header-references header))))
4600
4601           (when (setq header
4602                       (gnus-dependencies-add-header
4603                        header dependencies force-new))
4604             (push header headers))
4605           (goto-char (point-max))
4606           (widen))
4607         (nreverse headers)))))
4608
4609 ;; Goes through the xover lines and returns a list of vectors
4610 (defun gnus-get-newsgroup-headers-xover (sequence &optional
4611                                                   force-new dependencies
4612                                                   group also-fetch-heads)
4613   "Parse the news overview data in the server buffer, and return a
4614 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4615   ;; Get the Xref when the users reads the articles since most/some
4616   ;; NNTP servers do not include Xrefs when using XOVER.
4617   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4618   (let ((cur nntp-server-buffer)
4619         (dependencies (or dependencies gnus-newsgroup-dependencies))
4620         number headers header)
4621     (save-excursion
4622       (set-buffer nntp-server-buffer)
4623       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4624       ;; Allow the user to mangle the headers before parsing them.
4625       (gnus-run-hooks 'gnus-parse-headers-hook)
4626       (goto-char (point-min))
4627       (while (not (eobp))
4628         (condition-case ()
4629             (while (and sequence (not (eobp)))
4630               (setq number (read cur))
4631               (while (and sequence
4632                           (< (car sequence) number))
4633                 (setq sequence (cdr sequence)))
4634               (and sequence
4635                    (eq number (car sequence))
4636                    (progn
4637                      (setq sequence (cdr sequence))
4638                      (setq header (inline
4639                                     (gnus-nov-parse-line
4640                                      number dependencies force-new))))
4641                    (push header headers))
4642               (forward-line 1))
4643           (error
4644            (gnus-error 4 "Strange nov line (%d)"
4645                        (count-lines (point-min) (point)))))
4646         (forward-line 1))
4647       ;; A common bug in inn is that if you have posted an article and
4648       ;; then retrieves the active file, it will answer correctly --
4649       ;; the new article is included.  However, a NOV entry for the
4650       ;; article may not have been generated yet, so this may fail.
4651       ;; We work around this problem by retrieving the last few
4652       ;; headers using HEAD.
4653       (if (or (not also-fetch-heads)
4654               (not sequence))
4655           ;; We (probably) got all the headers.
4656           (nreverse headers)
4657         (let ((gnus-nov-is-evil t))
4658           (nconc
4659            (nreverse headers)
4660            (when (gnus-retrieve-headers sequence group)
4661              (gnus-get-newsgroup-headers))))))))
4662
4663 (defun gnus-article-get-xrefs ()
4664   "Fill in the Xref value in `gnus-current-headers', if necessary.
4665 This is meant to be called in `gnus-article-internal-prepare-hook'."
4666   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4667                                  gnus-current-headers)))
4668     (or (not gnus-use-cross-reference)
4669         (not headers)
4670         (and (mail-header-xref headers)
4671              (not (string= (mail-header-xref headers) "")))
4672         (let ((case-fold-search t)
4673               xref)
4674           (save-restriction
4675             (nnheader-narrow-to-headers)
4676             (goto-char (point-min))
4677             (when (or (and (eq (downcase (char-after)) ?x)
4678                            (looking-at "Xref:"))
4679                       (search-forward "\nXref:" nil t))
4680               (goto-char (1+ (match-end 0)))
4681               (setq xref (buffer-substring (point)
4682                                            (progn (end-of-line) (point))))
4683               (mail-header-set-xref headers xref)))))))
4684
4685 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4686   "Find article ID and insert the summary line for that article.
4687 OLD-HEADER can either be a header or a line number to insert
4688 the subject line on."
4689   (let* ((line (and (numberp old-header) old-header))
4690          (old-header (and (vectorp old-header) old-header))
4691          (header (cond ((and old-header use-old-header)
4692                         old-header)
4693                        ((and (numberp id)
4694                              (gnus-number-to-header id))
4695                         (gnus-number-to-header id))
4696                        (t
4697                         (gnus-read-header id))))
4698          (number (and (numberp id) id))
4699          d)
4700     (when header
4701       ;; Rebuild the thread that this article is part of and go to the
4702       ;; article we have fetched.
4703       (when (and (not gnus-show-threads)
4704                  old-header)
4705         (when (and number
4706                    (setq d (gnus-data-find (mail-header-number old-header))))
4707           (goto-char (gnus-data-pos d))
4708           (gnus-data-remove
4709            number
4710            (- (gnus-point-at-bol)
4711               (prog1
4712                   (1+ (gnus-point-at-eol))
4713                 (gnus-delete-line))))))
4714       (when old-header
4715         (mail-header-set-number header (mail-header-number old-header)))
4716       (setq gnus-newsgroup-sparse
4717             (delq (setq number (mail-header-number header))
4718                   gnus-newsgroup-sparse))
4719       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4720       (push number gnus-newsgroup-limit)
4721       (gnus-rebuild-thread (mail-header-id header) line)
4722       (gnus-summary-goto-subject number nil t))
4723     (when (and (numberp number)
4724                (> number 0))
4725       ;; We have to update the boundaries even if we can't fetch the
4726       ;; article if ID is a number -- so that the next `P' or `N'
4727       ;; command will fetch the previous (or next) article even
4728       ;; if the one we tried to fetch this time has been canceled.
4729       (when (> number gnus-newsgroup-end)
4730         (setq gnus-newsgroup-end number))
4731       (when (< number gnus-newsgroup-begin)
4732         (setq gnus-newsgroup-begin number))
4733       (setq gnus-newsgroup-unselected
4734             (delq number gnus-newsgroup-unselected)))
4735     ;; Report back a success?
4736     (and header (mail-header-number header))))
4737
4738 ;;; Process/prefix in the summary buffer
4739
4740 (defun gnus-summary-work-articles (n)
4741   "Return a list of articles to be worked upon.
4742 The prefix argument, the list of process marked articles, and the
4743 current article will be taken into consideration."
4744   (save-excursion
4745     (set-buffer gnus-summary-buffer)
4746     (cond
4747      (n
4748       ;; A numerical prefix has been given.
4749       (setq n (prefix-numeric-value n))
4750       (let ((backward (< n 0))
4751             (n (abs (prefix-numeric-value n)))
4752             articles article)
4753         (save-excursion
4754           (while
4755               (and (> n 0)
4756                    (push (setq article (gnus-summary-article-number))
4757                          articles)
4758                    (if backward
4759                        (gnus-summary-find-prev nil article)
4760                      (gnus-summary-find-next nil article)))
4761             (decf n)))
4762         (nreverse articles)))
4763      ((and (gnus-region-active-p) (mark))
4764       (message "region active")
4765       ;; Work on the region between point and mark.
4766       (let ((max (max (point) (mark)))
4767             articles article)
4768         (save-excursion
4769           (goto-char (min (point) (mark)))
4770           (while
4771               (and
4772                (push (setq article (gnus-summary-article-number)) articles)
4773                (gnus-summary-find-next nil article)
4774                (< (point) max)))
4775           (nreverse articles))))
4776      (gnus-newsgroup-processable
4777       ;; There are process-marked articles present.
4778       ;; Save current state.
4779       (gnus-summary-save-process-mark)
4780       ;; Return the list.
4781       (reverse gnus-newsgroup-processable))
4782      (t
4783       ;; Just return the current article.
4784       (list (gnus-summary-article-number))))))
4785
4786 (defmacro gnus-summary-iterate (arg &rest forms)
4787   "Iterate over the process/prefixed articles and do FORMS.
4788 ARG is the interactive prefix given to the command.  FORMS will be
4789 executed with point over the summary line of the articles."
4790   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
4791     `(let ((,articles (gnus-summary-work-articles ,arg)))
4792        (while ,articles
4793          (gnus-summary-goto-subject (car ,articles))
4794          ,@forms))))
4795
4796 (put 'gnus-summary-iterate 'lisp-indent-function 1)
4797 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
4798
4799 (defun gnus-summary-save-process-mark ()
4800   "Push the current set of process marked articles on the stack."
4801   (interactive)
4802   (push (copy-sequence gnus-newsgroup-processable)
4803         gnus-newsgroup-process-stack))
4804
4805 (defun gnus-summary-kill-process-mark ()
4806   "Push the current set of process marked articles on the stack and unmark."
4807   (interactive)
4808   (gnus-summary-save-process-mark)
4809   (gnus-summary-unmark-all-processable))
4810
4811 (defun gnus-summary-yank-process-mark ()
4812   "Pop the last process mark state off the stack and restore it."
4813   (interactive)
4814   (unless gnus-newsgroup-process-stack
4815     (error "Empty mark stack"))
4816   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4817
4818 (defun gnus-summary-process-mark-set (set)
4819   "Make SET into the current process marked articles."
4820   (gnus-summary-unmark-all-processable)
4821   (while set
4822     (gnus-summary-set-process-mark (pop set))))
4823
4824 ;;; Searching and stuff
4825
4826 (defun gnus-summary-search-group (&optional backward use-level)
4827   "Search for next unread newsgroup.
4828 If optional argument BACKWARD is non-nil, search backward instead."
4829   (save-excursion
4830     (set-buffer gnus-group-buffer)
4831     (when (gnus-group-search-forward
4832            backward nil (if use-level (gnus-group-group-level) nil))
4833       (gnus-group-group-name))))
4834
4835 (defun gnus-summary-best-group (&optional exclude-group)
4836   "Find the name of the best unread group.
4837 If EXCLUDE-GROUP, do not go to this group."
4838   (save-excursion
4839     (set-buffer gnus-group-buffer)
4840     (save-excursion
4841       (gnus-group-best-unread-group exclude-group))))
4842
4843 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
4844   (if backward (gnus-summary-find-prev)
4845     (let* ((dummy (gnus-summary-article-intangible-p))
4846            (article (or article (gnus-summary-article-number)))
4847            (arts (gnus-data-find-list article))
4848            result)
4849       (when (and (not dummy)
4850                  (or (not gnus-summary-check-current)
4851                      (not unread)
4852                      (not (gnus-data-unread-p (car arts)))))
4853         (setq arts (cdr arts)))
4854       (when (setq result
4855                   (if unread
4856                       (progn
4857                         (while arts
4858                           (when (or (and undownloaded
4859                                          (eq gnus-undownloaded-mark
4860                                              (gnus-data-mark (car arts))))
4861                                     (gnus-data-unread-p (car arts)))
4862                             (setq result (car arts)
4863                                   arts nil))
4864                           (setq arts (cdr arts)))
4865                         result)
4866                     (car arts)))
4867         (goto-char (gnus-data-pos result))
4868         (gnus-data-number result)))))
4869
4870 (defun gnus-summary-find-prev (&optional unread article)
4871   (let* ((eobp (eobp))
4872          (article (or article (gnus-summary-article-number)))
4873          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
4874          result)
4875     (when (and (not eobp)
4876                (or (not gnus-summary-check-current)
4877                    (not unread)
4878                    (not (gnus-data-unread-p (car arts)))))
4879       (setq arts (cdr arts)))
4880     (when (setq result
4881                 (if unread
4882                     (progn
4883                       (while arts
4884                         (when (gnus-data-unread-p (car arts))
4885                           (setq result (car arts)
4886                                 arts nil))
4887                         (setq arts (cdr arts)))
4888                       result)
4889                   (car arts)))
4890       (goto-char (gnus-data-pos result))
4891       (gnus-data-number result))))
4892
4893 (defun gnus-summary-find-subject (subject &optional unread backward article)
4894   (let* ((simp-subject (gnus-simplify-subject-fully subject))
4895          (article (or article (gnus-summary-article-number)))
4896          (articles (gnus-data-list backward))
4897          (arts (gnus-data-find-list article articles))
4898          result)
4899     (when (or (not gnus-summary-check-current)
4900               (not unread)
4901               (not (gnus-data-unread-p (car arts))))
4902       (setq arts (cdr arts)))
4903     (while arts
4904       (and (or (not unread)
4905                (gnus-data-unread-p (car arts)))
4906            (vectorp (gnus-data-header (car arts)))
4907            (gnus-subject-equal
4908             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
4909            (setq result (car arts)
4910                  arts nil))
4911       (setq arts (cdr arts)))
4912     (and result
4913          (goto-char (gnus-data-pos result))
4914          (gnus-data-number result))))
4915
4916 (defun gnus-summary-search-forward (&optional unread subject backward)
4917   "Search forward for an article.
4918 If UNREAD, look for unread articles.  If SUBJECT, look for
4919 articles with that subject.  If BACKWARD, search backward instead."
4920   (cond (subject (gnus-summary-find-subject subject unread backward))
4921         (backward (gnus-summary-find-prev unread))
4922         (t (gnus-summary-find-next unread))))
4923
4924 (defun gnus-recenter (&optional n)
4925   "Center point in window and redisplay frame.
4926 Also do horizontal recentering."
4927   (interactive "P")
4928   (when (and gnus-auto-center-summary
4929              (not (eq gnus-auto-center-summary 'vertical)))
4930     (gnus-horizontal-recenter))
4931   (recenter n))
4932
4933 (defun gnus-summary-recenter ()
4934   "Center point in the summary window.
4935 If `gnus-auto-center-summary' is nil, or the article buffer isn't
4936 displayed, no centering will be performed."
4937   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
4938   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
4939   (let* ((top (cond ((< (window-height) 4) 0)
4940                     ((< (window-height) 7) 1)
4941                     (t (if (numberp gnus-auto-center-summary)
4942                            gnus-auto-center-summary
4943                          2))))
4944          (height (1- (window-height)))
4945          (bottom (save-excursion (goto-char (point-max))
4946                                  (forward-line (- height))
4947                                  (point)))
4948          (window (get-buffer-window (current-buffer))))
4949     ;; The user has to want it.
4950     (when gnus-auto-center-summary
4951       (when (get-buffer-window gnus-article-buffer)
4952         ;; Only do recentering when the article buffer is displayed,
4953         ;; Set the window start to either `bottom', which is the biggest
4954         ;; possible valid number, or the second line from the top,
4955         ;; whichever is the least.
4956         (set-window-start
4957          window (min bottom (save-excursion
4958                               (forward-line (- top)) (point)))))
4959       ;; Do horizontal recentering while we're at it.
4960       (when (and (get-buffer-window (current-buffer) t)
4961                  (not (eq gnus-auto-center-summary 'vertical)))
4962         (let ((selected (selected-window)))
4963           (select-window (get-buffer-window (current-buffer) t))
4964           (gnus-summary-position-point)
4965           (gnus-horizontal-recenter)
4966           (select-window selected))))))
4967
4968 (defun gnus-summary-jump-to-group (newsgroup)
4969   "Move point to NEWSGROUP in group mode buffer."
4970   ;; Keep update point of group mode buffer if visible.
4971   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
4972       (save-window-excursion
4973         ;; Take care of tree window mode.
4974         (when (get-buffer-window gnus-group-buffer)
4975           (pop-to-buffer gnus-group-buffer))
4976         (gnus-group-jump-to-group newsgroup))
4977     (save-excursion
4978       ;; Take care of tree window mode.
4979       (if (get-buffer-window gnus-group-buffer)
4980           (pop-to-buffer gnus-group-buffer)
4981         (set-buffer gnus-group-buffer))
4982       (gnus-group-jump-to-group newsgroup))))
4983
4984 ;; This function returns a list of article numbers based on the
4985 ;; difference between the ranges of read articles in this group and
4986 ;; the range of active articles.
4987 (defun gnus-list-of-unread-articles (group)
4988   (let* ((read (gnus-info-read (gnus-get-info group)))
4989          (active (or (gnus-active group) (gnus-activate-group group)))
4990          (last (cdr active))
4991          first nlast unread)
4992     ;; If none are read, then all are unread.
4993     (if (not read)
4994         (setq first (car active))
4995       ;; If the range of read articles is a single range, then the
4996       ;; first unread article is the article after the last read
4997       ;; article.  Sounds logical, doesn't it?
4998       (if (not (listp (cdr read)))
4999           (setq first (max (car active) (1+ (cdr read))))
5000         ;; `read' is a list of ranges.
5001         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5002                                   (caar read)))
5003                   1)
5004           (setq first (car active)))
5005         (while read
5006           (when first
5007             (while (< first nlast)
5008               (push first unread)
5009               (setq first (1+ first))))
5010           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5011           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5012           (setq read (cdr read)))))
5013     ;; And add the last unread articles.
5014     (while (<= first last)
5015       (push first unread)
5016       (setq first (1+ first)))
5017     ;; Return the list of unread articles.
5018     (delq 0 (nreverse unread))))
5019
5020 (defun gnus-list-of-read-articles (group)
5021   "Return a list of unread, unticked and non-dormant articles."
5022   (let* ((info (gnus-get-info group))
5023          (marked (gnus-info-marks info))
5024          (active (gnus-active group)))
5025     (and info active
5026          (gnus-set-difference
5027           (gnus-sorted-complement
5028            (gnus-uncompress-range active)
5029            (gnus-list-of-unread-articles group))
5030           (append
5031            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5032            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5033
5034 ;; Various summary commands
5035
5036 (defun gnus-summary-select-article-buffer ()
5037   "Reconfigure windows to show article buffer."
5038   (interactive)
5039   (if (not (gnus-buffer-live-p gnus-article-buffer))
5040       (error "There is no article buffer for this summary buffer")
5041     (gnus-configure-windows 'article)
5042     (select-window (get-buffer-window gnus-article-buffer))))
5043
5044 (defun gnus-summary-universal-argument (arg)
5045   "Perform any operation on all articles that are process/prefixed."
5046   (interactive "P")
5047   (let ((articles (gnus-summary-work-articles arg))
5048         func article)
5049     (if (eq
5050          (setq
5051           func
5052           (key-binding
5053            (read-key-sequence
5054             (substitute-command-keys
5055              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
5056              ))))
5057          'undefined)
5058         (gnus-error 1 "Undefined key")
5059       (save-excursion
5060         (while articles
5061           (gnus-summary-goto-subject (setq article (pop articles)))
5062           (let (gnus-newsgroup-processable)
5063             (command-execute func))
5064           (gnus-summary-remove-process-mark article)))))
5065   (gnus-summary-position-point))
5066
5067 (defun gnus-summary-toggle-truncation (&optional arg)
5068   "Toggle truncation of summary lines.
5069 With arg, turn line truncation on iff arg is positive."
5070   (interactive "P")
5071   (setq truncate-lines
5072         (if (null arg) (not truncate-lines)
5073           (> (prefix-numeric-value arg) 0)))
5074   (redraw-display))
5075
5076 (defun gnus-summary-reselect-current-group (&optional all rescan)
5077   "Exit and then reselect the current newsgroup.
5078 The prefix argument ALL means to select all articles."
5079   (interactive "P")
5080   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5081     (error "Ephemeral groups can't be reselected"))
5082   (let ((current-subject (gnus-summary-article-number))
5083         (group gnus-newsgroup-name))
5084     (setq gnus-newsgroup-begin nil)
5085     (gnus-summary-exit)
5086     ;; We have to adjust the point of group mode buffer because
5087     ;; point was moved to the next unread newsgroup by exiting.
5088     (gnus-summary-jump-to-group group)
5089     (when rescan
5090       (save-excursion
5091         (gnus-group-get-new-news-this-group 1)))
5092     (gnus-group-read-group all t)
5093     (gnus-summary-goto-subject current-subject nil t)))
5094
5095 (defun gnus-summary-rescan-group (&optional all)
5096   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5097   (interactive "P")
5098   (gnus-summary-reselect-current-group all t))
5099
5100 (defun gnus-summary-update-info (&optional non-destructive)
5101   (save-excursion
5102     (let ((group gnus-newsgroup-name))
5103       (when group
5104         (when gnus-newsgroup-kill-headers
5105           (setq gnus-newsgroup-killed
5106                 (gnus-compress-sequence
5107                  (nconc
5108                   (gnus-set-sorted-intersection
5109                    (gnus-uncompress-range gnus-newsgroup-killed)
5110                    (setq gnus-newsgroup-unselected
5111                          (sort gnus-newsgroup-unselected '<)))
5112                   (setq gnus-newsgroup-unreads
5113                         (sort gnus-newsgroup-unreads '<)))
5114                  t)))
5115         (unless (listp (cdr gnus-newsgroup-killed))
5116           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5117         (let ((headers gnus-newsgroup-headers))
5118           ;; Set the new ranges of read articles.
5119           (save-excursion
5120             (set-buffer gnus-group-buffer)
5121             (gnus-undo-force-boundary))
5122           (gnus-update-read-articles
5123            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5124           ;; Set the current article marks.
5125           (let ((gnus-newsgroup-scored
5126                  (if (and (not gnus-save-score)
5127                           (not non-destructive))
5128                      nil
5129                    gnus-newsgroup-scored)))
5130             (save-excursion
5131               (gnus-update-marks)))
5132           ;; Do the cross-ref thing.
5133           (when gnus-use-cross-reference
5134             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5135           ;; Do not switch windows but change the buffer to work.
5136           (set-buffer gnus-group-buffer)
5137           (unless (gnus-ephemeral-group-p group)
5138             (gnus-group-update-group group)))))))
5139
5140 (defun gnus-summary-save-newsrc (&optional force)
5141   "Save the current number of read/marked articles in the dribble buffer.
5142 The dribble buffer will then be saved.
5143 If FORCE (the prefix), also save the .newsrc file(s)."
5144   (interactive "P")
5145   (gnus-summary-update-info t)
5146   (if force
5147       (gnus-save-newsrc-file)
5148     (gnus-dribble-save)))
5149
5150 (defun gnus-summary-exit (&optional temporary)
5151   "Exit reading current newsgroup, and then return to group selection mode.
5152 gnus-exit-group-hook is called with no arguments if that value is non-nil."
5153   (interactive)
5154   (gnus-set-global-variables)
5155   (gnus-kill-save-kill-buffer)
5156   (gnus-async-halt-prefetch)
5157   (let* ((group gnus-newsgroup-name)
5158          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5159          (mode major-mode)
5160          (group-point nil)
5161          (buf (current-buffer)))
5162     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5163     ;; If we have several article buffers, we kill them at exit.
5164     (unless gnus-single-article-buffer
5165       (gnus-kill-buffer gnus-original-article-buffer)
5166       (setq gnus-article-current nil))
5167     (when gnus-use-cache
5168       (gnus-cache-possibly-remove-articles)
5169       (gnus-cache-save-buffers))
5170     (gnus-async-prefetch-remove-group group)
5171     (when gnus-suppress-duplicates
5172       (gnus-dup-enter-articles))
5173     (when gnus-use-trees
5174       (gnus-tree-close group))
5175     ;; Remove entries for this group.
5176     (nnmail-purge-split-history (gnus-group-real-name group))
5177     ;; Make all changes in this group permanent.
5178     (unless quit-config
5179       (gnus-run-hooks 'gnus-exit-group-hook)
5180       (gnus-summary-update-info)
5181       ;; Do adaptive scoring, and possibly save score files.
5182       (when gnus-newsgroup-adaptive
5183         (gnus-score-adaptive))
5184       (when gnus-use-scoring
5185         (gnus-score-save)))
5186     (gnus-close-group group)
5187     ;; Make sure where we were, and go to next newsgroup.
5188     (set-buffer gnus-group-buffer)
5189     (unless quit-config
5190       (gnus-group-jump-to-group group))
5191     (gnus-run-hooks 'gnus-summary-exit-hook)
5192     (unless (or quit-config
5193                 ;; If this group has disappeared from the summary
5194                 ;; buffer, don't skip forwards.
5195                 (not (string= group (gnus-group-group-name))))
5196       (gnus-group-next-unread-group 1))
5197     (setq group-point (point))
5198     (if temporary
5199         nil                             ;Nothing to do.
5200       ;; If we have several article buffers, we kill them at exit.
5201       (unless gnus-single-article-buffer
5202         (gnus-kill-buffer gnus-article-buffer)
5203         (gnus-kill-buffer gnus-original-article-buffer)
5204         (setq gnus-article-current nil))
5205       (set-buffer buf)
5206       (if (not gnus-kill-summary-on-exit)
5207           (gnus-deaden-summary)
5208         ;; We set all buffer-local variables to nil.  It is unclear why
5209         ;; this is needed, but if we don't, buffer-local variables are
5210         ;; not garbage-collected, it seems.  This would the lead to en
5211         ;; ever-growing Emacs.
5212         (gnus-summary-clear-local-variables)
5213         (when (get-buffer gnus-article-buffer)
5214           (bury-buffer gnus-article-buffer))
5215         ;; We clear the global counterparts of the buffer-local
5216         ;; variables as well, just to be on the safe side.
5217         (set-buffer gnus-group-buffer)
5218         (gnus-summary-clear-local-variables)
5219         ;; Return to group mode buffer.
5220         (when (eq mode 'gnus-summary-mode)
5221           (gnus-kill-buffer buf)))
5222       (setq gnus-current-select-method gnus-select-method)
5223       (pop-to-buffer gnus-group-buffer)
5224       (if (not quit-config)
5225           (progn
5226             (goto-char group-point)
5227             (gnus-configure-windows 'group 'force))
5228         (gnus-handle-ephemeral-exit quit-config))
5229       ;; Clear the current group name.
5230       (unless quit-config
5231         (setq gnus-newsgroup-name nil)))))
5232
5233 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5234 (defun gnus-summary-exit-no-update (&optional no-questions)
5235   "Quit reading current newsgroup without updating read article info."
5236   (interactive)
5237   (let* ((group gnus-newsgroup-name)
5238          (quit-config (gnus-group-quit-config group)))
5239     (when (or no-questions
5240               gnus-expert-user
5241               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5242       (gnus-async-halt-prefetch)
5243       (gnus-run-hooks (delq 'gnus-summary-expire-articles
5244                             (copy-list gnus-summary-prepare-exit-hook)))
5245       ;; If we have several article buffers, we kill them at exit.
5246       (unless gnus-single-article-buffer
5247         (gnus-kill-buffer gnus-article-buffer)
5248         (gnus-kill-buffer gnus-original-article-buffer)
5249         (setq gnus-article-current nil))
5250       (if (not gnus-kill-summary-on-exit)
5251           (gnus-deaden-summary)
5252         (gnus-close-group group)
5253         (gnus-summary-clear-local-variables)
5254         (set-buffer gnus-group-buffer)
5255         (gnus-summary-clear-local-variables)
5256         (when (get-buffer gnus-summary-buffer)
5257           (kill-buffer gnus-summary-buffer)))
5258       (unless gnus-single-article-buffer
5259         (setq gnus-article-current nil))
5260       (when gnus-use-trees
5261         (gnus-tree-close group))
5262       (gnus-async-prefetch-remove-group group)
5263       (when (get-buffer gnus-article-buffer)
5264         (bury-buffer gnus-article-buffer))
5265       ;; Return to the group buffer.
5266       (gnus-configure-windows 'group 'force)
5267       ;; Clear the current group name.
5268       (setq gnus-newsgroup-name nil)
5269       (when (equal (gnus-group-group-name) group)
5270         (gnus-group-next-unread-group 1))
5271       (when quit-config
5272         (gnus-handle-ephemeral-exit quit-config)))))
5273
5274 (defun gnus-handle-ephemeral-exit (quit-config)
5275   "Handle movement when leaving an ephemeral group.
5276 The state which existed when entering the ephemeral is reset."
5277   (if (not (buffer-name (car quit-config)))
5278       (gnus-configure-windows 'group 'force)
5279     (set-buffer (car quit-config))
5280     (cond ((eq major-mode 'gnus-summary-mode)
5281            (gnus-set-global-variables))
5282           ((eq major-mode 'gnus-article-mode)
5283            (save-excursion
5284              ;; The `gnus-summary-buffer' variable may point
5285              ;; to the old summary buffer when using a single
5286              ;; article buffer.
5287              (unless (gnus-buffer-live-p gnus-summary-buffer)
5288                (set-buffer gnus-group-buffer))
5289              (set-buffer gnus-summary-buffer)
5290              (gnus-set-global-variables))))
5291     (if (or (eq (cdr quit-config) 'article)
5292             (eq (cdr quit-config) 'pick))
5293         (progn
5294           ;; The current article may be from the ephemeral group
5295           ;; thus it is best that we reload this article
5296           (gnus-summary-show-article)
5297           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5298               (gnus-configure-windows 'pick 'force)
5299             (gnus-configure-windows (cdr quit-config) 'force)))
5300       (gnus-configure-windows (cdr quit-config) 'force))
5301     (when (eq major-mode 'gnus-summary-mode)
5302       (gnus-summary-next-subject 1 nil t)
5303       (gnus-summary-recenter)
5304       (gnus-summary-position-point))))
5305
5306 (defun gnus-summary-preview-mime-message (arg)
5307   "MIME decode and play this message."
5308   (interactive "P")
5309   (or gnus-show-mime
5310       (let ((gnus-break-pages nil)
5311             (gnus-show-mime t))
5312         (gnus-summary-select-article t t)
5313         ))
5314   (select-window (get-buffer-window gnus-article-buffer))
5315   )
5316
5317 ;;; Dead summaries.
5318
5319 (defvar gnus-dead-summary-mode-map nil)
5320
5321 (unless gnus-dead-summary-mode-map
5322   (setq gnus-dead-summary-mode-map (make-keymap))
5323   (suppress-keymap gnus-dead-summary-mode-map)
5324   (substitute-key-definition
5325    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5326   (let ((keys '("\C-d" "\r" "\177" [delete])))
5327     (while keys
5328       (define-key gnus-dead-summary-mode-map
5329         (pop keys) 'gnus-summary-wake-up-the-dead))))
5330
5331 (defvar gnus-dead-summary-mode nil
5332   "Minor mode for Gnus summary buffers.")
5333
5334 (defun gnus-dead-summary-mode (&optional arg)
5335   "Minor mode for Gnus summary buffers."
5336   (interactive "P")
5337   (when (eq major-mode 'gnus-summary-mode)
5338     (make-local-variable 'gnus-dead-summary-mode)
5339     (setq gnus-dead-summary-mode
5340           (if (null arg) (not gnus-dead-summary-mode)
5341             (> (prefix-numeric-value arg) 0)))
5342     (when gnus-dead-summary-mode
5343       (gnus-add-minor-mode
5344        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5345
5346 (defun gnus-deaden-summary ()
5347   "Make the current summary buffer into a dead summary buffer."
5348   ;; Kill any previous dead summary buffer.
5349   (when (and gnus-dead-summary
5350              (buffer-name gnus-dead-summary))
5351     (save-excursion
5352       (set-buffer gnus-dead-summary)
5353       (when gnus-dead-summary-mode
5354         (kill-buffer (current-buffer)))))
5355   ;; Make this the current dead summary.
5356   (setq gnus-dead-summary (current-buffer))
5357   (gnus-dead-summary-mode 1)
5358   (let ((name (buffer-name)))
5359     (when (string-match "Summary" name)
5360       (rename-buffer
5361        (concat (substring name 0 (match-beginning 0)) "Dead "
5362                (substring name (match-beginning 0)))
5363        t))))
5364
5365 (defun gnus-kill-or-deaden-summary (buffer)
5366   "Kill or deaden the summary BUFFER."
5367   (save-excursion
5368     (when (and (buffer-name buffer)
5369                (not gnus-single-article-buffer))
5370       (save-excursion
5371         (set-buffer buffer)
5372         (gnus-kill-buffer gnus-article-buffer)
5373         (gnus-kill-buffer gnus-original-article-buffer)))
5374     (cond (gnus-kill-summary-on-exit
5375            (when (and gnus-use-trees
5376                       (gnus-buffer-exists-p buffer))
5377              (save-excursion
5378                (set-buffer buffer)
5379                (gnus-tree-close gnus-newsgroup-name)))
5380            (gnus-kill-buffer buffer))
5381           ((gnus-buffer-exists-p buffer)
5382            (save-excursion
5383              (set-buffer buffer)
5384              (gnus-deaden-summary))))))
5385
5386 (defun gnus-summary-wake-up-the-dead (&rest args)
5387   "Wake up the dead summary buffer."
5388   (interactive)
5389   (gnus-dead-summary-mode -1)
5390   (let ((name (buffer-name)))
5391     (when (string-match "Dead " name)
5392       (rename-buffer
5393        (concat (substring name 0 (match-beginning 0))
5394                (substring name (match-end 0)))
5395        t)))
5396   (gnus-message 3 "This dead summary is now alive again"))
5397
5398 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5399 (defun gnus-summary-fetch-faq (&optional faq-dir)
5400   "Fetch the FAQ for the current group.
5401 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5402 in."
5403   (interactive
5404    (list
5405     (when current-prefix-arg
5406       (completing-read
5407        "Faq dir: " (and (listp gnus-group-faq-directory)
5408                         (mapcar (lambda (file) (list file))
5409                                 gnus-group-faq-directory))))))
5410   (let (gnus-faq-buffer)
5411     (when (setq gnus-faq-buffer
5412                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5413       (gnus-configure-windows 'summary-faq))))
5414
5415 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5416 (defun gnus-summary-describe-group (&optional force)
5417   "Describe the current newsgroup."
5418   (interactive "P")
5419   (gnus-group-describe-group force gnus-newsgroup-name))
5420
5421 (defun gnus-summary-describe-briefly ()
5422   "Describe summary mode commands briefly."
5423   (interactive)
5424   (gnus-message 6
5425                 (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")))
5426
5427 ;; Walking around group mode buffer from summary mode.
5428
5429 (defun gnus-summary-next-group (&optional no-article target-group backward)
5430   "Exit current newsgroup and then select next unread newsgroup.
5431 If prefix argument NO-ARTICLE is non-nil, no article is selected
5432 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5433 previous group instead."
5434   (interactive "P")
5435   ;; Stop pre-fetching.
5436   (gnus-async-halt-prefetch)
5437   (let ((current-group gnus-newsgroup-name)
5438         (current-buffer (current-buffer))
5439         entered)
5440     ;; First we semi-exit this group to update Xrefs and all variables.
5441     ;; We can't do a real exit, because the window conf must remain
5442     ;; the same in case the user is prompted for info, and we don't
5443     ;; want the window conf to change before that...
5444     (gnus-summary-exit t)
5445     (while (not entered)
5446       ;; Then we find what group we are supposed to enter.
5447       (set-buffer gnus-group-buffer)
5448       (gnus-group-jump-to-group current-group)
5449       (setq target-group
5450             (or target-group
5451                 (if (eq gnus-keep-same-level 'best)
5452                     (gnus-summary-best-group gnus-newsgroup-name)
5453                   (gnus-summary-search-group backward gnus-keep-same-level))))
5454       (if (not target-group)
5455           ;; There are no further groups, so we return to the group
5456           ;; buffer.
5457           (progn
5458             (gnus-message 5 "Returning to the group buffer")
5459             (setq entered t)
5460             (when (gnus-buffer-live-p current-buffer)
5461               (set-buffer current-buffer)
5462               (gnus-summary-exit))
5463             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5464         ;; We try to enter the target group.
5465         (gnus-group-jump-to-group target-group)
5466         (let ((unreads (gnus-group-group-unread)))
5467           (if (and (or (eq t unreads)
5468                        (and unreads (not (zerop unreads))))
5469                    (gnus-summary-read-group
5470                     target-group nil no-article
5471                     (and (buffer-name current-buffer) current-buffer)
5472                     nil backward))
5473               (setq entered t)
5474             (setq current-group target-group
5475                   target-group nil)))))))
5476
5477 (defun gnus-summary-prev-group (&optional no-article)
5478   "Exit current newsgroup and then select previous unread newsgroup.
5479 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5480   (interactive "P")
5481   (gnus-summary-next-group no-article nil t))
5482
5483 ;; Walking around summary lines.
5484
5485 (defun gnus-summary-first-subject (&optional unread undownloaded)
5486   "Go to the first unread subject.
5487 If UNREAD is non-nil, go to the first unread article.
5488 Returns the article selected or nil if there are no unread articles."
5489   (interactive "P")
5490   (prog1
5491       (cond
5492        ;; Empty summary.
5493        ((null gnus-newsgroup-data)
5494         (gnus-message 3 "No articles in the group")
5495         nil)
5496        ;; Pick the first article.
5497        ((not unread)
5498         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5499         (gnus-data-number (car gnus-newsgroup-data)))
5500        ;; No unread articles.
5501        ((null gnus-newsgroup-unreads)
5502         (gnus-message 3 "No more unread articles")
5503         nil)
5504        ;; Find the first unread article.
5505        (t
5506         (let ((data gnus-newsgroup-data))
5507           (while (and data
5508                       (and (not (and undownloaded
5509                                      (eq gnus-undownloaded-mark
5510                                          (gnus-data-mark (car data)))))
5511                            (not (gnus-data-unread-p (car data)))))
5512             (setq data (cdr data)))
5513           (when data
5514             (goto-char (gnus-data-pos (car data)))
5515             (gnus-data-number (car data))))))
5516     (gnus-summary-position-point)))
5517
5518 (defun gnus-summary-next-subject (n &optional unread dont-display)
5519   "Go to next N'th summary line.
5520 If N is negative, go to the previous N'th subject line.
5521 If UNREAD is non-nil, only unread articles are selected.
5522 The difference between N and the actual number of steps taken is
5523 returned."
5524   (interactive "p")
5525   (let ((backward (< n 0))
5526         (n (abs n)))
5527     (while (and (> n 0)
5528                 (if backward
5529                     (gnus-summary-find-prev unread)
5530                   (gnus-summary-find-next unread)))
5531       (gnus-summary-show-thread)
5532       (setq n (1- n)))
5533     (when (/= 0 n)
5534       (gnus-message 7 "No more%s articles"
5535                     (if unread " unread" "")))
5536     (unless dont-display
5537       (gnus-summary-recenter)
5538       (gnus-summary-position-point))
5539     n))
5540
5541 (defun gnus-summary-next-unread-subject (n)
5542   "Go to next N'th unread summary line."
5543   (interactive "p")
5544   (gnus-summary-next-subject n t))
5545
5546 (defun gnus-summary-prev-subject (n &optional unread)
5547   "Go to previous N'th summary line.
5548 If optional argument UNREAD is non-nil, only unread article is selected."
5549   (interactive "p")
5550   (gnus-summary-next-subject (- n) unread))
5551
5552 (defun gnus-summary-prev-unread-subject (n)
5553   "Go to previous N'th unread summary line."
5554   (interactive "p")
5555   (gnus-summary-next-subject (- n) t))
5556
5557 (defun gnus-summary-goto-subject (article &optional force silent)
5558   "Go the subject line of ARTICLE.
5559 If FORCE, also allow jumping to articles not currently shown."
5560   (interactive "nArticle number: ")
5561   (let ((b (point))
5562         (data (gnus-data-find article)))
5563     ;; We read in the article if we have to.
5564     (and (not data)
5565          force
5566          (gnus-summary-insert-subject
5567           article
5568           (if (or (numberp force) (vectorp force)) force)
5569           t)
5570          (setq data (gnus-data-find article)))
5571     (goto-char b)
5572     (if (not data)
5573         (progn
5574           (unless silent
5575             (gnus-message 3 "Can't find article %d" article))
5576           nil)
5577       (goto-char (gnus-data-pos data))
5578       (gnus-summary-position-point)
5579       article)))
5580
5581 ;; Walking around summary lines with displaying articles.
5582
5583 (defun gnus-summary-expand-window (&optional arg)
5584   "Make the summary buffer take up the entire Emacs frame.
5585 Given a prefix, will force an `article' buffer configuration."
5586   (interactive "P")
5587   (if arg
5588       (gnus-configure-windows 'article 'force)
5589     (gnus-configure-windows 'summary 'force)))
5590
5591 (defun gnus-summary-display-article (article &optional all-header)
5592   "Display ARTICLE in article buffer."
5593   (gnus-set-global-variables)
5594   (if (null article)
5595       nil
5596     (prog1
5597         (if gnus-summary-display-article-function
5598             (funcall gnus-summary-display-article-function article all-header)
5599           (gnus-article-prepare article all-header))
5600       (gnus-run-hooks 'gnus-select-article-hook)
5601       (when (and gnus-current-article
5602                  (not (zerop gnus-current-article)))
5603         (gnus-summary-goto-subject gnus-current-article))
5604       (gnus-summary-recenter)
5605       (when (and gnus-use-trees gnus-show-threads)
5606         (gnus-possibly-generate-tree article)
5607         (gnus-highlight-selected-tree article))
5608       ;; Successfully display article.
5609       (gnus-article-set-window-start
5610        (cdr (assq article gnus-newsgroup-bookmarks))))))
5611
5612 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5613   "Select the current article.
5614 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5615 non-nil, the article will be re-fetched even if it already present in
5616 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5617 be displayed."
5618   ;; Make sure we are in the summary buffer to work around bbdb bug.
5619   (unless (eq major-mode 'gnus-summary-mode)
5620     (set-buffer gnus-summary-buffer))
5621   (let ((article (or article (gnus-summary-article-number)))
5622         (all-headers (not (not all-headers))) ;Must be T or NIL.
5623         gnus-summary-display-article-function
5624         did)
5625     (and (not pseudo)
5626          (gnus-summary-article-pseudo-p article)
5627          (error "This is a pseudo-article"))
5628     (prog1
5629         (save-excursion
5630           (set-buffer gnus-summary-buffer)
5631           (if (or (and gnus-single-article-buffer
5632                        (or (null gnus-current-article)
5633                            (null gnus-article-current)
5634                            (null (get-buffer gnus-article-buffer))
5635                            (not (eq article (cdr gnus-article-current)))
5636                            (not (equal (car gnus-article-current)
5637                                        gnus-newsgroup-name))))
5638                   (and (not gnus-single-article-buffer)
5639                        (or (null gnus-current-article)
5640                            (not (eq gnus-current-article article))))
5641                   force)
5642               ;; The requested article is different from the current article.
5643               (prog1
5644                   (gnus-summary-display-article article all-headers)
5645                 (setq did article))
5646             (when (or all-headers gnus-show-all-headers)
5647               (gnus-article-show-all-headers))
5648             'old))
5649       (when did
5650         (gnus-article-set-window-start
5651          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5652
5653 (defun gnus-summary-set-current-mark (&optional current-mark)
5654   "Obsolete function."
5655   nil)
5656
5657 (defun gnus-summary-next-article (&optional unread subject backward push)
5658   "Select the next article.
5659 If UNREAD, only unread articles are selected.
5660 If SUBJECT, only articles with SUBJECT are selected.
5661 If BACKWARD, the previous article is selected instead of the next."
5662   (interactive "P")
5663   (cond
5664    ;; Is there such an article?
5665    ((and (gnus-summary-search-forward unread subject backward)
5666          (or (gnus-summary-display-article (gnus-summary-article-number))
5667              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5668     (gnus-summary-position-point))
5669    ;; If not, we try the first unread, if that is wanted.
5670    ((and subject
5671          gnus-auto-select-same
5672          (gnus-summary-first-unread-article))
5673     (gnus-summary-position-point)
5674     (gnus-message 6 "Wrapped"))
5675    ;; Try to get next/previous article not displayed in this group.
5676    ((and gnus-auto-extend-newsgroup
5677          (not unread) (not subject))
5678     (gnus-summary-goto-article
5679      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5680      nil (count-lines (point-min) (point))))
5681    ;; Go to next/previous group.
5682    (t
5683     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5684       (gnus-summary-jump-to-group gnus-newsgroup-name))
5685     (let ((cmd last-command-char)
5686           (point
5687            (save-excursion
5688              (set-buffer gnus-group-buffer)
5689              (point)))
5690           (group
5691            (if (eq gnus-keep-same-level 'best)
5692                (gnus-summary-best-group gnus-newsgroup-name)
5693              (gnus-summary-search-group backward gnus-keep-same-level))))
5694       ;; For some reason, the group window gets selected.  We change
5695       ;; it back.
5696       (select-window (get-buffer-window (current-buffer)))
5697       ;; Select next unread newsgroup automagically.
5698       (cond
5699        ((or (not gnus-auto-select-next)
5700             (not cmd))
5701         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5702        ((or (eq gnus-auto-select-next 'quietly)
5703             (and (eq gnus-auto-select-next 'slightly-quietly)
5704                  push)
5705             (and (eq gnus-auto-select-next 'almost-quietly)
5706                  (gnus-summary-last-article-p)))
5707         ;; Select quietly.
5708         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5709             (gnus-summary-exit)
5710           (gnus-message 7 "No more%s articles (%s)..."
5711                         (if unread " unread" "")
5712                         (if group (concat "selecting " group)
5713                           "exiting"))
5714           (gnus-summary-next-group nil group backward)))
5715        (t
5716         (when (gnus-key-press-event-p last-input-event)
5717           (gnus-summary-walk-group-buffer
5718            gnus-newsgroup-name cmd unread backward point))))))))
5719
5720 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5721   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5722                       (?\C-p (gnus-group-prev-unread-group 1))))
5723         (cursor-in-echo-area t)
5724         keve key group ended)
5725     (save-excursion
5726       (set-buffer gnus-group-buffer)
5727       (goto-char start)
5728       (setq group
5729             (if (eq gnus-keep-same-level 'best)
5730                 (gnus-summary-best-group gnus-newsgroup-name)
5731               (gnus-summary-search-group backward gnus-keep-same-level))))
5732     (while (not ended)
5733       (gnus-message
5734        5 "No more%s articles%s" (if unread " unread" "")
5735        (if (and group
5736                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5737            (format " (Type %s for %s [%s])"
5738                    (single-key-description cmd) group
5739                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5740          (format " (Type %s to exit %s)"
5741                  (single-key-description cmd)
5742                  gnus-newsgroup-name)))
5743       ;; Confirm auto selection.
5744       (setq key (car (setq keve (gnus-read-event-char))))
5745       (setq ended t)
5746       (cond
5747        ((assq key keystrokes)
5748         (let ((obuf (current-buffer)))
5749           (switch-to-buffer gnus-group-buffer)
5750           (when group
5751             (gnus-group-jump-to-group group))
5752           (eval (cadr (assq key keystrokes)))
5753           (setq group (gnus-group-group-name))
5754           (switch-to-buffer obuf))
5755         (setq ended nil))
5756        ((equal key cmd)
5757         (if (or (not group)
5758                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5759             (gnus-summary-exit)
5760           (gnus-summary-next-group nil group backward)))
5761        (t
5762         (push (cdr keve) unread-command-events))))))
5763
5764 (defun gnus-summary-next-unread-article ()
5765   "Select unread article after current one."
5766   (interactive)
5767   (gnus-summary-next-article
5768    (or (not (eq gnus-summary-goto-unread 'never))
5769        (gnus-summary-last-article-p (gnus-summary-article-number)))
5770    (and gnus-auto-select-same
5771         (gnus-summary-article-subject))))
5772
5773 (defun gnus-summary-prev-article (&optional unread subject)
5774   "Select the article after the current one.
5775 If UNREAD is non-nil, only unread articles are selected."
5776   (interactive "P")
5777   (gnus-summary-next-article unread subject t))
5778
5779 (defun gnus-summary-prev-unread-article ()
5780   "Select unread article before current one."
5781   (interactive)
5782   (gnus-summary-prev-article
5783    (or (not (eq gnus-summary-goto-unread 'never))
5784        (gnus-summary-first-article-p (gnus-summary-article-number)))
5785    (and gnus-auto-select-same
5786         (gnus-summary-article-subject))))
5787
5788 (defun gnus-summary-next-page (&optional lines circular)
5789   "Show next page of the selected article.
5790 If at the end of the current article, select the next article.
5791 LINES says how many lines should be scrolled up.
5792
5793 If CIRCULAR is non-nil, go to the start of the article instead of
5794 selecting the next article when reaching the end of the current
5795 article."
5796   (interactive "P")
5797   (setq gnus-summary-buffer (current-buffer))
5798   (gnus-set-global-variables)
5799   (let ((article (gnus-summary-article-number))
5800         (article-window (get-buffer-window gnus-article-buffer t))
5801         endp)
5802     ;; If the buffer is empty, we have no article.
5803     (unless article
5804       (error "No article to select"))
5805     (gnus-configure-windows 'article)
5806     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5807         (if (and (eq gnus-summary-goto-unread 'never)
5808                  (not (gnus-summary-last-article-p article)))
5809             (gnus-summary-next-article)
5810           (gnus-summary-next-unread-article))
5811       (if (or (null gnus-current-article)
5812               (null gnus-article-current)
5813               (/= article (cdr gnus-article-current))
5814               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5815           ;; Selected subject is different from current article's.
5816           (gnus-summary-display-article article)
5817         (when article-window
5818           (gnus-eval-in-buffer-window gnus-article-buffer
5819             (setq endp (gnus-article-next-page lines)))
5820           (when endp
5821             (cond (circular
5822                    (gnus-summary-beginning-of-article))
5823                   (lines
5824                    (gnus-message 3 "End of message"))
5825                   ((null lines)
5826                    (if (and (eq gnus-summary-goto-unread 'never)
5827                             (not (gnus-summary-last-article-p article)))
5828                        (gnus-summary-next-article)
5829                      (gnus-summary-next-unread-article))))))))
5830     (gnus-summary-recenter)
5831     (gnus-summary-position-point)))
5832
5833 (defun gnus-summary-prev-page (&optional lines move)
5834   "Show previous page of selected article.
5835 Argument LINES specifies lines to be scrolled down.
5836 If MOVE, move to the previous unread article if point is at
5837 the beginning of the buffer."
5838   (interactive "P")
5839   (let ((article (gnus-summary-article-number))
5840         (article-window (get-buffer-window gnus-article-buffer t))
5841         endp)
5842     (gnus-configure-windows 'article)
5843     (if (or (null gnus-current-article)
5844             (null gnus-article-current)
5845             (/= article (cdr gnus-article-current))
5846             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5847         ;; Selected subject is different from current article's.
5848         (gnus-summary-display-article article)
5849       (gnus-summary-recenter)
5850       (when article-window
5851         (gnus-eval-in-buffer-window gnus-article-buffer
5852           (setq endp (gnus-article-prev-page lines)))
5853         (when (and move endp)
5854           (cond (lines
5855                  (gnus-message 3 "Beginning of message"))
5856                 ((null lines)
5857                  (if (and (eq gnus-summary-goto-unread 'never)
5858                           (not (gnus-summary-first-article-p article)))
5859                      (gnus-summary-prev-article)
5860                    (gnus-summary-prev-unread-article))))))))
5861   (gnus-summary-position-point))
5862
5863 (defun gnus-summary-prev-page-or-article (&optional lines)
5864   "Show previous page of selected article.
5865 Argument LINES specifies lines to be scrolled down.
5866 If at the beginning of the article, go to the next article."
5867   (interactive "P")
5868   (gnus-summary-prev-page lines t))
5869
5870 (defun gnus-summary-scroll-up (lines)
5871   "Scroll up (or down) one line current article.
5872 Argument LINES specifies lines to be scrolled up (or down if negative)."
5873   (interactive "p")
5874   (gnus-configure-windows 'article)
5875   (gnus-summary-show-thread)
5876   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
5877     (gnus-eval-in-buffer-window gnus-article-buffer
5878       (cond ((> lines 0)
5879              (when (gnus-article-next-page lines)
5880                (gnus-message 3 "End of message")))
5881             ((< lines 0)
5882              (gnus-article-prev-page (- lines))))))
5883   (gnus-summary-recenter)
5884   (gnus-summary-position-point))
5885
5886 (defun gnus-summary-scroll-down (lines)
5887   "Scroll down (or up) one line current article.
5888 Argument LINES specifies lines to be scrolled down (or up if negative)."
5889   (interactive "p")
5890   (gnus-summary-scroll-up (- lines)))
5891
5892 (defun gnus-summary-next-same-subject ()
5893   "Select next article which has the same subject as current one."
5894   (interactive)
5895   (gnus-summary-next-article nil (gnus-summary-article-subject)))
5896
5897 (defun gnus-summary-prev-same-subject ()
5898   "Select previous article which has the same subject as current one."
5899   (interactive)
5900   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
5901
5902 (defun gnus-summary-next-unread-same-subject ()
5903   "Select next unread article which has the same subject as current one."
5904   (interactive)
5905   (gnus-summary-next-article t (gnus-summary-article-subject)))
5906
5907 (defun gnus-summary-prev-unread-same-subject ()
5908   "Select previous unread article which has the same subject as current one."
5909   (interactive)
5910   (gnus-summary-prev-article t (gnus-summary-article-subject)))
5911
5912 (defun gnus-summary-first-unread-article ()
5913   "Select the first unread article.
5914 Return nil if there are no unread articles."
5915   (interactive)
5916   (prog1
5917       (when (gnus-summary-first-subject t)
5918         (gnus-summary-show-thread)
5919         (gnus-summary-first-subject t)
5920         (gnus-summary-display-article (gnus-summary-article-number)))
5921     (gnus-summary-position-point)))
5922
5923 (defun gnus-summary-first-unread-subject ()
5924   "Place the point on the subject line of the first unread article.
5925 Return nil if there are no unread articles."
5926   (interactive)
5927   (prog1
5928       (when (gnus-summary-first-subject t)
5929         (gnus-summary-show-thread)
5930         (gnus-summary-first-subject t))
5931     (gnus-summary-position-point)))
5932
5933 (defun gnus-summary-first-article ()
5934   "Select the first article.
5935 Return nil if there are no articles."
5936   (interactive)
5937   (prog1
5938       (when (gnus-summary-first-subject)
5939         (gnus-summary-show-thread)
5940         (gnus-summary-first-subject)
5941         (gnus-summary-display-article (gnus-summary-article-number)))
5942     (gnus-summary-position-point)))
5943
5944 (defun gnus-summary-best-unread-article ()
5945   "Select the unread article with the highest score."
5946   (interactive)
5947   (let ((best -1000000)
5948         (data gnus-newsgroup-data)
5949         article score)
5950     (while data
5951       (and (gnus-data-unread-p (car data))
5952            (> (setq score
5953                     (gnus-summary-article-score (gnus-data-number (car data))))
5954               best)
5955            (setq best score
5956                  article (gnus-data-number (car data))))
5957       (setq data (cdr data)))
5958     (prog1
5959         (if article
5960             (gnus-summary-goto-article article)
5961           (error "No unread articles"))
5962       (gnus-summary-position-point))))
5963
5964 (defun gnus-summary-last-subject ()
5965   "Go to the last displayed subject line in the group."
5966   (let ((article (gnus-data-number (car (gnus-data-list t)))))
5967     (when article
5968       (gnus-summary-goto-subject article))))
5969
5970 (defun gnus-summary-goto-article (article &optional all-headers force)
5971   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
5972 If ALL-HEADERS is non-nil, no header lines are hidden.
5973 If FORCE, go to the article even if it isn't displayed.  If FORCE
5974 is a number, it is the line the article is to be displayed on."
5975   (interactive
5976    (list
5977     (completing-read
5978      "Article number or Message-ID: "
5979      (mapcar (lambda (number) (list (int-to-string number)))
5980              gnus-newsgroup-limit))
5981     current-prefix-arg
5982     t))
5983   (prog1
5984       (if (and (stringp article)
5985                (string-match "@" article))
5986           (gnus-summary-refer-article article)
5987         (when (stringp article)
5988           (setq article (string-to-number article)))
5989         (if (gnus-summary-goto-subject article force)
5990             (gnus-summary-display-article article all-headers)
5991           (gnus-message 4 "Couldn't go to article %s" article) nil))
5992     (gnus-summary-position-point)))
5993
5994 (defun gnus-summary-goto-last-article ()
5995   "Go to the previously read article."
5996   (interactive)
5997   (prog1
5998       (when gnus-last-article
5999         (gnus-summary-goto-article gnus-last-article nil t))
6000     (gnus-summary-position-point)))
6001
6002 (defun gnus-summary-pop-article (number)
6003   "Pop one article off the history and go to the previous.
6004 NUMBER articles will be popped off."
6005   (interactive "p")
6006   (let (to)
6007     (setq gnus-newsgroup-history
6008           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6009     (if to
6010         (gnus-summary-goto-article (car to) nil t)
6011       (error "Article history empty")))
6012   (gnus-summary-position-point))
6013
6014 ;; Summary commands and functions for limiting the summary buffer.
6015
6016 (defun gnus-summary-limit-to-articles (n)
6017   "Limit the summary buffer to the next N articles.
6018 If not given a prefix, use the process marked articles instead."
6019   (interactive "P")
6020   (prog1
6021       (let ((articles (gnus-summary-work-articles n)))
6022         (setq gnus-newsgroup-processable nil)
6023         (gnus-summary-limit articles))
6024     (gnus-summary-position-point)))
6025
6026 (defun gnus-summary-pop-limit (&optional total)
6027   "Restore the previous limit.
6028 If given a prefix, remove all limits."
6029   (interactive "P")
6030   (when total
6031     (setq gnus-newsgroup-limits
6032           (list (mapcar (lambda (h) (mail-header-number h))
6033                         gnus-newsgroup-headers))))
6034   (unless gnus-newsgroup-limits
6035     (error "No limit to pop"))
6036   (prog1
6037       (gnus-summary-limit nil 'pop)
6038     (gnus-summary-position-point)))
6039
6040 (defun gnus-summary-limit-to-subject (subject &optional header)
6041   "Limit the summary buffer to articles that have subjects that match a regexp."
6042   (interactive "sLimit to subject (regexp): ")
6043   (unless header
6044     (setq header "subject"))
6045   (when (not (equal "" subject))
6046     (prog1
6047         (let ((articles (gnus-summary-find-matching
6048                          (or header "subject") subject 'all)))
6049           (unless articles
6050             (error "Found no matches for \"%s\"" subject))
6051           (gnus-summary-limit articles))
6052       (gnus-summary-position-point))))
6053
6054 (defun gnus-summary-limit-to-author (from)
6055   "Limit the summary buffer to articles that have authors that match a regexp."
6056   (interactive "sLimit to author (regexp): ")
6057   (gnus-summary-limit-to-subject from "from"))
6058
6059 (defun gnus-summary-limit-to-age (age &optional younger-p)
6060   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6061 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6062 articles that are younger than AGE days."
6063   (interactive "nTime in days: \nP")
6064   (prog1
6065       (let ((data gnus-newsgroup-data)
6066             (cutoff (days-to-time age))
6067             articles d date is-younger)
6068         (while (setq d (pop data))
6069           (when (and (vectorp (gnus-data-header d))
6070                      (setq date (mail-header-date (gnus-data-header d))))
6071             (setq is-younger (time-less-p
6072                               (time-since (date-to-time date))
6073                               cutoff))
6074             (when (if younger-p
6075                       is-younger
6076                     (not is-younger))
6077               (push (gnus-data-number d) articles))))
6078         (gnus-summary-limit (nreverse articles)))
6079     (gnus-summary-position-point)))
6080
6081 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6082 (make-obsolete
6083  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6084
6085 (defun gnus-summary-limit-to-unread (&optional all)
6086   "Limit the summary buffer to articles that are not marked as read.
6087 If ALL is non-nil, limit strictly to unread articles."
6088   (interactive "P")
6089   (if all
6090       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6091     (gnus-summary-limit-to-marks
6092      ;; Concat all the marks that say that an article is read and have
6093      ;; those removed.
6094      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6095            gnus-killed-mark gnus-kill-file-mark
6096            gnus-low-score-mark gnus-expirable-mark
6097            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6098            gnus-duplicate-mark gnus-souped-mark)
6099      'reverse)))
6100
6101 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6102 (make-obsolete 'gnus-summary-delete-marked-with
6103                'gnus-summary-limit-exlude-marks)
6104
6105 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6106   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6107 If REVERSE, limit the summary buffer to articles that are marked
6108 with MARKS.  MARKS can either be a string of marks or a list of marks.
6109 Returns how many articles were removed."
6110   (interactive "sMarks: ")
6111   (gnus-summary-limit-to-marks marks t))
6112
6113 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6114   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6115 If REVERSE (the prefix), limit the summary buffer to articles that are
6116 not marked with MARKS.  MARKS can either be a string of marks or a
6117 list of marks.
6118 Returns how many articles were removed."
6119   (interactive "sMarks: \nP")
6120   (prog1
6121       (let ((data gnus-newsgroup-data)
6122             (marks (if (listp marks) marks
6123                      (append marks nil))) ; Transform to list.
6124             articles)
6125         (while data
6126           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6127                   (memq (gnus-data-mark (car data)) marks))
6128             (push (gnus-data-number (car data)) articles))
6129           (setq data (cdr data)))
6130         (gnus-summary-limit articles))
6131     (gnus-summary-position-point)))
6132
6133 (defun gnus-summary-limit-to-score (&optional score)
6134   "Limit to articles with score at or above SCORE."
6135   (interactive "P")
6136   (setq score (if score
6137                   (prefix-numeric-value score)
6138                 (or gnus-summary-default-score 0)))
6139   (let ((data gnus-newsgroup-data)
6140         articles)
6141     (while data
6142       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6143                 score)
6144         (push (gnus-data-number (car data)) articles))
6145       (setq data (cdr data)))
6146     (prog1
6147         (gnus-summary-limit articles)
6148       (gnus-summary-position-point))))
6149
6150 (defun gnus-summary-limit-include-thread (id)
6151   "Display all the hidden articles that in the current thread."
6152   (interactive (list (mail-header-id (gnus-summary-article-header))))
6153   (let ((articles (gnus-articles-in-thread
6154                    (gnus-id-to-thread (gnus-root-id id)))))
6155     (prog1
6156         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6157       (gnus-summary-position-point))))
6158
6159 (defun gnus-summary-limit-include-dormant ()
6160   "Display all the hidden articles that are marked as dormant.
6161 Note that this command only works on a subset of the articles currently
6162 fetched for this group."
6163   (interactive)
6164   (unless gnus-newsgroup-dormant
6165     (error "There are no dormant articles in this group"))
6166   (prog1
6167       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6168     (gnus-summary-position-point)))
6169
6170 (defun gnus-summary-limit-exclude-dormant ()
6171   "Hide all dormant articles."
6172   (interactive)
6173   (prog1
6174       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6175     (gnus-summary-position-point)))
6176
6177 (defun gnus-summary-limit-exclude-childless-dormant ()
6178   "Hide all dormant articles that have no children."
6179   (interactive)
6180   (let ((data (gnus-data-list t))
6181         articles d children)
6182     ;; Find all articles that are either not dormant or have
6183     ;; children.
6184     (while (setq d (pop data))
6185       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6186                 (and (setq children
6187                            (gnus-article-children (gnus-data-number d)))
6188                      (let (found)
6189                        (while children
6190                          (when (memq (car children) articles)
6191                            (setq children nil
6192                                  found t))
6193                          (pop children))
6194                        found)))
6195         (push (gnus-data-number d) articles)))
6196     ;; Do the limiting.
6197     (prog1
6198         (gnus-summary-limit articles)
6199       (gnus-summary-position-point))))
6200
6201 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6202   "Mark all unread excluded articles as read.
6203 If ALL, mark even excluded ticked and dormants as read."
6204   (interactive "P")
6205   (let ((articles (gnus-sorted-complement
6206                    (sort
6207                     (mapcar (lambda (h) (mail-header-number h))
6208                             gnus-newsgroup-headers)
6209                     '<)
6210                    (sort gnus-newsgroup-limit '<)))
6211         article)
6212     (setq gnus-newsgroup-unreads
6213           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6214     (if all
6215         (setq gnus-newsgroup-dormant nil
6216               gnus-newsgroup-marked nil
6217               gnus-newsgroup-reads
6218               (nconc
6219                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6220                gnus-newsgroup-reads))
6221       (while (setq article (pop articles))
6222         (unless (or (memq article gnus-newsgroup-dormant)
6223                     (memq article gnus-newsgroup-marked))
6224           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6225
6226 (defun gnus-summary-limit (articles &optional pop)
6227   (if pop
6228       ;; We pop the previous limit off the stack and use that.
6229       (setq articles (car gnus-newsgroup-limits)
6230             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6231     ;; We use the new limit, so we push the old limit on the stack.
6232     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6233   ;; Set the limit.
6234   (setq gnus-newsgroup-limit articles)
6235   (let ((total (length gnus-newsgroup-data))
6236         (data (gnus-data-find-list (gnus-summary-article-number)))
6237         (gnus-summary-mark-below nil)   ; Inhibit this.
6238         found)
6239     ;; This will do all the work of generating the new summary buffer
6240     ;; according to the new limit.
6241     (gnus-summary-prepare)
6242     ;; Hide any threads, possibly.
6243     (and gnus-show-threads
6244          gnus-thread-hide-subtree
6245          (gnus-summary-hide-all-threads))
6246     ;; Try to return to the article you were at, or one in the
6247     ;; neighborhood.
6248     (when data
6249       ;; We try to find some article after the current one.
6250       (while data
6251         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6252           (setq data nil
6253                 found t))
6254         (setq data (cdr data))))
6255     (unless found
6256       ;; If there is no data, that means that we were after the last
6257       ;; article.  The same goes when we can't find any articles
6258       ;; after the current one.
6259       (goto-char (point-max))
6260       (gnus-summary-find-prev))
6261     (gnus-set-mode-line 'summary)
6262     ;; We return how many articles were removed from the summary
6263     ;; buffer as a result of the new limit.
6264     (- total (length gnus-newsgroup-data))))
6265
6266 (defsubst gnus-invisible-cut-children (threads)
6267   (let ((num 0))
6268     (while threads
6269       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6270         (incf num))
6271       (pop threads))
6272     (< num 2)))
6273
6274 (defsubst gnus-cut-thread (thread)
6275   "Go forwards in the thread until we find an article that we want to display."
6276   (when (or (eq gnus-fetch-old-headers 'some)
6277             (eq gnus-fetch-old-headers 'invisible)
6278             (eq gnus-build-sparse-threads 'some)
6279             (eq gnus-build-sparse-threads 'more))
6280     ;; Deal with old-fetched headers and sparse threads.
6281     (while (and
6282             thread
6283             (or
6284              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6285              (gnus-summary-article-ancient-p
6286               (mail-header-number (car thread))))
6287             (if (or (<= (length (cdr thread)) 1)
6288                     (eq gnus-fetch-old-headers 'invisible))
6289                 (setq gnus-newsgroup-limit
6290                       (delq (mail-header-number (car thread))
6291                             gnus-newsgroup-limit)
6292                       thread (cadr thread))
6293               (when (gnus-invisible-cut-children (cdr thread))
6294                 (let ((th (cdr thread)))
6295                   (while th
6296                     (if (memq (mail-header-number (caar th))
6297                               gnus-newsgroup-limit)
6298                         (setq thread (car th)
6299                               th nil)
6300                       (setq th (cdr th))))))))))
6301   thread)
6302
6303 (defun gnus-cut-threads (threads)
6304   "Cut off all uninteresting articles from the beginning of threads."
6305   (when (or (eq gnus-fetch-old-headers 'some)
6306             (eq gnus-fetch-old-headers 'invisible)
6307             (eq gnus-build-sparse-threads 'some)
6308             (eq gnus-build-sparse-threads 'more))
6309     (let ((th threads))
6310       (while th
6311         (setcar th (gnus-cut-thread (car th)))
6312         (setq th (cdr th)))))
6313   ;; Remove nixed out threads.
6314   (delq nil threads))
6315
6316 (defun gnus-summary-initial-limit (&optional show-if-empty)
6317   "Figure out what the initial limit is supposed to be on group entry.
6318 This entails weeding out unwanted dormants, low-scored articles,
6319 fetch-old-headers verbiage, and so on."
6320   ;; Most groups have nothing to remove.
6321   (if (or gnus-inhibit-limiting
6322           (and (null gnus-newsgroup-dormant)
6323                (not (eq gnus-fetch-old-headers 'some))
6324                (not (eq gnus-fetch-old-headers 'invisible))
6325                (null gnus-summary-expunge-below)
6326                (not (eq gnus-build-sparse-threads 'some))
6327                (not (eq gnus-build-sparse-threads 'more))
6328                (null gnus-thread-expunge-below)
6329                (not gnus-use-nocem)))
6330       ()                                ; Do nothing.
6331     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6332     (setq gnus-newsgroup-limit nil)
6333     (mapatoms
6334      (lambda (node)
6335        (unless (car (symbol-value node))
6336          ;; These threads have no parents -- they are roots.
6337          (let ((nodes (cdr (symbol-value node)))
6338                thread)
6339            (while nodes
6340              (if (and gnus-thread-expunge-below
6341                       (< (gnus-thread-total-score (car nodes))
6342                          gnus-thread-expunge-below))
6343                  (gnus-expunge-thread (pop nodes))
6344                (setq thread (pop nodes))
6345                (gnus-summary-limit-children thread))))))
6346      gnus-newsgroup-dependencies)
6347     ;; If this limitation resulted in an empty group, we might
6348     ;; pop the previous limit and use it instead.
6349     (when (and (not gnus-newsgroup-limit)
6350                show-if-empty)
6351       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6352     gnus-newsgroup-limit))
6353
6354 (defun gnus-summary-limit-children (thread)
6355   "Return 1 if this subthread is visible and 0 if it is not."
6356   ;; First we get the number of visible children to this thread.  This
6357   ;; is done by recursing down the thread using this function, so this
6358   ;; will really go down to a leaf article first, before slowly
6359   ;; working its way up towards the root.
6360   (when thread
6361     (let ((children
6362            (if (cdr thread)
6363                (apply '+ (mapcar 'gnus-summary-limit-children
6364                                  (cdr thread)))
6365              0))
6366           (number (mail-header-number (car thread)))
6367           score)
6368       (if (and
6369            (not (memq number gnus-newsgroup-marked))
6370            (or
6371             ;; If this article is dormant and has absolutely no visible
6372             ;; children, then this article isn't visible.
6373             (and (memq number gnus-newsgroup-dormant)
6374                  (zerop children))
6375             ;; If this is "fetch-old-headered" and there is no
6376             ;; visible children, then we don't want this article.
6377             (and (eq gnus-fetch-old-headers 'some)
6378                  (gnus-summary-article-ancient-p number)
6379                  (zerop children))
6380             ;; If this is "fetch-old-headered" and `invisible', then
6381             ;; we don't want this article.
6382             (and (eq gnus-fetch-old-headers 'invisible)
6383                  (gnus-summary-article-ancient-p number))
6384             ;; If this is a sparsely inserted article with no children,
6385             ;; we don't want it.
6386             (and (eq gnus-build-sparse-threads 'some)
6387                  (gnus-summary-article-sparse-p number)
6388                  (zerop children))
6389             ;; If we use expunging, and this article is really
6390             ;; low-scored, then we don't want this article.
6391             (when (and gnus-summary-expunge-below
6392                        (< (setq score
6393                                 (or (cdr (assq number gnus-newsgroup-scored))
6394                                     gnus-summary-default-score))
6395                           gnus-summary-expunge-below))
6396               ;; We increase the expunge-tally here, but that has
6397               ;; nothing to do with the limits, really.
6398               (incf gnus-newsgroup-expunged-tally)
6399               ;; We also mark as read here, if that's wanted.
6400               (when (and gnus-summary-mark-below
6401                          (< score gnus-summary-mark-below))
6402                 (setq gnus-newsgroup-unreads
6403                       (delq number gnus-newsgroup-unreads))
6404                 (if gnus-newsgroup-auto-expire
6405                     (push number gnus-newsgroup-expirable)
6406                   (push (cons number gnus-low-score-mark)
6407                         gnus-newsgroup-reads)))
6408               t)
6409             ;; Check NoCeM things.
6410             (if (and gnus-use-nocem
6411                      (gnus-nocem-unwanted-article-p
6412                       (mail-header-id (car thread))))
6413                 (progn
6414                   (setq gnus-newsgroup-unreads
6415                         (delq number gnus-newsgroup-unreads))
6416                   t))))
6417           ;; Nope, invisible article.
6418           0
6419         ;; Ok, this article is to be visible, so we add it to the limit
6420         ;; and return 1.
6421         (push number gnus-newsgroup-limit)
6422         1))))
6423
6424 (defun gnus-expunge-thread (thread)
6425   "Mark all articles in THREAD as read."
6426   (let* ((number (mail-header-number (car thread))))
6427     (incf gnus-newsgroup-expunged-tally)
6428     ;; We also mark as read here, if that's wanted.
6429     (setq gnus-newsgroup-unreads
6430           (delq number gnus-newsgroup-unreads))
6431     (if gnus-newsgroup-auto-expire
6432         (push number gnus-newsgroup-expirable)
6433       (push (cons number gnus-low-score-mark)
6434             gnus-newsgroup-reads)))
6435   ;; Go recursively through all subthreads.
6436   (mapcar 'gnus-expunge-thread (cdr thread)))
6437
6438 ;; Summary article oriented commands
6439
6440 (defun gnus-summary-refer-parent-article (n)
6441   "Refer parent article N times.
6442 If N is negative, go to ancestor -N instead.
6443 The difference between N and the number of articles fetched is returned."
6444   (interactive "p")
6445   (let ((skip 1)
6446         error header ref)
6447     (when (not (natnump n))
6448       (setq skip (abs n)
6449             n 1))
6450     (while (and (> n 0)
6451                 (not error))
6452       (setq header (gnus-summary-article-header))
6453       (if (and (eq (mail-header-number header)
6454                    (cdr gnus-article-current))
6455                (equal gnus-newsgroup-name
6456                       (car gnus-article-current)))
6457           ;; If we try to find the parent of the currently
6458           ;; displayed article, then we take a look at the actual
6459           ;; References header, since this is slightly more
6460           ;; reliable than the References field we got from the
6461           ;; server.
6462           (save-excursion
6463             (set-buffer gnus-original-article-buffer)
6464             (nnheader-narrow-to-headers)
6465             (unless (setq ref (message-fetch-field "references"))
6466               (setq ref (message-fetch-field "in-reply-to")))
6467             (widen))
6468         (setq ref
6469               ;; It's not the current article, so we take a bet on
6470               ;; the value we got from the server.
6471               (mail-header-references header)))
6472       (if (and ref
6473                (not (equal ref "")))
6474           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6475             (gnus-message 1 "Couldn't find parent"))
6476         (gnus-message 1 "No references in article %d"
6477                       (gnus-summary-article-number))
6478         (setq error t))
6479       (decf n))
6480     (gnus-summary-position-point)
6481     n))
6482
6483 (defun gnus-summary-refer-references ()
6484   "Fetch all articles mentioned in the References header.
6485 Return the number of articles fetched."
6486   (interactive)
6487   (let ((ref (mail-header-references (gnus-summary-article-header)))
6488         (current (gnus-summary-article-number))
6489         (n 0))
6490     (if (or (not ref)
6491             (equal ref ""))
6492         (error "No References in the current article")
6493       ;; For each Message-ID in the References header...
6494       (while (string-match "<[^>]*>" ref)
6495         (incf n)
6496         ;; ... fetch that article.
6497         (gnus-summary-refer-article
6498          (prog1 (match-string 0 ref)
6499            (setq ref (substring ref (match-end 0))))))
6500       (gnus-summary-goto-subject current)
6501       (gnus-summary-position-point)
6502       n)))
6503
6504 (defun gnus-summary-refer-thread (&optional limit)
6505   "Fetch all articles in the current thread.
6506 If LIMIT (the numerical prefix), fetch that many old headers instead
6507 of what's specified by the `gnus-refer-thread-limit' variable."
6508   (interactive "P")
6509   (let ((id (mail-header-id (gnus-summary-article-header)))
6510         (limit (if limit (prefix-numeric-value limit)
6511                  gnus-refer-thread-limit)))
6512     ;; We want to fetch LIMIT *old* headers, but we also have to
6513     ;; re-fetch all the headers in the current buffer, because many of
6514     ;; them may be undisplayed.  So we adjust LIMIT.
6515     (when (numberp limit)
6516       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6517     (unless (eq gnus-fetch-old-headers 'invisible)
6518       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6519       ;; Retrieve the headers and read them in.
6520       (if (eq (gnus-retrieve-headers
6521                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6522               'nov)
6523           (gnus-build-all-threads)
6524         (error "Can't fetch thread from backends that don't support NOV"))
6525       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6526     (gnus-summary-limit-include-thread id)))
6527
6528 (defun gnus-summary-refer-article (message-id &optional arg)
6529   "Fetch an article specified by MESSAGE-ID.
6530 If ARG (the prefix), fetch the article using `gnus-refer-article-method'
6531 or `gnus-select-method', no matter what backend the article comes from."
6532   (interactive "sMessage-ID: \nP")
6533   (when (and (stringp message-id)
6534              (not (zerop (length message-id))))
6535     ;; Construct the correct Message-ID if necessary.
6536     ;; Suggested by tale@pawl.rpi.edu.
6537     (unless (string-match "^<" message-id)
6538       (setq message-id (concat "<" message-id)))
6539     (unless (string-match ">$" message-id)
6540       (setq message-id (concat message-id ">")))
6541     (let* ((header (gnus-id-to-header message-id))
6542            (sparse (and header
6543                         (gnus-summary-article-sparse-p
6544                          (mail-header-number header))
6545                         (memq (mail-header-number header)
6546                               gnus-newsgroup-limit))))
6547       (cond
6548        ;; If the article is present in the buffer we just go to it.
6549        ((and header
6550              (or (not (gnus-summary-article-sparse-p
6551                        (mail-header-number header)))
6552                  sparse))
6553         (prog1
6554             (gnus-summary-goto-article
6555              (mail-header-number header) nil t)
6556           (when sparse
6557             (gnus-summary-update-article (mail-header-number header)))))
6558        (t
6559         ;; We fetch the article
6560         (let ((gnus-override-method
6561                (cond ((gnus-news-group-p gnus-newsgroup-name)
6562                       gnus-refer-article-method)
6563                      (arg
6564                       (or gnus-refer-article-method gnus-select-method))
6565                      (t nil)))
6566               number)
6567           ;; Start the special refer-article method, if necessary.
6568           (when (and gnus-refer-article-method
6569                      (gnus-news-group-p gnus-newsgroup-name))
6570             (gnus-check-server gnus-refer-article-method))
6571           ;; Fetch the header, and display the article.
6572           (if (setq number (gnus-summary-insert-subject message-id))
6573               (gnus-summary-select-article nil nil nil number)
6574             (gnus-message 3 "Couldn't fetch article %s" message-id))))))))
6575
6576 (defun gnus-summary-edit-parameters ()
6577   "Edit the group parameters of the current group."
6578   (interactive)
6579   (gnus-group-edit-group gnus-newsgroup-name 'params))
6580
6581 (defun gnus-summary-customize-parameters ()
6582   "Customize the group parameters of the current group."
6583   (interactive)
6584   (gnus-group-customize gnus-newsgroup-name))
6585
6586 (defun gnus-summary-enter-digest-group (&optional force)
6587   "Enter an nndoc group based on the current article.
6588 If FORCE, force a digest interpretation.  If not, try
6589 to guess what the document format is."
6590   (interactive "P")
6591   (let ((conf gnus-current-window-configuration))
6592     (save-excursion
6593       (gnus-summary-select-article))
6594     (setq gnus-current-window-configuration conf)
6595     (let* ((name (format "%s-%d"
6596                          (gnus-group-prefixed-name
6597                           gnus-newsgroup-name (list 'nndoc ""))
6598                          (save-excursion
6599                            (set-buffer gnus-summary-buffer)
6600                            gnus-current-article)))
6601            (ogroup gnus-newsgroup-name)
6602            (params (append (gnus-info-params (gnus-get-info ogroup))
6603                            (list (cons 'to-group ogroup))
6604                            (list (cons 'save-article-group ogroup))))
6605            (case-fold-search t)
6606            (buf (current-buffer))
6607            dig)
6608       (save-excursion
6609         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6610         (insert-buffer-substring gnus-original-article-buffer)
6611         ;; Remove lines that may lead nndoc to misinterpret the
6612         ;; document type.
6613         (narrow-to-region
6614          (goto-char (point-min))
6615          (or (search-forward "\n\n" nil t) (point)))
6616         (goto-char (point-min))
6617         (delete-matching-lines "^\\(Path\\):\\|^From ")
6618         (widen))
6619       (unwind-protect
6620           (if (gnus-group-read-ephemeral-group
6621                name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6622                             (nndoc-article-type
6623                              ,(if force 'digest 'guess))) t)
6624               ;; Make all postings to this group go to the parent group.
6625               (nconc (gnus-info-params (gnus-get-info name))
6626                      params)
6627             ;; Couldn't select this doc group.
6628             (switch-to-buffer buf)
6629             (gnus-set-global-variables)
6630             (gnus-configure-windows 'summary)
6631             (gnus-message 3 "Article couldn't be entered?"))
6632         (kill-buffer dig)))))
6633
6634 (defun gnus-summary-read-document (n)
6635   "Open a new group based on the current article(s).
6636 This will allow you to read digests and other similar
6637 documents as newsgroups.
6638 Obeys the standard process/prefix convention."
6639   (interactive "P")
6640   (let* ((articles (gnus-summary-work-articles n))
6641          (ogroup gnus-newsgroup-name)
6642          (params (append (gnus-info-params (gnus-get-info ogroup))
6643                          (list (cons 'to-group ogroup))))
6644          article group egroup groups vgroup)
6645     (while (setq article (pop articles))
6646       (setq group (format "%s-%d" gnus-newsgroup-name article))
6647       (gnus-summary-remove-process-mark article)
6648       (when (gnus-summary-display-article article)
6649         (save-excursion
6650           (with-temp-buffer
6651             (insert-buffer-substring gnus-original-article-buffer)
6652             ;; Remove some headers that may lead nndoc to make
6653             ;; the wrong guess.
6654             (message-narrow-to-head)
6655             (goto-char (point-min))
6656             (delete-matching-lines "^\\(Path\\):\\|^From ")
6657             (widen)
6658             (if (setq egroup
6659                       (gnus-group-read-ephemeral-group
6660                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6661                                      (nndoc-article-type guess))
6662                        t nil t))
6663                 (progn
6664                   ;; Make all postings to this group go to the parent group.
6665                   (nconc (gnus-info-params (gnus-get-info egroup))
6666                          params)
6667                   (push egroup groups))
6668               ;; Couldn't select this doc group.
6669               (gnus-error 3 "Article couldn't be entered"))))))
6670     ;; Now we have selected all the documents.
6671     (cond
6672      ((not groups)
6673       (error "None of the articles could be interpreted as documents"))
6674      ((gnus-group-read-ephemeral-group
6675        (setq vgroup (format
6676                      "nnvirtual:%s-%s" gnus-newsgroup-name
6677                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6678        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6679        t
6680        (cons (current-buffer) 'summary)))
6681      (t
6682       (error "Couldn't select virtual nndoc group")))))
6683
6684 (defun gnus-summary-isearch-article (&optional regexp-p)
6685   "Do incremental search forward on the current article.
6686 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6687   (interactive "P")
6688   (gnus-summary-select-article)
6689   (gnus-configure-windows 'article)
6690   (gnus-eval-in-buffer-window gnus-article-buffer
6691     (save-restriction
6692       (widen)
6693       (isearch-forward regexp-p))))
6694
6695 (defun gnus-summary-search-article-forward (regexp &optional backward)
6696   "Search for an article containing REGEXP forward.
6697 If BACKWARD, search backward instead."
6698   (interactive
6699    (list (read-string
6700           (format "Search article %s (regexp%s): "
6701                   (if current-prefix-arg "backward" "forward")
6702                   (if gnus-last-search-regexp
6703                       (concat ", default " gnus-last-search-regexp)
6704                     "")))
6705          current-prefix-arg))
6706   (if (string-equal regexp "")
6707       (setq regexp (or gnus-last-search-regexp ""))
6708     (setq gnus-last-search-regexp regexp))
6709   (if (gnus-summary-search-article regexp backward)
6710       (gnus-summary-show-thread)
6711     (error "Search failed: \"%s\"" regexp)))
6712
6713 (defun gnus-summary-search-article-backward (regexp)
6714   "Search for an article containing REGEXP backward."
6715   (interactive
6716    (list (read-string
6717           (format "Search article backward (regexp%s): "
6718                   (if gnus-last-search-regexp
6719                       (concat ", default " gnus-last-search-regexp)
6720                     "")))))
6721   (gnus-summary-search-article-forward regexp 'backward))
6722
6723 (defun gnus-summary-search-article (regexp &optional backward)
6724   "Search for an article containing REGEXP.
6725 Optional argument BACKWARD means do search for backward.
6726 `gnus-select-article-hook' is not called during the search."
6727   ;; We have to require this here to make sure that the following
6728   ;; dynamic binding isn't shadowed by autoloading.
6729   (require 'gnus-async)
6730   (require 'gnus-art)
6731   (let ((gnus-select-article-hook nil)  ;Disable hook.
6732         (gnus-article-display-hook nil)
6733         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
6734         (gnus-use-article-prefetch nil)
6735         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
6736         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
6737         (sum (current-buffer))
6738         (found nil)
6739         point)
6740     (gnus-save-hidden-threads
6741       (gnus-summary-select-article)
6742       (set-buffer gnus-article-buffer)
6743       (when backward
6744         (forward-line -1))
6745       (while (not found)
6746         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
6747         (if (if backward
6748                 (re-search-backward regexp nil t)
6749               (re-search-forward regexp nil t))
6750             ;; We found the regexp.
6751             (progn
6752               (setq found 'found)
6753               (beginning-of-line)
6754               (set-window-start
6755                (get-buffer-window (current-buffer))
6756                (point))
6757               (forward-line 1)
6758               (set-buffer sum)
6759               (setq point (point)))
6760           ;; We didn't find it, so we go to the next article.
6761           (set-buffer sum)
6762           (setq found 'not)
6763           (while (eq found 'not)
6764             (if (not (if backward (gnus-summary-find-prev)
6765                        (gnus-summary-find-next)))
6766                 ;; No more articles.
6767                 (setq found t)
6768               ;; Select the next article and adjust point.
6769               (unless (gnus-summary-article-sparse-p
6770                        (gnus-summary-article-number))
6771                 (setq found nil)
6772                 (gnus-summary-select-article)
6773                 (set-buffer gnus-article-buffer)
6774                 (widen)
6775                 (goto-char (if backward (point-max) (point-min))))))))
6776       (gnus-message 7 ""))
6777     ;; Return whether we found the regexp.
6778     (when (eq found 'found)
6779       (goto-char point)
6780       (gnus-summary-show-thread)
6781       (gnus-summary-goto-subject gnus-current-article)
6782       (gnus-summary-position-point)
6783       t)))
6784
6785 (defun gnus-summary-find-matching (header regexp &optional backward unread
6786                                           not-case-fold)
6787   "Return a list of all articles that match REGEXP on HEADER.
6788 The search stars on the current article and goes forwards unless
6789 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
6790 If UNREAD is non-nil, only unread articles will
6791 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
6792 in the comparisons."
6793   (let ((data (if (eq backward 'all) gnus-newsgroup-data
6794                 (gnus-data-find-list
6795                  (gnus-summary-article-number) (gnus-data-list backward))))
6796         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
6797         (case-fold-search (not not-case-fold))
6798         articles d)
6799     (unless (fboundp (intern (concat "mail-header-" header)))
6800       (error "%s is not a valid header" header))
6801     (while data
6802       (setq d (car data))
6803       (and (or (not unread)             ; We want all articles...
6804                (gnus-data-unread-p d))  ; Or just unreads.
6805            (vectorp (gnus-data-header d)) ; It's not a pseudo.
6806            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
6807            (push (gnus-data-number d) articles)) ; Success!
6808       (setq data (cdr data)))
6809     (nreverse articles)))
6810
6811 (defun gnus-summary-execute-command (header regexp command &optional backward)
6812   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
6813 If HEADER is an empty string (or nil), the match is done on the entire
6814 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
6815   (interactive
6816    (list (let ((completion-ignore-case t))
6817            (completing-read
6818             "Header name: "
6819             (mapcar (lambda (string) (list string))
6820                     '("Number" "Subject" "From" "Lines" "Date"
6821                       "Message-ID" "Xref" "References" "Body"))
6822             nil 'require-match))
6823          (read-string "Regexp: ")
6824          (read-key-sequence "Command: ")
6825          current-prefix-arg))
6826   (when (equal header "Body")
6827     (setq header ""))
6828   ;; Hidden thread subtrees must be searched as well.
6829   (gnus-summary-show-all-threads)
6830   ;; We don't want to change current point nor window configuration.
6831   (save-excursion
6832     (save-window-excursion
6833       (gnus-message 6 "Executing %s..." (key-description command))
6834       ;; We'd like to execute COMMAND interactively so as to give arguments.
6835       (gnus-execute header regexp
6836                     `(call-interactively ',(key-binding command))
6837                     backward)
6838       (gnus-message 6 "Executing %s...done" (key-description command)))))
6839
6840 (defun gnus-summary-beginning-of-article ()
6841   "Scroll the article back to the beginning."
6842   (interactive)
6843   (gnus-summary-select-article)
6844   (gnus-configure-windows 'article)
6845   (gnus-eval-in-buffer-window gnus-article-buffer
6846     (widen)
6847     (goto-char (point-min))
6848     (when gnus-page-broken
6849       (gnus-narrow-to-page))))
6850
6851 (defun gnus-summary-end-of-article ()
6852   "Scroll to the end of the article."
6853   (interactive)
6854   (gnus-summary-select-article)
6855   (gnus-configure-windows 'article)
6856   (gnus-eval-in-buffer-window gnus-article-buffer
6857     (widen)
6858     (goto-char (point-max))
6859     (recenter -3)
6860     (when gnus-page-broken
6861       (gnus-narrow-to-page))))
6862
6863 (defun gnus-summary-print-article (&optional filename n)
6864   "Generate and print a PostScript image of the N next (mail) articles.
6865
6866 If N is negative, print the N previous articles.  If N is nil and articles
6867 have been marked with the process mark, print these instead.
6868
6869 If the optional second argument FILENAME is nil, send the image to the
6870 printer.  If FILENAME is a string, save the PostScript image in a file with
6871 that name.  If FILENAME is a number, prompt the user for the name of the file
6872 to save in."
6873   (interactive (list (ps-print-preprint current-prefix-arg)
6874                      current-prefix-arg))
6875   (dolist (article (gnus-summary-work-articles n))
6876     (gnus-summary-select-article nil nil 'pseudo article)
6877     (gnus-eval-in-buffer-window gnus-article-buffer
6878       (let ((buffer (generate-new-buffer " *print*")))
6879         (unwind-protect
6880             (progn
6881               (copy-to-buffer buffer (point-min) (point-max))
6882               (set-buffer buffer)
6883               (gnus-article-delete-invisible-text)
6884               (let ((ps-left-header
6885                      (list
6886                       (concat "("
6887                               (mail-header-subject gnus-current-headers) ")")
6888                       (concat "("
6889                               (mail-header-from gnus-current-headers) ")")))
6890                     (ps-right-header
6891                      (list
6892                       "/pagenumberstring load"
6893                       (concat "("
6894                               (mail-header-date gnus-current-headers) ")"))))
6895                 (gnus-run-hooks 'gnus-ps-print-hook)
6896                 (save-excursion
6897                   (ps-print-buffer-with-faces filename))))
6898           (kill-buffer buffer))))))
6899
6900 (defun gnus-summary-show-article (&optional arg)
6901   "Force re-fetching of the current article.
6902 If ARG (the prefix) is non-nil, show the raw article without any
6903 article massaging functions being run."
6904   (interactive "P")
6905   (if (not arg)
6906       ;; Select the article the normal way.
6907       (gnus-summary-select-article nil 'force)
6908     ;; We have to require this here to make sure that the following
6909     ;; dynamic binding isn't shadowed by autoloading.
6910     (require 'gnus-async)
6911     (require 'gnus-art)
6912     ;; Bind the article treatment functions to nil.
6913     (let ((gnus-have-all-headers t)
6914           gnus-article-display-hook
6915           gnus-article-prepare-hook
6916           gnus-article-decode-hook
6917           gnus-break-pages
6918           gnus-show-mime
6919           gnus-visual)
6920       (gnus-summary-select-article nil 'force)))
6921   (gnus-summary-goto-subject gnus-current-article)
6922   (gnus-summary-position-point))
6923
6924 (defun gnus-summary-verbose-headers (&optional arg)
6925   "Toggle permanent full header display.
6926 If ARG is a positive number, turn header display on.
6927 If ARG is a negative number, turn header display off."
6928   (interactive "P")
6929   (setq gnus-show-all-headers
6930         (cond ((or (not (numberp arg))
6931                    (zerop arg))
6932                (not gnus-show-all-headers))
6933               ((natnump arg)
6934                t)))
6935   (gnus-summary-show-article))
6936
6937 (defun gnus-summary-toggle-header (&optional arg)
6938   "Show the headers if they are hidden, or hide them if they are shown.
6939 If ARG is a positive number, show the entire header.
6940 If ARG is a negative number, hide the unwanted header lines."
6941   (interactive "P")
6942   (save-excursion
6943     (set-buffer gnus-article-buffer)
6944     (let* ((buffer-read-only nil)
6945            (inhibit-point-motion-hooks t)
6946            (hidden (text-property-any
6947                     (goto-char (point-min)) (search-forward "\n\n")
6948                     'invisible t))
6949            e)
6950       (goto-char (point-min))
6951       (when (search-forward "\n\n" nil t)
6952         (delete-region (point-min) (1- (point))))
6953       (goto-char (point-min))
6954       (save-excursion
6955         (set-buffer gnus-original-article-buffer)
6956         (goto-char (point-min))
6957         (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
6958       (insert-buffer-substring gnus-original-article-buffer 1 e)
6959       (let ((article-inhibit-hiding t))
6960         (gnus-run-hooks 'gnus-article-display-hook))
6961       (when (or (not hidden) (and (numberp arg) (< arg 0)))
6962         (gnus-article-hide-headers)))))
6963
6964 (defun gnus-summary-show-all-headers ()
6965   "Make all header lines visible."
6966   (interactive)
6967   (gnus-article-show-all-headers))
6968
6969 (defun gnus-summary-toggle-mime (&optional arg)
6970   "Toggle MIME processing.
6971 If ARG is a positive number, turn MIME processing on."
6972   (interactive "P")
6973   (setq gnus-show-mime
6974         (if (null arg) (not gnus-show-mime)
6975           (> (prefix-numeric-value arg) 0)))
6976   (gnus-summary-select-article t 'force))
6977
6978 (defun gnus-summary-caesar-message (&optional arg)
6979   "Caesar rotate the current article by 13.
6980 The numerical prefix specifies how many places to rotate each letter
6981 forward."
6982   (interactive "P")
6983   (gnus-summary-select-article)
6984   (let ((mail-header-separator ""))
6985     (gnus-eval-in-buffer-window gnus-article-buffer
6986       (save-restriction
6987         (widen)
6988         (let ((start (window-start))
6989               buffer-read-only)
6990           (message-caesar-buffer-body arg)
6991           (set-window-start (get-buffer-window (current-buffer)) start))))))
6992
6993 (defun gnus-summary-stop-page-breaking ()
6994   "Stop page breaking in the current article."
6995   (interactive)
6996   (gnus-summary-select-article)
6997   (gnus-eval-in-buffer-window gnus-article-buffer
6998     (widen)
6999     (when (gnus-visual-p 'page-marker)
7000       (let ((buffer-read-only nil))
7001         (gnus-remove-text-with-property 'gnus-prev)
7002         (gnus-remove-text-with-property 'gnus-next))
7003       (setq gnus-page-broken nil))))
7004
7005 (defun gnus-summary-move-article (&optional n to-newsgroup
7006                                             select-method action)
7007   "Move the current article to a different newsgroup.
7008 If N is a positive number, move the N next articles.
7009 If N is a negative number, move the N previous articles.
7010 If N is nil and any articles have been marked with the process mark,
7011 move those articles instead.
7012 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7013 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7014 re-spool using this method.
7015
7016 For this function to work, both the current newsgroup and the
7017 newsgroup that you want to move to have to support the `request-move'
7018 and `request-accept' functions."
7019   (interactive "P")
7020   (unless action
7021     (setq action 'move))
7022   ;; Disable marking as read.
7023   (let (gnus-mark-article-hook)
7024     (save-window-excursion
7025       (gnus-summary-select-article)))
7026   ;; Check whether the source group supports the required functions.
7027   (cond ((and (eq action 'move)
7028               (not (gnus-check-backend-function
7029                     'request-move-article gnus-newsgroup-name)))
7030          (error "The current group does not support article moving"))
7031         ((and (eq action 'crosspost)
7032               (not (gnus-check-backend-function
7033                     'request-replace-article gnus-newsgroup-name)))
7034          (error "The current group does not support article editing")))
7035   (let ((articles (gnus-summary-work-articles n))
7036         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
7037         (names '((move "Move" "Moving")
7038                  (copy "Copy" "Copying")
7039                  (crosspost "Crosspost" "Crossposting")))
7040         (copy-buf (save-excursion
7041                     (nnheader-set-temp-buffer " *copy article*")))
7042         art-group to-method new-xref article to-groups)
7043     (unless (assq action names)
7044       (error "Unknown action %s" action))
7045     ;; Read the newsgroup name.
7046     (when (and (not to-newsgroup)
7047                (not select-method))
7048       (setq to-newsgroup
7049             (gnus-read-move-group-name
7050              (cadr (assq action names))
7051              (symbol-value (intern (format "gnus-current-%s-group" action)))
7052              articles prefix))
7053       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7054     (setq to-method (or select-method
7055                         (gnus-group-name-to-method to-newsgroup)))
7056     ;; Check the method we are to move this article to...
7057     (unless (gnus-check-backend-function
7058              'request-accept-article (car to-method))
7059       (error "%s does not support article copying" (car to-method)))
7060     (unless (gnus-check-server to-method)
7061       (error "Can't open server %s" (car to-method)))
7062     (gnus-message 6 "%s to %s: %s..."
7063                   (caddr (assq action names))
7064                   (or (car select-method) to-newsgroup) articles)
7065     (while articles
7066       (setq article (pop articles))
7067       (setq
7068        art-group
7069        (cond
7070         ;; Move the article.
7071         ((eq action 'move)
7072          ;; Remove this article from future suppression.
7073          (gnus-dup-unsuppress-article article)
7074          (gnus-request-move-article
7075           article                       ; Article to move
7076           gnus-newsgroup-name           ; From newsgroup
7077           (nth 1 (gnus-find-method-for-group
7078                   gnus-newsgroup-name)) ; Server
7079           (list 'gnus-request-accept-article
7080                 to-newsgroup (list 'quote select-method)
7081                 (not articles) t)               ; Accept form
7082           (not articles)))              ; Only save nov last time
7083         ;; Copy the article.
7084         ((eq action 'copy)
7085          (save-excursion
7086            (set-buffer copy-buf)
7087            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7088              (gnus-request-accept-article
7089               to-newsgroup select-method (not articles) t))))
7090         ;; Crosspost the article.
7091         ((eq action 'crosspost)
7092          (let ((xref (message-tokenize-header
7093                       (mail-header-xref (gnus-summary-article-header article))
7094                       " ")))
7095            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7096                                   ":" article))
7097            (unless xref
7098              (setq xref (list (system-name))))
7099            (setq new-xref
7100                  (concat
7101                   (mapconcat 'identity
7102                              (delete "Xref:" (delete new-xref xref))
7103                              " ")
7104                   " " new-xref))
7105            (save-excursion
7106              (set-buffer copy-buf)
7107              ;; First put the article in the destination group.
7108              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7109              (when (consp (setq art-group
7110                                 (gnus-request-accept-article
7111                                  to-newsgroup select-method (not articles))))
7112                (setq new-xref (concat new-xref " " (car art-group)
7113                                       ":" (cdr art-group)))
7114                ;; Now we have the new Xrefs header, so we insert
7115                ;; it and replace the new article.
7116                (nnheader-replace-header "Xref" new-xref)
7117                (gnus-request-replace-article
7118                 (cdr art-group) to-newsgroup (current-buffer))
7119                art-group))))))
7120       (cond
7121        ((not art-group)
7122         (gnus-message 1 "Couldn't %s article %s"
7123                       (cadr (assq action names)) article))
7124        ((and (eq art-group 'junk)
7125              (eq action 'move))
7126         (gnus-summary-mark-article article gnus-canceled-mark)
7127         (gnus-message 4 "Deleted article %s" article))
7128        (t
7129         (let* ((pto-group (gnus-group-prefixed-name
7130                            (car art-group) to-method))
7131                (entry
7132                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7133                (info (nth 2 entry))
7134                (to-group (gnus-info-group info)))
7135           ;; Update the group that has been moved to.
7136           (when (and info
7137                      (memq action '(move copy)))
7138             (unless (member to-group to-groups)
7139               (push to-group to-groups))
7140
7141             (unless (memq article gnus-newsgroup-unreads)
7142               (gnus-info-set-read
7143                info (gnus-add-to-range (gnus-info-read info)
7144                                        (list (cdr art-group)))))
7145
7146             ;; Copy any marks over to the new group.
7147             (let ((marks gnus-article-mark-lists)
7148                   (to-article (cdr art-group)))
7149
7150               ;; See whether the article is to be put in the cache.
7151               (when gnus-use-cache
7152                 (gnus-cache-possibly-enter-article
7153                  to-group to-article
7154                  (let ((header (copy-sequence
7155                                 (gnus-summary-article-header article))))
7156                    (mail-header-set-number header to-article)
7157                    header)
7158                  (memq article gnus-newsgroup-marked)
7159                  (memq article gnus-newsgroup-dormant)
7160                  (memq article gnus-newsgroup-unreads)))
7161
7162               (when (and (equal to-group gnus-newsgroup-name)
7163                          (not (memq article gnus-newsgroup-unreads)))
7164                 ;; Mark this article as read in this group.
7165                 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7166                 (setcdr (gnus-active to-group) to-article)
7167                 (setcdr gnus-newsgroup-active to-article))
7168
7169               (while marks
7170                 (when (memq article (symbol-value
7171                                      (intern (format "gnus-newsgroup-%s"
7172                                                      (caar marks)))))
7173                   ;; If the other group is the same as this group,
7174                   ;; then we have to add the mark to the list.
7175                   (when (equal to-group gnus-newsgroup-name)
7176                     (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7177                          (cons to-article
7178                                (symbol-value
7179                                 (intern (format "gnus-newsgroup-%s"
7180                                                 (caar marks)))))))
7181                   ;; Copy the marks to other group.
7182                   (gnus-add-marked-articles
7183                    to-group (cdar marks) (list to-article) info))
7184                 (setq marks (cdr marks)))
7185
7186               (gnus-dribble-enter
7187                (concat "(gnus-group-set-info '"
7188                        (gnus-prin1-to-string (gnus-get-info to-group))
7189                        ")"))))
7190
7191           ;; Update the Xref header in this article to point to
7192           ;; the new crossposted article we have just created.
7193           (when (eq action 'crosspost)
7194             (save-excursion
7195               (set-buffer copy-buf)
7196               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7197               (nnheader-replace-header "Xref" new-xref)
7198               (gnus-request-replace-article
7199                article gnus-newsgroup-name (current-buffer)))))
7200
7201         ;;;!!!Why is this necessary?
7202         (set-buffer gnus-summary-buffer)
7203
7204         (gnus-summary-goto-subject article)
7205         (when (eq action 'move)
7206           (gnus-summary-mark-article article gnus-canceled-mark))))
7207       (gnus-summary-remove-process-mark article))
7208     ;; Re-activate all groups that have been moved to.
7209     (while to-groups
7210       (save-excursion
7211         (set-buffer gnus-group-buffer)
7212         (when (gnus-group-goto-group (car to-groups) t)
7213           (gnus-group-get-new-news-this-group 1 t))
7214         (pop to-groups)))
7215
7216     (gnus-kill-buffer copy-buf)
7217     (gnus-summary-position-point)
7218     (gnus-set-mode-line 'summary)))
7219
7220 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7221   "Move the current article to a different newsgroup.
7222 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7223 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7224 re-spool using this method."
7225   (interactive "P")
7226   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7227
7228 (defun gnus-summary-crosspost-article (&optional n)
7229   "Crosspost the current article to some other group."
7230   (interactive "P")
7231   (gnus-summary-move-article n nil nil 'crosspost))
7232
7233 (defcustom gnus-summary-respool-default-method nil
7234   "Default method for respooling an article.
7235 If nil, use to the current newsgroup method."
7236   :type '(choice (gnus-select-method :value (nnml ""))
7237                  (const nil))
7238   :group 'gnus-summary-mail)
7239
7240 (defun gnus-summary-respool-article (&optional n method)
7241   "Respool the current article.
7242 The article will be squeezed through the mail spooling process again,
7243 which means that it will be put in some mail newsgroup or other
7244 depending on `nnmail-split-methods'.
7245 If N is a positive number, respool the N next articles.
7246 If N is a negative number, respool the N previous articles.
7247 If N is nil and any articles have been marked with the process mark,
7248 respool those articles instead.
7249
7250 Respooling can be done both from mail groups and \"real\" newsgroups.
7251 In the former case, the articles in question will be moved from the
7252 current group into whatever groups they are destined to.  In the
7253 latter case, they will be copied into the relevant groups."
7254   (interactive
7255    (list current-prefix-arg
7256          (let* ((methods (gnus-methods-using 'respool))
7257                 (methname
7258                  (symbol-name (or gnus-summary-respool-default-method
7259                                   (car (gnus-find-method-for-group
7260                                         gnus-newsgroup-name)))))
7261                 (method
7262                  (gnus-completing-read
7263                   methname "What backend do you want to use when respooling?"
7264                   methods nil t nil 'gnus-mail-method-history))
7265                 ms)
7266            (cond
7267             ((zerop (length (setq ms (gnus-servers-using-backend
7268                                       (intern method)))))
7269              (list (intern method) ""))
7270             ((= 1 (length ms))
7271              (car ms))
7272             (t
7273              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7274                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7275                            ms-alist))))))))
7276   (unless method
7277     (error "No method given for respooling"))
7278   (if (assoc (symbol-name
7279               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7280              (gnus-methods-using 'respool))
7281       (gnus-summary-move-article n nil method)
7282     (gnus-summary-copy-article n nil method)))
7283
7284 (defun gnus-summary-import-article (file)
7285   "Import an arbitrary file into a mail newsgroup."
7286   (interactive "fImport file: ")
7287   (let ((group gnus-newsgroup-name)
7288         (now (current-time))
7289         atts lines)
7290     (unless (gnus-check-backend-function 'request-accept-article group)
7291       (error "%s does not support article importing" group))
7292     (or (file-readable-p file)
7293         (not (file-regular-p file))
7294         (error "Can't read %s" file))
7295     (save-excursion
7296       (set-buffer (gnus-get-buffer-create " *import file*"))
7297       (erase-buffer)
7298       (nnheader-insert-file-contents file)
7299       (goto-char (point-min))
7300       (unless (nnheader-article-p)
7301         ;; This doesn't look like an article, so we fudge some headers.
7302         (setq atts (file-attributes file)
7303               lines (count-lines (point-min) (point-max)))
7304         (insert "From: " (read-string "From: ") "\n"
7305                 "Subject: " (read-string "Subject: ") "\n"
7306                 "Date: " (message-make-date (nth 5 atts))
7307                 "\n"
7308                 "Message-ID: " (message-make-message-id) "\n"
7309                 "Lines: " (int-to-string lines) "\n"
7310                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7311       (gnus-request-accept-article group nil t)
7312       (kill-buffer (current-buffer)))))
7313
7314 (defun gnus-summary-article-posted-p ()
7315   "Say whether the current (mail) article is available from `gnus-select-method' as well.
7316 This will be the case if the article has both been mailed and posted."
7317   (interactive)
7318   (let ((id (mail-header-references (gnus-summary-article-header)))
7319         (gnus-override-method
7320          (or gnus-refer-article-method gnus-select-method)))
7321     (if (gnus-request-head id "")
7322         (gnus-message 2 "The current message was found on %s"
7323                       gnus-override-method)
7324       (gnus-message 2 "The current message couldn't be found on %s"
7325                     gnus-override-method)
7326       nil)))
7327
7328 (defun gnus-summary-expire-articles (&optional now)
7329   "Expire all articles that are marked as expirable in the current group."
7330   (interactive)
7331   (when (gnus-check-backend-function
7332          'request-expire-articles gnus-newsgroup-name)
7333     ;; This backend supports expiry.
7334     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7335            (expirable (if total
7336                           (progn
7337                             ;; We need to update the info for
7338                             ;; this group for `gnus-list-of-read-articles'
7339                             ;; to give us the right answer.
7340                             (gnus-run-hooks 'gnus-exit-group-hook)
7341                             (gnus-summary-update-info)
7342                             (gnus-list-of-read-articles gnus-newsgroup-name))
7343                         (setq gnus-newsgroup-expirable
7344                               (sort gnus-newsgroup-expirable '<))))
7345            (expiry-wait (if now 'immediate
7346                           (gnus-group-find-parameter
7347                            gnus-newsgroup-name 'expiry-wait)))
7348            es)
7349       (when expirable
7350         ;; There are expirable articles in this group, so we run them
7351         ;; through the expiry process.
7352         (gnus-message 6 "Expiring articles...")
7353         ;; The list of articles that weren't expired is returned.
7354         (save-excursion
7355           (if expiry-wait
7356               (let ((nnmail-expiry-wait-function nil)
7357                     (nnmail-expiry-wait expiry-wait))
7358                 (setq es (gnus-request-expire-articles
7359                           expirable gnus-newsgroup-name)))
7360             (setq es (gnus-request-expire-articles
7361                       expirable gnus-newsgroup-name))))
7362         (unless total
7363           (setq gnus-newsgroup-expirable es))
7364         ;; We go through the old list of expirable, and mark all
7365         ;; really expired articles as nonexistent.
7366         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
7367           (let ((gnus-use-cache nil))
7368             (while expirable
7369               (unless (memq (car expirable) es)
7370                 (when (gnus-data-find (car expirable))
7371                   (gnus-summary-mark-article
7372                    (car expirable) gnus-canceled-mark)))
7373               (setq expirable (cdr expirable)))))
7374         (gnus-message 6 "Expiring articles...done")))))
7375
7376 (defun gnus-summary-expire-articles-now ()
7377   "Expunge all expirable articles in the current group.
7378 This means that *all* articles that are marked as expirable will be
7379 deleted forever, right now."
7380   (interactive)
7381   (or gnus-expert-user
7382       (gnus-yes-or-no-p
7383        "Are you really, really, really sure you want to delete all these messages? ")
7384       (error "Phew!"))
7385   (gnus-summary-expire-articles t))
7386
7387 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7388 (defun gnus-summary-delete-article (&optional n)
7389   "Delete the N next (mail) articles.
7390 This command actually deletes articles.  This is not a marking
7391 command.  The article will disappear forever from your life, never to
7392 return.
7393 If N is negative, delete backwards.
7394 If N is nil and articles have been marked with the process mark,
7395 delete these instead."
7396   (interactive "P")
7397   (unless (gnus-check-backend-function 'request-expire-articles
7398                                        gnus-newsgroup-name)
7399     (error "The current newsgroup does not support article deletion"))
7400   ;; Compute the list of articles to delete.
7401   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
7402         not-deleted)
7403     (if (and gnus-novice-user
7404              (not (gnus-yes-or-no-p
7405                    (format "Do you really want to delete %s forever? "
7406                            (if (> (length articles) 1)
7407                                (format "these %s articles" (length articles))
7408                              "this article")))))
7409         ()
7410       ;; Delete the articles.
7411       (setq not-deleted (gnus-request-expire-articles
7412                          articles gnus-newsgroup-name 'force))
7413       (while articles
7414         (gnus-summary-remove-process-mark (car articles))
7415         ;; The backend might not have been able to delete the article
7416         ;; after all.
7417         (unless (memq (car articles) not-deleted)
7418           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7419         (setq articles (cdr articles)))
7420       (when not-deleted
7421         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7422     (gnus-summary-position-point)
7423     (gnus-set-mode-line 'summary)
7424     not-deleted))
7425
7426 (defun gnus-summary-edit-article (&optional force)
7427   "Edit the current article.
7428 This will have permanent effect only in mail groups.
7429 If FORCE is non-nil, allow editing of articles even in read-only
7430 groups."
7431   (interactive "P")
7432   (save-excursion
7433     (set-buffer gnus-summary-buffer)
7434     (gnus-set-global-variables)
7435     (when (and (not force)
7436                (gnus-group-read-only-p))
7437       (error "The current newsgroup does not support article editing"))
7438     ;; Select article if needed.
7439     (unless (eq (gnus-summary-article-number)
7440                 gnus-current-article)
7441       (gnus-summary-select-article t))
7442     (gnus-article-date-original)
7443     (gnus-article-edit-article
7444      `(lambda (no-highlight)
7445         (gnus-summary-edit-article-done
7446          ,(or (mail-header-references gnus-current-headers) "")
7447          ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))
7448
7449 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7450
7451 (defun gnus-summary-edit-article-done (&optional references read-only buffer
7452                                                  no-highlight)
7453   "Make edits to the current article permanent."
7454   (interactive)
7455   ;; Replace the article.
7456   (let ((buf (current-buffer)))
7457     (with-temp-buffer
7458       (insert-buffer buf)
7459       (if (and (not read-only)
7460                (not (gnus-request-replace-article
7461                      (cdr gnus-article-current) (car gnus-article-current)
7462                      (current-buffer))))
7463           (error "Couldn't replace article")
7464         ;; Update the summary buffer.
7465         (if (and references
7466                  (equal (message-tokenize-header references " ")
7467                         (message-tokenize-header
7468                          (or (message-fetch-field "references") "") " ")))
7469             ;; We only have to update this line.
7470             (save-excursion
7471               (save-restriction
7472                 (message-narrow-to-head)
7473                 (let ((head (buffer-string))
7474                       header)
7475                   (with-temp-buffer
7476                     (insert (format "211 %d Article retrieved.\n"
7477                                     (cdr gnus-article-current)))
7478                     (insert head)
7479                     (insert ".\n")
7480                     (let ((nntp-server-buffer (current-buffer)))
7481                       (setq header (car (gnus-get-newsgroup-headers
7482                                          (save-excursion
7483                                            (set-buffer gnus-summary-buffer)
7484                                            gnus-newsgroup-dependencies)
7485                                          t))))
7486                     (save-excursion
7487                       (set-buffer gnus-summary-buffer)
7488                       (gnus-data-set-header
7489                        (gnus-data-find (cdr gnus-article-current))
7490                        header)
7491                       (gnus-summary-update-article-line
7492                        (cdr gnus-article-current) header))))))
7493           ;; Update threads.
7494           (set-buffer (or buffer gnus-summary-buffer))
7495           (gnus-summary-update-article (cdr gnus-article-current)))
7496         ;; Prettify the article buffer again.
7497         (unless no-highlight
7498           (save-excursion
7499             (set-buffer gnus-article-buffer)
7500             (gnus-run-hooks 'gnus-article-display-hook)
7501             (set-buffer gnus-original-article-buffer)
7502             (gnus-request-article
7503              (cdr gnus-article-current)
7504              (car gnus-article-current) (current-buffer))))
7505         ;; Prettify the summary buffer line.
7506         (when (gnus-visual-p 'summary-highlight 'highlight)
7507           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
7508
7509 (defun gnus-summary-edit-wash (key)
7510   "Perform editing command KEY in the article buffer."
7511   (interactive
7512    (list
7513     (progn
7514       (message "%s" (concat (this-command-keys) "- "))
7515       (read-char))))
7516   (message "")
7517   (gnus-summary-edit-article)
7518   (execute-kbd-macro (concat (this-command-keys) key))
7519   (gnus-article-edit-done))
7520
7521 ;;; Respooling
7522
7523 (defun gnus-summary-respool-query (&optional silent trace)
7524   "Query where the respool algorithm would put this article."
7525   (interactive)
7526   (let (gnus-mark-article-hook)
7527     (gnus-summary-select-article)
7528     (save-excursion
7529       (set-buffer gnus-original-article-buffer)
7530       (save-restriction
7531         (message-narrow-to-head)
7532         (let ((groups (nnmail-article-group 'identity trace)))
7533           (unless silent
7534             (if groups
7535                 (message "This message would go to %s"
7536                          (mapconcat 'car groups ", "))
7537               (message "This message would go to no groups"))
7538             groups))))))
7539
7540 (defun gnus-summary-respool-trace ()
7541   "Trace where the respool algorithm would put this article.
7542 Display a buffer showing all fancy splitting patterns which matched."
7543   (interactive)
7544   (gnus-summary-respool-query nil t))
7545
7546 ;; Summary marking commands.
7547
7548 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7549   "Mark articles which has the same subject as read, and then select the next.
7550 If UNMARK is positive, remove any kind of mark.
7551 If UNMARK is negative, tick articles."
7552   (interactive "P")
7553   (when unmark
7554     (setq unmark (prefix-numeric-value unmark)))
7555   (let ((count
7556          (gnus-summary-mark-same-subject
7557           (gnus-summary-article-subject) unmark)))
7558     ;; Select next unread article.  If auto-select-same mode, should
7559     ;; select the first unread article.
7560     (gnus-summary-next-article t (and gnus-auto-select-same
7561                                       (gnus-summary-article-subject)))
7562     (gnus-message 7 "%d article%s marked as %s"
7563                   count (if (= count 1) " is" "s are")
7564                   (if unmark "unread" "read"))))
7565
7566 (defun gnus-summary-kill-same-subject (&optional unmark)
7567   "Mark articles which has the same subject as read.
7568 If UNMARK is positive, remove any kind of mark.
7569 If UNMARK is negative, tick articles."
7570   (interactive "P")
7571   (when unmark
7572     (setq unmark (prefix-numeric-value unmark)))
7573   (let ((count
7574          (gnus-summary-mark-same-subject
7575           (gnus-summary-article-subject) unmark)))
7576     ;; If marked as read, go to next unread subject.
7577     (when (null unmark)
7578       ;; Go to next unread subject.
7579       (gnus-summary-next-subject 1 t))
7580     (gnus-message 7 "%d articles are marked as %s"
7581                   count (if unmark "unread" "read"))))
7582
7583 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7584   "Mark articles with same SUBJECT as read, and return marked number.
7585 If optional argument UNMARK is positive, remove any kinds of marks.
7586 If optional argument UNMARK is negative, mark articles as unread instead."
7587   (let ((count 1))
7588     (save-excursion
7589       (cond
7590        ((null unmark)                   ; Mark as read.
7591         (while (and
7592                 (progn
7593                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7594                   (gnus-summary-show-thread) t)
7595                 (gnus-summary-find-subject subject))
7596           (setq count (1+ count))))
7597        ((> unmark 0)                    ; Tick.
7598         (while (and
7599                 (progn
7600                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7601                   (gnus-summary-show-thread) t)
7602                 (gnus-summary-find-subject subject))
7603           (setq count (1+ count))))
7604        (t                               ; Mark as unread.
7605         (while (and
7606                 (progn
7607                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7608                   (gnus-summary-show-thread) t)
7609                 (gnus-summary-find-subject subject))
7610           (setq count (1+ count)))))
7611       (gnus-set-mode-line 'summary)
7612       ;; Return the number of marked articles.
7613       count)))
7614
7615 (defun gnus-summary-mark-as-processable (n &optional unmark)
7616   "Set the process mark on the next N articles.
7617 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7618 the process mark instead.  The difference between N and the actual
7619 number of articles marked is returned."
7620   (interactive "p")
7621   (let ((backward (< n 0))
7622         (n (abs n)))
7623     (while (and
7624             (> n 0)
7625             (if unmark
7626                 (gnus-summary-remove-process-mark
7627                  (gnus-summary-article-number))
7628               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7629             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7630       (setq n (1- n)))
7631     (when (/= 0 n)
7632       (gnus-message 7 "No more articles"))
7633     (gnus-summary-recenter)
7634     (gnus-summary-position-point)
7635     n))
7636
7637 (defun gnus-summary-unmark-as-processable (n)
7638   "Remove the process mark from the next N articles.
7639 If N is negative, unmark backward instead.  The difference between N and
7640 the actual number of articles unmarked is returned."
7641   (interactive "p")
7642   (gnus-summary-mark-as-processable n t))
7643
7644 (defun gnus-summary-unmark-all-processable ()
7645   "Remove the process mark from all articles."
7646   (interactive)
7647   (save-excursion
7648     (while gnus-newsgroup-processable
7649       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7650   (gnus-summary-position-point))
7651
7652 (defun gnus-summary-mark-as-expirable (n)
7653   "Mark N articles forward as expirable.
7654 If N is negative, mark backward instead.  The difference between N and
7655 the actual number of articles marked is returned."
7656   (interactive "p")
7657   (gnus-summary-mark-forward n gnus-expirable-mark))
7658
7659 (defun gnus-summary-mark-article-as-replied (article)
7660   "Mark ARTICLE replied and update the summary line."
7661   (push article gnus-newsgroup-replied)
7662   (let ((buffer-read-only nil))
7663     (when (gnus-summary-goto-subject article nil t)
7664       (gnus-summary-update-secondary-mark article))))
7665
7666 (defun gnus-summary-set-bookmark (article)
7667   "Set a bookmark in current article."
7668   (interactive (list (gnus-summary-article-number)))
7669   (when (or (not (get-buffer gnus-article-buffer))
7670             (not gnus-current-article)
7671             (not gnus-article-current)
7672             (not (equal gnus-newsgroup-name (car gnus-article-current))))
7673     (error "No current article selected"))
7674   ;; Remove old bookmark, if one exists.
7675   (let ((old (assq article gnus-newsgroup-bookmarks)))
7676     (when old
7677       (setq gnus-newsgroup-bookmarks
7678             (delq old gnus-newsgroup-bookmarks))))
7679   ;; Set the new bookmark, which is on the form
7680   ;; (article-number . line-number-in-body).
7681   (push
7682    (cons article
7683          (save-excursion
7684            (set-buffer gnus-article-buffer)
7685            (count-lines
7686             (min (point)
7687                  (save-excursion
7688                    (goto-char (point-min))
7689                    (search-forward "\n\n" nil t)
7690                    (point)))
7691             (point))))
7692    gnus-newsgroup-bookmarks)
7693   (gnus-message 6 "A bookmark has been added to the current article."))
7694
7695 (defun gnus-summary-remove-bookmark (article)
7696   "Remove the bookmark from the current article."
7697   (interactive (list (gnus-summary-article-number)))
7698   ;; Remove old bookmark, if one exists.
7699   (let ((old (assq article gnus-newsgroup-bookmarks)))
7700     (if old
7701         (progn
7702           (setq gnus-newsgroup-bookmarks
7703                 (delq old gnus-newsgroup-bookmarks))
7704           (gnus-message 6 "Removed bookmark."))
7705       (gnus-message 6 "No bookmark in current article."))))
7706
7707 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7708 (defun gnus-summary-mark-as-dormant (n)
7709   "Mark N articles forward as dormant.
7710 If N is negative, mark backward instead.  The difference between N and
7711 the actual number of articles marked is returned."
7712   (interactive "p")
7713   (gnus-summary-mark-forward n gnus-dormant-mark))
7714
7715 (defun gnus-summary-set-process-mark (article)
7716   "Set the process mark on ARTICLE and update the summary line."
7717   (setq gnus-newsgroup-processable
7718         (cons article
7719               (delq article gnus-newsgroup-processable)))
7720   (when (gnus-summary-goto-subject article)
7721     (gnus-summary-show-thread)
7722     (gnus-summary-goto-subject article)
7723     (gnus-summary-update-secondary-mark article)))
7724
7725 (defun gnus-summary-remove-process-mark (article)
7726   "Remove the process mark from ARTICLE and update the summary line."
7727   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
7728   (when (gnus-summary-goto-subject article)
7729     (gnus-summary-show-thread)
7730     (gnus-summary-goto-subject article)
7731     (gnus-summary-update-secondary-mark article)))
7732
7733 (defun gnus-summary-set-saved-mark (article)
7734   "Set the process mark on ARTICLE and update the summary line."
7735   (push article gnus-newsgroup-saved)
7736   (when (gnus-summary-goto-subject article)
7737     (gnus-summary-update-secondary-mark article)))
7738
7739 (defun gnus-summary-mark-forward (n &optional mark no-expire)
7740   "Mark N articles as read forwards.
7741 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
7742 The difference between N and the actual number of articles marked is
7743 returned."
7744   (interactive "p")
7745   (gnus-summary-show-thread)
7746   (let ((backward (< n 0))
7747         (gnus-summary-goto-unread
7748          (and gnus-summary-goto-unread
7749               (not (eq gnus-summary-goto-unread 'never))
7750               (not (memq mark (list gnus-unread-mark
7751                                     gnus-ticked-mark gnus-dormant-mark)))))
7752         (n (abs n))
7753         (mark (or mark gnus-del-mark)))
7754     (while (and (> n 0)
7755                 (gnus-summary-mark-article nil mark no-expire)
7756                 (zerop (gnus-summary-next-subject
7757                         (if backward -1 1)
7758                         (and gnus-summary-goto-unread
7759                              (not (eq gnus-summary-goto-unread 'never)))
7760                         t)))
7761       (setq n (1- n)))
7762     (when (/= 0 n)
7763       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
7764     (gnus-summary-recenter)
7765     (gnus-summary-position-point)
7766     (gnus-set-mode-line 'summary)
7767     n))
7768
7769 (defun gnus-summary-mark-article-as-read (mark)
7770   "Mark the current article quickly as read with MARK."
7771   (let ((article (gnus-summary-article-number)))
7772     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7773     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7774     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7775     (push (cons article mark) gnus-newsgroup-reads)
7776     ;; Possibly remove from cache, if that is used.
7777     (when gnus-use-cache
7778       (gnus-cache-enter-remove-article article))
7779     ;; Allow the backend to change the mark.
7780     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7781     ;; Check for auto-expiry.
7782     (when (and gnus-newsgroup-auto-expire
7783                (memq mark gnus-auto-expirable-marks))
7784       (setq mark gnus-expirable-mark)
7785       ;; Let the backend know about the mark change.
7786       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7787       (push article gnus-newsgroup-expirable))
7788     ;; Set the mark in the buffer.
7789     (gnus-summary-update-mark mark 'unread)
7790     t))
7791
7792 (defun gnus-summary-mark-article-as-unread (mark)
7793   "Mark the current article quickly as unread with MARK."
7794   (let* ((article (gnus-summary-article-number))
7795          (old-mark (gnus-summary-article-mark article)))
7796     ;; Allow the backend to change the mark.
7797     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7798     (if (eq mark old-mark)
7799         t
7800       (if (<= article 0)
7801           (progn
7802             (gnus-error 1 "Can't mark negative article numbers")
7803             nil)
7804         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7805         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7806         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
7807         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
7808         (cond ((= mark gnus-ticked-mark)
7809                (push article gnus-newsgroup-marked))
7810               ((= mark gnus-dormant-mark)
7811                (push article gnus-newsgroup-dormant))
7812               (t
7813                (push article gnus-newsgroup-unreads)))
7814         (gnus-pull article gnus-newsgroup-reads)
7815
7816         ;; See whether the article is to be put in the cache.
7817         (and gnus-use-cache
7818              (vectorp (gnus-summary-article-header article))
7819              (save-excursion
7820                (gnus-cache-possibly-enter-article
7821                 gnus-newsgroup-name article
7822                 (gnus-summary-article-header article)
7823                 (= mark gnus-ticked-mark)
7824                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7825
7826         ;; Fix the mark.
7827         (gnus-summary-update-mark mark 'unread)
7828         t))))
7829
7830 (defun gnus-summary-mark-article (&optional article mark no-expire)
7831   "Mark ARTICLE with MARK.  MARK can be any character.
7832 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
7833 `??' (dormant) and `?E' (expirable).
7834 If MARK is nil, then the default character `?r' is used.
7835 If ARTICLE is nil, then the article on the current line will be
7836 marked."
7837   ;; The mark might be a string.
7838   (when (stringp mark)
7839     (setq mark (aref mark 0)))
7840   ;; If no mark is given, then we check auto-expiring.
7841   (when (null mark)
7842     (setq mark gnus-del-mark))
7843   (when (and (not no-expire)
7844              gnus-newsgroup-auto-expire
7845              (memq mark gnus-auto-expirable-marks))
7846     (setq mark gnus-expirable-mark))
7847   (let ((article (or article (gnus-summary-article-number)))
7848         (old-mark (gnus-summary-article-mark article)))
7849     ;; Allow the backend to change the mark.
7850     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7851     (if (eq mark old-mark)
7852         t
7853       (unless article
7854         (error "No article on current line"))
7855       (if (not (if (or (= mark gnus-unread-mark)
7856                        (= mark gnus-ticked-mark)
7857                        (= mark gnus-dormant-mark))
7858                    (gnus-mark-article-as-unread article mark)
7859                  (gnus-mark-article-as-read article mark)))
7860           t
7861         ;; See whether the article is to be put in the cache.
7862         (and gnus-use-cache
7863              (not (= mark gnus-canceled-mark))
7864              (vectorp (gnus-summary-article-header article))
7865              (save-excursion
7866                (gnus-cache-possibly-enter-article
7867                 gnus-newsgroup-name article
7868                 (gnus-summary-article-header article)
7869                 (= mark gnus-ticked-mark)
7870                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7871
7872         (when (gnus-summary-goto-subject article nil t)
7873           (let ((buffer-read-only nil))
7874             (gnus-summary-show-thread)
7875             ;; Fix the mark.
7876             (gnus-summary-update-mark mark 'unread)
7877             t))))))
7878
7879 (defun gnus-summary-update-secondary-mark (article)
7880   "Update the secondary (read, process, cache) mark."
7881   (gnus-summary-update-mark
7882    (cond ((memq article gnus-newsgroup-processable)
7883           gnus-process-mark)
7884          ((memq article gnus-newsgroup-cached)
7885           gnus-cached-mark)
7886          ((memq article gnus-newsgroup-replied)
7887           gnus-replied-mark)
7888          ((memq article gnus-newsgroup-saved)
7889           gnus-saved-mark)
7890          (t gnus-unread-mark))
7891    'replied)
7892   (when (gnus-visual-p 'summary-highlight 'highlight)
7893     (gnus-run-hooks 'gnus-summary-update-hook))
7894   t)
7895
7896 (defun gnus-summary-update-mark (mark type)
7897   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
7898         (buffer-read-only nil))
7899     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
7900     (when forward
7901       (when (looking-at "\r")
7902         (incf forward))
7903       (when (<= (+ forward (point)) (point-max))
7904         ;; Go to the right position on the line.
7905         (goto-char (+ forward (point)))
7906         ;; Replace the old mark with the new mark.
7907         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
7908         ;; Optionally update the marks by some user rule.
7909         (when (eq type 'unread)
7910           (gnus-data-set-mark
7911            (gnus-data-find (gnus-summary-article-number)) mark)
7912           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
7913
7914 (defun gnus-mark-article-as-read (article &optional mark)
7915   "Enter ARTICLE in the pertinent lists and remove it from others."
7916   ;; Make the article expirable.
7917   (let ((mark (or mark gnus-del-mark)))
7918     (if (= mark gnus-expirable-mark)
7919         (push article gnus-newsgroup-expirable)
7920       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
7921     ;; Remove from unread and marked lists.
7922     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7923     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7924     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7925     (push (cons article mark) gnus-newsgroup-reads)
7926     ;; Possibly remove from cache, if that is used.
7927     (when gnus-use-cache
7928       (gnus-cache-enter-remove-article article))
7929     t))
7930
7931 (defun gnus-mark-article-as-unread (article &optional mark)
7932   "Enter ARTICLE in the pertinent lists and remove it from others."
7933   (let ((mark (or mark gnus-ticked-mark)))
7934     (if (<= article 0)
7935         (progn
7936           (gnus-error 1 "Can't mark negative article numbers")
7937           nil)
7938       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
7939             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
7940             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
7941             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7942
7943       ;; Unsuppress duplicates?
7944       (when gnus-suppress-duplicates
7945         (gnus-dup-unsuppress-article article))
7946
7947       (cond ((= mark gnus-ticked-mark)
7948              (push article gnus-newsgroup-marked))
7949             ((= mark gnus-dormant-mark)
7950              (push article gnus-newsgroup-dormant))
7951             (t
7952              (push article gnus-newsgroup-unreads)))
7953       (gnus-pull article gnus-newsgroup-reads)
7954       t)))
7955
7956 (defalias 'gnus-summary-mark-as-unread-forward
7957   'gnus-summary-tick-article-forward)
7958 (make-obsolete 'gnus-summary-mark-as-unread-forward
7959                'gnus-summary-tick-article-forward)
7960 (defun gnus-summary-tick-article-forward (n)
7961   "Tick N articles forwards.
7962 If N is negative, tick backwards instead.
7963 The difference between N and the number of articles ticked is returned."
7964   (interactive "p")
7965   (gnus-summary-mark-forward n gnus-ticked-mark))
7966
7967 (defalias 'gnus-summary-mark-as-unread-backward
7968   'gnus-summary-tick-article-backward)
7969 (make-obsolete 'gnus-summary-mark-as-unread-backward
7970                'gnus-summary-tick-article-backward)
7971 (defun gnus-summary-tick-article-backward (n)
7972   "Tick N articles backwards.
7973 The difference between N and the number of articles ticked is returned."
7974   (interactive "p")
7975   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
7976
7977 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
7978 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
7979 (defun gnus-summary-tick-article (&optional article clear-mark)
7980   "Mark current article as unread.
7981 Optional 1st argument ARTICLE specifies article number to be marked as unread.
7982 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
7983   (interactive)
7984   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
7985                                        gnus-ticked-mark)))
7986
7987 (defun gnus-summary-mark-as-read-forward (n)
7988   "Mark N articles as read forwards.
7989 If N is negative, mark backwards instead.
7990 The difference between N and the actual number of articles marked is
7991 returned."
7992   (interactive "p")
7993   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
7994
7995 (defun gnus-summary-mark-as-read-backward (n)
7996   "Mark the N articles as read backwards.
7997 The difference between N and the actual number of articles marked is
7998 returned."
7999   (interactive "p")
8000   (gnus-summary-mark-forward (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8001
8002 (defun gnus-summary-mark-as-read (&optional article mark)
8003   "Mark current article as read.
8004 ARTICLE specifies the article to be marked as read.
8005 MARK specifies a string to be inserted at the beginning of the line."
8006   (gnus-summary-mark-article article mark))
8007
8008 (defun gnus-summary-clear-mark-forward (n)
8009   "Clear marks from N articles forward.
8010 If N is negative, clear backward instead.
8011 The difference between N and the number of marks cleared is returned."
8012   (interactive "p")
8013   (gnus-summary-mark-forward n gnus-unread-mark))
8014
8015 (defun gnus-summary-clear-mark-backward (n)
8016   "Clear marks from N articles backward.
8017 The difference between N and the number of marks cleared is returned."
8018   (interactive "p")
8019   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8020
8021 (defun gnus-summary-mark-unread-as-read ()
8022   "Intended to be used by `gnus-summary-mark-article-hook'."
8023   (when (memq gnus-current-article gnus-newsgroup-unreads)
8024     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8025
8026 (defun gnus-summary-mark-read-and-unread-as-read ()
8027   "Intended to be used by `gnus-summary-mark-article-hook'."
8028   (let ((mark (gnus-summary-article-mark)))
8029     (when (or (gnus-unread-mark-p mark)
8030               (gnus-read-mark-p mark))
8031       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8032
8033 (defun gnus-summary-mark-region-as-read (point mark all)
8034   "Mark all unread articles between point and mark as read.
8035 If given a prefix, mark all articles between point and mark as read,
8036 even ticked and dormant ones."
8037   (interactive "r\nP")
8038   (save-excursion
8039     (let (article)
8040       (goto-char point)
8041       (beginning-of-line)
8042       (while (and
8043               (< (point) mark)
8044               (progn
8045                 (when (or all
8046                           (memq (setq article (gnus-summary-article-number))
8047                                 gnus-newsgroup-unreads))
8048                   (gnus-summary-mark-article article gnus-del-mark))
8049                 t)
8050               (gnus-summary-find-next))))))
8051
8052 (defun gnus-summary-mark-below (score mark)
8053   "Mark articles with score less than SCORE with MARK."
8054   (interactive "P\ncMark: ")
8055   (setq score (if score
8056                   (prefix-numeric-value score)
8057                 (or gnus-summary-default-score 0)))
8058   (save-excursion
8059     (set-buffer gnus-summary-buffer)
8060     (goto-char (point-min))
8061     (while
8062         (progn
8063           (and (< (gnus-summary-article-score) score)
8064                (gnus-summary-mark-article nil mark))
8065           (gnus-summary-find-next)))))
8066
8067 (defun gnus-summary-kill-below (&optional score)
8068   "Mark articles with score below SCORE as read."
8069   (interactive "P")
8070   (gnus-summary-mark-below score gnus-killed-mark))
8071
8072 (defun gnus-summary-clear-above (&optional score)
8073   "Clear all marks from articles with score above SCORE."
8074   (interactive "P")
8075   (gnus-summary-mark-above score gnus-unread-mark))
8076
8077 (defun gnus-summary-tick-above (&optional score)
8078   "Tick all articles with score above SCORE."
8079   (interactive "P")
8080   (gnus-summary-mark-above score gnus-ticked-mark))
8081
8082 (defun gnus-summary-mark-above (score mark)
8083   "Mark articles with score over SCORE with MARK."
8084   (interactive "P\ncMark: ")
8085   (setq score (if score
8086                   (prefix-numeric-value score)
8087                 (or gnus-summary-default-score 0)))
8088   (save-excursion
8089     (set-buffer gnus-summary-buffer)
8090     (goto-char (point-min))
8091     (while (and (progn
8092                   (when (> (gnus-summary-article-score) score)
8093                     (gnus-summary-mark-article nil mark))
8094                   t)
8095                 (gnus-summary-find-next)))))
8096
8097 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8098 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8099 (defun gnus-summary-limit-include-expunged (&optional no-error)
8100   "Display all the hidden articles that were expunged for low scores."
8101   (interactive)
8102   (let ((buffer-read-only nil))
8103     (let ((scored gnus-newsgroup-scored)
8104           headers h)
8105       (while scored
8106         (unless (gnus-summary-goto-subject (caar scored))
8107           (and (setq h (gnus-summary-article-header (caar scored)))
8108                (< (cdar scored) gnus-summary-expunge-below)
8109                (push h headers)))
8110         (setq scored (cdr scored)))
8111       (if (not headers)
8112           (when (not no-error)
8113             (error "No expunged articles hidden"))
8114         (goto-char (point-min))
8115         (gnus-summary-prepare-unthreaded (nreverse headers))
8116         (goto-char (point-min))
8117         (gnus-summary-position-point)
8118         t))))
8119
8120 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8121   "Mark all unread articles in this newsgroup as read.
8122 If prefix argument ALL is non-nil, ticked and dormant articles will
8123 also be marked as read.
8124 If QUIETLY is non-nil, no questions will be asked.
8125 If TO-HERE is non-nil, it should be a point in the buffer.  All
8126 articles before this point will be marked as read.
8127 Note that this function will only catch up the unread article
8128 in the current summary buffer limitation.
8129 The number of articles marked as read is returned."
8130   (interactive "P")
8131   (prog1
8132       (save-excursion
8133         (when (or quietly
8134                   (not gnus-interactive-catchup) ;Without confirmation?
8135                   gnus-expert-user
8136                   (gnus-y-or-n-p
8137                    (if all
8138                        "Mark absolutely all articles as read? "
8139                      "Mark all unread articles as read? ")))
8140           (if (and not-mark
8141                    (not gnus-newsgroup-adaptive)
8142                    (not gnus-newsgroup-auto-expire)
8143                    (not gnus-suppress-duplicates)
8144                    (or (not gnus-use-cache)
8145                        (eq gnus-use-cache 'passive)))
8146               (progn
8147                 (when all
8148                   (setq gnus-newsgroup-marked nil
8149                         gnus-newsgroup-dormant nil))
8150                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8151             ;; We actually mark all articles as canceled, which we
8152             ;; have to do when using auto-expiry or adaptive scoring.
8153             (gnus-summary-show-all-threads)
8154             (when (gnus-summary-first-subject (not all) t)
8155               (while (and
8156                       (if to-here (< (point) to-here) t)
8157                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8158                       (gnus-summary-find-next (not all) nil nil t))))
8159             (gnus-set-mode-line 'summary))
8160           t))
8161     (gnus-summary-position-point)))
8162
8163 (defun gnus-summary-catchup-to-here (&optional all)
8164   "Mark all unticked articles before the current one as read.
8165 If ALL is non-nil, also mark ticked and dormant articles as read."
8166   (interactive "P")
8167   (save-excursion
8168     (gnus-save-hidden-threads
8169       (let ((beg (point)))
8170         ;; We check that there are unread articles.
8171         (when (or all (gnus-summary-find-prev))
8172           (gnus-summary-catchup all t beg)))))
8173   (gnus-summary-position-point))
8174
8175 (defun gnus-summary-catchup-all (&optional quietly)
8176   "Mark all articles in this newsgroup as read."
8177   (interactive "P")
8178   (gnus-summary-catchup t quietly))
8179
8180 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8181   "Mark all articles not marked as unread in this newsgroup as read, then exit.
8182 If prefix argument ALL is non-nil, all articles are marked as read."
8183   (interactive "P")
8184   (when (gnus-summary-catchup all quietly nil 'fast)
8185     ;; Select next newsgroup or exit.
8186     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8187              (eq gnus-auto-select-next 'quietly))
8188         (gnus-summary-next-group nil)
8189       (gnus-summary-exit))))
8190
8191 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8192   "Mark all articles in this newsgroup as read, and then exit."
8193   (interactive "P")
8194   (gnus-summary-catchup-and-exit t quietly))
8195
8196 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
8197 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8198   "Mark all articles in this group as read and select the next group.
8199 If given a prefix, mark all articles, unread as well as ticked, as
8200 read."
8201   (interactive "P")
8202   (save-excursion
8203     (gnus-summary-catchup all))
8204   (gnus-summary-next-article t nil nil t))
8205
8206 ;; Thread-based commands.
8207
8208 (defun gnus-summary-articles-in-thread (&optional article)
8209   "Return a list of all articles in the current thread.
8210 If ARTICLE is non-nil, return all articles in the thread that starts
8211 with that article."
8212   (let* ((article (or article (gnus-summary-article-number)))
8213          (data (gnus-data-find-list article))
8214          (top-level (gnus-data-level (car data)))
8215          (top-subject
8216           (cond ((null gnus-thread-operation-ignore-subject)
8217                  (gnus-simplify-subject-re
8218                   (mail-header-subject (gnus-data-header (car data)))))
8219                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8220                  (gnus-simplify-subject-fuzzy
8221                   (mail-header-subject (gnus-data-header (car data)))))
8222                 (t nil)))
8223          (end-point (save-excursion
8224                       (if (gnus-summary-go-to-next-thread)
8225                           (point) (point-max))))
8226          articles)
8227     (while (and data
8228                 (< (gnus-data-pos (car data)) end-point))
8229       (when (or (not top-subject)
8230                 (string= top-subject
8231                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8232                              (gnus-simplify-subject-fuzzy
8233                               (mail-header-subject
8234                                (gnus-data-header (car data))))
8235                            (gnus-simplify-subject-re
8236                             (mail-header-subject
8237                              (gnus-data-header (car data)))))))
8238         (push (gnus-data-number (car data)) articles))
8239       (unless (and (setq data (cdr data))
8240                    (> (gnus-data-level (car data)) top-level))
8241         (setq data nil)))
8242     ;; Return the list of articles.
8243     (nreverse articles)))
8244
8245 (defun gnus-summary-rethread-current ()
8246   "Rethread the thread the current article is part of."
8247   (interactive)
8248   (let* ((gnus-show-threads t)
8249          (article (gnus-summary-article-number))
8250          (id (mail-header-id (gnus-summary-article-header)))
8251          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8252     (unless id
8253       (error "No article on the current line"))
8254     (gnus-rebuild-thread id)
8255     (gnus-summary-goto-subject article)))
8256
8257 (defun gnus-summary-reparent-thread ()
8258   "Make the current article child of the marked (or previous) article.
8259
8260 Note that the re-threading will only work if `gnus-thread-ignore-subject'
8261 is non-nil or the Subject: of both articles are the same."
8262   (interactive)
8263   (unless (not (gnus-group-read-only-p))
8264     (error "The current newsgroup does not support article editing"))
8265   (unless (<= (length gnus-newsgroup-processable) 1)
8266     (error "No more than one article may be marked"))
8267   (save-window-excursion
8268     (let ((gnus-article-buffer " *reparent*")
8269           (current-article (gnus-summary-article-number))
8270           ;; First grab the marked article, otherwise one line up.
8271           (parent-article (if (not (null gnus-newsgroup-processable))
8272                               (car gnus-newsgroup-processable)
8273                             (save-excursion
8274                               (if (eq (forward-line -1) 0)
8275                                   (gnus-summary-article-number)
8276                                 (error "Beginning of summary buffer"))))))
8277       (unless (not (eq current-article parent-article))
8278         (error "An article may not be self-referential"))
8279       (let ((message-id (mail-header-id
8280                          (gnus-summary-article-header parent-article))))
8281         (unless (and message-id (not (equal message-id "")))
8282           (error "No message-id in desired parent"))
8283         ;; We don't want the article to be marked as read.
8284         (let (gnus-mark-article-hook)
8285           (gnus-summary-select-article t t nil current-article))
8286         (set-buffer gnus-original-article-buffer)
8287         (let ((buf (format "%s" (buffer-string))))
8288           (with-temp-buffer
8289             (insert buf)
8290             (goto-char (point-min))
8291             (if (re-search-forward "^References: " nil t)
8292                 (progn
8293                   (re-search-forward "^[^ \t]" nil t)
8294                   (forward-line -1)
8295                   (end-of-line)
8296                   (insert " " message-id))
8297               (insert "References: " message-id "\n"))
8298             (unless (gnus-request-replace-article
8299                      current-article (car gnus-article-current)
8300                      (current-buffer))
8301               (error "Couldn't replace article"))))
8302         (set-buffer gnus-summary-buffer)
8303         (gnus-summary-unmark-all-processable)
8304         (gnus-summary-update-article current-article)
8305         (gnus-summary-rethread-current)
8306         (gnus-message 3 "Article %d is now the child of article %d"
8307                       current-article parent-article)))))
8308
8309 (defun gnus-summary-toggle-threads (&optional arg)
8310   "Toggle showing conversation threads.
8311 If ARG is positive number, turn showing conversation threads on."
8312   (interactive "P")
8313   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8314     (setq gnus-show-threads
8315           (if (null arg) (not gnus-show-threads)
8316             (> (prefix-numeric-value arg) 0)))
8317     (gnus-summary-prepare)
8318     (gnus-summary-goto-subject current)
8319     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8320     (gnus-summary-position-point)))
8321
8322 (defun gnus-summary-show-all-threads ()
8323   "Show all threads."
8324   (interactive)
8325   (save-excursion
8326     (let ((buffer-read-only nil))
8327       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8328   (gnus-summary-position-point))
8329
8330 (defun gnus-summary-show-thread ()
8331   "Show thread subtrees.
8332 Returns nil if no thread was there to be shown."
8333   (interactive)
8334   (let ((buffer-read-only nil)
8335         (orig (point))
8336         ;; first goto end then to beg, to have point at beg after let
8337         (end (progn (end-of-line) (point)))
8338         (beg (progn (beginning-of-line) (point))))
8339     (prog1
8340         ;; Any hidden lines here?
8341         (search-forward "\r" end t)
8342       (subst-char-in-region beg end ?\^M ?\n t)
8343       (goto-char orig)
8344       (gnus-summary-position-point))))
8345
8346 (defun gnus-summary-hide-all-threads ()
8347   "Hide all thread subtrees."
8348   (interactive)
8349   (save-excursion
8350     (goto-char (point-min))
8351     (gnus-summary-hide-thread)
8352     (while (zerop (gnus-summary-next-thread 1 t))
8353       (gnus-summary-hide-thread)))
8354   (gnus-summary-position-point))
8355
8356 (defun gnus-summary-hide-thread ()
8357   "Hide thread subtrees.
8358 Returns nil if no threads were there to be hidden."
8359   (interactive)
8360   (let ((buffer-read-only nil)
8361         (start (point))
8362         (article (gnus-summary-article-number)))
8363     (goto-char start)
8364     ;; Go forward until either the buffer ends or the subthread
8365     ;; ends.
8366     (when (and (not (eobp))
8367                (or (zerop (gnus-summary-next-thread 1 t))
8368                    (goto-char (point-max))))
8369       (prog1
8370           (if (and (> (point) start)
8371                    (search-backward "\n" start t))
8372               (progn
8373                 (subst-char-in-region start (point) ?\n ?\^M)
8374                 (gnus-summary-goto-subject article))
8375             (goto-char start)
8376             nil)
8377         ;;(gnus-summary-position-point)
8378         ))))
8379
8380 (defun gnus-summary-go-to-next-thread (&optional previous)
8381   "Go to the same level (or less) next thread.
8382 If PREVIOUS is non-nil, go to previous thread instead.
8383 Return the article number moved to, or nil if moving was impossible."
8384   (let ((level (gnus-summary-thread-level))
8385         (way (if previous -1 1))
8386         (beg (point)))
8387     (forward-line way)
8388     (while (and (not (eobp))
8389                 (< level (gnus-summary-thread-level)))
8390       (forward-line way))
8391     (if (eobp)
8392         (progn
8393           (goto-char beg)
8394           nil)
8395       (setq beg (point))
8396       (prog1
8397           (gnus-summary-article-number)
8398         (goto-char beg)))))
8399
8400 (defun gnus-summary-next-thread (n &optional silent)
8401   "Go to the same level next N'th thread.
8402 If N is negative, search backward instead.
8403 Returns the difference between N and the number of skips actually
8404 done.
8405
8406 If SILENT, don't output messages."
8407   (interactive "p")
8408   (let ((backward (< n 0))
8409         (n (abs n)))
8410     (while (and (> n 0)
8411                 (gnus-summary-go-to-next-thread backward))
8412       (decf n))
8413     (unless silent
8414       (gnus-summary-position-point))
8415     (when (and (not silent) (/= 0 n))
8416       (gnus-message 7 "No more threads"))
8417     n))
8418
8419 (defun gnus-summary-prev-thread (n)
8420   "Go to the same level previous N'th thread.
8421 Returns the difference between N and the number of skips actually
8422 done."
8423   (interactive "p")
8424   (gnus-summary-next-thread (- n)))
8425
8426 (defun gnus-summary-go-down-thread ()
8427   "Go down one level in the current thread."
8428   (let ((children (gnus-summary-article-children)))
8429     (when children
8430       (gnus-summary-goto-subject (car children)))))
8431
8432 (defun gnus-summary-go-up-thread ()
8433   "Go up one level in the current thread."
8434   (let ((parent (gnus-summary-article-parent)))
8435     (when parent
8436       (gnus-summary-goto-subject parent))))
8437
8438 (defun gnus-summary-down-thread (n)
8439   "Go down thread N steps.
8440 If N is negative, go up instead.
8441 Returns the difference between N and how many steps down that were
8442 taken."
8443   (interactive "p")
8444   (let ((up (< n 0))
8445         (n (abs n)))
8446     (while (and (> n 0)
8447                 (if up (gnus-summary-go-up-thread)
8448                   (gnus-summary-go-down-thread)))
8449       (setq n (1- n)))
8450     (gnus-summary-position-point)
8451     (when (/= 0 n)
8452       (gnus-message 7 "Can't go further"))
8453     n))
8454
8455 (defun gnus-summary-up-thread (n)
8456   "Go up thread N steps.
8457 If N is negative, go up instead.
8458 Returns the difference between N and how many steps down that were
8459 taken."
8460   (interactive "p")
8461   (gnus-summary-down-thread (- n)))
8462
8463 (defun gnus-summary-top-thread ()
8464   "Go to the top of the thread."
8465   (interactive)
8466   (while (gnus-summary-go-up-thread))
8467   (gnus-summary-article-number))
8468
8469 (defun gnus-summary-kill-thread (&optional unmark)
8470   "Mark articles under current thread as read.
8471 If the prefix argument is positive, remove any kinds of marks.
8472 If the prefix argument is negative, tick articles instead."
8473   (interactive "P")
8474   (when unmark
8475     (setq unmark (prefix-numeric-value unmark)))
8476   (let ((articles (gnus-summary-articles-in-thread)))
8477     (save-excursion
8478       ;; Expand the thread.
8479       (gnus-summary-show-thread)
8480       ;; Mark all the articles.
8481       (while articles
8482         (gnus-summary-goto-subject (car articles))
8483         (cond ((null unmark)
8484                (gnus-summary-mark-article-as-read gnus-killed-mark))
8485               ((> unmark 0)
8486                (gnus-summary-mark-article-as-unread gnus-unread-mark))
8487               (t
8488                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8489         (setq articles (cdr articles))))
8490     ;; Hide killed subtrees.
8491     (and (null unmark)
8492          gnus-thread-hide-killed
8493          (gnus-summary-hide-thread))
8494     ;; If marked as read, go to next unread subject.
8495     (when (null unmark)
8496       ;; Go to next unread subject.
8497       (gnus-summary-next-subject 1 t)))
8498   (gnus-set-mode-line 'summary))
8499
8500 ;; Summary sorting commands
8501
8502 (defun gnus-summary-sort-by-number (&optional reverse)
8503   "Sort the summary buffer by article number.
8504 Argument REVERSE means reverse order."
8505   (interactive "P")
8506   (gnus-summary-sort 'number reverse))
8507
8508 (defun gnus-summary-sort-by-author (&optional reverse)
8509   "Sort the summary buffer by author name alphabetically.
8510 If case-fold-search is non-nil, case of letters is ignored.
8511 Argument REVERSE means reverse order."
8512   (interactive "P")
8513   (gnus-summary-sort 'author reverse))
8514
8515 (defun gnus-summary-sort-by-subject (&optional reverse)
8516   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
8517 If case-fold-search is non-nil, case of letters is ignored.
8518 Argument REVERSE means reverse order."
8519   (interactive "P")
8520   (gnus-summary-sort 'subject reverse))
8521
8522 (defun gnus-summary-sort-by-date (&optional reverse)
8523   "Sort the summary buffer by date.
8524 Argument REVERSE means reverse order."
8525   (interactive "P")
8526   (gnus-summary-sort 'date reverse))
8527
8528 (defun gnus-summary-sort-by-score (&optional reverse)
8529   "Sort the summary buffer by score.
8530 Argument REVERSE means reverse order."
8531   (interactive "P")
8532   (gnus-summary-sort 'score reverse))
8533
8534 (defun gnus-summary-sort-by-lines (&optional reverse)
8535   "Sort the summary buffer by article length.
8536 Argument REVERSE means reverse order."
8537   (interactive "P")
8538   (gnus-summary-sort 'lines reverse))
8539
8540 (defun gnus-summary-sort (predicate reverse)
8541   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8542   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8543          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8544          (gnus-thread-sort-functions
8545           (if (not reverse)
8546               thread
8547             `(lambda (t1 t2)
8548                (,thread t2 t1))))
8549          (gnus-article-sort-functions
8550           (if (not reverse)
8551               article
8552             `(lambda (t1 t2)
8553                (,article t2 t1))))
8554          (buffer-read-only)
8555          (gnus-summary-prepare-hook nil))
8556     ;; We do the sorting by regenerating the threads.
8557     (gnus-summary-prepare)
8558     ;; Hide subthreads if needed.
8559     (when (and gnus-show-threads gnus-thread-hide-subtree)
8560       (gnus-summary-hide-all-threads))))
8561
8562 ;; Summary saving commands.
8563
8564 (defun gnus-summary-save-article (&optional n not-saved)
8565   "Save the current article using the default saver function.
8566 If N is a positive number, save the N next articles.
8567 If N is a negative number, save the N previous articles.
8568 If N is nil and any articles have been marked with the process mark,
8569 save those articles instead.
8570 The variable `gnus-default-article-saver' specifies the saver function."
8571   (interactive "P")
8572   (let* ((articles (gnus-summary-work-articles n))
8573          (save-buffer (save-excursion
8574                         (nnheader-set-temp-buffer " *Gnus Save*")))
8575          (num (length articles))
8576          header article file)
8577     (while articles
8578       (setq header (gnus-summary-article-header
8579                     (setq article (pop articles))))
8580       (if (not (vectorp header))
8581           ;; This is a pseudo-article.
8582           (if (assq 'name header)
8583               (gnus-copy-file (cdr (assq 'name header)))
8584             (gnus-message 1 "Article %d is unsaveable" article))
8585         ;; This is a real article.
8586         (save-window-excursion
8587           (gnus-summary-select-article t nil nil article))
8588         (save-excursion
8589           (set-buffer save-buffer)
8590           (erase-buffer)
8591           (insert-buffer-substring gnus-original-article-buffer))
8592         (setq file (gnus-article-save save-buffer file num))
8593         (gnus-summary-remove-process-mark article)
8594         (unless not-saved
8595           (gnus-summary-set-saved-mark article))))
8596     (gnus-kill-buffer save-buffer)
8597     (gnus-summary-position-point)
8598     (gnus-set-mode-line 'summary)
8599     n))
8600
8601 (defun gnus-summary-pipe-output (&optional arg)
8602   "Pipe the current article to a subprocess.
8603 If N is a positive number, pipe the N next articles.
8604 If N is a negative number, pipe the N previous articles.
8605 If N is nil and any articles have been marked with the process mark,
8606 pipe those articles instead."
8607   (interactive "P")
8608   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8609     (gnus-summary-save-article arg t))
8610   (gnus-configure-windows 'pipe))
8611
8612 (defun gnus-summary-save-article-mail (&optional arg)
8613   "Append the current article to an mail file.
8614 If N is a positive number, save the N next articles.
8615 If N is a negative number, save the N previous articles.
8616 If N is nil and any articles have been marked with the process mark,
8617 save those articles instead."
8618   (interactive "P")
8619   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8620     (gnus-summary-save-article arg)))
8621
8622 (defun gnus-summary-save-article-rmail (&optional arg)
8623   "Append the current article to an rmail file.
8624 If N is a positive number, save the N next articles.
8625 If N is a negative number, save the N previous articles.
8626 If N is nil and any articles have been marked with the process mark,
8627 save those articles instead."
8628   (interactive "P")
8629   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
8630     (gnus-summary-save-article arg)))
8631
8632 (defun gnus-summary-save-article-file (&optional arg)
8633   "Append the current article to a file.
8634 If N is a positive number, save the N next articles.
8635 If N is a negative number, save the N previous articles.
8636 If N is nil and any articles have been marked with the process mark,
8637 save those articles instead."
8638   (interactive "P")
8639   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8640     (gnus-summary-save-article arg)))
8641
8642 (defun gnus-summary-write-article-file (&optional arg)
8643   "Write the current article to a file, deleting the previous file.
8644 If N is a positive number, save the N next articles.
8645 If N is a negative number, save the N previous articles.
8646 If N is nil and any articles have been marked with the process mark,
8647 save those articles instead."
8648   (interactive "P")
8649   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8650     (gnus-summary-save-article arg)))
8651
8652 (defun gnus-summary-save-article-body-file (&optional arg)
8653   "Append the current article body to a file.
8654 If N is a positive number, save the N next articles.
8655 If N is a negative number, save the N previous articles.
8656 If N is nil and any articles have been marked with the process mark,
8657 save those articles instead."
8658   (interactive "P")
8659   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8660     (gnus-summary-save-article arg)))
8661
8662 (defun gnus-summary-pipe-message (program)
8663   "Pipe the current article through PROGRAM."
8664   (interactive "sProgram: ")
8665   (gnus-summary-select-article)
8666   (let ((mail-header-separator ""))
8667     (gnus-eval-in-buffer-window gnus-article-buffer
8668       (save-restriction
8669         (widen)
8670         (let ((start (window-start))
8671               buffer-read-only)
8672           (message-pipe-buffer-body program)
8673           (set-window-start (get-buffer-window (current-buffer)) start))))))
8674
8675 (defun gnus-get-split-value (methods)
8676   "Return a value based on the split METHODS."
8677   (let (split-name method result match)
8678     (when methods
8679       (save-excursion
8680         (set-buffer gnus-original-article-buffer)
8681         (save-restriction
8682           (nnheader-narrow-to-headers)
8683           (while methods
8684             (goto-char (point-min))
8685             (setq method (pop methods))
8686             (setq match (car method))
8687             (when (cond
8688                    ((stringp match)
8689                     ;; Regular expression.
8690                     (ignore-errors
8691                       (re-search-forward match nil t)))
8692                    ((gnus-functionp match)
8693                     ;; Function.
8694                     (save-restriction
8695                       (widen)
8696                       (setq result (funcall match gnus-newsgroup-name))))
8697                    ((consp match)
8698                     ;; Form.
8699                     (save-restriction
8700                       (widen)
8701                       (setq result (eval match)))))
8702               (setq split-name (append (cdr method) split-name))
8703               (cond ((stringp result)
8704                      (push (expand-file-name
8705                             result gnus-article-save-directory)
8706                            split-name))
8707                     ((consp result)
8708                      (setq split-name (append result split-name)))))))))
8709     split-name))
8710
8711 (defun gnus-valid-move-group-p (group)
8712   (and (boundp group)
8713        (symbol-name group)
8714        (symbol-value group)
8715        (memq 'respool
8716              (assoc (symbol-name
8717                      (car (gnus-find-method-for-group
8718                            (symbol-name group))))
8719                     gnus-valid-select-methods))))
8720
8721 (defun gnus-read-move-group-name (prompt default articles prefix)
8722   "Read a group name."
8723   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
8724          (minibuffer-confirm-incomplete nil) ; XEmacs
8725          (prom
8726           (format "%s %s to:"
8727                   prompt
8728                   (if (> (length articles) 1)
8729                       (format "these %d articles" (length articles))
8730                     "this article")))
8731          (to-newsgroup
8732           (cond
8733            ((null split-name)
8734             (gnus-completing-read default prom
8735                                   gnus-active-hashtb
8736                                   'gnus-valid-move-group-p
8737                                   nil prefix
8738                                   'gnus-group-history))
8739            ((= 1 (length split-name))
8740             (gnus-completing-read (car split-name) prom
8741                                   gnus-active-hashtb
8742                                   'gnus-valid-move-group-p
8743                                   nil nil
8744                                   'gnus-group-history))
8745            (t
8746             (gnus-completing-read nil prom
8747                                   (mapcar (lambda (el) (list el))
8748                                           (nreverse split-name))
8749                                   nil nil nil
8750                                   'gnus-group-history)))))
8751     (when to-newsgroup
8752       (if (or (string= to-newsgroup "")
8753               (string= to-newsgroup prefix))
8754           (setq to-newsgroup default))
8755       (unless to-newsgroup
8756         (error "No group name entered"))
8757       (or (gnus-active to-newsgroup)
8758           (gnus-activate-group to-newsgroup)
8759           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
8760                                      to-newsgroup))
8761               (or (and (gnus-request-create-group
8762                         to-newsgroup (gnus-group-name-to-method to-newsgroup))
8763                        (gnus-activate-group to-newsgroup nil nil
8764                                             (gnus-group-name-to-method
8765                                              to-newsgroup)))
8766                   (error "Couldn't create group %s" to-newsgroup)))
8767           (error "No such group: %s" to-newsgroup)))
8768     to-newsgroup))
8769
8770 ;; Summary extract commands
8771
8772 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
8773   (let ((buffer-read-only nil)
8774         (article (gnus-summary-article-number))
8775         after-article b e)
8776     (unless (gnus-summary-goto-subject article)
8777       (error "No such article: %d" article))
8778     (gnus-summary-position-point)
8779     ;; If all commands are to be bunched up on one line, we collect
8780     ;; them here.
8781     (unless gnus-view-pseudos-separately
8782       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
8783             files action)
8784         (while ps
8785           (setq action (cdr (assq 'action (car ps))))
8786           (setq files (list (cdr (assq 'name (car ps)))))
8787           (while (and ps (cdr ps)
8788                       (string= (or action "1")
8789                                (or (cdr (assq 'action (cadr ps))) "2")))
8790             (push (cdr (assq 'name (cadr ps))) files)
8791             (setcdr ps (cddr ps)))
8792           (when files
8793             (when (not (string-match "%s" action))
8794               (push " " files))
8795             (push " " files)
8796             (when (assq 'execute (car ps))
8797               (setcdr (assq 'execute (car ps))
8798                       (funcall (if (string-match "%s" action)
8799                                    'format 'concat)
8800                                action
8801                                (mapconcat
8802                                 (lambda (f)
8803                                   (if (equal f " ")
8804                                       f
8805                                     (gnus-quote-arg-for-sh-or-csh f)))
8806                                 files " ")))))
8807           (setq ps (cdr ps)))))
8808     (if (and gnus-view-pseudos (not not-view))
8809         (while pslist
8810           (when (assq 'execute (car pslist))
8811             (gnus-execute-command (cdr (assq 'execute (car pslist)))
8812                                   (eq gnus-view-pseudos 'not-confirm)))
8813           (setq pslist (cdr pslist)))
8814       (save-excursion
8815         (while pslist
8816           (setq after-article (or (cdr (assq 'article (car pslist)))
8817                                   (gnus-summary-article-number)))
8818           (gnus-summary-goto-subject after-article)
8819           (forward-line 1)
8820           (setq b (point))
8821           (insert "    " (file-name-nondirectory
8822                           (cdr (assq 'name (car pslist))))
8823                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
8824           (setq e (point))
8825           (forward-line -1)             ; back to `b'
8826           (gnus-add-text-properties
8827            b (1- e) (list 'gnus-number gnus-reffed-article-number
8828                           gnus-mouse-face-prop gnus-mouse-face))
8829           (gnus-data-enter
8830            after-article gnus-reffed-article-number
8831            gnus-unread-mark b (car pslist) 0 (- e b))
8832           (push gnus-reffed-article-number gnus-newsgroup-unreads)
8833           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
8834           (setq pslist (cdr pslist)))))))
8835
8836 (defun gnus-pseudos< (p1 p2)
8837   (let ((c1 (cdr (assq 'action p1)))
8838         (c2 (cdr (assq 'action p2))))
8839     (and c1 c2 (string< c1 c2))))
8840
8841 (defun gnus-request-pseudo-article (props)
8842   (cond ((assq 'execute props)
8843          (gnus-execute-command (cdr (assq 'execute props)))))
8844   (let ((gnus-current-article (gnus-summary-article-number)))
8845     (gnus-run-hooks 'gnus-mark-article-hook)))
8846
8847 (defun gnus-execute-command (command &optional automatic)
8848   (save-excursion
8849     (gnus-article-setup-buffer)
8850     (set-buffer gnus-article-buffer)
8851     (setq buffer-read-only nil)
8852     (let ((command (if automatic command
8853                      (read-string "Command: " (cons command 0)))))
8854       (erase-buffer)
8855       (insert "$ " command "\n\n")
8856       (if gnus-view-pseudo-asynchronously
8857           (start-process "gnus-execute" (current-buffer) shell-file-name
8858                          shell-command-switch command)
8859         (call-process shell-file-name nil t nil
8860                       shell-command-switch command)))))
8861
8862 ;; Summary kill commands.
8863
8864 (defun gnus-summary-edit-global-kill (article)
8865   "Edit the \"global\" kill file."
8866   (interactive (list (gnus-summary-article-number)))
8867   (gnus-group-edit-global-kill article))
8868
8869 (defun gnus-summary-edit-local-kill ()
8870   "Edit a local kill file applied to the current newsgroup."
8871   (interactive)
8872   (setq gnus-current-headers (gnus-summary-article-header))
8873   (gnus-group-edit-local-kill
8874    (gnus-summary-article-number) gnus-newsgroup-name))
8875
8876 ;;; Header reading.
8877
8878 (defun gnus-read-header (id &optional header)
8879   "Read the headers of article ID and enter them into the Gnus system."
8880   (let ((group gnus-newsgroup-name)
8881         (gnus-override-method
8882          (and (gnus-news-group-p gnus-newsgroup-name)
8883               gnus-refer-article-method))
8884         where)
8885     ;; First we check to see whether the header in question is already
8886     ;; fetched.
8887     (if (stringp id)
8888         ;; This is a Message-ID.
8889         (setq header (or header (gnus-id-to-header id)))
8890       ;; This is an article number.
8891       (setq header (or header (gnus-summary-article-header id))))
8892     (if (and header
8893              (not (gnus-summary-article-sparse-p (mail-header-number header))))
8894         ;; We have found the header.
8895         header
8896       ;; If this is a sparse article, we have to nix out its
8897       ;; previous entry in the thread hashtb.
8898       (when (and header
8899                  (gnus-summary-article-sparse-p (mail-header-number header)))
8900         (let* ((parent (gnus-parent-id (mail-header-references header)))
8901                (thread (and parent (gnus-id-to-thread parent))))
8902           (when thread
8903             (delq (assq header thread) thread))))
8904       ;; We have to really fetch the header to this article.
8905       (save-excursion
8906         (set-buffer nntp-server-buffer)
8907         (when (setq where (gnus-request-head id group))
8908           (nnheader-fold-continuation-lines)
8909           (goto-char (point-max))
8910           (insert ".\n")
8911           (goto-char (point-min))
8912           (insert "211 ")
8913           (princ (cond
8914                   ((numberp id) id)
8915                   ((cdr where) (cdr where))
8916                   (header (mail-header-number header))
8917                   (t gnus-reffed-article-number))
8918                  (current-buffer))
8919           (insert " Article retrieved.\n"))
8920         (if (or (not where)
8921                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
8922             ()                          ; Malformed head.
8923           (unless (gnus-summary-article-sparse-p (mail-header-number header))
8924             (when (and (stringp id)
8925                        (not (string= (gnus-group-real-name group)
8926                                      (car where))))
8927               ;; If we fetched by Message-ID and the article came
8928               ;; from a different group, we fudge some bogus article
8929               ;; numbers for this article.
8930               (mail-header-set-number header gnus-reffed-article-number))
8931             (save-excursion
8932               (set-buffer gnus-summary-buffer)
8933               (decf gnus-reffed-article-number)
8934               (gnus-remove-header (mail-header-number header))
8935               (push header gnus-newsgroup-headers)
8936               (setq gnus-current-headers header)
8937               (push (mail-header-number header) gnus-newsgroup-limit)))
8938           header)))))
8939
8940 (defun gnus-remove-header (number)
8941   "Remove header NUMBER from `gnus-newsgroup-headers'."
8942   (if (and gnus-newsgroup-headers
8943            (= number (mail-header-number (car gnus-newsgroup-headers))))
8944       (pop gnus-newsgroup-headers)
8945     (let ((headers gnus-newsgroup-headers))
8946       (while (and (cdr headers)
8947                   (not (= number (mail-header-number (cadr headers)))))
8948         (pop headers))
8949       (when (cdr headers)
8950         (setcdr headers (cddr headers))))))
8951
8952 ;;;
8953 ;;; summary highlights
8954 ;;;
8955
8956 (defun gnus-highlight-selected-summary ()
8957   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
8958   ;; Highlight selected article in summary buffer
8959   (when gnus-summary-selected-face
8960     (save-excursion
8961       (let* ((beg (progn (beginning-of-line) (point)))
8962              (end (progn (end-of-line) (point)))
8963              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
8964              (from (if (get-text-property beg gnus-mouse-face-prop)
8965                        beg
8966                      (or (next-single-property-change
8967                           beg gnus-mouse-face-prop nil end)
8968                          beg)))
8969              (to
8970               (if (= from end)
8971                   (- from 2)
8972                 (or (next-single-property-change
8973                      from gnus-mouse-face-prop nil end)
8974                     end))))
8975         ;; If no mouse-face prop on line we will have to = from = end,
8976         ;; so we highlight the entire line instead.
8977         (when (= (+ to 2) from)
8978           (setq from beg)
8979           (setq to end))
8980         (if gnus-newsgroup-selected-overlay
8981             ;; Move old overlay.
8982             (gnus-move-overlay
8983              gnus-newsgroup-selected-overlay from to (current-buffer))
8984           ;; Create new overlay.
8985           (gnus-overlay-put
8986            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
8987            'face gnus-summary-selected-face))))))
8988
8989 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
8990 (defun gnus-summary-highlight-line ()
8991   "Highlight current line according to `gnus-summary-highlight'."
8992   (let* ((list gnus-summary-highlight)
8993          (p (point))
8994          (end (progn (end-of-line) (point)))
8995          ;; now find out where the line starts and leave point there.
8996          (beg (progn (beginning-of-line) (point)))
8997          (article (gnus-summary-article-number))
8998          (score (or (cdr (assq (or article gnus-current-article)
8999                                gnus-newsgroup-scored))
9000                     gnus-summary-default-score 0))
9001          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9002          (inhibit-read-only t))
9003     ;; Eval the cars of the lists until we find a match.
9004     (let ((default gnus-summary-default-score))
9005       (while (and list
9006                   (not (eval (caar list))))
9007         (setq list (cdr list))))
9008     (let ((face (cdar list)))
9009       (unless (eq face (get-text-property beg 'face))
9010         (gnus-put-text-property-excluding-characters-with-faces
9011          beg end 'face
9012          (setq face (if (boundp face) (symbol-value face) face)))
9013         (when gnus-summary-highlight-line-function
9014           (funcall gnus-summary-highlight-line-function article face))))
9015     (goto-char p)))
9016
9017 (defun gnus-update-read-articles (group unread &optional compute)
9018   "Update the list of read articles in GROUP."
9019   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9020          (entry (gnus-gethash group gnus-newsrc-hashtb))
9021          (info (nth 2 entry))
9022          (prev 1)
9023          (unread (sort (copy-sequence unread) '<))
9024          read)
9025     (if (or (not info) (not active))
9026         ;; There is no info on this group if it was, in fact,
9027         ;; killed.  Gnus stores no information on killed groups, so
9028         ;; there's nothing to be done.
9029         ;; One could store the information somewhere temporarily,
9030         ;; perhaps...  Hmmm...
9031         ()
9032       ;; Remove any negative articles numbers.
9033       (while (and unread (< (car unread) 0))
9034         (setq unread (cdr unread)))
9035       ;; Remove any expired article numbers
9036       (while (and unread (< (car unread) (car active)))
9037         (setq unread (cdr unread)))
9038       ;; Compute the ranges of read articles by looking at the list of
9039       ;; unread articles.
9040       (while unread
9041         (when (/= (car unread) prev)
9042           (push (if (= prev (1- (car unread))) prev
9043                   (cons prev (1- (car unread))))
9044                 read))
9045         (setq prev (1+ (car unread)))
9046         (setq unread (cdr unread)))
9047       (when (<= prev (cdr active))
9048         (push (cons prev (cdr active)) read))
9049       (setq read (if (> (length read) 1) (nreverse read) read))
9050       (if compute
9051           read
9052         (save-excursion
9053           (set-buffer gnus-group-buffer)
9054           (gnus-undo-register
9055             `(progn
9056                (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9057                (gnus-info-set-read ',info ',(gnus-info-read info))
9058                (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
9059                (gnus-group-update-group ,group t))))
9060         ;; Enter this list into the group info.
9061         (gnus-info-set-read info read)
9062         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9063         (gnus-get-unread-articles-in-group info (gnus-active group))
9064         t))))
9065
9066 (defun gnus-offer-save-summaries ()
9067   "Offer to save all active summary buffers."
9068   (save-excursion
9069     (let ((buflist (buffer-list))
9070           buffers bufname)
9071       ;; Go through all buffers and find all summaries.
9072       (while buflist
9073         (and (setq bufname (buffer-name (car buflist)))
9074              (string-match "Summary" bufname)
9075              (save-excursion
9076                (set-buffer bufname)
9077                ;; We check that this is, indeed, a summary buffer.
9078                (and (eq major-mode 'gnus-summary-mode)
9079                     ;; Also make sure this isn't bogus.
9080                     gnus-newsgroup-prepared
9081                     ;; Also make sure that this isn't a dead summary buffer.
9082                     (not gnus-dead-summary-mode)))
9083              (push bufname buffers))
9084         (setq buflist (cdr buflist)))
9085       ;; Go through all these summary buffers and offer to save them.
9086       (when buffers
9087         (map-y-or-n-p
9088          "Update summary buffer %s? "
9089          (lambda (buf)
9090            (switch-to-buffer buf)
9091            (gnus-summary-exit))
9092          buffers)))))
9093
9094
9095 ;;; @ for mime-partial
9096 ;;;
9097
9098 (defun gnus-request-partial-message ()
9099   (save-excursion
9100     (let ((number (gnus-summary-article-number))
9101           (group gnus-newsgroup-name)
9102           (mother gnus-article-buffer))
9103       (set-buffer (get-buffer-create " *Partial Article*"))
9104       (erase-buffer)
9105       (setq mime-preview-buffer mother)
9106       (gnus-request-article-this-buffer number group)
9107       (mime-parse-buffer)
9108       )))
9109
9110 (autoload 'mime-combine-message/partial-pieces-automatically
9111   "mime-partial"
9112   "Internal method to combine message/partial messages automatically.")
9113
9114 (mime-add-condition
9115  'action '((type . message)(subtype . partial)
9116            (major-mode . gnus-original-article-mode)
9117            (method . mime-combine-message/partial-pieces-automatically)
9118            (summary-buffer-exp . gnus-summary-buffer)
9119            (request-partial-message-method . gnus-request-partial-message)
9120            ))
9121
9122
9123 ;;; @ end
9124 ;;;
9125
9126 (gnus-ems-redefine)
9127
9128 (provide 'gnus-sum)
9129
9130 (run-hooks 'gnus-sum-load-hook)
9131
9132 ;;; gnus-sum.el ends here