Sync up with pgnus-0.53
[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 (defcustom gnus-newsgroup-coding-system-alist 
814   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" . cn-big5)
815     ("^cn\\>\\|\\<chinese\\>" . cn-gb-2312)
816     ("^fj\\>" . iso-2022-jp-2)
817     ("^relcom\\>" . koi8-r))
818   "Alist of Regexps (to match group names) and CODING-SYSTEMs to be applied."
819   :type '(repeat (cons (regexp :tag "Group")
820                        (symbol :tag "Charset")))
821   :group 'gnus)
822
823 (defcustom gnus-newsgroup-iso-8859-1-forced-regexp 
824   "^tw\\>\\|^hk\\>\\|^cn\\>\\|\\<chinese\\>"
825   "Regexp of newsgroup in which ISO-8859-1 is forced to other charset."
826   :type 'regexp
827   :group 'gnus)
828
829 ;;; Internal variables
830
831 (defvar gnus-scores-exclude-files nil)
832 (defvar gnus-page-broken nil)
833
834 (defvar gnus-original-article nil)
835 (defvar gnus-article-internal-prepare-hook nil)
836 (defvar gnus-newsgroup-process-stack nil)
837
838 (defvar gnus-thread-indent-array nil)
839 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
840
841 ;; Avoid highlighting in kill files.
842 (defvar gnus-summary-inhibit-highlight nil)
843 (defvar gnus-newsgroup-selected-overlay nil)
844 (defvar gnus-inhibit-limiting nil)
845 (defvar gnus-newsgroup-adaptive-score-file nil)
846 (defvar gnus-current-score-file nil)
847 (defvar gnus-current-move-group nil)
848 (defvar gnus-current-copy-group nil)
849 (defvar gnus-current-crosspost-group nil)
850
851 (defvar gnus-newsgroup-dependencies nil)
852 (defvar gnus-newsgroup-adaptive nil)
853 (defvar gnus-summary-display-article-function nil)
854 (defvar gnus-summary-highlight-line-function nil
855   "Function called after highlighting a summary line.")
856
857 (defvar gnus-summary-line-format-alist
858   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
859     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
860     (?s gnus-tmp-subject-or-nil ?s)
861     (?n gnus-tmp-name ?s)
862     (?A (std11-address-string
863          (car (mime-read-field 'From gnus-tmp-header))) ?s)
864     (?a (or (std11-full-name-string
865              (car (mime-read-field 'From gnus-tmp-header)))
866             gnus-tmp-from) ?s)
867     (?F gnus-tmp-from ?s)
868     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
869     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
870     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
871     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
872     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
873     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
874     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
875     (?L gnus-tmp-lines ?d)
876     (?I gnus-tmp-indentation ?s)
877     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
878     (?R gnus-tmp-replied ?c)
879     (?\[ gnus-tmp-opening-bracket ?c)
880     (?\] gnus-tmp-closing-bracket ?c)
881     (?\> (make-string gnus-tmp-level ? ) ?s)
882     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
883     (?i gnus-tmp-score ?d)
884     (?z gnus-tmp-score-char ?c)
885     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
886     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
887     (?U gnus-tmp-unread ?c)
888     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
889     (?t (gnus-summary-number-of-articles-in-thread
890          (and (boundp 'thread) (car thread)) gnus-tmp-level)
891         ?d)
892     (?e (gnus-summary-number-of-articles-in-thread
893          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
894         ?c)
895     (?u gnus-tmp-user-defined ?s)
896     (?P (gnus-pick-line-number) ?d))
897   "An alist of format specifications that can appear in summary lines,
898 and what variables they correspond with, along with the type of the
899 variable (string, integer, character, etc).")
900
901 (defvar gnus-summary-dummy-line-format-alist
902   `((?S gnus-tmp-subject ?s)
903     (?N gnus-tmp-number ?d)
904     (?u gnus-tmp-user-defined ?s)))
905
906 (defvar gnus-summary-mode-line-format-alist
907   `((?G gnus-tmp-group-name ?s)
908     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
909     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
910     (?A gnus-tmp-article-number ?d)
911     (?Z gnus-tmp-unread-and-unselected ?s)
912     (?V gnus-version ?s)
913     (?U gnus-tmp-unread-and-unticked ?d)
914     (?S gnus-tmp-subject ?s)
915     (?e gnus-tmp-unselected ?d)
916     (?u gnus-tmp-user-defined ?s)
917     (?d (length gnus-newsgroup-dormant) ?d)
918     (?t (length gnus-newsgroup-marked) ?d)
919     (?r (length gnus-newsgroup-reads) ?d)
920     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
921     (?E gnus-newsgroup-expunged-tally ?d)
922     (?s (gnus-current-score-file-nondirectory) ?s)))
923
924 (defvar gnus-last-search-regexp nil
925   "Default regexp for article search command.")
926
927 (defvar gnus-last-shell-command nil
928   "Default shell command on article.")
929
930 (defvar gnus-newsgroup-begin nil)
931 (defvar gnus-newsgroup-end nil)
932 (defvar gnus-newsgroup-last-rmail nil)
933 (defvar gnus-newsgroup-last-mail nil)
934 (defvar gnus-newsgroup-last-folder nil)
935 (defvar gnus-newsgroup-last-file nil)
936 (defvar gnus-newsgroup-auto-expire nil)
937 (defvar gnus-newsgroup-active nil)
938
939 (defvar gnus-newsgroup-data nil)
940 (defvar gnus-newsgroup-data-reverse nil)
941 (defvar gnus-newsgroup-limit nil)
942 (defvar gnus-newsgroup-limits nil)
943
944 (defvar gnus-newsgroup-unreads nil
945   "List of unread articles in the current newsgroup.")
946
947 (defvar gnus-newsgroup-unselected nil
948   "List of unselected unread articles in the current newsgroup.")
949
950 (defvar gnus-newsgroup-reads nil
951   "Alist of read articles and article marks in the current newsgroup.")
952
953 (defvar gnus-newsgroup-expunged-tally nil)
954
955 (defvar gnus-newsgroup-marked nil
956   "List of ticked articles in the current newsgroup (a subset of unread art).")
957
958 (defvar gnus-newsgroup-killed nil
959   "List of ranges of articles that have been through the scoring process.")
960
961 (defvar gnus-newsgroup-cached nil
962   "List of articles that come from the article cache.")
963
964 (defvar gnus-newsgroup-saved nil
965   "List of articles that have been saved.")
966
967 (defvar gnus-newsgroup-kill-headers nil)
968
969 (defvar gnus-newsgroup-replied nil
970   "List of articles that have been replied to in the current newsgroup.")
971
972 (defvar gnus-newsgroup-expirable nil
973   "List of articles in the current newsgroup that can be expired.")
974
975 (defvar gnus-newsgroup-processable nil
976   "List of articles in the current newsgroup that can be processed.")
977
978 (defvar gnus-newsgroup-downloadable nil
979   "List of articles in the current newsgroup that can be processed.")
980
981 (defvar gnus-newsgroup-undownloaded nil
982   "List of articles in the current newsgroup that haven't been downloaded..")
983
984 (defvar gnus-newsgroup-unsendable nil
985   "List of articles in the current newsgroup that won't be sent.")
986
987 (defvar gnus-newsgroup-bookmarks nil
988   "List of articles in the current newsgroup that have bookmarks.")
989
990 (defvar gnus-newsgroup-dormant nil
991   "List of dormant articles in the current newsgroup.")
992
993 (defvar gnus-newsgroup-scored nil
994   "List of scored articles in the current newsgroup.")
995
996 (defvar gnus-newsgroup-headers nil
997   "List of article headers in the current newsgroup.")
998
999 (defvar gnus-newsgroup-threads nil)
1000
1001 (defvar gnus-newsgroup-prepared nil
1002   "Whether the current group has been prepared properly.")
1003
1004 (defvar gnus-newsgroup-ancient nil
1005   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1006
1007 (defvar gnus-newsgroup-sparse nil)
1008
1009 (defvar gnus-current-article nil)
1010 (defvar gnus-article-current nil)
1011 (defvar gnus-current-headers nil)
1012 (defvar gnus-have-all-headers nil)
1013 (defvar gnus-last-article nil)
1014 (defvar gnus-newsgroup-history nil)
1015
1016 (defvar gnus-newsgroup-coding-system nil)
1017 (defvar gnus-newsgroup-iso-8859-1-forced nil)
1018
1019 (defconst gnus-summary-local-variables
1020   '(gnus-newsgroup-name
1021     gnus-newsgroup-begin gnus-newsgroup-end
1022     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1023     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1024     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1025     gnus-newsgroup-unselected gnus-newsgroup-marked
1026     gnus-newsgroup-reads gnus-newsgroup-saved
1027     gnus-newsgroup-replied gnus-newsgroup-expirable
1028     gnus-newsgroup-processable gnus-newsgroup-killed
1029     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1030     gnus-newsgroup-unsendable
1031     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1032     gnus-newsgroup-headers gnus-newsgroup-threads
1033     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1034     gnus-current-article gnus-current-headers gnus-have-all-headers
1035     gnus-last-article gnus-article-internal-prepare-hook
1036     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1037     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1038     gnus-thread-expunge-below
1039     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1040     (gnus-summary-mark-below . global)
1041     gnus-newsgroup-active gnus-scores-exclude-files
1042     gnus-newsgroup-history gnus-newsgroup-ancient
1043     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1044     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1045     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1046     (gnus-newsgroup-expunged-tally . 0)
1047     gnus-cache-removable-articles gnus-newsgroup-cached
1048     gnus-newsgroup-data gnus-newsgroup-data-reverse
1049     gnus-newsgroup-limit gnus-newsgroup-limits
1050     gnus-newsgroup-coding-system gnus-newsgroup-iso-8859-1-forced)
1051   "Variables that are buffer-local to the summary buffers.")
1052
1053 ;; Byte-compiler warning.
1054 (defvar gnus-article-mode-map)
1055
1056 ;; Subject simplification.
1057
1058 (defun gnus-simplify-whitespace (str)
1059   "Remove excessive whitespace."
1060   (let ((mystr str))
1061     ;; Multiple spaces.
1062     (while (string-match "[ \t][ \t]+" mystr)
1063       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1064                           " "
1065                           (substring mystr (match-end 0)))))
1066     ;; Leading spaces.
1067     (when (string-match "^[ \t]+" mystr)
1068       (setq mystr (substring mystr (match-end 0))))
1069     ;; Trailing spaces.
1070     (when (string-match "[ \t]+$" mystr)
1071       (setq mystr (substring mystr 0 (match-beginning 0))))
1072     mystr))
1073
1074 (defsubst gnus-simplify-subject-re (subject)
1075   "Remove \"Re:\" from subject lines."
1076   (if (string-match "^[Rr][Ee]: *" subject)
1077       (substring subject (match-end 0))
1078     subject))
1079
1080 (defun gnus-simplify-subject (subject &optional re-only)
1081   "Remove `Re:' and words in parentheses.
1082 If RE-ONLY is non-nil, strip leading `Re:'s only."
1083   (let ((case-fold-search t))           ;Ignore case.
1084     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1085     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1086       (setq subject (substring subject (match-end 0))))
1087     ;; Remove uninteresting prefixes.
1088     (when (and (not re-only)
1089                gnus-simplify-ignored-prefixes
1090                (string-match gnus-simplify-ignored-prefixes subject))
1091       (setq subject (substring subject (match-end 0))))
1092     ;; Remove words in parentheses from end.
1093     (unless re-only
1094       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1095         (setq subject (substring subject 0 (match-beginning 0)))))
1096     ;; Return subject string.
1097     subject))
1098
1099 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1100 ;; all whitespace.
1101 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1102   (goto-char (point-min))
1103   (while (re-search-forward regexp nil t)
1104       (replace-match (or newtext ""))))
1105
1106 (defun gnus-simplify-buffer-fuzzy ()
1107   "Simplify string in the buffer fuzzily.
1108 The string in the accessible portion of the current buffer is simplified.
1109 It is assumed to be a single-line subject.
1110 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1111 matter is removed.  Additional things can be deleted by setting
1112 gnus-simplify-subject-fuzzy-regexp."
1113   (let ((case-fold-search t)
1114         (modified-tick))
1115     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1116
1117     (while (not (eq modified-tick (buffer-modified-tick)))
1118       (setq modified-tick (buffer-modified-tick))
1119       (cond
1120        ((listp gnus-simplify-subject-fuzzy-regexp)
1121         (mapcar 'gnus-simplify-buffer-fuzzy-step
1122                 gnus-simplify-subject-fuzzy-regexp))
1123        (gnus-simplify-subject-fuzzy-regexp
1124         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1125       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1126       (gnus-simplify-buffer-fuzzy-step
1127        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1128       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1129
1130     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1131     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1132     (gnus-simplify-buffer-fuzzy-step " $")
1133     (gnus-simplify-buffer-fuzzy-step "^ +")))
1134
1135 (defun gnus-simplify-subject-fuzzy (subject)
1136   "Simplify a subject string fuzzily.
1137 See `gnus-simplify-buffer-fuzzy' for details."
1138   (save-excursion
1139     (gnus-set-work-buffer)
1140     (let ((case-fold-search t))
1141       ;; Remove uninteresting prefixes.
1142       (when (and gnus-simplify-ignored-prefixes
1143                  (string-match gnus-simplify-ignored-prefixes subject))
1144         (setq subject (substring subject (match-end 0))))
1145       (insert subject)
1146       (inline (gnus-simplify-buffer-fuzzy))
1147       (buffer-string))))
1148
1149 (defsubst gnus-simplify-subject-fully (subject)
1150   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1151   (cond
1152    (gnus-simplify-subject-functions
1153     (gnus-map-function gnus-simplify-subject-functions subject))
1154    ((null gnus-summary-gather-subject-limit)
1155     (gnus-simplify-subject-re subject))
1156    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1157     (gnus-simplify-subject-fuzzy subject))
1158    ((numberp gnus-summary-gather-subject-limit)
1159     (gnus-limit-string (gnus-simplify-subject-re subject)
1160                        gnus-summary-gather-subject-limit))
1161    (t
1162     subject)))
1163
1164 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1165   "Check whether two subjects are equal.
1166 If optional argument simple-first is t, first argument is already
1167 simplified."
1168   (cond
1169    ((null simple-first)
1170     (equal (gnus-simplify-subject-fully s1)
1171            (gnus-simplify-subject-fully s2)))
1172    (t
1173     (equal s1
1174            (gnus-simplify-subject-fully s2)))))
1175
1176 (defun gnus-summary-bubble-group ()
1177   "Increase the score of the current group.
1178 This is a handy function to add to `gnus-summary-exit-hook' to
1179 increase the score of each group you read."
1180   (gnus-group-add-score gnus-newsgroup-name))
1181
1182 \f
1183 ;;;
1184 ;;; Gnus summary mode
1185 ;;;
1186
1187 (put 'gnus-summary-mode 'mode-class 'special)
1188
1189 (when t
1190   ;; Non-orthogonal keys
1191
1192   (gnus-define-keys gnus-summary-mode-map
1193     " " gnus-summary-next-page
1194     "\177" gnus-summary-prev-page
1195     [delete] gnus-summary-prev-page
1196     [backspace] gnus-summary-prev-page
1197     "\r" gnus-summary-scroll-up
1198     "\M-\r" gnus-summary-scroll-down
1199     "n" gnus-summary-next-unread-article
1200     "p" gnus-summary-prev-unread-article
1201     "N" gnus-summary-next-article
1202     "P" gnus-summary-prev-article
1203     "\M-\C-n" gnus-summary-next-same-subject
1204     "\M-\C-p" gnus-summary-prev-same-subject
1205     "\M-n" gnus-summary-next-unread-subject
1206     "\M-p" gnus-summary-prev-unread-subject
1207     "." gnus-summary-first-unread-article
1208     "," gnus-summary-best-unread-article
1209     "\M-s" gnus-summary-search-article-forward
1210     "\M-r" gnus-summary-search-article-backward
1211     "<" gnus-summary-beginning-of-article
1212     ">" gnus-summary-end-of-article
1213     "j" gnus-summary-goto-article
1214     "^" gnus-summary-refer-parent-article
1215     "\M-^" gnus-summary-refer-article
1216     "u" gnus-summary-tick-article-forward
1217     "!" gnus-summary-tick-article-forward
1218     "U" gnus-summary-tick-article-backward
1219     "d" gnus-summary-mark-as-read-forward
1220     "D" gnus-summary-mark-as-read-backward
1221     "E" gnus-summary-mark-as-expirable
1222     "\M-u" gnus-summary-clear-mark-forward
1223     "\M-U" gnus-summary-clear-mark-backward
1224     "k" gnus-summary-kill-same-subject-and-select
1225     "\C-k" gnus-summary-kill-same-subject
1226     "\M-\C-k" gnus-summary-kill-thread
1227     "\M-\C-l" gnus-summary-lower-thread
1228     "e" gnus-summary-edit-article
1229     "#" gnus-summary-mark-as-processable
1230     "\M-#" gnus-summary-unmark-as-processable
1231     "\M-\C-t" gnus-summary-toggle-threads
1232     "\M-\C-s" gnus-summary-show-thread
1233     "\M-\C-h" gnus-summary-hide-thread
1234     "\M-\C-f" gnus-summary-next-thread
1235     "\M-\C-b" gnus-summary-prev-thread
1236     "\M-\C-u" gnus-summary-up-thread
1237     "\M-\C-d" gnus-summary-down-thread
1238     "&" gnus-summary-execute-command
1239     "c" gnus-summary-catchup-and-exit
1240     "\C-w" gnus-summary-mark-region-as-read
1241     "\C-t" gnus-summary-toggle-truncation
1242     "?" gnus-summary-mark-as-dormant
1243     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1244     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1245     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1246     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1247     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1248     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1249     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1250     "=" gnus-summary-expand-window
1251     "\C-x\C-s" gnus-summary-reselect-current-group
1252     "\M-g" gnus-summary-rescan-group
1253     "w" gnus-summary-stop-page-breaking
1254     "\C-c\C-r" gnus-summary-caesar-message
1255     "\M-t" gnus-summary-toggle-mime
1256     "f" gnus-summary-followup
1257     "F" gnus-summary-followup-with-original
1258     "C" gnus-summary-cancel-article
1259     "r" gnus-summary-reply
1260     "R" gnus-summary-reply-with-original
1261     "\C-c\C-f" gnus-summary-mail-forward
1262     "o" gnus-summary-save-article
1263     "\C-o" gnus-summary-save-article-mail
1264     "|" gnus-summary-pipe-output
1265     "\M-k" gnus-summary-edit-local-kill
1266     "\M-K" gnus-summary-edit-global-kill
1267     ;; "V" gnus-version
1268     "\C-c\C-d" gnus-summary-describe-group
1269     "q" gnus-summary-exit
1270     "Q" gnus-summary-exit-no-update
1271     "\C-c\C-i" gnus-info-find-node
1272     gnus-mouse-2 gnus-mouse-pick-article
1273     "m" gnus-summary-mail-other-window
1274     "a" gnus-summary-post-news
1275     "x" gnus-summary-limit-to-unread
1276     "s" gnus-summary-isearch-article
1277     "t" gnus-article-hide-headers
1278     "g" gnus-summary-show-article
1279     "l" gnus-summary-goto-last-article
1280     "v" gnus-summary-preview-mime-message
1281     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1282     "\C-d" gnus-summary-enter-digest-group
1283     "\M-\C-d" gnus-summary-read-document
1284     "\M-\C-e" gnus-summary-edit-parameters
1285     "\M-\C-g" gnus-summary-customize-parameters
1286     "\C-c\C-b" gnus-bug
1287     "*" gnus-cache-enter-article
1288     "\M-*" gnus-cache-remove-article
1289     "\M-&" gnus-summary-universal-argument
1290     "\C-l" gnus-recenter
1291     "I" gnus-summary-increase-score
1292     "L" gnus-summary-lower-score
1293     "\M-i" gnus-symbolic-argument
1294     "h" gnus-summary-select-article-buffer
1295     
1296     "V" gnus-summary-score-map
1297     "X" gnus-uu-extract-map
1298     "S" gnus-summary-send-map)
1299
1300   ;; Sort of orthogonal keymap
1301   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1302     "t" gnus-summary-tick-article-forward
1303     "!" gnus-summary-tick-article-forward
1304     "d" gnus-summary-mark-as-read-forward
1305     "r" gnus-summary-mark-as-read-forward
1306     "c" gnus-summary-clear-mark-forward
1307     " " gnus-summary-clear-mark-forward
1308     "e" gnus-summary-mark-as-expirable
1309     "x" gnus-summary-mark-as-expirable
1310     "?" gnus-summary-mark-as-dormant
1311     "b" gnus-summary-set-bookmark
1312     "B" gnus-summary-remove-bookmark
1313     "#" gnus-summary-mark-as-processable
1314     "\M-#" gnus-summary-unmark-as-processable
1315     "S" gnus-summary-limit-include-expunged
1316     "C" gnus-summary-catchup
1317     "H" gnus-summary-catchup-to-here
1318     "\C-c" gnus-summary-catchup-all
1319     "k" gnus-summary-kill-same-subject-and-select
1320     "K" gnus-summary-kill-same-subject
1321     "P" gnus-uu-mark-map)
1322
1323   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1324     "c" gnus-summary-clear-above
1325     "u" gnus-summary-tick-above
1326     "m" gnus-summary-mark-above
1327     "k" gnus-summary-kill-below)
1328
1329   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1330     "/" gnus-summary-limit-to-subject
1331     "n" gnus-summary-limit-to-articles
1332     "w" gnus-summary-pop-limit
1333     "s" gnus-summary-limit-to-subject
1334     "a" gnus-summary-limit-to-author
1335     "u" gnus-summary-limit-to-unread
1336     "m" gnus-summary-limit-to-marks
1337     "v" gnus-summary-limit-to-score
1338     "*" gnus-summary-limit-include-cached
1339     "D" gnus-summary-limit-include-dormant
1340     "T" gnus-summary-limit-include-thread
1341     "d" gnus-summary-limit-exclude-dormant
1342     "t" gnus-summary-limit-to-age
1343     "E" gnus-summary-limit-include-expunged
1344     "c" gnus-summary-limit-exclude-childless-dormant
1345     "C" gnus-summary-limit-mark-excluded-as-read)
1346
1347   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1348     "n" gnus-summary-next-unread-article
1349     "p" gnus-summary-prev-unread-article
1350     "N" gnus-summary-next-article
1351     "P" gnus-summary-prev-article
1352     "\C-n" gnus-summary-next-same-subject
1353     "\C-p" gnus-summary-prev-same-subject
1354     "\M-n" gnus-summary-next-unread-subject
1355     "\M-p" gnus-summary-prev-unread-subject
1356     "f" gnus-summary-first-unread-article
1357     "b" gnus-summary-best-unread-article
1358     "j" gnus-summary-goto-article
1359     "g" gnus-summary-goto-subject
1360     "l" gnus-summary-goto-last-article
1361     "o" gnus-summary-pop-article)
1362
1363   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1364     "k" gnus-summary-kill-thread
1365     "l" gnus-summary-lower-thread
1366     "i" gnus-summary-raise-thread
1367     "T" gnus-summary-toggle-threads
1368     "t" gnus-summary-rethread-current
1369     "^" gnus-summary-reparent-thread
1370     "s" gnus-summary-show-thread
1371     "S" gnus-summary-show-all-threads
1372     "h" gnus-summary-hide-thread
1373     "H" gnus-summary-hide-all-threads
1374     "n" gnus-summary-next-thread
1375     "p" gnus-summary-prev-thread
1376     "u" gnus-summary-up-thread
1377     "o" gnus-summary-top-thread
1378     "d" gnus-summary-down-thread
1379     "#" gnus-uu-mark-thread
1380     "\M-#" gnus-uu-unmark-thread)
1381
1382   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1383     "g" gnus-summary-prepare
1384     "c" gnus-summary-insert-cached-articles)
1385
1386   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1387     "c" gnus-summary-catchup-and-exit
1388     "C" gnus-summary-catchup-all-and-exit
1389     "E" gnus-summary-exit-no-update
1390     "Q" gnus-summary-exit
1391     "Z" gnus-summary-exit
1392     "n" gnus-summary-catchup-and-goto-next-group
1393     "R" gnus-summary-reselect-current-group
1394     "G" gnus-summary-rescan-group
1395     "N" gnus-summary-next-group
1396     "s" gnus-summary-save-newsrc
1397     "P" gnus-summary-prev-group)
1398
1399   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1400     " " gnus-summary-next-page
1401     "n" gnus-summary-next-page
1402     "\177" gnus-summary-prev-page
1403     [delete] gnus-summary-prev-page
1404     "p" gnus-summary-prev-page
1405     "\r" gnus-summary-scroll-up
1406     "\M-\r" gnus-summary-scroll-down
1407     "<" gnus-summary-beginning-of-article
1408     ">" gnus-summary-end-of-article
1409     "b" gnus-summary-beginning-of-article
1410     "e" gnus-summary-end-of-article
1411     "^" gnus-summary-refer-parent-article
1412     "r" gnus-summary-refer-parent-article
1413     "R" gnus-summary-refer-references
1414     "T" gnus-summary-refer-thread
1415     "g" gnus-summary-show-article
1416     "s" gnus-summary-isearch-article
1417     "P" gnus-summary-print-article)
1418
1419   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1420     "b" gnus-article-add-buttons
1421     "B" gnus-article-add-buttons-to-head
1422     "o" gnus-article-treat-overstrike
1423     "e" gnus-article-emphasize
1424     "w" gnus-article-fill-cited-article
1425     "c" gnus-article-remove-cr
1426     "f" gnus-article-display-x-face
1427     "l" gnus-summary-stop-page-breaking
1428     "r" gnus-summary-caesar-message
1429     "t" gnus-article-hide-headers
1430     "v" gnus-summary-verbose-headers
1431     "m" gnus-summary-toggle-mime
1432     "h" gnus-article-treat-html
1433     "d" gnus-article-treat-dumbquotes)
1434
1435   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1436     "a" gnus-article-hide
1437     "h" gnus-article-hide-headers
1438     "b" gnus-article-hide-boring-headers
1439     "s" gnus-article-hide-signature
1440     "c" gnus-article-hide-citation
1441     "C" gnus-article-hide-citation-in-followups
1442     "p" gnus-article-hide-pgp
1443     "P" gnus-article-hide-pem
1444     "\C-c" gnus-article-hide-citation-maybe)
1445
1446   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1447     "a" gnus-article-highlight
1448     "h" gnus-article-highlight-headers
1449     "c" gnus-article-highlight-citation
1450     "s" gnus-article-highlight-signature)
1451
1452   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1453     "z" gnus-article-date-ut
1454     "u" gnus-article-date-ut
1455     "l" gnus-article-date-local
1456     "e" gnus-article-date-lapsed
1457     "o" gnus-article-date-original
1458     "i" gnus-article-date-iso8601
1459     "s" gnus-article-date-user)
1460
1461   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1462     "t" gnus-article-remove-trailing-blank-lines
1463     "l" gnus-article-strip-leading-blank-lines
1464     "m" gnus-article-strip-multiple-blank-lines
1465     "a" gnus-article-strip-blank-lines
1466     "A" gnus-article-strip-all-blank-lines
1467     "s" gnus-article-strip-leading-space)
1468
1469   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1470     "v" gnus-version
1471     "f" gnus-summary-fetch-faq
1472     "d" gnus-summary-describe-group
1473     "h" gnus-summary-describe-briefly
1474     "i" gnus-info-find-node)
1475
1476   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1477     "e" gnus-summary-expire-articles
1478     "\M-\C-e" gnus-summary-expire-articles-now
1479     "\177" gnus-summary-delete-article
1480     [delete] gnus-summary-delete-article
1481     "m" gnus-summary-move-article
1482     "r" gnus-summary-respool-article
1483     "w" gnus-summary-edit-article
1484     "c" gnus-summary-copy-article
1485     "B" gnus-summary-crosspost-article
1486     "q" gnus-summary-respool-query
1487     "t" gnus-summary-respool-trace
1488     "i" gnus-summary-import-article
1489     "p" gnus-summary-article-posted-p)
1490
1491   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1492     "o" gnus-summary-save-article
1493     "m" gnus-summary-save-article-mail
1494     "F" gnus-summary-write-article-file
1495     "r" gnus-summary-save-article-rmail
1496     "f" gnus-summary-save-article-file
1497     "b" gnus-summary-save-article-body-file
1498     "h" gnus-summary-save-article-folder
1499     "v" gnus-summary-save-article-vm
1500     "p" gnus-summary-pipe-output
1501     "s" gnus-soup-add-article)
1502
1503   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1504     "b" gnus-summary-display-buttonized)
1505   )
1506
1507 (defun gnus-summary-make-menu-bar ()
1508   (gnus-turn-off-edit-menu 'summary)
1509
1510   (unless (boundp 'gnus-summary-misc-menu)
1511
1512     (easy-menu-define
1513      gnus-summary-kill-menu gnus-summary-mode-map ""
1514      (cons
1515       "Score"
1516       (nconc
1517        (list
1518         ["Enter score..." gnus-summary-score-entry t]
1519         ["Customize" gnus-score-customize t])
1520        (gnus-make-score-map 'increase)
1521        (gnus-make-score-map 'lower)
1522        '(("Mark"
1523           ["Kill below" gnus-summary-kill-below t]
1524           ["Mark above" gnus-summary-mark-above t]
1525           ["Tick above" gnus-summary-tick-above t]
1526           ["Clear above" gnus-summary-clear-above t])
1527          ["Current score" gnus-summary-current-score t]
1528          ["Set score" gnus-summary-set-score t]
1529          ["Switch current score file..." gnus-score-change-score-file t]
1530          ["Set mark below..." gnus-score-set-mark-below t]
1531          ["Set expunge below..." gnus-score-set-expunge-below t]
1532          ["Edit current score file" gnus-score-edit-current-scores t]
1533          ["Edit score file" gnus-score-edit-file t]
1534          ["Trace score" gnus-score-find-trace t]
1535          ["Find words" gnus-score-find-favourite-words t]
1536          ["Rescore buffer" gnus-summary-rescore t]
1537          ["Increase score..." gnus-summary-increase-score t]
1538          ["Lower score..." gnus-summary-lower-score t]))))
1539
1540     ;; Define both the Article menu in the summary buffer and the equivalent
1541     ;; Commands menu in the article buffer here for consistency.
1542     (let ((innards
1543            '(("Hide"
1544               ["All" gnus-article-hide t]
1545               ["Headers" gnus-article-hide-headers t]
1546               ["Signature" gnus-article-hide-signature t]
1547               ["Citation" gnus-article-hide-citation t]
1548               ["PGP" gnus-article-hide-pgp t]
1549               ["Boring headers" gnus-article-hide-boring-headers t])
1550              ("Highlight"
1551               ["All" gnus-article-highlight t]
1552               ["Headers" gnus-article-highlight-headers t]
1553               ["Signature" gnus-article-highlight-signature t]
1554               ["Citation" gnus-article-highlight-citation t])
1555              ("Date"
1556               ["Local" gnus-article-date-local t]
1557               ["ISO8601" gnus-article-date-iso8601 t]
1558               ["UT" gnus-article-date-ut t]
1559               ["Original" gnus-article-date-original t]
1560               ["Lapsed" gnus-article-date-lapsed t]
1561               ["User-defined" gnus-article-date-user t])
1562              ("Washing"
1563               ("Remove Blanks"
1564                ["Leading" gnus-article-strip-leading-blank-lines t]
1565                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1566                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1567                ["All of the above" gnus-article-strip-blank-lines t]
1568                ["All" gnus-article-strip-all-blank-lines t]
1569                ["Leading space" gnus-article-strip-leading-space t])
1570               ["Overstrike" gnus-article-treat-overstrike t]
1571               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1572               ["Emphasis" gnus-article-emphasize t]
1573               ["Word wrap" gnus-article-fill-cited-article t]
1574               ["CR" gnus-article-remove-cr t]
1575               ["Show X-Face" gnus-article-display-x-face t]
1576               ["UnHTMLize" gnus-article-treat-html t]
1577               ["Rot 13" gnus-summary-caesar-message t]
1578               ["Unix pipe" gnus-summary-pipe-message t]
1579               ["Add buttons" gnus-article-add-buttons t]
1580               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1581               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1582               ["Toggle MIME" gnus-summary-toggle-mime t]
1583               ["Verbose header" gnus-summary-verbose-headers t]
1584               ["Toggle header" gnus-summary-toggle-header t])
1585              ("Output"
1586               ["Save in default format" gnus-summary-save-article t]
1587               ["Save in file" gnus-summary-save-article-file t]
1588               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1589               ["Save in MH folder" gnus-summary-save-article-folder t]
1590               ["Save in VM folder" gnus-summary-save-article-vm t]
1591               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1592               ["Save body in file" gnus-summary-save-article-body-file t]
1593               ["Pipe through a filter" gnus-summary-pipe-output t]
1594               ["Add to SOUP packet" gnus-soup-add-article t]
1595               ["Print" gnus-summary-print-article t])
1596              ("Backend"
1597               ["Respool article..." gnus-summary-respool-article t]
1598               ["Move article..." gnus-summary-move-article
1599                (gnus-check-backend-function
1600                 'request-move-article gnus-newsgroup-name)]
1601               ["Copy article..." gnus-summary-copy-article t]
1602               ["Crosspost article..." gnus-summary-crosspost-article
1603                (gnus-check-backend-function
1604                 'request-replace-article gnus-newsgroup-name)]
1605               ["Import file..." gnus-summary-import-article t]
1606               ["Check if posted" gnus-summary-article-posted-p t]
1607               ["Edit article" gnus-summary-edit-article
1608                (not (gnus-group-read-only-p))]
1609               ["Delete article" gnus-summary-delete-article
1610                (gnus-check-backend-function
1611                 'request-expire-articles gnus-newsgroup-name)]
1612               ["Query respool" gnus-summary-respool-query t]
1613               ["Trace respool" gnus-summary-respool-trace t]
1614               ["Delete expirable articles" gnus-summary-expire-articles-now
1615                (gnus-check-backend-function
1616                 'request-expire-articles gnus-newsgroup-name)])
1617              ("Extract"
1618               ["Uudecode" gnus-uu-decode-uu t]
1619               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1620               ["Unshar" gnus-uu-decode-unshar t]
1621               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1622               ["Save" gnus-uu-decode-save t]
1623               ["Binhex" gnus-uu-decode-binhex t]
1624               ["Postscript" gnus-uu-decode-postscript t])
1625              ("Cache"
1626               ["Enter article" gnus-cache-enter-article t]
1627               ["Remove article" gnus-cache-remove-article t])
1628              ["Select article buffer" gnus-summary-select-article-buffer t]
1629              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1630              ["Isearch article..." gnus-summary-isearch-article t]
1631              ["Beginning of the article" gnus-summary-beginning-of-article t]
1632              ["End of the article" gnus-summary-end-of-article t]
1633              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1634              ["Fetch referenced articles" gnus-summary-refer-references t]
1635              ["Fetch current thread" gnus-summary-refer-thread t]
1636              ["Fetch article with id..." gnus-summary-refer-article t]
1637              ["Redisplay" gnus-summary-show-article t])))
1638       (easy-menu-define
1639        gnus-summary-article-menu gnus-summary-mode-map ""
1640        (cons "Article" innards))
1641
1642       (easy-menu-define
1643        gnus-article-commands-menu gnus-article-mode-map ""
1644        (cons "Commands" innards)))
1645
1646     (easy-menu-define
1647      gnus-summary-thread-menu gnus-summary-mode-map ""
1648      '("Threads"
1649        ["Toggle threading" gnus-summary-toggle-threads t]
1650        ["Hide threads" gnus-summary-hide-all-threads t]
1651        ["Show threads" gnus-summary-show-all-threads t]
1652        ["Hide thread" gnus-summary-hide-thread t]
1653        ["Show thread" gnus-summary-show-thread t]
1654        ["Go to next thread" gnus-summary-next-thread t]
1655        ["Go to previous thread" gnus-summary-prev-thread t]
1656        ["Go down thread" gnus-summary-down-thread t]
1657        ["Go up thread" gnus-summary-up-thread t]
1658        ["Top of thread" gnus-summary-top-thread t]
1659        ["Mark thread as read" gnus-summary-kill-thread t]
1660        ["Lower thread score" gnus-summary-lower-thread t]
1661        ["Raise thread score" gnus-summary-raise-thread t]
1662        ["Rethread current" gnus-summary-rethread-current t]
1663        ))
1664
1665     (easy-menu-define
1666      gnus-summary-post-menu gnus-summary-mode-map ""
1667      '("Post"
1668        ["Post an article" gnus-summary-post-news t]
1669        ["Followup" gnus-summary-followup t]
1670        ["Followup and yank" gnus-summary-followup-with-original t]
1671        ["Supersede article" gnus-summary-supersede-article t]
1672        ["Cancel article" gnus-summary-cancel-article t]
1673        ["Reply" gnus-summary-reply t]
1674        ["Reply and yank" gnus-summary-reply-with-original t]
1675        ["Wide reply" gnus-summary-wide-reply t]
1676        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
1677        ["Mail forward" gnus-summary-mail-forward t]
1678        ["Post forward" gnus-summary-post-forward t]
1679        ["Digest and mail" gnus-summary-mail-digest t]
1680        ["Digest and post" gnus-summary-post-digest t]
1681        ["Resend message" gnus-summary-resend-message t]
1682        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1683        ["Send a mail" gnus-summary-mail-other-window t]
1684        ["Uuencode and post" gnus-uu-post-news t]
1685        ["Followup via news" gnus-summary-followup-to-mail t]
1686        ["Followup via news and yank"
1687         gnus-summary-followup-to-mail-with-original t]
1688        ;;("Draft"
1689        ;;["Send" gnus-summary-send-draft t]
1690        ;;["Send bounced" gnus-resend-bounced-mail t])
1691        ))
1692
1693     (easy-menu-define
1694      gnus-summary-misc-menu gnus-summary-mode-map ""
1695      '("Misc"
1696        ("Mark Read"
1697         ["Mark as read" gnus-summary-mark-as-read-forward t]
1698         ["Mark same subject and select"
1699          gnus-summary-kill-same-subject-and-select t]
1700         ["Mark same subject" gnus-summary-kill-same-subject t]
1701         ["Catchup" gnus-summary-catchup t]
1702         ["Catchup all" gnus-summary-catchup-all t]
1703         ["Catchup to here" gnus-summary-catchup-to-here t]
1704         ["Catchup region" gnus-summary-mark-region-as-read t]
1705         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1706        ("Mark Various"
1707         ["Tick" gnus-summary-tick-article-forward t]
1708         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1709         ["Remove marks" gnus-summary-clear-mark-forward t]
1710         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1711         ["Set bookmark" gnus-summary-set-bookmark t]
1712         ["Remove bookmark" gnus-summary-remove-bookmark t])
1713        ("Mark Limit"
1714         ["Marks..." gnus-summary-limit-to-marks t]
1715         ["Subject..." gnus-summary-limit-to-subject t]
1716         ["Author..." gnus-summary-limit-to-author t]
1717         ["Age..." gnus-summary-limit-to-age t]
1718         ["Score" gnus-summary-limit-to-score t]
1719         ["Unread" gnus-summary-limit-to-unread t]
1720         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1721         ["Articles" gnus-summary-limit-to-articles t]
1722         ["Pop limit" gnus-summary-pop-limit t]
1723         ["Show dormant" gnus-summary-limit-include-dormant t]
1724         ["Hide childless dormant"
1725          gnus-summary-limit-exclude-childless-dormant t]
1726         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1727         ["Show expunged" gnus-summary-show-all-expunged t])
1728        ("Process Mark"
1729         ["Set mark" gnus-summary-mark-as-processable t]
1730         ["Remove mark" gnus-summary-unmark-as-processable t]
1731         ["Remove all marks" gnus-summary-unmark-all-processable t]
1732         ["Mark above" gnus-uu-mark-over t]
1733         ["Mark series" gnus-uu-mark-series t]
1734         ["Mark region" gnus-uu-mark-region t]
1735         ["Unmark region" gnus-uu-unmark-region t]
1736         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1737         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1738         ["Mark all" gnus-uu-mark-all t]
1739         ["Mark buffer" gnus-uu-mark-buffer t]
1740         ["Mark sparse" gnus-uu-mark-sparse t]
1741         ["Mark thread" gnus-uu-mark-thread t]
1742         ["Unmark thread" gnus-uu-unmark-thread t]
1743         ("Process Mark Sets"
1744          ["Kill" gnus-summary-kill-process-mark t]
1745          ["Yank" gnus-summary-yank-process-mark
1746           gnus-newsgroup-process-stack]
1747          ["Save" gnus-summary-save-process-mark t]))
1748        ("Scroll article"
1749         ["Page forward" gnus-summary-next-page t]
1750         ["Page backward" gnus-summary-prev-page t]
1751         ["Line forward" gnus-summary-scroll-up t])
1752        ("Move"
1753         ["Next unread article" gnus-summary-next-unread-article t]
1754         ["Previous unread article" gnus-summary-prev-unread-article t]
1755         ["Next article" gnus-summary-next-article t]
1756         ["Previous article" gnus-summary-prev-article t]
1757         ["Next unread subject" gnus-summary-next-unread-subject t]
1758         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1759         ["Next article same subject" gnus-summary-next-same-subject t]
1760         ["Previous article same subject" gnus-summary-prev-same-subject t]
1761         ["First unread article" gnus-summary-first-unread-article t]
1762         ["Best unread article" gnus-summary-best-unread-article t]
1763         ["Go to subject number..." gnus-summary-goto-subject t]
1764         ["Go to article number..." gnus-summary-goto-article t]
1765         ["Go to the last article" gnus-summary-goto-last-article t]
1766         ["Pop article off history" gnus-summary-pop-article t])
1767        ("Sort"
1768         ["Sort by number" gnus-summary-sort-by-number t]
1769         ["Sort by author" gnus-summary-sort-by-author t]
1770         ["Sort by subject" gnus-summary-sort-by-subject t]
1771         ["Sort by date" gnus-summary-sort-by-date t]
1772         ["Sort by score" gnus-summary-sort-by-score t]
1773         ["Sort by lines" gnus-summary-sort-by-lines t])
1774        ("Help"
1775         ["Fetch group FAQ" gnus-summary-fetch-faq t]
1776         ["Describe group" gnus-summary-describe-group t]
1777         ["Read manual" gnus-info-find-node t])
1778        ("Modes"
1779         ["Pick and read" gnus-pick-mode t]
1780         ["Binary" gnus-binary-mode t])
1781        ("Regeneration"
1782         ["Regenerate" gnus-summary-prepare t]
1783         ["Insert cached articles" gnus-summary-insert-cached-articles t]
1784         ["Toggle threading" gnus-summary-toggle-threads t])
1785        ["Filter articles..." gnus-summary-execute-command t]
1786        ["Run command on subjects..." gnus-summary-universal-argument t]
1787        ["Search articles forward..." gnus-summary-search-article-forward t]
1788        ["Search articles backward..." gnus-summary-search-article-backward t]
1789        ["Toggle line truncation" gnus-summary-toggle-truncation t]
1790        ["Expand window" gnus-summary-expand-window t]
1791        ["Expire expirable articles" gnus-summary-expire-articles
1792         (gnus-check-backend-function
1793          'request-expire-articles gnus-newsgroup-name)]
1794        ["Edit local kill file" gnus-summary-edit-local-kill t]
1795        ["Edit main kill file" gnus-summary-edit-global-kill t]
1796        ["Edit group parameters" gnus-summary-edit-parameters t]
1797        ["Customize group parameters" gnus-summary-customize-parameters t]
1798        ["Send a bug report" gnus-bug t]
1799        ("Exit"
1800         ["Catchup and exit" gnus-summary-catchup-and-exit t]
1801         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
1802         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
1803         ["Exit group" gnus-summary-exit t]
1804         ["Exit group without updating" gnus-summary-exit-no-update t]
1805         ["Exit and goto next group" gnus-summary-next-group t]
1806         ["Exit and goto prev group" gnus-summary-prev-group t]
1807         ["Reselect group" gnus-summary-reselect-current-group t]
1808         ["Rescan group" gnus-summary-rescan-group t]
1809         ["Update dribble" gnus-summary-save-newsrc t])))
1810
1811     (gnus-run-hooks 'gnus-summary-menu-hook)))
1812
1813 (defun gnus-score-set-default (var value)
1814   "A version of set that updates the GNU Emacs menu-bar."
1815   (set var value)
1816   ;; It is the message that forces the active status to be updated.
1817   (message ""))
1818
1819 (defun gnus-make-score-map (type)
1820   "Make a summary score map of type TYPE."
1821   (if t
1822       nil
1823     (let ((headers '(("author" "from" string)
1824                      ("subject" "subject" string)
1825                      ("article body" "body" string)
1826                      ("article head" "head" string)
1827                      ("xref" "xref" string)
1828                      ("extra header" "extra" string)
1829                      ("lines" "lines" number)
1830                      ("followups to author" "followup" string)))
1831           (types '((number ("less than" <)
1832                            ("greater than" >)
1833                            ("equal" =))
1834                    (string ("substring" s)
1835                            ("exact string" e)
1836                            ("fuzzy string" f)
1837                            ("regexp" r))))
1838           (perms '(("temporary" (current-time-string))
1839                    ("permanent" nil)
1840                    ("immediate" now)))
1841           header)
1842       (list
1843        (apply
1844         'nconc
1845         (list
1846          (if (eq type 'lower)
1847              "Lower score"
1848            "Increase score"))
1849         (let (outh)
1850           (while headers
1851             (setq header (car headers))
1852             (setq outh
1853                   (cons
1854                    (apply
1855                     'nconc
1856                     (list (car header))
1857                     (let ((ts (cdr (assoc (nth 2 header) types)))
1858                           outt)
1859                       (while ts
1860                         (setq outt
1861                               (cons
1862                                (apply
1863                                 'nconc
1864                                 (list (caar ts))
1865                                 (let ((ps perms)
1866                                       outp)
1867                                   (while ps
1868                                     (setq outp
1869                                           (cons
1870                                            (vector
1871                                             (caar ps)
1872                                             (list
1873                                              'gnus-summary-score-entry
1874                                              (nth 1 header)
1875                                              (if (or (string= (nth 1 header)
1876                                                               "head")
1877                                                      (string= (nth 1 header)
1878                                                               "body"))
1879                                                  ""
1880                                                (list 'gnus-summary-header
1881                                                      (nth 1 header)))
1882                                              (list 'quote (nth 1 (car ts)))
1883                                              (list 'gnus-score-default nil)
1884                                              (nth 1 (car ps))
1885                                              t)
1886                                             t)
1887                                            outp))
1888                                     (setq ps (cdr ps)))
1889                                   (list (nreverse outp))))
1890                                outt))
1891                         (setq ts (cdr ts)))
1892                       (list (nreverse outt))))
1893                    outh))
1894             (setq headers (cdr headers)))
1895           (list (nreverse outh))))))))
1896
1897 \f
1898
1899 (defun gnus-summary-mode (&optional group)
1900   "Major mode for reading articles.
1901
1902 All normal editing commands are switched off.
1903 \\<gnus-summary-mode-map>
1904 Each line in this buffer represents one article.  To read an
1905 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
1906 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
1907 respectively.
1908
1909 You can also post articles and send mail from this buffer.  To
1910 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
1911 of an article, type `\\[gnus-summary-reply]'.
1912
1913 There are approx. one gazillion commands you can execute in this
1914 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
1915
1916 The following commands are available:
1917
1918 \\{gnus-summary-mode-map}"
1919   (interactive)
1920   (when (gnus-visual-p 'summary-menu 'menu)
1921     (gnus-summary-make-menu-bar))
1922   (kill-all-local-variables)
1923   (gnus-summary-make-local-variables)
1924   (gnus-make-thread-indent-array)
1925   (gnus-simplify-mode-line)
1926   (setq major-mode 'gnus-summary-mode)
1927   (setq mode-name "Summary")
1928   (make-local-variable 'minor-mode-alist)
1929   (use-local-map gnus-summary-mode-map)
1930   (buffer-disable-undo)
1931   (setq buffer-read-only t)             ;Disable modification
1932   (setq truncate-lines t)
1933   (setq selective-display t)
1934   (setq selective-display-ellipses t)   ;Display `...'
1935   (gnus-summary-set-display-table)
1936   (gnus-set-default-directory)
1937   (setq gnus-newsgroup-name group)
1938   (make-local-variable 'gnus-summary-line-format)
1939   (make-local-variable 'gnus-summary-line-format-spec)
1940   (make-local-variable 'gnus-summary-dummy-line-format)
1941   (make-local-variable 'gnus-summary-dummy-line-format-spec)
1942   (make-local-variable 'gnus-summary-mark-positions)
1943   (make-local-hook 'post-command-hook)
1944   (add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
1945   (make-local-hook 'pre-command-hook)
1946   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
1947   (gnus-run-hooks 'gnus-summary-mode-hook)
1948   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
1949   (gnus-update-summary-mark-positions))
1950
1951 (defun gnus-summary-make-local-variables ()
1952   "Make all the local summary buffer variables."
1953   (let ((locals gnus-summary-local-variables)
1954         global local)
1955     (while (setq local (pop locals))
1956       (if (consp local)
1957           (progn
1958             (if (eq (cdr local) 'global)
1959                 ;; Copy the global value of the variable.
1960                 (setq global (symbol-value (car local)))
1961               ;; Use the value from the list.
1962               (setq global (eval (cdr local))))
1963             (make-local-variable (car local))
1964             (set (car local) global))
1965         ;; Simple nil-valued local variable.
1966         (make-local-variable local)
1967         (set local nil)))))
1968
1969 (defun gnus-summary-clear-local-variables ()
1970   (let ((locals gnus-summary-local-variables))
1971     (while locals
1972       (if (consp (car locals))
1973           (and (vectorp (caar locals))
1974                (set (caar locals) nil))
1975         (and (vectorp (car locals))
1976              (set (car locals) nil)))
1977       (setq locals (cdr locals)))))
1978
1979 ;; Summary data functions.
1980
1981 (defmacro gnus-data-number (data)
1982   `(car ,data))
1983
1984 (defmacro gnus-data-set-number (data number)
1985   `(setcar ,data ,number))
1986
1987 (defmacro gnus-data-mark (data)
1988   `(nth 1 ,data))
1989
1990 (defmacro gnus-data-set-mark (data mark)
1991   `(setcar (nthcdr 1 ,data) ,mark))
1992
1993 (defmacro gnus-data-pos (data)
1994   `(nth 2 ,data))
1995
1996 (defmacro gnus-data-set-pos (data pos)
1997   `(setcar (nthcdr 2 ,data) ,pos))
1998
1999 (defmacro gnus-data-header (data)
2000   `(nth 3 ,data))
2001
2002 (defmacro gnus-data-set-header (data header)
2003   `(setf (nth 3 ,data) ,header))
2004
2005 (defmacro gnus-data-level (data)
2006   `(nth 4 ,data))
2007
2008 (defmacro gnus-data-unread-p (data)
2009   `(= (nth 1 ,data) gnus-unread-mark))
2010
2011 (defmacro gnus-data-read-p (data)
2012   `(/= (nth 1 ,data) gnus-unread-mark))
2013
2014 (defmacro gnus-data-pseudo-p (data)
2015   `(consp (nth 3 ,data)))
2016
2017 (defmacro gnus-data-find (number)
2018   `(assq ,number gnus-newsgroup-data))
2019
2020 (defmacro gnus-data-find-list (number &optional data)
2021   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2022      (memq (assq ,number bdata)
2023            bdata)))
2024
2025 (defmacro gnus-data-make (number mark pos header level)
2026   `(list ,number ,mark ,pos ,header ,level))
2027
2028 (defun gnus-data-enter (after-article number mark pos header level offset)
2029   (let ((data (gnus-data-find-list after-article)))
2030     (unless data
2031       (error "No such article: %d" after-article))
2032     (setcdr data (cons (gnus-data-make number mark pos header level)
2033                        (cdr data)))
2034     (setq gnus-newsgroup-data-reverse nil)
2035     (gnus-data-update-list (cddr data) offset)))
2036
2037 (defun gnus-data-enter-list (after-article list &optional offset)
2038   (when list
2039     (let ((data (and after-article (gnus-data-find-list after-article)))
2040           (ilist list))
2041       (if (not (or data
2042                    after-article))
2043           (let ((odata gnus-newsgroup-data))
2044             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2045             (when offset
2046               (gnus-data-update-list odata offset)))
2047         ;; Find the last element in the list to be spliced into the main
2048         ;; list.
2049         (while (cdr list)
2050           (setq list (cdr list)))
2051         (if (not data)
2052             (progn
2053               (setcdr list gnus-newsgroup-data)
2054               (setq gnus-newsgroup-data ilist)
2055               (when offset
2056                 (gnus-data-update-list (cdr list) offset)))
2057           (setcdr list (cdr data))
2058           (setcdr data ilist)
2059           (when offset
2060             (gnus-data-update-list (cdr list) offset))))
2061       (setq gnus-newsgroup-data-reverse nil))))
2062
2063 (defun gnus-data-remove (article &optional offset)
2064   (let ((data gnus-newsgroup-data))
2065     (if (= (gnus-data-number (car data)) article)
2066         (progn
2067           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2068                 gnus-newsgroup-data-reverse nil)
2069           (when offset
2070             (gnus-data-update-list gnus-newsgroup-data offset)))
2071       (while (cdr data)
2072         (when (= (gnus-data-number (cadr data)) article)
2073           (setcdr data (cddr data))
2074           (when offset
2075             (gnus-data-update-list (cdr data) offset))
2076           (setq data nil
2077                 gnus-newsgroup-data-reverse nil))
2078         (setq data (cdr data))))))
2079
2080 (defmacro gnus-data-list (backward)
2081   `(if ,backward
2082        (or gnus-newsgroup-data-reverse
2083            (setq gnus-newsgroup-data-reverse
2084                  (reverse gnus-newsgroup-data)))
2085      gnus-newsgroup-data))
2086
2087 (defun gnus-data-update-list (data offset)
2088   "Add OFFSET to the POS of all data entries in DATA."
2089   (setq gnus-newsgroup-data-reverse nil)
2090   (while data
2091     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2092     (setq data (cdr data))))
2093
2094 (defun gnus-summary-article-pseudo-p (article)
2095   "Say whether this article is a pseudo article or not."
2096   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2097
2098 (defmacro gnus-summary-article-sparse-p (article)
2099   "Say whether this article is a sparse article or not."
2100   `(memq ,article gnus-newsgroup-sparse))
2101
2102 (defmacro gnus-summary-article-ancient-p (article)
2103   "Say whether this article is a sparse article or not."
2104   `(memq ,article gnus-newsgroup-ancient))
2105
2106 (defun gnus-article-parent-p (number)
2107   "Say whether this article is a parent or not."
2108   (let ((data (gnus-data-find-list number)))
2109     (and (cdr data)                     ; There has to be an article after...
2110          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2111             (gnus-data-level (nth 1 data))))))
2112
2113 (defun gnus-article-children (number)
2114   "Return a list of all children to NUMBER."
2115   (let* ((data (gnus-data-find-list number))
2116          (level (gnus-data-level (car data)))
2117          children)
2118     (setq data (cdr data))
2119     (while (and data
2120                 (= (gnus-data-level (car data)) (1+ level)))
2121       (push (gnus-data-number (car data)) children)
2122       (setq data (cdr data)))
2123     children))
2124
2125 (defmacro gnus-summary-skip-intangible ()
2126   "If the current article is intangible, then jump to a different article."
2127   '(let ((to (get-text-property (point) 'gnus-intangible)))
2128      (and to (gnus-summary-goto-subject to))))
2129
2130 (defmacro gnus-summary-article-intangible-p ()
2131   "Say whether this article is intangible or not."
2132   '(get-text-property (point) 'gnus-intangible))
2133
2134 (defun gnus-article-read-p (article)
2135   "Say whether ARTICLE is read or not."
2136   (not (or (memq article gnus-newsgroup-marked)
2137            (memq article gnus-newsgroup-unreads)
2138            (memq article gnus-newsgroup-unselected)
2139            (memq article gnus-newsgroup-dormant))))
2140
2141 ;; Some summary mode macros.
2142
2143 (defmacro gnus-summary-article-number ()
2144   "The article number of the article on the current line.
2145 If there isn's an article number here, then we return the current
2146 article number."
2147   '(progn
2148      (gnus-summary-skip-intangible)
2149      (or (get-text-property (point) 'gnus-number)
2150          (gnus-summary-last-subject))))
2151
2152 (defmacro gnus-summary-article-header (&optional number)
2153   "Return the header of article NUMBER."
2154   `(gnus-data-header (gnus-data-find
2155                       ,(or number '(gnus-summary-article-number)))))
2156
2157 (defmacro gnus-summary-thread-level (&optional number)
2158   "Return the level of thread that starts with article NUMBER."
2159   `(if (and (eq gnus-summary-make-false-root 'dummy)
2160             (get-text-property (point) 'gnus-intangible))
2161        0
2162      (gnus-data-level (gnus-data-find
2163                        ,(or number '(gnus-summary-article-number))))))
2164
2165 (defmacro gnus-summary-article-mark (&optional number)
2166   "Return the mark of article NUMBER."
2167   `(gnus-data-mark (gnus-data-find
2168                     ,(or number '(gnus-summary-article-number)))))
2169
2170 (defmacro gnus-summary-article-pos (&optional number)
2171   "Return the position of the line of article NUMBER."
2172   `(gnus-data-pos (gnus-data-find
2173                    ,(or number '(gnus-summary-article-number)))))
2174
2175 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2176 (defmacro gnus-summary-article-subject (&optional number)
2177   "Return current subject string or nil if nothing."
2178   `(let ((headers
2179           ,(if number
2180                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2181              '(gnus-data-header (assq (gnus-summary-article-number)
2182                                       gnus-newsgroup-data)))))
2183      (and headers
2184           (vectorp headers)
2185           (mail-header-subject headers))))
2186
2187 (defmacro gnus-summary-article-score (&optional number)
2188   "Return current article score."
2189   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2190                   gnus-newsgroup-scored))
2191        gnus-summary-default-score 0))
2192
2193 (defun gnus-summary-article-children (&optional number)
2194   "Return a list of article numbers that are children of article NUMBER."
2195   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2196          (level (gnus-data-level (car data)))
2197          l children)
2198     (while (and (setq data (cdr data))
2199                 (> (setq l (gnus-data-level (car data))) level))
2200       (and (= (1+ level) l)
2201            (push (gnus-data-number (car data))
2202                  children)))
2203     (nreverse children)))
2204
2205 (defun gnus-summary-article-parent (&optional number)
2206   "Return the article number of the parent of article NUMBER."
2207   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2208                                     (gnus-data-list t)))
2209          (level (gnus-data-level (car data))))
2210     (if (zerop level)
2211         ()                              ; This is a root.
2212       ;; We search until we find an article with a level less than
2213       ;; this one.  That function has to be the parent.
2214       (while (and (setq data (cdr data))
2215                   (not (< (gnus-data-level (car data)) level))))
2216       (and data (gnus-data-number (car data))))))
2217
2218 (defun gnus-unread-mark-p (mark)
2219   "Say whether MARK is the unread mark."
2220   (= mark gnus-unread-mark))
2221
2222 (defun gnus-read-mark-p (mark)
2223   "Say whether MARK is one of the marks that mark as read.
2224 This is all marks except unread, ticked, dormant, and expirable."
2225   (not (or (= mark gnus-unread-mark)
2226            (= mark gnus-ticked-mark)
2227            (= mark gnus-dormant-mark)
2228            (= mark gnus-expirable-mark))))
2229
2230 (defmacro gnus-article-mark (number)
2231   "Return the MARK of article NUMBER.
2232 This macro should only be used when computing the mark the \"first\"
2233 time; i.e., when generating the summary lines.  After that,
2234 `gnus-summary-article-mark' should be used to examine the
2235 marks of articles."
2236   `(cond
2237     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2238     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2239     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2240     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2241     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2242     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2243     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2244     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2245            gnus-ancient-mark))))
2246
2247 ;; Saving hidden threads.
2248
2249 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2250 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2251
2252 (defmacro gnus-save-hidden-threads (&rest forms)
2253   "Save hidden threads, eval FORMS, and restore the hidden threads."
2254   (let ((config (make-symbol "config")))
2255     `(let ((,config (gnus-hidden-threads-configuration)))
2256        (unwind-protect
2257            (save-excursion
2258              ,@forms)
2259          (gnus-restore-hidden-threads-configuration ,config)))))
2260
2261 (defun gnus-data-compute-positions ()
2262   "Compute the positions of all articles."
2263   (setq gnus-newsgroup-data-reverse nil)
2264   (let ((data gnus-newsgroup-data))
2265     (save-excursion
2266       (gnus-save-hidden-threads
2267         (gnus-summary-show-all-threads)
2268         (goto-char (point-min))
2269         (while data
2270           (while (get-text-property (point) 'gnus-intangible)
2271             (forward-line 1))
2272           (gnus-data-set-pos (car data) (+ (point) 3))
2273           (setq data (cdr data))
2274           (forward-line 1))))))
2275
2276 (defun gnus-hidden-threads-configuration ()
2277   "Return the current hidden threads configuration."
2278   (save-excursion
2279     (let (config)
2280       (goto-char (point-min))
2281       (while (search-forward "\r" nil t)
2282         (push (1- (point)) config))
2283       config)))
2284
2285 (defun gnus-restore-hidden-threads-configuration (config)
2286   "Restore hidden threads configuration from CONFIG."
2287   (let (point buffer-read-only)
2288     (while (setq point (pop config))
2289       (when (and (< point (point-max))
2290                  (goto-char point)
2291                  (eq (char-after) ?\n))
2292         (subst-char-in-region point (1+ point) ?\n ?\r)))))
2293
2294 ;; Various summary mode internalish functions.
2295
2296 (defun gnus-mouse-pick-article (e)
2297   (interactive "e")
2298   (mouse-set-point e)
2299   (gnus-summary-next-page nil t))
2300
2301 (defun gnus-summary-set-display-table ()
2302   ;; Change the display table.  Odd characters have a tendency to mess
2303   ;; up nicely formatted displays - we make all possible glyphs
2304   ;; display only a single character.
2305
2306   ;; We start from the standard display table, if any.
2307   (let ((table (or (copy-sequence standard-display-table)
2308                    (make-display-table)))
2309         (i 32))
2310     ;; Nix out all the control chars...
2311     (while (>= (setq i (1- i)) 0)
2312       (aset table i [??]))
2313     ;; ... but not newline and cr, of course.  (cr is necessary for the
2314     ;; selective display).
2315     (aset table ?\n nil)
2316     (aset table ?\r nil)
2317     ;; We keep TAB as well.
2318     (aset table ?\t nil)
2319     ;; We nix out any glyphs over 126 that are not set already.
2320     (let ((i 256))
2321       (while (>= (setq i (1- i)) 127)
2322         ;; Only modify if the entry is nil.
2323         (unless (aref table i)
2324           (aset table i [??]))))
2325     (setq buffer-display-table table)))
2326
2327 (defun gnus-summary-setup-buffer (group)
2328   "Initialize summary buffer."
2329   (let ((buffer (concat "*Summary " group "*")))
2330     (if (get-buffer buffer)
2331         (progn
2332           (set-buffer buffer)
2333           (setq gnus-summary-buffer (current-buffer))
2334           (not gnus-newsgroup-prepared))
2335       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2336       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2337       (gnus-summary-mode group)
2338       (when gnus-carpal
2339         (gnus-carpal-setup-buffer 'summary))
2340       (unless gnus-single-article-buffer
2341         (make-local-variable 'gnus-article-buffer)
2342         (make-local-variable 'gnus-article-current)
2343         (make-local-variable 'gnus-original-article-buffer))
2344       (setq gnus-newsgroup-name group)
2345       t)))
2346
2347 (defun gnus-set-global-variables ()
2348   ;; Set the global equivalents of the summary buffer-local variables
2349   ;; to the latest values they had.  These reflect the summary buffer
2350   ;; that was in action when the last article was fetched.
2351   (when (eq major-mode 'gnus-summary-mode)
2352     (setq gnus-summary-buffer (current-buffer))
2353     (let ((name gnus-newsgroup-name)
2354           (marked gnus-newsgroup-marked)
2355           (unread gnus-newsgroup-unreads)
2356           (headers gnus-current-headers)
2357           (data gnus-newsgroup-data)
2358           (summary gnus-summary-buffer)
2359           (article-buffer gnus-article-buffer)
2360           (original gnus-original-article-buffer)
2361           (gac gnus-article-current)
2362           (reffed gnus-reffed-article-number)
2363           (score-file gnus-current-score-file)
2364           (coding-system gnus-newsgroup-coding-system)
2365           (iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2366       (save-excursion
2367         (set-buffer gnus-group-buffer)
2368         (setq gnus-newsgroup-name name
2369               gnus-newsgroup-marked marked
2370               gnus-newsgroup-unreads unread
2371               gnus-current-headers headers
2372               gnus-newsgroup-data data
2373               gnus-article-current gac
2374               gnus-summary-buffer summary
2375               gnus-article-buffer article-buffer
2376               gnus-original-article-buffer original
2377               gnus-reffed-article-number reffed
2378               gnus-current-score-file score-file
2379               gnus-newsgroup-coding-system coding-system
2380               gnus-newsgroup-iso-8859-1-forced iso-8859-1-forced)
2381         ;; The article buffer also has local variables.
2382         (when (gnus-buffer-live-p gnus-article-buffer)
2383           (set-buffer gnus-article-buffer)
2384           (setq gnus-summary-buffer summary))))))
2385
2386 (defun gnus-summary-article-unread-p (article)
2387   "Say whether ARTICLE is unread or not."
2388   (memq article gnus-newsgroup-unreads))
2389
2390 (defun gnus-summary-first-article-p (&optional article)
2391   "Return whether ARTICLE is the first article in the buffer."
2392   (if (not (setq article (or article (gnus-summary-article-number))))
2393       nil
2394     (eq article (caar gnus-newsgroup-data))))
2395
2396 (defun gnus-summary-last-article-p (&optional article)
2397   "Return whether ARTICLE is the last article in the buffer."
2398   (if (not (setq article (or article (gnus-summary-article-number))))
2399       t                                 ; All non-existent numbers are the last article.  :-)
2400     (not (cdr (gnus-data-find-list article)))))
2401
2402 (defun gnus-make-thread-indent-array ()
2403   (let ((n 200))
2404     (unless (and gnus-thread-indent-array
2405                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2406       (setq gnus-thread-indent-array (make-vector 201 "")
2407             gnus-thread-indent-array-level gnus-thread-indent-level)
2408       (while (>= n 0)
2409         (aset gnus-thread-indent-array n
2410               (make-string (* n gnus-thread-indent-level) ? ))
2411         (setq n (1- n))))))
2412
2413 (defun gnus-update-summary-mark-positions ()
2414   "Compute where the summary marks are to go."
2415   (save-excursion
2416     (when (gnus-buffer-exists-p gnus-summary-buffer)
2417       (set-buffer gnus-summary-buffer))
2418     (let ((gnus-replied-mark 129)
2419           (gnus-score-below-mark 130)
2420           (gnus-score-over-mark 130)
2421           (gnus-download-mark 131)
2422           (spec gnus-summary-line-format-spec)
2423           gnus-visual pos)
2424       (save-excursion
2425         (gnus-set-work-buffer)
2426         (let ((gnus-summary-line-format-spec spec)
2427               (gnus-newsgroup-downloadable '((0 . t))))
2428           (gnus-summary-insert-line
2429            (make-full-mail-header 0 "" "" "" "" "" 0 0 "" nil)
2430            0 nil 128 t nil "" nil 1)
2431           (goto-char (point-min))
2432           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2433                                              (- (point) 2)))))
2434           (goto-char (point-min))
2435           (push (cons 'replied (and (search-forward "\201" nil t)
2436                                     (- (point) 2)))
2437                 pos)
2438           (goto-char (point-min))
2439           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2440                 pos)
2441           (goto-char (point-min))
2442           (push (cons 'download
2443                       (and (search-forward "\203" nil t) (- (point) 2)))
2444                 pos)))
2445       (setq gnus-summary-mark-positions pos))))
2446
2447 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2448   "Insert a dummy root in the summary buffer."
2449   (beginning-of-line)
2450   (gnus-add-text-properties
2451    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2452    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2453
2454 (defun gnus-summary-from-or-to-or-newsgroups (header)
2455   (let ((to (cdr (assq 'To (mail-header-extra header))))
2456         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2457         (rfc2047-default-charset gnus-newsgroup-coding-system)
2458         (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2459     (cond
2460      ((and to
2461            gnus-ignored-from-addresses
2462            (string-match gnus-ignored-from-addresses
2463                          (mail-header-from header)))
2464       (concat "-> "
2465               (or (car (funcall gnus-extract-address-components
2466                                 (funcall
2467                                  gnus-decode-encoded-word-function to)))
2468                   (funcall gnus-decode-encoded-word-function to))))
2469      ((and newsgroups
2470            gnus-ignored-from-addresses
2471            (string-match gnus-ignored-from-addresses
2472                          (mail-header-from header)))
2473       (concat "=> " newsgroups))
2474      (t
2475       (or (car (funcall gnus-extract-address-components
2476                         (mail-header-from header)))
2477           (mail-header-from header))))))
2478
2479 (defun gnus-summary-insert-line (gnus-tmp-header
2480                                  gnus-tmp-level gnus-tmp-current
2481                                  gnus-tmp-unread gnus-tmp-replied
2482                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2483                                  &optional gnus-tmp-dummy gnus-tmp-score
2484                                  gnus-tmp-process)
2485   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2486          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2487          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2488          (gnus-tmp-score-char
2489           (if (or (null gnus-summary-default-score)
2490                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2491                       gnus-summary-zcore-fuzz))
2492               ? 
2493             (if (< gnus-tmp-score gnus-summary-default-score)
2494                 gnus-score-below-mark gnus-score-over-mark)))
2495          (gnus-tmp-replied
2496           (cond (gnus-tmp-process gnus-process-mark)
2497                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2498                  gnus-cached-mark)
2499                 (gnus-tmp-replied gnus-replied-mark)
2500                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2501                  gnus-saved-mark)
2502                 (t gnus-unread-mark)))
2503          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2504          (gnus-tmp-name
2505           (cond
2506            ((string-match "<[^>]+> *$" gnus-tmp-from)
2507             (let ((beg (match-beginning 0)))
2508               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2509                        (substring gnus-tmp-from (1+ (match-beginning 0))
2510                                   (1- (match-end 0))))
2511                   (substring gnus-tmp-from 0 beg))))
2512            ((string-match "(.+)" gnus-tmp-from)
2513             (substring gnus-tmp-from
2514                        (1+ (match-beginning 0)) (1- (match-end 0))))
2515            (t gnus-tmp-from)))
2516          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2517          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2518          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2519          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2520          (buffer-read-only nil))
2521     (when (string= gnus-tmp-name "")
2522       (setq gnus-tmp-name gnus-tmp-from))
2523     (unless (numberp gnus-tmp-lines)
2524       (setq gnus-tmp-lines 0))
2525     (gnus-put-text-property-excluding-characters-with-faces
2526      (point)
2527      (progn (eval gnus-summary-line-format-spec) (point))
2528      'gnus-number gnus-tmp-number)
2529     (when (gnus-visual-p 'summary-highlight 'highlight)
2530       (forward-line -1)
2531       (gnus-run-hooks 'gnus-summary-update-hook)
2532       (forward-line 1))))
2533
2534 (defun gnus-summary-update-line (&optional dont-update)
2535   ;; Update summary line after change.
2536   (when (and gnus-summary-default-score
2537              (not gnus-summary-inhibit-highlight))
2538     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2539            (article (gnus-summary-article-number))
2540            (score (gnus-summary-article-score article)))
2541       (unless dont-update
2542         (if (and gnus-summary-mark-below
2543                  (< (gnus-summary-article-score)
2544                     gnus-summary-mark-below))
2545             ;; This article has a low score, so we mark it as read.
2546             (when (memq article gnus-newsgroup-unreads)
2547               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2548           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2549             ;; This article was previously marked as read on account
2550             ;; of a low score, but now it has risen, so we mark it as
2551             ;; unread.
2552             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2553         (gnus-summary-update-mark
2554          (if (or (null gnus-summary-default-score)
2555                  (<= (abs (- score gnus-summary-default-score))
2556                      gnus-summary-zcore-fuzz))
2557              ? 
2558            (if (< score gnus-summary-default-score)
2559                gnus-score-below-mark gnus-score-over-mark))
2560          'score))
2561       ;; Do visual highlighting.
2562       (when (gnus-visual-p 'summary-highlight 'highlight)
2563         (gnus-run-hooks 'gnus-summary-update-hook)))))
2564
2565 (defvar gnus-tmp-new-adopts nil)
2566
2567 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2568   "Return the number of articles in THREAD.
2569 This may be 0 in some cases -- if none of the articles in
2570 the thread are to be displayed."
2571   (let* ((number
2572           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2573           (cond
2574            ((not (listp thread))
2575             1)
2576            ((and (consp thread) (cdr thread))
2577             (apply
2578              '+ 1 (mapcar
2579                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2580            ((null thread)
2581             1)
2582            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2583             1)
2584            (t 0))))
2585     (when (and level (zerop level) gnus-tmp-new-adopts)
2586       (incf number
2587             (apply '+ (mapcar
2588                        'gnus-summary-number-of-articles-in-thread
2589                        gnus-tmp-new-adopts))))
2590     (if char
2591         (if (> number 1) gnus-not-empty-thread-mark
2592           gnus-empty-thread-mark)
2593       number)))
2594
2595 (defun gnus-summary-set-local-parameters (group)
2596   "Go through the local params of GROUP and set all variable specs in that list."
2597   (let ((params (gnus-group-find-parameter group))
2598         elem)
2599     (while params
2600       (setq elem (car params)
2601             params (cdr params))
2602       (and (consp elem)                 ; Has to be a cons.
2603            (consp (cdr elem))           ; The cdr has to be a list.
2604            (symbolp (car elem))         ; Has to be a symbol in there.
2605            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2606            (ignore-errors               ; So we set it.
2607              (make-local-variable (car elem))
2608              (set (car elem) (eval (nth 1 elem))))))))
2609
2610 (defun gnus-summary-read-group (group &optional show-all no-article
2611                                       kill-buffer no-display backward
2612                                       select-articles)
2613   "Start reading news in newsgroup GROUP.
2614 If SHOW-ALL is non-nil, already read articles are also listed.
2615 If NO-ARTICLE is non-nil, no article is selected initially.
2616 If NO-DISPLAY, don't generate a summary buffer."
2617   (let (result)
2618     (while (and group
2619                 (null (setq result
2620                             (let ((gnus-auto-select-next nil))
2621                               (or (gnus-summary-read-group-1
2622                                    group show-all no-article
2623                                    kill-buffer no-display
2624                                    select-articles)
2625                                   (setq show-all nil
2626                                         select-articles nil)))))
2627                 (eq gnus-auto-select-next 'quietly))
2628       (set-buffer gnus-group-buffer)
2629       ;; The entry function called above goes to the next
2630       ;; group automatically, so we go two groups back
2631       ;; if we are searching for the previous group.
2632       (when backward
2633         (gnus-group-prev-unread-group 2))
2634       (if (not (equal group (gnus-group-group-name)))
2635           (setq group (gnus-group-group-name))
2636         (setq group nil)))
2637     result))
2638
2639 (defun gnus-summary-read-group-1 (group show-all no-article
2640                                         kill-buffer no-display
2641                                         &optional select-articles)
2642   ;; Killed foreign groups can't be entered.
2643   (when (and (not (gnus-group-native-p group))
2644              (not (gnus-gethash group gnus-newsrc-hashtb)))
2645     (error "Dead non-native groups can't be entered"))
2646   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2647   (let* ((new-group (gnus-summary-setup-buffer group))
2648          (quit-config (gnus-group-quit-config group))
2649          (did-select (and new-group (gnus-select-newsgroup
2650                                      group show-all select-articles))))
2651     (cond
2652      ;; This summary buffer exists already, so we just select it.
2653      ((not new-group)
2654       (gnus-set-global-variables)
2655       (when kill-buffer
2656         (gnus-kill-or-deaden-summary kill-buffer))
2657       (gnus-configure-windows 'summary 'force)
2658       (gnus-set-mode-line 'summary)
2659       (gnus-summary-position-point)
2660       (message "")
2661       t)
2662      ;; We couldn't select this group.
2663      ((null did-select)
2664       (when (and (eq major-mode 'gnus-summary-mode)
2665                  (not (equal (current-buffer) kill-buffer)))
2666         (kill-buffer (current-buffer))
2667         (if (not quit-config)
2668             (progn
2669               ;; Update the info -- marks might need to be removed,
2670               ;; for instance.
2671               (gnus-summary-update-info)
2672               (set-buffer gnus-group-buffer)
2673               (gnus-group-jump-to-group group)
2674               (gnus-group-next-unread-group 1))
2675           (gnus-handle-ephemeral-exit quit-config)))
2676       (gnus-message 3 "Can't select group")
2677       nil)
2678      ;; The user did a `C-g' while prompting for number of articles,
2679      ;; so we exit this group.
2680      ((eq did-select 'quit)
2681       (and (eq major-mode 'gnus-summary-mode)
2682            (not (equal (current-buffer) kill-buffer))
2683            (kill-buffer (current-buffer)))
2684       (when kill-buffer
2685         (gnus-kill-or-deaden-summary kill-buffer))
2686       (if (not quit-config)
2687           (progn
2688             (set-buffer gnus-group-buffer)
2689             (gnus-group-jump-to-group group)
2690             (gnus-group-next-unread-group 1)
2691             (gnus-configure-windows 'group 'force))
2692         (gnus-handle-ephemeral-exit quit-config))
2693       ;; Finally signal the quit.
2694       (signal 'quit nil))
2695      ;; The group was successfully selected.
2696      (t
2697       (gnus-set-global-variables)
2698       ;; Save the active value in effect when the group was entered.
2699       (setq gnus-newsgroup-active
2700             (gnus-copy-sequence
2701              (gnus-active gnus-newsgroup-name)))
2702       ;; You can change the summary buffer in some way with this hook.
2703       (gnus-run-hooks 'gnus-select-group-hook)
2704       ;; Set any local variables in the group parameters.
2705       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2706       (gnus-update-format-specifications
2707        nil 'summary 'summary-mode 'summary-dummy)
2708       ;; Do score processing.
2709       (when gnus-use-scoring
2710         (gnus-possibly-score-headers))
2711       ;; Check whether to fill in the gaps in the threads.
2712       (when gnus-build-sparse-threads
2713         (gnus-build-sparse-threads))
2714       ;; Find the initial limit.
2715       (if gnus-show-threads
2716           (if show-all
2717               (let ((gnus-newsgroup-dormant nil))
2718                 (gnus-summary-initial-limit show-all))
2719             (gnus-summary-initial-limit show-all))
2720         (setq gnus-newsgroup-limit
2721               (mapcar
2722                (lambda (header) (mail-header-number header))
2723                gnus-newsgroup-headers)))
2724       ;; Generate the summary buffer.
2725       (unless no-display
2726         (gnus-summary-prepare))
2727       (when gnus-use-trees
2728         (gnus-tree-open group)
2729         (setq gnus-summary-highlight-line-function
2730               'gnus-tree-highlight-article))
2731       ;; If the summary buffer is empty, but there are some low-scored
2732       ;; articles or some excluded dormants, we include these in the
2733       ;; buffer.
2734       (when (and (zerop (buffer-size))
2735                  (not no-display))
2736         (cond (gnus-newsgroup-dormant
2737                (gnus-summary-limit-include-dormant))
2738               ((and gnus-newsgroup-scored show-all)
2739                (gnus-summary-limit-include-expunged t))))
2740       ;; Function `gnus-apply-kill-file' must be called in this hook.
2741       (gnus-run-hooks 'gnus-apply-kill-hook)
2742       (if (and (zerop (buffer-size))
2743                (not no-display))
2744           (progn
2745             ;; This newsgroup is empty.
2746             (gnus-summary-catchup-and-exit nil t)
2747             (gnus-message 6 "No unread news")
2748             (when kill-buffer
2749               (gnus-kill-or-deaden-summary kill-buffer))
2750             ;; Return nil from this function.
2751             nil)
2752         ;; Hide conversation thread subtrees.  We cannot do this in
2753         ;; gnus-summary-prepare-hook since kill processing may not
2754         ;; work with hidden articles.
2755         (and gnus-show-threads
2756              gnus-thread-hide-subtree
2757              (gnus-summary-hide-all-threads))
2758         (when kill-buffer
2759           (gnus-kill-or-deaden-summary kill-buffer))
2760         ;; Show first unread article if requested.
2761         (if (and (not no-article)
2762                  (not no-display)
2763                  gnus-newsgroup-unreads
2764                  gnus-auto-select-first)
2765             (progn
2766               (gnus-configure-windows 'summary)
2767               (cond
2768                ((eq gnus-auto-select-first 'best)
2769                 (gnus-summary-best-unread-article))
2770                ((eq gnus-auto-select-first t)
2771                 (gnus-summary-first-unread-article))
2772                ((gnus-functionp gnus-auto-select-first)
2773                 (funcall gnus-auto-select-first))))
2774           ;; Don't select any articles, just move point to the first
2775           ;; article in the group.
2776           (goto-char (point-min))
2777           (gnus-summary-position-point)
2778           (gnus-configure-windows 'summary 'force)
2779           (gnus-set-mode-line 'summary))
2780         (when (get-buffer-window gnus-group-buffer t)
2781           ;; Gotta use windows, because recenter does weird stuff if
2782           ;; the current buffer ain't the displayed window.
2783           (let ((owin (selected-window)))
2784             (select-window (get-buffer-window gnus-group-buffer t))
2785             (when (gnus-group-goto-group group)
2786               (recenter))
2787             (select-window owin)))
2788         ;; Mark this buffer as "prepared".
2789         (setq gnus-newsgroup-prepared t)
2790         (gnus-run-hooks 'gnus-summary-prepared-hook)
2791         t)))))
2792
2793 (defun gnus-summary-prepare ()
2794   "Generate the summary buffer."
2795   (interactive)
2796   (let ((buffer-read-only nil))
2797     (erase-buffer)
2798     (setq gnus-newsgroup-data nil
2799           gnus-newsgroup-data-reverse nil)
2800     (gnus-run-hooks 'gnus-summary-generate-hook)
2801     ;; Generate the buffer, either with threads or without.
2802     (when gnus-newsgroup-headers
2803       (gnus-summary-prepare-threads
2804        (if gnus-show-threads
2805            (gnus-sort-gathered-threads
2806             (funcall gnus-summary-thread-gathering-function
2807                      (gnus-sort-threads
2808                       (gnus-cut-threads (gnus-make-threads)))))
2809          ;; Unthreaded display.
2810          (gnus-sort-articles gnus-newsgroup-headers))))
2811     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
2812     ;; Call hooks for modifying summary buffer.
2813     (goto-char (point-min))
2814     (gnus-run-hooks 'gnus-summary-prepare-hook)))
2815
2816 (defsubst gnus-general-simplify-subject (subject)
2817   "Simply subject by the same rules as gnus-gather-threads-by-subject."
2818   (setq subject
2819         (cond
2820          ;; Truncate the subject.
2821          (gnus-simplify-subject-functions
2822           (gnus-map-function gnus-simplify-subject-functions subject))
2823          ((numberp gnus-summary-gather-subject-limit)
2824           (setq subject (gnus-simplify-subject-re subject))
2825           (if (> (length subject) gnus-summary-gather-subject-limit)
2826               (substring subject 0 gnus-summary-gather-subject-limit)
2827             subject))
2828          ;; Fuzzily simplify it.
2829          ((eq 'fuzzy gnus-summary-gather-subject-limit)
2830           (gnus-simplify-subject-fuzzy subject))
2831          ;; Just remove the leading "Re:".
2832          (t
2833           (gnus-simplify-subject-re subject))))
2834
2835   (if (and gnus-summary-gather-exclude-subject
2836            (string-match gnus-summary-gather-exclude-subject subject))
2837       nil                               ; This article shouldn't be gathered
2838     subject))
2839
2840 (defun gnus-summary-simplify-subject-query ()
2841   "Query where the respool algorithm would put this article."
2842   (interactive)
2843   (gnus-summary-select-article)
2844   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
2845
2846 (defun gnus-gather-threads-by-subject (threads)
2847   "Gather threads by looking at Subject headers."
2848   (if (not gnus-summary-make-false-root)
2849       threads
2850     (let ((hashtb (gnus-make-hashtable 1024))
2851           (prev threads)
2852           (result threads)
2853           subject hthread whole-subject)
2854       (while threads
2855         (setq subject (gnus-general-simplify-subject
2856                        (setq whole-subject (mail-header-subject
2857                                             (caar threads)))))
2858         (when subject
2859           (if (setq hthread (gnus-gethash subject hashtb))
2860               (progn
2861                 ;; We enter a dummy root into the thread, if we
2862                 ;; haven't done that already.
2863                 (unless (stringp (caar hthread))
2864                   (setcar hthread (list whole-subject (car hthread))))
2865                 ;; We add this new gathered thread to this gathered
2866                 ;; thread.
2867                 (setcdr (car hthread)
2868                         (nconc (cdar hthread) (list (car threads))))
2869                 ;; Remove it from the list of threads.
2870                 (setcdr prev (cdr threads))
2871                 (setq threads prev))
2872             ;; Enter this thread into the hash table.
2873             (gnus-sethash subject threads hashtb)))
2874         (setq prev threads)
2875         (setq threads (cdr threads)))
2876       result)))
2877
2878 (defun gnus-gather-threads-by-references (threads)
2879   "Gather threads by looking at References headers."
2880   (let ((idhashtb (gnus-make-hashtable 1024))
2881         (thhashtb (gnus-make-hashtable 1024))
2882         (prev threads)
2883         (result threads)
2884         ids references id gthread gid entered ref)
2885     (while threads
2886       (when (setq references (mail-header-references (caar threads)))
2887         (setq id (mail-header-id (caar threads))
2888               ids (gnus-split-references references)
2889               entered nil)
2890         (while (setq ref (pop ids))
2891           (setq ids (delete ref ids))
2892           (if (not (setq gid (gnus-gethash ref idhashtb)))
2893               (progn
2894                 (gnus-sethash ref id idhashtb)
2895                 (gnus-sethash id threads thhashtb))
2896             (setq gthread (gnus-gethash gid thhashtb))
2897             (unless entered
2898               ;; We enter a dummy root into the thread, if we
2899               ;; haven't done that already.
2900               (unless (stringp (caar gthread))
2901                 (setcar gthread (list (mail-header-subject (caar gthread))
2902                                       (car gthread))))
2903               ;; We add this new gathered thread to this gathered
2904               ;; thread.
2905               (setcdr (car gthread)
2906                       (nconc (cdar gthread) (list (car threads)))))
2907             ;; Add it into the thread hash table.
2908             (gnus-sethash id gthread thhashtb)
2909             (setq entered t)
2910             ;; Remove it from the list of threads.
2911             (setcdr prev (cdr threads))
2912             (setq threads prev))))
2913       (setq prev threads)
2914       (setq threads (cdr threads)))
2915     result))
2916
2917 (defun gnus-sort-gathered-threads (threads)
2918   "Sort subtreads inside each gathered thread by article number."
2919   (let ((result threads))
2920     (while threads
2921       (when (stringp (caar threads))
2922         (setcdr (car threads)
2923                 (sort (cdar threads) 'gnus-thread-sort-by-number)))
2924       (setq threads (cdr threads)))
2925     result))
2926
2927 (defun gnus-thread-loop-p (root thread)
2928   "Say whether ROOT is in THREAD."
2929   (let ((stack (list thread))
2930         (infloop 0)
2931         th)
2932     (while (setq thread (pop stack))
2933       (setq th (cdr thread))
2934       (while (and th
2935                   (not (eq (caar th) root)))
2936         (pop th))
2937       (if th
2938           ;; We have found a loop.
2939           (let (ref-dep)
2940             (setcdr thread (delq (car th) (cdr thread)))
2941             (if (boundp (setq ref-dep (intern "none"
2942                                               gnus-newsgroup-dependencies)))
2943                 (setcdr (symbol-value ref-dep)
2944                         (nconc (cdr (symbol-value ref-dep))
2945                                (list (car th))))
2946               (set ref-dep (list nil (car th))))
2947             (setq infloop 1
2948                   stack nil))
2949         ;; Push all the subthreads onto the stack.
2950         (push (cdr thread) stack)))
2951     infloop))
2952
2953 (defun gnus-make-threads ()
2954   "Go through the dependency hashtb and find the roots.  Return all threads."
2955   (let (threads)
2956     (while (catch 'infloop
2957              (mapatoms
2958               (lambda (refs)
2959                 ;; Deal with self-referencing References loops.
2960                 (when (and (car (symbol-value refs))
2961                            (not (zerop
2962                                  (apply
2963                                   '+
2964                                   (mapcar
2965                                    (lambda (thread)
2966                                      (gnus-thread-loop-p
2967                                       (car (symbol-value refs)) thread))
2968                                    (cdr (symbol-value refs)))))))
2969                   (setq threads nil)
2970                   (throw 'infloop t))
2971                 (unless (car (symbol-value refs))
2972                   ;; These threads do not refer back to any other articles,
2973                   ;; so they're roots.
2974                   (setq threads (append (cdr (symbol-value refs)) threads))))
2975               gnus-newsgroup-dependencies)))
2976     threads))
2977
2978 ;; Build the thread tree.
2979 (defsubst gnus-dependencies-add-header (header dependencies force-new)
2980   "Enter HEADER into the DEPENDENCIES table if it is not already there.
2981
2982 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
2983 if it was already present.
2984
2985 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
2986 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
2987 Message-IDs will be renamed be renamed to a unique Message-ID before
2988 being entered.
2989
2990 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
2991   (let* ((id (mail-header-id header))
2992          (id-dep (and id (intern id dependencies)))
2993          ref ref-dep ref-header)
2994     ;; Enter this `header' in the `dependencies' table.
2995     (cond
2996      ((not id-dep)
2997       (setq header nil))
2998      ;; The first two cases do the normal part: enter a new `header'
2999      ;; in the `dependencies' table.
3000      ((not (boundp id-dep))
3001       (set id-dep (list header)))
3002      ((null (car (symbol-value id-dep)))
3003       (setcar (symbol-value id-dep) header))
3004
3005      ;; From here the `header' was already present in the
3006      ;; `dependencies' table.
3007      (force-new
3008       ;; Overrides an existing entry;
3009       ;; just set the header part of the entry.
3010       (setcar (symbol-value id-dep) header))
3011
3012      ;; Renames the existing `header' to a unique Message-ID.
3013      ((not gnus-summary-ignore-duplicates)
3014       ;; An article with this Message-ID has already been seen.
3015       ;; We rename the Message-ID.
3016       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3017            (list header))
3018       (mail-header-set-id header id))
3019
3020      ;; The last case ignores an existing entry, except it adds any
3021      ;; additional Xrefs (in case the two articles came from different
3022      ;; servers.
3023      ;; Also sets `header' to `nil' meaning that the `dependencies'
3024      ;; table was *not* modified.
3025      (t
3026       (mail-header-set-xref
3027        (car (symbol-value id-dep))
3028        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3029                    "")
3030                (or (mail-header-xref header) "")))
3031       (setq header nil)))
3032
3033     (when header
3034       ;; First check if that we are not creating a References loop.
3035       (setq ref (gnus-parent-id (mail-header-references header)))
3036       (while (and ref
3037                   (setq ref-dep (intern-soft ref dependencies))
3038                   (boundp ref-dep)
3039                   (setq ref-header (car (symbol-value ref-dep))))
3040         (if (string= id ref)
3041             ;; Yuk!  This is a reference loop.  Make the article be a
3042             ;; root article.
3043             (progn
3044               (mail-header-set-references (car (symbol-value id-dep)) "none")
3045               (setq ref nil))
3046           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3047       (setq ref (gnus-parent-id (mail-header-references header)))
3048       (setq ref-dep (intern (or ref "none") dependencies))
3049       (if (boundp ref-dep)
3050           (setcdr (symbol-value ref-dep)
3051                   (nconc (cdr (symbol-value ref-dep))
3052                          (list (symbol-value id-dep))))
3053         (set ref-dep (list nil (symbol-value id-dep)))))
3054     header))
3055
3056 (defun gnus-build-sparse-threads ()
3057   (let ((headers gnus-newsgroup-headers)
3058         (gnus-summary-ignore-duplicates t)
3059         header references generation relations
3060         subject child end new-child date)
3061     ;; First we create an alist of generations/relations, where
3062     ;; generations is how much we trust the relation, and the relation
3063     ;; is parent/child.
3064     (gnus-message 7 "Making sparse threads...")
3065     (save-excursion
3066       (nnheader-set-temp-buffer " *gnus sparse threads*")
3067       (while (setq header (pop headers))
3068         (when (and (setq references (mail-header-references header))
3069                    (not (string= references "")))
3070           (insert references)
3071           (setq child (mail-header-id header)
3072                 subject (mail-header-subject header)
3073                 date (mail-header-date header)
3074                 generation 0)
3075           (while (search-backward ">" nil t)
3076             (setq end (1+ (point)))
3077             (when (search-backward "<" nil t)
3078               (setq new-child (buffer-substring (point) end))
3079               (push (list (incf generation)
3080                           child (setq child new-child)
3081                           subject date)
3082                     relations)))
3083           (when child
3084             (push (list (1+ generation) child nil subject) relations))
3085           (erase-buffer)))
3086       (kill-buffer (current-buffer)))
3087     ;; Sort over trustworthiness.
3088     (mapcar
3089      (lambda (relation)
3090        (when (gnus-dependencies-add-header
3091               (make-full-mail-header
3092                gnus-reffed-article-number
3093                (nth 3 relation) "" (or (nth 4 relation) "")
3094                (nth 1 relation)
3095                (or (nth 2 relation) "") 0 0 "")
3096               gnus-newsgroup-dependencies nil)
3097          (push gnus-reffed-article-number gnus-newsgroup-limit)
3098          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3099          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3100                gnus-newsgroup-reads)
3101          (decf gnus-reffed-article-number)))
3102      (sort relations 'car-less-than-car))
3103     (gnus-message 7 "Making sparse threads...done")))
3104
3105 (defun gnus-build-old-threads ()
3106   ;; Look at all the articles that refer back to old articles, and
3107   ;; fetch the headers for the articles that aren't there.  This will
3108   ;; build complete threads - if the roots haven't been expired by the
3109   ;; server, that is.
3110   (let (id heads)
3111     (mapatoms
3112      (lambda (refs)
3113        (when (not (car (symbol-value refs)))
3114          (setq heads (cdr (symbol-value refs)))
3115          (while heads
3116            (if (memq (mail-header-number (caar heads))
3117                      gnus-newsgroup-dormant)
3118                (setq heads (cdr heads))
3119              (setq id (symbol-name refs))
3120              (while (and (setq id (gnus-build-get-header id))
3121                          (not (car (gnus-id-to-thread id)))))
3122              (setq heads nil)))))
3123      gnus-newsgroup-dependencies)))
3124
3125 (defmacro gnus-nov-read-integer ()
3126   '(prog1
3127        (if (eq (char-after) ?\t)
3128            0
3129          (let ((num (ignore-errors (read buffer))))
3130            (if (numberp num) num 0)))
3131      (unless (eobp)
3132        (search-forward "\t" eol 'move))))
3133
3134 (defmacro gnus-nov-skip-field ()
3135   '(search-forward "\t" eol 'move))
3136
3137 (defmacro gnus-nov-field ()
3138   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
3139
3140 (defmacro gnus-nov-parse-extra ()
3141   '(let (out string)
3142      (while (not (memq (char-after) '(?\n nil)))
3143        (setq string (gnus-nov-field))
3144        (when (string-match "^\\([^ :]+\\): " string)
3145          (push (cons (intern (match-string 1 string))
3146                      (substring string (match-end 0)))
3147                out)))
3148      out))
3149
3150 ;; This function has to be called with point after the article number
3151 ;; on the beginning of the line.
3152 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3153   (let ((eol (gnus-point-at-eol))
3154         (buffer (current-buffer))
3155         header)
3156
3157     ;; overview: [num subject from date id refs chars lines misc]
3158     (unwind-protect
3159         (progn
3160           (narrow-to-region (point) eol)
3161           (unless (eobp)
3162             (forward-char))
3163
3164           (setq header
3165                 (make-full-mail-header
3166                  number                 ; number
3167                  (gnus-nov-field)       ; subject
3168                  (gnus-nov-field)       ; from
3169                  (gnus-nov-field)       ; date
3170                  (or (gnus-nov-field)
3171                      (nnheader-generate-fake-message-id)) ; id
3172                  (gnus-nov-field)       ; refs
3173                  (gnus-nov-read-integer) ; chars
3174                  (gnus-nov-read-integer) ; lines
3175                  (unless (eq (char-after) ?\n)
3176                    (gnus-nov-field))    ; misc
3177                  (gnus-nov-parse-extra)))) ; extra
3178
3179       (widen))
3180
3181     (when gnus-alter-header-function
3182       (funcall gnus-alter-header-function header))
3183     (gnus-dependencies-add-header header dependencies force-new)))
3184
3185 (defun gnus-build-get-header (id)
3186   ;; Look through the buffer of NOV lines and find the header to
3187   ;; ID.  Enter this line into the dependencies hash table, and return
3188   ;; the id of the parent article (if any).
3189   (let ((deps gnus-newsgroup-dependencies)
3190         found header)
3191     (prog1
3192         (save-excursion
3193           (set-buffer nntp-server-buffer)
3194           (let ((case-fold-search nil))
3195             (goto-char (point-min))
3196             (while (and (not found)
3197                         (search-forward id nil t))
3198               (beginning-of-line)
3199               (setq found (looking-at
3200                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3201                                    (regexp-quote id))))
3202               (or found (beginning-of-line 2)))
3203             (when found
3204               (beginning-of-line)
3205               (and
3206                (setq header (gnus-nov-parse-line
3207                              (read (current-buffer)) deps))
3208                (gnus-parent-id (mail-header-references header))))))
3209       (when header
3210         (let ((number (mail-header-number header)))
3211           (push number gnus-newsgroup-limit)
3212           (push header gnus-newsgroup-headers)
3213           (if (memq number gnus-newsgroup-unselected)
3214               (progn
3215                 (push number gnus-newsgroup-unreads)
3216                 (setq gnus-newsgroup-unselected
3217                       (delq number gnus-newsgroup-unselected)))
3218             (push number gnus-newsgroup-ancient)))))))
3219
3220 (defun gnus-build-all-threads ()
3221   "Read all the headers."
3222   (let ((gnus-summary-ignore-duplicates t)
3223         (dependencies gnus-newsgroup-dependencies)
3224         header article)
3225     (save-excursion
3226       (set-buffer nntp-server-buffer)
3227       (let ((case-fold-search nil))
3228         (goto-char (point-min))
3229         (while (not (eobp))
3230           (ignore-errors
3231             (setq article (read (current-buffer))
3232                   header (gnus-nov-parse-line
3233                           article dependencies)))
3234           (when header
3235             (save-excursion
3236               (set-buffer gnus-summary-buffer)
3237               (push header gnus-newsgroup-headers)
3238               (if (memq (setq article (mail-header-number header))
3239                         gnus-newsgroup-unselected)
3240                   (progn
3241                     (push article gnus-newsgroup-unreads)
3242                     (setq gnus-newsgroup-unselected
3243                           (delq article gnus-newsgroup-unselected)))
3244                 (push article gnus-newsgroup-ancient)))
3245             (forward-line 1)))))))
3246
3247 (defun gnus-summary-update-article-line (article header)
3248   "Update the line for ARTICLE using HEADERS."
3249   (let* ((id (mail-header-id header))
3250          (thread (gnus-id-to-thread id)))
3251     (unless thread
3252       (error "Article in no thread"))
3253     ;; Update the thread.
3254     (setcar thread header)
3255     (gnus-summary-goto-subject article)
3256     (let* ((datal (gnus-data-find-list article))
3257            (data (car datal))
3258            (length (when (cdr datal)
3259                      (- (gnus-data-pos data)
3260                         (gnus-data-pos (cadr datal)))))
3261            (buffer-read-only nil)
3262            (level (gnus-summary-thread-level)))
3263       (gnus-delete-line)
3264       (gnus-summary-insert-line
3265        header level nil (gnus-article-mark article)
3266        (memq article gnus-newsgroup-replied)
3267        (memq article gnus-newsgroup-expirable)
3268        ;; Only insert the Subject string when it's different
3269        ;; from the previous Subject string.
3270        (if (gnus-subject-equal
3271             (condition-case ()
3272                 (mail-header-subject
3273                  (gnus-data-header
3274                   (cadr
3275                    (gnus-data-find-list
3276                     article
3277                     (gnus-data-list t)))))
3278               ;; Error on the side of excessive subjects.
3279               (error ""))
3280             (mail-header-subject header))
3281            ""
3282          (mail-header-subject header))
3283        nil (cdr (assq article gnus-newsgroup-scored))
3284        (memq article gnus-newsgroup-processable))
3285       (when length
3286         (gnus-data-update-list
3287          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3288
3289 (defun gnus-summary-update-article (article &optional iheader)
3290   "Update ARTICLE in the summary buffer."
3291   (set-buffer gnus-summary-buffer)
3292   (let* ((header (gnus-summary-article-header article))
3293          (id (mail-header-id header))
3294          (data (gnus-data-find article))
3295          (thread (gnus-id-to-thread id))
3296          (references (mail-header-references header))
3297          (parent
3298           (gnus-id-to-thread
3299            (or (gnus-parent-id
3300                 (when (and references
3301                            (not (equal "" references)))
3302                   references))
3303                "none")))
3304          (buffer-read-only nil)
3305          (old (car thread)))
3306     (when thread
3307       (unless iheader
3308         (setcar thread nil)
3309         (when parent
3310           (delq thread parent)))
3311       (if (gnus-summary-insert-subject id header)
3312           ;; Set the (possibly) new article number in the data structure.
3313           (gnus-data-set-number data (gnus-id-to-article id))
3314         (setcar thread old)
3315         nil))))
3316
3317 (defun gnus-rebuild-thread (id &optional line)
3318   "Rebuild the thread containing ID.
3319 If LINE, insert the rebuilt thread starting on line LINE."
3320   (let ((buffer-read-only nil)
3321         old-pos current thread data)
3322     (if (not gnus-show-threads)
3323         (setq thread (list (car (gnus-id-to-thread id))))
3324       ;; Get the thread this article is part of.
3325       (setq thread (gnus-remove-thread id)))
3326     (setq old-pos (gnus-point-at-bol))
3327     (setq current (save-excursion
3328                     (and (zerop (forward-line -1))
3329                          (gnus-summary-article-number))))
3330     ;; If this is a gathered thread, we have to go some re-gathering.
3331     (when (stringp (car thread))
3332       (let ((subject (car thread))
3333             roots thr)
3334         (setq thread (cdr thread))
3335         (while thread
3336           (unless (memq (setq thr (gnus-id-to-thread
3337                                    (gnus-root-id
3338                                     (mail-header-id (caar thread)))))
3339                         roots)
3340             (push thr roots))
3341           (setq thread (cdr thread)))
3342         ;; We now have all (unique) roots.
3343         (if (= (length roots) 1)
3344             ;; All the loose roots are now one solid root.
3345             (setq thread (car roots))
3346           (setq thread (cons subject (gnus-sort-threads roots))))))
3347     (let (threads)
3348       ;; We then insert this thread into the summary buffer.
3349       (when line
3350         (goto-char (point-min))
3351         (forward-line (1- line)))
3352       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3353         (if gnus-show-threads
3354             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3355           (gnus-summary-prepare-unthreaded thread))
3356         (setq data (nreverse gnus-newsgroup-data))
3357         (setq threads gnus-newsgroup-threads))
3358       ;; We splice the new data into the data structure.
3359       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3360       ;;!!! then we want to insert at the beginning of the buffer.
3361       ;;!!! That happens to be true with Gnus now, but that may
3362       ;;!!! change in the future.  Perhaps.
3363       (gnus-data-enter-list
3364        (if line nil current) data (- (point) old-pos))
3365       (setq gnus-newsgroup-threads
3366             (nconc threads gnus-newsgroup-threads))
3367       (gnus-data-compute-positions))))
3368
3369 (defun gnus-number-to-header (number)
3370   "Return the header for article NUMBER."
3371   (let ((headers gnus-newsgroup-headers))
3372     (while (and headers
3373                 (not (= number (mail-header-number (car headers)))))
3374       (pop headers))
3375     (when headers
3376       (car headers))))
3377
3378 (defun gnus-parent-headers (in-headers &optional generation)
3379   "Return the headers of the GENERATIONeth parent of HEADERS."
3380   (unless generation
3381     (setq generation 1))
3382   (let ((parent t)
3383         (headers in-headers)
3384         references)
3385     (while (and parent
3386                 (not (zerop generation))
3387                 (setq references (mail-header-references headers)))
3388       (setq headers (if (and references
3389                              (setq parent (gnus-parent-id references)))
3390                         (car (gnus-id-to-thread parent))
3391                       nil))
3392       (decf generation))
3393     (and (not (eq headers in-headers))
3394          headers)))
3395
3396 (defun gnus-id-to-thread (id)
3397   "Return the (sub-)thread where ID appears."
3398   (gnus-gethash id gnus-newsgroup-dependencies))
3399
3400 (defun gnus-id-to-article (id)
3401   "Return the article number of ID."
3402   (let ((thread (gnus-id-to-thread id)))
3403     (when (and thread
3404                (car thread))
3405       (mail-header-number (car thread)))))
3406
3407 (defun gnus-id-to-header (id)
3408   "Return the article headers of ID."
3409   (car (gnus-id-to-thread id)))
3410
3411 (defun gnus-article-displayed-root-p (article)
3412   "Say whether ARTICLE is a root(ish) article."
3413   (let ((level (gnus-summary-thread-level article))
3414         (refs (mail-header-references  (gnus-summary-article-header article)))
3415         particle)
3416     (cond
3417      ((null level) nil)
3418      ((zerop level) t)
3419      ((null refs) t)
3420      ((null (gnus-parent-id refs)) t)
3421      ((and (= 1 level)
3422            (null (setq particle (gnus-id-to-article
3423                                  (gnus-parent-id refs))))
3424            (null (gnus-summary-thread-level particle)))))))
3425
3426 (defun gnus-root-id (id)
3427   "Return the id of the root of the thread where ID appears."
3428   (let (last-id prev)
3429     (while (and id (setq prev (car (gnus-id-to-thread id))))
3430       (setq last-id id
3431             id (gnus-parent-id (mail-header-references prev))))
3432     last-id))
3433
3434 (defun gnus-articles-in-thread (thread)
3435   "Return the list of articles in THREAD."
3436   (cons (mail-header-number (car thread))
3437         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3438
3439 (defun gnus-remove-thread (id &optional dont-remove)
3440   "Remove the thread that has ID in it."
3441   (let (headers thread last-id)
3442     ;; First go up in this thread until we find the root.
3443     (setq last-id (gnus-root-id id)
3444           headers (message-flatten-list (gnus-id-to-thread last-id)))
3445     ;; We have now found the real root of this thread.  It might have
3446     ;; been gathered into some loose thread, so we have to search
3447     ;; through the threads to find the thread we wanted.
3448     (let ((threads gnus-newsgroup-threads)
3449           sub)
3450       (while threads
3451         (setq sub (car threads))
3452         (if (stringp (car sub))
3453             ;; This is a gathered thread, so we look at the roots
3454             ;; below it to find whether this article is in this
3455             ;; gathered root.
3456             (progn
3457               (setq sub (cdr sub))
3458               (while sub
3459                 (when (member (caar sub) headers)
3460                   (setq thread (car threads)
3461                         threads nil
3462                         sub nil))
3463                 (setq sub (cdr sub))))
3464           ;; It's an ordinary thread, so we check it.
3465           (when (eq (car sub) (car headers))
3466             (setq thread sub
3467                   threads nil)))
3468         (setq threads (cdr threads)))
3469       ;; If this article is in no thread, then it's a root.
3470       (if thread
3471           (unless dont-remove
3472             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3473         (setq thread (gnus-id-to-thread last-id)))
3474       (when thread
3475         (prog1
3476             thread                      ; We return this thread.
3477           (unless dont-remove
3478             (if (stringp (car thread))
3479                 (progn
3480                   ;; If we use dummy roots, then we have to remove the
3481                   ;; dummy root as well.
3482                   (when (eq gnus-summary-make-false-root 'dummy)
3483                     ;; We go to the dummy root by going to
3484                     ;; the first sub-"thread", and then one line up.
3485                     (gnus-summary-goto-article
3486                      (mail-header-number (caadr thread)))
3487                     (forward-line -1)
3488                     (gnus-delete-line)
3489                     (gnus-data-compute-positions))
3490                   (setq thread (cdr thread))
3491                   (while thread
3492                     (gnus-remove-thread-1 (car thread))
3493                     (setq thread (cdr thread))))
3494               (gnus-summary-show-all-threads)
3495               (gnus-remove-thread-1 thread))))))))
3496
3497 (defun gnus-remove-thread-1 (thread)
3498   "Remove the thread THREAD recursively."
3499   (let ((number (mail-header-number (pop thread)))
3500         d)
3501     (setq thread (reverse thread))
3502     (while thread
3503       (gnus-remove-thread-1 (pop thread)))
3504     (when (setq d (gnus-data-find number))
3505       (goto-char (gnus-data-pos d))
3506       (gnus-data-remove
3507        number
3508        (- (gnus-point-at-bol)
3509           (prog1
3510               (1+ (gnus-point-at-eol))
3511             (gnus-delete-line)))))))
3512
3513 (defun gnus-sort-threads (threads)
3514   "Sort THREADS."
3515   (if (not gnus-thread-sort-functions)
3516       threads
3517     (gnus-message 8 "Sorting threads...")
3518     (prog1
3519         (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
3520       (gnus-message 8 "Sorting threads...done"))))
3521
3522 (defun gnus-sort-articles (articles)
3523   "Sort ARTICLES."
3524   (when gnus-article-sort-functions
3525     (gnus-message 7 "Sorting articles...")
3526     (prog1
3527         (setq gnus-newsgroup-headers
3528               (sort articles (gnus-make-sort-function
3529                               gnus-article-sort-functions)))
3530       (gnus-message 7 "Sorting articles...done"))))
3531
3532 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3533 (defmacro gnus-thread-header (thread)
3534   ;; Return header of first article in THREAD.
3535   ;; Note that THREAD must never, ever be anything else than a variable -
3536   ;; using some other form will lead to serious barfage.
3537   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3538   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3539   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
3540         (vector thread) 2))
3541
3542 (defsubst gnus-article-sort-by-number (h1 h2)
3543   "Sort articles by article number."
3544   (< (mail-header-number h1)
3545      (mail-header-number h2)))
3546
3547 (defun gnus-thread-sort-by-number (h1 h2)
3548   "Sort threads by root article number."
3549   (gnus-article-sort-by-number
3550    (gnus-thread-header h1) (gnus-thread-header h2)))
3551
3552 (defsubst gnus-article-sort-by-lines (h1 h2)
3553   "Sort articles by article Lines header."
3554   (< (mail-header-lines h1)
3555      (mail-header-lines h2)))
3556
3557 (defun gnus-thread-sort-by-lines (h1 h2)
3558   "Sort threads by root article Lines header."
3559   (gnus-article-sort-by-lines
3560    (gnus-thread-header h1) (gnus-thread-header h2)))
3561
3562 (defsubst gnus-article-sort-by-author (h1 h2)
3563   "Sort articles by root author."
3564   (string-lessp
3565    (let ((addr (mime-read-field 'From h1)))
3566      (or (std11-full-name-string addr)
3567          (std11-address-string addr)
3568          ""))
3569    (let ((addr (mime-read-field 'From h2)))
3570      (or (std11-full-name-string addr)
3571          (std11-address-string addr)
3572          ""))
3573    ))
3574
3575 (defun gnus-thread-sort-by-author (h1 h2)
3576   "Sort threads by root author."
3577   (gnus-article-sort-by-author
3578    (gnus-thread-header h1)  (gnus-thread-header h2)))
3579
3580 (defsubst gnus-article-sort-by-subject (h1 h2)
3581   "Sort articles by root subject."
3582   (string-lessp
3583    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3584    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3585
3586 (defun gnus-thread-sort-by-subject (h1 h2)
3587   "Sort threads by root subject."
3588   (gnus-article-sort-by-subject
3589    (gnus-thread-header h1) (gnus-thread-header h2)))
3590
3591 (defsubst gnus-article-sort-by-date (h1 h2)
3592   "Sort articles by root article date."
3593   (time-less-p
3594    (gnus-date-get-time (mail-header-date h1))
3595    (gnus-date-get-time (mail-header-date h2))))
3596
3597 (defun gnus-thread-sort-by-date (h1 h2)
3598   "Sort threads by root article date."
3599   (gnus-article-sort-by-date
3600    (gnus-thread-header h1) (gnus-thread-header h2)))
3601
3602 (defsubst gnus-article-sort-by-score (h1 h2)
3603   "Sort articles by root article score.
3604 Unscored articles will be counted as having a score of zero."
3605   (> (or (cdr (assq (mail-header-number h1)
3606                     gnus-newsgroup-scored))
3607          gnus-summary-default-score 0)
3608      (or (cdr (assq (mail-header-number h2)
3609                     gnus-newsgroup-scored))
3610          gnus-summary-default-score 0)))
3611
3612 (defun gnus-thread-sort-by-score (h1 h2)
3613   "Sort threads by root article score."
3614   (gnus-article-sort-by-score
3615    (gnus-thread-header h1) (gnus-thread-header h2)))
3616
3617 (defun gnus-thread-sort-by-total-score (h1 h2)
3618   "Sort threads by the sum of all scores in the thread.
3619 Unscored articles will be counted as having a score of zero."
3620   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3621
3622 (defun gnus-thread-total-score (thread)
3623   ;;  This function find the total score of THREAD.
3624   (cond ((null thread)
3625          0)
3626         ((consp thread)
3627          (if (stringp (car thread))
3628              (apply gnus-thread-score-function 0
3629                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3630            (gnus-thread-total-score-1 thread)))
3631         (t
3632          (gnus-thread-total-score-1 (list thread)))))
3633
3634 (defun gnus-thread-total-score-1 (root)
3635   ;; This function find the total score of the thread below ROOT.
3636   (setq root (car root))
3637   (apply gnus-thread-score-function
3638          (or (append
3639               (mapcar 'gnus-thread-total-score
3640                       (cdr (gnus-id-to-thread (mail-header-id root))))
3641               (when (> (mail-header-number root) 0)
3642                 (list (or (cdr (assq (mail-header-number root)
3643                                      gnus-newsgroup-scored))
3644                           gnus-summary-default-score 0))))
3645              (list gnus-summary-default-score)
3646              '(0))))
3647
3648 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3649 (defvar gnus-tmp-prev-subject nil)
3650 (defvar gnus-tmp-false-parent nil)
3651 (defvar gnus-tmp-root-expunged nil)
3652 (defvar gnus-tmp-dummy-line nil)
3653
3654 (defvar gnus-tmp-header)
3655 (defun gnus-extra-header (type &optional header)
3656   "Return the extra header of TYPE."
3657   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3658       ""))
3659
3660 (defun gnus-summary-prepare-threads (threads)
3661   "Prepare summary buffer from THREADS and indentation LEVEL.
3662 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3663 or a straight list of headers."
3664   (gnus-message 7 "Generating summary...")
3665
3666   (setq gnus-newsgroup-threads threads)
3667   (beginning-of-line)
3668
3669   (let ((gnus-tmp-level 0)
3670         (default-score (or gnus-summary-default-score 0))
3671         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3672         thread number subject stack state gnus-tmp-gathered beg-match
3673         new-roots gnus-tmp-new-adopts thread-end
3674         gnus-tmp-header gnus-tmp-unread
3675         gnus-tmp-replied gnus-tmp-subject-or-nil
3676         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3677         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3678         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3679
3680     (setq gnus-tmp-prev-subject nil)
3681
3682     (if (vectorp (car threads))
3683         ;; If this is a straight (sic) list of headers, then a
3684         ;; threaded summary display isn't required, so we just create
3685         ;; an unthreaded one.
3686         (gnus-summary-prepare-unthreaded threads)
3687
3688       ;; Do the threaded display.
3689
3690       (while (or threads stack gnus-tmp-new-adopts new-roots)
3691
3692         (if (and (= gnus-tmp-level 0)
3693                  (or (not stack)
3694                      (= (caar stack) 0))
3695                  (not gnus-tmp-false-parent)
3696                  (or gnus-tmp-new-adopts new-roots))
3697             (if gnus-tmp-new-adopts
3698                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3699                       thread (list (car gnus-tmp-new-adopts))
3700                       gnus-tmp-header (caar thread)
3701                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3702               (when new-roots
3703                 (setq thread (list (car new-roots))
3704                       gnus-tmp-header (caar thread)
3705                       new-roots (cdr new-roots))))
3706
3707           (if threads
3708               ;; If there are some threads, we do them before the
3709               ;; threads on the stack.
3710               (setq thread threads
3711                     gnus-tmp-header (caar thread))
3712             ;; There were no current threads, so we pop something off
3713             ;; the stack.
3714             (setq state (car stack)
3715                   gnus-tmp-level (car state)
3716                   thread (cdr state)
3717                   stack (cdr stack)
3718                   gnus-tmp-header (caar thread))))
3719
3720         (setq gnus-tmp-false-parent nil)
3721         (setq gnus-tmp-root-expunged nil)
3722         (setq thread-end nil)
3723
3724         (if (stringp gnus-tmp-header)
3725             ;; The header is a dummy root.
3726             (cond
3727              ((eq gnus-summary-make-false-root 'adopt)
3728               ;; We let the first article adopt the rest.
3729               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3730                                                (cddar thread)))
3731               (setq gnus-tmp-gathered
3732                     (nconc (mapcar
3733                             (lambda (h) (mail-header-number (car h)))
3734                             (cddar thread))
3735                            gnus-tmp-gathered))
3736               (setq thread (cons (list (caar thread)
3737                                        (cadar thread))
3738                                  (cdr thread)))
3739               (setq gnus-tmp-level -1
3740                     gnus-tmp-false-parent t))
3741              ((eq gnus-summary-make-false-root 'empty)
3742               ;; We print adopted articles with empty subject fields.
3743               (setq gnus-tmp-gathered
3744                     (nconc (mapcar
3745                             (lambda (h) (mail-header-number (car h)))
3746                             (cddar thread))
3747                            gnus-tmp-gathered))
3748               (setq gnus-tmp-level -1))
3749              ((eq gnus-summary-make-false-root 'dummy)
3750               ;; We remember that we probably want to output a dummy
3751               ;; root.
3752               (setq gnus-tmp-dummy-line gnus-tmp-header)
3753               (setq gnus-tmp-prev-subject gnus-tmp-header))
3754              (t
3755               ;; We do not make a root for the gathered
3756               ;; sub-threads at all.
3757               (setq gnus-tmp-level -1)))
3758
3759           (setq number (mail-header-number gnus-tmp-header)
3760                 subject (mail-header-subject gnus-tmp-header))
3761
3762           (cond
3763            ;; If the thread has changed subject, we might want to make
3764            ;; this subthread into a root.
3765            ((and (null gnus-thread-ignore-subject)
3766                  (not (zerop gnus-tmp-level))
3767                  gnus-tmp-prev-subject
3768                  (not (inline
3769                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
3770             (setq new-roots (nconc new-roots (list (car thread)))
3771                   thread-end t
3772                   gnus-tmp-header nil))
3773            ;; If the article lies outside the current limit,
3774            ;; then we do not display it.
3775            ((not (memq number gnus-newsgroup-limit))
3776             (setq gnus-tmp-gathered
3777                   (nconc (mapcar
3778                           (lambda (h) (mail-header-number (car h)))
3779                           (cdar thread))
3780                          gnus-tmp-gathered))
3781             (setq gnus-tmp-new-adopts (if (cdar thread)
3782                                           (append gnus-tmp-new-adopts
3783                                                   (cdar thread))
3784                                         gnus-tmp-new-adopts)
3785                   thread-end t
3786                   gnus-tmp-header nil)
3787             (when (zerop gnus-tmp-level)
3788               (setq gnus-tmp-root-expunged t)))
3789            ;; Perhaps this article is to be marked as read?
3790            ((and gnus-summary-mark-below
3791                  (< (or (cdr (assq number gnus-newsgroup-scored))
3792                         default-score)
3793                     gnus-summary-mark-below)
3794                  ;; Don't touch sparse articles.
3795                  (not (gnus-summary-article-sparse-p number))
3796                  (not (gnus-summary-article-ancient-p number)))
3797             (setq gnus-newsgroup-unreads
3798                   (delq number gnus-newsgroup-unreads))
3799             (if gnus-newsgroup-auto-expire
3800                 (push number gnus-newsgroup-expirable)
3801               (push (cons number gnus-low-score-mark)
3802                     gnus-newsgroup-reads))))
3803
3804           (when gnus-tmp-header
3805             ;; We may have an old dummy line to output before this
3806             ;; article.
3807             (when (and gnus-tmp-dummy-line
3808                        (gnus-subject-equal
3809                         gnus-tmp-dummy-line
3810                         (mail-header-subject gnus-tmp-header)))
3811               (gnus-summary-insert-dummy-line
3812                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
3813               (setq gnus-tmp-dummy-line nil))
3814
3815             ;; Compute the mark.
3816             (setq gnus-tmp-unread (gnus-article-mark number))
3817
3818             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
3819                                   gnus-tmp-header gnus-tmp-level)
3820                   gnus-newsgroup-data)
3821
3822             ;; Actually insert the line.
3823             (setq
3824              gnus-tmp-subject-or-nil
3825              (cond
3826               ((and gnus-thread-ignore-subject
3827                     gnus-tmp-prev-subject
3828                     (not (inline (gnus-subject-equal
3829                                   gnus-tmp-prev-subject subject))))
3830                subject)
3831               ((zerop gnus-tmp-level)
3832                (if (and (eq gnus-summary-make-false-root 'empty)
3833                         (memq number gnus-tmp-gathered)
3834                         gnus-tmp-prev-subject
3835                         (inline (gnus-subject-equal
3836                                  gnus-tmp-prev-subject subject)))
3837                    gnus-summary-same-subject
3838                  subject))
3839               (t gnus-summary-same-subject)))
3840             (if (and (eq gnus-summary-make-false-root 'adopt)
3841                      (= gnus-tmp-level 1)
3842                      (memq number gnus-tmp-gathered))
3843                 (setq gnus-tmp-opening-bracket ?\<
3844                       gnus-tmp-closing-bracket ?\>)
3845               (setq gnus-tmp-opening-bracket ?\[
3846                     gnus-tmp-closing-bracket ?\]))
3847             (setq
3848              gnus-tmp-indentation
3849              (aref gnus-thread-indent-array gnus-tmp-level)
3850              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
3851              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
3852                                 gnus-summary-default-score 0)
3853              gnus-tmp-score-char
3854              (if (or (null gnus-summary-default-score)
3855                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3856                          gnus-summary-zcore-fuzz))
3857                  ? 
3858                (if (< gnus-tmp-score gnus-summary-default-score)
3859                    gnus-score-below-mark gnus-score-over-mark))
3860              gnus-tmp-replied
3861              (cond ((memq number gnus-newsgroup-processable)
3862                     gnus-process-mark)
3863                    ((memq number gnus-newsgroup-cached)
3864                     gnus-cached-mark)
3865                    ((memq number gnus-newsgroup-replied)
3866                     gnus-replied-mark)
3867                    ((memq number gnus-newsgroup-saved)
3868                     gnus-saved-mark)
3869                    (t gnus-unread-mark))
3870              gnus-tmp-from (mail-header-from gnus-tmp-header)
3871              gnus-tmp-name
3872              (cond
3873               ((string-match "<[^>]+> *$" gnus-tmp-from)
3874                (setq beg-match (match-beginning 0))
3875                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
3876                         (substring gnus-tmp-from (1+ (match-beginning 0))
3877                                    (1- (match-end 0))))
3878                    (substring gnus-tmp-from 0 beg-match)))
3879               ((string-match "(.+)" gnus-tmp-from)
3880                (substring gnus-tmp-from
3881                           (1+ (match-beginning 0)) (1- (match-end 0))))
3882               (t gnus-tmp-from)))
3883             (when (string= gnus-tmp-name "")
3884               (setq gnus-tmp-name gnus-tmp-from))
3885             (unless (numberp gnus-tmp-lines)
3886               (setq gnus-tmp-lines 0))
3887             (gnus-put-text-property
3888              (point)
3889              (progn (eval gnus-summary-line-format-spec) (point))
3890              'gnus-number number)
3891             (when gnus-visual-p
3892               (forward-line -1)
3893               (gnus-run-hooks 'gnus-summary-update-hook)
3894               (forward-line 1))
3895
3896             (setq gnus-tmp-prev-subject subject)))
3897
3898         (when (nth 1 thread)
3899           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
3900         (incf gnus-tmp-level)
3901         (setq threads (if thread-end nil (cdar thread)))
3902         (unless threads
3903           (setq gnus-tmp-level 0)))))
3904   (gnus-message 7 "Generating summary...done"))
3905
3906 (defun gnus-summary-prepare-unthreaded (headers)
3907   "Generate an unthreaded summary buffer based on HEADERS."
3908   (let (header number mark)
3909
3910     (beginning-of-line)
3911
3912     (while headers
3913       ;; We may have to root out some bad articles...
3914       (when (memq (setq number (mail-header-number
3915                                 (setq header (pop headers))))
3916                   gnus-newsgroup-limit)
3917         ;; Mark article as read when it has a low score.
3918         (when (and gnus-summary-mark-below
3919                    (< (or (cdr (assq number gnus-newsgroup-scored))
3920                           gnus-summary-default-score 0)
3921                       gnus-summary-mark-below)
3922                    (not (gnus-summary-article-ancient-p number)))
3923           (setq gnus-newsgroup-unreads
3924                 (delq number gnus-newsgroup-unreads))
3925           (if gnus-newsgroup-auto-expire
3926               (push number gnus-newsgroup-expirable)
3927             (push (cons number gnus-low-score-mark)
3928                   gnus-newsgroup-reads)))
3929
3930         (setq mark (gnus-article-mark number))
3931         (push (gnus-data-make number mark (1+ (point)) header 0)
3932               gnus-newsgroup-data)
3933         (gnus-summary-insert-line
3934          header 0 number
3935          mark (memq number gnus-newsgroup-replied)
3936          (memq number gnus-newsgroup-expirable)
3937          (mail-header-subject header) nil
3938          (cdr (assq number gnus-newsgroup-scored))
3939          (memq number gnus-newsgroup-processable))))))
3940
3941 (defun gnus-select-newsgroup (group &optional read-all select-articles)
3942   "Select newsgroup GROUP.
3943 If READ-ALL is non-nil, all articles in the group are selected.
3944 If SELECT-ARTICLES, only select those articles from GROUP."
3945   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
3946          ;;!!! Dirty hack; should be removed.
3947          (gnus-summary-ignore-duplicates
3948           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
3949               t
3950             gnus-summary-ignore-duplicates))
3951          (info (nth 2 entry))
3952          articles fetched-articles cached)
3953
3954     (unless (gnus-check-server
3955              (setq gnus-current-select-method
3956                    (gnus-find-method-for-group group)))
3957       (error "Couldn't open server"))
3958
3959     (or (and entry (not (eq (car entry) t))) ; Either it's active...
3960         (gnus-activate-group group)     ; Or we can activate it...
3961         (progn                          ; Or we bug out.
3962           (when (equal major-mode 'gnus-summary-mode)
3963             (kill-buffer (current-buffer)))
3964           (error "Couldn't request group %s: %s"
3965                  group (gnus-status-message group))))
3966
3967     (unless (gnus-request-group group t)
3968       (when (equal major-mode 'gnus-summary-mode)
3969         (kill-buffer (current-buffer)))
3970       (error "Couldn't request group %s: %s"
3971              group (gnus-status-message group)))
3972
3973     (setq gnus-newsgroup-name group)
3974     (setq gnus-newsgroup-unselected nil)
3975     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
3976
3977     ;; Adjust and set lists of article marks.
3978     (when info
3979       (gnus-adjust-marked-articles info))
3980
3981     ;; Kludge to avoid having cached articles nixed out in virtual groups.
3982     (when (gnus-virtual-group-p group)
3983       (setq cached gnus-newsgroup-cached))
3984
3985     (setq gnus-newsgroup-unreads
3986           (gnus-set-difference
3987            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
3988            gnus-newsgroup-dormant))
3989
3990     (setq gnus-newsgroup-processable nil)
3991
3992     (gnus-update-read-articles group gnus-newsgroup-unreads)
3993
3994     (if (setq articles select-articles)
3995         (setq gnus-newsgroup-unselected
3996               (gnus-sorted-intersection
3997                gnus-newsgroup-unreads
3998                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
3999       (setq articles (gnus-articles-to-read group read-all)))
4000
4001     (cond
4002      ((null articles)
4003       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4004       'quit)
4005      ((eq articles 0) nil)
4006      (t
4007       ;; Init the dependencies hash table.
4008       (setq gnus-newsgroup-dependencies
4009             (gnus-make-hashtable (length articles)))
4010       (gnus-set-global-variables)
4011       ;; Retrieve the headers and read them in.
4012       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4013       (setq gnus-newsgroup-headers
4014             (if (eq 'nov
4015                     (setq gnus-headers-retrieved-by
4016                           (gnus-retrieve-headers
4017                            articles gnus-newsgroup-name
4018                            ;; We might want to fetch old headers, but
4019                            ;; not if there is only 1 article.
4020                            (and (or (and
4021                                      (not (eq gnus-fetch-old-headers 'some))
4022                                      (not (numberp gnus-fetch-old-headers)))
4023                                     (> (length articles) 1))
4024                                 gnus-fetch-old-headers))))
4025                 (gnus-get-newsgroup-headers-xover
4026                  articles nil nil gnus-newsgroup-name t)
4027               (gnus-get-newsgroup-headers)))
4028       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4029
4030       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4031       (when cached
4032         (setq gnus-newsgroup-cached cached))
4033
4034       ;; Suppress duplicates?
4035       (when gnus-suppress-duplicates
4036         (gnus-dup-suppress-articles))
4037
4038       ;; Set the initial limit.
4039       (setq gnus-newsgroup-limit (copy-sequence articles))
4040       ;; Remove canceled articles from the list of unread articles.
4041       (setq gnus-newsgroup-unreads
4042             (gnus-set-sorted-intersection
4043              gnus-newsgroup-unreads
4044              (setq fetched-articles
4045                    (mapcar (lambda (headers) (mail-header-number headers))
4046                            gnus-newsgroup-headers))))
4047       ;; Removed marked articles that do not exist.
4048       (gnus-update-missing-marks
4049        (gnus-sorted-complement fetched-articles articles))
4050       ;; We might want to build some more threads first.
4051       (when (and gnus-fetch-old-headers
4052                  (eq gnus-headers-retrieved-by 'nov))
4053         (if (eq gnus-fetch-old-headers 'invisible)
4054             (gnus-build-all-threads)
4055           (gnus-build-old-threads)))
4056       ;; Let the Gnus agent mark articles as read.
4057       (when gnus-agent
4058         (gnus-agent-get-undownloaded-list))
4059       ;; Check whether auto-expire is to be done in this group.
4060       (setq gnus-newsgroup-auto-expire
4061             (gnus-group-auto-expirable-p group))
4062       ;; Set up the article buffer now, if necessary.
4063       (unless gnus-single-article-buffer
4064         (gnus-article-setup-buffer))
4065       ;; First and last article in this newsgroup.
4066       (when gnus-newsgroup-headers
4067         (setq gnus-newsgroup-begin
4068               (mail-header-number (car gnus-newsgroup-headers))
4069               gnus-newsgroup-end
4070               (mail-header-number
4071                (gnus-last-element gnus-newsgroup-headers))))
4072       ;; GROUP is successfully selected.
4073       (or gnus-newsgroup-headers t)))))
4074
4075 (defun gnus-articles-to-read (group &optional read-all)
4076   ;; Find out what articles the user wants to read.
4077   (let* ((articles
4078           ;; Select all articles if `read-all' is non-nil, or if there
4079           ;; are no unread articles.
4080           (if (or read-all
4081                   (and (zerop (length gnus-newsgroup-marked))
4082                        (zerop (length gnus-newsgroup-unreads)))
4083                   (eq (gnus-group-find-parameter group 'display)
4084                       'all))
4085               (gnus-uncompress-range (gnus-active group))
4086             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4087                           (copy-sequence gnus-newsgroup-unreads))
4088                   '<)))
4089          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4090          (scored (length scored-list))
4091          (number (length articles))
4092          (marked (+ (length gnus-newsgroup-marked)
4093                     (length gnus-newsgroup-dormant)))
4094          (select
4095           (cond
4096            ((numberp read-all)
4097             read-all)
4098            (t
4099             (condition-case ()
4100                 (cond
4101                  ((and (or (<= scored marked) (= scored number))
4102                        (numberp gnus-large-newsgroup)
4103                        (> number gnus-large-newsgroup))
4104                   (let ((input
4105                          (read-string
4106                           (format
4107                            "How many articles from %s (default %d): "
4108                            (gnus-limit-string gnus-newsgroup-name 35)
4109                            number))))
4110                     (if (string-match "^[ \t]*$" input) number input)))
4111                  ((and (> scored marked) (< scored number)
4112                        (> (- scored number) 20))
4113                   (let ((input
4114                          (read-string
4115                           (format "%s %s (%d scored, %d total): "
4116                                   "How many articles from"
4117                                   group scored number))))
4118                     (if (string-match "^[ \t]*$" input)
4119                         number input)))
4120                  (t number))
4121               (quit nil))))))
4122     (setq select (if (stringp select) (string-to-number select) select))
4123     (if (or (null select) (zerop select))
4124         select
4125       (if (and (not (zerop scored)) (<= (abs select) scored))
4126           (progn
4127             (setq articles (sort scored-list '<))
4128             (setq number (length articles)))
4129         (setq articles (copy-sequence articles)))
4130
4131       (when (< (abs select) number)
4132         (if (< select 0)
4133             ;; Select the N oldest articles.
4134             (setcdr (nthcdr (1- (abs select)) articles) nil)
4135           ;; Select the N most recent articles.
4136           (setq articles (nthcdr (- number select) articles))))
4137       (setq gnus-newsgroup-unselected
4138             (gnus-sorted-intersection
4139              gnus-newsgroup-unreads
4140              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4141       articles)))
4142
4143 (defun gnus-killed-articles (killed articles)
4144   (let (out)
4145     (while articles
4146       (when (inline (gnus-member-of-range (car articles) killed))
4147         (push (car articles) out))
4148       (setq articles (cdr articles)))
4149     out))
4150
4151 (defun gnus-uncompress-marks (marks)
4152   "Uncompress the mark ranges in MARKS."
4153   (let ((uncompressed '(score bookmark))
4154         out)
4155     (while marks
4156       (if (memq (caar marks) uncompressed)
4157           (push (car marks) out)
4158         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4159       (setq marks (cdr marks)))
4160     out))
4161
4162 (defun gnus-adjust-marked-articles (info)
4163   "Set all article lists and remove all marks that are no longer legal."
4164   (let* ((marked-lists (gnus-info-marks info))
4165          (active (gnus-active (gnus-info-group info)))
4166          (min (car active))
4167          (max (cdr active))
4168          (types gnus-article-mark-lists)
4169          (uncompressed '(score bookmark killed))
4170          marks var articles article mark)
4171
4172     (while marked-lists
4173       (setq marks (pop marked-lists))
4174       (set (setq var (intern (format "gnus-newsgroup-%s"
4175                                      (car (rassq (setq mark (car marks))
4176                                                  types)))))
4177            (if (memq (car marks) uncompressed) (cdr marks)
4178              (gnus-uncompress-range (cdr marks))))
4179
4180       (setq articles (symbol-value var))
4181
4182       ;; All articles have to be subsets of the active articles.
4183       (cond
4184        ;; Adjust "simple" lists.
4185        ((memq mark '(tick dormant expire reply save))
4186         (while articles
4187           (when (or (< (setq article (pop articles)) min) (> article max))
4188             (set var (delq article (symbol-value var))))))
4189        ;; Adjust assocs.
4190        ((memq mark uncompressed)
4191         (when (not (listp (cdr (symbol-value var))))
4192           (set var (list (symbol-value var))))
4193         (when (not (listp (cdr articles)))
4194           (setq articles (list articles)))
4195         (while articles
4196           (when (or (not (consp (setq article (pop articles))))
4197                     (< (car article) min)
4198                     (> (car article) max))
4199             (set var (delq article (symbol-value var))))))))))
4200
4201 (defun gnus-update-missing-marks (missing)
4202   "Go through the list of MISSING articles and remove them from the mark lists."
4203   (when missing
4204     (let ((types gnus-article-mark-lists)
4205           var m)
4206       ;; Go through all types.
4207       (while types
4208         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4209         (when (symbol-value var)
4210           ;; This list has articles.  So we delete all missing articles
4211           ;; from it.
4212           (setq m missing)
4213           (while m
4214             (set var (delq (pop m) (symbol-value var)))))))))
4215
4216 (defun gnus-update-marks ()
4217   "Enter the various lists of marked articles into the newsgroup info list."
4218   (let ((types gnus-article-mark-lists)
4219         (info (gnus-get-info gnus-newsgroup-name))
4220         (uncompressed '(score bookmark killed))
4221         type list newmarked symbol delta-marks)
4222     (when info
4223       ;; Add all marks lists that are non-nil to the list of marks lists.
4224       (while (setq type (pop types))
4225         (when (setq list (symbol-value
4226                           (setq symbol
4227                                 (intern (format "gnus-newsgroup-%s"
4228                                                 (car type))))))
4229
4230           ;; Get rid of the entries of the articles that have the
4231           ;; default score.
4232           (when (and (eq (cdr type) 'score)
4233                      gnus-save-score
4234                      list)
4235             (let* ((arts list)
4236                    (prev (cons nil list))
4237                    (all prev))
4238               (while arts
4239                 (if (or (not (consp (car arts)))
4240                         (= (cdar arts) gnus-summary-default-score))
4241                     (setcdr prev (cdr arts))
4242                   (setq prev arts))
4243                 (setq arts (cdr arts)))
4244               (setq list (cdr all))))
4245
4246           (push (cons (cdr type)
4247                       (if (memq (cdr type) uncompressed) list
4248                         (gnus-compress-sequence
4249                          (set symbol (sort list '<)) t)))
4250                 newmarked)))
4251
4252       ;; Enter these new marks into the info of the group.
4253       (if (nthcdr 3 info)
4254           (setcar (nthcdr 3 info) newmarked)
4255         ;; Add the marks lists to the end of the info.
4256         (when newmarked
4257           (setcdr (nthcdr 2 info) (list newmarked))))
4258
4259       ;; Cut off the end of the info if there's nothing else there.
4260       (let ((i 5))
4261         (while (and (> i 2)
4262                     (not (nth i info)))
4263           (when (nthcdr (decf i) info)
4264             (setcdr (nthcdr i info) nil)))))))
4265
4266 (defun gnus-set-mode-line (where)
4267   "This function sets the mode line of the article or summary buffers.
4268 If WHERE is `summary', the summary mode line format will be used."
4269   ;; Is this mode line one we keep updated?
4270   (when (and (memq where gnus-updated-mode-lines)
4271              (symbol-value
4272               (intern (format "gnus-%s-mode-line-format-spec" where))))
4273     (let (mode-string)
4274       (save-excursion
4275         ;; We evaluate this in the summary buffer since these
4276         ;; variables are buffer-local to that buffer.
4277         (set-buffer gnus-summary-buffer)
4278         ;; We bind all these variables that are used in the `eval' form
4279         ;; below.
4280         (let* ((mformat (symbol-value
4281                          (intern
4282                           (format "gnus-%s-mode-line-format-spec" where))))
4283                (gnus-tmp-group-name gnus-newsgroup-name)
4284                (gnus-tmp-article-number (or gnus-current-article 0))
4285                (gnus-tmp-unread gnus-newsgroup-unreads)
4286                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4287                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4288                (gnus-tmp-unread-and-unselected
4289                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4290                             (zerop gnus-tmp-unselected))
4291                        "")
4292                       ((zerop gnus-tmp-unselected)
4293                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4294                       (t (format "{%d(+%d) more}"
4295                                  gnus-tmp-unread-and-unticked
4296                                  gnus-tmp-unselected))))
4297                (gnus-tmp-subject
4298                 (if (and gnus-current-headers
4299                          (vectorp gnus-current-headers))
4300                     (gnus-mode-string-quote
4301                      (mail-header-subject gnus-current-headers))
4302                   ""))
4303                bufname-length max-len
4304                gnus-tmp-header);; passed as argument to any user-format-funcs
4305           (setq mode-string (eval mformat))
4306           (setq bufname-length (if (string-match "%b" mode-string)
4307                                    (- (length
4308                                        (buffer-name
4309                                         (if (eq where 'summary)
4310                                             nil
4311                                           (get-buffer gnus-article-buffer))))
4312                                       2)
4313                                  0))
4314           (setq max-len (max 4 (if gnus-mode-non-string-length
4315                                    (- (window-width)
4316                                       gnus-mode-non-string-length
4317                                       bufname-length)
4318                                  (length mode-string))))
4319           ;; We might have to chop a bit of the string off...
4320           (when (> (length mode-string) max-len)
4321             (setq mode-string
4322                   (concat (gnus-truncate-string mode-string (- max-len 3))
4323                           "...")))
4324           ;; Pad the mode string a bit.
4325           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4326       ;; Update the mode line.
4327       (setq mode-line-buffer-identification
4328             (gnus-mode-line-buffer-identification (list mode-string)))
4329       (set-buffer-modified-p t))))
4330
4331 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4332   "Go through the HEADERS list and add all Xrefs to a hash table.
4333 The resulting hash table is returned, or nil if no Xrefs were found."
4334   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4335          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4336          (xref-hashtb (gnus-make-hashtable))
4337          start group entry number xrefs header)
4338     (while headers
4339       (setq header (pop headers))
4340       (when (and (setq xrefs (mail-header-xref header))
4341                  (not (memq (setq number (mail-header-number header))
4342                             unreads)))
4343         (setq start 0)
4344         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4345           (setq start (match-end 0))
4346           (setq group (if prefix
4347                           (concat prefix (substring xrefs (match-beginning 1)
4348                                                     (match-end 1)))
4349                         (substring xrefs (match-beginning 1) (match-end 1))))
4350           (setq number
4351                 (string-to-int (substring xrefs (match-beginning 2)
4352                                           (match-end 2))))
4353           (if (setq entry (gnus-gethash group xref-hashtb))
4354               (setcdr entry (cons number (cdr entry)))
4355             (gnus-sethash group (cons number nil) xref-hashtb)))))
4356     (and start xref-hashtb)))
4357
4358 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4359   "Look through all the headers and mark the Xrefs as read."
4360   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4361         name entry info xref-hashtb idlist method nth4)
4362     (save-excursion
4363       (set-buffer gnus-group-buffer)
4364       (when (setq xref-hashtb
4365                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4366         (mapatoms
4367          (lambda (group)
4368            (unless (string= from-newsgroup (setq name (symbol-name group)))
4369              (setq idlist (symbol-value group))
4370              ;; Dead groups are not updated.
4371              (and (prog1
4372                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4373                             info (nth 2 entry))
4374                     (when (stringp (setq nth4 (gnus-info-method info)))
4375                       (setq nth4 (gnus-server-to-method nth4))))
4376                   ;; Only do the xrefs if the group has the same
4377                   ;; select method as the group we have just read.
4378                   (or (gnus-methods-equal-p
4379                        nth4 (gnus-find-method-for-group from-newsgroup))
4380                       virtual
4381                       (equal nth4 (setq method (gnus-find-method-for-group
4382                                                 from-newsgroup)))
4383                       (and (equal (car nth4) (car method))
4384                            (equal (nth 1 nth4) (nth 1 method))))
4385                   gnus-use-cross-reference
4386                   (or (not (eq gnus-use-cross-reference t))
4387                       virtual
4388                       ;; Only do cross-references on subscribed
4389                       ;; groups, if that is what is wanted.
4390                       (<= (gnus-info-level info) gnus-level-subscribed))
4391                   (gnus-group-make-articles-read name idlist))))
4392          xref-hashtb)))))
4393
4394 (defun gnus-compute-read-articles (group articles)
4395   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4396          (info (nth 2 entry))
4397          (active (gnus-active group))
4398          ninfo)
4399     (when entry
4400       ;; First peel off all illegal article numbers.
4401       (when active
4402         (let ((ids articles)
4403               id first)
4404           (while (setq id (pop ids))
4405             (when (and first (> id (cdr active)))
4406               ;; We'll end up in this situation in one particular
4407               ;; obscure situation.  If you re-scan a group and get
4408               ;; a new article that is cross-posted to a different
4409               ;; group that has not been re-scanned, you might get
4410               ;; crossposted article that has a higher number than
4411               ;; Gnus believes possible.  So we re-activate this
4412               ;; group as well.  This might mean doing the
4413               ;; crossposting thingy will *increase* the number
4414               ;; of articles in some groups.  Tsk, tsk.
4415               (setq active (or (gnus-activate-group group) active)))
4416             (when (or (> id (cdr active))
4417                       (< id (car active)))
4418               (setq articles (delq id articles))))))
4419       ;; If the read list is nil, we init it.
4420       (if (and active
4421                (null (gnus-info-read info))
4422                (> (car active) 1))
4423           (setq ninfo (cons 1 (1- (car active))))
4424         (setq ninfo (gnus-info-read info)))
4425       ;; Then we add the read articles to the range.
4426       (gnus-add-to-range
4427        ninfo (setq articles (sort articles '<))))))
4428
4429 (defun gnus-group-make-articles-read (group articles)
4430   "Update the info of GROUP to say that ARTICLES are read."
4431   (let* ((num 0)
4432          (entry (gnus-gethash group gnus-newsrc-hashtb))
4433          (info (nth 2 entry))
4434          (active (gnus-active group))
4435          range)
4436     (when entry
4437       (setq range (gnus-compute-read-articles group articles))
4438       (save-excursion
4439         (set-buffer gnus-group-buffer)
4440         (gnus-undo-register
4441           `(progn
4442              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4443              (gnus-info-set-read ',info ',(gnus-info-read info))
4444              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4445              (gnus-group-update-group ,group t))))
4446       ;; Add the read articles to the range.
4447       (gnus-info-set-read info range)
4448       ;; Then we have to re-compute how many unread
4449       ;; articles there are in this group.
4450       (when active
4451         (cond
4452          ((not range)
4453           (setq num (- (1+ (cdr active)) (car active))))
4454          ((not (listp (cdr range)))
4455           (setq num (- (cdr active) (- (1+ (cdr range))
4456                                        (car range)))))
4457          (t
4458           (while range
4459             (if (numberp (car range))
4460                 (setq num (1+ num))
4461               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4462             (setq range (cdr range)))
4463           (setq num (- (cdr active) num))))
4464         ;; Update the number of unread articles.
4465         (setcar entry num)
4466         ;; Update the group buffer.
4467         (gnus-group-update-group group t)))))
4468
4469 (defun gnus-methods-equal-p (m1 m2)
4470   (let ((m1 (or m1 gnus-select-method))
4471         (m2 (or m2 gnus-select-method)))
4472     (or (equal m1 m2)
4473         (and (eq (car m1) (car m2))
4474              (or (not (memq 'address (assoc (symbol-name (car m1))
4475                                             gnus-valid-select-methods)))
4476                  (equal (nth 1 m1) (nth 1 m2)))))))
4477
4478 (defvar gnus-newsgroup-none-id 0)
4479
4480 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4481   (let ((cur nntp-server-buffer)
4482         (dependencies
4483          (or dependencies
4484              (save-excursion (set-buffer gnus-summary-buffer)
4485                              gnus-newsgroup-dependencies)))
4486         headers id end ref
4487         (rfc2047-default-charset gnus-newsgroup-coding-system)
4488         (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
4489     (save-excursion
4490       (set-buffer nntp-server-buffer)
4491       ;; Translate all TAB characters into SPACE characters.
4492       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4493       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4494       (gnus-run-hooks 'gnus-parse-headers-hook)
4495       (let ((case-fold-search t)
4496             in-reply-to header p lines chars ctype)
4497         (goto-char (point-min))
4498         ;; Search to the beginning of the next header.  Error messages
4499         ;; do not begin with 2 or 3.
4500         (while (re-search-forward "^[23][0-9]+ " nil t)
4501           (setq id nil
4502                 ref nil)
4503           ;; This implementation of this function, with nine
4504           ;; search-forwards instead of the one re-search-forward and
4505           ;; a case (which basically was the old function) is actually
4506           ;; about twice as fast, even though it looks messier.  You
4507           ;; can't have everything, I guess.  Speed and elegance
4508           ;; doesn't always go hand in hand.
4509           (setq
4510            header
4511            (make-full-mail-header
4512             ;; Number.
4513             (prog1
4514                 (read cur)
4515               (end-of-line)
4516               (setq p (point))
4517               (narrow-to-region (point)
4518                                 (or (and (search-forward "\n.\n" nil t)
4519                                          (- (point) 2))
4520                                     (point))))
4521             ;; Subject.
4522             (progn
4523               (goto-char p)
4524               (if (search-forward "\nsubject: " nil t)
4525                   (buffer-substring (match-end 0) (std11-field-end))
4526                 "(none)"))
4527             ;; From.
4528             (progn
4529               (goto-char p)
4530               (if (search-forward "\nfrom: " nil t)
4531                   (buffer-substring (match-end 0) (std11-field-end))
4532                 "(nobody)"))
4533             ;; Date.
4534             (progn
4535               (goto-char p)
4536               (if (search-forward "\ndate: " nil t)
4537                   (buffer-substring (match-end 0) (std11-field-end))
4538                 ""))
4539             ;; Message-ID.
4540             (progn
4541               (goto-char p)
4542               (setq id (if (re-search-forward
4543                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4544                            ;; We do it this way to make sure the Message-ID
4545                            ;; is (somewhat) syntactically valid.
4546                            (buffer-substring (match-beginning 1)
4547                                              (match-end 1))
4548                          ;; If there was no message-id, we just fake one
4549                          ;; to make subsequent routines simpler.
4550                          (nnheader-generate-fake-message-id))))
4551             ;; References.
4552             (progn
4553               (goto-char p)
4554               (if (search-forward "\nreferences: " nil t)
4555                   (progn
4556                     (setq end (point))
4557                     (prog1
4558                         (buffer-substring (match-end 0) (std11-field-end))
4559                       (setq ref
4560                             (buffer-substring
4561                              (progn
4562                                ;; (end-of-line)
4563                                (search-backward ">" end t)
4564                                (1+ (point)))
4565                              (progn
4566                                (search-backward "<" end t)
4567                                (point))))))
4568                 ;; Get the references from the in-reply-to header if there
4569                 ;; were no references and the in-reply-to header looks
4570                 ;; promising.
4571                 (if (and (search-forward "\nin-reply-to: " nil t)
4572                          (setq in-reply-to
4573                                (buffer-substring (match-end 0)
4574                                                  (std11-field-end)))
4575                          (string-match "<[^>]+>" in-reply-to))
4576                     (let (ref2)
4577                       (setq ref (substring in-reply-to (match-beginning 0)
4578                                            (match-end 0)))
4579                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4580                         (setq ref2 (substring in-reply-to (match-beginning 0)
4581                                               (match-end 0)))
4582                         (when (> (length ref2) (length ref))
4583                           (setq ref ref2)))
4584                       ref)
4585                   (setq ref nil))))
4586             ;; Chars.
4587             (progn
4588               (goto-char p)
4589               (if (search-forward "\nchars: " nil t)
4590                   (if (numberp (setq chars (ignore-errors (read cur))))
4591                       chars 0)
4592                 0))
4593             ;; Lines.
4594             (progn
4595               (goto-char p)
4596               (if (search-forward "\nlines: " nil t)
4597                   (if (numberp (setq lines (ignore-errors (read cur))))
4598                       lines 0)
4599                 0))
4600             ;; Xref.
4601             (progn
4602               (goto-char p)
4603               (and (search-forward "\nxref: " nil t)
4604                    (buffer-substring (match-end 0) (std11-field-end))))
4605             ;; Extra.
4606             (when gnus-extra-headers
4607               (let ((extra gnus-extra-headers)
4608                     out)
4609                 (while extra
4610                   (goto-char p)
4611                   (when (search-forward
4612                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4613                     (push (cons (car extra)
4614                                 (buffer-substring (match-end 0)
4615                                                   (std11-field-end)))
4616                           out))
4617                   (pop extra))
4618                 out))))
4619           (goto-char p)
4620           (if (and (search-forward "\ncontent-type: " nil t)
4621                    (setq ctype
4622                          (buffer-substring (match-end 0) (std11-field-end))))
4623               (mime-entity-set-content-type-internal
4624                header (mime-parse-Content-Type ctype)))
4625           (when (equal id ref)
4626             (setq ref nil))
4627
4628           (when gnus-alter-header-function
4629             (funcall gnus-alter-header-function header)
4630             (setq id (mail-header-id header)
4631                   ref (gnus-parent-id (mail-header-references header))))
4632
4633           (when (setq header
4634                       (gnus-dependencies-add-header
4635                        header dependencies force-new))
4636             (push header headers))
4637           (goto-char (point-max))
4638           (widen))
4639         (nreverse headers)))))
4640
4641 ;; Goes through the xover lines and returns a list of vectors
4642 (defun gnus-get-newsgroup-headers-xover (sequence &optional
4643                                                   force-new dependencies
4644                                                   group also-fetch-heads)
4645   "Parse the news overview data in the server buffer, and return a
4646 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4647   ;; Get the Xref when the users reads the articles since most/some
4648   ;; NNTP servers do not include Xrefs when using XOVER.
4649   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4650   (let ((rfc2047-default-charset gnus-newsgroup-coding-system)
4651         (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
4652         (cur nntp-server-buffer)
4653         (dependencies (or dependencies gnus-newsgroup-dependencies))
4654         number headers header)
4655     (save-excursion
4656       (set-buffer nntp-server-buffer)
4657       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4658       ;; Allow the user to mangle the headers before parsing them.
4659       (gnus-run-hooks 'gnus-parse-headers-hook)
4660       (goto-char (point-min))
4661       (while (not (eobp))
4662         (condition-case ()
4663             (while (and sequence (not (eobp)))
4664               (setq number (read cur))
4665               (while (and sequence
4666                           (< (car sequence) number))
4667                 (setq sequence (cdr sequence)))
4668               (and sequence
4669                    (eq number (car sequence))
4670                    (progn
4671                      (setq sequence (cdr sequence))
4672                      (setq header (inline
4673                                     (gnus-nov-parse-line
4674                                      number dependencies force-new))))
4675                    (push header headers))
4676               (forward-line 1))
4677           (error
4678            (gnus-error 4 "Strange nov line (%d)"
4679                        (count-lines (point-min) (point)))))
4680         (forward-line 1))
4681       ;; A common bug in inn is that if you have posted an article and
4682       ;; then retrieves the active file, it will answer correctly --
4683       ;; the new article is included.  However, a NOV entry for the
4684       ;; article may not have been generated yet, so this may fail.
4685       ;; We work around this problem by retrieving the last few
4686       ;; headers using HEAD.
4687       (if (or (not also-fetch-heads)
4688               (not sequence))
4689           ;; We (probably) got all the headers.
4690           (nreverse headers)
4691         (let ((gnus-nov-is-evil t))
4692           (nconc
4693            (nreverse headers)
4694            (when (gnus-retrieve-headers sequence group)
4695              (gnus-get-newsgroup-headers))))))))
4696
4697 (defun gnus-article-get-xrefs ()
4698   "Fill in the Xref value in `gnus-current-headers', if necessary.
4699 This is meant to be called in `gnus-article-internal-prepare-hook'."
4700   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4701                                  gnus-current-headers)))
4702     (or (not gnus-use-cross-reference)
4703         (not headers)
4704         (and (mail-header-xref headers)
4705              (not (string= (mail-header-xref headers) "")))
4706         (let ((case-fold-search t)
4707               xref)
4708           (save-restriction
4709             (nnheader-narrow-to-headers)
4710             (goto-char (point-min))
4711             (when (or (and (eq (downcase (char-after)) ?x)
4712                            (looking-at "Xref:"))
4713                       (search-forward "\nXref:" nil t))
4714               (goto-char (1+ (match-end 0)))
4715               (setq xref (buffer-substring (point)
4716                                            (progn (end-of-line) (point))))
4717               (mail-header-set-xref headers xref)))))))
4718
4719 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4720   "Find article ID and insert the summary line for that article.
4721 OLD-HEADER can either be a header or a line number to insert
4722 the subject line on."
4723   (let* ((line (and (numberp old-header) old-header))
4724          (old-header (and (vectorp old-header) old-header))
4725          (header (cond ((and old-header use-old-header)
4726                         old-header)
4727                        ((and (numberp id)
4728                              (gnus-number-to-header id))
4729                         (gnus-number-to-header id))
4730                        (t
4731                         (gnus-read-header id))))
4732          (number (and (numberp id) id))
4733          d)
4734     (when header
4735       ;; Rebuild the thread that this article is part of and go to the
4736       ;; article we have fetched.
4737       (when (and (not gnus-show-threads)
4738                  old-header)
4739         (when (and number
4740                    (setq d (gnus-data-find (mail-header-number old-header))))
4741           (goto-char (gnus-data-pos d))
4742           (gnus-data-remove
4743            number
4744            (- (gnus-point-at-bol)
4745               (prog1
4746                   (1+ (gnus-point-at-eol))
4747                 (gnus-delete-line))))))
4748       (when old-header
4749         (mail-header-set-number header (mail-header-number old-header)))
4750       (setq gnus-newsgroup-sparse
4751             (delq (setq number (mail-header-number header))
4752                   gnus-newsgroup-sparse))
4753       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4754       (push number gnus-newsgroup-limit)
4755       (gnus-rebuild-thread (mail-header-id header) line)
4756       (gnus-summary-goto-subject number nil t))
4757     (when (and (numberp number)
4758                (> number 0))
4759       ;; We have to update the boundaries even if we can't fetch the
4760       ;; article if ID is a number -- so that the next `P' or `N'
4761       ;; command will fetch the previous (or next) article even
4762       ;; if the one we tried to fetch this time has been canceled.
4763       (when (> number gnus-newsgroup-end)
4764         (setq gnus-newsgroup-end number))
4765       (when (< number gnus-newsgroup-begin)
4766         (setq gnus-newsgroup-begin number))
4767       (setq gnus-newsgroup-unselected
4768             (delq number gnus-newsgroup-unselected)))
4769     ;; Report back a success?
4770     (and header (mail-header-number header))))
4771
4772 ;;; Process/prefix in the summary buffer
4773
4774 (defun gnus-summary-work-articles (n)
4775   "Return a list of articles to be worked upon.
4776 The prefix argument, the list of process marked articles, and the
4777 current article will be taken into consideration."
4778   (save-excursion
4779     (set-buffer gnus-summary-buffer)
4780     (cond
4781      (n
4782       ;; A numerical prefix has been given.
4783       (setq n (prefix-numeric-value n))
4784       (let ((backward (< n 0))
4785             (n (abs (prefix-numeric-value n)))
4786             articles article)
4787         (save-excursion
4788           (while
4789               (and (> n 0)
4790                    (push (setq article (gnus-summary-article-number))
4791                          articles)
4792                    (if backward
4793                        (gnus-summary-find-prev nil article)
4794                      (gnus-summary-find-next nil article)))
4795             (decf n)))
4796         (nreverse articles)))
4797      ((and (gnus-region-active-p) (mark))
4798       (message "region active")
4799       ;; Work on the region between point and mark.
4800       (let ((max (max (point) (mark)))
4801             articles article)
4802         (save-excursion
4803           (goto-char (min (point) (mark)))
4804           (while
4805               (and
4806                (push (setq article (gnus-summary-article-number)) articles)
4807                (gnus-summary-find-next nil article)
4808                (< (point) max)))
4809           (nreverse articles))))
4810      (gnus-newsgroup-processable
4811       ;; There are process-marked articles present.
4812       ;; Save current state.
4813       (gnus-summary-save-process-mark)
4814       ;; Return the list.
4815       (reverse gnus-newsgroup-processable))
4816      (t
4817       ;; Just return the current article.
4818       (list (gnus-summary-article-number))))))
4819
4820 (defmacro gnus-summary-iterate (arg &rest forms)
4821   "Iterate over the process/prefixed articles and do FORMS.
4822 ARG is the interactive prefix given to the command.  FORMS will be
4823 executed with point over the summary line of the articles."
4824   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
4825     `(let ((,articles (gnus-summary-work-articles ,arg)))
4826        (while ,articles
4827          (gnus-summary-goto-subject (car ,articles))
4828          ,@forms))))
4829
4830 (put 'gnus-summary-iterate 'lisp-indent-function 1)
4831 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
4832
4833 (defun gnus-summary-save-process-mark ()
4834   "Push the current set of process marked articles on the stack."
4835   (interactive)
4836   (push (copy-sequence gnus-newsgroup-processable)
4837         gnus-newsgroup-process-stack))
4838
4839 (defun gnus-summary-kill-process-mark ()
4840   "Push the current set of process marked articles on the stack and unmark."
4841   (interactive)
4842   (gnus-summary-save-process-mark)
4843   (gnus-summary-unmark-all-processable))
4844
4845 (defun gnus-summary-yank-process-mark ()
4846   "Pop the last process mark state off the stack and restore it."
4847   (interactive)
4848   (unless gnus-newsgroup-process-stack
4849     (error "Empty mark stack"))
4850   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4851
4852 (defun gnus-summary-process-mark-set (set)
4853   "Make SET into the current process marked articles."
4854   (gnus-summary-unmark-all-processable)
4855   (while set
4856     (gnus-summary-set-process-mark (pop set))))
4857
4858 ;;; Searching and stuff
4859
4860 (defun gnus-summary-search-group (&optional backward use-level)
4861   "Search for next unread newsgroup.
4862 If optional argument BACKWARD is non-nil, search backward instead."
4863   (save-excursion
4864     (set-buffer gnus-group-buffer)
4865     (when (gnus-group-search-forward
4866            backward nil (if use-level (gnus-group-group-level) nil))
4867       (gnus-group-group-name))))
4868
4869 (defun gnus-summary-best-group (&optional exclude-group)
4870   "Find the name of the best unread group.
4871 If EXCLUDE-GROUP, do not go to this group."
4872   (save-excursion
4873     (set-buffer gnus-group-buffer)
4874     (save-excursion
4875       (gnus-group-best-unread-group exclude-group))))
4876
4877 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
4878   (if backward (gnus-summary-find-prev)
4879     (let* ((dummy (gnus-summary-article-intangible-p))
4880            (article (or article (gnus-summary-article-number)))
4881            (arts (gnus-data-find-list article))
4882            result)
4883       (when (and (not dummy)
4884                  (or (not gnus-summary-check-current)
4885                      (not unread)
4886                      (not (gnus-data-unread-p (car arts)))))
4887         (setq arts (cdr arts)))
4888       (when (setq result
4889                   (if unread
4890                       (progn
4891                         (while arts
4892                           (when (or (and undownloaded
4893                                          (eq gnus-undownloaded-mark
4894                                              (gnus-data-mark (car arts))))
4895                                     (gnus-data-unread-p (car arts)))
4896                             (setq result (car arts)
4897                                   arts nil))
4898                           (setq arts (cdr arts)))
4899                         result)
4900                     (car arts)))
4901         (goto-char (gnus-data-pos result))
4902         (gnus-data-number result)))))
4903
4904 (defun gnus-summary-find-prev (&optional unread article)
4905   (let* ((eobp (eobp))
4906          (article (or article (gnus-summary-article-number)))
4907          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
4908          result)
4909     (when (and (not eobp)
4910                (or (not gnus-summary-check-current)
4911                    (not unread)
4912                    (not (gnus-data-unread-p (car arts)))))
4913       (setq arts (cdr arts)))
4914     (when (setq result
4915                 (if unread
4916                     (progn
4917                       (while arts
4918                         (when (gnus-data-unread-p (car arts))
4919                           (setq result (car arts)
4920                                 arts nil))
4921                         (setq arts (cdr arts)))
4922                       result)
4923                   (car arts)))
4924       (goto-char (gnus-data-pos result))
4925       (gnus-data-number result))))
4926
4927 (defun gnus-summary-find-subject (subject &optional unread backward article)
4928   (let* ((simp-subject (gnus-simplify-subject-fully subject))
4929          (article (or article (gnus-summary-article-number)))
4930          (articles (gnus-data-list backward))
4931          (arts (gnus-data-find-list article articles))
4932          result)
4933     (when (or (not gnus-summary-check-current)
4934               (not unread)
4935               (not (gnus-data-unread-p (car arts))))
4936       (setq arts (cdr arts)))
4937     (while arts
4938       (and (or (not unread)
4939                (gnus-data-unread-p (car arts)))
4940            (vectorp (gnus-data-header (car arts)))
4941            (gnus-subject-equal
4942             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
4943            (setq result (car arts)
4944                  arts nil))
4945       (setq arts (cdr arts)))
4946     (and result
4947          (goto-char (gnus-data-pos result))
4948          (gnus-data-number result))))
4949
4950 (defun gnus-summary-search-forward (&optional unread subject backward)
4951   "Search forward for an article.
4952 If UNREAD, look for unread articles.  If SUBJECT, look for
4953 articles with that subject.  If BACKWARD, search backward instead."
4954   (cond (subject (gnus-summary-find-subject subject unread backward))
4955         (backward (gnus-summary-find-prev unread))
4956         (t (gnus-summary-find-next unread))))
4957
4958 (defun gnus-recenter (&optional n)
4959   "Center point in window and redisplay frame.
4960 Also do horizontal recentering."
4961   (interactive "P")
4962   (when (and gnus-auto-center-summary
4963              (not (eq gnus-auto-center-summary 'vertical)))
4964     (gnus-horizontal-recenter))
4965   (recenter n))
4966
4967 (defun gnus-summary-recenter ()
4968   "Center point in the summary window.
4969 If `gnus-auto-center-summary' is nil, or the article buffer isn't
4970 displayed, no centering will be performed."
4971   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
4972   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
4973   (let* ((top (cond ((< (window-height) 4) 0)
4974                     ((< (window-height) 7) 1)
4975                     (t (if (numberp gnus-auto-center-summary)
4976                            gnus-auto-center-summary
4977                          2))))
4978          (height (1- (window-height)))
4979          (bottom (save-excursion (goto-char (point-max))
4980                                  (forward-line (- height))
4981                                  (point)))
4982          (window (get-buffer-window (current-buffer))))
4983     ;; The user has to want it.
4984     (when gnus-auto-center-summary
4985       (when (get-buffer-window gnus-article-buffer)
4986         ;; Only do recentering when the article buffer is displayed,
4987         ;; Set the window start to either `bottom', which is the biggest
4988         ;; possible valid number, or the second line from the top,
4989         ;; whichever is the least.
4990         (set-window-start
4991          window (min bottom (save-excursion
4992                               (forward-line (- top)) (point)))))
4993       ;; Do horizontal recentering while we're at it.
4994       (when (and (get-buffer-window (current-buffer) t)
4995                  (not (eq gnus-auto-center-summary 'vertical)))
4996         (let ((selected (selected-window)))
4997           (select-window (get-buffer-window (current-buffer) t))
4998           (gnus-summary-position-point)
4999           (gnus-horizontal-recenter)
5000           (select-window selected))))))
5001
5002 (defun gnus-summary-jump-to-group (newsgroup)
5003   "Move point to NEWSGROUP in group mode buffer."
5004   ;; Keep update point of group mode buffer if visible.
5005   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5006       (save-window-excursion
5007         ;; Take care of tree window mode.
5008         (when (get-buffer-window gnus-group-buffer)
5009           (pop-to-buffer gnus-group-buffer))
5010         (gnus-group-jump-to-group newsgroup))
5011     (save-excursion
5012       ;; Take care of tree window mode.
5013       (if (get-buffer-window gnus-group-buffer)
5014           (pop-to-buffer gnus-group-buffer)
5015         (set-buffer gnus-group-buffer))
5016       (gnus-group-jump-to-group newsgroup))))
5017
5018 ;; This function returns a list of article numbers based on the
5019 ;; difference between the ranges of read articles in this group and
5020 ;; the range of active articles.
5021 (defun gnus-list-of-unread-articles (group)
5022   (let* ((read (gnus-info-read (gnus-get-info group)))
5023          (active (or (gnus-active group) (gnus-activate-group group)))
5024          (last (cdr active))
5025          first nlast unread)
5026     ;; If none are read, then all are unread.
5027     (if (not read)
5028         (setq first (car active))
5029       ;; If the range of read articles is a single range, then the
5030       ;; first unread article is the article after the last read
5031       ;; article.  Sounds logical, doesn't it?
5032       (if (not (listp (cdr read)))
5033           (setq first (max (car active) (1+ (cdr read))))
5034         ;; `read' is a list of ranges.
5035         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5036                                   (caar read)))
5037                   1)
5038           (setq first (car active)))
5039         (while read
5040           (when first
5041             (while (< first nlast)
5042               (push first unread)
5043               (setq first (1+ first))))
5044           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5045           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5046           (setq read (cdr read)))))
5047     ;; And add the last unread articles.
5048     (while (<= first last)
5049       (push first unread)
5050       (setq first (1+ first)))
5051     ;; Return the list of unread articles.
5052     (delq 0 (nreverse unread))))
5053
5054 (defun gnus-list-of-read-articles (group)
5055   "Return a list of unread, unticked and non-dormant articles."
5056   (let* ((info (gnus-get-info group))
5057          (marked (gnus-info-marks info))
5058          (active (gnus-active group)))
5059     (and info active
5060          (gnus-set-difference
5061           (gnus-sorted-complement
5062            (gnus-uncompress-range active)
5063            (gnus-list-of-unread-articles group))
5064           (append
5065            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5066            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5067
5068 ;; Various summary commands
5069
5070 (defun gnus-summary-select-article-buffer ()
5071   "Reconfigure windows to show article buffer."
5072   (interactive)
5073   (if (not (gnus-buffer-live-p gnus-article-buffer))
5074       (error "There is no article buffer for this summary buffer")
5075     (gnus-configure-windows 'article)
5076     (select-window (get-buffer-window gnus-article-buffer))))
5077
5078 (defun gnus-summary-universal-argument (arg)
5079   "Perform any operation on all articles that are process/prefixed."
5080   (interactive "P")
5081   (let ((articles (gnus-summary-work-articles arg))
5082         func article)
5083     (if (eq
5084          (setq
5085           func
5086           (key-binding
5087            (read-key-sequence
5088             (substitute-command-keys
5089              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
5090              ))))
5091          'undefined)
5092         (gnus-error 1 "Undefined key")
5093       (save-excursion
5094         (while articles
5095           (gnus-summary-goto-subject (setq article (pop articles)))
5096           (let (gnus-newsgroup-processable)
5097             (command-execute func))
5098           (gnus-summary-remove-process-mark article)))))
5099   (gnus-summary-position-point))
5100
5101 (defun gnus-summary-toggle-truncation (&optional arg)
5102   "Toggle truncation of summary lines.
5103 With arg, turn line truncation on iff arg is positive."
5104   (interactive "P")
5105   (setq truncate-lines
5106         (if (null arg) (not truncate-lines)
5107           (> (prefix-numeric-value arg) 0)))
5108   (redraw-display))
5109
5110 (defun gnus-summary-reselect-current-group (&optional all rescan)
5111   "Exit and then reselect the current newsgroup.
5112 The prefix argument ALL means to select all articles."
5113   (interactive "P")
5114   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5115     (error "Ephemeral groups can't be reselected"))
5116   (let ((current-subject (gnus-summary-article-number))
5117         (group gnus-newsgroup-name))
5118     (setq gnus-newsgroup-begin nil)
5119     (gnus-summary-exit)
5120     ;; We have to adjust the point of group mode buffer because
5121     ;; point was moved to the next unread newsgroup by exiting.
5122     (gnus-summary-jump-to-group group)
5123     (when rescan
5124       (save-excursion
5125         (gnus-group-get-new-news-this-group 1)))
5126     (gnus-group-read-group all t)
5127     (gnus-summary-goto-subject current-subject nil t)))
5128
5129 (defun gnus-summary-rescan-group (&optional all)
5130   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5131   (interactive "P")
5132   (gnus-summary-reselect-current-group all t))
5133
5134 (defun gnus-summary-update-info (&optional non-destructive)
5135   (save-excursion
5136     (let ((group gnus-newsgroup-name))
5137       (when group
5138         (when gnus-newsgroup-kill-headers
5139           (setq gnus-newsgroup-killed
5140                 (gnus-compress-sequence
5141                  (nconc
5142                   (gnus-set-sorted-intersection
5143                    (gnus-uncompress-range gnus-newsgroup-killed)
5144                    (setq gnus-newsgroup-unselected
5145                          (sort gnus-newsgroup-unselected '<)))
5146                   (setq gnus-newsgroup-unreads
5147                         (sort gnus-newsgroup-unreads '<)))
5148                  t)))
5149         (unless (listp (cdr gnus-newsgroup-killed))
5150           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5151         (let ((headers gnus-newsgroup-headers))
5152           ;; Set the new ranges of read articles.
5153           (save-excursion
5154             (set-buffer gnus-group-buffer)
5155             (gnus-undo-force-boundary))
5156           (gnus-update-read-articles
5157            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5158           ;; Set the current article marks.
5159           (let ((gnus-newsgroup-scored
5160                  (if (and (not gnus-save-score)
5161                           (not non-destructive))
5162                      nil
5163                    gnus-newsgroup-scored)))
5164             (save-excursion
5165               (gnus-update-marks)))
5166           ;; Do the cross-ref thing.
5167           (when gnus-use-cross-reference
5168             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5169           ;; Do not switch windows but change the buffer to work.
5170           (set-buffer gnus-group-buffer)
5171           (unless (gnus-ephemeral-group-p group)
5172             (gnus-group-update-group group)))))))
5173
5174 (defun gnus-summary-save-newsrc (&optional force)
5175   "Save the current number of read/marked articles in the dribble buffer.
5176 The dribble buffer will then be saved.
5177 If FORCE (the prefix), also save the .newsrc file(s)."
5178   (interactive "P")
5179   (gnus-summary-update-info t)
5180   (if force
5181       (gnus-save-newsrc-file)
5182     (gnus-dribble-save)))
5183
5184 (defun gnus-summary-exit (&optional temporary)
5185   "Exit reading current newsgroup, and then return to group selection mode.
5186 gnus-exit-group-hook is called with no arguments if that value is non-nil."
5187   (interactive)
5188   (gnus-set-global-variables)
5189   (gnus-kill-save-kill-buffer)
5190   (gnus-async-halt-prefetch)
5191   (let* ((group gnus-newsgroup-name)
5192          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5193          (mode major-mode)
5194          (group-point nil)
5195          (buf (current-buffer)))
5196     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5197     ;; If we have several article buffers, we kill them at exit.
5198     (unless gnus-single-article-buffer
5199       (gnus-kill-buffer gnus-original-article-buffer)
5200       (setq gnus-article-current nil))
5201     (when gnus-use-cache
5202       (gnus-cache-possibly-remove-articles)
5203       (gnus-cache-save-buffers))
5204     (gnus-async-prefetch-remove-group group)
5205     (when gnus-suppress-duplicates
5206       (gnus-dup-enter-articles))
5207     (when gnus-use-trees
5208       (gnus-tree-close group))
5209     ;; Remove entries for this group.
5210     (nnmail-purge-split-history (gnus-group-real-name group))
5211     ;; Make all changes in this group permanent.
5212     (unless quit-config
5213       (gnus-run-hooks 'gnus-exit-group-hook)
5214       (gnus-summary-update-info)
5215       ;; Do adaptive scoring, and possibly save score files.
5216       (when gnus-newsgroup-adaptive
5217         (gnus-score-adaptive))
5218       (when gnus-use-scoring
5219         (gnus-score-save)))
5220     (gnus-close-group group)
5221     ;; Make sure where we were, and go to next newsgroup.
5222     (set-buffer gnus-group-buffer)
5223     (unless quit-config
5224       (gnus-group-jump-to-group group))
5225     (gnus-run-hooks 'gnus-summary-exit-hook)
5226     (unless (or quit-config
5227                 ;; If this group has disappeared from the summary
5228                 ;; buffer, don't skip forwards.
5229                 (not (string= group (gnus-group-group-name))))
5230       (gnus-group-next-unread-group 1))
5231     (setq group-point (point))
5232     (if temporary
5233         nil                             ;Nothing to do.
5234       ;; If we have several article buffers, we kill them at exit.
5235       (unless gnus-single-article-buffer
5236         (gnus-kill-buffer gnus-article-buffer)
5237         (gnus-kill-buffer gnus-original-article-buffer)
5238         (setq gnus-article-current nil))
5239       (set-buffer buf)
5240       (if (not gnus-kill-summary-on-exit)
5241           (gnus-deaden-summary)
5242         ;; We set all buffer-local variables to nil.  It is unclear why
5243         ;; this is needed, but if we don't, buffer-local variables are
5244         ;; not garbage-collected, it seems.  This would the lead to en
5245         ;; ever-growing Emacs.
5246         (gnus-summary-clear-local-variables)
5247         (when (get-buffer gnus-article-buffer)
5248           (bury-buffer gnus-article-buffer))
5249         ;; We clear the global counterparts of the buffer-local
5250         ;; variables as well, just to be on the safe side.
5251         (set-buffer gnus-group-buffer)
5252         (gnus-summary-clear-local-variables)
5253         ;; Return to group mode buffer.
5254         (when (eq mode 'gnus-summary-mode)
5255           (gnus-kill-buffer buf)))
5256       (setq gnus-current-select-method gnus-select-method)
5257       (pop-to-buffer gnus-group-buffer)
5258       (if (not quit-config)
5259           (progn
5260             (goto-char group-point)
5261             (gnus-configure-windows 'group 'force))
5262         (gnus-handle-ephemeral-exit quit-config))
5263       ;; Clear the current group name.
5264       (unless quit-config
5265         (setq gnus-newsgroup-name nil)))))
5266
5267 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5268 (defun gnus-summary-exit-no-update (&optional no-questions)
5269   "Quit reading current newsgroup without updating read article info."
5270   (interactive)
5271   (let* ((group gnus-newsgroup-name)
5272          (quit-config (gnus-group-quit-config group)))
5273     (when (or no-questions
5274               gnus-expert-user
5275               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5276       (gnus-async-halt-prefetch)
5277       (gnus-run-hooks (delq 'gnus-summary-expire-articles
5278                             (copy-list gnus-summary-prepare-exit-hook)))
5279       ;; If we have several article buffers, we kill them at exit.
5280       (unless gnus-single-article-buffer
5281         (gnus-kill-buffer gnus-article-buffer)
5282         (gnus-kill-buffer gnus-original-article-buffer)
5283         (setq gnus-article-current nil))
5284       (if (not gnus-kill-summary-on-exit)
5285           (gnus-deaden-summary)
5286         (gnus-close-group group)
5287         (gnus-summary-clear-local-variables)
5288         (set-buffer gnus-group-buffer)
5289         (gnus-summary-clear-local-variables)
5290         (when (get-buffer gnus-summary-buffer)
5291           (kill-buffer gnus-summary-buffer)))
5292       (unless gnus-single-article-buffer
5293         (setq gnus-article-current nil))
5294       (when gnus-use-trees
5295         (gnus-tree-close group))
5296       (gnus-async-prefetch-remove-group group)
5297       (when (get-buffer gnus-article-buffer)
5298         (bury-buffer gnus-article-buffer))
5299       ;; Return to the group buffer.
5300       (gnus-configure-windows 'group 'force)
5301       ;; Clear the current group name.
5302       (setq gnus-newsgroup-name nil)
5303       (when (equal (gnus-group-group-name) group)
5304         (gnus-group-next-unread-group 1))
5305       (when quit-config
5306         (gnus-handle-ephemeral-exit quit-config)))))
5307
5308 (defun gnus-handle-ephemeral-exit (quit-config)
5309   "Handle movement when leaving an ephemeral group.
5310 The state which existed when entering the ephemeral is reset."
5311   (if (not (buffer-name (car quit-config)))
5312       (gnus-configure-windows 'group 'force)
5313     (set-buffer (car quit-config))
5314     (cond ((eq major-mode 'gnus-summary-mode)
5315            (gnus-set-global-variables))
5316           ((eq major-mode 'gnus-article-mode)
5317            (save-excursion
5318              ;; The `gnus-summary-buffer' variable may point
5319              ;; to the old summary buffer when using a single
5320              ;; article buffer.
5321              (unless (gnus-buffer-live-p gnus-summary-buffer)
5322                (set-buffer gnus-group-buffer))
5323              (set-buffer gnus-summary-buffer)
5324              (gnus-set-global-variables))))
5325     (if (or (eq (cdr quit-config) 'article)
5326             (eq (cdr quit-config) 'pick))
5327         (progn
5328           ;; The current article may be from the ephemeral group
5329           ;; thus it is best that we reload this article
5330           (gnus-summary-show-article)
5331           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5332               (gnus-configure-windows 'pick 'force)
5333             (gnus-configure-windows (cdr quit-config) 'force)))
5334       (gnus-configure-windows (cdr quit-config) 'force))
5335     (when (eq major-mode 'gnus-summary-mode)
5336       (gnus-summary-next-subject 1 nil t)
5337       (gnus-summary-recenter)
5338       (gnus-summary-position-point))))
5339
5340 (defun gnus-summary-preview-mime-message (arg)
5341   "MIME decode and play this message."
5342   (interactive "P")
5343   (or gnus-show-mime
5344       (let ((gnus-break-pages nil)
5345             (gnus-show-mime t))
5346         (gnus-summary-select-article t t)
5347         ))
5348   (select-window (get-buffer-window gnus-article-buffer))
5349   )
5350
5351 ;;; Dead summaries.
5352
5353 (defvar gnus-dead-summary-mode-map nil)
5354
5355 (unless gnus-dead-summary-mode-map
5356   (setq gnus-dead-summary-mode-map (make-keymap))
5357   (suppress-keymap gnus-dead-summary-mode-map)
5358   (substitute-key-definition
5359    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5360   (let ((keys '("\C-d" "\r" "\177" [delete])))
5361     (while keys
5362       (define-key gnus-dead-summary-mode-map
5363         (pop keys) 'gnus-summary-wake-up-the-dead))))
5364
5365 (defvar gnus-dead-summary-mode nil
5366   "Minor mode for Gnus summary buffers.")
5367
5368 (defun gnus-dead-summary-mode (&optional arg)
5369   "Minor mode for Gnus summary buffers."
5370   (interactive "P")
5371   (when (eq major-mode 'gnus-summary-mode)
5372     (make-local-variable 'gnus-dead-summary-mode)
5373     (setq gnus-dead-summary-mode
5374           (if (null arg) (not gnus-dead-summary-mode)
5375             (> (prefix-numeric-value arg) 0)))
5376     (when gnus-dead-summary-mode
5377       (gnus-add-minor-mode
5378        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5379
5380 (defun gnus-deaden-summary ()
5381   "Make the current summary buffer into a dead summary buffer."
5382   ;; Kill any previous dead summary buffer.
5383   (when (and gnus-dead-summary
5384              (buffer-name gnus-dead-summary))
5385     (save-excursion
5386       (set-buffer gnus-dead-summary)
5387       (when gnus-dead-summary-mode
5388         (kill-buffer (current-buffer)))))
5389   ;; Make this the current dead summary.
5390   (setq gnus-dead-summary (current-buffer))
5391   (gnus-dead-summary-mode 1)
5392   (let ((name (buffer-name)))
5393     (when (string-match "Summary" name)
5394       (rename-buffer
5395        (concat (substring name 0 (match-beginning 0)) "Dead "
5396                (substring name (match-beginning 0)))
5397        t))))
5398
5399 (defun gnus-kill-or-deaden-summary (buffer)
5400   "Kill or deaden the summary BUFFER."
5401   (save-excursion
5402     (when (and (buffer-name buffer)
5403                (not gnus-single-article-buffer))
5404       (save-excursion
5405         (set-buffer buffer)
5406         (gnus-kill-buffer gnus-article-buffer)
5407         (gnus-kill-buffer gnus-original-article-buffer)))
5408     (cond (gnus-kill-summary-on-exit
5409            (when (and gnus-use-trees
5410                       (gnus-buffer-exists-p buffer))
5411              (save-excursion
5412                (set-buffer buffer)
5413                (gnus-tree-close gnus-newsgroup-name)))
5414            (gnus-kill-buffer buffer))
5415           ((gnus-buffer-exists-p buffer)
5416            (save-excursion
5417              (set-buffer buffer)
5418              (gnus-deaden-summary))))))
5419
5420 (defun gnus-summary-wake-up-the-dead (&rest args)
5421   "Wake up the dead summary buffer."
5422   (interactive)
5423   (gnus-dead-summary-mode -1)
5424   (let ((name (buffer-name)))
5425     (when (string-match "Dead " name)
5426       (rename-buffer
5427        (concat (substring name 0 (match-beginning 0))
5428                (substring name (match-end 0)))
5429        t)))
5430   (gnus-message 3 "This dead summary is now alive again"))
5431
5432 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5433 (defun gnus-summary-fetch-faq (&optional faq-dir)
5434   "Fetch the FAQ for the current group.
5435 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5436 in."
5437   (interactive
5438    (list
5439     (when current-prefix-arg
5440       (completing-read
5441        "Faq dir: " (and (listp gnus-group-faq-directory)
5442                         (mapcar (lambda (file) (list file))
5443                                 gnus-group-faq-directory))))))
5444   (let (gnus-faq-buffer)
5445     (when (setq gnus-faq-buffer
5446                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5447       (gnus-configure-windows 'summary-faq))))
5448
5449 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5450 (defun gnus-summary-describe-group (&optional force)
5451   "Describe the current newsgroup."
5452   (interactive "P")
5453   (gnus-group-describe-group force gnus-newsgroup-name))
5454
5455 (defun gnus-summary-describe-briefly ()
5456   "Describe summary mode commands briefly."
5457   (interactive)
5458   (gnus-message 6
5459                 (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")))
5460
5461 ;; Walking around group mode buffer from summary mode.
5462
5463 (defun gnus-summary-next-group (&optional no-article target-group backward)
5464   "Exit current newsgroup and then select next unread newsgroup.
5465 If prefix argument NO-ARTICLE is non-nil, no article is selected
5466 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5467 previous group instead."
5468   (interactive "P")
5469   ;; Stop pre-fetching.
5470   (gnus-async-halt-prefetch)
5471   (let ((current-group gnus-newsgroup-name)
5472         (current-buffer (current-buffer))
5473         entered)
5474     ;; First we semi-exit this group to update Xrefs and all variables.
5475     ;; We can't do a real exit, because the window conf must remain
5476     ;; the same in case the user is prompted for info, and we don't
5477     ;; want the window conf to change before that...
5478     (gnus-summary-exit t)
5479     (while (not entered)
5480       ;; Then we find what group we are supposed to enter.
5481       (set-buffer gnus-group-buffer)
5482       (gnus-group-jump-to-group current-group)
5483       (setq target-group
5484             (or target-group
5485                 (if (eq gnus-keep-same-level 'best)
5486                     (gnus-summary-best-group gnus-newsgroup-name)
5487                   (gnus-summary-search-group backward gnus-keep-same-level))))
5488       (if (not target-group)
5489           ;; There are no further groups, so we return to the group
5490           ;; buffer.
5491           (progn
5492             (gnus-message 5 "Returning to the group buffer")
5493             (setq entered t)
5494             (when (gnus-buffer-live-p current-buffer)
5495               (set-buffer current-buffer)
5496               (gnus-summary-exit))
5497             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5498         ;; We try to enter the target group.
5499         (gnus-group-jump-to-group target-group)
5500         (let ((unreads (gnus-group-group-unread)))
5501           (if (and (or (eq t unreads)
5502                        (and unreads (not (zerop unreads))))
5503                    (gnus-summary-read-group
5504                     target-group nil no-article
5505                     (and (buffer-name current-buffer) current-buffer)
5506                     nil backward))
5507               (setq entered t)
5508             (setq current-group target-group
5509                   target-group nil)))))))
5510
5511 (defun gnus-summary-prev-group (&optional no-article)
5512   "Exit current newsgroup and then select previous unread newsgroup.
5513 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5514   (interactive "P")
5515   (gnus-summary-next-group no-article nil t))
5516
5517 ;; Walking around summary lines.
5518
5519 (defun gnus-summary-first-subject (&optional unread undownloaded)
5520   "Go to the first unread subject.
5521 If UNREAD is non-nil, go to the first unread article.
5522 Returns the article selected or nil if there are no unread articles."
5523   (interactive "P")
5524   (prog1
5525       (cond
5526        ;; Empty summary.
5527        ((null gnus-newsgroup-data)
5528         (gnus-message 3 "No articles in the group")
5529         nil)
5530        ;; Pick the first article.
5531        ((not unread)
5532         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5533         (gnus-data-number (car gnus-newsgroup-data)))
5534        ;; No unread articles.
5535        ((null gnus-newsgroup-unreads)
5536         (gnus-message 3 "No more unread articles")
5537         nil)
5538        ;; Find the first unread article.
5539        (t
5540         (let ((data gnus-newsgroup-data))
5541           (while (and data
5542                       (and (not (and undownloaded
5543                                      (eq gnus-undownloaded-mark
5544                                          (gnus-data-mark (car data)))))
5545                            (not (gnus-data-unread-p (car data)))))
5546             (setq data (cdr data)))
5547           (when data
5548             (goto-char (gnus-data-pos (car data)))
5549             (gnus-data-number (car data))))))
5550     (gnus-summary-position-point)))
5551
5552 (defun gnus-summary-next-subject (n &optional unread dont-display)
5553   "Go to next N'th summary line.
5554 If N is negative, go to the previous N'th subject line.
5555 If UNREAD is non-nil, only unread articles are selected.
5556 The difference between N and the actual number of steps taken is
5557 returned."
5558   (interactive "p")
5559   (let ((backward (< n 0))
5560         (n (abs n)))
5561     (while (and (> n 0)
5562                 (if backward
5563                     (gnus-summary-find-prev unread)
5564                   (gnus-summary-find-next unread)))
5565       (gnus-summary-show-thread)
5566       (setq n (1- n)))
5567     (when (/= 0 n)
5568       (gnus-message 7 "No more%s articles"
5569                     (if unread " unread" "")))
5570     (unless dont-display
5571       (gnus-summary-recenter)
5572       (gnus-summary-position-point))
5573     n))
5574
5575 (defun gnus-summary-next-unread-subject (n)
5576   "Go to next N'th unread summary line."
5577   (interactive "p")
5578   (gnus-summary-next-subject n t))
5579
5580 (defun gnus-summary-prev-subject (n &optional unread)
5581   "Go to previous N'th summary line.
5582 If optional argument UNREAD is non-nil, only unread article is selected."
5583   (interactive "p")
5584   (gnus-summary-next-subject (- n) unread))
5585
5586 (defun gnus-summary-prev-unread-subject (n)
5587   "Go to previous N'th unread summary line."
5588   (interactive "p")
5589   (gnus-summary-next-subject (- n) t))
5590
5591 (defun gnus-summary-goto-subject (article &optional force silent)
5592   "Go the subject line of ARTICLE.
5593 If FORCE, also allow jumping to articles not currently shown."
5594   (interactive "nArticle number: ")
5595   (let ((b (point))
5596         (data (gnus-data-find article)))
5597     ;; We read in the article if we have to.
5598     (and (not data)
5599          force
5600          (gnus-summary-insert-subject
5601           article
5602           (if (or (numberp force) (vectorp force)) force)
5603           t)
5604          (setq data (gnus-data-find article)))
5605     (goto-char b)
5606     (if (not data)
5607         (progn
5608           (unless silent
5609             (gnus-message 3 "Can't find article %d" article))
5610           nil)
5611       (goto-char (gnus-data-pos data))
5612       (gnus-summary-position-point)
5613       article)))
5614
5615 ;; Walking around summary lines with displaying articles.
5616
5617 (defun gnus-summary-expand-window (&optional arg)
5618   "Make the summary buffer take up the entire Emacs frame.
5619 Given a prefix, will force an `article' buffer configuration."
5620   (interactive "P")
5621   (if arg
5622       (gnus-configure-windows 'article 'force)
5623     (gnus-configure-windows 'summary 'force)))
5624
5625 (defun gnus-summary-display-article (article &optional all-header)
5626   "Display ARTICLE in article buffer."
5627   (gnus-set-global-variables)
5628   (if (null article)
5629       nil
5630     (prog1
5631         (if gnus-summary-display-article-function
5632             (funcall gnus-summary-display-article-function article all-header)
5633           (gnus-article-prepare article all-header))
5634       (gnus-run-hooks 'gnus-select-article-hook)
5635       (when (and gnus-current-article
5636                  (not (zerop gnus-current-article)))
5637         (gnus-summary-goto-subject gnus-current-article))
5638       (gnus-summary-recenter)
5639       (when (and gnus-use-trees gnus-show-threads)
5640         (gnus-possibly-generate-tree article)
5641         (gnus-highlight-selected-tree article))
5642       ;; Successfully display article.
5643       (gnus-article-set-window-start
5644        (cdr (assq article gnus-newsgroup-bookmarks))))))
5645
5646 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5647   "Select the current article.
5648 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5649 non-nil, the article will be re-fetched even if it already present in
5650 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5651 be displayed."
5652   ;; Make sure we are in the summary buffer to work around bbdb bug.
5653   (unless (eq major-mode 'gnus-summary-mode)
5654     (set-buffer gnus-summary-buffer))
5655   (let ((article (or article (gnus-summary-article-number)))
5656         (all-headers (not (not all-headers))) ;Must be T or NIL.
5657         gnus-summary-display-article-function
5658         did)
5659     (and (not pseudo)
5660          (gnus-summary-article-pseudo-p article)
5661          (error "This is a pseudo-article"))
5662     (prog1
5663         (save-excursion
5664           (set-buffer gnus-summary-buffer)
5665           (if (or (and gnus-single-article-buffer
5666                        (or (null gnus-current-article)
5667                            (null gnus-article-current)
5668                            (null (get-buffer gnus-article-buffer))
5669                            (not (eq article (cdr gnus-article-current)))
5670                            (not (equal (car gnus-article-current)
5671                                        gnus-newsgroup-name))))
5672                   (and (not gnus-single-article-buffer)
5673                        (or (null gnus-current-article)
5674                            (not (eq gnus-current-article article))))
5675                   force)
5676               ;; The requested article is different from the current article.
5677               (prog1
5678                   (gnus-summary-display-article article all-headers)
5679                 (setq did article))
5680             (when (or all-headers gnus-show-all-headers)
5681               (gnus-article-show-all-headers))
5682             'old))
5683       (when did
5684         (gnus-article-set-window-start
5685          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5686
5687 (defun gnus-summary-set-current-mark (&optional current-mark)
5688   "Obsolete function."
5689   nil)
5690
5691 (defun gnus-summary-next-article (&optional unread subject backward push)
5692   "Select the next article.
5693 If UNREAD, only unread articles are selected.
5694 If SUBJECT, only articles with SUBJECT are selected.
5695 If BACKWARD, the previous article is selected instead of the next."
5696   (interactive "P")
5697   (cond
5698    ;; Is there such an article?
5699    ((and (gnus-summary-search-forward unread subject backward)
5700          (or (gnus-summary-display-article (gnus-summary-article-number))
5701              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5702     (gnus-summary-position-point))
5703    ;; If not, we try the first unread, if that is wanted.
5704    ((and subject
5705          gnus-auto-select-same
5706          (gnus-summary-first-unread-article))
5707     (gnus-summary-position-point)
5708     (gnus-message 6 "Wrapped"))
5709    ;; Try to get next/previous article not displayed in this group.
5710    ((and gnus-auto-extend-newsgroup
5711          (not unread) (not subject))
5712     (gnus-summary-goto-article
5713      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5714      nil (count-lines (point-min) (point))))
5715    ;; Go to next/previous group.
5716    (t
5717     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5718       (gnus-summary-jump-to-group gnus-newsgroup-name))
5719     (let ((cmd last-command-char)
5720           (point
5721            (save-excursion
5722              (set-buffer gnus-group-buffer)
5723              (point)))
5724           (group
5725            (if (eq gnus-keep-same-level 'best)
5726                (gnus-summary-best-group gnus-newsgroup-name)
5727              (gnus-summary-search-group backward gnus-keep-same-level))))
5728       ;; For some reason, the group window gets selected.  We change
5729       ;; it back.
5730       (select-window (get-buffer-window (current-buffer)))
5731       ;; Select next unread newsgroup automagically.
5732       (cond
5733        ((or (not gnus-auto-select-next)
5734             (not cmd))
5735         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5736        ((or (eq gnus-auto-select-next 'quietly)
5737             (and (eq gnus-auto-select-next 'slightly-quietly)
5738                  push)
5739             (and (eq gnus-auto-select-next 'almost-quietly)
5740                  (gnus-summary-last-article-p)))
5741         ;; Select quietly.
5742         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5743             (gnus-summary-exit)
5744           (gnus-message 7 "No more%s articles (%s)..."
5745                         (if unread " unread" "")
5746                         (if group (concat "selecting " group)
5747                           "exiting"))
5748           (gnus-summary-next-group nil group backward)))
5749        (t
5750         (when (gnus-key-press-event-p last-input-event)
5751           (gnus-summary-walk-group-buffer
5752            gnus-newsgroup-name cmd unread backward point))))))))
5753
5754 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5755   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5756                       (?\C-p (gnus-group-prev-unread-group 1))))
5757         (cursor-in-echo-area t)
5758         keve key group ended)
5759     (save-excursion
5760       (set-buffer gnus-group-buffer)
5761       (goto-char start)
5762       (setq group
5763             (if (eq gnus-keep-same-level 'best)
5764                 (gnus-summary-best-group gnus-newsgroup-name)
5765               (gnus-summary-search-group backward gnus-keep-same-level))))
5766     (while (not ended)
5767       (gnus-message
5768        5 "No more%s articles%s" (if unread " unread" "")
5769        (if (and group
5770                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5771            (format " (Type %s for %s [%s])"
5772                    (single-key-description cmd) group
5773                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5774          (format " (Type %s to exit %s)"
5775                  (single-key-description cmd)
5776                  gnus-newsgroup-name)))
5777       ;; Confirm auto selection.
5778       (setq key (car (setq keve (gnus-read-event-char))))
5779       (setq ended t)
5780       (cond
5781        ((assq key keystrokes)
5782         (let ((obuf (current-buffer)))
5783           (switch-to-buffer gnus-group-buffer)
5784           (when group
5785             (gnus-group-jump-to-group group))
5786           (eval (cadr (assq key keystrokes)))
5787           (setq group (gnus-group-group-name))
5788           (switch-to-buffer obuf))
5789         (setq ended nil))
5790        ((equal key cmd)
5791         (if (or (not group)
5792                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5793             (gnus-summary-exit)
5794           (gnus-summary-next-group nil group backward)))
5795        (t
5796         (push (cdr keve) unread-command-events))))))
5797
5798 (defun gnus-summary-next-unread-article ()
5799   "Select unread article after current one."
5800   (interactive)
5801   (gnus-summary-next-article
5802    (or (not (eq gnus-summary-goto-unread 'never))
5803        (gnus-summary-last-article-p (gnus-summary-article-number)))
5804    (and gnus-auto-select-same
5805         (gnus-summary-article-subject))))
5806
5807 (defun gnus-summary-prev-article (&optional unread subject)
5808   "Select the article after the current one.
5809 If UNREAD is non-nil, only unread articles are selected."
5810   (interactive "P")
5811   (gnus-summary-next-article unread subject t))
5812
5813 (defun gnus-summary-prev-unread-article ()
5814   "Select unread article before current one."
5815   (interactive)
5816   (gnus-summary-prev-article
5817    (or (not (eq gnus-summary-goto-unread 'never))
5818        (gnus-summary-first-article-p (gnus-summary-article-number)))
5819    (and gnus-auto-select-same
5820         (gnus-summary-article-subject))))
5821
5822 (defun gnus-summary-next-page (&optional lines circular)
5823   "Show next page of the selected article.
5824 If at the end of the current article, select the next article.
5825 LINES says how many lines should be scrolled up.
5826
5827 If CIRCULAR is non-nil, go to the start of the article instead of
5828 selecting the next article when reaching the end of the current
5829 article."
5830   (interactive "P")
5831   (setq gnus-summary-buffer (current-buffer))
5832   (gnus-set-global-variables)
5833   (let ((article (gnus-summary-article-number))
5834         (article-window (get-buffer-window gnus-article-buffer t))
5835         endp)
5836     ;; If the buffer is empty, we have no article.
5837     (unless article
5838       (error "No article to select"))
5839     (gnus-configure-windows 'article)
5840     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5841         (if (and (eq gnus-summary-goto-unread 'never)
5842                  (not (gnus-summary-last-article-p article)))
5843             (gnus-summary-next-article)
5844           (gnus-summary-next-unread-article))
5845       (if (or (null gnus-current-article)
5846               (null gnus-article-current)
5847               (/= article (cdr gnus-article-current))
5848               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5849           ;; Selected subject is different from current article's.
5850           (gnus-summary-display-article article)
5851         (when article-window
5852           (gnus-eval-in-buffer-window gnus-article-buffer
5853             (setq endp (gnus-article-next-page lines)))
5854           (when endp
5855             (cond (circular
5856                    (gnus-summary-beginning-of-article))
5857                   (lines
5858                    (gnus-message 3 "End of message"))
5859                   ((null lines)
5860                    (if (and (eq gnus-summary-goto-unread 'never)
5861                             (not (gnus-summary-last-article-p article)))
5862                        (gnus-summary-next-article)
5863                      (gnus-summary-next-unread-article))))))))
5864     (gnus-summary-recenter)
5865     (gnus-summary-position-point)))
5866
5867 (defun gnus-summary-prev-page (&optional lines move)
5868   "Show previous page of selected article.
5869 Argument LINES specifies lines to be scrolled down.
5870 If MOVE, move to the previous unread article if point is at
5871 the beginning of the buffer."
5872   (interactive "P")
5873   (let ((article (gnus-summary-article-number))
5874         (article-window (get-buffer-window gnus-article-buffer t))
5875         endp)
5876     (gnus-configure-windows 'article)
5877     (if (or (null gnus-current-article)
5878             (null gnus-article-current)
5879             (/= article (cdr gnus-article-current))
5880             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5881         ;; Selected subject is different from current article's.
5882         (gnus-summary-display-article article)
5883       (gnus-summary-recenter)
5884       (when article-window
5885         (gnus-eval-in-buffer-window gnus-article-buffer
5886           (setq endp (gnus-article-prev-page lines)))
5887         (when (and move endp)
5888           (cond (lines
5889                  (gnus-message 3 "Beginning of message"))
5890                 ((null lines)
5891                  (if (and (eq gnus-summary-goto-unread 'never)
5892                           (not (gnus-summary-first-article-p article)))
5893                      (gnus-summary-prev-article)
5894                    (gnus-summary-prev-unread-article))))))))
5895   (gnus-summary-position-point))
5896
5897 (defun gnus-summary-prev-page-or-article (&optional lines)
5898   "Show previous page of selected article.
5899 Argument LINES specifies lines to be scrolled down.
5900 If at the beginning of the article, go to the next article."
5901   (interactive "P")
5902   (gnus-summary-prev-page lines t))
5903
5904 (defun gnus-summary-scroll-up (lines)
5905   "Scroll up (or down) one line current article.
5906 Argument LINES specifies lines to be scrolled up (or down if negative)."
5907   (interactive "p")
5908   (gnus-configure-windows 'article)
5909   (gnus-summary-show-thread)
5910   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
5911     (gnus-eval-in-buffer-window gnus-article-buffer
5912       (cond ((> lines 0)
5913              (when (gnus-article-next-page lines)
5914                (gnus-message 3 "End of message")))
5915             ((< lines 0)
5916              (gnus-article-prev-page (- lines))))))
5917   (gnus-summary-recenter)
5918   (gnus-summary-position-point))
5919
5920 (defun gnus-summary-scroll-down (lines)
5921   "Scroll down (or up) one line current article.
5922 Argument LINES specifies lines to be scrolled down (or up if negative)."
5923   (interactive "p")
5924   (gnus-summary-scroll-up (- lines)))
5925
5926 (defun gnus-summary-next-same-subject ()
5927   "Select next article which has the same subject as current one."
5928   (interactive)
5929   (gnus-summary-next-article nil (gnus-summary-article-subject)))
5930
5931 (defun gnus-summary-prev-same-subject ()
5932   "Select previous article which has the same subject as current one."
5933   (interactive)
5934   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
5935
5936 (defun gnus-summary-next-unread-same-subject ()
5937   "Select next unread article which has the same subject as current one."
5938   (interactive)
5939   (gnus-summary-next-article t (gnus-summary-article-subject)))
5940
5941 (defun gnus-summary-prev-unread-same-subject ()
5942   "Select previous unread article which has the same subject as current one."
5943   (interactive)
5944   (gnus-summary-prev-article t (gnus-summary-article-subject)))
5945
5946 (defun gnus-summary-first-unread-article ()
5947   "Select the first unread article.
5948 Return nil if there are no unread articles."
5949   (interactive)
5950   (prog1
5951       (when (gnus-summary-first-subject t)
5952         (gnus-summary-show-thread)
5953         (gnus-summary-first-subject t)
5954         (gnus-summary-display-article (gnus-summary-article-number)))
5955     (gnus-summary-position-point)))
5956
5957 (defun gnus-summary-first-unread-subject ()
5958   "Place the point on the subject line of the first unread article.
5959 Return nil if there are no unread articles."
5960   (interactive)
5961   (prog1
5962       (when (gnus-summary-first-subject t)
5963         (gnus-summary-show-thread)
5964         (gnus-summary-first-subject t))
5965     (gnus-summary-position-point)))
5966
5967 (defun gnus-summary-first-article ()
5968   "Select the first article.
5969 Return nil if there are no articles."
5970   (interactive)
5971   (prog1
5972       (when (gnus-summary-first-subject)
5973         (gnus-summary-show-thread)
5974         (gnus-summary-first-subject)
5975         (gnus-summary-display-article (gnus-summary-article-number)))
5976     (gnus-summary-position-point)))
5977
5978 (defun gnus-summary-best-unread-article ()
5979   "Select the unread article with the highest score."
5980   (interactive)
5981   (let ((best -1000000)
5982         (data gnus-newsgroup-data)
5983         article score)
5984     (while data
5985       (and (gnus-data-unread-p (car data))
5986            (> (setq score
5987                     (gnus-summary-article-score (gnus-data-number (car data))))
5988               best)
5989            (setq best score
5990                  article (gnus-data-number (car data))))
5991       (setq data (cdr data)))
5992     (prog1
5993         (if article
5994             (gnus-summary-goto-article article)
5995           (error "No unread articles"))
5996       (gnus-summary-position-point))))
5997
5998 (defun gnus-summary-last-subject ()
5999   "Go to the last displayed subject line in the group."
6000   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6001     (when article
6002       (gnus-summary-goto-subject article))))
6003
6004 (defun gnus-summary-goto-article (article &optional all-headers force)
6005   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6006 If ALL-HEADERS is non-nil, no header lines are hidden.
6007 If FORCE, go to the article even if it isn't displayed.  If FORCE
6008 is a number, it is the line the article is to be displayed on."
6009   (interactive
6010    (list
6011     (completing-read
6012      "Article number or Message-ID: "
6013      (mapcar (lambda (number) (list (int-to-string number)))
6014              gnus-newsgroup-limit))
6015     current-prefix-arg
6016     t))
6017   (prog1
6018       (if (and (stringp article)
6019                (string-match "@" article))
6020           (gnus-summary-refer-article article)
6021         (when (stringp article)
6022           (setq article (string-to-number article)))
6023         (if (gnus-summary-goto-subject article force)
6024             (gnus-summary-display-article article all-headers)
6025           (gnus-message 4 "Couldn't go to article %s" article) nil))
6026     (gnus-summary-position-point)))
6027
6028 (defun gnus-summary-goto-last-article ()
6029   "Go to the previously read article."
6030   (interactive)
6031   (prog1
6032       (when gnus-last-article
6033         (gnus-summary-goto-article gnus-last-article nil t))
6034     (gnus-summary-position-point)))
6035
6036 (defun gnus-summary-pop-article (number)
6037   "Pop one article off the history and go to the previous.
6038 NUMBER articles will be popped off."
6039   (interactive "p")
6040   (let (to)
6041     (setq gnus-newsgroup-history
6042           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6043     (if to
6044         (gnus-summary-goto-article (car to) nil t)
6045       (error "Article history empty")))
6046   (gnus-summary-position-point))
6047
6048 ;; Summary commands and functions for limiting the summary buffer.
6049
6050 (defun gnus-summary-limit-to-articles (n)
6051   "Limit the summary buffer to the next N articles.
6052 If not given a prefix, use the process marked articles instead."
6053   (interactive "P")
6054   (prog1
6055       (let ((articles (gnus-summary-work-articles n)))
6056         (setq gnus-newsgroup-processable nil)
6057         (gnus-summary-limit articles))
6058     (gnus-summary-position-point)))
6059
6060 (defun gnus-summary-pop-limit (&optional total)
6061   "Restore the previous limit.
6062 If given a prefix, remove all limits."
6063   (interactive "P")
6064   (when total
6065     (setq gnus-newsgroup-limits
6066           (list (mapcar (lambda (h) (mail-header-number h))
6067                         gnus-newsgroup-headers))))
6068   (unless gnus-newsgroup-limits
6069     (error "No limit to pop"))
6070   (prog1
6071       (gnus-summary-limit nil 'pop)
6072     (gnus-summary-position-point)))
6073
6074 (defun gnus-summary-limit-to-subject (subject &optional header)
6075   "Limit the summary buffer to articles that have subjects that match a regexp."
6076   (interactive "sLimit to subject (regexp): ")
6077   (unless header
6078     (setq header "subject"))
6079   (when (not (equal "" subject))
6080     (prog1
6081         (let ((articles (gnus-summary-find-matching
6082                          (or header "subject") subject 'all)))
6083           (unless articles
6084             (error "Found no matches for \"%s\"" subject))
6085           (gnus-summary-limit articles))
6086       (gnus-summary-position-point))))
6087
6088 (defun gnus-summary-limit-to-author (from)
6089   "Limit the summary buffer to articles that have authors that match a regexp."
6090   (interactive "sLimit to author (regexp): ")
6091   (gnus-summary-limit-to-subject from "from"))
6092
6093 (defun gnus-summary-limit-to-age (age &optional younger-p)
6094   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6095 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6096 articles that are younger than AGE days."
6097   (interactive "nTime in days: \nP")
6098   (prog1
6099       (let ((data gnus-newsgroup-data)
6100             (cutoff (days-to-time age))
6101             articles d date is-younger)
6102         (while (setq d (pop data))
6103           (when (and (vectorp (gnus-data-header d))
6104                      (setq date (mail-header-date (gnus-data-header d))))
6105             (setq is-younger (time-less-p
6106                               (time-since (date-to-time date))
6107                               cutoff))
6108             (when (if younger-p
6109                       is-younger
6110                     (not is-younger))
6111               (push (gnus-data-number d) articles))))
6112         (gnus-summary-limit (nreverse articles)))
6113     (gnus-summary-position-point)))
6114
6115 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6116 (make-obsolete
6117  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6118
6119 (defun gnus-summary-limit-to-unread (&optional all)
6120   "Limit the summary buffer to articles that are not marked as read.
6121 If ALL is non-nil, limit strictly to unread articles."
6122   (interactive "P")
6123   (if all
6124       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6125     (gnus-summary-limit-to-marks
6126      ;; Concat all the marks that say that an article is read and have
6127      ;; those removed.
6128      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6129            gnus-killed-mark gnus-kill-file-mark
6130            gnus-low-score-mark gnus-expirable-mark
6131            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6132            gnus-duplicate-mark gnus-souped-mark)
6133      'reverse)))
6134
6135 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6136 (make-obsolete 'gnus-summary-delete-marked-with
6137                'gnus-summary-limit-exlude-marks)
6138
6139 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6140   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6141 If REVERSE, limit the summary buffer to articles that are marked
6142 with MARKS.  MARKS can either be a string of marks or a list of marks.
6143 Returns how many articles were removed."
6144   (interactive "sMarks: ")
6145   (gnus-summary-limit-to-marks marks t))
6146
6147 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6148   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6149 If REVERSE (the prefix), limit the summary buffer to articles that are
6150 not marked with MARKS.  MARKS can either be a string of marks or a
6151 list of marks.
6152 Returns how many articles were removed."
6153   (interactive "sMarks: \nP")
6154   (prog1
6155       (let ((data gnus-newsgroup-data)
6156             (marks (if (listp marks) marks
6157                      (append marks nil))) ; Transform to list.
6158             articles)
6159         (while data
6160           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6161                   (memq (gnus-data-mark (car data)) marks))
6162             (push (gnus-data-number (car data)) articles))
6163           (setq data (cdr data)))
6164         (gnus-summary-limit articles))
6165     (gnus-summary-position-point)))
6166
6167 (defun gnus-summary-limit-to-score (&optional score)
6168   "Limit to articles with score at or above SCORE."
6169   (interactive "P")
6170   (setq score (if score
6171                   (prefix-numeric-value score)
6172                 (or gnus-summary-default-score 0)))
6173   (let ((data gnus-newsgroup-data)
6174         articles)
6175     (while data
6176       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6177                 score)
6178         (push (gnus-data-number (car data)) articles))
6179       (setq data (cdr data)))
6180     (prog1
6181         (gnus-summary-limit articles)
6182       (gnus-summary-position-point))))
6183
6184 (defun gnus-summary-limit-include-thread (id)
6185   "Display all the hidden articles that in the current thread."
6186   (interactive (list (mail-header-id (gnus-summary-article-header))))
6187   (let ((articles (gnus-articles-in-thread
6188                    (gnus-id-to-thread (gnus-root-id id)))))
6189     (prog1
6190         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6191       (gnus-summary-position-point))))
6192
6193 (defun gnus-summary-limit-include-dormant ()
6194   "Display all the hidden articles that are marked as dormant.
6195 Note that this command only works on a subset of the articles currently
6196 fetched for this group."
6197   (interactive)
6198   (unless gnus-newsgroup-dormant
6199     (error "There are no dormant articles in this group"))
6200   (prog1
6201       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6202     (gnus-summary-position-point)))
6203
6204 (defun gnus-summary-limit-exclude-dormant ()
6205   "Hide all dormant articles."
6206   (interactive)
6207   (prog1
6208       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6209     (gnus-summary-position-point)))
6210
6211 (defun gnus-summary-limit-exclude-childless-dormant ()
6212   "Hide all dormant articles that have no children."
6213   (interactive)
6214   (let ((data (gnus-data-list t))
6215         articles d children)
6216     ;; Find all articles that are either not dormant or have
6217     ;; children.
6218     (while (setq d (pop data))
6219       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6220                 (and (setq children
6221                            (gnus-article-children (gnus-data-number d)))
6222                      (let (found)
6223                        (while children
6224                          (when (memq (car children) articles)
6225                            (setq children nil
6226                                  found t))
6227                          (pop children))
6228                        found)))
6229         (push (gnus-data-number d) articles)))
6230     ;; Do the limiting.
6231     (prog1
6232         (gnus-summary-limit articles)
6233       (gnus-summary-position-point))))
6234
6235 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6236   "Mark all unread excluded articles as read.
6237 If ALL, mark even excluded ticked and dormants as read."
6238   (interactive "P")
6239   (let ((articles (gnus-sorted-complement
6240                    (sort
6241                     (mapcar (lambda (h) (mail-header-number h))
6242                             gnus-newsgroup-headers)
6243                     '<)
6244                    (sort gnus-newsgroup-limit '<)))
6245         article)
6246     (setq gnus-newsgroup-unreads
6247           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6248     (if all
6249         (setq gnus-newsgroup-dormant nil
6250               gnus-newsgroup-marked nil
6251               gnus-newsgroup-reads
6252               (nconc
6253                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6254                gnus-newsgroup-reads))
6255       (while (setq article (pop articles))
6256         (unless (or (memq article gnus-newsgroup-dormant)
6257                     (memq article gnus-newsgroup-marked))
6258           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6259
6260 (defun gnus-summary-limit (articles &optional pop)
6261   (if pop
6262       ;; We pop the previous limit off the stack and use that.
6263       (setq articles (car gnus-newsgroup-limits)
6264             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6265     ;; We use the new limit, so we push the old limit on the stack.
6266     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6267   ;; Set the limit.
6268   (setq gnus-newsgroup-limit articles)
6269   (let ((total (length gnus-newsgroup-data))
6270         (data (gnus-data-find-list (gnus-summary-article-number)))
6271         (gnus-summary-mark-below nil)   ; Inhibit this.
6272         found)
6273     ;; This will do all the work of generating the new summary buffer
6274     ;; according to the new limit.
6275     (gnus-summary-prepare)
6276     ;; Hide any threads, possibly.
6277     (and gnus-show-threads
6278          gnus-thread-hide-subtree
6279          (gnus-summary-hide-all-threads))
6280     ;; Try to return to the article you were at, or one in the
6281     ;; neighborhood.
6282     (when data
6283       ;; We try to find some article after the current one.
6284       (while data
6285         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6286           (setq data nil
6287                 found t))
6288         (setq data (cdr data))))
6289     (unless found
6290       ;; If there is no data, that means that we were after the last
6291       ;; article.  The same goes when we can't find any articles
6292       ;; after the current one.
6293       (goto-char (point-max))
6294       (gnus-summary-find-prev))
6295     (gnus-set-mode-line 'summary)
6296     ;; We return how many articles were removed from the summary
6297     ;; buffer as a result of the new limit.
6298     (- total (length gnus-newsgroup-data))))
6299
6300 (defsubst gnus-invisible-cut-children (threads)
6301   (let ((num 0))
6302     (while threads
6303       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6304         (incf num))
6305       (pop threads))
6306     (< num 2)))
6307
6308 (defsubst gnus-cut-thread (thread)
6309   "Go forwards in the thread until we find an article that we want to display."
6310   (when (or (eq gnus-fetch-old-headers 'some)
6311             (eq gnus-fetch-old-headers 'invisible)
6312             (eq gnus-build-sparse-threads 'some)
6313             (eq gnus-build-sparse-threads 'more))
6314     ;; Deal with old-fetched headers and sparse threads.
6315     (while (and
6316             thread
6317             (or
6318              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6319              (gnus-summary-article-ancient-p
6320               (mail-header-number (car thread))))
6321             (if (or (<= (length (cdr thread)) 1)
6322                     (eq gnus-fetch-old-headers 'invisible))
6323                 (setq gnus-newsgroup-limit
6324                       (delq (mail-header-number (car thread))
6325                             gnus-newsgroup-limit)
6326                       thread (cadr thread))
6327               (when (gnus-invisible-cut-children (cdr thread))
6328                 (let ((th (cdr thread)))
6329                   (while th
6330                     (if (memq (mail-header-number (caar th))
6331                               gnus-newsgroup-limit)
6332                         (setq thread (car th)
6333                               th nil)
6334                       (setq th (cdr th))))))))))
6335   thread)
6336
6337 (defun gnus-cut-threads (threads)
6338   "Cut off all uninteresting articles from the beginning of threads."
6339   (when (or (eq gnus-fetch-old-headers 'some)
6340             (eq gnus-fetch-old-headers 'invisible)
6341             (eq gnus-build-sparse-threads 'some)
6342             (eq gnus-build-sparse-threads 'more))
6343     (let ((th threads))
6344       (while th
6345         (setcar th (gnus-cut-thread (car th)))
6346         (setq th (cdr th)))))
6347   ;; Remove nixed out threads.
6348   (delq nil threads))
6349
6350 (defun gnus-summary-initial-limit (&optional show-if-empty)
6351   "Figure out what the initial limit is supposed to be on group entry.
6352 This entails weeding out unwanted dormants, low-scored articles,
6353 fetch-old-headers verbiage, and so on."
6354   ;; Most groups have nothing to remove.
6355   (if (or gnus-inhibit-limiting
6356           (and (null gnus-newsgroup-dormant)
6357                (not (eq gnus-fetch-old-headers 'some))
6358                (not (eq gnus-fetch-old-headers 'invisible))
6359                (null gnus-summary-expunge-below)
6360                (not (eq gnus-build-sparse-threads 'some))
6361                (not (eq gnus-build-sparse-threads 'more))
6362                (null gnus-thread-expunge-below)
6363                (not gnus-use-nocem)))
6364       ()                                ; Do nothing.
6365     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6366     (setq gnus-newsgroup-limit nil)
6367     (mapatoms
6368      (lambda (node)
6369        (unless (car (symbol-value node))
6370          ;; These threads have no parents -- they are roots.
6371          (let ((nodes (cdr (symbol-value node)))
6372                thread)
6373            (while nodes
6374              (if (and gnus-thread-expunge-below
6375                       (< (gnus-thread-total-score (car nodes))
6376                          gnus-thread-expunge-below))
6377                  (gnus-expunge-thread (pop nodes))
6378                (setq thread (pop nodes))
6379                (gnus-summary-limit-children thread))))))
6380      gnus-newsgroup-dependencies)
6381     ;; If this limitation resulted in an empty group, we might
6382     ;; pop the previous limit and use it instead.
6383     (when (and (not gnus-newsgroup-limit)
6384                show-if-empty)
6385       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6386     gnus-newsgroup-limit))
6387
6388 (defun gnus-summary-limit-children (thread)
6389   "Return 1 if this subthread is visible and 0 if it is not."
6390   ;; First we get the number of visible children to this thread.  This
6391   ;; is done by recursing down the thread using this function, so this
6392   ;; will really go down to a leaf article first, before slowly
6393   ;; working its way up towards the root.
6394   (when thread
6395     (let ((children
6396            (if (cdr thread)
6397                (apply '+ (mapcar 'gnus-summary-limit-children
6398                                  (cdr thread)))
6399              0))
6400           (number (mail-header-number (car thread)))
6401           score)
6402       (if (and
6403            (not (memq number gnus-newsgroup-marked))
6404            (or
6405             ;; If this article is dormant and has absolutely no visible
6406             ;; children, then this article isn't visible.
6407             (and (memq number gnus-newsgroup-dormant)
6408                  (zerop children))
6409             ;; If this is "fetch-old-headered" and there is no
6410             ;; visible children, then we don't want this article.
6411             (and (eq gnus-fetch-old-headers 'some)
6412                  (gnus-summary-article-ancient-p number)
6413                  (zerop children))
6414             ;; If this is "fetch-old-headered" and `invisible', then
6415             ;; we don't want this article.
6416             (and (eq gnus-fetch-old-headers 'invisible)
6417                  (gnus-summary-article-ancient-p number))
6418             ;; If this is a sparsely inserted article with no children,
6419             ;; we don't want it.
6420             (and (eq gnus-build-sparse-threads 'some)
6421                  (gnus-summary-article-sparse-p number)
6422                  (zerop children))
6423             ;; If we use expunging, and this article is really
6424             ;; low-scored, then we don't want this article.
6425             (when (and gnus-summary-expunge-below
6426                        (< (setq score
6427                                 (or (cdr (assq number gnus-newsgroup-scored))
6428                                     gnus-summary-default-score))
6429                           gnus-summary-expunge-below))
6430               ;; We increase the expunge-tally here, but that has
6431               ;; nothing to do with the limits, really.
6432               (incf gnus-newsgroup-expunged-tally)
6433               ;; We also mark as read here, if that's wanted.
6434               (when (and gnus-summary-mark-below
6435                          (< score gnus-summary-mark-below))
6436                 (setq gnus-newsgroup-unreads
6437                       (delq number gnus-newsgroup-unreads))
6438                 (if gnus-newsgroup-auto-expire
6439                     (push number gnus-newsgroup-expirable)
6440                   (push (cons number gnus-low-score-mark)
6441                         gnus-newsgroup-reads)))
6442               t)
6443             ;; Check NoCeM things.
6444             (if (and gnus-use-nocem
6445                      (gnus-nocem-unwanted-article-p
6446                       (mail-header-id (car thread))))
6447                 (progn
6448                   (setq gnus-newsgroup-unreads
6449                         (delq number gnus-newsgroup-unreads))
6450                   t))))
6451           ;; Nope, invisible article.
6452           0
6453         ;; Ok, this article is to be visible, so we add it to the limit
6454         ;; and return 1.
6455         (push number gnus-newsgroup-limit)
6456         1))))
6457
6458 (defun gnus-expunge-thread (thread)
6459   "Mark all articles in THREAD as read."
6460   (let* ((number (mail-header-number (car thread))))
6461     (incf gnus-newsgroup-expunged-tally)
6462     ;; We also mark as read here, if that's wanted.
6463     (setq gnus-newsgroup-unreads
6464           (delq number gnus-newsgroup-unreads))
6465     (if gnus-newsgroup-auto-expire
6466         (push number gnus-newsgroup-expirable)
6467       (push (cons number gnus-low-score-mark)
6468             gnus-newsgroup-reads)))
6469   ;; Go recursively through all subthreads.
6470   (mapcar 'gnus-expunge-thread (cdr thread)))
6471
6472 ;; Summary article oriented commands
6473
6474 (defun gnus-summary-refer-parent-article (n)
6475   "Refer parent article N times.
6476 If N is negative, go to ancestor -N instead.
6477 The difference between N and the number of articles fetched is returned."
6478   (interactive "p")
6479   (let ((skip 1)
6480         error header ref)
6481     (when (not (natnump n))
6482       (setq skip (abs n)
6483             n 1))
6484     (while (and (> n 0)
6485                 (not error))
6486       (setq header (gnus-summary-article-header))
6487       (if (and (eq (mail-header-number header)
6488                    (cdr gnus-article-current))
6489                (equal gnus-newsgroup-name
6490                       (car gnus-article-current)))
6491           ;; If we try to find the parent of the currently
6492           ;; displayed article, then we take a look at the actual
6493           ;; References header, since this is slightly more
6494           ;; reliable than the References field we got from the
6495           ;; server.
6496           (save-excursion
6497             (set-buffer gnus-original-article-buffer)
6498             (nnheader-narrow-to-headers)
6499             (unless (setq ref (message-fetch-field "references"))
6500               (setq ref (message-fetch-field "in-reply-to")))
6501             (widen))
6502         (setq ref
6503               ;; It's not the current article, so we take a bet on
6504               ;; the value we got from the server.
6505               (mail-header-references header)))
6506       (if (and ref
6507                (not (equal ref "")))
6508           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6509             (gnus-message 1 "Couldn't find parent"))
6510         (gnus-message 1 "No references in article %d"
6511                       (gnus-summary-article-number))
6512         (setq error t))
6513       (decf n))
6514     (gnus-summary-position-point)
6515     n))
6516
6517 (defun gnus-summary-refer-references ()
6518   "Fetch all articles mentioned in the References header.
6519 Return the number of articles fetched."
6520   (interactive)
6521   (let ((ref (mail-header-references (gnus-summary-article-header)))
6522         (current (gnus-summary-article-number))
6523         (n 0))
6524     (if (or (not ref)
6525             (equal ref ""))
6526         (error "No References in the current article")
6527       ;; For each Message-ID in the References header...
6528       (while (string-match "<[^>]*>" ref)
6529         (incf n)
6530         ;; ... fetch that article.
6531         (gnus-summary-refer-article
6532          (prog1 (match-string 0 ref)
6533            (setq ref (substring ref (match-end 0))))))
6534       (gnus-summary-goto-subject current)
6535       (gnus-summary-position-point)
6536       n)))
6537
6538 (defun gnus-summary-refer-thread (&optional limit)
6539   "Fetch all articles in the current thread.
6540 If LIMIT (the numerical prefix), fetch that many old headers instead
6541 of what's specified by the `gnus-refer-thread-limit' variable."
6542   (interactive "P")
6543   (let ((id (mail-header-id (gnus-summary-article-header)))
6544         (limit (if limit (prefix-numeric-value limit)
6545                  gnus-refer-thread-limit)))
6546     ;; We want to fetch LIMIT *old* headers, but we also have to
6547     ;; re-fetch all the headers in the current buffer, because many of
6548     ;; them may be undisplayed.  So we adjust LIMIT.
6549     (when (numberp limit)
6550       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6551     (unless (eq gnus-fetch-old-headers 'invisible)
6552       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6553       ;; Retrieve the headers and read them in.
6554       (if (eq (gnus-retrieve-headers
6555                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6556               'nov)
6557           (gnus-build-all-threads)
6558         (error "Can't fetch thread from backends that don't support NOV"))
6559       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6560     (gnus-summary-limit-include-thread id)))
6561
6562 (defun gnus-summary-refer-article (message-id &optional arg)
6563   "Fetch an article specified by MESSAGE-ID.
6564 If ARG (the prefix), fetch the article using `gnus-refer-article-method'
6565 or `gnus-select-method', no matter what backend the article comes from."
6566   (interactive "sMessage-ID: \nP")
6567   (when (and (stringp message-id)
6568              (not (zerop (length message-id))))
6569     ;; Construct the correct Message-ID if necessary.
6570     ;; Suggested by tale@pawl.rpi.edu.
6571     (unless (string-match "^<" message-id)
6572       (setq message-id (concat "<" message-id)))
6573     (unless (string-match ">$" message-id)
6574       (setq message-id (concat message-id ">")))
6575     (let* ((header (gnus-id-to-header message-id))
6576            (sparse (and header
6577                         (gnus-summary-article-sparse-p
6578                          (mail-header-number header))
6579                         (memq (mail-header-number header)
6580                               gnus-newsgroup-limit))))
6581       (cond
6582        ;; If the article is present in the buffer we just go to it.
6583        ((and header
6584              (or (not (gnus-summary-article-sparse-p
6585                        (mail-header-number header)))
6586                  sparse))
6587         (prog1
6588             (gnus-summary-goto-article
6589              (mail-header-number header) nil t)
6590           (when sparse
6591             (gnus-summary-update-article (mail-header-number header)))))
6592        (t
6593         ;; We fetch the article
6594         (let ((gnus-override-method
6595                (cond ((gnus-news-group-p gnus-newsgroup-name)
6596                       gnus-refer-article-method)
6597                      (arg
6598                       (or gnus-refer-article-method gnus-select-method))
6599                      (t nil)))
6600               number)
6601           ;; Start the special refer-article method, if necessary.
6602           (when (and gnus-refer-article-method
6603                      (gnus-news-group-p gnus-newsgroup-name))
6604             (gnus-check-server gnus-refer-article-method))
6605           ;; Fetch the header, and display the article.
6606           (if (setq number (gnus-summary-insert-subject message-id))
6607               (gnus-summary-select-article nil nil nil number)
6608             (gnus-message 3 "Couldn't fetch article %s" message-id))))))))
6609
6610 (defun gnus-summary-edit-parameters ()
6611   "Edit the group parameters of the current group."
6612   (interactive)
6613   (gnus-group-edit-group gnus-newsgroup-name 'params))
6614
6615 (defun gnus-summary-customize-parameters ()
6616   "Customize the group parameters of the current group."
6617   (interactive)
6618   (gnus-group-customize gnus-newsgroup-name))
6619
6620 (defun gnus-summary-enter-digest-group (&optional force)
6621   "Enter an nndoc group based on the current article.
6622 If FORCE, force a digest interpretation.  If not, try
6623 to guess what the document format is."
6624   (interactive "P")
6625   (let ((conf gnus-current-window-configuration))
6626     (save-excursion
6627       (gnus-summary-select-article))
6628     (setq gnus-current-window-configuration conf)
6629     (let* ((name (format "%s-%d"
6630                          (gnus-group-prefixed-name
6631                           gnus-newsgroup-name (list 'nndoc ""))
6632                          (save-excursion
6633                            (set-buffer gnus-summary-buffer)
6634                            gnus-current-article)))
6635            (ogroup gnus-newsgroup-name)
6636            (params (append (gnus-info-params (gnus-get-info ogroup))
6637                            (list (cons 'to-group ogroup))
6638                            (list (cons 'save-article-group ogroup))))
6639            (case-fold-search t)
6640            (buf (current-buffer))
6641            dig)
6642       (save-excursion
6643         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6644         (insert-buffer-substring gnus-original-article-buffer)
6645         ;; Remove lines that may lead nndoc to misinterpret the
6646         ;; document type.
6647         (narrow-to-region
6648          (goto-char (point-min))
6649          (or (search-forward "\n\n" nil t) (point)))
6650         (goto-char (point-min))
6651         (delete-matching-lines "^\\(Path\\):\\|^From ")
6652         (widen))
6653       (unwind-protect
6654           (if (gnus-group-read-ephemeral-group
6655                name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6656                             (nndoc-article-type
6657                              ,(if force 'digest 'guess))) t)
6658               ;; Make all postings to this group go to the parent group.
6659               (nconc (gnus-info-params (gnus-get-info name))
6660                      params)
6661             ;; Couldn't select this doc group.
6662             (switch-to-buffer buf)
6663             (gnus-set-global-variables)
6664             (gnus-configure-windows 'summary)
6665             (gnus-message 3 "Article couldn't be entered?"))
6666         (kill-buffer dig)))))
6667
6668 (defun gnus-summary-read-document (n)
6669   "Open a new group based on the current article(s).
6670 This will allow you to read digests and other similar
6671 documents as newsgroups.
6672 Obeys the standard process/prefix convention."
6673   (interactive "P")
6674   (let* ((articles (gnus-summary-work-articles n))
6675          (ogroup gnus-newsgroup-name)
6676          (params (append (gnus-info-params (gnus-get-info ogroup))
6677                          (list (cons 'to-group ogroup))))
6678          article group egroup groups vgroup)
6679     (while (setq article (pop articles))
6680       (setq group (format "%s-%d" gnus-newsgroup-name article))
6681       (gnus-summary-remove-process-mark article)
6682       (when (gnus-summary-display-article article)
6683         (save-excursion
6684           (with-temp-buffer
6685             (insert-buffer-substring gnus-original-article-buffer)
6686             ;; Remove some headers that may lead nndoc to make
6687             ;; the wrong guess.
6688             (message-narrow-to-head)
6689             (goto-char (point-min))
6690             (delete-matching-lines "^\\(Path\\):\\|^From ")
6691             (widen)
6692             (if (setq egroup
6693                       (gnus-group-read-ephemeral-group
6694                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6695                                      (nndoc-article-type guess))
6696                        t nil t))
6697                 (progn
6698                   ;; Make all postings to this group go to the parent group.
6699                   (nconc (gnus-info-params (gnus-get-info egroup))
6700                          params)
6701                   (push egroup groups))
6702               ;; Couldn't select this doc group.
6703               (gnus-error 3 "Article couldn't be entered"))))))
6704     ;; Now we have selected all the documents.
6705     (cond
6706      ((not groups)
6707       (error "None of the articles could be interpreted as documents"))
6708      ((gnus-group-read-ephemeral-group
6709        (setq vgroup (format
6710                      "nnvirtual:%s-%s" gnus-newsgroup-name
6711                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6712        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6713        t
6714        (cons (current-buffer) 'summary)))
6715      (t
6716       (error "Couldn't select virtual nndoc group")))))
6717
6718 (defun gnus-summary-isearch-article (&optional regexp-p)
6719   "Do incremental search forward on the current article.
6720 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6721   (interactive "P")
6722   (gnus-summary-select-article)
6723   (gnus-configure-windows 'article)
6724   (gnus-eval-in-buffer-window gnus-article-buffer
6725     (save-restriction
6726       (widen)
6727       (isearch-forward regexp-p))))
6728
6729 (defun gnus-summary-search-article-forward (regexp &optional backward)
6730   "Search for an article containing REGEXP forward.
6731 If BACKWARD, search backward instead."
6732   (interactive
6733    (list (read-string
6734           (format "Search article %s (regexp%s): "
6735                   (if current-prefix-arg "backward" "forward")
6736                   (if gnus-last-search-regexp
6737                       (concat ", default " gnus-last-search-regexp)
6738                     "")))
6739          current-prefix-arg))
6740   (if (string-equal regexp "")
6741       (setq regexp (or gnus-last-search-regexp ""))
6742     (setq gnus-last-search-regexp regexp))
6743   (if (gnus-summary-search-article regexp backward)
6744       (gnus-summary-show-thread)
6745     (error "Search failed: \"%s\"" regexp)))
6746
6747 (defun gnus-summary-search-article-backward (regexp)
6748   "Search for an article containing REGEXP backward."
6749   (interactive
6750    (list (read-string
6751           (format "Search article backward (regexp%s): "
6752                   (if gnus-last-search-regexp
6753                       (concat ", default " gnus-last-search-regexp)
6754                     "")))))
6755   (gnus-summary-search-article-forward regexp 'backward))
6756
6757 (defun gnus-summary-search-article (regexp &optional backward)
6758   "Search for an article containing REGEXP.
6759 Optional argument BACKWARD means do search for backward.
6760 `gnus-select-article-hook' is not called during the search."
6761   ;; We have to require this here to make sure that the following
6762   ;; dynamic binding isn't shadowed by autoloading.
6763   (require 'gnus-async)
6764   (require 'gnus-art)
6765   (let ((gnus-select-article-hook nil)  ;Disable hook.
6766         (gnus-article-display-hook nil)
6767         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
6768         (gnus-use-article-prefetch nil)
6769         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
6770         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
6771         (sum (current-buffer))
6772         (found nil)
6773         point)
6774     (gnus-save-hidden-threads
6775       (gnus-summary-select-article)
6776       (set-buffer gnus-article-buffer)
6777       (when backward
6778         (forward-line -1))
6779       (while (not found)
6780         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
6781         (if (if backward
6782                 (re-search-backward regexp nil t)
6783               (re-search-forward regexp nil t))
6784             ;; We found the regexp.
6785             (progn
6786               (setq found 'found)
6787               (beginning-of-line)
6788               (set-window-start
6789                (get-buffer-window (current-buffer))
6790                (point))
6791               (forward-line 1)
6792               (set-buffer sum)
6793               (setq point (point)))
6794           ;; We didn't find it, so we go to the next article.
6795           (set-buffer sum)
6796           (setq found 'not)
6797           (while (eq found 'not)
6798             (if (not (if backward (gnus-summary-find-prev)
6799                        (gnus-summary-find-next)))
6800                 ;; No more articles.
6801                 (setq found t)
6802               ;; Select the next article and adjust point.
6803               (unless (gnus-summary-article-sparse-p
6804                        (gnus-summary-article-number))
6805                 (setq found nil)
6806                 (gnus-summary-select-article)
6807                 (set-buffer gnus-article-buffer)
6808                 (widen)
6809                 (goto-char (if backward (point-max) (point-min))))))))
6810       (gnus-message 7 ""))
6811     ;; Return whether we found the regexp.
6812     (when (eq found 'found)
6813       (goto-char point)
6814       (gnus-summary-show-thread)
6815       (gnus-summary-goto-subject gnus-current-article)
6816       (gnus-summary-position-point)
6817       t)))
6818
6819 (defun gnus-summary-find-matching (header regexp &optional backward unread
6820                                           not-case-fold)
6821   "Return a list of all articles that match REGEXP on HEADER.
6822 The search stars on the current article and goes forwards unless
6823 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
6824 If UNREAD is non-nil, only unread articles will
6825 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
6826 in the comparisons."
6827   (let ((data (if (eq backward 'all) gnus-newsgroup-data
6828                 (gnus-data-find-list
6829                  (gnus-summary-article-number) (gnus-data-list backward))))
6830         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
6831         (case-fold-search (not not-case-fold))
6832         articles d)
6833     (unless (fboundp (intern (concat "mail-header-" header)))
6834       (error "%s is not a valid header" header))
6835     (while data
6836       (setq d (car data))
6837       (and (or (not unread)             ; We want all articles...
6838                (gnus-data-unread-p d))  ; Or just unreads.
6839            (vectorp (gnus-data-header d)) ; It's not a pseudo.
6840            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
6841            (push (gnus-data-number d) articles)) ; Success!
6842       (setq data (cdr data)))
6843     (nreverse articles)))
6844
6845 (defun gnus-summary-execute-command (header regexp command &optional backward)
6846   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
6847 If HEADER is an empty string (or nil), the match is done on the entire
6848 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
6849   (interactive
6850    (list (let ((completion-ignore-case t))
6851            (completing-read
6852             "Header name: "
6853             (mapcar (lambda (string) (list string))
6854                     '("Number" "Subject" "From" "Lines" "Date"
6855                       "Message-ID" "Xref" "References" "Body"))
6856             nil 'require-match))
6857          (read-string "Regexp: ")
6858          (read-key-sequence "Command: ")
6859          current-prefix-arg))
6860   (when (equal header "Body")
6861     (setq header ""))
6862   ;; Hidden thread subtrees must be searched as well.
6863   (gnus-summary-show-all-threads)
6864   ;; We don't want to change current point nor window configuration.
6865   (save-excursion
6866     (save-window-excursion
6867       (gnus-message 6 "Executing %s..." (key-description command))
6868       ;; We'd like to execute COMMAND interactively so as to give arguments.
6869       (gnus-execute header regexp
6870                     `(call-interactively ',(key-binding command))
6871                     backward)
6872       (gnus-message 6 "Executing %s...done" (key-description command)))))
6873
6874 (defun gnus-summary-beginning-of-article ()
6875   "Scroll the article back to the beginning."
6876   (interactive)
6877   (gnus-summary-select-article)
6878   (gnus-configure-windows 'article)
6879   (gnus-eval-in-buffer-window gnus-article-buffer
6880     (widen)
6881     (goto-char (point-min))
6882     (when gnus-page-broken
6883       (gnus-narrow-to-page))))
6884
6885 (defun gnus-summary-end-of-article ()
6886   "Scroll to the end of the article."
6887   (interactive)
6888   (gnus-summary-select-article)
6889   (gnus-configure-windows 'article)
6890   (gnus-eval-in-buffer-window gnus-article-buffer
6891     (widen)
6892     (goto-char (point-max))
6893     (recenter -3)
6894     (when gnus-page-broken
6895       (gnus-narrow-to-page))))
6896
6897 (defun gnus-summary-print-article (&optional filename n)
6898   "Generate and print a PostScript image of the N next (mail) articles.
6899
6900 If N is negative, print the N previous articles.  If N is nil and articles
6901 have been marked with the process mark, print these instead.
6902
6903 If the optional second argument FILENAME is nil, send the image to the
6904 printer.  If FILENAME is a string, save the PostScript image in a file with
6905 that name.  If FILENAME is a number, prompt the user for the name of the file
6906 to save in."
6907   (interactive (list (ps-print-preprint current-prefix-arg)
6908                      current-prefix-arg))
6909   (dolist (article (gnus-summary-work-articles n))
6910     (gnus-summary-select-article nil nil 'pseudo article)
6911     (gnus-eval-in-buffer-window gnus-article-buffer
6912       (let ((buffer (generate-new-buffer " *print*")))
6913         (unwind-protect
6914             (progn
6915               (copy-to-buffer buffer (point-min) (point-max))
6916               (set-buffer buffer)
6917               (gnus-article-delete-invisible-text)
6918               (let ((ps-left-header
6919                      (list
6920                       (concat "("
6921                               (mail-header-subject gnus-current-headers) ")")
6922                       (concat "("
6923                               (mail-header-from gnus-current-headers) ")")))
6924                     (ps-right-header
6925                      (list
6926                       "/pagenumberstring load"
6927                       (concat "("
6928                               (mail-header-date gnus-current-headers) ")"))))
6929                 (gnus-run-hooks 'gnus-ps-print-hook)
6930                 (save-excursion
6931                   (ps-print-buffer-with-faces filename))))
6932           (kill-buffer buffer))))))
6933
6934 (defun gnus-summary-show-article (&optional arg)
6935   "Force re-fetching of the current article.
6936 If ARG (the prefix) is non-nil, show the raw article without any
6937 article massaging functions being run."
6938   (interactive "P")
6939   (if (not arg)
6940       ;; Select the article the normal way.
6941       (gnus-summary-select-article nil 'force)
6942     ;; We have to require this here to make sure that the following
6943     ;; dynamic binding isn't shadowed by autoloading.
6944     (require 'gnus-async)
6945     (require 'gnus-art)
6946     ;; Bind the article treatment functions to nil.
6947     (let ((gnus-have-all-headers t)
6948           gnus-article-display-hook
6949           gnus-article-prepare-hook
6950           gnus-article-decode-hook
6951           gnus-break-pages
6952           gnus-show-mime
6953           gnus-visual)
6954       (gnus-summary-select-article nil 'force)))
6955   (gnus-summary-goto-subject gnus-current-article)
6956   (gnus-summary-position-point))
6957
6958 (defun gnus-summary-verbose-headers (&optional arg)
6959   "Toggle permanent full header display.
6960 If ARG is a positive number, turn header display on.
6961 If ARG is a negative number, turn header display off."
6962   (interactive "P")
6963   (setq gnus-show-all-headers
6964         (cond ((or (not (numberp arg))
6965                    (zerop arg))
6966                (not gnus-show-all-headers))
6967               ((natnump arg)
6968                t)))
6969   (gnus-summary-show-article))
6970
6971 (defun gnus-summary-toggle-header (&optional arg)
6972   "Show the headers if they are hidden, or hide them if they are shown.
6973 If ARG is a positive number, show the entire header.
6974 If ARG is a negative number, hide the unwanted header lines."
6975   (interactive "P")
6976   (save-excursion
6977     (set-buffer gnus-article-buffer)
6978     (let* ((buffer-read-only nil)
6979            (inhibit-point-motion-hooks t)
6980            (hidden (text-property-any
6981                     (goto-char (point-min)) (search-forward "\n\n")
6982                     'invisible t))
6983            e)
6984       (goto-char (point-min))
6985       (when (search-forward "\n\n" nil t)
6986         (delete-region (point-min) (1- (point))))
6987       (goto-char (point-min))
6988       (save-excursion
6989         (set-buffer gnus-original-article-buffer)
6990         (goto-char (point-min))
6991         (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
6992       (insert-buffer-substring gnus-original-article-buffer 1 e)
6993       (let ((article-inhibit-hiding t))
6994         (gnus-run-hooks 'gnus-article-display-hook))
6995       (when (or (not hidden) (and (numberp arg) (< arg 0)))
6996         (gnus-article-hide-headers)))))
6997
6998 (defun gnus-summary-show-all-headers ()
6999   "Make all header lines visible."
7000   (interactive)
7001   (gnus-article-show-all-headers))
7002
7003 (defun gnus-summary-toggle-mime (&optional arg)
7004   "Toggle MIME processing.
7005 If ARG is a positive number, turn MIME processing on."
7006   (interactive "P")
7007   (setq gnus-show-mime
7008         (if (null arg) (not gnus-show-mime)
7009           (> (prefix-numeric-value arg) 0)))
7010   (gnus-summary-select-article t 'force))
7011
7012 (defun gnus-summary-caesar-message (&optional arg)
7013   "Caesar rotate the current article by 13.
7014 The numerical prefix specifies how many places to rotate each letter
7015 forward."
7016   (interactive "P")
7017   (gnus-summary-select-article)
7018   (let ((mail-header-separator ""))
7019     (gnus-eval-in-buffer-window gnus-article-buffer
7020       (save-restriction
7021         (widen)
7022         (let ((start (window-start))
7023               buffer-read-only)
7024           (message-caesar-buffer-body arg)
7025           (set-window-start (get-buffer-window (current-buffer)) start))))))
7026
7027 (defun gnus-summary-stop-page-breaking ()
7028   "Stop page breaking in the current article."
7029   (interactive)
7030   (gnus-summary-select-article)
7031   (gnus-eval-in-buffer-window gnus-article-buffer
7032     (widen)
7033     (when (gnus-visual-p 'page-marker)
7034       (let ((buffer-read-only nil))
7035         (gnus-remove-text-with-property 'gnus-prev)
7036         (gnus-remove-text-with-property 'gnus-next))
7037       (setq gnus-page-broken nil))))
7038
7039 (defun gnus-summary-move-article (&optional n to-newsgroup
7040                                             select-method action)
7041   "Move the current article to a different newsgroup.
7042 If N is a positive number, move the N next articles.
7043 If N is a negative number, move the N previous articles.
7044 If N is nil and any articles have been marked with the process mark,
7045 move those articles instead.
7046 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7047 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7048 re-spool using this method.
7049
7050 For this function to work, both the current newsgroup and the
7051 newsgroup that you want to move to have to support the `request-move'
7052 and `request-accept' functions."
7053   (interactive "P")
7054   (unless action
7055     (setq action 'move))
7056   ;; Disable marking as read.
7057   (let (gnus-mark-article-hook)
7058     (save-window-excursion
7059       (gnus-summary-select-article)))
7060   ;; Check whether the source group supports the required functions.
7061   (cond ((and (eq action 'move)
7062               (not (gnus-check-backend-function
7063                     'request-move-article gnus-newsgroup-name)))
7064          (error "The current group does not support article moving"))
7065         ((and (eq action 'crosspost)
7066               (not (gnus-check-backend-function
7067                     'request-replace-article gnus-newsgroup-name)))
7068          (error "The current group does not support article editing")))
7069   (let ((articles (gnus-summary-work-articles n))
7070         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
7071         (names '((move "Move" "Moving")
7072                  (copy "Copy" "Copying")
7073                  (crosspost "Crosspost" "Crossposting")))
7074         (copy-buf (save-excursion
7075                     (nnheader-set-temp-buffer " *copy article*")))
7076         art-group to-method new-xref article to-groups)
7077     (unless (assq action names)
7078       (error "Unknown action %s" action))
7079     ;; Read the newsgroup name.
7080     (when (and (not to-newsgroup)
7081                (not select-method))
7082       (setq to-newsgroup
7083             (gnus-read-move-group-name
7084              (cadr (assq action names))
7085              (symbol-value (intern (format "gnus-current-%s-group" action)))
7086              articles prefix))
7087       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7088     (setq to-method (or select-method
7089                         (gnus-group-name-to-method to-newsgroup)))
7090     ;; Check the method we are to move this article to...
7091     (unless (gnus-check-backend-function
7092              'request-accept-article (car to-method))
7093       (error "%s does not support article copying" (car to-method)))
7094     (unless (gnus-check-server to-method)
7095       (error "Can't open server %s" (car to-method)))
7096     (gnus-message 6 "%s to %s: %s..."
7097                   (caddr (assq action names))
7098                   (or (car select-method) to-newsgroup) articles)
7099     (while articles
7100       (setq article (pop articles))
7101       (setq
7102        art-group
7103        (cond
7104         ;; Move the article.
7105         ((eq action 'move)
7106          ;; Remove this article from future suppression.
7107          (gnus-dup-unsuppress-article article)
7108          (gnus-request-move-article
7109           article                       ; Article to move
7110           gnus-newsgroup-name           ; From newsgroup
7111           (nth 1 (gnus-find-method-for-group
7112                   gnus-newsgroup-name)) ; Server
7113           (list 'gnus-request-accept-article
7114                 to-newsgroup (list 'quote select-method)
7115                 (not articles) t)               ; Accept form
7116           (not articles)))              ; Only save nov last time
7117         ;; Copy the article.
7118         ((eq action 'copy)
7119          (save-excursion
7120            (set-buffer copy-buf)
7121            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7122              (gnus-request-accept-article
7123               to-newsgroup select-method (not articles) t))))
7124         ;; Crosspost the article.
7125         ((eq action 'crosspost)
7126          (let ((xref (message-tokenize-header
7127                       (mail-header-xref (gnus-summary-article-header article))
7128                       " ")))
7129            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7130                                   ":" article))
7131            (unless xref
7132              (setq xref (list (system-name))))
7133            (setq new-xref
7134                  (concat
7135                   (mapconcat 'identity
7136                              (delete "Xref:" (delete new-xref xref))
7137                              " ")
7138                   " " new-xref))
7139            (save-excursion
7140              (set-buffer copy-buf)
7141              ;; First put the article in the destination group.
7142              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7143              (when (consp (setq art-group
7144                                 (gnus-request-accept-article
7145                                  to-newsgroup select-method (not articles))))
7146                (setq new-xref (concat new-xref " " (car art-group)
7147                                       ":" (cdr art-group)))
7148                ;; Now we have the new Xrefs header, so we insert
7149                ;; it and replace the new article.
7150                (nnheader-replace-header "Xref" new-xref)
7151                (gnus-request-replace-article
7152                 (cdr art-group) to-newsgroup (current-buffer))
7153                art-group))))))
7154       (cond
7155        ((not art-group)
7156         (gnus-message 1 "Couldn't %s article %s"
7157                       (cadr (assq action names)) article))
7158        ((and (eq art-group 'junk)
7159              (eq action 'move))
7160         (gnus-summary-mark-article article gnus-canceled-mark)
7161         (gnus-message 4 "Deleted article %s" article))
7162        (t
7163         (let* ((pto-group (gnus-group-prefixed-name
7164                            (car art-group) to-method))
7165                (entry
7166                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7167                (info (nth 2 entry))
7168                (to-group (gnus-info-group info)))
7169           ;; Update the group that has been moved to.
7170           (when (and info
7171                      (memq action '(move copy)))
7172             (unless (member to-group to-groups)
7173               (push to-group to-groups))
7174
7175             (unless (memq article gnus-newsgroup-unreads)
7176               (gnus-info-set-read
7177                info (gnus-add-to-range (gnus-info-read info)
7178                                        (list (cdr art-group)))))
7179
7180             ;; Copy any marks over to the new group.
7181             (let ((marks gnus-article-mark-lists)
7182                   (to-article (cdr art-group)))
7183
7184               ;; See whether the article is to be put in the cache.
7185               (when gnus-use-cache
7186                 (gnus-cache-possibly-enter-article
7187                  to-group to-article
7188                  (let ((header (copy-sequence
7189                                 (gnus-summary-article-header article))))
7190                    (mail-header-set-number header to-article)
7191                    header)
7192                  (memq article gnus-newsgroup-marked)
7193                  (memq article gnus-newsgroup-dormant)
7194                  (memq article gnus-newsgroup-unreads)))
7195
7196               (when (and (equal to-group gnus-newsgroup-name)
7197                          (not (memq article gnus-newsgroup-unreads)))
7198                 ;; Mark this article as read in this group.
7199                 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7200                 (setcdr (gnus-active to-group) to-article)
7201                 (setcdr gnus-newsgroup-active to-article))
7202
7203               (while marks
7204                 (when (memq article (symbol-value
7205                                      (intern (format "gnus-newsgroup-%s"
7206                                                      (caar marks)))))
7207                   ;; If the other group is the same as this group,
7208                   ;; then we have to add the mark to the list.
7209                   (when (equal to-group gnus-newsgroup-name)
7210                     (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7211                          (cons to-article
7212                                (symbol-value
7213                                 (intern (format "gnus-newsgroup-%s"
7214                                                 (caar marks)))))))
7215                   ;; Copy the marks to other group.
7216                   (gnus-add-marked-articles
7217                    to-group (cdar marks) (list to-article) info))
7218                 (setq marks (cdr marks)))
7219
7220               (gnus-dribble-enter
7221                (concat "(gnus-group-set-info '"
7222                        (gnus-prin1-to-string (gnus-get-info to-group))
7223                        ")"))))
7224
7225           ;; Update the Xref header in this article to point to
7226           ;; the new crossposted article we have just created.
7227           (when (eq action 'crosspost)
7228             (save-excursion
7229               (set-buffer copy-buf)
7230               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7231               (nnheader-replace-header "Xref" new-xref)
7232               (gnus-request-replace-article
7233                article gnus-newsgroup-name (current-buffer)))))
7234
7235         ;;;!!!Why is this necessary?
7236         (set-buffer gnus-summary-buffer)
7237
7238         (gnus-summary-goto-subject article)
7239         (when (eq action 'move)
7240           (gnus-summary-mark-article article gnus-canceled-mark))))
7241       (gnus-summary-remove-process-mark article))
7242     ;; Re-activate all groups that have been moved to.
7243     (while to-groups
7244       (save-excursion
7245         (set-buffer gnus-group-buffer)
7246         (when (gnus-group-goto-group (car to-groups) t)
7247           (gnus-group-get-new-news-this-group 1 t))
7248         (pop to-groups)))
7249
7250     (gnus-kill-buffer copy-buf)
7251     (gnus-summary-position-point)
7252     (gnus-set-mode-line 'summary)))
7253
7254 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7255   "Move the current article to a different newsgroup.
7256 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7257 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7258 re-spool using this method."
7259   (interactive "P")
7260   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7261
7262 (defun gnus-summary-crosspost-article (&optional n)
7263   "Crosspost the current article to some other group."
7264   (interactive "P")
7265   (gnus-summary-move-article n nil nil 'crosspost))
7266
7267 (defcustom gnus-summary-respool-default-method nil
7268   "Default method for respooling an article.
7269 If nil, use to the current newsgroup method."
7270   :type '(choice (gnus-select-method :value (nnml ""))
7271                  (const nil))
7272   :group 'gnus-summary-mail)
7273
7274 (defun gnus-summary-respool-article (&optional n method)
7275   "Respool the current article.
7276 The article will be squeezed through the mail spooling process again,
7277 which means that it will be put in some mail newsgroup or other
7278 depending on `nnmail-split-methods'.
7279 If N is a positive number, respool the N next articles.
7280 If N is a negative number, respool the N previous articles.
7281 If N is nil and any articles have been marked with the process mark,
7282 respool those articles instead.
7283
7284 Respooling can be done both from mail groups and \"real\" newsgroups.
7285 In the former case, the articles in question will be moved from the
7286 current group into whatever groups they are destined to.  In the
7287 latter case, they will be copied into the relevant groups."
7288   (interactive
7289    (list current-prefix-arg
7290          (let* ((methods (gnus-methods-using 'respool))
7291                 (methname
7292                  (symbol-name (or gnus-summary-respool-default-method
7293                                   (car (gnus-find-method-for-group
7294                                         gnus-newsgroup-name)))))
7295                 (method
7296                  (gnus-completing-read
7297                   methname "What backend do you want to use when respooling?"
7298                   methods nil t nil 'gnus-mail-method-history))
7299                 ms)
7300            (cond
7301             ((zerop (length (setq ms (gnus-servers-using-backend
7302                                       (intern method)))))
7303              (list (intern method) ""))
7304             ((= 1 (length ms))
7305              (car ms))
7306             (t
7307              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7308                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7309                            ms-alist))))))))
7310   (unless method
7311     (error "No method given for respooling"))
7312   (if (assoc (symbol-name
7313               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7314              (gnus-methods-using 'respool))
7315       (gnus-summary-move-article n nil method)
7316     (gnus-summary-copy-article n nil method)))
7317
7318 (defun gnus-summary-import-article (file)
7319   "Import an arbitrary file into a mail newsgroup."
7320   (interactive "fImport file: ")
7321   (let ((group gnus-newsgroup-name)
7322         (now (current-time))
7323         atts lines)
7324     (unless (gnus-check-backend-function 'request-accept-article group)
7325       (error "%s does not support article importing" group))
7326     (or (file-readable-p file)
7327         (not (file-regular-p file))
7328         (error "Can't read %s" file))
7329     (save-excursion
7330       (set-buffer (gnus-get-buffer-create " *import file*"))
7331       (erase-buffer)
7332       (nnheader-insert-file-contents file)
7333       (goto-char (point-min))
7334       (unless (nnheader-article-p)
7335         ;; This doesn't look like an article, so we fudge some headers.
7336         (setq atts (file-attributes file)
7337               lines (count-lines (point-min) (point-max)))
7338         (insert "From: " (read-string "From: ") "\n"
7339                 "Subject: " (read-string "Subject: ") "\n"
7340                 "Date: " (message-make-date (nth 5 atts))
7341                 "\n"
7342                 "Message-ID: " (message-make-message-id) "\n"
7343                 "Lines: " (int-to-string lines) "\n"
7344                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7345       (gnus-request-accept-article group nil t)
7346       (kill-buffer (current-buffer)))))
7347
7348 (defun gnus-summary-article-posted-p ()
7349   "Say whether the current (mail) article is available from `gnus-select-method' as well.
7350 This will be the case if the article has both been mailed and posted."
7351   (interactive)
7352   (let ((id (mail-header-references (gnus-summary-article-header)))
7353         (gnus-override-method
7354          (or gnus-refer-article-method gnus-select-method)))
7355     (if (gnus-request-head id "")
7356         (gnus-message 2 "The current message was found on %s"
7357                       gnus-override-method)
7358       (gnus-message 2 "The current message couldn't be found on %s"
7359                     gnus-override-method)
7360       nil)))
7361
7362 (defun gnus-summary-expire-articles (&optional now)
7363   "Expire all articles that are marked as expirable in the current group."
7364   (interactive)
7365   (when (gnus-check-backend-function
7366          'request-expire-articles gnus-newsgroup-name)
7367     ;; This backend supports expiry.
7368     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7369            (expirable (if total
7370                           (progn
7371                             ;; We need to update the info for
7372                             ;; this group for `gnus-list-of-read-articles'
7373                             ;; to give us the right answer.
7374                             (gnus-run-hooks 'gnus-exit-group-hook)
7375                             (gnus-summary-update-info)
7376                             (gnus-list-of-read-articles gnus-newsgroup-name))
7377                         (setq gnus-newsgroup-expirable
7378                               (sort gnus-newsgroup-expirable '<))))
7379            (expiry-wait (if now 'immediate
7380                           (gnus-group-find-parameter
7381                            gnus-newsgroup-name 'expiry-wait)))
7382            es)
7383       (when expirable
7384         ;; There are expirable articles in this group, so we run them
7385         ;; through the expiry process.
7386         (gnus-message 6 "Expiring articles...")
7387         ;; The list of articles that weren't expired is returned.
7388         (save-excursion
7389           (if expiry-wait
7390               (let ((nnmail-expiry-wait-function nil)
7391                     (nnmail-expiry-wait expiry-wait))
7392                 (setq es (gnus-request-expire-articles
7393                           expirable gnus-newsgroup-name)))
7394             (setq es (gnus-request-expire-articles
7395                       expirable gnus-newsgroup-name))))
7396         (unless total
7397           (setq gnus-newsgroup-expirable es))
7398         ;; We go through the old list of expirable, and mark all
7399         ;; really expired articles as nonexistent.
7400         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
7401           (let ((gnus-use-cache nil))
7402             (while expirable
7403               (unless (memq (car expirable) es)
7404                 (when (gnus-data-find (car expirable))
7405                   (gnus-summary-mark-article
7406                    (car expirable) gnus-canceled-mark)))
7407               (setq expirable (cdr expirable)))))
7408         (gnus-message 6 "Expiring articles...done")))))
7409
7410 (defun gnus-summary-expire-articles-now ()
7411   "Expunge all expirable articles in the current group.
7412 This means that *all* articles that are marked as expirable will be
7413 deleted forever, right now."
7414   (interactive)
7415   (or gnus-expert-user
7416       (gnus-yes-or-no-p
7417        "Are you really, really, really sure you want to delete all these messages? ")
7418       (error "Phew!"))
7419   (gnus-summary-expire-articles t))
7420
7421 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7422 (defun gnus-summary-delete-article (&optional n)
7423   "Delete the N next (mail) articles.
7424 This command actually deletes articles.  This is not a marking
7425 command.  The article will disappear forever from your life, never to
7426 return.
7427 If N is negative, delete backwards.
7428 If N is nil and articles have been marked with the process mark,
7429 delete these instead."
7430   (interactive "P")
7431   (unless (gnus-check-backend-function 'request-expire-articles
7432                                        gnus-newsgroup-name)
7433     (error "The current newsgroup does not support article deletion"))
7434   ;; Compute the list of articles to delete.
7435   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
7436         not-deleted)
7437     (if (and gnus-novice-user
7438              (not (gnus-yes-or-no-p
7439                    (format "Do you really want to delete %s forever? "
7440                            (if (> (length articles) 1)
7441                                (format "these %s articles" (length articles))
7442                              "this article")))))
7443         ()
7444       ;; Delete the articles.
7445       (setq not-deleted (gnus-request-expire-articles
7446                          articles gnus-newsgroup-name 'force))
7447       (while articles
7448         (gnus-summary-remove-process-mark (car articles))
7449         ;; The backend might not have been able to delete the article
7450         ;; after all.
7451         (unless (memq (car articles) not-deleted)
7452           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7453         (setq articles (cdr articles)))
7454       (when not-deleted
7455         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7456     (gnus-summary-position-point)
7457     (gnus-set-mode-line 'summary)
7458     not-deleted))
7459
7460 (defun gnus-summary-edit-article (&optional force)
7461   "Edit the current article.
7462 This will have permanent effect only in mail groups.
7463 If FORCE is non-nil, allow editing of articles even in read-only
7464 groups."
7465   (interactive "P")
7466   (save-excursion
7467     (set-buffer gnus-summary-buffer)
7468     (gnus-set-global-variables)
7469     (when (and (not force)
7470                (gnus-group-read-only-p))
7471       (error "The current newsgroup does not support article editing"))
7472     ;; Select article if needed.
7473     (unless (eq (gnus-summary-article-number)
7474                 gnus-current-article)
7475       (gnus-summary-select-article t))
7476     (gnus-article-date-original)
7477     (gnus-article-edit-article
7478      `(lambda (no-highlight)
7479         (gnus-summary-edit-article-done
7480          ,(or (mail-header-references gnus-current-headers) "")
7481          ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))
7482
7483 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7484
7485 (defun gnus-summary-edit-article-done (&optional references read-only buffer
7486                                                  no-highlight)
7487   "Make edits to the current article permanent."
7488   (interactive)
7489   ;; Replace the article.
7490   (let ((buf (current-buffer)))
7491     (with-temp-buffer
7492       (insert-buffer buf)
7493       (if (and (not read-only)
7494                (not (gnus-request-replace-article
7495                      (cdr gnus-article-current) (car gnus-article-current)
7496                      (current-buffer))))
7497           (error "Couldn't replace article")
7498         ;; Update the summary buffer.
7499         (if (and references
7500                  (equal (message-tokenize-header references " ")
7501                         (message-tokenize-header
7502                          (or (message-fetch-field "references") "") " ")))
7503             ;; We only have to update this line.
7504             (save-excursion
7505               (save-restriction
7506                 (message-narrow-to-head)
7507                 (let ((head (buffer-string))
7508                       header)
7509                   (with-temp-buffer
7510                     (insert (format "211 %d Article retrieved.\n"
7511                                     (cdr gnus-article-current)))
7512                     (insert head)
7513                     (insert ".\n")
7514                     (let ((nntp-server-buffer (current-buffer)))
7515                       (setq header (car (gnus-get-newsgroup-headers
7516                                          (save-excursion
7517                                            (set-buffer gnus-summary-buffer)
7518                                            gnus-newsgroup-dependencies)
7519                                          t))))
7520                     (save-excursion
7521                       (set-buffer gnus-summary-buffer)
7522                       (gnus-data-set-header
7523                        (gnus-data-find (cdr gnus-article-current))
7524                        header)
7525                       (gnus-summary-update-article-line
7526                        (cdr gnus-article-current) header))))))
7527           ;; Update threads.
7528           (set-buffer (or buffer gnus-summary-buffer))
7529           (gnus-summary-update-article (cdr gnus-article-current)))
7530         ;; Prettify the article buffer again.
7531         (unless no-highlight
7532           (save-excursion
7533             (set-buffer gnus-article-buffer)
7534             (gnus-run-hooks 'gnus-article-display-hook)
7535             (set-buffer gnus-original-article-buffer)
7536             (gnus-request-article
7537              (cdr gnus-article-current)
7538              (car gnus-article-current) (current-buffer))))
7539         ;; Prettify the summary buffer line.
7540         (when (gnus-visual-p 'summary-highlight 'highlight)
7541           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
7542
7543 (defun gnus-summary-edit-wash (key)
7544   "Perform editing command KEY in the article buffer."
7545   (interactive
7546    (list
7547     (progn
7548       (message "%s" (concat (this-command-keys) "- "))
7549       (read-char))))
7550   (message "")
7551   (gnus-summary-edit-article)
7552   (execute-kbd-macro (concat (this-command-keys) key))
7553   (gnus-article-edit-done))
7554
7555 ;;; Respooling
7556
7557 (defun gnus-summary-respool-query (&optional silent trace)
7558   "Query where the respool algorithm would put this article."
7559   (interactive)
7560   (let (gnus-mark-article-hook)
7561     (gnus-summary-select-article)
7562     (save-excursion
7563       (set-buffer gnus-original-article-buffer)
7564       (save-restriction
7565         (message-narrow-to-head)
7566         (let ((groups (nnmail-article-group 'identity trace)))
7567           (unless silent
7568             (if groups
7569                 (message "This message would go to %s"
7570                          (mapconcat 'car groups ", "))
7571               (message "This message would go to no groups"))
7572             groups))))))
7573
7574 (defun gnus-summary-respool-trace ()
7575   "Trace where the respool algorithm would put this article.
7576 Display a buffer showing all fancy splitting patterns which matched."
7577   (interactive)
7578   (gnus-summary-respool-query nil t))
7579
7580 ;; Summary marking commands.
7581
7582 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7583   "Mark articles which has the same subject as read, and then select the next.
7584 If UNMARK is positive, remove any kind of mark.
7585 If UNMARK is negative, tick articles."
7586   (interactive "P")
7587   (when unmark
7588     (setq unmark (prefix-numeric-value unmark)))
7589   (let ((count
7590          (gnus-summary-mark-same-subject
7591           (gnus-summary-article-subject) unmark)))
7592     ;; Select next unread article.  If auto-select-same mode, should
7593     ;; select the first unread article.
7594     (gnus-summary-next-article t (and gnus-auto-select-same
7595                                       (gnus-summary-article-subject)))
7596     (gnus-message 7 "%d article%s marked as %s"
7597                   count (if (= count 1) " is" "s are")
7598                   (if unmark "unread" "read"))))
7599
7600 (defun gnus-summary-kill-same-subject (&optional unmark)
7601   "Mark articles which has the same subject as read.
7602 If UNMARK is positive, remove any kind of mark.
7603 If UNMARK is negative, tick articles."
7604   (interactive "P")
7605   (when unmark
7606     (setq unmark (prefix-numeric-value unmark)))
7607   (let ((count
7608          (gnus-summary-mark-same-subject
7609           (gnus-summary-article-subject) unmark)))
7610     ;; If marked as read, go to next unread subject.
7611     (when (null unmark)
7612       ;; Go to next unread subject.
7613       (gnus-summary-next-subject 1 t))
7614     (gnus-message 7 "%d articles are marked as %s"
7615                   count (if unmark "unread" "read"))))
7616
7617 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7618   "Mark articles with same SUBJECT as read, and return marked number.
7619 If optional argument UNMARK is positive, remove any kinds of marks.
7620 If optional argument UNMARK is negative, mark articles as unread instead."
7621   (let ((count 1))
7622     (save-excursion
7623       (cond
7624        ((null unmark)                   ; Mark as read.
7625         (while (and
7626                 (progn
7627                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7628                   (gnus-summary-show-thread) t)
7629                 (gnus-summary-find-subject subject))
7630           (setq count (1+ count))))
7631        ((> unmark 0)                    ; Tick.
7632         (while (and
7633                 (progn
7634                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7635                   (gnus-summary-show-thread) t)
7636                 (gnus-summary-find-subject subject))
7637           (setq count (1+ count))))
7638        (t                               ; Mark as unread.
7639         (while (and
7640                 (progn
7641                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7642                   (gnus-summary-show-thread) t)
7643                 (gnus-summary-find-subject subject))
7644           (setq count (1+ count)))))
7645       (gnus-set-mode-line 'summary)
7646       ;; Return the number of marked articles.
7647       count)))
7648
7649 (defun gnus-summary-mark-as-processable (n &optional unmark)
7650   "Set the process mark on the next N articles.
7651 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7652 the process mark instead.  The difference between N and the actual
7653 number of articles marked is returned."
7654   (interactive "p")
7655   (let ((backward (< n 0))
7656         (n (abs n)))
7657     (while (and
7658             (> n 0)
7659             (if unmark
7660                 (gnus-summary-remove-process-mark
7661                  (gnus-summary-article-number))
7662               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7663             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7664       (setq n (1- n)))
7665     (when (/= 0 n)
7666       (gnus-message 7 "No more articles"))
7667     (gnus-summary-recenter)
7668     (gnus-summary-position-point)
7669     n))
7670
7671 (defun gnus-summary-unmark-as-processable (n)
7672   "Remove the process mark from the next N articles.
7673 If N is negative, unmark backward instead.  The difference between N and
7674 the actual number of articles unmarked is returned."
7675   (interactive "p")
7676   (gnus-summary-mark-as-processable n t))
7677
7678 (defun gnus-summary-unmark-all-processable ()
7679   "Remove the process mark from all articles."
7680   (interactive)
7681   (save-excursion
7682     (while gnus-newsgroup-processable
7683       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7684   (gnus-summary-position-point))
7685
7686 (defun gnus-summary-mark-as-expirable (n)
7687   "Mark N articles forward as expirable.
7688 If N is negative, mark backward instead.  The difference between N and
7689 the actual number of articles marked is returned."
7690   (interactive "p")
7691   (gnus-summary-mark-forward n gnus-expirable-mark))
7692
7693 (defun gnus-summary-mark-article-as-replied (article)
7694   "Mark ARTICLE replied and update the summary line."
7695   (push article gnus-newsgroup-replied)
7696   (let ((buffer-read-only nil))
7697     (when (gnus-summary-goto-subject article nil t)
7698       (gnus-summary-update-secondary-mark article))))
7699
7700 (defun gnus-summary-set-bookmark (article)
7701   "Set a bookmark in current article."
7702   (interactive (list (gnus-summary-article-number)))
7703   (when (or (not (get-buffer gnus-article-buffer))
7704             (not gnus-current-article)
7705             (not gnus-article-current)
7706             (not (equal gnus-newsgroup-name (car gnus-article-current))))
7707     (error "No current article selected"))
7708   ;; Remove old bookmark, if one exists.
7709   (let ((old (assq article gnus-newsgroup-bookmarks)))
7710     (when old
7711       (setq gnus-newsgroup-bookmarks
7712             (delq old gnus-newsgroup-bookmarks))))
7713   ;; Set the new bookmark, which is on the form
7714   ;; (article-number . line-number-in-body).
7715   (push
7716    (cons article
7717          (save-excursion
7718            (set-buffer gnus-article-buffer)
7719            (count-lines
7720             (min (point)
7721                  (save-excursion
7722                    (goto-char (point-min))
7723                    (search-forward "\n\n" nil t)
7724                    (point)))
7725             (point))))
7726    gnus-newsgroup-bookmarks)
7727   (gnus-message 6 "A bookmark has been added to the current article."))
7728
7729 (defun gnus-summary-remove-bookmark (article)
7730   "Remove the bookmark from the current article."
7731   (interactive (list (gnus-summary-article-number)))
7732   ;; Remove old bookmark, if one exists.
7733   (let ((old (assq article gnus-newsgroup-bookmarks)))
7734     (if old
7735         (progn
7736           (setq gnus-newsgroup-bookmarks
7737                 (delq old gnus-newsgroup-bookmarks))
7738           (gnus-message 6 "Removed bookmark."))
7739       (gnus-message 6 "No bookmark in current article."))))
7740
7741 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7742 (defun gnus-summary-mark-as-dormant (n)
7743   "Mark N articles forward as dormant.
7744 If N is negative, mark backward instead.  The difference between N and
7745 the actual number of articles marked is returned."
7746   (interactive "p")
7747   (gnus-summary-mark-forward n gnus-dormant-mark))
7748
7749 (defun gnus-summary-set-process-mark (article)
7750   "Set the process mark on ARTICLE and update the summary line."
7751   (setq gnus-newsgroup-processable
7752         (cons article
7753               (delq article gnus-newsgroup-processable)))
7754   (when (gnus-summary-goto-subject article)
7755     (gnus-summary-show-thread)
7756     (gnus-summary-goto-subject article)
7757     (gnus-summary-update-secondary-mark article)))
7758
7759 (defun gnus-summary-remove-process-mark (article)
7760   "Remove the process mark from ARTICLE and update the summary line."
7761   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
7762   (when (gnus-summary-goto-subject article)
7763     (gnus-summary-show-thread)
7764     (gnus-summary-goto-subject article)
7765     (gnus-summary-update-secondary-mark article)))
7766
7767 (defun gnus-summary-set-saved-mark (article)
7768   "Set the process mark on ARTICLE and update the summary line."
7769   (push article gnus-newsgroup-saved)
7770   (when (gnus-summary-goto-subject article)
7771     (gnus-summary-update-secondary-mark article)))
7772
7773 (defun gnus-summary-mark-forward (n &optional mark no-expire)
7774   "Mark N articles as read forwards.
7775 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
7776 The difference between N and the actual number of articles marked is
7777 returned."
7778   (interactive "p")
7779   (gnus-summary-show-thread)
7780   (let ((backward (< n 0))
7781         (gnus-summary-goto-unread
7782          (and gnus-summary-goto-unread
7783               (not (eq gnus-summary-goto-unread 'never))
7784               (not (memq mark (list gnus-unread-mark
7785                                     gnus-ticked-mark gnus-dormant-mark)))))
7786         (n (abs n))
7787         (mark (or mark gnus-del-mark)))
7788     (while (and (> n 0)
7789                 (gnus-summary-mark-article nil mark no-expire)
7790                 (zerop (gnus-summary-next-subject
7791                         (if backward -1 1)
7792                         (and gnus-summary-goto-unread
7793                              (not (eq gnus-summary-goto-unread 'never)))
7794                         t)))
7795       (setq n (1- n)))
7796     (when (/= 0 n)
7797       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
7798     (gnus-summary-recenter)
7799     (gnus-summary-position-point)
7800     (gnus-set-mode-line 'summary)
7801     n))
7802
7803 (defun gnus-summary-mark-article-as-read (mark)
7804   "Mark the current article quickly as read with MARK."
7805   (let ((article (gnus-summary-article-number)))
7806     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7807     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7808     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7809     (push (cons article mark) gnus-newsgroup-reads)
7810     ;; Possibly remove from cache, if that is used.
7811     (when gnus-use-cache
7812       (gnus-cache-enter-remove-article article))
7813     ;; Allow the backend to change the mark.
7814     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7815     ;; Check for auto-expiry.
7816     (when (and gnus-newsgroup-auto-expire
7817                (memq mark gnus-auto-expirable-marks))
7818       (setq mark gnus-expirable-mark)
7819       ;; Let the backend know about the mark change.
7820       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7821       (push article gnus-newsgroup-expirable))
7822     ;; Set the mark in the buffer.
7823     (gnus-summary-update-mark mark 'unread)
7824     t))
7825
7826 (defun gnus-summary-mark-article-as-unread (mark)
7827   "Mark the current article quickly as unread with MARK."
7828   (let* ((article (gnus-summary-article-number))
7829          (old-mark (gnus-summary-article-mark article)))
7830     ;; Allow the backend to change the mark.
7831     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7832     (if (eq mark old-mark)
7833         t
7834       (if (<= article 0)
7835           (progn
7836             (gnus-error 1 "Can't mark negative article numbers")
7837             nil)
7838         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7839         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7840         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
7841         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
7842         (cond ((= mark gnus-ticked-mark)
7843                (push article gnus-newsgroup-marked))
7844               ((= mark gnus-dormant-mark)
7845                (push article gnus-newsgroup-dormant))
7846               (t
7847                (push article gnus-newsgroup-unreads)))
7848         (gnus-pull article gnus-newsgroup-reads)
7849
7850         ;; See whether the article is to be put in the cache.
7851         (and gnus-use-cache
7852              (vectorp (gnus-summary-article-header article))
7853              (save-excursion
7854                (gnus-cache-possibly-enter-article
7855                 gnus-newsgroup-name article
7856                 (gnus-summary-article-header article)
7857                 (= mark gnus-ticked-mark)
7858                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7859
7860         ;; Fix the mark.
7861         (gnus-summary-update-mark mark 'unread)
7862         t))))
7863
7864 (defun gnus-summary-mark-article (&optional article mark no-expire)
7865   "Mark ARTICLE with MARK.  MARK can be any character.
7866 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
7867 `??' (dormant) and `?E' (expirable).
7868 If MARK is nil, then the default character `?r' is used.
7869 If ARTICLE is nil, then the article on the current line will be
7870 marked."
7871   ;; The mark might be a string.
7872   (when (stringp mark)
7873     (setq mark (aref mark 0)))
7874   ;; If no mark is given, then we check auto-expiring.
7875   (when (null mark)
7876     (setq mark gnus-del-mark))
7877   (when (and (not no-expire)
7878              gnus-newsgroup-auto-expire
7879              (memq mark gnus-auto-expirable-marks))
7880     (setq mark gnus-expirable-mark))
7881   (let ((article (or article (gnus-summary-article-number)))
7882         (old-mark (gnus-summary-article-mark article)))
7883     ;; Allow the backend to change the mark.
7884     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7885     (if (eq mark old-mark)
7886         t
7887       (unless article
7888         (error "No article on current line"))
7889       (if (not (if (or (= mark gnus-unread-mark)
7890                        (= mark gnus-ticked-mark)
7891                        (= mark gnus-dormant-mark))
7892                    (gnus-mark-article-as-unread article mark)
7893                  (gnus-mark-article-as-read article mark)))
7894           t
7895         ;; See whether the article is to be put in the cache.
7896         (and gnus-use-cache
7897              (not (= mark gnus-canceled-mark))
7898              (vectorp (gnus-summary-article-header article))
7899              (save-excursion
7900                (gnus-cache-possibly-enter-article
7901                 gnus-newsgroup-name article
7902                 (gnus-summary-article-header article)
7903                 (= mark gnus-ticked-mark)
7904                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7905
7906         (when (gnus-summary-goto-subject article nil t)
7907           (let ((buffer-read-only nil))
7908             (gnus-summary-show-thread)
7909             ;; Fix the mark.
7910             (gnus-summary-update-mark mark 'unread)
7911             t))))))
7912
7913 (defun gnus-summary-update-secondary-mark (article)
7914   "Update the secondary (read, process, cache) mark."
7915   (gnus-summary-update-mark
7916    (cond ((memq article gnus-newsgroup-processable)
7917           gnus-process-mark)
7918          ((memq article gnus-newsgroup-cached)
7919           gnus-cached-mark)
7920          ((memq article gnus-newsgroup-replied)
7921           gnus-replied-mark)
7922          ((memq article gnus-newsgroup-saved)
7923           gnus-saved-mark)
7924          (t gnus-unread-mark))
7925    'replied)
7926   (when (gnus-visual-p 'summary-highlight 'highlight)
7927     (gnus-run-hooks 'gnus-summary-update-hook))
7928   t)
7929
7930 (defun gnus-summary-update-mark (mark type)
7931   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
7932         (buffer-read-only nil))
7933     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
7934     (when forward
7935       (when (looking-at "\r")
7936         (incf forward))
7937       (when (<= (+ forward (point)) (point-max))
7938         ;; Go to the right position on the line.
7939         (goto-char (+ forward (point)))
7940         ;; Replace the old mark with the new mark.
7941         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
7942         ;; Optionally update the marks by some user rule.
7943         (when (eq type 'unread)
7944           (gnus-data-set-mark
7945            (gnus-data-find (gnus-summary-article-number)) mark)
7946           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
7947
7948 (defun gnus-mark-article-as-read (article &optional mark)
7949   "Enter ARTICLE in the pertinent lists and remove it from others."
7950   ;; Make the article expirable.
7951   (let ((mark (or mark gnus-del-mark)))
7952     (if (= mark gnus-expirable-mark)
7953         (push article gnus-newsgroup-expirable)
7954       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
7955     ;; Remove from unread and marked lists.
7956     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7957     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7958     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7959     (push (cons article mark) gnus-newsgroup-reads)
7960     ;; Possibly remove from cache, if that is used.
7961     (when gnus-use-cache
7962       (gnus-cache-enter-remove-article article))
7963     t))
7964
7965 (defun gnus-mark-article-as-unread (article &optional mark)
7966   "Enter ARTICLE in the pertinent lists and remove it from others."
7967   (let ((mark (or mark gnus-ticked-mark)))
7968     (if (<= article 0)
7969         (progn
7970           (gnus-error 1 "Can't mark negative article numbers")
7971           nil)
7972       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
7973             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
7974             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
7975             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7976
7977       ;; Unsuppress duplicates?
7978       (when gnus-suppress-duplicates
7979         (gnus-dup-unsuppress-article article))
7980
7981       (cond ((= mark gnus-ticked-mark)
7982              (push article gnus-newsgroup-marked))
7983             ((= mark gnus-dormant-mark)
7984              (push article gnus-newsgroup-dormant))
7985             (t
7986              (push article gnus-newsgroup-unreads)))
7987       (gnus-pull article gnus-newsgroup-reads)
7988       t)))
7989
7990 (defalias 'gnus-summary-mark-as-unread-forward
7991   'gnus-summary-tick-article-forward)
7992 (make-obsolete 'gnus-summary-mark-as-unread-forward
7993                'gnus-summary-tick-article-forward)
7994 (defun gnus-summary-tick-article-forward (n)
7995   "Tick N articles forwards.
7996 If N is negative, tick backwards instead.
7997 The difference between N and the number of articles ticked is returned."
7998   (interactive "p")
7999   (gnus-summary-mark-forward n gnus-ticked-mark))
8000
8001 (defalias 'gnus-summary-mark-as-unread-backward
8002   'gnus-summary-tick-article-backward)
8003 (make-obsolete 'gnus-summary-mark-as-unread-backward
8004                'gnus-summary-tick-article-backward)
8005 (defun gnus-summary-tick-article-backward (n)
8006   "Tick N articles backwards.
8007 The difference between N and the number of articles ticked is returned."
8008   (interactive "p")
8009   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8010
8011 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8012 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8013 (defun gnus-summary-tick-article (&optional article clear-mark)
8014   "Mark current article as unread.
8015 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8016 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8017   (interactive)
8018   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8019                                        gnus-ticked-mark)))
8020
8021 (defun gnus-summary-mark-as-read-forward (n)
8022   "Mark N articles as read forwards.
8023 If N is negative, mark backwards instead.
8024 The difference between N and the actual number of articles marked is
8025 returned."
8026   (interactive "p")
8027   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8028
8029 (defun gnus-summary-mark-as-read-backward (n)
8030   "Mark the N articles as read backwards.
8031 The difference between N and the actual number of articles marked is
8032 returned."
8033   (interactive "p")
8034   (gnus-summary-mark-forward (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8035
8036 (defun gnus-summary-mark-as-read (&optional article mark)
8037   "Mark current article as read.
8038 ARTICLE specifies the article to be marked as read.
8039 MARK specifies a string to be inserted at the beginning of the line."
8040   (gnus-summary-mark-article article mark))
8041
8042 (defun gnus-summary-clear-mark-forward (n)
8043   "Clear marks from N articles forward.
8044 If N is negative, clear backward instead.
8045 The difference between N and the number of marks cleared is returned."
8046   (interactive "p")
8047   (gnus-summary-mark-forward n gnus-unread-mark))
8048
8049 (defun gnus-summary-clear-mark-backward (n)
8050   "Clear marks from N articles backward.
8051 The difference between N and the number of marks cleared is returned."
8052   (interactive "p")
8053   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8054
8055 (defun gnus-summary-mark-unread-as-read ()
8056   "Intended to be used by `gnus-summary-mark-article-hook'."
8057   (when (memq gnus-current-article gnus-newsgroup-unreads)
8058     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8059
8060 (defun gnus-summary-mark-read-and-unread-as-read ()
8061   "Intended to be used by `gnus-summary-mark-article-hook'."
8062   (let ((mark (gnus-summary-article-mark)))
8063     (when (or (gnus-unread-mark-p mark)
8064               (gnus-read-mark-p mark))
8065       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8066
8067 (defun gnus-summary-mark-region-as-read (point mark all)
8068   "Mark all unread articles between point and mark as read.
8069 If given a prefix, mark all articles between point and mark as read,
8070 even ticked and dormant ones."
8071   (interactive "r\nP")
8072   (save-excursion
8073     (let (article)
8074       (goto-char point)
8075       (beginning-of-line)
8076       (while (and
8077               (< (point) mark)
8078               (progn
8079                 (when (or all
8080                           (memq (setq article (gnus-summary-article-number))
8081                                 gnus-newsgroup-unreads))
8082                   (gnus-summary-mark-article article gnus-del-mark))
8083                 t)
8084               (gnus-summary-find-next))))))
8085
8086 (defun gnus-summary-mark-below (score mark)
8087   "Mark articles with score less than SCORE with MARK."
8088   (interactive "P\ncMark: ")
8089   (setq score (if score
8090                   (prefix-numeric-value score)
8091                 (or gnus-summary-default-score 0)))
8092   (save-excursion
8093     (set-buffer gnus-summary-buffer)
8094     (goto-char (point-min))
8095     (while
8096         (progn
8097           (and (< (gnus-summary-article-score) score)
8098                (gnus-summary-mark-article nil mark))
8099           (gnus-summary-find-next)))))
8100
8101 (defun gnus-summary-kill-below (&optional score)
8102   "Mark articles with score below SCORE as read."
8103   (interactive "P")
8104   (gnus-summary-mark-below score gnus-killed-mark))
8105
8106 (defun gnus-summary-clear-above (&optional score)
8107   "Clear all marks from articles with score above SCORE."
8108   (interactive "P")
8109   (gnus-summary-mark-above score gnus-unread-mark))
8110
8111 (defun gnus-summary-tick-above (&optional score)
8112   "Tick all articles with score above SCORE."
8113   (interactive "P")
8114   (gnus-summary-mark-above score gnus-ticked-mark))
8115
8116 (defun gnus-summary-mark-above (score mark)
8117   "Mark articles with score over SCORE with MARK."
8118   (interactive "P\ncMark: ")
8119   (setq score (if score
8120                   (prefix-numeric-value score)
8121                 (or gnus-summary-default-score 0)))
8122   (save-excursion
8123     (set-buffer gnus-summary-buffer)
8124     (goto-char (point-min))
8125     (while (and (progn
8126                   (when (> (gnus-summary-article-score) score)
8127                     (gnus-summary-mark-article nil mark))
8128                   t)
8129                 (gnus-summary-find-next)))))
8130
8131 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8132 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8133 (defun gnus-summary-limit-include-expunged (&optional no-error)
8134   "Display all the hidden articles that were expunged for low scores."
8135   (interactive)
8136   (let ((buffer-read-only nil))
8137     (let ((scored gnus-newsgroup-scored)
8138           headers h)
8139       (while scored
8140         (unless (gnus-summary-goto-subject (caar scored))
8141           (and (setq h (gnus-summary-article-header (caar scored)))
8142                (< (cdar scored) gnus-summary-expunge-below)
8143                (push h headers)))
8144         (setq scored (cdr scored)))
8145       (if (not headers)
8146           (when (not no-error)
8147             (error "No expunged articles hidden"))
8148         (goto-char (point-min))
8149         (gnus-summary-prepare-unthreaded (nreverse headers))
8150         (goto-char (point-min))
8151         (gnus-summary-position-point)
8152         t))))
8153
8154 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8155   "Mark all unread articles in this newsgroup as read.
8156 If prefix argument ALL is non-nil, ticked and dormant articles will
8157 also be marked as read.
8158 If QUIETLY is non-nil, no questions will be asked.
8159 If TO-HERE is non-nil, it should be a point in the buffer.  All
8160 articles before this point will be marked as read.
8161 Note that this function will only catch up the unread article
8162 in the current summary buffer limitation.
8163 The number of articles marked as read is returned."
8164   (interactive "P")
8165   (prog1
8166       (save-excursion
8167         (when (or quietly
8168                   (not gnus-interactive-catchup) ;Without confirmation?
8169                   gnus-expert-user
8170                   (gnus-y-or-n-p
8171                    (if all
8172                        "Mark absolutely all articles as read? "
8173                      "Mark all unread articles as read? ")))
8174           (if (and not-mark
8175                    (not gnus-newsgroup-adaptive)
8176                    (not gnus-newsgroup-auto-expire)
8177                    (not gnus-suppress-duplicates)
8178                    (or (not gnus-use-cache)
8179                        (eq gnus-use-cache 'passive)))
8180               (progn
8181                 (when all
8182                   (setq gnus-newsgroup-marked nil
8183                         gnus-newsgroup-dormant nil))
8184                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8185             ;; We actually mark all articles as canceled, which we
8186             ;; have to do when using auto-expiry or adaptive scoring.
8187             (gnus-summary-show-all-threads)
8188             (when (gnus-summary-first-subject (not all) t)
8189               (while (and
8190                       (if to-here (< (point) to-here) t)
8191                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8192                       (gnus-summary-find-next (not all) nil nil t))))
8193             (gnus-set-mode-line 'summary))
8194           t))
8195     (gnus-summary-position-point)))
8196
8197 (defun gnus-summary-catchup-to-here (&optional all)
8198   "Mark all unticked articles before the current one as read.
8199 If ALL is non-nil, also mark ticked and dormant articles as read."
8200   (interactive "P")
8201   (save-excursion
8202     (gnus-save-hidden-threads
8203       (let ((beg (point)))
8204         ;; We check that there are unread articles.
8205         (when (or all (gnus-summary-find-prev))
8206           (gnus-summary-catchup all t beg)))))
8207   (gnus-summary-position-point))
8208
8209 (defun gnus-summary-catchup-all (&optional quietly)
8210   "Mark all articles in this newsgroup as read."
8211   (interactive "P")
8212   (gnus-summary-catchup t quietly))
8213
8214 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8215   "Mark all articles not marked as unread in this newsgroup as read, then exit.
8216 If prefix argument ALL is non-nil, all articles are marked as read."
8217   (interactive "P")
8218   (when (gnus-summary-catchup all quietly nil 'fast)
8219     ;; Select next newsgroup or exit.
8220     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8221              (eq gnus-auto-select-next 'quietly))
8222         (gnus-summary-next-group nil)
8223       (gnus-summary-exit))))
8224
8225 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8226   "Mark all articles in this newsgroup as read, and then exit."
8227   (interactive "P")
8228   (gnus-summary-catchup-and-exit t quietly))
8229
8230 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
8231 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8232   "Mark all articles in this group as read and select the next group.
8233 If given a prefix, mark all articles, unread as well as ticked, as
8234 read."
8235   (interactive "P")
8236   (save-excursion
8237     (gnus-summary-catchup all))
8238   (gnus-summary-next-article t nil nil t))
8239
8240 ;; Thread-based commands.
8241
8242 (defun gnus-summary-articles-in-thread (&optional article)
8243   "Return a list of all articles in the current thread.
8244 If ARTICLE is non-nil, return all articles in the thread that starts
8245 with that article."
8246   (let* ((article (or article (gnus-summary-article-number)))
8247          (data (gnus-data-find-list article))
8248          (top-level (gnus-data-level (car data)))
8249          (top-subject
8250           (cond ((null gnus-thread-operation-ignore-subject)
8251                  (gnus-simplify-subject-re
8252                   (mail-header-subject (gnus-data-header (car data)))))
8253                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8254                  (gnus-simplify-subject-fuzzy
8255                   (mail-header-subject (gnus-data-header (car data)))))
8256                 (t nil)))
8257          (end-point (save-excursion
8258                       (if (gnus-summary-go-to-next-thread)
8259                           (point) (point-max))))
8260          articles)
8261     (while (and data
8262                 (< (gnus-data-pos (car data)) end-point))
8263       (when (or (not top-subject)
8264                 (string= top-subject
8265                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8266                              (gnus-simplify-subject-fuzzy
8267                               (mail-header-subject
8268                                (gnus-data-header (car data))))
8269                            (gnus-simplify-subject-re
8270                             (mail-header-subject
8271                              (gnus-data-header (car data)))))))
8272         (push (gnus-data-number (car data)) articles))
8273       (unless (and (setq data (cdr data))
8274                    (> (gnus-data-level (car data)) top-level))
8275         (setq data nil)))
8276     ;; Return the list of articles.
8277     (nreverse articles)))
8278
8279 (defun gnus-summary-rethread-current ()
8280   "Rethread the thread the current article is part of."
8281   (interactive)
8282   (let* ((gnus-show-threads t)
8283          (article (gnus-summary-article-number))
8284          (id (mail-header-id (gnus-summary-article-header)))
8285          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8286     (unless id
8287       (error "No article on the current line"))
8288     (gnus-rebuild-thread id)
8289     (gnus-summary-goto-subject article)))
8290
8291 (defun gnus-summary-reparent-thread ()
8292   "Make the current article child of the marked (or previous) article.
8293
8294 Note that the re-threading will only work if `gnus-thread-ignore-subject'
8295 is non-nil or the Subject: of both articles are the same."
8296   (interactive)
8297   (unless (not (gnus-group-read-only-p))
8298     (error "The current newsgroup does not support article editing"))
8299   (unless (<= (length gnus-newsgroup-processable) 1)
8300     (error "No more than one article may be marked"))
8301   (save-window-excursion
8302     (let ((gnus-article-buffer " *reparent*")
8303           (current-article (gnus-summary-article-number))
8304           ;; First grab the marked article, otherwise one line up.
8305           (parent-article (if (not (null gnus-newsgroup-processable))
8306                               (car gnus-newsgroup-processable)
8307                             (save-excursion
8308                               (if (eq (forward-line -1) 0)
8309                                   (gnus-summary-article-number)
8310                                 (error "Beginning of summary buffer"))))))
8311       (unless (not (eq current-article parent-article))
8312         (error "An article may not be self-referential"))
8313       (let ((message-id (mail-header-id
8314                          (gnus-summary-article-header parent-article))))
8315         (unless (and message-id (not (equal message-id "")))
8316           (error "No message-id in desired parent"))
8317         ;; We don't want the article to be marked as read.
8318         (let (gnus-mark-article-hook)
8319           (gnus-summary-select-article t t nil current-article))
8320         (set-buffer gnus-original-article-buffer)
8321         (let ((buf (format "%s" (buffer-string))))
8322           (with-temp-buffer
8323             (insert buf)
8324             (goto-char (point-min))
8325             (if (re-search-forward "^References: " nil t)
8326                 (progn
8327                   (re-search-forward "^[^ \t]" nil t)
8328                   (forward-line -1)
8329                   (end-of-line)
8330                   (insert " " message-id))
8331               (insert "References: " message-id "\n"))
8332             (unless (gnus-request-replace-article
8333                      current-article (car gnus-article-current)
8334                      (current-buffer))
8335               (error "Couldn't replace article"))))
8336         (set-buffer gnus-summary-buffer)
8337         (gnus-summary-unmark-all-processable)
8338         (gnus-summary-update-article current-article)
8339         (gnus-summary-rethread-current)
8340         (gnus-message 3 "Article %d is now the child of article %d"
8341                       current-article parent-article)))))
8342
8343 (defun gnus-summary-toggle-threads (&optional arg)
8344   "Toggle showing conversation threads.
8345 If ARG is positive number, turn showing conversation threads on."
8346   (interactive "P")
8347   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8348     (setq gnus-show-threads
8349           (if (null arg) (not gnus-show-threads)
8350             (> (prefix-numeric-value arg) 0)))
8351     (gnus-summary-prepare)
8352     (gnus-summary-goto-subject current)
8353     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8354     (gnus-summary-position-point)))
8355
8356 (defun gnus-summary-show-all-threads ()
8357   "Show all threads."
8358   (interactive)
8359   (save-excursion
8360     (let ((buffer-read-only nil))
8361       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8362   (gnus-summary-position-point))
8363
8364 (defun gnus-summary-show-thread ()
8365   "Show thread subtrees.
8366 Returns nil if no thread was there to be shown."
8367   (interactive)
8368   (let ((buffer-read-only nil)
8369         (orig (point))
8370         ;; first goto end then to beg, to have point at beg after let
8371         (end (progn (end-of-line) (point)))
8372         (beg (progn (beginning-of-line) (point))))
8373     (prog1
8374         ;; Any hidden lines here?
8375         (search-forward "\r" end t)
8376       (subst-char-in-region beg end ?\^M ?\n t)
8377       (goto-char orig)
8378       (gnus-summary-position-point))))
8379
8380 (defun gnus-summary-hide-all-threads ()
8381   "Hide all thread subtrees."
8382   (interactive)
8383   (save-excursion
8384     (goto-char (point-min))
8385     (gnus-summary-hide-thread)
8386     (while (zerop (gnus-summary-next-thread 1 t))
8387       (gnus-summary-hide-thread)))
8388   (gnus-summary-position-point))
8389
8390 (defun gnus-summary-hide-thread ()
8391   "Hide thread subtrees.
8392 Returns nil if no threads were there to be hidden."
8393   (interactive)
8394   (let ((buffer-read-only nil)
8395         (start (point))
8396         (article (gnus-summary-article-number)))
8397     (goto-char start)
8398     ;; Go forward until either the buffer ends or the subthread
8399     ;; ends.
8400     (when (and (not (eobp))
8401                (or (zerop (gnus-summary-next-thread 1 t))
8402                    (goto-char (point-max))))
8403       (prog1
8404           (if (and (> (point) start)
8405                    (search-backward "\n" start t))
8406               (progn
8407                 (subst-char-in-region start (point) ?\n ?\^M)
8408                 (gnus-summary-goto-subject article))
8409             (goto-char start)
8410             nil)
8411         ;;(gnus-summary-position-point)
8412         ))))
8413
8414 (defun gnus-summary-go-to-next-thread (&optional previous)
8415   "Go to the same level (or less) next thread.
8416 If PREVIOUS is non-nil, go to previous thread instead.
8417 Return the article number moved to, or nil if moving was impossible."
8418   (let ((level (gnus-summary-thread-level))
8419         (way (if previous -1 1))
8420         (beg (point)))
8421     (forward-line way)
8422     (while (and (not (eobp))
8423                 (< level (gnus-summary-thread-level)))
8424       (forward-line way))
8425     (if (eobp)
8426         (progn
8427           (goto-char beg)
8428           nil)
8429       (setq beg (point))
8430       (prog1
8431           (gnus-summary-article-number)
8432         (goto-char beg)))))
8433
8434 (defun gnus-summary-next-thread (n &optional silent)
8435   "Go to the same level next N'th thread.
8436 If N is negative, search backward instead.
8437 Returns the difference between N and the number of skips actually
8438 done.
8439
8440 If SILENT, don't output messages."
8441   (interactive "p")
8442   (let ((backward (< n 0))
8443         (n (abs n)))
8444     (while (and (> n 0)
8445                 (gnus-summary-go-to-next-thread backward))
8446       (decf n))
8447     (unless silent
8448       (gnus-summary-position-point))
8449     (when (and (not silent) (/= 0 n))
8450       (gnus-message 7 "No more threads"))
8451     n))
8452
8453 (defun gnus-summary-prev-thread (n)
8454   "Go to the same level previous N'th thread.
8455 Returns the difference between N and the number of skips actually
8456 done."
8457   (interactive "p")
8458   (gnus-summary-next-thread (- n)))
8459
8460 (defun gnus-summary-go-down-thread ()
8461   "Go down one level in the current thread."
8462   (let ((children (gnus-summary-article-children)))
8463     (when children
8464       (gnus-summary-goto-subject (car children)))))
8465
8466 (defun gnus-summary-go-up-thread ()
8467   "Go up one level in the current thread."
8468   (let ((parent (gnus-summary-article-parent)))
8469     (when parent
8470       (gnus-summary-goto-subject parent))))
8471
8472 (defun gnus-summary-down-thread (n)
8473   "Go down thread N steps.
8474 If N is negative, go up instead.
8475 Returns the difference between N and how many steps down that were
8476 taken."
8477   (interactive "p")
8478   (let ((up (< n 0))
8479         (n (abs n)))
8480     (while (and (> n 0)
8481                 (if up (gnus-summary-go-up-thread)
8482                   (gnus-summary-go-down-thread)))
8483       (setq n (1- n)))
8484     (gnus-summary-position-point)
8485     (when (/= 0 n)
8486       (gnus-message 7 "Can't go further"))
8487     n))
8488
8489 (defun gnus-summary-up-thread (n)
8490   "Go up thread N steps.
8491 If N is negative, go up instead.
8492 Returns the difference between N and how many steps down that were
8493 taken."
8494   (interactive "p")
8495   (gnus-summary-down-thread (- n)))
8496
8497 (defun gnus-summary-top-thread ()
8498   "Go to the top of the thread."
8499   (interactive)
8500   (while (gnus-summary-go-up-thread))
8501   (gnus-summary-article-number))
8502
8503 (defun gnus-summary-kill-thread (&optional unmark)
8504   "Mark articles under current thread as read.
8505 If the prefix argument is positive, remove any kinds of marks.
8506 If the prefix argument is negative, tick articles instead."
8507   (interactive "P")
8508   (when unmark
8509     (setq unmark (prefix-numeric-value unmark)))
8510   (let ((articles (gnus-summary-articles-in-thread)))
8511     (save-excursion
8512       ;; Expand the thread.
8513       (gnus-summary-show-thread)
8514       ;; Mark all the articles.
8515       (while articles
8516         (gnus-summary-goto-subject (car articles))
8517         (cond ((null unmark)
8518                (gnus-summary-mark-article-as-read gnus-killed-mark))
8519               ((> unmark 0)
8520                (gnus-summary-mark-article-as-unread gnus-unread-mark))
8521               (t
8522                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8523         (setq articles (cdr articles))))
8524     ;; Hide killed subtrees.
8525     (and (null unmark)
8526          gnus-thread-hide-killed
8527          (gnus-summary-hide-thread))
8528     ;; If marked as read, go to next unread subject.
8529     (when (null unmark)
8530       ;; Go to next unread subject.
8531       (gnus-summary-next-subject 1 t)))
8532   (gnus-set-mode-line 'summary))
8533
8534 ;; Summary sorting commands
8535
8536 (defun gnus-summary-sort-by-number (&optional reverse)
8537   "Sort the summary buffer by article number.
8538 Argument REVERSE means reverse order."
8539   (interactive "P")
8540   (gnus-summary-sort 'number reverse))
8541
8542 (defun gnus-summary-sort-by-author (&optional reverse)
8543   "Sort the summary buffer by author name alphabetically.
8544 If case-fold-search is non-nil, case of letters is ignored.
8545 Argument REVERSE means reverse order."
8546   (interactive "P")
8547   (gnus-summary-sort 'author reverse))
8548
8549 (defun gnus-summary-sort-by-subject (&optional reverse)
8550   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
8551 If case-fold-search is non-nil, case of letters is ignored.
8552 Argument REVERSE means reverse order."
8553   (interactive "P")
8554   (gnus-summary-sort 'subject reverse))
8555
8556 (defun gnus-summary-sort-by-date (&optional reverse)
8557   "Sort the summary buffer by date.
8558 Argument REVERSE means reverse order."
8559   (interactive "P")
8560   (gnus-summary-sort 'date reverse))
8561
8562 (defun gnus-summary-sort-by-score (&optional reverse)
8563   "Sort the summary buffer by score.
8564 Argument REVERSE means reverse order."
8565   (interactive "P")
8566   (gnus-summary-sort 'score reverse))
8567
8568 (defun gnus-summary-sort-by-lines (&optional reverse)
8569   "Sort the summary buffer by article length.
8570 Argument REVERSE means reverse order."
8571   (interactive "P")
8572   (gnus-summary-sort 'lines reverse))
8573
8574 (defun gnus-summary-sort (predicate reverse)
8575   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8576   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8577          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8578          (gnus-thread-sort-functions
8579           (if (not reverse)
8580               thread
8581             `(lambda (t1 t2)
8582                (,thread t2 t1))))
8583          (gnus-article-sort-functions
8584           (if (not reverse)
8585               article
8586             `(lambda (t1 t2)
8587                (,article t2 t1))))
8588          (buffer-read-only)
8589          (gnus-summary-prepare-hook nil))
8590     ;; We do the sorting by regenerating the threads.
8591     (gnus-summary-prepare)
8592     ;; Hide subthreads if needed.
8593     (when (and gnus-show-threads gnus-thread-hide-subtree)
8594       (gnus-summary-hide-all-threads))))
8595
8596 ;; Summary saving commands.
8597
8598 (defun gnus-summary-save-article (&optional n not-saved)
8599   "Save the current article using the default saver function.
8600 If N is a positive number, save the N next articles.
8601 If N is a negative number, save the N previous articles.
8602 If N is nil and any articles have been marked with the process mark,
8603 save those articles instead.
8604 The variable `gnus-default-article-saver' specifies the saver function."
8605   (interactive "P")
8606   (let* ((articles (gnus-summary-work-articles n))
8607          (save-buffer (save-excursion
8608                         (nnheader-set-temp-buffer " *Gnus Save*")))
8609          (num (length articles))
8610          header article file)
8611     (while articles
8612       (setq header (gnus-summary-article-header
8613                     (setq article (pop articles))))
8614       (if (not (vectorp header))
8615           ;; This is a pseudo-article.
8616           (if (assq 'name header)
8617               (gnus-copy-file (cdr (assq 'name header)))
8618             (gnus-message 1 "Article %d is unsaveable" article))
8619         ;; This is a real article.
8620         (save-window-excursion
8621           (gnus-summary-select-article t nil nil article))
8622         (save-excursion
8623           (set-buffer save-buffer)
8624           (erase-buffer)
8625           (insert-buffer-substring gnus-original-article-buffer))
8626         (setq file (gnus-article-save save-buffer file num))
8627         (gnus-summary-remove-process-mark article)
8628         (unless not-saved
8629           (gnus-summary-set-saved-mark article))))
8630     (gnus-kill-buffer save-buffer)
8631     (gnus-summary-position-point)
8632     (gnus-set-mode-line 'summary)
8633     n))
8634
8635 (defun gnus-summary-pipe-output (&optional arg)
8636   "Pipe the current article to a subprocess.
8637 If N is a positive number, pipe the N next articles.
8638 If N is a negative number, pipe the N previous articles.
8639 If N is nil and any articles have been marked with the process mark,
8640 pipe those articles instead."
8641   (interactive "P")
8642   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8643     (gnus-summary-save-article arg t))
8644   (gnus-configure-windows 'pipe))
8645
8646 (defun gnus-summary-save-article-mail (&optional arg)
8647   "Append the current article to an mail file.
8648 If N is a positive number, save the N next articles.
8649 If N is a negative number, save the N previous articles.
8650 If N is nil and any articles have been marked with the process mark,
8651 save those articles instead."
8652   (interactive "P")
8653   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8654     (gnus-summary-save-article arg)))
8655
8656 (defun gnus-summary-save-article-rmail (&optional arg)
8657   "Append the current article to an rmail file.
8658 If N is a positive number, save the N next articles.
8659 If N is a negative number, save the N previous articles.
8660 If N is nil and any articles have been marked with the process mark,
8661 save those articles instead."
8662   (interactive "P")
8663   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
8664     (gnus-summary-save-article arg)))
8665
8666 (defun gnus-summary-save-article-file (&optional arg)
8667   "Append the current article to a file.
8668 If N is a positive number, save the N next articles.
8669 If N is a negative number, save the N previous articles.
8670 If N is nil and any articles have been marked with the process mark,
8671 save those articles instead."
8672   (interactive "P")
8673   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8674     (gnus-summary-save-article arg)))
8675
8676 (defun gnus-summary-write-article-file (&optional arg)
8677   "Write the current article to a file, deleting the previous file.
8678 If N is a positive number, save the N next articles.
8679 If N is a negative number, save the N previous articles.
8680 If N is nil and any articles have been marked with the process mark,
8681 save those articles instead."
8682   (interactive "P")
8683   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8684     (gnus-summary-save-article arg)))
8685
8686 (defun gnus-summary-save-article-body-file (&optional arg)
8687   "Append the current article body to a file.
8688 If N is a positive number, save the N next articles.
8689 If N is a negative number, save the N previous articles.
8690 If N is nil and any articles have been marked with the process mark,
8691 save those articles instead."
8692   (interactive "P")
8693   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8694     (gnus-summary-save-article arg)))
8695
8696 (defun gnus-summary-pipe-message (program)
8697   "Pipe the current article through PROGRAM."
8698   (interactive "sProgram: ")
8699   (gnus-summary-select-article)
8700   (let ((mail-header-separator ""))
8701     (gnus-eval-in-buffer-window gnus-article-buffer
8702       (save-restriction
8703         (widen)
8704         (let ((start (window-start))
8705               buffer-read-only)
8706           (message-pipe-buffer-body program)
8707           (set-window-start (get-buffer-window (current-buffer)) start))))))
8708
8709 (defun gnus-get-split-value (methods)
8710   "Return a value based on the split METHODS."
8711   (let (split-name method result match)
8712     (when methods
8713       (save-excursion
8714         (set-buffer gnus-original-article-buffer)
8715         (save-restriction
8716           (nnheader-narrow-to-headers)
8717           (while methods
8718             (goto-char (point-min))
8719             (setq method (pop methods))
8720             (setq match (car method))
8721             (when (cond
8722                    ((stringp match)
8723                     ;; Regular expression.
8724                     (ignore-errors
8725                       (re-search-forward match nil t)))
8726                    ((gnus-functionp match)
8727                     ;; Function.
8728                     (save-restriction
8729                       (widen)
8730                       (setq result (funcall match gnus-newsgroup-name))))
8731                    ((consp match)
8732                     ;; Form.
8733                     (save-restriction
8734                       (widen)
8735                       (setq result (eval match)))))
8736               (setq split-name (append (cdr method) split-name))
8737               (cond ((stringp result)
8738                      (push (expand-file-name
8739                             result gnus-article-save-directory)
8740                            split-name))
8741                     ((consp result)
8742                      (setq split-name (append result split-name)))))))))
8743     split-name))
8744
8745 (defun gnus-valid-move-group-p (group)
8746   (and (boundp group)
8747        (symbol-name group)
8748        (symbol-value group)
8749        (memq 'respool
8750              (assoc (symbol-name
8751                      (car (gnus-find-method-for-group
8752                            (symbol-name group))))
8753                     gnus-valid-select-methods))))
8754
8755 (defun gnus-read-move-group-name (prompt default articles prefix)
8756   "Read a group name."
8757   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
8758          (minibuffer-confirm-incomplete nil) ; XEmacs
8759          (prom
8760           (format "%s %s to:"
8761                   prompt
8762                   (if (> (length articles) 1)
8763                       (format "these %d articles" (length articles))
8764                     "this article")))
8765          (to-newsgroup
8766           (cond
8767            ((null split-name)
8768             (gnus-completing-read default prom
8769                                   gnus-active-hashtb
8770                                   'gnus-valid-move-group-p
8771                                   nil prefix
8772                                   'gnus-group-history))
8773            ((= 1 (length split-name))
8774             (gnus-completing-read (car split-name) prom
8775                                   gnus-active-hashtb
8776                                   'gnus-valid-move-group-p
8777                                   nil nil
8778                                   'gnus-group-history))
8779            (t
8780             (gnus-completing-read nil prom
8781                                   (mapcar (lambda (el) (list el))
8782                                           (nreverse split-name))
8783                                   nil nil nil
8784                                   'gnus-group-history)))))
8785     (when to-newsgroup
8786       (if (or (string= to-newsgroup "")
8787               (string= to-newsgroup prefix))
8788           (setq to-newsgroup default))
8789       (unless to-newsgroup
8790         (error "No group name entered"))
8791       (or (gnus-active to-newsgroup)
8792           (gnus-activate-group to-newsgroup)
8793           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
8794                                      to-newsgroup))
8795               (or (and (gnus-request-create-group
8796                         to-newsgroup (gnus-group-name-to-method to-newsgroup))
8797                        (gnus-activate-group to-newsgroup nil nil
8798                                             (gnus-group-name-to-method
8799                                              to-newsgroup)))
8800                   (error "Couldn't create group %s" to-newsgroup)))
8801           (error "No such group: %s" to-newsgroup)))
8802     to-newsgroup))
8803
8804 ;; Summary extract commands
8805
8806 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
8807   (let ((buffer-read-only nil)
8808         (article (gnus-summary-article-number))
8809         after-article b e)
8810     (unless (gnus-summary-goto-subject article)
8811       (error "No such article: %d" article))
8812     (gnus-summary-position-point)
8813     ;; If all commands are to be bunched up on one line, we collect
8814     ;; them here.
8815     (unless gnus-view-pseudos-separately
8816       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
8817             files action)
8818         (while ps
8819           (setq action (cdr (assq 'action (car ps))))
8820           (setq files (list (cdr (assq 'name (car ps)))))
8821           (while (and ps (cdr ps)
8822                       (string= (or action "1")
8823                                (or (cdr (assq 'action (cadr ps))) "2")))
8824             (push (cdr (assq 'name (cadr ps))) files)
8825             (setcdr ps (cddr ps)))
8826           (when files
8827             (when (not (string-match "%s" action))
8828               (push " " files))
8829             (push " " files)
8830             (when (assq 'execute (car ps))
8831               (setcdr (assq 'execute (car ps))
8832                       (funcall (if (string-match "%s" action)
8833                                    'format 'concat)
8834                                action
8835                                (mapconcat
8836                                 (lambda (f)
8837                                   (if (equal f " ")
8838                                       f
8839                                     (gnus-quote-arg-for-sh-or-csh f)))
8840                                 files " ")))))
8841           (setq ps (cdr ps)))))
8842     (if (and gnus-view-pseudos (not not-view))
8843         (while pslist
8844           (when (assq 'execute (car pslist))
8845             (gnus-execute-command (cdr (assq 'execute (car pslist)))
8846                                   (eq gnus-view-pseudos 'not-confirm)))
8847           (setq pslist (cdr pslist)))
8848       (save-excursion
8849         (while pslist
8850           (setq after-article (or (cdr (assq 'article (car pslist)))
8851                                   (gnus-summary-article-number)))
8852           (gnus-summary-goto-subject after-article)
8853           (forward-line 1)
8854           (setq b (point))
8855           (insert "    " (file-name-nondirectory
8856                           (cdr (assq 'name (car pslist))))
8857                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
8858           (setq e (point))
8859           (forward-line -1)             ; back to `b'
8860           (gnus-add-text-properties
8861            b (1- e) (list 'gnus-number gnus-reffed-article-number
8862                           gnus-mouse-face-prop gnus-mouse-face))
8863           (gnus-data-enter
8864            after-article gnus-reffed-article-number
8865            gnus-unread-mark b (car pslist) 0 (- e b))
8866           (push gnus-reffed-article-number gnus-newsgroup-unreads)
8867           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
8868           (setq pslist (cdr pslist)))))))
8869
8870 (defun gnus-pseudos< (p1 p2)
8871   (let ((c1 (cdr (assq 'action p1)))
8872         (c2 (cdr (assq 'action p2))))
8873     (and c1 c2 (string< c1 c2))))
8874
8875 (defun gnus-request-pseudo-article (props)
8876   (cond ((assq 'execute props)
8877          (gnus-execute-command (cdr (assq 'execute props)))))
8878   (let ((gnus-current-article (gnus-summary-article-number)))
8879     (gnus-run-hooks 'gnus-mark-article-hook)))
8880
8881 (defun gnus-execute-command (command &optional automatic)
8882   (save-excursion
8883     (gnus-article-setup-buffer)
8884     (set-buffer gnus-article-buffer)
8885     (setq buffer-read-only nil)
8886     (let ((command (if automatic command
8887                      (read-string "Command: " (cons command 0)))))
8888       (erase-buffer)
8889       (insert "$ " command "\n\n")
8890       (if gnus-view-pseudo-asynchronously
8891           (start-process "gnus-execute" (current-buffer) shell-file-name
8892                          shell-command-switch command)
8893         (call-process shell-file-name nil t nil
8894                       shell-command-switch command)))))
8895
8896 ;; Summary kill commands.
8897
8898 (defun gnus-summary-edit-global-kill (article)
8899   "Edit the \"global\" kill file."
8900   (interactive (list (gnus-summary-article-number)))
8901   (gnus-group-edit-global-kill article))
8902
8903 (defun gnus-summary-edit-local-kill ()
8904   "Edit a local kill file applied to the current newsgroup."
8905   (interactive)
8906   (setq gnus-current-headers (gnus-summary-article-header))
8907   (gnus-group-edit-local-kill
8908    (gnus-summary-article-number) gnus-newsgroup-name))
8909
8910 ;;; Header reading.
8911
8912 (defun gnus-read-header (id &optional header)
8913   "Read the headers of article ID and enter them into the Gnus system."
8914   (let ((group gnus-newsgroup-name)
8915         (gnus-override-method
8916          (and (gnus-news-group-p gnus-newsgroup-name)
8917               gnus-refer-article-method))
8918         where)
8919     ;; First we check to see whether the header in question is already
8920     ;; fetched.
8921     (if (stringp id)
8922         ;; This is a Message-ID.
8923         (setq header (or header (gnus-id-to-header id)))
8924       ;; This is an article number.
8925       (setq header (or header (gnus-summary-article-header id))))
8926     (if (and header
8927              (not (gnus-summary-article-sparse-p (mail-header-number header))))
8928         ;; We have found the header.
8929         header
8930       ;; If this is a sparse article, we have to nix out its
8931       ;; previous entry in the thread hashtb.
8932       (when (and header
8933                  (gnus-summary-article-sparse-p (mail-header-number header)))
8934         (let* ((parent (gnus-parent-id (mail-header-references header)))
8935                (thread (and parent (gnus-id-to-thread parent))))
8936           (when thread
8937             (delq (assq header thread) thread))))
8938       ;; We have to really fetch the header to this article.
8939       (save-excursion
8940         (set-buffer nntp-server-buffer)
8941         (when (setq where (gnus-request-head id group))
8942           (nnheader-fold-continuation-lines)
8943           (goto-char (point-max))
8944           (insert ".\n")
8945           (goto-char (point-min))
8946           (insert "211 ")
8947           (princ (cond
8948                   ((numberp id) id)
8949                   ((cdr where) (cdr where))
8950                   (header (mail-header-number header))
8951                   (t gnus-reffed-article-number))
8952                  (current-buffer))
8953           (insert " Article retrieved.\n"))
8954         (if (or (not where)
8955                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
8956             ()                          ; Malformed head.
8957           (unless (gnus-summary-article-sparse-p (mail-header-number header))
8958             (when (and (stringp id)
8959                        (not (string= (gnus-group-real-name group)
8960                                      (car where))))
8961               ;; If we fetched by Message-ID and the article came
8962               ;; from a different group, we fudge some bogus article
8963               ;; numbers for this article.
8964               (mail-header-set-number header gnus-reffed-article-number))
8965             (save-excursion
8966               (set-buffer gnus-summary-buffer)
8967               (decf gnus-reffed-article-number)
8968               (gnus-remove-header (mail-header-number header))
8969               (push header gnus-newsgroup-headers)
8970               (setq gnus-current-headers header)
8971               (push (mail-header-number header) gnus-newsgroup-limit)))
8972           header)))))
8973
8974 (defun gnus-remove-header (number)
8975   "Remove header NUMBER from `gnus-newsgroup-headers'."
8976   (if (and gnus-newsgroup-headers
8977            (= number (mail-header-number (car gnus-newsgroup-headers))))
8978       (pop gnus-newsgroup-headers)
8979     (let ((headers gnus-newsgroup-headers))
8980       (while (and (cdr headers)
8981                   (not (= number (mail-header-number (cadr headers)))))
8982         (pop headers))
8983       (when (cdr headers)
8984         (setcdr headers (cddr headers))))))
8985
8986 ;;;
8987 ;;; summary highlights
8988 ;;;
8989
8990 (defun gnus-highlight-selected-summary ()
8991   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
8992   ;; Highlight selected article in summary buffer
8993   (when gnus-summary-selected-face
8994     (save-excursion
8995       (let* ((beg (progn (beginning-of-line) (point)))
8996              (end (progn (end-of-line) (point)))
8997              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
8998              (from (if (get-text-property beg gnus-mouse-face-prop)
8999                        beg
9000                      (or (next-single-property-change
9001                           beg gnus-mouse-face-prop nil end)
9002                          beg)))
9003              (to
9004               (if (= from end)
9005                   (- from 2)
9006                 (or (next-single-property-change
9007                      from gnus-mouse-face-prop nil end)
9008                     end))))
9009         ;; If no mouse-face prop on line we will have to = from = end,
9010         ;; so we highlight the entire line instead.
9011         (when (= (+ to 2) from)
9012           (setq from beg)
9013           (setq to end))
9014         (if gnus-newsgroup-selected-overlay
9015             ;; Move old overlay.
9016             (gnus-move-overlay
9017              gnus-newsgroup-selected-overlay from to (current-buffer))
9018           ;; Create new overlay.
9019           (gnus-overlay-put
9020            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9021            'face gnus-summary-selected-face))))))
9022
9023 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9024 (defun gnus-summary-highlight-line ()
9025   "Highlight current line according to `gnus-summary-highlight'."
9026   (let* ((list gnus-summary-highlight)
9027          (p (point))
9028          (end (progn (end-of-line) (point)))
9029          ;; now find out where the line starts and leave point there.
9030          (beg (progn (beginning-of-line) (point)))
9031          (article (gnus-summary-article-number))
9032          (score (or (cdr (assq (or article gnus-current-article)
9033                                gnus-newsgroup-scored))
9034                     gnus-summary-default-score 0))
9035          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9036          (inhibit-read-only t))
9037     ;; Eval the cars of the lists until we find a match.
9038     (let ((default gnus-summary-default-score))
9039       (while (and list
9040                   (not (eval (caar list))))
9041         (setq list (cdr list))))
9042     (let ((face (cdar list)))
9043       (unless (eq face (get-text-property beg 'face))
9044         (gnus-put-text-property-excluding-characters-with-faces
9045          beg end 'face
9046          (setq face (if (boundp face) (symbol-value face) face)))
9047         (when gnus-summary-highlight-line-function
9048           (funcall gnus-summary-highlight-line-function article face))))
9049     (goto-char p)))
9050
9051 (defun gnus-update-read-articles (group unread &optional compute)
9052   "Update the list of read articles in GROUP."
9053   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9054          (entry (gnus-gethash group gnus-newsrc-hashtb))
9055          (info (nth 2 entry))
9056          (prev 1)
9057          (unread (sort (copy-sequence unread) '<))
9058          read)
9059     (if (or (not info) (not active))
9060         ;; There is no info on this group if it was, in fact,
9061         ;; killed.  Gnus stores no information on killed groups, so
9062         ;; there's nothing to be done.
9063         ;; One could store the information somewhere temporarily,
9064         ;; perhaps...  Hmmm...
9065         ()
9066       ;; Remove any negative articles numbers.
9067       (while (and unread (< (car unread) 0))
9068         (setq unread (cdr unread)))
9069       ;; Remove any expired article numbers
9070       (while (and unread (< (car unread) (car active)))
9071         (setq unread (cdr unread)))
9072       ;; Compute the ranges of read articles by looking at the list of
9073       ;; unread articles.
9074       (while unread
9075         (when (/= (car unread) prev)
9076           (push (if (= prev (1- (car unread))) prev
9077                   (cons prev (1- (car unread))))
9078                 read))
9079         (setq prev (1+ (car unread)))
9080         (setq unread (cdr unread)))
9081       (when (<= prev (cdr active))
9082         (push (cons prev (cdr active)) read))
9083       (setq read (if (> (length read) 1) (nreverse read) read))
9084       (if compute
9085           read
9086         (save-excursion
9087           (set-buffer gnus-group-buffer)
9088           (gnus-undo-register
9089             `(progn
9090                (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9091                (gnus-info-set-read ',info ',(gnus-info-read info))
9092                (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
9093                (gnus-group-update-group ,group t))))
9094         ;; Enter this list into the group info.
9095         (gnus-info-set-read info read)
9096         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9097         (gnus-get-unread-articles-in-group info (gnus-active group))
9098         t))))
9099
9100 (defun gnus-offer-save-summaries ()
9101   "Offer to save all active summary buffers."
9102   (save-excursion
9103     (let ((buflist (buffer-list))
9104           buffers bufname)
9105       ;; Go through all buffers and find all summaries.
9106       (while buflist
9107         (and (setq bufname (buffer-name (car buflist)))
9108              (string-match "Summary" bufname)
9109              (save-excursion
9110                (set-buffer bufname)
9111                ;; We check that this is, indeed, a summary buffer.
9112                (and (eq major-mode 'gnus-summary-mode)
9113                     ;; Also make sure this isn't bogus.
9114                     gnus-newsgroup-prepared
9115                     ;; Also make sure that this isn't a dead summary buffer.
9116                     (not gnus-dead-summary-mode)))
9117              (push bufname buffers))
9118         (setq buflist (cdr buflist)))
9119       ;; Go through all these summary buffers and offer to save them.
9120       (when buffers
9121         (map-y-or-n-p
9122          "Update summary buffer %s? "
9123          (lambda (buf)
9124            (switch-to-buffer buf)
9125            (gnus-summary-exit))
9126          buffers)))))
9127
9128
9129 ;;; @ for mime-partial
9130 ;;;
9131
9132 (defun gnus-request-partial-message ()
9133   (save-excursion
9134     (let ((number (gnus-summary-article-number))
9135           (group gnus-newsgroup-name)
9136           (mother gnus-article-buffer))
9137       (set-buffer (get-buffer-create " *Partial Article*"))
9138       (erase-buffer)
9139       (setq mime-preview-buffer mother)
9140       (gnus-request-article-this-buffer number group)
9141       (mime-parse-buffer)
9142       )))
9143
9144 (autoload 'mime-combine-message/partial-pieces-automatically
9145   "mime-partial"
9146   "Internal method to combine message/partial messages automatically.")
9147
9148 (mime-add-condition
9149  'action '((type . message)(subtype . partial)
9150            (major-mode . gnus-original-article-mode)
9151            (method . mime-combine-message/partial-pieces-automatically)
9152            (summary-buffer-exp . gnus-summary-buffer)
9153            (request-partial-message-method . gnus-request-partial-message)
9154            ))
9155
9156
9157 ;;; @ end
9158 ;;;
9159
9160 (defun gnus-newsgroup-setup-coding-system ()
9161   "Setup newsgroup default coding system."
9162   (setq gnus-newsgroup-coding-system
9163         (or (and gnus-newsgroup-name
9164                  (or (gnus-group-find-parameter
9165                       gnus-newsgroup-name 'charset)
9166                      (let ((alist gnus-newsgroup-coding-system-alist) 
9167                            elem (charset nil))
9168                        (while alist
9169                          (if (string-match 
9170                               (car (setq elem (pop alist)))
9171                               gnus-newsgroup-name)
9172                              (setq alist nil
9173                                    charset (cdr elem))))
9174                        charset)))
9175             rfc2047-default-charset))
9176   (setq gnus-newsgroup-iso-8859-1-forced 
9177         (and gnus-newsgroup-name
9178              (or (gnus-group-find-parameter
9179                   gnus-newsgroup-name 'iso-8859-1-forced)
9180                  (string-match  gnus-newsgroup-iso-8859-1-forced-regexp 
9181                                 gnus-newsgroup-name))))
9182   (if (stringp gnus-newsgroup-coding-system)
9183       (setq gnus-newsgroup-coding-system
9184             (intern (downcase gnus-newsgroup-coding-system))))
9185   (setq gnus-newsgroup-iso-8859-1-forced
9186         (if (stringp gnus-newsgroup-iso-8859-1-forced)
9187             (intern (downcase gnus-newsgroup-iso-8859-1-forced))
9188           (and gnus-newsgroup-iso-8859-1-forced
9189                gnus-newsgroup-coding-system))))
9190
9191 ;;;
9192 ;;; MIME Commands
9193 ;;;
9194
9195 (defun gnus-summary-display-buttonized (&optional arg)
9196   "Display the current buffer fully MIME-buttonized."
9197   (interactive "P")
9198   (require 'gnus-art)
9199   (let ((gnus-unbuttonized-mime-types nil))
9200     (gnus-summary-show-article arg)))
9201     
9202 (gnus-ems-redefine)
9203
9204 (provide 'gnus-sum)
9205
9206 (run-hooks 'gnus-sum-load-hook)
9207
9208 ;;; gnus-sum.el ends here