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