*** 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
4162                   ;; been seen, so we ignore this one, except we add
4163                   ;; any additional Xrefs (in case the two articles
4164                   ;; came from different servers).
4165                   (progn
4166                     (mail-header-set-xref
4167                      (car (symbol-value id-dep))
4168                      (concat (or (mail-header-xref
4169                                   (car (symbol-value id-dep)))
4170                                  "")
4171                              (or (mail-header-xref header) "")))
4172                     (setq header nil))
4173                 (setcar (symbol-value id-dep) header))
4174             (set id-dep (list header)))
4175           (when  header
4176             (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
4177                 (setcdr (symbol-value ref-dep)
4178                         (nconc (cdr (symbol-value ref-dep))
4179                                (list (symbol-value id-dep))))
4180               (set ref-dep (list nil (symbol-value id-dep))))
4181             (push header headers))
4182           (goto-char (point-max))
4183           (widen))
4184         (nreverse headers)))))
4185
4186 ;; The following macros and functions were written by Felix Lee
4187 ;; <flee@cse.psu.edu>.
4188
4189 (defmacro gnus-nov-read-integer ()
4190   '(prog1
4191        (if (= (following-char) ?\t)
4192            0
4193          (let ((num (ignore-errors (read buffer))))
4194            (if (numberp num) num 0)))
4195      (unless (eobp)
4196        (forward-char 1))))
4197
4198 (defmacro gnus-nov-skip-field ()
4199   '(search-forward "\t" eol 'move))
4200
4201 (defmacro gnus-nov-field ()
4202   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
4203
4204 ;; (defvar gnus-nov-none-counter 0)
4205
4206 ;; This function has to be called with point after the article number
4207 ;; on the beginning of the line.
4208 (defun gnus-nov-parse-line (number dependencies &optional force-new)
4209   (let ((eol (gnus-point-at-eol))
4210         (buffer (current-buffer))
4211         header ref id id-dep ref-dep)
4212
4213     ;; overview: [num subject from date id refs chars lines misc]
4214     (unwind-protect
4215         (progn
4216           (narrow-to-region (point) eol)
4217           (unless (eobp)
4218             (forward-char))
4219
4220           (setq header
4221                 (vector
4222                  number                 ; number
4223                  (gnus-nov-field)       ; subject
4224                  (gnus-nov-field)       ; from
4225                  (gnus-nov-field)       ; date
4226                  (setq id (or (gnus-nov-field)
4227                               (nnheader-generate-fake-message-id))) ; id
4228                  (progn
4229                    (let ((beg (point)))
4230                      (search-forward "\t" eol)
4231                      (if (search-backward ">" beg t)
4232                          (setq ref
4233                                (buffer-substring
4234                                 (1+ (point))
4235                                 (search-backward "<" beg t)))
4236                        (setq ref nil))
4237                      (goto-char beg))
4238                    (gnus-nov-field))    ; refs
4239                  (gnus-nov-read-integer) ; chars
4240                  (gnus-nov-read-integer) ; lines
4241                  (if (= (following-char) ?\n)
4242                      nil
4243                    (gnus-nov-field))    ; misc
4244                  )))
4245
4246       (widen))
4247
4248     ;; We build the thread tree.
4249     (when (equal id ref)
4250       ;; This article refers back to itself.  Naughty, naughty.
4251       (setq ref nil))
4252     (if (boundp (setq id-dep (intern id dependencies)))
4253         (if (and (car (symbol-value id-dep))
4254                  (not force-new))
4255             ;; An article with this Message-ID has already been seen,
4256             ;; so we ignore this one, except we add any additional
4257             ;; Xrefs (in case the two articles came from different
4258             ;; servers.
4259             (progn
4260               (mail-header-set-xref
4261                (car (symbol-value id-dep))
4262                (concat (or (mail-header-xref
4263                             (car (symbol-value id-dep)))
4264                            "")
4265                        (or (mail-header-xref header) "")))
4266               (setq header nil))
4267           (setcar (symbol-value id-dep) header))
4268       (set id-dep (list header)))
4269     (when header
4270       (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
4271           (setcdr (symbol-value ref-dep)
4272                   (nconc (cdr (symbol-value ref-dep))
4273                          (list (symbol-value id-dep))))
4274         (set ref-dep (list nil (symbol-value id-dep)))))
4275     header))
4276
4277 ;; Goes through the xover lines and returns a list of vectors
4278 (defun gnus-get-newsgroup-headers-xover (sequence &optional 
4279                                                   force-new dependencies
4280                                                   group also-fetch-heads)
4281   "Parse the news overview data in the server buffer, and return a
4282 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4283   ;; Get the Xref when the users reads the articles since most/some
4284   ;; NNTP servers do not include Xrefs when using XOVER.
4285   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4286   (let ((cur nntp-server-buffer)
4287         (dependencies (or dependencies gnus-newsgroup-dependencies))
4288         number headers header)
4289     (save-excursion
4290       (set-buffer nntp-server-buffer)
4291       ;; Allow the user to mangle the headers before parsing them.
4292       (run-hooks 'gnus-parse-headers-hook)
4293       (goto-char (point-min))
4294       (while (not (eobp))
4295         (condition-case ()
4296             (while (and sequence (not (eobp)))
4297               (setq number (read cur))
4298               (while (and sequence
4299                           (< (car sequence) number))
4300                 (setq sequence (cdr sequence)))
4301               (and sequence
4302                    (eq number (car sequence))
4303                    (progn
4304                      (setq sequence (cdr sequence))
4305                      (setq header (inline
4306                                     (gnus-nov-parse-line
4307                                      number dependencies force-new))))
4308                    (push header headers))
4309               (forward-line 1))
4310           (error
4311            (gnus-error 4 "Strange nov line (%d)"
4312                        (count-lines (point-min) (point)))))
4313         (forward-line 1))
4314       ;; A common bug in inn is that if you have posted an article and
4315       ;; then retrieves the active file, it will answer correctly --
4316       ;; the new article is included.  However, a NOV entry for the
4317       ;; article may not have been generated yet, so this may fail.
4318       ;; We work around this problem by retrieving the last few
4319       ;; headers using HEAD.
4320       (if (or (not also-fetch-heads)
4321               (not sequence))
4322           ;; We (probably) got all the headers.
4323           (nreverse headers)
4324         (let ((gnus-nov-is-evil t))
4325           (nconc
4326            (nreverse headers)
4327            (when (gnus-retrieve-headers sequence group)
4328              (gnus-get-newsgroup-headers))))))))
4329
4330 (defun gnus-article-get-xrefs ()
4331   "Fill in the Xref value in `gnus-current-headers', if necessary.
4332 This is meant to be called in `gnus-article-internal-prepare-hook'."
4333   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4334                                  gnus-current-headers)))
4335     (or (not gnus-use-cross-reference)
4336         (not headers)
4337         (and (mail-header-xref headers)
4338              (not (string= (mail-header-xref headers) "")))
4339         (let ((case-fold-search t)
4340               xref)
4341           (save-restriction
4342             (nnheader-narrow-to-headers)
4343             (goto-char (point-min))
4344             (when (or (and (eq (downcase (following-char)) ?x)
4345                            (looking-at "Xref:"))
4346                       (search-forward "\nXref:" nil t))
4347               (goto-char (1+ (match-end 0)))
4348               (setq xref (buffer-substring (point)
4349                                            (progn (end-of-line) (point))))
4350               (mail-header-set-xref headers xref)))))))
4351
4352 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4353   "Find article ID and insert the summary line for that article."
4354   (let ((header (if (and old-header use-old-header)
4355                     old-header (gnus-read-header id)))
4356         (number (and (numberp id) id))
4357         pos d)
4358     (when header
4359       ;; Rebuild the thread that this article is part of and go to the
4360       ;; article we have fetched.
4361       (when (and (not gnus-show-threads)
4362                  old-header)
4363         (when (setq d (gnus-data-find (mail-header-number old-header)))
4364           (goto-char (gnus-data-pos d))
4365           (gnus-data-remove 
4366            number
4367            (- (gnus-point-at-bol)
4368               (prog1
4369                   (1+ (gnus-point-at-eol))
4370                 (gnus-delete-line))))))
4371       (when old-header
4372         (mail-header-set-number header (mail-header-number old-header)))
4373       (setq gnus-newsgroup-sparse
4374             (delq (setq number (mail-header-number header))
4375                   gnus-newsgroup-sparse))
4376       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4377       (gnus-rebuild-thread (mail-header-id header))
4378       (gnus-summary-goto-subject number nil t))
4379     (when (and (numberp number)
4380                (> number 0))
4381       ;; We have to update the boundaries even if we can't fetch the
4382       ;; article if ID is a number -- so that the next `P' or `N'
4383       ;; command will fetch the previous (or next) article even
4384       ;; if the one we tried to fetch this time has been canceled.
4385       (when (> number gnus-newsgroup-end)
4386         (setq gnus-newsgroup-end number))
4387       (when (< number gnus-newsgroup-begin)
4388         (setq gnus-newsgroup-begin number))
4389       (setq gnus-newsgroup-unselected
4390             (delq number gnus-newsgroup-unselected)))
4391     ;; Report back a success?
4392     (and header (mail-header-number header))))
4393
4394 ;;; Process/prefix in the summary buffer
4395
4396 (defun gnus-summary-work-articles (n)
4397   "Return a list of articles to be worked upon.  The prefix argument,
4398 the list of process marked articles, and the current article will be
4399 taken into consideration."
4400   (cond
4401    (n
4402     ;; A numerical prefix has been given.
4403     (setq n (prefix-numeric-value n))
4404     (let ((backward (< n 0))
4405           (n (abs (prefix-numeric-value n)))
4406           articles article)
4407       (save-excursion
4408         (while
4409             (and (> n 0)
4410                  (push (setq article (gnus-summary-article-number))
4411                        articles)
4412                  (if backward
4413                      (gnus-summary-find-prev nil article)
4414                    (gnus-summary-find-next nil article)))
4415           (decf n)))
4416       (nreverse articles)))
4417    ((gnus-region-active-p)
4418     ;; Work on the region between point and mark.
4419     (let ((max (max (point) (mark)))
4420           articles article)
4421       (save-excursion
4422         (goto-char (min (point) (mark)))
4423         (while
4424             (and
4425              (push (setq article (gnus-summary-article-number)) articles)
4426              (gnus-summary-find-next nil article)
4427              (< (point) max)))
4428         (nreverse articles))))
4429    (gnus-newsgroup-processable
4430     ;; There are process-marked articles present.
4431     ;; Save current state.
4432     (gnus-summary-save-process-mark)
4433     ;; Return the list.
4434     (reverse gnus-newsgroup-processable))
4435    (t
4436     ;; Just return the current article.
4437     (list (gnus-summary-article-number)))))
4438
4439 (defun gnus-summary-save-process-mark ()
4440   "Push the current set of process marked articles on the stack."
4441   (interactive)
4442   (push (copy-sequence gnus-newsgroup-processable)
4443         gnus-newsgroup-process-stack))
4444
4445 (defun gnus-summary-kill-process-mark ()
4446   "Push the current set of process marked articles on the stack and unmark."
4447   (interactive)
4448   (gnus-summary-save-process-mark)
4449   (gnus-summary-unmark-all-processable))
4450
4451 (defun gnus-summary-yank-process-mark ()
4452   "Pop the last process mark state off the stack and restore it."
4453   (interactive)
4454   (unless gnus-newsgroup-process-stack
4455     (error "Empty mark stack"))
4456   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4457
4458 (defun gnus-summary-process-mark-set (set)
4459   "Make SET into the current process marked articles."
4460   (gnus-summary-unmark-all-processable)
4461   (while set
4462     (gnus-summary-set-process-mark (pop set))))
4463
4464 ;;; Searching and stuff
4465
4466 (defun gnus-summary-search-group (&optional backward use-level)
4467   "Search for next unread newsgroup.
4468 If optional argument BACKWARD is non-nil, search backward instead."
4469   (save-excursion
4470     (set-buffer gnus-group-buffer)
4471     (when (gnus-group-search-forward
4472            backward nil (if use-level (gnus-group-group-level) nil))
4473       (gnus-group-group-name))))
4474
4475 (defun gnus-summary-best-group (&optional exclude-group)
4476   "Find the name of the best unread group.
4477 If EXCLUDE-GROUP, do not go to this group."
4478   (save-excursion
4479     (set-buffer gnus-group-buffer)
4480     (save-excursion
4481       (gnus-group-best-unread-group exclude-group))))
4482
4483 (defun gnus-summary-find-next (&optional unread article backward)
4484   (if backward (gnus-summary-find-prev)
4485     (let* ((dummy (gnus-summary-article-intangible-p))
4486            (article (or article (gnus-summary-article-number)))
4487            (arts (gnus-data-find-list article))
4488            result)
4489       (when (and (not dummy)
4490                  (or (not gnus-summary-check-current)
4491                      (not unread)
4492                      (not (gnus-data-unread-p (car arts)))))
4493         (setq arts (cdr arts)))
4494       (when (setq result
4495                   (if unread
4496                       (progn
4497                         (while arts
4498                           (when (gnus-data-unread-p (car arts))
4499                             (setq result (car arts)
4500                                   arts nil))
4501                           (setq arts (cdr arts)))
4502                         result)
4503                     (car arts)))
4504         (goto-char (gnus-data-pos result))
4505         (gnus-data-number result)))))
4506
4507 (defun gnus-summary-find-prev (&optional unread article)
4508   (let* ((eobp (eobp))
4509          (article (or article (gnus-summary-article-number)))
4510          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
4511          result)
4512     (when (and (not eobp)
4513                (or (not gnus-summary-check-current)
4514                    (not unread)
4515                    (not (gnus-data-unread-p (car arts)))))
4516       (setq arts (cdr arts)))
4517     (when (setq result
4518                 (if unread
4519                     (progn
4520                       (while arts
4521                         (when (gnus-data-unread-p (car arts))
4522                           (setq result (car arts)
4523                                 arts nil))
4524                         (setq arts (cdr arts)))
4525                       result)
4526                   (car arts)))
4527       (goto-char (gnus-data-pos result))
4528       (gnus-data-number result))))
4529
4530 (defun gnus-summary-find-subject (subject &optional unread backward article)
4531   (let* ((simp-subject (gnus-simplify-subject-fully subject))
4532          (article (or article (gnus-summary-article-number)))
4533          (articles (gnus-data-list backward))
4534          (arts (gnus-data-find-list article articles))
4535          result)
4536     (when (or (not gnus-summary-check-current)
4537               (not unread)
4538               (not (gnus-data-unread-p (car arts))))
4539       (setq arts (cdr arts)))
4540     (while arts
4541       (and (or (not unread)
4542                (gnus-data-unread-p (car arts)))
4543            (vectorp (gnus-data-header (car arts)))
4544            (gnus-subject-equal
4545             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
4546            (setq result (car arts)
4547                  arts nil))
4548       (setq arts (cdr arts)))
4549     (and result
4550          (goto-char (gnus-data-pos result))
4551          (gnus-data-number result))))
4552
4553 (defun gnus-summary-search-forward (&optional unread subject backward)
4554   "Search forward for an article.
4555 If UNREAD, look for unread articles.  If SUBJECT, look for
4556 articles with that subject.  If BACKWARD, search backward instead."
4557   (cond (subject (gnus-summary-find-subject subject unread backward))
4558         (backward (gnus-summary-find-prev unread))
4559         (t (gnus-summary-find-next unread))))
4560
4561 (defun gnus-recenter (&optional n)
4562   "Center point in window and redisplay frame.
4563 Also do horizontal recentering."
4564   (interactive "P")
4565   (when (and gnus-auto-center-summary
4566              (not (eq gnus-auto-center-summary 'vertical)))
4567     (gnus-horizontal-recenter))
4568   (recenter n))
4569
4570 (defun gnus-summary-recenter ()
4571   "Center point in the summary window.
4572 If `gnus-auto-center-summary' is nil, or the article buffer isn't
4573 displayed, no centering will be performed."
4574   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
4575   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
4576   (let* ((top (cond ((< (window-height) 4) 0)
4577                     ((< (window-height) 7) 1)
4578                     (t 2)))
4579          (height (1- (window-height)))
4580          (bottom (save-excursion (goto-char (point-max))
4581                                  (forward-line (- height))
4582                                  (point)))
4583          (window (get-buffer-window (current-buffer))))
4584     ;; The user has to want it.
4585     (when gnus-auto-center-summary
4586       (when (get-buffer-window gnus-article-buffer)
4587         ;; Only do recentering when the article buffer is displayed,
4588         ;; Set the window start to either `bottom', which is the biggest
4589         ;; possible valid number, or the second line from the top,
4590         ;; whichever is the least.
4591         (set-window-start
4592          window (min bottom (save-excursion 
4593                               (forward-line (- top)) (point)))))
4594       ;; Do horizontal recentering while we're at it.
4595       (when (and (get-buffer-window (current-buffer) t)
4596                  (not (eq gnus-auto-center-summary 'vertical)))
4597         (let ((selected (selected-window)))
4598           (select-window (get-buffer-window (current-buffer) t))
4599           (gnus-summary-position-point)
4600           (gnus-horizontal-recenter)
4601           (select-window selected))))))
4602
4603 (defun gnus-summary-jump-to-group (newsgroup)
4604   "Move point to NEWSGROUP in group mode buffer."
4605   ;; Keep update point of group mode buffer if visible.
4606   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
4607       (save-window-excursion
4608         ;; Take care of tree window mode.
4609         (when (get-buffer-window gnus-group-buffer)
4610           (pop-to-buffer gnus-group-buffer))
4611         (gnus-group-jump-to-group newsgroup))
4612     (save-excursion
4613       ;; Take care of tree window mode.
4614       (if (get-buffer-window gnus-group-buffer)
4615           (pop-to-buffer gnus-group-buffer)
4616         (set-buffer gnus-group-buffer))
4617       (gnus-group-jump-to-group newsgroup))))
4618
4619 ;; This function returns a list of article numbers based on the
4620 ;; difference between the ranges of read articles in this group and
4621 ;; the range of active articles.
4622 (defun gnus-list-of-unread-articles (group)
4623   (let* ((read (gnus-info-read (gnus-get-info group)))
4624          (active (or (gnus-active group) (gnus-activate-group group)))
4625          (last (cdr active))
4626          first nlast unread)
4627     ;; If none are read, then all are unread.
4628     (if (not read)
4629         (setq first (car active))
4630       ;; If the range of read articles is a single range, then the
4631       ;; first unread article is the article after the last read
4632       ;; article.  Sounds logical, doesn't it?
4633       (if (not (listp (cdr read)))
4634           (setq first (1+ (cdr read)))
4635         ;; `read' is a list of ranges.
4636         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
4637                                   (caar read)))
4638                   1)
4639           (setq first 1))
4640         (while read
4641           (when first
4642             (while (< first nlast)
4643               (push first unread)
4644               (setq first (1+ first))))
4645           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
4646           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
4647           (setq read (cdr read)))))
4648     ;; And add the last unread articles.
4649     (while (<= first last)
4650       (push first unread)
4651       (setq first (1+ first)))
4652     ;; Return the list of unread articles.
4653     (nreverse unread)))
4654
4655 (defun gnus-list-of-read-articles (group)
4656   "Return a list of unread, unticked and non-dormant articles."
4657   (let* ((info (gnus-get-info group))
4658          (marked (gnus-info-marks info))
4659          (active (gnus-active group)))
4660     (and info active
4661          (gnus-set-difference
4662           (gnus-sorted-complement
4663            (gnus-uncompress-range active)
4664            (gnus-list-of-unread-articles group))
4665           (append
4666            (gnus-uncompress-range (cdr (assq 'dormant marked)))
4667            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
4668
4669 ;; Various summary commands
4670
4671 (defun gnus-summary-universal-argument (arg)
4672   "Perform any operation on all articles that are process/prefixed."
4673   (interactive "P")
4674   (gnus-set-global-variables)
4675   (let ((articles (gnus-summary-work-articles arg))
4676         func article)
4677     (if (eq
4678          (setq
4679           func
4680           (key-binding
4681            (read-key-sequence
4682             (substitute-command-keys
4683              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
4684              ))))
4685          'undefined)
4686         (gnus-error 1 "Undefined key")
4687       (save-excursion
4688         (while articles
4689           (gnus-summary-goto-subject (setq article (pop articles)))
4690           (let (gnus-newsgroup-processable)
4691             (command-execute func))
4692           (gnus-summary-remove-process-mark article)))))
4693   (gnus-summary-position-point))
4694
4695 (defun gnus-summary-toggle-truncation (&optional arg)
4696   "Toggle truncation of summary lines.
4697 With arg, turn line truncation on iff arg is positive."
4698   (interactive "P")
4699   (setq truncate-lines
4700         (if (null arg) (not truncate-lines)
4701           (> (prefix-numeric-value arg) 0)))
4702   (redraw-display))
4703
4704 (defun gnus-summary-reselect-current-group (&optional all rescan)
4705   "Exit and then reselect the current newsgroup.
4706 The prefix argument ALL means to select all articles."
4707   (interactive "P")
4708   (gnus-set-global-variables)
4709   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
4710     (error "Ephemeral groups can't be reselected"))
4711   (let ((current-subject (gnus-summary-article-number))
4712         (group gnus-newsgroup-name))
4713     (setq gnus-newsgroup-begin nil)
4714     (gnus-summary-exit)
4715     ;; We have to adjust the point of group mode buffer because 
4716     ;; point was moved to the next unread newsgroup by exiting.
4717     (gnus-summary-jump-to-group group)
4718     (when rescan
4719       (save-excursion
4720         (gnus-group-get-new-news-this-group 1)))
4721     (gnus-group-read-group all t)
4722     (gnus-summary-goto-subject current-subject nil t)))
4723
4724 (defun gnus-summary-rescan-group (&optional all)
4725   "Exit the newsgroup, ask for new articles, and select the newsgroup."
4726   (interactive "P")
4727   (gnus-summary-reselect-current-group all t))
4728
4729 (defun gnus-summary-update-info (&optional non-destructive)
4730   (save-excursion
4731     (let ((group gnus-newsgroup-name))
4732       (when gnus-newsgroup-kill-headers
4733         (setq gnus-newsgroup-killed
4734               (gnus-compress-sequence
4735                (nconc
4736                 (gnus-set-sorted-intersection
4737                  (gnus-uncompress-range gnus-newsgroup-killed)
4738                  (setq gnus-newsgroup-unselected
4739                        (sort gnus-newsgroup-unselected '<)))
4740                 (setq gnus-newsgroup-unreads
4741                       (sort gnus-newsgroup-unreads '<)))
4742                t)))
4743       (unless (listp (cdr gnus-newsgroup-killed))
4744         (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
4745       (let ((headers gnus-newsgroup-headers))
4746         (when (and (not gnus-save-score)
4747                    (not non-destructive))
4748           (setq gnus-newsgroup-scored nil))
4749         ;; Set the new ranges of read articles.
4750         (gnus-update-read-articles
4751          group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
4752         ;; Set the current article marks.
4753         (gnus-update-marks)
4754         ;; Do the cross-ref thing.
4755         (when gnus-use-cross-reference
4756           (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
4757         ;; Do adaptive scoring, and possibly save score files.
4758         (when gnus-newsgroup-adaptive
4759           (gnus-score-adaptive))
4760         (when gnus-use-scoring
4761           (gnus-score-save))
4762         ;; Do not switch windows but change the buffer to work.
4763         (set-buffer gnus-group-buffer)
4764         (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
4765           (gnus-group-update-group group))))))
4766
4767 (defun gnus-summary-save-newsrc (&optional force)
4768   "Save the current number of read/marked articles in the dribble buffer.
4769 The dribble buffer will then be saved.
4770 If FORCE (the prefix), also save the .newsrc file(s)."
4771   (interactive "P")
4772   (gnus-summary-update-info t)
4773   (if force
4774       (gnus-save-newsrc-file)
4775     (gnus-dribble-save)))
4776
4777 (defun gnus-summary-exit (&optional temporary)
4778   "Exit reading current newsgroup, and then return to group selection mode.
4779 gnus-exit-group-hook is called with no arguments if that value is non-nil."
4780   (interactive)
4781   (gnus-set-global-variables)
4782   (gnus-kill-save-kill-buffer)
4783   (let* ((group gnus-newsgroup-name)
4784          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
4785          (mode major-mode)
4786          (buf (current-buffer)))
4787     (run-hooks 'gnus-summary-prepare-exit-hook)
4788     ;; If we have several article buffers, we kill them at exit.
4789     (unless gnus-single-article-buffer
4790       (gnus-kill-buffer gnus-original-article-buffer)
4791       (setq gnus-article-current nil))
4792     (when gnus-use-cache
4793       (gnus-cache-possibly-remove-articles)
4794       (gnus-cache-save-buffers))
4795     (gnus-async-prefetch-remove-group group)
4796     (when gnus-suppress-duplicates
4797       (gnus-dup-enter-articles))
4798     (when gnus-use-trees
4799       (gnus-tree-close group))
4800     ;; Make all changes in this group permanent.
4801     (unless quit-config
4802       (run-hooks 'gnus-exit-group-hook)
4803       (gnus-summary-update-info))
4804     (gnus-close-group group)
4805     ;; Make sure where I was, and go to next newsgroup.
4806     (set-buffer gnus-group-buffer)
4807     (unless quit-config
4808       (gnus-group-jump-to-group group))
4809     (run-hooks 'gnus-summary-exit-hook)
4810     (unless quit-config
4811       (gnus-group-next-unread-group 1))
4812     (if temporary
4813         nil                             ;Nothing to do.
4814       ;; If we have several article buffers, we kill them at exit.
4815       (unless gnus-single-article-buffer
4816         (gnus-kill-buffer gnus-article-buffer)
4817         (gnus-kill-buffer gnus-original-article-buffer)
4818         (setq gnus-article-current nil))
4819       (set-buffer buf)
4820       (if (not gnus-kill-summary-on-exit)
4821           (gnus-deaden-summary)
4822         ;; We set all buffer-local variables to nil.  It is unclear why
4823         ;; this is needed, but if we don't, buffer-local variables are
4824         ;; not garbage-collected, it seems.  This would the lead to en
4825         ;; ever-growing Emacs.
4826         (gnus-summary-clear-local-variables)
4827         (when (get-buffer gnus-article-buffer)
4828           (bury-buffer gnus-article-buffer))
4829         ;; We clear the global counterparts of the buffer-local
4830         ;; variables as well, just to be on the safe side.
4831         (set-buffer gnus-group-buffer)
4832         (gnus-summary-clear-local-variables)
4833         ;; Return to group mode buffer.
4834         (when (eq mode 'gnus-summary-mode)
4835           (gnus-kill-buffer buf)))
4836       (setq gnus-current-select-method gnus-select-method)
4837       (pop-to-buffer gnus-group-buffer)
4838       ;; Clear the current group name.
4839       (if (not quit-config)
4840           (progn
4841             (gnus-group-jump-to-group group)
4842             (gnus-group-next-unread-group 1)
4843             (gnus-configure-windows 'group 'force))
4844         (gnus-handle-ephemeral-exit quit-config))
4845       (unless quit-config
4846         (setq gnus-newsgroup-name nil)))))
4847
4848 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
4849 (defun gnus-summary-exit-no-update (&optional no-questions)
4850   "Quit reading current newsgroup without updating read article info."
4851   (interactive)
4852   (gnus-set-global-variables)
4853   (let* ((group gnus-newsgroup-name)
4854          (quit-config (gnus-group-quit-config group)))
4855     (when (or no-questions
4856               gnus-expert-user
4857               (gnus-y-or-n-p "Discard changes to this group and exit? "))
4858       ;; If we have several article buffers, we kill them at exit.
4859       (unless gnus-single-article-buffer
4860         (gnus-kill-buffer gnus-article-buffer)
4861         (gnus-kill-buffer gnus-original-article-buffer)
4862         (setq gnus-article-current nil))
4863       (if (not gnus-kill-summary-on-exit)
4864           (gnus-deaden-summary)
4865         (gnus-close-group group)
4866         (gnus-summary-clear-local-variables)
4867         (set-buffer gnus-group-buffer)
4868         (gnus-summary-clear-local-variables)
4869         (when (get-buffer gnus-summary-buffer)
4870           (kill-buffer gnus-summary-buffer)))
4871       (unless gnus-single-article-buffer
4872         (setq gnus-article-current nil))
4873       (when gnus-use-trees
4874         (gnus-tree-close group))
4875       (gnus-async-prefetch-remove-group group)
4876       (when (get-buffer gnus-article-buffer)
4877         (bury-buffer gnus-article-buffer))
4878       ;; Return to the group buffer.
4879       (gnus-configure-windows 'group 'force)
4880       ;; Clear the current group name.
4881       (setq gnus-newsgroup-name nil)
4882       (when (equal (gnus-group-group-name) group)
4883         (gnus-group-next-unread-group 1))
4884       (when quit-config
4885         (gnus-handle-ephemeral-exit quit-config)))))
4886
4887 (defun gnus-handle-ephemeral-exit (quit-config)
4888   "Handle movement when leaving an ephemeral group.  The state
4889 which existed when entering the ephemeral is reset."
4890   (if (not (buffer-name (car quit-config)))
4891       (gnus-configure-windows 'group 'force)
4892     (set-buffer (car quit-config))
4893     (cond ((eq major-mode 'gnus-summary-mode)
4894            (gnus-set-global-variables))
4895           ((eq major-mode 'gnus-article-mode)
4896            (save-excursion
4897              ;; The `gnus-summary-buffer' variable may point
4898              ;; to the old summary buffer when using a single
4899              ;; article buffer.
4900              (unless (gnus-buffer-live-p gnus-summary-buffer)
4901                (set-buffer gnus-group-buffer))
4902              (set-buffer gnus-summary-buffer)
4903              (gnus-set-global-variables))))
4904     (if (or (eq (cdr quit-config) 'article)
4905             (eq (cdr quit-config) 'pick))
4906         (progn
4907           ;; The current article may be from the ephemeral group
4908           ;; thus it is best that we reload this article
4909           (gnus-summary-show-article)
4910           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
4911               (gnus-configure-windows 'pick 'force)
4912             (gnus-configure-windows (cdr quit-config) 'force)))
4913       (gnus-configure-windows (cdr quit-config) 'force))
4914     (when (eq major-mode 'gnus-summary-mode)
4915       (gnus-summary-next-subject 1 nil t)
4916       (gnus-summary-recenter)
4917       (gnus-summary-position-point))))
4918
4919 ;;; Dead summaries.
4920
4921 (defvar gnus-dead-summary-mode-map nil)
4922
4923 (unless gnus-dead-summary-mode-map
4924   (setq gnus-dead-summary-mode-map (make-keymap))
4925   (suppress-keymap gnus-dead-summary-mode-map)
4926   (substitute-key-definition
4927    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
4928   (let ((keys '("\C-d" "\r" "\177")))
4929     (while keys
4930       (define-key gnus-dead-summary-mode-map
4931         (pop keys) 'gnus-summary-wake-up-the-dead))))
4932
4933 (defvar gnus-dead-summary-mode nil
4934   "Minor mode for Gnus summary buffers.")
4935
4936 (defun gnus-dead-summary-mode (&optional arg)
4937   "Minor mode for Gnus summary buffers."
4938   (interactive "P")
4939   (when (eq major-mode 'gnus-summary-mode)
4940     (make-local-variable 'gnus-dead-summary-mode)
4941     (setq gnus-dead-summary-mode
4942           (if (null arg) (not gnus-dead-summary-mode)
4943             (> (prefix-numeric-value arg) 0)))
4944     (when gnus-dead-summary-mode
4945       (unless (assq 'gnus-dead-summary-mode minor-mode-alist)
4946         (push '(gnus-dead-summary-mode " Dead") minor-mode-alist))
4947       (unless (assq 'gnus-dead-summary-mode minor-mode-map-alist)
4948         (push (cons 'gnus-dead-summary-mode gnus-dead-summary-mode-map)
4949               minor-mode-map-alist)))))
4950
4951 (defun gnus-deaden-summary ()
4952   "Make the current summary buffer into a dead summary buffer."
4953   ;; Kill any previous dead summary buffer.
4954   (when (and gnus-dead-summary
4955              (buffer-name gnus-dead-summary))
4956     (save-excursion
4957       (set-buffer gnus-dead-summary)
4958       (when gnus-dead-summary-mode
4959         (kill-buffer (current-buffer)))))
4960   ;; Make this the current dead summary.
4961   (setq gnus-dead-summary (current-buffer))
4962   (gnus-dead-summary-mode 1)
4963   (let ((name (buffer-name)))
4964     (when (string-match "Summary" name)
4965       (rename-buffer
4966        (concat (substring name 0 (match-beginning 0)) "Dead "
4967                (substring name (match-beginning 0)))
4968        t))))
4969
4970 (defun gnus-kill-or-deaden-summary (buffer)
4971   "Kill or deaden the summary BUFFER."
4972   (when (and (buffer-name buffer)
4973              (not gnus-single-article-buffer))
4974     (save-excursion
4975       (set-buffer buffer)
4976       (gnus-kill-buffer gnus-article-buffer)
4977       (gnus-kill-buffer gnus-original-article-buffer)))
4978   (cond (gnus-kill-summary-on-exit
4979          (when (and gnus-use-trees
4980                     (and (get-buffer buffer)
4981                          (buffer-name (get-buffer buffer))))
4982            (save-excursion
4983              (set-buffer (get-buffer buffer))
4984              (gnus-tree-close gnus-newsgroup-name)))
4985          (gnus-kill-buffer buffer))
4986         ((and (get-buffer buffer)
4987               (buffer-name (get-buffer buffer)))
4988          (save-excursion
4989            (set-buffer buffer)
4990            (gnus-deaden-summary)))))
4991
4992 (defun gnus-summary-wake-up-the-dead (&rest args)
4993   "Wake up the dead summary buffer."
4994   (interactive)
4995   (gnus-dead-summary-mode -1)
4996   (let ((name (buffer-name)))
4997     (when (string-match "Dead " name)
4998       (rename-buffer
4999        (concat (substring name 0 (match-beginning 0))
5000                (substring name (match-end 0)))
5001        t)))
5002   (gnus-message 3 "This dead summary is now alive again"))
5003
5004 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5005 (defun gnus-summary-fetch-faq (&optional faq-dir)
5006   "Fetch the FAQ for the current group.
5007 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5008 in."
5009   (interactive
5010    (list
5011     (when current-prefix-arg
5012       (completing-read
5013        "Faq dir: " (and (listp gnus-group-faq-directory)
5014                         gnus-group-faq-directory)))))
5015   (let (gnus-faq-buffer)
5016     (when (setq gnus-faq-buffer
5017                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5018       (gnus-configure-windows 'summary-faq))))
5019
5020 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5021 (defun gnus-summary-describe-group (&optional force)
5022   "Describe the current newsgroup."
5023   (interactive "P")
5024   (gnus-group-describe-group force gnus-newsgroup-name))
5025
5026 (defun gnus-summary-describe-briefly ()
5027   "Describe summary mode commands briefly."
5028   (interactive)
5029   (gnus-message 6
5030                 (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")))
5031
5032 ;; Walking around group mode buffer from summary mode.
5033
5034 (defun gnus-summary-next-group (&optional no-article target-group backward)
5035   "Exit current newsgroup and then select next unread newsgroup.
5036 If prefix argument NO-ARTICLE is non-nil, no article is selected
5037 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5038 previous group instead."
5039   (interactive "P")
5040   (gnus-set-global-variables)
5041   ;; Stop pre-fetching.
5042   (gnus-async-halt-prefetch)
5043   (let ((current-group gnus-newsgroup-name)
5044         (current-buffer (current-buffer))
5045         entered)
5046     ;; First we semi-exit this group to update Xrefs and all variables.
5047     ;; We can't do a real exit, because the window conf must remain
5048     ;; the same in case the user is prompted for info, and we don't
5049     ;; want the window conf to change before that...
5050     (gnus-summary-exit t)
5051     (while (not entered)
5052       ;; Then we find what group we are supposed to enter.
5053       (set-buffer gnus-group-buffer)
5054       (gnus-group-jump-to-group current-group)
5055       (setq target-group
5056             (or target-group
5057                 (if (eq gnus-keep-same-level 'best)
5058                     (gnus-summary-best-group gnus-newsgroup-name)
5059                   (gnus-summary-search-group backward gnus-keep-same-level))))
5060       (if (not target-group)
5061           ;; There are no further groups, so we return to the group
5062           ;; buffer.
5063           (progn
5064             (gnus-message 5 "Returning to the group buffer")
5065             (setq entered t)
5066             (set-buffer current-buffer)
5067             (gnus-summary-exit)
5068             (run-hooks 'gnus-group-no-more-groups-hook))
5069         ;; We try to enter the target group.
5070         (gnus-group-jump-to-group target-group)
5071         (let ((unreads (gnus-group-group-unread)))
5072           (if (and (or (eq t unreads)
5073                        (and unreads (not (zerop unreads))))
5074                    (gnus-summary-read-group
5075                     target-group nil no-article current-buffer))
5076               (setq entered t)
5077             (setq current-group target-group
5078                   target-group nil)))))))
5079
5080 (defun gnus-summary-prev-group (&optional no-article)
5081   "Exit current newsgroup and then select previous unread newsgroup.
5082 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5083   (interactive "P")
5084   (gnus-summary-next-group no-article nil t))
5085
5086 ;; Walking around summary lines.
5087
5088 (defun gnus-summary-first-subject (&optional unread)
5089   "Go to the first unread subject.
5090 If UNREAD is non-nil, go to the first unread article.
5091 Returns the article selected or nil if there are no unread articles."
5092   (interactive "P")
5093   (prog1
5094       (cond
5095        ;; Empty summary.
5096        ((null gnus-newsgroup-data)
5097         (gnus-message 3 "No articles in the group")
5098         nil)
5099        ;; Pick the first article.
5100        ((not unread)
5101         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5102         (gnus-data-number (car gnus-newsgroup-data)))
5103        ;; No unread articles.
5104        ((null gnus-newsgroup-unreads)
5105         (gnus-message 3 "No more unread articles")
5106         nil)
5107        ;; Find the first unread article.
5108        (t
5109         (let ((data gnus-newsgroup-data))
5110           (while (and data
5111                       (not (gnus-data-unread-p (car data))))
5112             (setq data (cdr data)))
5113           (when data
5114             (goto-char (gnus-data-pos (car data)))
5115             (gnus-data-number (car data))))))
5116     (gnus-summary-position-point)))
5117
5118 (defun gnus-summary-next-subject (n &optional unread dont-display)
5119   "Go to next N'th summary line.
5120 If N is negative, go to the previous N'th subject line.
5121 If UNREAD is non-nil, only unread articles are selected.
5122 The difference between N and the actual number of steps taken is
5123 returned."
5124   (interactive "p")
5125   (let ((backward (< n 0))
5126         (n (abs n)))
5127     (while (and (> n 0)
5128                 (if backward
5129                     (gnus-summary-find-prev unread)
5130                   (gnus-summary-find-next unread)))
5131       (setq n (1- n)))
5132     (when (/= 0 n)
5133       (gnus-message 7 "No more%s articles"
5134                     (if unread " unread" "")))
5135     (unless dont-display
5136       (gnus-summary-recenter)
5137       (gnus-summary-position-point))
5138     n))
5139
5140 (defun gnus-summary-next-unread-subject (n)
5141   "Go to next N'th unread summary line."
5142   (interactive "p")
5143   (gnus-summary-next-subject n t))
5144
5145 (defun gnus-summary-prev-subject (n &optional unread)
5146   "Go to previous N'th summary line.
5147 If optional argument UNREAD is non-nil, only unread article is selected."
5148   (interactive "p")
5149   (gnus-summary-next-subject (- n) unread))
5150
5151 (defun gnus-summary-prev-unread-subject (n)
5152   "Go to previous N'th unread summary line."
5153   (interactive "p")
5154   (gnus-summary-next-subject (- n) t))
5155
5156 (defun gnus-summary-goto-subject (article &optional force silent)
5157   "Go the subject line of ARTICLE.
5158 If FORCE, also allow jumping to articles not currently shown."
5159   (interactive "nArticle number: ")
5160   (let ((b (point))
5161         (data (gnus-data-find article)))
5162     ;; We read in the article if we have to.
5163     (and (not data)
5164          force
5165          (gnus-summary-insert-subject article (and (vectorp force) force) t)
5166          (setq data (gnus-data-find article)))
5167     (goto-char b)
5168     (if (not data)
5169         (progn
5170           (unless silent
5171             (gnus-message 3 "Can't find article %d" article))
5172           nil)
5173       (goto-char (gnus-data-pos data))
5174       article)))
5175
5176 ;; Walking around summary lines with displaying articles.
5177
5178 (defun gnus-summary-expand-window (&optional arg)
5179   "Make the summary buffer take up the entire Emacs frame.
5180 Given a prefix, will force an `article' buffer configuration."
5181   (interactive "P")
5182   (gnus-set-global-variables)
5183   (if arg
5184       (gnus-configure-windows 'article 'force)
5185     (gnus-configure-windows 'summary 'force)))
5186
5187 (defun gnus-summary-display-article (article &optional all-header)
5188   "Display ARTICLE in article buffer."
5189   (gnus-set-global-variables)
5190   (if (null article)
5191       nil
5192     (prog1
5193         (if gnus-summary-display-article-function
5194             (funcall gnus-summary-display-article-function article all-header)
5195           (gnus-article-prepare article all-header))
5196       (run-hooks 'gnus-select-article-hook)
5197       (when (and gnus-current-article
5198                  (not (zerop gnus-current-article)))
5199         (gnus-summary-goto-subject gnus-current-article))
5200       (gnus-summary-recenter)
5201       (when (and gnus-use-trees gnus-show-threads)
5202         (gnus-possibly-generate-tree article)
5203         (gnus-highlight-selected-tree article))
5204       ;; Successfully display article.
5205       (gnus-article-set-window-start
5206        (cdr (assq article gnus-newsgroup-bookmarks))))))
5207
5208 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5209   "Select the current article.
5210 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5211 non-nil, the article will be re-fetched even if it already present in
5212 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5213 be displayed."
5214   ;; Make sure we are in the summary buffer to work around bbdb bug.
5215   (unless (eq major-mode 'gnus-summary-mode)
5216     (set-buffer gnus-summary-buffer))
5217   (let ((article (or article (gnus-summary-article-number)))
5218         (all-headers (not (not all-headers))) ;Must be T or NIL.
5219         gnus-summary-display-article-function
5220         did)
5221     (and (not pseudo)
5222          (gnus-summary-article-pseudo-p article)
5223          (error "This is a pseudo-article."))
5224     (prog1
5225         (save-excursion
5226           (set-buffer gnus-summary-buffer)
5227           (if (or (and gnus-single-article-buffer
5228                        (or (null gnus-current-article)
5229                            (null gnus-article-current)
5230                            (null (get-buffer gnus-article-buffer))
5231                            (not (eq article (cdr gnus-article-current)))
5232                            (not (equal (car gnus-article-current)
5233                                        gnus-newsgroup-name))))
5234                   (and (not gnus-single-article-buffer)
5235                        (or (null gnus-current-article)
5236                            (not (eq gnus-current-article article))))
5237                   force)
5238               ;; The requested article is different from the current article.
5239               (prog1
5240                   (gnus-summary-display-article article all-headers)
5241                 (setq did article))
5242             (when (or all-headers gnus-show-all-headers)
5243               (gnus-article-show-all-headers))
5244             'old))
5245       (when did
5246         (gnus-article-set-window-start
5247          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5248
5249 (defun gnus-summary-set-current-mark (&optional current-mark)
5250   "Obsolete function."
5251   nil)
5252
5253 (defun gnus-summary-next-article (&optional unread subject backward push)
5254   "Select the next article.
5255 If UNREAD, only unread articles are selected.
5256 If SUBJECT, only articles with SUBJECT are selected.
5257 If BACKWARD, the previous article is selected instead of the next."
5258   (interactive "P")
5259   (gnus-set-global-variables)
5260   (cond
5261    ;; Is there such an article?
5262    ((and (gnus-summary-search-forward unread subject backward)
5263          (or (gnus-summary-display-article (gnus-summary-article-number))
5264              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5265     (gnus-summary-position-point))
5266    ;; If not, we try the first unread, if that is wanted.
5267    ((and subject
5268          gnus-auto-select-same
5269          (gnus-summary-first-unread-article))
5270     (gnus-summary-position-point)
5271     (gnus-message 6 "Wrapped"))
5272    ;; Try to get next/previous article not displayed in this group.
5273    ((and gnus-auto-extend-newsgroup
5274          (not unread) (not subject))
5275     (gnus-summary-goto-article
5276      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5277      nil t))
5278    ;; Go to next/previous group.
5279    (t
5280     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5281       (gnus-summary-jump-to-group gnus-newsgroup-name))
5282     (let ((cmd last-command-char)
5283           (point
5284            (save-excursion
5285              (set-buffer gnus-group-buffer)
5286              (point)))
5287           (group
5288            (if (eq gnus-keep-same-level 'best)
5289                (gnus-summary-best-group gnus-newsgroup-name)
5290              (gnus-summary-search-group backward gnus-keep-same-level))))
5291       ;; For some reason, the group window gets selected.  We change
5292       ;; it back.
5293       (select-window (get-buffer-window (current-buffer)))
5294       ;; Select next unread newsgroup automagically.
5295       (cond
5296        ((or (not gnus-auto-select-next)
5297             (not cmd))
5298         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5299        ((or (eq gnus-auto-select-next 'quietly)
5300             (and (eq gnus-auto-select-next 'slightly-quietly)
5301                  push)
5302             (and (eq gnus-auto-select-next 'almost-quietly)
5303                  (gnus-summary-last-article-p)))
5304         ;; Select quietly.
5305         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5306             (gnus-summary-exit)
5307           (gnus-message 7 "No more%s articles (%s)..."
5308                         (if unread " unread" "")
5309                         (if group (concat "selecting " group)
5310                           "exiting"))
5311           (gnus-summary-next-group nil group backward)))
5312        (t
5313         (when (gnus-key-press-event-p last-input-event)
5314           (gnus-summary-walk-group-buffer
5315            gnus-newsgroup-name cmd unread backward point))))))))
5316
5317 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5318   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5319                       (?\C-p (gnus-group-prev-unread-group 1))))
5320         (cursor-in-echo-area t)
5321         keve key group ended)
5322     (save-excursion
5323       (set-buffer gnus-group-buffer)
5324       (goto-char start)
5325       (setq group
5326             (if (eq gnus-keep-same-level 'best)
5327                 (gnus-summary-best-group gnus-newsgroup-name)
5328               (gnus-summary-search-group backward gnus-keep-same-level))))
5329     (while (not ended)
5330       (gnus-message
5331        5 "No more%s articles%s" (if unread " unread" "")
5332        (if (and group
5333                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5334            (format " (Type %s for %s [%s])"
5335                    (single-key-description cmd) group
5336                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5337          (format " (Type %s to exit %s)"
5338                  (single-key-description cmd)
5339                  gnus-newsgroup-name)))
5340       ;; Confirm auto selection.
5341       (setq key (car (setq keve (gnus-read-event-char))))
5342       (setq ended t)
5343       (cond
5344        ((assq key keystrokes)
5345         (let ((obuf (current-buffer)))
5346           (switch-to-buffer gnus-group-buffer)
5347           (when group
5348             (gnus-group-jump-to-group group))
5349           (eval (cadr (assq key keystrokes)))
5350           (setq group (gnus-group-group-name))
5351           (switch-to-buffer obuf))
5352         (setq ended nil))
5353        ((equal key cmd)
5354         (if (or (not group)
5355                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5356             (gnus-summary-exit)
5357           (gnus-summary-next-group nil group backward)))
5358        (t
5359         (push (cdr keve) unread-command-events))))))
5360
5361 (defun gnus-summary-next-unread-article ()
5362   "Select unread article after current one."
5363   (interactive)
5364   (gnus-summary-next-article 
5365    (or (not (eq gnus-summary-goto-unread 'never))
5366        (gnus-summary-last-article-p (gnus-summary-article-number)))
5367    (and gnus-auto-select-same
5368         (gnus-summary-article-subject))))
5369
5370 (defun gnus-summary-prev-article (&optional unread subject)
5371   "Select the article after the current one.
5372 If UNREAD is non-nil, only unread articles are selected."
5373   (interactive "P")
5374   (gnus-summary-next-article unread subject t))
5375
5376 (defun gnus-summary-prev-unread-article ()
5377   "Select unread article before current one."
5378   (interactive)
5379   (gnus-summary-prev-article
5380    (or (not (eq gnus-summary-goto-unread 'never))
5381        (gnus-summary-first-article-p (gnus-summary-article-number)))
5382    (and gnus-auto-select-same
5383         (gnus-summary-article-subject))))
5384
5385 (defun gnus-summary-next-page (&optional lines circular)
5386   "Show next page of the selected article.
5387 If at the end of the current article, select the next article.
5388 LINES says how many lines should be scrolled up.
5389
5390 If CIRCULAR is non-nil, go to the start of the article instead of
5391 selecting the next article when reaching the end of the current
5392 article."
5393   (interactive "P")
5394   (setq gnus-summary-buffer (current-buffer))
5395   (gnus-set-global-variables)
5396   (let ((article (gnus-summary-article-number))
5397         (article-window (get-buffer-window gnus-article-buffer t))
5398         (endp nil))
5399     (gnus-configure-windows 'article)
5400     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5401         (if (and (eq gnus-summary-goto-unread 'never)
5402                  (not (gnus-summary-last-article-p article)))
5403             (gnus-summary-next-article)
5404           (gnus-summary-next-unread-article))
5405       (if (or (null gnus-current-article)
5406               (null gnus-article-current)
5407               (/= article (cdr gnus-article-current))
5408               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5409           ;; Selected subject is different from current article's.
5410           (gnus-summary-display-article article)
5411         (when article-window
5412           (gnus-eval-in-buffer-window gnus-article-buffer
5413             (setq endp (gnus-article-next-page lines)))
5414           (when endp
5415             (cond (circular
5416                    (gnus-summary-beginning-of-article))
5417                   (lines
5418                    (gnus-message 3 "End of message"))
5419                   ((null lines)
5420                    (if (and (eq gnus-summary-goto-unread 'never)
5421                             (not (gnus-summary-last-article-p article)))
5422                        (gnus-summary-next-article)
5423                      (gnus-summary-next-unread-article))))))))
5424     (gnus-summary-recenter)
5425     (gnus-summary-position-point)))
5426
5427 (defun gnus-summary-prev-page (&optional lines)
5428   "Show previous page of selected article.
5429 Argument LINES specifies lines to be scrolled down."
5430   (interactive "P")
5431   (gnus-set-global-variables)
5432   (let ((article (gnus-summary-article-number))
5433         (article-window (get-buffer-window gnus-article-buffer t)))
5434     (gnus-configure-windows 'article)
5435     (if (or (null gnus-current-article)
5436             (null gnus-article-current)
5437             (/= article (cdr gnus-article-current))
5438             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5439         ;; Selected subject is different from current article's.
5440         (gnus-summary-display-article article)
5441       (gnus-summary-recenter)
5442       (when article-window
5443         (gnus-eval-in-buffer-window gnus-article-buffer
5444           (gnus-article-prev-page lines)))))
5445   (gnus-summary-position-point))
5446
5447 (defun gnus-summary-scroll-up (lines)
5448   "Scroll up (or down) one line current article.
5449 Argument LINES specifies lines to be scrolled up (or down if negative)."
5450   (interactive "p")
5451   (gnus-set-global-variables)
5452   (gnus-configure-windows 'article)
5453   (gnus-summary-show-thread)
5454   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
5455     (gnus-eval-in-buffer-window gnus-article-buffer
5456       (cond ((> lines 0)
5457              (when (gnus-article-next-page lines)
5458                (gnus-message 3 "End of message")))
5459             ((< lines 0)
5460              (gnus-article-prev-page (- lines))))))
5461   (gnus-summary-recenter)
5462   (gnus-summary-position-point))
5463
5464 (defun gnus-summary-next-same-subject ()
5465   "Select next article which has the same subject as current one."
5466   (interactive)
5467   (gnus-set-global-variables)
5468   (gnus-summary-next-article nil (gnus-summary-article-subject)))
5469
5470 (defun gnus-summary-prev-same-subject ()
5471   "Select previous article which has the same subject as current one."
5472   (interactive)
5473   (gnus-set-global-variables)
5474   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
5475
5476 (defun gnus-summary-next-unread-same-subject ()
5477   "Select next unread article which has the same subject as current one."
5478   (interactive)
5479   (gnus-set-global-variables)
5480   (gnus-summary-next-article t (gnus-summary-article-subject)))
5481
5482 (defun gnus-summary-prev-unread-same-subject ()
5483   "Select previous unread article which has the same subject as current one."
5484   (interactive)
5485   (gnus-set-global-variables)
5486   (gnus-summary-prev-article t (gnus-summary-article-subject)))
5487
5488 (defun gnus-summary-first-unread-article ()
5489   "Select the first unread article.
5490 Return nil if there are no unread articles."
5491   (interactive)
5492   (gnus-set-global-variables)
5493   (prog1
5494       (when (gnus-summary-first-subject t)
5495         (gnus-summary-show-thread)
5496         (gnus-summary-first-subject t)
5497         (gnus-summary-display-article (gnus-summary-article-number)))
5498     (gnus-summary-position-point)))
5499
5500 (defun gnus-summary-first-article ()
5501   "Select the first article.
5502 Return nil if there are no articles."
5503   (interactive)
5504   (gnus-set-global-variables)
5505   (prog1
5506       (when (gnus-summary-first-subject)
5507       (gnus-summary-show-thread)
5508       (gnus-summary-first-subject)
5509       (gnus-summary-display-article (gnus-summary-article-number)))
5510     (gnus-summary-position-point)))
5511
5512 (defun gnus-summary-best-unread-article ()
5513   "Select the unread article with the highest score."
5514   (interactive)
5515   (gnus-set-global-variables)
5516   (let ((best -1000000)
5517         (data gnus-newsgroup-data)
5518         article score)
5519     (while data
5520       (and (gnus-data-unread-p (car data))
5521            (> (setq score
5522                     (gnus-summary-article-score (gnus-data-number (car data))))
5523               best)
5524            (setq best score
5525                  article (gnus-data-number (car data))))
5526       (setq data (cdr data)))
5527     (prog1
5528         (if article
5529             (gnus-summary-goto-article article)
5530           (error "No unread articles"))
5531       (gnus-summary-position-point))))
5532
5533 (defun gnus-summary-last-subject ()
5534   "Go to the last displayed subject line in the group."
5535   (let ((article (gnus-data-number (car (gnus-data-list t)))))
5536     (when article
5537       (gnus-summary-goto-subject article))))
5538
5539 (defun gnus-summary-goto-article (article &optional all-headers force)
5540   "Fetch ARTICLE and display it if it exists.
5541 If ALL-HEADERS is non-nil, no header lines are hidden."
5542   (interactive
5543    (list
5544     (string-to-int
5545      (completing-read
5546       "Article number: "
5547       (mapcar (lambda (number) (list (int-to-string number)))
5548               gnus-newsgroup-limit)))
5549     current-prefix-arg
5550     t))
5551   (prog1
5552       (if (gnus-summary-goto-subject article force)
5553           (gnus-summary-display-article article all-headers)
5554         (gnus-message 4 "Couldn't go to article %s" article) nil)
5555     (gnus-summary-position-point)))
5556
5557 (defun gnus-summary-goto-last-article ()
5558   "Go to the previously read article."
5559   (interactive)
5560   (prog1
5561       (when gnus-last-article
5562         (gnus-summary-goto-article gnus-last-article))
5563     (gnus-summary-position-point)))
5564
5565 (defun gnus-summary-pop-article (number)
5566   "Pop one article off the history and go to the previous.
5567 NUMBER articles will be popped off."
5568   (interactive "p")
5569   (let (to)
5570     (setq gnus-newsgroup-history
5571           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
5572     (if to
5573         (gnus-summary-goto-article (car to))
5574       (error "Article history empty")))
5575   (gnus-summary-position-point))
5576
5577 ;; Summary commands and functions for limiting the summary buffer.
5578
5579 (defun gnus-summary-limit-to-articles (n)
5580   "Limit the summary buffer to the next N articles.
5581 If not given a prefix, use the process marked articles instead."
5582   (interactive "P")
5583   (gnus-set-global-variables)
5584   (prog1
5585       (let ((articles (gnus-summary-work-articles n)))
5586         (setq gnus-newsgroup-processable nil)
5587         (gnus-summary-limit articles))
5588     (gnus-summary-position-point)))
5589
5590 (defun gnus-summary-pop-limit (&optional total)
5591   "Restore the previous limit.
5592 If given a prefix, remove all limits."
5593   (interactive "P")
5594   (gnus-set-global-variables)
5595   (when total 
5596     (setq gnus-newsgroup-limits
5597           (list (mapcar (lambda (h) (mail-header-number h))
5598                         gnus-newsgroup-headers))))
5599   (unless gnus-newsgroup-limits
5600     (error "No limit to pop"))
5601   (prog1
5602       (gnus-summary-limit nil 'pop)
5603     (gnus-summary-position-point)))
5604
5605 (defun gnus-summary-limit-to-subject (subject &optional header)
5606   "Limit the summary buffer to articles that have subjects that match a regexp."
5607   (interactive "sLimit to subject (regexp): ")
5608   (unless header
5609     (setq header "subject"))
5610   (when (not (equal "" subject))
5611     (prog1
5612         (let ((articles (gnus-summary-find-matching
5613                          (or header "subject") subject 'all)))
5614           (unless articles
5615             (error "Found no matches for \"%s\"" subject))
5616           (gnus-summary-limit articles))
5617       (gnus-summary-position-point))))
5618
5619 (defun gnus-summary-limit-to-author (from)
5620   "Limit the summary buffer to articles that have authors that match a regexp."
5621   (interactive "sLimit to author (regexp): ")
5622   (gnus-summary-limit-to-subject from "from"))
5623
5624 (defun gnus-summary-limit-to-age (age &optional younger-p)
5625   "Limit the summary buffer to articles that are older than (or equal) AGE days. 
5626 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
5627 articles that are younger than AGE days."
5628   (interactive "nTime in days: \nP")
5629   (prog1
5630       (let ((data gnus-newsgroup-data)
5631             (cutoff (nnmail-days-to-time age))
5632             articles d date is-younger)
5633         (while (setq d (pop data))
5634           (when (and (vectorp (gnus-data-header d))
5635                      (setq date (mail-header-date (gnus-data-header d))))
5636             (setq is-younger (nnmail-time-less
5637                               (nnmail-time-since (nnmail-date-to-time date))
5638                               cutoff))
5639             (when (if younger-p is-younger (not is-younger))
5640               (push (gnus-data-number d) articles))))
5641         (gnus-summary-limit (nreverse articles)))
5642     (gnus-summary-position-point)))
5643
5644 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
5645 (make-obsolete
5646  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
5647
5648 (defun gnus-summary-limit-to-unread (&optional all)
5649   "Limit the summary buffer to articles that are not marked as read.
5650 If ALL is non-nil, limit strictly to unread articles."
5651   (interactive "P")
5652   (if all
5653       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
5654     (gnus-summary-limit-to-marks
5655      ;; Concat all the marks that say that an article is read and have
5656      ;; those removed.
5657      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
5658            gnus-killed-mark gnus-kill-file-mark
5659            gnus-low-score-mark gnus-expirable-mark
5660            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
5661            gnus-duplicate-mark)
5662      'reverse)))
5663
5664 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
5665 (make-obsolete 'gnus-summary-delete-marked-with
5666                'gnus-summary-limit-exlude-marks)
5667
5668 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
5669   "Exclude articles that are marked with MARKS (e.g. \"DK\").
5670 If REVERSE, limit the summary buffer to articles that are marked
5671 with MARKS.  MARKS can either be a string of marks or a list of marks.
5672 Returns how many articles were removed."
5673   (interactive "sMarks: ")
5674   (gnus-summary-limit-to-marks marks t))
5675   
5676 (defun gnus-summary-limit-to-marks (marks &optional reverse)
5677   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
5678 If REVERSE (the prefix), limit the summary buffer to articles that are
5679 not marked with MARKS.  MARKS can either be a string of marks or a
5680 list of marks.
5681 Returns how many articles were removed."
5682   (interactive (list (read-string "Marks: ") current-prefix-arg))
5683   (gnus-set-global-variables)
5684   (prog1
5685       (let ((data gnus-newsgroup-data)
5686             (marks (if (listp marks) marks
5687                      (append marks nil))) ; Transform to list.
5688             articles)
5689         (while data
5690           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
5691                   (memq (gnus-data-mark (car data)) marks))
5692             (push (gnus-data-number (car data)) articles))
5693           (setq data (cdr data)))
5694         (gnus-summary-limit articles))
5695     (gnus-summary-position-point)))
5696
5697 (defun gnus-summary-limit-to-score (&optional score)
5698   "Limit to articles with score at or above SCORE."
5699   (interactive "P")
5700   (gnus-set-global-variables)
5701   (setq score (if score
5702                   (prefix-numeric-value score)
5703                 (or gnus-summary-default-score 0)))
5704   (let ((data gnus-newsgroup-data)
5705         articles)
5706     (while data
5707       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
5708                 score)
5709         (push (gnus-data-number (car data)) articles))
5710       (setq data (cdr data)))
5711     (prog1
5712         (gnus-summary-limit articles)
5713       (gnus-summary-position-point))))
5714
5715 (defun gnus-summary-limit-include-dormant ()
5716   "Display all the hidden articles that are marked as dormant."
5717   (interactive)
5718   (gnus-set-global-variables)
5719   (unless gnus-newsgroup-dormant
5720     (error "There are no dormant articles in this group"))
5721   (prog1
5722       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
5723     (gnus-summary-position-point)))
5724
5725 (defun gnus-summary-limit-exclude-dormant ()
5726   "Hide all dormant articles."
5727   (interactive)
5728   (gnus-set-global-variables)
5729   (prog1
5730       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
5731     (gnus-summary-position-point)))
5732
5733 (defun gnus-summary-limit-exclude-childless-dormant ()
5734   "Hide all dormant articles that have no children."
5735   (interactive)
5736   (gnus-set-global-variables)
5737   (let ((data (gnus-data-list t))
5738         articles d children)
5739     ;; Find all articles that are either not dormant or have
5740     ;; children.
5741     (while (setq d (pop data))
5742       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
5743                 (and (setq children 
5744                            (gnus-article-children (gnus-data-number d)))
5745                      (let (found)
5746                        (while children
5747                          (when (memq (car children) articles)
5748                            (setq children nil
5749                                  found t))
5750                          (pop children))
5751                        found)))
5752         (push (gnus-data-number d) articles)))
5753     ;; Do the limiting.
5754     (prog1
5755         (gnus-summary-limit articles)
5756       (gnus-summary-position-point))))
5757
5758 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
5759   "Mark all unread excluded articles as read.
5760 If ALL, mark even excluded ticked and dormants as read."
5761   (interactive "P")
5762   (let ((articles (gnus-sorted-complement
5763                    (sort
5764                     (mapcar (lambda (h) (mail-header-number h))
5765                             gnus-newsgroup-headers)
5766                     '<)
5767                    (sort gnus-newsgroup-limit '<)))
5768         article)
5769     (setq gnus-newsgroup-unreads nil)
5770     (if all
5771         (setq gnus-newsgroup-dormant nil
5772               gnus-newsgroup-marked nil
5773               gnus-newsgroup-reads
5774               (nconc
5775                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
5776                gnus-newsgroup-reads))
5777       (while (setq article (pop articles))
5778         (unless (or (memq article gnus-newsgroup-dormant)
5779                     (memq article gnus-newsgroup-marked))
5780           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
5781
5782 (defun gnus-summary-limit (articles &optional pop)
5783   (if pop
5784       ;; We pop the previous limit off the stack and use that.
5785       (setq articles (car gnus-newsgroup-limits)
5786             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
5787     ;; We use the new limit, so we push the old limit on the stack.
5788     (push gnus-newsgroup-limit gnus-newsgroup-limits))
5789   ;; Set the limit.
5790   (setq gnus-newsgroup-limit articles)
5791   (let ((total (length gnus-newsgroup-data))
5792         (data (gnus-data-find-list (gnus-summary-article-number)))
5793         (gnus-summary-mark-below nil)   ; Inhibit this.
5794         found)
5795     ;; This will do all the work of generating the new summary buffer
5796     ;; according to the new limit.
5797     (gnus-summary-prepare)
5798     ;; Hide any threads, possibly.
5799     (and gnus-show-threads
5800          gnus-thread-hide-subtree
5801          (gnus-summary-hide-all-threads))
5802     ;; Try to return to the article you were at, or one in the
5803     ;; neighborhood.
5804     (when data
5805       ;; We try to find some article after the current one.
5806       (while data
5807         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
5808           (setq data nil
5809                 found t))
5810         (setq data (cdr data))))
5811     (unless found
5812       ;; If there is no data, that means that we were after the last
5813       ;; article.  The same goes when we can't find any articles
5814       ;; after the current one.
5815       (goto-char (point-max))
5816       (gnus-summary-find-prev))
5817     ;; We return how many articles were removed from the summary
5818     ;; buffer as a result of the new limit.
5819     (- total (length gnus-newsgroup-data))))
5820
5821 (defsubst gnus-invisible-cut-children (threads)
5822   (let ((num 0))
5823     (while threads
5824       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
5825         (incf num))
5826       (pop threads))
5827     (< num 2)))
5828
5829 (defsubst gnus-cut-thread (thread)
5830   "Go forwards in the thread until we find an article that we want to display."
5831   (when (or (eq gnus-fetch-old-headers 'some)
5832             (eq gnus-build-sparse-threads 'some)
5833             (eq gnus-build-sparse-threads 'more))
5834     ;; Deal with old-fetched headers and sparse threads.
5835     (while (and
5836             thread
5837             (or
5838              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
5839              (gnus-summary-article-ancient-p
5840               (mail-header-number (car thread))))
5841             (progn
5842               (if (<= (length (cdr thread)) 1)
5843                   (setq thread (cadr thread))
5844                 (when (gnus-invisible-cut-children (cdr thread))
5845                   (let ((th (cdr thread)))
5846                     (while th
5847                       (if (memq (mail-header-number (caar th))
5848                                 gnus-newsgroup-limit)
5849                           (setq thread (car th)
5850                                 th nil)
5851                         (setq th (cdr th)))))))))
5852       ))
5853   thread)
5854
5855 (defun gnus-cut-threads (threads)
5856   "Cut off all uninteresting articles from the beginning of threads."
5857   (when (or (eq gnus-fetch-old-headers 'some)
5858             (eq gnus-build-sparse-threads 'some)
5859             (eq gnus-build-sparse-threads 'more))
5860     (let ((th threads))
5861       (while th
5862         (setcar th (gnus-cut-thread (car th)))
5863         (setq th (cdr th)))))
5864   ;; Remove nixed out threads.
5865   (delq nil threads))
5866
5867 (defun gnus-summary-initial-limit (&optional show-if-empty)
5868   "Figure out what the initial limit is supposed to be on group entry.
5869 This entails weeding out unwanted dormants, low-scored articles,
5870 fetch-old-headers verbiage, and so on."
5871   ;; Most groups have nothing to remove.
5872   (if (or gnus-inhibit-limiting
5873           (and (null gnus-newsgroup-dormant)
5874                (not (eq gnus-fetch-old-headers 'some))
5875                (null gnus-summary-expunge-below)
5876                (not (eq gnus-build-sparse-threads 'some))
5877                (not (eq gnus-build-sparse-threads 'more))
5878                (null gnus-thread-expunge-below)
5879                (not gnus-use-nocem)))
5880       ()                                ; Do nothing.
5881     (push gnus-newsgroup-limit gnus-newsgroup-limits)
5882     (setq gnus-newsgroup-limit nil)
5883     (mapatoms
5884      (lambda (node)
5885        (unless (car (symbol-value node))
5886          ;; These threads have no parents -- they are roots.
5887          (let ((nodes (cdr (symbol-value node)))
5888                thread)
5889            (while nodes
5890              (if (and gnus-thread-expunge-below
5891                       (< (gnus-thread-total-score (car nodes))
5892                          gnus-thread-expunge-below))
5893                  (gnus-expunge-thread (pop nodes))
5894                (setq thread (pop nodes))
5895                (gnus-summary-limit-children thread))))))
5896      gnus-newsgroup-dependencies)
5897     ;; If this limitation resulted in an empty group, we might
5898     ;; pop the previous limit and use it instead.
5899     (when (and (not gnus-newsgroup-limit)
5900                show-if-empty)
5901       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
5902     gnus-newsgroup-limit))
5903
5904 (defun gnus-summary-limit-children (thread)
5905   "Return 1 if this subthread is visible and 0 if it is not."
5906   ;; First we get the number of visible children to this thread.  This
5907   ;; is done by recursing down the thread using this function, so this
5908   ;; will really go down to a leaf article first, before slowly
5909   ;; working its way up towards the root.
5910   (when thread
5911     (let ((children
5912            (if (cdr thread)
5913                (apply '+ (mapcar 'gnus-summary-limit-children
5914                                  (cdr thread)))
5915              0))
5916           (number (mail-header-number (car thread)))
5917           score)
5918       (if (and
5919            (not (memq number gnus-newsgroup-marked))
5920            (or
5921             ;; If this article is dormant and has absolutely no visible
5922             ;; children, then this article isn't visible.
5923             (and (memq number gnus-newsgroup-dormant)
5924                  (zerop children))
5925             ;; If this is "fetch-old-headered" and there is no
5926             ;; visible children, then we don't want this article.
5927             (and (eq gnus-fetch-old-headers 'some)
5928                  (gnus-summary-article-ancient-p number)
5929                  (zerop children))
5930             ;; If this is a sparsely inserted article with no children,
5931             ;; we don't want it.
5932             (and (eq gnus-build-sparse-threads 'some)
5933                  (gnus-summary-article-sparse-p number)
5934                  (zerop children))
5935             ;; If we use expunging, and this article is really
5936             ;; low-scored, then we don't want this article.
5937             (when (and gnus-summary-expunge-below
5938                        (< (setq score
5939                                 (or (cdr (assq number gnus-newsgroup-scored))
5940                                     gnus-summary-default-score))
5941                           gnus-summary-expunge-below))
5942               ;; We increase the expunge-tally here, but that has
5943               ;; nothing to do with the limits, really.
5944               (incf gnus-newsgroup-expunged-tally)
5945               ;; We also mark as read here, if that's wanted.
5946               (when (and gnus-summary-mark-below
5947                          (< score gnus-summary-mark-below))
5948                 (setq gnus-newsgroup-unreads
5949                       (delq number gnus-newsgroup-unreads))
5950                 (if gnus-newsgroup-auto-expire
5951                     (push number gnus-newsgroup-expirable)
5952                   (push (cons number gnus-low-score-mark)
5953                         gnus-newsgroup-reads)))
5954               t)
5955             ;; Check NoCeM things.
5956             (if (and gnus-use-nocem
5957                      (gnus-nocem-unwanted-article-p
5958                       (mail-header-id (car thread))))
5959                 (progn
5960                   (setq gnus-newsgroup-reads 
5961                         (delq number gnus-newsgroup-unreads))
5962                   t))))
5963           ;; Nope, invisible article.
5964           0
5965         ;; Ok, this article is to be visible, so we add it to the limit
5966         ;; and return 1.
5967         (push number gnus-newsgroup-limit)
5968         1))))
5969
5970 (defun gnus-expunge-thread (thread)
5971   "Mark all articles in THREAD as read."
5972   (let* ((number (mail-header-number (car thread))))
5973     (incf gnus-newsgroup-expunged-tally)
5974     ;; We also mark as read here, if that's wanted.
5975     (setq gnus-newsgroup-unreads
5976           (delq number gnus-newsgroup-unreads))
5977     (if gnus-newsgroup-auto-expire
5978         (push number gnus-newsgroup-expirable)
5979       (push (cons number gnus-low-score-mark)
5980             gnus-newsgroup-reads)))
5981   ;; Go recursively through all subthreads.
5982   (mapcar 'gnus-expunge-thread (cdr thread)))
5983
5984 ;; Summary article oriented commands
5985
5986 (defun gnus-summary-refer-parent-article (n)
5987   "Refer parent article N times.
5988 If N is negative, go to ancestor -N instead.
5989 The difference between N and the number of articles fetched is returned."
5990   (interactive "p")
5991   (gnus-set-global-variables)
5992   (let ((skip 1)
5993         error header ref)
5994     (when (not (natnump n))
5995       (setq skip (abs n)
5996             n 1))
5997     (while (and (> n 0)
5998                 (not error))
5999       (setq header (gnus-summary-article-header))
6000       (if (and (eq (mail-header-number header)
6001                    (cdr gnus-article-current))
6002                (equal gnus-newsgroup-name
6003                       (car gnus-article-current)))
6004           ;; If we try to find the parent of the currently
6005           ;; displayed article, then we take a look at the actual
6006           ;; References header, since this is slightly more
6007           ;; reliable than the References field we got from the
6008           ;; server.
6009           (save-excursion
6010             (set-buffer gnus-original-article-buffer)
6011             (nnheader-narrow-to-headers)
6012             (unless (setq ref (message-fetch-field "references"))
6013               (setq ref (message-fetch-field "in-reply-to")))
6014             (widen))
6015         (setq ref
6016               ;; It's not the current article, so we take a bet on
6017               ;; the value we got from the server.
6018               (mail-header-references header)))
6019       (if (and ref
6020                (not (equal ref "")))
6021           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6022             (gnus-message 1 "Couldn't find parent"))
6023         (gnus-message 1 "No references in article %d"
6024                       (gnus-summary-article-number))
6025         (setq error t))
6026       (decf n))
6027     (gnus-summary-position-point)
6028     n))
6029
6030 (defun gnus-summary-refer-references ()
6031   "Fetch all articles mentioned in the References header.
6032 Return how many articles were fetched."
6033   (interactive)
6034   (gnus-set-global-variables)
6035   (let ((ref (mail-header-references (gnus-summary-article-header)))
6036         (current (gnus-summary-article-number))
6037         (n 0))
6038     (if (or (not ref)
6039             (equal ref ""))
6040         (error "No References in the current article")
6041       ;; For each Message-ID in the References header...
6042       (while (string-match "<[^>]*>" ref)
6043         (incf n)
6044         ;; ... fetch that article.
6045         (gnus-summary-refer-article
6046          (prog1 (match-string 0 ref)
6047            (setq ref (substring ref (match-end 0))))))
6048       (gnus-summary-goto-subject current)
6049       (gnus-summary-position-point)
6050       n)))
6051
6052 (defun gnus-summary-refer-article (message-id)
6053   "Fetch an article specified by MESSAGE-ID."
6054   (interactive "sMessage-ID: ")
6055   (when (and (stringp message-id)
6056              (not (zerop (length message-id))))
6057     ;; Construct the correct Message-ID if necessary.
6058     ;; Suggested by tale@pawl.rpi.edu.
6059     (unless (string-match "^<" message-id)
6060       (setq message-id (concat "<" message-id)))
6061     (unless (string-match ">$" message-id)
6062       (setq message-id (concat message-id ">")))
6063     (let* ((header (gnus-id-to-header message-id))
6064            (sparse (and header
6065                         (gnus-summary-article-sparse-p 
6066                          (mail-header-number header)))))
6067       (if header
6068           (prog1
6069               ;; The article is present in the buffer, to we just go to it.
6070               (gnus-summary-goto-article 
6071                (mail-header-number header) nil header)
6072             (when sparse
6073               (gnus-summary-update-article (mail-header-number header))))
6074         ;; We fetch the article
6075         (let ((gnus-override-method 
6076                (and (gnus-news-group-p gnus-newsgroup-name)
6077                     gnus-refer-article-method))
6078               number)
6079           ;; Start the special refer-article method, if necessary.
6080           (when (and gnus-refer-article-method
6081                      (gnus-news-group-p gnus-newsgroup-name))
6082             (gnus-check-server gnus-refer-article-method))
6083           ;; Fetch the header, and display the article.
6084           (if (setq number (gnus-summary-insert-subject message-id))
6085               (gnus-summary-select-article nil nil nil number)
6086             (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
6087
6088 (defun gnus-summary-enter-digest-group (&optional force)
6089   "Enter an nndoc group based on the current article.
6090 If FORCE, force a digest interpretation.  If not, try
6091 to guess what the document format is."
6092   (interactive "P")
6093   (gnus-set-global-variables)
6094   (let ((conf gnus-current-window-configuration))
6095     (save-excursion
6096       (gnus-summary-select-article))
6097     (setq gnus-current-window-configuration conf)
6098     (let* ((name (format "%s-%d"
6099                          (gnus-group-prefixed-name
6100                           gnus-newsgroup-name (list 'nndoc ""))
6101                          (save-excursion
6102                            (set-buffer gnus-summary-buffer)
6103                            gnus-current-article)))
6104            (ogroup gnus-newsgroup-name)
6105            (params (append (gnus-info-params (gnus-get-info ogroup))
6106                            (list (cons 'to-group ogroup))))
6107            (case-fold-search t)
6108            (buf (current-buffer))
6109            dig)
6110       (save-excursion
6111         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6112         (insert-buffer-substring gnus-original-article-buffer)
6113         ;; Remove lines that may lead nndoc to misinterpret the
6114         ;; document type.
6115         (narrow-to-region
6116          (goto-char (point-min))
6117          (or (search-forward "\n\n" nil t) (point)))
6118         (goto-char (point-min))
6119         (delete-matching-lines "^\\(Path\\):\\|^From ")
6120         (widen))
6121       (unwind-protect
6122           (if (gnus-group-read-ephemeral-group
6123                name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6124                             (nndoc-article-type 
6125                              ,(if force 'digest 'guess))) t)
6126               ;; Make all postings to this group go to the parent group.
6127               (nconc (gnus-info-params (gnus-get-info name))
6128                      params)
6129             ;; Couldn't select this doc group.
6130             (switch-to-buffer buf)
6131             (gnus-set-global-variables)
6132             (gnus-configure-windows 'summary)
6133             (gnus-message 3 "Article couldn't be entered?"))
6134         (kill-buffer dig)))))
6135
6136 (defun gnus-summary-read-document (n)
6137   "Open a new group based on the current article(s).
6138 This will allow you to read digests and other similar
6139 documents as newsgroups.
6140 Obeys the standard process/prefix convention."
6141   (interactive "P")
6142   (let* ((articles (gnus-summary-work-articles n))
6143          (ogroup gnus-newsgroup-name)
6144          (params (append (gnus-info-params (gnus-get-info ogroup))
6145                          (list (cons 'to-group ogroup))))
6146          article group egroup groups vgroup)
6147     (while (setq article (pop articles))
6148       (setq group (format "%s-%d" gnus-newsgroup-name article))
6149       (gnus-summary-remove-process-mark article)
6150       (when (gnus-summary-display-article article)
6151         (save-excursion
6152           (nnheader-temp-write nil
6153             (insert-buffer-substring gnus-original-article-buffer)
6154             ;; Remove some headers that may lead nndoc to make
6155             ;; the wrong guess.
6156             (message-narrow-to-head)
6157             (goto-char (point-min))
6158             (delete-matching-lines "^\\(Path\\):\\|^From ")
6159             (widen)
6160             (if (setq egroup
6161                       (gnus-group-read-ephemeral-group
6162                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6163                                      (nndoc-article-type guess))
6164                        t nil t))
6165                 (progn
6166                   ;; Make all postings to this group go to the parent group.
6167                   (nconc (gnus-info-params (gnus-get-info egroup))
6168                          params)
6169                   (push egroup groups))
6170               ;; Couldn't select this doc group.
6171               (gnus-error 3 "Article couldn't be entered"))))))
6172     ;; Now we have selected all the documents.
6173     (cond
6174      ((not groups)
6175       (error "None of the articles could be interpreted as documents"))
6176      ((gnus-group-read-ephemeral-group
6177        (setq vgroup (format
6178                      "nnvirtual:%s-%s" gnus-newsgroup-name
6179                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6180        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6181        t
6182        (cons (current-buffer) 'summary)))
6183      (t
6184       (error "Couldn't select virtual nndoc group")))))
6185       
6186 (defun gnus-summary-isearch-article (&optional regexp-p)
6187   "Do incremental search forward on the current article.
6188 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6189   (interactive "P")
6190   (gnus-set-global-variables)
6191   (gnus-summary-select-article)
6192   (gnus-configure-windows 'article)
6193   (gnus-eval-in-buffer-window gnus-article-buffer
6194     ;;(goto-char (point-min))
6195     (isearch-forward regexp-p)))
6196
6197 (defun gnus-summary-search-article-forward (regexp &optional backward)
6198   "Search for an article containing REGEXP forward.
6199 If BACKWARD, search backward instead."
6200   (interactive
6201    (list (read-string
6202           (format "Search article %s (regexp%s): "
6203                   (if current-prefix-arg "backward" "forward")
6204                   (if gnus-last-search-regexp
6205                       (concat ", default " gnus-last-search-regexp)
6206                     "")))
6207          current-prefix-arg))
6208   (gnus-set-global-variables)
6209   (if (string-equal regexp "")
6210       (setq regexp (or gnus-last-search-regexp ""))
6211     (setq gnus-last-search-regexp regexp))
6212   (if (gnus-summary-search-article regexp backward)
6213       (gnus-summary-show-thread)
6214     (error "Search failed: \"%s\"" regexp)))
6215
6216 (defun gnus-summary-search-article-backward (regexp)
6217   "Search for an article containing REGEXP backward."
6218   (interactive
6219    (list (read-string
6220           (format "Search article backward (regexp%s): "
6221                   (if gnus-last-search-regexp
6222                       (concat ", default " gnus-last-search-regexp)
6223                     "")))))
6224   (gnus-summary-search-article-forward regexp 'backward))
6225
6226 (defun gnus-summary-search-article (regexp &optional backward)
6227   "Search for an article containing REGEXP.
6228 Optional argument BACKWARD means do search for backward.
6229 `gnus-select-article-hook' is not called during the search."
6230   (let ((gnus-select-article-hook nil)  ;Disable hook.
6231         (gnus-article-display-hook nil)
6232         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
6233         (gnus-use-article-prefetch nil)
6234         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
6235         (sum (current-buffer))
6236         (found nil)
6237         point)
6238     (gnus-save-hidden-threads
6239       (gnus-summary-select-article)
6240       (set-buffer gnus-article-buffer)
6241       (when backward
6242         (forward-line -1))
6243       (while (not found)
6244         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
6245         (if (if backward
6246                 (re-search-backward regexp nil t)
6247               (re-search-forward regexp nil t))
6248             ;; We found the regexp.
6249             (progn
6250               (setq found 'found)
6251               (beginning-of-line)
6252               (set-window-start
6253                (get-buffer-window (current-buffer))
6254                (point))
6255               (forward-line 1)
6256               (set-buffer sum)
6257               (setq point (point)))
6258           ;; We didn't find it, so we go to the next article.
6259           (set-buffer sum)
6260           (setq found 'not)
6261           (while (eq found 'not)
6262             (if (not (if backward (gnus-summary-find-prev)
6263                        (gnus-summary-find-next)))
6264                 ;; No more articles.
6265                 (setq found t)
6266               ;; Select the next article and adjust point.
6267               (unless (gnus-summary-article-sparse-p
6268                        (gnus-summary-article-number))
6269                 (setq found nil)
6270                 (gnus-summary-select-article)
6271                 (set-buffer gnus-article-buffer)
6272                 (widen)
6273                 (goto-char (if backward (point-max) (point-min))))))))
6274       (gnus-message 7 ""))
6275     ;; Return whether we found the regexp.
6276     (when (eq found 'found)
6277       (goto-char point)
6278       (gnus-summary-show-thread)
6279       (gnus-summary-goto-subject gnus-current-article)
6280       (gnus-summary-position-point)
6281       t)))
6282
6283 (defun gnus-summary-find-matching (header regexp &optional backward unread
6284                                           not-case-fold)
6285   "Return a list of all articles that match REGEXP on HEADER.
6286 The search stars on the current article and goes forwards unless
6287 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
6288 If UNREAD is non-nil, only unread articles will
6289 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
6290 in the comparisons."
6291   (let ((data (if (eq backward 'all) gnus-newsgroup-data
6292                 (gnus-data-find-list
6293                  (gnus-summary-article-number) (gnus-data-list backward))))
6294         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
6295         (case-fold-search (not not-case-fold))
6296         articles d)
6297     (unless (fboundp (intern (concat "mail-header-" header)))
6298       (error "%s is not a valid header" header))
6299     (while data
6300       (setq d (car data))
6301       (and (or (not unread)             ; We want all articles...
6302                (gnus-data-unread-p d))  ; Or just unreads.
6303            (vectorp (gnus-data-header d)) ; It's not a pseudo.
6304            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
6305            (push (gnus-data-number d) articles)) ; Success!
6306       (setq data (cdr data)))
6307     (nreverse articles)))
6308
6309 (defun gnus-summary-execute-command (header regexp command &optional backward)
6310   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
6311 If HEADER is an empty string (or nil), the match is done on the entire
6312 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
6313   (interactive
6314    (list (let ((completion-ignore-case t))
6315            (completing-read
6316             "Header name: "
6317             (mapcar (lambda (string) (list string))
6318                     '("Number" "Subject" "From" "Lines" "Date"
6319                       "Message-ID" "Xref" "References" "Body"))
6320             nil 'require-match))
6321          (read-string "Regexp: ")
6322          (read-key-sequence "Command: ")
6323          current-prefix-arg))
6324   (when (equal header "Body")
6325     (setq header ""))
6326   (gnus-set-global-variables)
6327   ;; Hidden thread subtrees must be searched as well.
6328   (gnus-summary-show-all-threads)
6329   ;; We don't want to change current point nor window configuration.
6330   (save-excursion
6331     (save-window-excursion
6332       (gnus-message 6 "Executing %s..." (key-description command))
6333       ;; We'd like to execute COMMAND interactively so as to give arguments.
6334       (gnus-execute header regexp
6335                     `(call-interactively ',(key-binding command))
6336                     backward)
6337       (gnus-message 6 "Executing %s...done" (key-description command)))))
6338
6339 (defun gnus-summary-beginning-of-article ()
6340   "Scroll the article back to the beginning."
6341   (interactive)
6342   (gnus-set-global-variables)
6343   (gnus-summary-select-article)
6344   (gnus-configure-windows 'article)
6345   (gnus-eval-in-buffer-window gnus-article-buffer
6346     (widen)
6347     (goto-char (point-min))
6348     (when gnus-break-pages
6349       (gnus-narrow-to-page))))
6350
6351 (defun gnus-summary-end-of-article ()
6352   "Scroll to the end of the article."
6353   (interactive)
6354   (gnus-set-global-variables)
6355   (gnus-summary-select-article)
6356   (gnus-configure-windows 'article)
6357   (gnus-eval-in-buffer-window gnus-article-buffer
6358     (widen)
6359     (goto-char (point-max))
6360     (recenter -3)
6361     (when gnus-break-pages
6362       (gnus-narrow-to-page))))
6363
6364 (defun gnus-summary-print-article (&optional filename)
6365   "Generate and print a PostScript image of the article buffer.
6366
6367 If the optional argument FILENAME is nil, send the image to the printer.
6368 If FILENAME is a string, save the PostScript image in a file with that
6369 name.  If FILENAME is a number, prompt the user for the name of the file
6370 to save in."
6371   (interactive (list (ps-print-preprint current-prefix-arg)))
6372   (gnus-summary-select-article)
6373   (gnus-eval-in-buffer-window gnus-article-buffer
6374     (let ((buffer (generate-new-buffer " *print*")))
6375       (unwind-protect
6376           (progn
6377             (copy-to-buffer buffer (point-min) (point-max))
6378             (set-buffer buffer)
6379             (gnus-article-delete-invisible-text)
6380             (run-hooks 'gnus-ps-print-hook)
6381             (ps-print-buffer-with-faces filename))
6382         (kill-buffer buffer)))))
6383
6384 (defun gnus-summary-show-article (&optional arg)
6385   "Force re-fetching of the current article.
6386 If ARG (the prefix) is non-nil, show the raw article without any
6387 article massaging functions being run."
6388   (interactive "P")
6389   (gnus-set-global-variables)
6390   (if (not arg)
6391       ;; Select the article the normal way.
6392       (gnus-summary-select-article nil 'force)
6393     ;; Bind the article treatment functions to nil.
6394     (let ((gnus-have-all-headers t)
6395           gnus-article-display-hook
6396           gnus-article-prepare-hook
6397           gnus-break-pages
6398           gnus-visual)
6399       (gnus-summary-select-article nil 'force)))
6400   (gnus-summary-goto-subject gnus-current-article)
6401                                         ;  (gnus-configure-windows 'article)
6402   (gnus-summary-position-point))
6403
6404 (defun gnus-summary-verbose-headers (&optional arg)
6405   "Toggle permanent full header display.
6406 If ARG is a positive number, turn header display on.
6407 If ARG is a negative number, turn header display off."
6408   (interactive "P")
6409   (gnus-set-global-variables)
6410   (setq gnus-show-all-headers
6411         (cond ((or (not (numberp arg))
6412                    (zerop arg))
6413                (not gnus-show-all-headers))
6414               ((natnump arg)
6415                t)))
6416   (gnus-summary-show-article))
6417
6418 (defun gnus-summary-toggle-header (&optional arg)
6419   "Show the headers if they are hidden, or hide them if they are shown.
6420 If ARG is a positive number, show the entire header.
6421 If ARG is a negative number, hide the unwanted header lines."
6422   (interactive "P")
6423   (gnus-set-global-variables)
6424   (save-excursion
6425     (set-buffer gnus-article-buffer)
6426     (let* ((buffer-read-only nil)
6427            (inhibit-point-motion-hooks t)
6428            (hidden (text-property-any
6429                     (goto-char (point-min)) (search-forward "\n\n")
6430                     'invisible t))
6431            e)
6432       (goto-char (point-min))
6433       (when (search-forward "\n\n" nil t)
6434         (delete-region (point-min) (1- (point))))
6435       (goto-char (point-min))
6436       (save-excursion
6437         (set-buffer gnus-original-article-buffer)
6438         (goto-char (point-min))
6439         (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
6440       (insert-buffer-substring gnus-original-article-buffer 1 e)
6441       (let ((article-inhibit-hiding t))
6442         (run-hooks 'gnus-article-display-hook))
6443       (when (or (not hidden) (and (numberp arg) (< arg 0)))
6444         (gnus-article-hide-headers)))))
6445
6446 (defun gnus-summary-show-all-headers ()
6447   "Make all header lines visible."
6448   (interactive)
6449   (gnus-set-global-variables)
6450   (gnus-article-show-all-headers))
6451
6452 (defun gnus-summary-toggle-mime (&optional arg)
6453   "Toggle MIME processing.
6454 If ARG is a positive number, turn MIME processing on."
6455   (interactive "P")
6456   (gnus-set-global-variables)
6457   (setq gnus-show-mime
6458         (if (null arg) (not gnus-show-mime)
6459           (> (prefix-numeric-value arg) 0)))
6460   (gnus-summary-select-article t 'force))
6461
6462 (defun gnus-summary-caesar-message (&optional arg)
6463   "Caesar rotate the current article by 13.
6464 The numerical prefix specifies how many places to rotate each letter
6465 forward."
6466   (interactive "P")
6467   (gnus-set-global-variables)
6468   (gnus-summary-select-article)
6469   (let ((mail-header-separator ""))
6470     (gnus-eval-in-buffer-window gnus-article-buffer
6471       (save-restriction
6472         (widen)
6473         (let ((start (window-start))
6474               buffer-read-only)
6475           (message-caesar-buffer-body arg)
6476           (set-window-start (get-buffer-window (current-buffer)) start))))))
6477
6478 (defun gnus-summary-stop-page-breaking ()
6479   "Stop page breaking in the current article."
6480   (interactive)
6481   (gnus-set-global-variables)
6482   (gnus-summary-select-article)
6483   (gnus-eval-in-buffer-window gnus-article-buffer
6484     (widen)
6485     (when (gnus-visual-p 'page-marker)
6486       (let ((buffer-read-only nil))
6487         (gnus-remove-text-with-property 'gnus-prev)
6488         (gnus-remove-text-with-property 'gnus-next)))))
6489
6490 (defun gnus-summary-move-article (&optional n to-newsgroup 
6491                                             select-method action)
6492   "Move the current article to a different newsgroup.
6493 If N is a positive number, move the N next articles.
6494 If N is a negative number, move the N previous articles.
6495 If N is nil and any articles have been marked with the process mark,
6496 move those articles instead.
6497 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
6498 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
6499 re-spool using this method.
6500
6501 For this function to work, both the current newsgroup and the
6502 newsgroup that you want to move to have to support the `request-move'
6503 and `request-accept' functions."
6504   (interactive "P")
6505   (unless action
6506     (setq action 'move))
6507   (gnus-set-global-variables)
6508   ;; Disable marking as read.
6509   (let (gnus-mark-article-hook)
6510     (save-window-excursion
6511       (gnus-summary-select-article)))
6512   ;; Check whether the source group supports the required functions.
6513   (cond ((and (eq action 'move)
6514               (not (gnus-check-backend-function
6515                     'request-move-article gnus-newsgroup-name)))
6516          (error "The current group does not support article moving"))
6517         ((and (eq action 'crosspost)
6518               (not (gnus-check-backend-function
6519                     'request-replace-article gnus-newsgroup-name)))
6520          (error "The current group does not support article editing")))
6521   (let ((articles (gnus-summary-work-articles n))
6522         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
6523         (names '((move "Move" "Moving")
6524                  (copy "Copy" "Copying")
6525                  (crosspost "Crosspost" "Crossposting")))
6526         (copy-buf (save-excursion
6527                     (nnheader-set-temp-buffer " *copy article*")))
6528         art-group to-method new-xref article to-groups)
6529     (unless (assq action names)
6530       (error "Unknown action %s" action))
6531     ;; Read the newsgroup name.
6532     (when (and (not to-newsgroup)
6533                (not select-method))
6534       (setq to-newsgroup
6535             (gnus-read-move-group-name
6536              (cadr (assq action names))
6537              (symbol-value (intern (format "gnus-current-%s-group" action)))
6538              articles prefix))
6539       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
6540     (setq to-method (or select-method 
6541                         (gnus-group-name-to-method to-newsgroup)))
6542     ;; Check the method we are to move this article to...
6543     (unless (gnus-check-backend-function 
6544              'request-accept-article (car to-method))
6545       (error "%s does not support article copying" (car to-method)))
6546     (unless (gnus-check-server to-method)
6547       (error "Can't open server %s" (car to-method)))
6548     (gnus-message 6 "%s to %s: %s..."
6549                   (caddr (assq action names))
6550                   (or (car select-method) to-newsgroup) articles)
6551     (while articles
6552       (setq article (pop articles))
6553       (setq
6554        art-group
6555        (cond
6556         ;; Move the article.
6557         ((eq action 'move)
6558          (gnus-request-move-article
6559           article                       ; Article to move
6560           gnus-newsgroup-name           ; From newsgroup
6561           (nth 1 (gnus-find-method-for-group
6562                   gnus-newsgroup-name)) ; Server
6563           (list 'gnus-request-accept-article
6564                 to-newsgroup (list 'quote select-method)
6565                 (not articles))         ; Accept form
6566           (not articles)))              ; Only save nov last time
6567         ;; Copy the article.
6568         ((eq action 'copy)
6569          (save-excursion
6570            (set-buffer copy-buf)
6571            (gnus-request-article-this-buffer article gnus-newsgroup-name)
6572            (gnus-request-accept-article
6573             to-newsgroup select-method (not articles))))
6574         ;; Crosspost the article.
6575         ((eq action 'crosspost)
6576          (let ((xref (message-tokenize-header
6577                       (mail-header-xref (gnus-summary-article-header article))
6578                       " ")))
6579            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
6580                                   ":" article))
6581            (unless xref 
6582              (setq xref (list (system-name))))
6583            (setq new-xref
6584                  (concat
6585                   (mapconcat 'identity 
6586                              (delete "Xref:" (delete new-xref xref))
6587                              " ")
6588                   " " new-xref))
6589            (save-excursion
6590              (set-buffer copy-buf)
6591              ;; First put the article in the destination group.
6592              (gnus-request-article-this-buffer article gnus-newsgroup-name)
6593              (setq art-group
6594                    (gnus-request-accept-article
6595                     to-newsgroup select-method (not articles)))
6596              (setq new-xref (concat new-xref " " (car art-group)
6597                                     ":" (cdr art-group)))
6598              ;; Now we have the new Xrefs header, so we insert
6599              ;; it and replace the new article.
6600              (nnheader-replace-header "Xref" new-xref)
6601              (gnus-request-replace-article
6602               (cdr art-group) to-newsgroup (current-buffer))
6603              art-group)))))
6604       (if (not art-group)
6605           (gnus-message 1 "Couldn't %s article %s"
6606                         (cadr (assq action names)) article)
6607         (let* ((entry
6608                 (or
6609                  (gnus-gethash (car art-group) gnus-newsrc-hashtb)
6610                  (gnus-gethash
6611                   (gnus-group-prefixed-name
6612                    (car art-group)
6613                    (or select-method 
6614                        (gnus-find-method-for-group to-newsgroup)))
6615                   gnus-newsrc-hashtb)))
6616                (info (nth 2 entry))
6617                (to-group (gnus-info-group info)))
6618           ;; Update the group that has been moved to.
6619           (when (and info
6620                      (memq action '(move copy)))
6621             (unless (member to-group to-groups)
6622               (push to-group to-groups))
6623
6624             (unless (memq article gnus-newsgroup-unreads)
6625               (gnus-info-set-read
6626                info (gnus-add-to-range (gnus-info-read info)
6627                                        (list (cdr art-group)))))
6628
6629             ;; Copy any marks over to the new group.
6630             (let ((marks gnus-article-mark-lists)
6631                   (to-article (cdr art-group)))
6632
6633               ;; See whether the article is to be put in the cache.
6634               (when gnus-use-cache
6635                 (gnus-cache-possibly-enter-article
6636                  to-group to-article
6637                  (let ((header (copy-sequence
6638                                 (gnus-summary-article-header article))))
6639                    (mail-header-set-number header to-article)
6640                    header)
6641                  (memq article gnus-newsgroup-marked)
6642                  (memq article gnus-newsgroup-dormant)
6643                  (memq article gnus-newsgroup-unreads)))
6644
6645               (when (and (equal to-group gnus-newsgroup-name)
6646                          (not (memq article gnus-newsgroup-unreads)))
6647                 ;; Mark this article as read in this group.
6648                 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
6649                 (setcdr (gnus-active to-group) to-article)
6650                 (setcdr gnus-newsgroup-active to-article))
6651               
6652               (while marks
6653                 (when (memq article (symbol-value
6654                                      (intern (format "gnus-newsgroup-%s"
6655                                                      (caar marks)))))
6656                   ;; If the other group is the same as this group,
6657                   ;; then we have to add the mark to the list.
6658                   (when (equal to-group gnus-newsgroup-name)
6659                     (set (intern (format "gnus-newsgroup-%s" (caar marks)))
6660                          (cons to-article
6661                                (symbol-value
6662                                 (intern (format "gnus-newsgroup-%s"
6663                                                 (caar marks)))))))
6664                   ;; Copy the marks to other group.
6665                   (gnus-add-marked-articles
6666                    to-group (cdar marks) (list to-article) info))
6667                 (setq marks (cdr marks)))))
6668
6669           ;; Update the Xref header in this article to point to
6670           ;; the new crossposted article we have just created.
6671           (when (eq action 'crosspost)
6672             (save-excursion
6673               (set-buffer copy-buf)
6674               (gnus-request-article-this-buffer article gnus-newsgroup-name)
6675               (nnheader-replace-header "Xref" new-xref)
6676               (gnus-request-replace-article
6677                article gnus-newsgroup-name (current-buffer)))))
6678
6679         (gnus-summary-goto-subject article)
6680         (when (eq action 'move)
6681           (gnus-summary-mark-article article gnus-canceled-mark)))
6682       (gnus-summary-remove-process-mark article))
6683     ;; Re-activate all groups that have been moved to.
6684     (while to-groups
6685       (gnus-activate-group (pop to-groups)))
6686     
6687     (gnus-kill-buffer copy-buf)
6688     (gnus-summary-position-point)
6689     (gnus-set-mode-line 'summary)))
6690
6691 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
6692   "Move the current article to a different newsgroup.
6693 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
6694 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
6695 re-spool using this method."
6696   (interactive "P")
6697   (gnus-summary-move-article n to-newsgroup select-method 'copy))
6698
6699 (defun gnus-summary-crosspost-article (&optional n)
6700   "Crosspost the current article to some other group."
6701   (interactive "P")
6702   (gnus-summary-move-article n nil nil 'crosspost))
6703
6704 (defcustom gnus-summary-respool-default-method nil
6705   "Default method for respooling an article.  
6706 If nil, use to the current newsgroup method."
6707   :type 'gnus-select-method-name
6708   :group 'gnus-summary-mail)
6709
6710 (defun gnus-summary-respool-article (&optional n method)
6711   "Respool the current article.
6712 The article will be squeezed through the mail spooling process again,
6713 which means that it will be put in some mail newsgroup or other
6714 depending on `nnmail-split-methods'.
6715 If N is a positive number, respool the N next articles.
6716 If N is a negative number, respool the N previous articles.
6717 If N is nil and any articles have been marked with the process mark,
6718 respool those articles instead.
6719
6720 Respooling can be done both from mail groups and \"real\" newsgroups.
6721 In the former case, the articles in question will be moved from the
6722 current group into whatever groups they are destined to.  In the
6723 latter case, they will be copied into the relevant groups."
6724   (interactive 
6725    (list current-prefix-arg
6726          (let* ((methods (gnus-methods-using 'respool))
6727                 (methname
6728                  (symbol-name (or gnus-summary-respool-default-method
6729                                   (car (gnus-find-method-for-group
6730                                         gnus-newsgroup-name)))))
6731                 (method
6732                  (gnus-completing-read 
6733                   methname "What backend do you want to use when respooling?"
6734                   methods nil t nil 'gnus-mail-method-history))
6735                 ms)
6736            (cond
6737             ((zerop (length (setq ms (gnus-servers-using-backend 
6738                                       (intern method)))))
6739              (list (intern method) ""))
6740             ((= 1 (length ms))
6741              (car ms))
6742             (t
6743              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
6744                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
6745                            ms-alist))))))))
6746   (gnus-set-global-variables)
6747   (unless method
6748     (error "No method given for respooling"))
6749   (if (assoc (symbol-name
6750               (car (gnus-find-method-for-group gnus-newsgroup-name)))
6751              (gnus-methods-using 'respool))
6752       (gnus-summary-move-article n nil method)
6753     (gnus-summary-copy-article n nil method)))
6754
6755 (defun gnus-summary-import-article (file)
6756   "Import a random file into a mail newsgroup."
6757   (interactive "fImport file: ")
6758   (gnus-set-global-variables)
6759   (let ((group gnus-newsgroup-name)
6760         (now (current-time))
6761         atts lines)
6762     (unless (gnus-check-backend-function 'request-accept-article group)
6763       (error "%s does not support article importing" group))
6764     (or (file-readable-p file)
6765         (not (file-regular-p file))
6766         (error "Can't read %s" file))
6767     (save-excursion
6768       (set-buffer (get-buffer-create " *import file*"))
6769       (buffer-disable-undo (current-buffer))
6770       (erase-buffer)
6771       (insert-file-contents file)
6772       (goto-char (point-min))
6773       (unless (nnheader-article-p)
6774         ;; This doesn't look like an article, so we fudge some headers.
6775         (setq atts (file-attributes file)
6776               lines (count-lines (point-min) (point-max)))
6777         (insert "From: " (read-string "From: ") "\n"
6778                 "Subject: " (read-string "Subject: ") "\n"
6779                 "Date: " (timezone-make-date-arpa-standard
6780                           (current-time-string (nth 5 atts))
6781                           (current-time-zone now)
6782                           (current-time-zone now))
6783                 "\n"
6784                 "Message-ID: " (message-make-message-id) "\n"
6785                 "Lines: " (int-to-string lines) "\n"
6786                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
6787       (gnus-request-accept-article group nil t)
6788       (kill-buffer (current-buffer)))))
6789
6790 (defun gnus-summary-article-posted-p ()
6791   "Say whether the current (mail) article is available from `gnus-select-method' as well.
6792 This will be the case if the article has both been mailed and posted."
6793   (interactive)
6794   (let ((id (mail-header-references (gnus-summary-article-header)))
6795         (gnus-override-method
6796          (or gnus-refer-article-method gnus-select-method)))
6797     (if (gnus-request-head id "")
6798         (gnus-message 2 "The current message was found on %s"
6799                       gnus-override-method)
6800       (gnus-message 2 "The current message couldn't be found on %s"
6801                     gnus-override-method)
6802       nil)))
6803
6804 (defun gnus-summary-expire-articles (&optional now)
6805   "Expire all articles that are marked as expirable in the current group."
6806   (interactive)
6807   (gnus-set-global-variables)
6808   (when (gnus-check-backend-function
6809          'request-expire-articles gnus-newsgroup-name)
6810     ;; This backend supports expiry.
6811     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
6812            (expirable (if total
6813                           (progn
6814                             ;; We need to update the info for
6815                             ;; this group for `gnus-list-of-read-articles'
6816                             ;; to give us the right answer.
6817                             (run-hooks 'gnus-exit-group-hook)
6818                             (gnus-summary-update-info)
6819                             (gnus-list-of-read-articles gnus-newsgroup-name))
6820                         (setq gnus-newsgroup-expirable
6821                               (sort gnus-newsgroup-expirable '<))))
6822            (expiry-wait (if now 'immediate
6823                           (gnus-group-find-parameter
6824                            gnus-newsgroup-name 'expiry-wait)))
6825            es)
6826       (when expirable
6827         ;; There are expirable articles in this group, so we run them
6828         ;; through the expiry process.
6829         (gnus-message 6 "Expiring articles...")
6830         ;; The list of articles that weren't expired is returned.
6831         (if expiry-wait
6832             (let ((nnmail-expiry-wait-function nil)
6833                   (nnmail-expiry-wait expiry-wait))
6834               (setq es (gnus-request-expire-articles
6835                         expirable gnus-newsgroup-name)))
6836           (setq es (gnus-request-expire-articles
6837                     expirable gnus-newsgroup-name)))
6838         (unless total
6839           (setq gnus-newsgroup-expirable es))
6840         ;; We go through the old list of expirable, and mark all
6841         ;; really expired articles as nonexistent.
6842         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
6843           (let ((gnus-use-cache nil))
6844             (while expirable
6845               (unless (memq (car expirable) es)
6846                 (when (gnus-data-find (car expirable))
6847                   (gnus-summary-mark-article
6848                    (car expirable) gnus-canceled-mark)))
6849               (setq expirable (cdr expirable)))))
6850         (gnus-message 6 "Expiring articles...done")))))
6851
6852 (defun gnus-summary-expire-articles-now ()
6853   "Expunge all expirable articles in the current group.
6854 This means that *all* articles that are marked as expirable will be
6855 deleted forever, right now."
6856   (interactive)
6857   (gnus-set-global-variables)
6858   (or gnus-expert-user
6859       (gnus-yes-or-no-p
6860        "Are you really, really, really sure you want to delete all these messages? ")
6861       (error "Phew!"))
6862   (gnus-summary-expire-articles t))
6863
6864 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
6865 (defun gnus-summary-delete-article (&optional n)
6866   "Delete the N next (mail) articles.
6867 This command actually deletes articles.  This is not a marking
6868 command.  The article will disappear forever from your life, never to
6869 return.
6870 If N is negative, delete backwards.
6871 If N is nil and articles have been marked with the process mark,
6872 delete these instead."
6873   (interactive "P")
6874   (gnus-set-global-variables)
6875   (unless (gnus-check-backend-function 'request-expire-articles
6876                                        gnus-newsgroup-name)
6877     (error "The current newsgroup does not support article deletion."))
6878   ;; Compute the list of articles to delete.
6879   (let ((articles (gnus-summary-work-articles n))
6880         not-deleted)
6881     (if (and gnus-novice-user
6882              (not (gnus-yes-or-no-p
6883                    (format "Do you really want to delete %s forever? "
6884                            (if (> (length articles) 1)
6885                                (format "these %s articles" (length articles))
6886                              "this article")))))
6887         ()
6888       ;; Delete the articles.
6889       (setq not-deleted (gnus-request-expire-articles
6890                          articles gnus-newsgroup-name 'force))
6891       (while articles
6892         (gnus-summary-remove-process-mark (car articles))
6893         ;; The backend might not have been able to delete the article
6894         ;; after all.
6895         (unless (memq (car articles) not-deleted)
6896           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
6897         (setq articles (cdr articles)))
6898       (when not-deleted
6899         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
6900     (gnus-summary-position-point)
6901     (gnus-set-mode-line 'summary)
6902     not-deleted))
6903
6904 (defun gnus-summary-edit-article (&optional force)
6905   "Edit the current article.
6906 This will have permanent effect only in mail groups.
6907 If FORCE is non-nil, allow editing of articles even in read-only
6908 groups." 
6909   (interactive "P")
6910   (save-excursion
6911     (set-buffer gnus-summary-buffer)
6912     (gnus-set-global-variables)
6913     (when (and (not force)
6914                (gnus-group-read-only-p))
6915       (error "The current newsgroup does not support article editing."))
6916     ;; Select article if needed.
6917     (unless (eq (gnus-summary-article-number)
6918                 gnus-current-article)
6919       (gnus-summary-select-article t))
6920     (gnus-article-edit-article
6921      `(lambda ()
6922         (gnus-summary-edit-article-done
6923          ,(or (mail-header-references gnus-current-headers) "")
6924          ,(gnus-group-read-only-p) ,gnus-summary-buffer)))))
6925
6926 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
6927
6928 (defun gnus-summary-edit-article-done (&optional references read-only buffer)
6929   "Make edits to the current article permanent."
6930   (interactive)
6931   ;; Replace the article.
6932   (if (and (not read-only)
6933            (not (gnus-request-replace-article
6934                  (cdr gnus-article-current) (car gnus-article-current)
6935                  (current-buffer))))
6936       (error "Couldn't replace article.")
6937     ;; Update the summary buffer.
6938     (if (and references
6939              (equal (message-tokenize-header references " ")
6940                     (message-tokenize-header
6941                      (or (message-fetch-field "references") "") " ")))
6942         ;; We only have to update this line.
6943         (save-excursion
6944           (save-restriction
6945             (message-narrow-to-head)
6946             (let ((head (buffer-string))
6947                   header)
6948               (nnheader-temp-write nil
6949                 (insert (format "211 %d Article retrieved.\n"
6950                                 (cdr gnus-article-current)))
6951                 (insert head)
6952                 (insert ".\n")
6953                 (let ((nntp-server-buffer (current-buffer)))
6954                   (setq header (car (gnus-get-newsgroup-headers
6955                                      (save-excursion
6956                                        (set-buffer gnus-summary-buffer)
6957                                        gnus-newsgroup-dependencies)
6958                                      t))))
6959                 (save-excursion
6960                   (set-buffer gnus-summary-buffer)
6961                   (gnus-data-set-header
6962                    (gnus-data-find (cdr gnus-article-current))
6963                    header)
6964                   (gnus-summary-update-article-line
6965                    (cdr gnus-article-current) header))))))
6966       ;; Update threads.
6967       (set-buffer (or buffer gnus-summary-buffer))
6968       (gnus-summary-update-article (cdr gnus-article-current)))
6969     ;; Prettify the article buffer again.
6970     (save-excursion
6971       (set-buffer gnus-article-buffer)
6972       (run-hooks 'gnus-article-display-hook)
6973       (set-buffer gnus-original-article-buffer)
6974       (gnus-request-article
6975        (cdr gnus-article-current) (car gnus-article-current) (current-buffer)))
6976     ;; Prettify the summary buffer line.
6977     (when (gnus-visual-p 'summary-highlight 'highlight)
6978       (run-hooks 'gnus-visual-mark-article-hook))))
6979
6980 (defun gnus-summary-edit-wash (key)
6981   "Perform editing command in the article buffer."
6982   (interactive 
6983    (list
6984     (progn
6985       (message "%s" (concat (this-command-keys) "- "))
6986       (read-char))))
6987   (message "")
6988   (gnus-summary-edit-article)
6989   (execute-kbd-macro (concat (this-command-keys) key))
6990   (gnus-article-edit-done))
6991
6992 ;;; Respooling
6993
6994 (defun gnus-summary-respool-query ()
6995   "Query where the respool algorithm would put this article."
6996   (interactive)
6997   (gnus-set-global-variables)
6998   (let (gnus-mark-article-hook)
6999     (gnus-summary-select-article)
7000     (save-excursion
7001       (set-buffer gnus-original-article-buffer)
7002       (save-restriction
7003         (message-narrow-to-head)
7004         (message "This message would go to %s"
7005                  (mapconcat 'car (nnmail-article-group 'identity) ", "))))))
7006
7007 ;; Summary marking commands.
7008
7009 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7010   "Mark articles which has the same subject as read, and then select the next.
7011 If UNMARK is positive, remove any kind of mark.
7012 If UNMARK is negative, tick articles."
7013   (interactive "P")
7014   (gnus-set-global-variables)
7015   (when unmark
7016     (setq unmark (prefix-numeric-value unmark)))
7017   (let ((count
7018          (gnus-summary-mark-same-subject
7019           (gnus-summary-article-subject) unmark)))
7020     ;; Select next unread article.  If auto-select-same mode, should
7021     ;; select the first unread article.
7022     (gnus-summary-next-article t (and gnus-auto-select-same
7023                                       (gnus-summary-article-subject)))
7024     (gnus-message 7 "%d article%s marked as %s"
7025                   count (if (= count 1) " is" "s are")
7026                   (if unmark "unread" "read"))))
7027
7028 (defun gnus-summary-kill-same-subject (&optional unmark)
7029   "Mark articles which has the same subject as read.
7030 If UNMARK is positive, remove any kind of mark.
7031 If UNMARK is negative, tick articles."
7032   (interactive "P")
7033   (gnus-set-global-variables)
7034   (when unmark
7035     (setq unmark (prefix-numeric-value unmark)))
7036   (let ((count
7037          (gnus-summary-mark-same-subject
7038           (gnus-summary-article-subject) unmark)))
7039     ;; If marked as read, go to next unread subject.
7040     (when (null unmark)
7041       ;; Go to next unread subject.
7042       (gnus-summary-next-subject 1 t))
7043     (gnus-message 7 "%d articles are marked as %s"
7044                   count (if unmark "unread" "read"))))
7045
7046 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7047   "Mark articles with same SUBJECT as read, and return marked number.
7048 If optional argument UNMARK is positive, remove any kinds of marks.
7049 If optional argument UNMARK is negative, mark articles as unread instead."
7050   (let ((count 1))
7051     (save-excursion
7052       (cond
7053        ((null unmark)                   ; Mark as read.
7054         (while (and
7055                 (progn
7056                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7057                   (gnus-summary-show-thread) t)
7058                 (gnus-summary-find-subject subject))
7059           (setq count (1+ count))))
7060        ((> unmark 0)                    ; Tick.
7061         (while (and
7062                 (progn
7063                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7064                   (gnus-summary-show-thread) t)
7065                 (gnus-summary-find-subject subject))
7066           (setq count (1+ count))))
7067        (t                               ; Mark as unread.
7068         (while (and
7069                 (progn
7070                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7071                   (gnus-summary-show-thread) t)
7072                 (gnus-summary-find-subject subject))
7073           (setq count (1+ count)))))
7074       (gnus-set-mode-line 'summary)
7075       ;; Return the number of marked articles.
7076       count)))
7077
7078 (defun gnus-summary-mark-as-processable (n &optional unmark)
7079   "Set the process mark on the next N articles.
7080 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7081 the process mark instead.  The difference between N and the actual
7082 number of articles marked is returned."
7083   (interactive "p")
7084   (gnus-set-global-variables)
7085   (let ((backward (< n 0))
7086         (n (abs n)))
7087     (while (and
7088             (> n 0)
7089             (if unmark
7090                 (gnus-summary-remove-process-mark
7091                  (gnus-summary-article-number))
7092               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7093             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7094       (setq n (1- n)))
7095     (when (/= 0 n)
7096       (gnus-message 7 "No more articles"))
7097     (gnus-summary-recenter)
7098     (gnus-summary-position-point)
7099     n))
7100
7101 (defun gnus-summary-unmark-as-processable (n)
7102   "Remove the process mark from the next N articles.
7103 If N is negative, mark backward instead.  The difference between N and
7104 the actual number of articles marked is returned."
7105   (interactive "p")
7106   (gnus-set-global-variables)
7107   (gnus-summary-mark-as-processable n t))
7108
7109 (defun gnus-summary-unmark-all-processable ()
7110   "Remove the process mark from all articles."
7111   (interactive)
7112   (gnus-set-global-variables)
7113   (save-excursion
7114     (while gnus-newsgroup-processable
7115       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7116   (gnus-summary-position-point))
7117
7118 (defun gnus-summary-mark-as-expirable (n)
7119   "Mark N articles forward as expirable.
7120 If N is negative, mark backward instead.  The difference between N and
7121 the actual number of articles marked is returned."
7122   (interactive "p")
7123   (gnus-set-global-variables)
7124   (gnus-summary-mark-forward n gnus-expirable-mark))
7125
7126 (defun gnus-summary-mark-article-as-replied (article)
7127   "Mark ARTICLE replied and update the summary line."
7128   (push article gnus-newsgroup-replied)
7129   (let ((buffer-read-only nil))
7130     (when (gnus-summary-goto-subject article)
7131       (gnus-summary-update-secondary-mark article))))
7132
7133 (defun gnus-summary-set-bookmark (article)
7134   "Set a bookmark in current article."
7135   (interactive (list (gnus-summary-article-number)))
7136   (gnus-set-global-variables)
7137   (when (or (not (get-buffer gnus-article-buffer))
7138             (not gnus-current-article)
7139             (not gnus-article-current)
7140             (not (equal gnus-newsgroup-name (car gnus-article-current))))
7141     (error "No current article selected"))
7142   ;; Remove old bookmark, if one exists.
7143   (let ((old (assq article gnus-newsgroup-bookmarks)))
7144     (when old
7145       (setq gnus-newsgroup-bookmarks
7146             (delq old gnus-newsgroup-bookmarks))))
7147   ;; Set the new bookmark, which is on the form
7148   ;; (article-number . line-number-in-body).
7149   (push
7150    (cons article
7151          (save-excursion
7152            (set-buffer gnus-article-buffer)
7153            (count-lines
7154             (min (point)
7155                  (save-excursion
7156                    (goto-char (point-min))
7157                    (search-forward "\n\n" nil t)
7158                    (point)))
7159             (point))))
7160    gnus-newsgroup-bookmarks)
7161   (gnus-message 6 "A bookmark has been added to the current article."))
7162
7163 (defun gnus-summary-remove-bookmark (article)
7164   "Remove the bookmark from the current article."
7165   (interactive (list (gnus-summary-article-number)))
7166   (gnus-set-global-variables)
7167   ;; Remove old bookmark, if one exists.
7168   (let ((old (assq article gnus-newsgroup-bookmarks)))
7169     (if old
7170         (progn
7171           (setq gnus-newsgroup-bookmarks
7172                 (delq old gnus-newsgroup-bookmarks))
7173           (gnus-message 6 "Removed bookmark."))
7174       (gnus-message 6 "No bookmark in current article."))))
7175
7176 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7177 (defun gnus-summary-mark-as-dormant (n)
7178   "Mark N articles forward as dormant.
7179 If N is negative, mark backward instead.  The difference between N and
7180 the actual number of articles marked is returned."
7181   (interactive "p")
7182   (gnus-set-global-variables)
7183   (gnus-summary-mark-forward n gnus-dormant-mark))
7184
7185 (defun gnus-summary-set-process-mark (article)
7186   "Set the process mark on ARTICLE and update the summary line."
7187   (setq gnus-newsgroup-processable
7188         (cons article
7189               (delq article gnus-newsgroup-processable)))
7190   (when (gnus-summary-goto-subject article)
7191     (gnus-summary-show-thread)
7192     (gnus-summary-update-secondary-mark article)))
7193
7194 (defun gnus-summary-remove-process-mark (article)
7195   "Remove the process mark from ARTICLE and update the summary line."
7196   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
7197   (when (gnus-summary-goto-subject article)
7198     (gnus-summary-show-thread)
7199     (gnus-summary-update-secondary-mark article)))
7200
7201 (defun gnus-summary-set-saved-mark (article)
7202   "Set the process mark on ARTICLE and update the summary line."
7203   (push article gnus-newsgroup-saved)
7204   (when (gnus-summary-goto-subject article)
7205     (gnus-summary-update-secondary-mark article)))
7206
7207 (defun gnus-summary-mark-forward (n &optional mark no-expire)
7208   "Mark N articles as read forwards.
7209 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
7210 The difference between N and the actual number of articles marked is
7211 returned."
7212   (interactive "p")
7213   (gnus-set-global-variables)
7214   (let ((backward (< n 0))
7215         (gnus-summary-goto-unread
7216          (and gnus-summary-goto-unread
7217               (not (eq gnus-summary-goto-unread 'never))
7218               (not (memq mark (list gnus-unread-mark
7219                                     gnus-ticked-mark gnus-dormant-mark)))))
7220         (n (abs n))
7221         (mark (or mark gnus-del-mark)))
7222     (while (and (> n 0)
7223                 (gnus-summary-mark-article nil mark no-expire)
7224                 (zerop (gnus-summary-next-subject
7225                         (if backward -1 1)
7226                         (and gnus-summary-goto-unread
7227                              (not (eq gnus-summary-goto-unread 'never)))
7228                         t)))
7229       (setq n (1- n)))
7230     (when (/= 0 n)
7231       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
7232     (gnus-summary-recenter)
7233     (gnus-summary-position-point)
7234     (gnus-set-mode-line 'summary)
7235     n))
7236
7237 (defun gnus-summary-mark-article-as-read (mark)
7238   "Mark the current article quickly as read with MARK."
7239   (let ((article (gnus-summary-article-number)))
7240     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7241     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7242     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7243     (push (cons article mark) gnus-newsgroup-reads)
7244     ;; Possibly remove from cache, if that is used.
7245     (when gnus-use-cache
7246       (gnus-cache-enter-remove-article article))
7247     ;; Allow the backend to change the mark.
7248     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7249     ;; Check for auto-expiry.
7250     (when (and gnus-newsgroup-auto-expire
7251                (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
7252                    (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
7253                    (= mark gnus-ancient-mark)
7254                    (= mark gnus-read-mark) (= mark gnus-souped-mark)
7255                    (= mark gnus-duplicate-mark)))
7256       (setq mark gnus-expirable-mark)
7257       (push article gnus-newsgroup-expirable))
7258     ;; Set the mark in the buffer.
7259     (gnus-summary-update-mark mark 'unread)
7260     t))
7261
7262 (defun gnus-summary-mark-article-as-unread (mark)
7263   "Mark the current article quickly as unread with MARK."
7264   (let ((article (gnus-summary-article-number)))
7265     (if (< article 0)
7266         (gnus-error 1 "Unmarkable article")
7267       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7268       (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7269       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
7270       (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
7271       (cond ((= mark gnus-ticked-mark)
7272              (push article gnus-newsgroup-marked))
7273             ((= mark gnus-dormant-mark)
7274              (push article gnus-newsgroup-dormant))
7275             (t
7276              (push article gnus-newsgroup-unreads)))
7277       (setq gnus-newsgroup-reads
7278             (delq (assq article gnus-newsgroup-reads)
7279                   gnus-newsgroup-reads))
7280
7281       ;; See whether the article is to be put in the cache.
7282       (and gnus-use-cache
7283            (vectorp (gnus-summary-article-header article))
7284            (save-excursion
7285              (gnus-cache-possibly-enter-article
7286               gnus-newsgroup-name article
7287               (gnus-summary-article-header article)
7288               (= mark gnus-ticked-mark)
7289               (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7290
7291       ;; Fix the mark.
7292       (gnus-summary-update-mark mark 'unread))
7293     t))
7294
7295 (defun gnus-summary-mark-article (&optional article mark no-expire)
7296   "Mark ARTICLE with MARK.  MARK can be any character.
7297 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
7298 `??' (dormant) and `?E' (expirable).
7299 If MARK is nil, then the default character `?D' is used.
7300 If ARTICLE is nil, then the article on the current line will be
7301 marked."
7302   ;; The mark might be a string.
7303   (when (stringp mark)
7304     (setq mark (aref mark 0)))
7305   ;; If no mark is given, then we check auto-expiring.
7306   (and (not no-expire)
7307        gnus-newsgroup-auto-expire
7308        (or (not mark)
7309            (and (gnus-characterp mark)
7310                 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
7311                     (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
7312                     (= mark gnus-read-mark) (= mark gnus-souped-mark)
7313                     (= mark gnus-duplicate-mark))))
7314        (setq mark gnus-expirable-mark))
7315   (let* ((mark (or mark gnus-del-mark))
7316          (article (or article (gnus-summary-article-number))))
7317     (unless article
7318       (error "No article on current line"))
7319     (if (or (= mark gnus-unread-mark)
7320             (= mark gnus-ticked-mark)
7321             (= mark gnus-dormant-mark))
7322         (gnus-mark-article-as-unread article mark)
7323       (gnus-mark-article-as-read article mark))
7324
7325     ;; See whether the article is to be put in the cache.
7326     (and gnus-use-cache
7327          (not (= mark gnus-canceled-mark))
7328          (vectorp (gnus-summary-article-header article))
7329          (save-excursion
7330            (gnus-cache-possibly-enter-article
7331             gnus-newsgroup-name article
7332             (gnus-summary-article-header article)
7333             (= mark gnus-ticked-mark)
7334             (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7335
7336     (when (gnus-summary-goto-subject article nil t)
7337       (let ((buffer-read-only nil))
7338         (gnus-summary-show-thread)
7339         ;; Fix the mark.
7340         (gnus-summary-update-mark mark 'unread)
7341         t))))
7342
7343 (defun gnus-summary-update-secondary-mark (article)
7344   "Update the secondary (read, process, cache) mark."
7345   (gnus-summary-update-mark
7346    (cond ((memq article gnus-newsgroup-processable)
7347           gnus-process-mark)
7348          ((memq article gnus-newsgroup-cached)
7349           gnus-cached-mark)
7350          ((memq article gnus-newsgroup-replied)
7351           gnus-replied-mark)
7352          ((memq article gnus-newsgroup-saved)
7353           gnus-saved-mark)
7354          (t gnus-unread-mark))
7355    'replied)
7356   (when (gnus-visual-p 'summary-highlight 'highlight)
7357     (run-hooks 'gnus-summary-update-hook))
7358   t)
7359
7360 (defun gnus-summary-update-mark (mark type)
7361   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
7362         (buffer-read-only nil))
7363     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
7364     (when (looking-at "\r")
7365       (incf forward))
7366     (when (and forward
7367                (<= (+ forward (point)) (point-max)))
7368       ;; Go to the right position on the line.
7369       (goto-char (+ forward (point)))
7370       ;; Replace the old mark with the new mark.
7371       (subst-char-in-region (point) (1+ (point)) (following-char) mark)
7372       ;; Optionally update the marks by some user rule.
7373       (when (eq type 'unread)
7374         (gnus-data-set-mark
7375          (gnus-data-find (gnus-summary-article-number)) mark)
7376         (gnus-summary-update-line (eq mark gnus-unread-mark))))))
7377
7378 (defun gnus-mark-article-as-read (article &optional mark)
7379   "Enter ARTICLE in the pertinent lists and remove it from others."
7380   ;; Make the article expirable.
7381   (let ((mark (or mark gnus-del-mark)))
7382     (if (= mark gnus-expirable-mark)
7383         (push article gnus-newsgroup-expirable)
7384       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
7385     ;; Remove from unread and marked lists.
7386     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7387     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7388     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7389     (push (cons article mark) gnus-newsgroup-reads)
7390     ;; Possibly remove from cache, if that is used.
7391     (when gnus-use-cache
7392       (gnus-cache-enter-remove-article article))))
7393
7394 (defun gnus-mark-article-as-unread (article &optional mark)
7395   "Enter ARTICLE in the pertinent lists and remove it from others."
7396   (let ((mark (or mark gnus-ticked-mark)))
7397     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
7398           gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
7399           gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
7400           gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7401
7402     ;; Unsuppress duplicates?
7403     (when gnus-suppress-duplicates
7404       (gnus-dup-unsuppress-article article))
7405
7406     (cond ((= mark gnus-ticked-mark)
7407            (push article gnus-newsgroup-marked))
7408           ((= mark gnus-dormant-mark)
7409            (push article gnus-newsgroup-dormant))
7410           (t
7411            (push article gnus-newsgroup-unreads)))
7412     (setq gnus-newsgroup-reads
7413           (delq (assq article gnus-newsgroup-reads)
7414                 gnus-newsgroup-reads))))
7415
7416 (defalias 'gnus-summary-mark-as-unread-forward
7417   'gnus-summary-tick-article-forward)
7418 (make-obsolete 'gnus-summary-mark-as-unread-forward
7419                'gnus-summary-tick-article-forward)
7420 (defun gnus-summary-tick-article-forward (n)
7421   "Tick N articles forwards.
7422 If N is negative, tick backwards instead.
7423 The difference between N and the number of articles ticked is returned."
7424   (interactive "p")
7425   (gnus-summary-mark-forward n gnus-ticked-mark))
7426
7427 (defalias 'gnus-summary-mark-as-unread-backward
7428   'gnus-summary-tick-article-backward)
7429 (make-obsolete 'gnus-summary-mark-as-unread-backward
7430                'gnus-summary-tick-article-backward)
7431 (defun gnus-summary-tick-article-backward (n)
7432   "Tick N articles backwards.
7433 The difference between N and the number of articles ticked is returned."
7434   (interactive "p")
7435   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
7436
7437 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
7438 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
7439 (defun gnus-summary-tick-article (&optional article clear-mark)
7440   "Mark current article as unread.
7441 Optional 1st argument ARTICLE specifies article number to be marked as unread.
7442 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
7443   (interactive)
7444   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
7445                                        gnus-ticked-mark)))
7446
7447 (defun gnus-summary-mark-as-read-forward (n)
7448   "Mark N articles as read forwards.
7449 If N is negative, mark backwards instead.
7450 The difference between N and the actual number of articles marked is
7451 returned."
7452   (interactive "p")
7453   (gnus-summary-mark-forward n gnus-del-mark t))
7454
7455 (defun gnus-summary-mark-as-read-backward (n)
7456   "Mark the N articles as read backwards.
7457 The difference between N and the actual number of articles marked is
7458 returned."
7459   (interactive "p")
7460   (gnus-summary-mark-forward (- n) gnus-del-mark t))
7461
7462 (defun gnus-summary-mark-as-read (&optional article mark)
7463   "Mark current article as read.
7464 ARTICLE specifies the article to be marked as read.
7465 MARK specifies a string to be inserted at the beginning of the line."
7466   (gnus-summary-mark-article article mark))
7467
7468 (defun gnus-summary-clear-mark-forward (n)
7469   "Clear marks from N articles forward.
7470 If N is negative, clear backward instead.
7471 The difference between N and the number of marks cleared is returned."
7472   (interactive "p")
7473   (gnus-summary-mark-forward n gnus-unread-mark))
7474
7475 (defun gnus-summary-clear-mark-backward (n)
7476   "Clear marks from N articles backward.
7477 The difference between N and the number of marks cleared is returned."
7478   (interactive "p")
7479   (gnus-summary-mark-forward (- n) gnus-unread-mark))
7480
7481 (defun gnus-summary-mark-unread-as-read ()
7482   "Intended to be used by `gnus-summary-mark-article-hook'."
7483   (when (memq gnus-current-article gnus-newsgroup-unreads)
7484     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
7485
7486 (defun gnus-summary-mark-read-and-unread-as-read ()
7487   "Intended to be used by `gnus-summary-mark-article-hook'."
7488   (let ((mark (gnus-summary-article-mark)))
7489     (when (or (gnus-unread-mark-p mark)
7490               (gnus-read-mark-p mark))
7491       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
7492
7493 (defun gnus-summary-mark-region-as-read (point mark all)
7494   "Mark all unread articles between point and mark as read.
7495 If given a prefix, mark all articles between point and mark as read,
7496 even ticked and dormant ones."
7497   (interactive "r\nP")
7498   (save-excursion
7499     (let (article)
7500       (goto-char point)
7501       (beginning-of-line)
7502       (while (and
7503               (< (point) mark)
7504               (progn
7505                 (when (or all
7506                           (memq (setq article (gnus-summary-article-number))
7507                                 gnus-newsgroup-unreads))
7508                   (gnus-summary-mark-article article gnus-del-mark))
7509                 t)
7510               (gnus-summary-find-next))))))
7511
7512 (defun gnus-summary-mark-below (score mark)
7513   "Mark articles with score less than SCORE with MARK."
7514   (interactive "P\ncMark: ")
7515   (gnus-set-global-variables)
7516   (setq score (if score
7517                   (prefix-numeric-value score)
7518                 (or gnus-summary-default-score 0)))
7519   (save-excursion
7520     (set-buffer gnus-summary-buffer)
7521     (goto-char (point-min))
7522     (while 
7523         (progn
7524           (and (< (gnus-summary-article-score) score)
7525                (gnus-summary-mark-article nil mark))
7526           (gnus-summary-find-next)))))
7527
7528 (defun gnus-summary-kill-below (&optional score)
7529   "Mark articles with score below SCORE as read."
7530   (interactive "P")
7531   (gnus-set-global-variables)
7532   (gnus-summary-mark-below score gnus-killed-mark))
7533
7534 (defun gnus-summary-clear-above (&optional score)
7535   "Clear all marks from articles with score above SCORE."
7536   (interactive "P")
7537   (gnus-set-global-variables)
7538   (gnus-summary-mark-above score gnus-unread-mark))
7539
7540 (defun gnus-summary-tick-above (&optional score)
7541   "Tick all articles with score above SCORE."
7542   (interactive "P")
7543   (gnus-set-global-variables)
7544   (gnus-summary-mark-above score gnus-ticked-mark))
7545
7546 (defun gnus-summary-mark-above (score mark)
7547   "Mark articles with score over SCORE with MARK."
7548   (interactive "P\ncMark: ")
7549   (gnus-set-global-variables)
7550   (setq score (if score
7551                   (prefix-numeric-value score)
7552                 (or gnus-summary-default-score 0)))
7553   (save-excursion
7554     (set-buffer gnus-summary-buffer)
7555     (goto-char (point-min))
7556     (while (and (progn
7557                   (when (> (gnus-summary-article-score) score)
7558                     (gnus-summary-mark-article nil mark))
7559                   t)
7560                 (gnus-summary-find-next)))))
7561
7562 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7563 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
7564 (defun gnus-summary-limit-include-expunged (&optional no-error)
7565   "Display all the hidden articles that were expunged for low scores."
7566   (interactive)
7567   (gnus-set-global-variables)
7568   (let ((buffer-read-only nil))
7569     (let ((scored gnus-newsgroup-scored)
7570           headers h)
7571       (while scored
7572         (unless (gnus-summary-goto-subject (caar scored))
7573           (and (setq h (gnus-summary-article-header (caar scored)))
7574                (< (cdar scored) gnus-summary-expunge-below)
7575                (push h headers)))
7576         (setq scored (cdr scored)))
7577       (if (not headers)
7578           (when (not no-error)
7579             (error "No expunged articles hidden."))
7580         (goto-char (point-min))
7581         (gnus-summary-prepare-unthreaded (nreverse headers))
7582         (goto-char (point-min))
7583         (gnus-summary-position-point)
7584         t))))
7585
7586 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
7587   "Mark all unread articles in this newsgroup as read.
7588 If prefix argument ALL is non-nil, ticked and dormant articles will 
7589 also be marked as read.
7590 If QUIETLY is non-nil, no questions will be asked.
7591 If TO-HERE is non-nil, it should be a point in the buffer.  All
7592 articles before this point will be marked as read.
7593 Note that this function will only catch up the unread article
7594 in the current summary buffer limitation.
7595 The number of articles marked as read is returned."
7596   (interactive "P")
7597   (gnus-set-global-variables)
7598   (prog1
7599       (save-excursion
7600         (when (or quietly
7601                   (not gnus-interactive-catchup) ;Without confirmation?
7602                   gnus-expert-user
7603                   (gnus-y-or-n-p
7604                    (if all
7605                        "Mark absolutely all articles as read? "
7606                      "Mark all unread articles as read? ")))
7607           (if (and not-mark
7608                    (not gnus-newsgroup-adaptive)
7609                    (not gnus-newsgroup-auto-expire)
7610                    (not gnus-suppress-duplicates))
7611               (progn
7612                 (when all
7613                   (setq gnus-newsgroup-marked nil
7614                         gnus-newsgroup-dormant nil))
7615                 (setq gnus-newsgroup-unreads nil))
7616             ;; We actually mark all articles as canceled, which we
7617             ;; have to do when using auto-expiry or adaptive scoring.
7618             (gnus-summary-show-all-threads)
7619             (when (gnus-summary-first-subject (not all))
7620               (while (and
7621                       (if to-here (< (point) to-here) t)
7622                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
7623                       (gnus-summary-find-next (not all)))))
7624             (gnus-set-mode-line 'summary))
7625           t))
7626     (gnus-summary-position-point)))
7627
7628 (defun gnus-summary-catchup-to-here (&optional all)
7629   "Mark all unticked articles before the current one as read.
7630 If ALL is non-nil, also mark ticked and dormant articles as read."
7631   (interactive "P")
7632   (gnus-set-global-variables)
7633   (save-excursion
7634     (gnus-save-hidden-threads
7635       (let ((beg (point)))
7636         ;; We check that there are unread articles.
7637         (when (or all (gnus-summary-find-prev))
7638           (gnus-summary-catchup all t beg)))))
7639   (gnus-summary-position-point))
7640
7641 (defun gnus-summary-catchup-all (&optional quietly)
7642   "Mark all articles in this newsgroup as read."
7643   (interactive "P")
7644   (gnus-set-global-variables)
7645   (gnus-summary-catchup t quietly))
7646
7647 (defun gnus-summary-catchup-and-exit (&optional all quietly)
7648   "Mark all articles not marked as unread in this newsgroup as read, then exit.
7649 If prefix argument ALL is non-nil, all articles are marked as read."
7650   (interactive "P")
7651   (gnus-set-global-variables)
7652   (when (gnus-summary-catchup all quietly nil 'fast)
7653     ;; Select next newsgroup or exit.
7654     (if (eq gnus-auto-select-next 'quietly)
7655         (gnus-summary-next-group nil)
7656       (gnus-summary-exit))))
7657
7658 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
7659   "Mark all articles in this newsgroup as read, and then exit."
7660   (interactive "P")
7661   (gnus-set-global-variables)
7662   (gnus-summary-catchup-and-exit t quietly))
7663
7664 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
7665 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
7666   "Mark all articles in this group as read and select the next group.
7667 If given a prefix, mark all articles, unread as well as ticked, as
7668 read."
7669   (interactive "P")
7670   (gnus-set-global-variables)
7671   (save-excursion
7672     (gnus-summary-catchup all))
7673   (gnus-summary-next-article t nil nil t))
7674
7675 ;; Thread-based commands.
7676
7677 (defun gnus-summary-articles-in-thread (&optional article)
7678   "Return a list of all articles in the current thread.
7679 If ARTICLE is non-nil, return all articles in the thread that starts
7680 with that article."
7681   (let* ((article (or article (gnus-summary-article-number)))
7682          (data (gnus-data-find-list article))
7683          (top-level (gnus-data-level (car data)))
7684          (top-subject
7685           (cond ((null gnus-thread-operation-ignore-subject)
7686                  (gnus-simplify-subject-re
7687                   (mail-header-subject (gnus-data-header (car data)))))
7688                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
7689                  (gnus-simplify-subject-fuzzy
7690                   (mail-header-subject (gnus-data-header (car data)))))
7691                 (t nil)))
7692          (end-point (save-excursion
7693                       (if (gnus-summary-go-to-next-thread)
7694                           (point) (point-max))))
7695          articles)
7696     (while (and data
7697                 (< (gnus-data-pos (car data)) end-point))
7698       (when (or (not top-subject)
7699                 (string= top-subject
7700                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
7701                              (gnus-simplify-subject-fuzzy
7702                               (mail-header-subject
7703                                (gnus-data-header (car data))))
7704                            (gnus-simplify-subject-re
7705                             (mail-header-subject
7706                              (gnus-data-header (car data)))))))
7707         (push (gnus-data-number (car data)) articles))
7708       (unless (and (setq data (cdr data))
7709                    (> (gnus-data-level (car data)) top-level))
7710         (setq data nil)))
7711     ;; Return the list of articles.
7712     (nreverse articles)))
7713
7714 (defun gnus-summary-rethread-current ()
7715   "Rethread the thread the current article is part of."
7716   (interactive)
7717   (gnus-set-global-variables)
7718   (let* ((gnus-show-threads t)
7719          (article (gnus-summary-article-number))
7720          (id (mail-header-id (gnus-summary-article-header)))
7721          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
7722     (unless id
7723       (error "No article on the current line"))
7724     (gnus-rebuild-thread id)
7725     (gnus-summary-goto-subject article)))
7726
7727 (defun gnus-summary-reparent-thread ()
7728   "Make the current article child of the marked (or previous) article.
7729
7730 Note that the re-threading will only work if `gnus-thread-ignore-subject'
7731 is non-nil or the Subject: of both articles are the same."
7732   (interactive)
7733   (unless (not (gnus-group-read-only-p))
7734     (error "The current newsgroup does not support article editing."))
7735   (unless (<= (length gnus-newsgroup-processable) 1)
7736     (error "No more than one article may be marked."))
7737   (save-window-excursion
7738     (let ((gnus-article-buffer " *reparent*")
7739           (current-article (gnus-summary-article-number))
7740           ;; First grab the marked article, otherwise one line up.
7741           (parent-article (if (not (null gnus-newsgroup-processable))
7742                               (car gnus-newsgroup-processable)
7743                             (save-excursion
7744                               (if (eq (forward-line -1) 0)
7745                                   (gnus-summary-article-number)
7746                                 (error "Beginning of summary buffer."))))))
7747       (unless (not (eq current-article parent-article))
7748         (error "An article may not be self-referential."))
7749       (let ((message-id (mail-header-id 
7750                          (gnus-summary-article-header parent-article))))
7751         (unless (and message-id (not (equal message-id "")))
7752           (error "No message-id in desired parent."))
7753         (gnus-summary-select-article t t nil current-article)
7754         (set-buffer gnus-original-article-buffer)
7755         (let ((buf (format "%s" (buffer-string))))
7756           (nnheader-temp-write nil
7757             (insert buf)
7758             (goto-char (point-min))
7759             (if (search-forward-regexp "^References: " nil t)
7760                 (insert message-id " " )
7761               (insert "References: " message-id "\n"))
7762             (unless (gnus-request-replace-article
7763                      current-article (car gnus-article-current)
7764                      (current-buffer))
7765               (error "Couldn't replace article."))))
7766         (set-buffer gnus-summary-buffer)
7767         (gnus-summary-unmark-all-processable)
7768         (gnus-summary-rethread-current)
7769         (gnus-message 3 "Article %d is now the child of article %d."
7770                       current-article parent-article)))))
7771
7772 (defun gnus-summary-toggle-threads (&optional arg)
7773   "Toggle showing conversation threads.
7774 If ARG is positive number, turn showing conversation threads on."
7775   (interactive "P")
7776   (gnus-set-global-variables)
7777   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
7778     (setq gnus-show-threads
7779           (if (null arg) (not gnus-show-threads)
7780             (> (prefix-numeric-value arg) 0)))
7781     (gnus-summary-prepare)
7782     (gnus-summary-goto-subject current)
7783     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
7784     (gnus-summary-position-point)))
7785
7786 (defun gnus-summary-show-all-threads ()
7787   "Show all threads."
7788   (interactive)
7789   (gnus-set-global-variables)
7790   (save-excursion
7791     (let ((buffer-read-only nil))
7792       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
7793   (gnus-summary-position-point))
7794
7795 (defun gnus-summary-show-thread ()
7796   "Show thread subtrees.
7797 Returns nil if no thread was there to be shown."
7798   (interactive)
7799   (gnus-set-global-variables)
7800   (let ((buffer-read-only nil)
7801         (orig (point))
7802         ;; first goto end then to beg, to have point at beg after let
7803         (end (progn (end-of-line) (point)))
7804         (beg (progn (beginning-of-line) (point))))
7805     (prog1
7806         ;; Any hidden lines here?
7807         (search-forward "\r" end t)
7808       (subst-char-in-region beg end ?\^M ?\n t)
7809       (goto-char orig)
7810       (gnus-summary-position-point))))
7811
7812 (defun gnus-summary-hide-all-threads ()
7813   "Hide all thread subtrees."
7814   (interactive)
7815   (gnus-set-global-variables)
7816   (save-excursion
7817     (goto-char (point-min))
7818     (gnus-summary-hide-thread)
7819     (while (zerop (gnus-summary-next-thread 1 t))
7820       (gnus-summary-hide-thread)))
7821   (gnus-summary-position-point))
7822
7823 (defun gnus-summary-hide-thread ()
7824   "Hide thread subtrees.
7825 Returns nil if no threads were there to be hidden."
7826   (interactive)
7827   (gnus-set-global-variables)
7828   (let ((buffer-read-only nil)
7829         (start (point))
7830         (article (gnus-summary-article-number)))
7831     (goto-char start)
7832     ;; Go forward until either the buffer ends or the subthread
7833     ;; ends.
7834     (when (and (not (eobp))
7835                (or (zerop (gnus-summary-next-thread 1 t))
7836                    (goto-char (point-max))))
7837       (prog1
7838           (if (and (> (point) start)
7839                    (search-backward "\n" start t))
7840               (progn
7841                 (subst-char-in-region start (point) ?\n ?\^M)
7842                 (gnus-summary-goto-subject article))
7843             (goto-char start)
7844             nil)
7845         ;;(gnus-summary-position-point)
7846         ))))
7847
7848 (defun gnus-summary-go-to-next-thread (&optional previous)
7849   "Go to the same level (or less) next thread.
7850 If PREVIOUS is non-nil, go to previous thread instead.
7851 Return the article number moved to, or nil if moving was impossible."
7852   (let ((level (gnus-summary-thread-level))
7853         (way (if previous -1 1))
7854         (beg (point)))
7855     (forward-line way)
7856     (while (and (not (eobp))
7857                 (< level (gnus-summary-thread-level)))
7858       (forward-line way))
7859     (if (eobp)
7860         (progn
7861           (goto-char beg)
7862           nil)
7863       (setq beg (point))
7864       (prog1
7865           (gnus-summary-article-number)
7866         (goto-char beg)))))
7867
7868 (defun gnus-summary-next-thread (n &optional silent)
7869   "Go to the same level next N'th thread.
7870 If N is negative, search backward instead.
7871 Returns the difference between N and the number of skips actually
7872 done.
7873
7874 If SILENT, don't output messages."
7875   (interactive "p")
7876   (gnus-set-global-variables)
7877   (let ((backward (< n 0))
7878         (n (abs n)))
7879     (while (and (> n 0)
7880                 (gnus-summary-go-to-next-thread backward))
7881       (decf n))
7882     (unless silent 
7883       (gnus-summary-position-point))
7884     (when (and (not silent) (/= 0 n))
7885       (gnus-message 7 "No more threads"))
7886     n))
7887
7888 (defun gnus-summary-prev-thread (n)
7889   "Go to the same level previous N'th thread.
7890 Returns the difference between N and the number of skips actually
7891 done."
7892   (interactive "p")
7893   (gnus-set-global-variables)
7894   (gnus-summary-next-thread (- n)))
7895
7896 (defun gnus-summary-go-down-thread ()
7897   "Go down one level in the current thread."
7898   (let ((children (gnus-summary-article-children)))
7899     (when children
7900       (gnus-summary-goto-subject (car children)))))
7901
7902 (defun gnus-summary-go-up-thread ()
7903   "Go up one level in the current thread."
7904   (let ((parent (gnus-summary-article-parent)))
7905     (when parent
7906       (gnus-summary-goto-subject parent))))
7907
7908 (defun gnus-summary-down-thread (n)
7909   "Go down thread N steps.
7910 If N is negative, go up instead.
7911 Returns the difference between N and how many steps down that were
7912 taken."
7913   (interactive "p")
7914   (gnus-set-global-variables)
7915   (let ((up (< n 0))
7916         (n (abs n)))
7917     (while (and (> n 0)
7918                 (if up (gnus-summary-go-up-thread)
7919                   (gnus-summary-go-down-thread)))
7920       (setq n (1- n)))
7921     (gnus-summary-position-point)
7922     (when (/= 0 n)
7923       (gnus-message 7 "Can't go further"))
7924     n))
7925
7926 (defun gnus-summary-up-thread (n)
7927   "Go up thread N steps.
7928 If N is negative, go up instead.
7929 Returns the difference between N and how many steps down that were
7930 taken."
7931   (interactive "p")
7932   (gnus-set-global-variables)
7933   (gnus-summary-down-thread (- n)))
7934
7935 (defun gnus-summary-top-thread ()
7936   "Go to the top of the thread."
7937   (interactive)
7938   (gnus-set-global-variables)
7939   (while (gnus-summary-go-up-thread))
7940   (gnus-summary-article-number))
7941
7942 (defun gnus-summary-kill-thread (&optional unmark)
7943   "Mark articles under current thread as read.
7944 If the prefix argument is positive, remove any kinds of marks.
7945 If the prefix argument is negative, tick articles instead."
7946   (interactive "P")
7947   (gnus-set-global-variables)
7948   (when unmark
7949     (setq unmark (prefix-numeric-value unmark)))
7950   (let ((articles (gnus-summary-articles-in-thread)))
7951     (save-excursion
7952       ;; Expand the thread.
7953       (gnus-summary-show-thread)
7954       ;; Mark all the articles.
7955       (while articles
7956         (gnus-summary-goto-subject (car articles))
7957         (cond ((null unmark)
7958                (gnus-summary-mark-article-as-read gnus-killed-mark))
7959               ((> unmark 0)
7960                (gnus-summary-mark-article-as-unread gnus-unread-mark))
7961               (t
7962                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
7963         (setq articles (cdr articles))))
7964     ;; Hide killed subtrees.
7965     (and (null unmark)
7966          gnus-thread-hide-killed
7967          (gnus-summary-hide-thread))
7968     ;; If marked as read, go to next unread subject.
7969     (when (null unmark)
7970       ;; Go to next unread subject.
7971       (gnus-summary-next-subject 1 t)))
7972   (gnus-set-mode-line 'summary))
7973
7974 ;; Summary sorting commands
7975
7976 (defun gnus-summary-sort-by-number (&optional reverse)
7977   "Sort the summary buffer by article number.
7978 Argument REVERSE means reverse order."
7979   (interactive "P")
7980   (gnus-summary-sort 'number reverse))
7981
7982 (defun gnus-summary-sort-by-author (&optional reverse)
7983   "Sort the summary buffer by author name alphabetically.
7984 If case-fold-search is non-nil, case of letters is ignored.
7985 Argument REVERSE means reverse order."
7986   (interactive "P")
7987   (gnus-summary-sort 'author reverse))
7988
7989 (defun gnus-summary-sort-by-subject (&optional reverse)
7990   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
7991 If case-fold-search is non-nil, case of letters is ignored.
7992 Argument REVERSE means reverse order."
7993   (interactive "P")
7994   (gnus-summary-sort 'subject reverse))
7995
7996 (defun gnus-summary-sort-by-date (&optional reverse)
7997   "Sort the summary buffer by date.
7998 Argument REVERSE means reverse order."
7999   (interactive "P")
8000   (gnus-summary-sort 'date reverse))
8001
8002 (defun gnus-summary-sort-by-score (&optional reverse)
8003   "Sort the summary buffer by score.
8004 Argument REVERSE means reverse order."
8005   (interactive "P")
8006   (gnus-summary-sort 'score reverse))
8007
8008 (defun gnus-summary-sort-by-lines (&optional reverse)
8009   "Sort the summary buffer by article length.
8010 Argument REVERSE means reverse order."
8011   (interactive "P")
8012   (gnus-summary-sort 'lines reverse))
8013
8014 (defun gnus-summary-sort (predicate reverse)
8015   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8016   (gnus-set-global-variables)
8017   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8018          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8019          (gnus-thread-sort-functions
8020           (list
8021            (if (not reverse)
8022                thread
8023              `(lambda (t1 t2)
8024                 (,thread t2 t1)))))
8025          (gnus-article-sort-functions
8026           (list
8027            (if (not reverse)
8028                article
8029              `(lambda (t1 t2)
8030                 (,article t2 t1)))))
8031          (buffer-read-only)
8032          (gnus-summary-prepare-hook nil))
8033     ;; We do the sorting by regenerating the threads.
8034     (gnus-summary-prepare)
8035     ;; Hide subthreads if needed.
8036     (when (and gnus-show-threads gnus-thread-hide-subtree)
8037       (gnus-summary-hide-all-threads))))
8038
8039 ;; Summary saving commands.
8040
8041 (defun gnus-summary-save-article (&optional n not-saved)
8042   "Save the current article using the default saver function.
8043 If N is a positive number, save the N next articles.
8044 If N is a negative number, save the N previous articles.
8045 If N is nil and any articles have been marked with the process mark,
8046 save those articles instead.
8047 The variable `gnus-default-article-saver' specifies the saver function."
8048   (interactive "P")
8049   (gnus-set-global-variables)
8050   (let* ((articles (gnus-summary-work-articles n))
8051          (save-buffer (save-excursion 
8052                         (nnheader-set-temp-buffer " *Gnus Save*")))
8053          (num (length articles))
8054          header article file)
8055     (while articles
8056       (setq header (gnus-summary-article-header
8057                     (setq article (pop articles))))
8058       (if (not (vectorp header))
8059           ;; This is a pseudo-article.
8060           (if (assq 'name header)
8061               (gnus-copy-file (cdr (assq 'name header)))
8062             (gnus-message 1 "Article %d is unsaveable" article))
8063         ;; This is a real article.
8064         (save-window-excursion
8065           (gnus-summary-select-article t nil nil article))
8066         (save-excursion
8067           (set-buffer save-buffer)
8068           (erase-buffer)
8069           (insert-buffer-substring gnus-original-article-buffer))
8070         (setq file (gnus-article-save save-buffer file num))
8071         (gnus-summary-remove-process-mark article)
8072         (unless not-saved
8073           (gnus-summary-set-saved-mark article))))
8074     (gnus-kill-buffer save-buffer)
8075     (gnus-summary-position-point)
8076     (gnus-set-mode-line 'summary)
8077     n))
8078
8079 (defun gnus-summary-pipe-output (&optional arg)
8080   "Pipe the current article to a subprocess.
8081 If N is a positive number, pipe the N next articles.
8082 If N is a negative number, pipe the N previous articles.
8083 If N is nil and any articles have been marked with the process mark,
8084 pipe those articles instead."
8085   (interactive "P")
8086   (gnus-set-global-variables)
8087   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8088     (gnus-summary-save-article arg t))
8089   (gnus-configure-windows 'pipe))
8090
8091 (defun gnus-summary-save-article-mail (&optional arg)
8092   "Append the current article to an mail file.
8093 If N is a positive number, save the N next articles.
8094 If N is a negative number, save the N previous articles.
8095 If N is nil and any articles have been marked with the process mark,
8096 save those articles instead."
8097   (interactive "P")
8098   (gnus-set-global-variables)
8099   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8100     (gnus-summary-save-article arg)))
8101
8102 (defun gnus-summary-save-article-rmail (&optional arg)
8103   "Append the current article to an rmail file.
8104 If N is a positive number, save the N next articles.
8105 If N is a negative number, save the N previous articles.
8106 If N is nil and any articles have been marked with the process mark,
8107 save those articles instead."
8108   (interactive "P")
8109   (gnus-set-global-variables)
8110   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
8111     (gnus-summary-save-article arg)))
8112
8113 (defun gnus-summary-save-article-file (&optional arg)
8114   "Append the current article to a file.
8115 If N is a positive number, save the N next articles.
8116 If N is a negative number, save the N previous articles.
8117 If N is nil and any articles have been marked with the process mark,
8118 save those articles instead."
8119   (interactive "P")
8120   (gnus-set-global-variables)
8121   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8122     (gnus-summary-save-article arg)))
8123
8124 (defun gnus-summary-write-article-file (&optional arg)
8125   "Write the current article to a file, deleting the previous file.
8126 If N is a positive number, save the N next articles.
8127 If N is a negative number, save the N previous articles.
8128 If N is nil and any articles have been marked with the process mark,
8129 save those articles instead."
8130   (interactive "P")
8131   (gnus-set-global-variables)
8132   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8133     (gnus-summary-save-article arg)))
8134
8135 (defun gnus-summary-save-article-body-file (&optional arg)
8136   "Append the current article body to a file.
8137 If N is a positive number, save the N next articles.
8138 If N is a negative number, save the N previous articles.
8139 If N is nil and any articles have been marked with the process mark,
8140 save those articles instead."
8141   (interactive "P")
8142   (gnus-set-global-variables)
8143   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8144     (gnus-summary-save-article arg)))
8145
8146 (defun gnus-summary-pipe-message (program)
8147   "Pipe the current article through PROGRAM."
8148   (interactive "sProgram: ")
8149   (gnus-set-global-variables)
8150   (gnus-summary-select-article)
8151   (let ((mail-header-separator "")
8152         (art-buf (get-buffer gnus-article-buffer)))
8153     (gnus-eval-in-buffer-window gnus-article-buffer
8154       (save-restriction
8155         (widen)
8156         (let ((start (window-start))
8157               buffer-read-only)
8158           (message-pipe-buffer-body program)
8159           (set-window-start (get-buffer-window (current-buffer)) start))))))
8160
8161 (defun gnus-get-split-value (methods)
8162   "Return a value based on the split METHODS."
8163   (let (split-name method result match)
8164     (when methods
8165       (save-excursion
8166         (set-buffer gnus-original-article-buffer)
8167         (save-restriction
8168           (nnheader-narrow-to-headers)
8169           (while methods
8170             (goto-char (point-min))
8171             (setq method (pop methods))
8172             (setq match (car method))
8173             (when (cond
8174                    ((stringp match)
8175                     ;; Regular expression.
8176                     (ignore-errors
8177                       (re-search-forward match nil t)))
8178                    ((gnus-functionp match)
8179                     ;; Function.
8180                     (save-restriction
8181                       (widen)
8182                       (setq result (funcall match gnus-newsgroup-name))))
8183                    ((consp match)
8184                     ;; Form.
8185                     (save-restriction
8186                       (widen)
8187                       (setq result (eval match)))))
8188               (setq split-name (append (cdr method) split-name))
8189               (cond ((stringp result)
8190                      (push (expand-file-name
8191                             result gnus-article-save-directory)
8192                            split-name))
8193                     ((consp result)
8194                      (setq split-name (append result split-name)))))))))
8195     split-name))
8196
8197 (defun gnus-valid-move-group-p (group)
8198   (and (boundp group)
8199        (symbol-name group)
8200        (memq 'respool
8201              (assoc (symbol-name
8202                      (car (gnus-find-method-for-group
8203                            (symbol-name group))))
8204                     gnus-valid-select-methods))))
8205
8206 (defun gnus-read-move-group-name (prompt default articles prefix)
8207   "Read a group name."
8208   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
8209          (minibuffer-confirm-incomplete nil) ; XEmacs
8210          (prom
8211           (format "%s %s to:"
8212                   prompt
8213                   (if (> (length articles) 1)
8214                       (format "these %d articles" (length articles))
8215                     "this article")))
8216          (to-newsgroup
8217           (cond
8218            ((null split-name)
8219             (gnus-completing-read default prom
8220                                   gnus-active-hashtb
8221                                   'gnus-valid-move-group-p
8222                                   nil prefix
8223                                   'gnus-group-history))
8224            ((= 1 (length split-name))
8225             (gnus-completing-read (car split-name) prom
8226                                   gnus-active-hashtb
8227                                   'gnus-valid-move-group-p
8228                                   nil nil
8229                                   'gnus-group-history))
8230            (t
8231             (gnus-completing-read nil prom 
8232                                   (mapcar (lambda (el) (list el))
8233                                           (nreverse split-name))
8234                                   nil nil nil
8235                                   'gnus-group-history)))))
8236     (when to-newsgroup
8237       (if (or (string= to-newsgroup "")
8238               (string= to-newsgroup prefix))
8239           (setq to-newsgroup (or default "")))
8240       (or (gnus-active to-newsgroup)
8241           (gnus-activate-group to-newsgroup)
8242           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
8243                                      to-newsgroup))
8244               (or (and (gnus-request-create-group 
8245                         to-newsgroup (gnus-group-name-to-method to-newsgroup))
8246                        (gnus-activate-group to-newsgroup nil nil
8247                                             (gnus-group-name-to-method
8248                                              to-newsgroup)))
8249                   (error "Couldn't create group %s" to-newsgroup)))
8250           (error "No such group: %s" to-newsgroup)))
8251     to-newsgroup))
8252
8253 ;; Summary extract commands
8254
8255 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
8256   (let ((buffer-read-only nil)
8257         (article (gnus-summary-article-number))
8258         after-article b e)
8259     (unless (gnus-summary-goto-subject article)
8260       (error "No such article: %d" article))
8261     (gnus-summary-position-point)
8262     ;; If all commands are to be bunched up on one line, we collect
8263     ;; them here.
8264     (unless gnus-view-pseudos-separately
8265       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
8266             files action)
8267         (while ps
8268           (setq action (cdr (assq 'action (car ps))))
8269           (setq files (list (cdr (assq 'name (car ps)))))
8270           (while (and ps (cdr ps)
8271                       (string= (or action "1")
8272                                (or (cdr (assq 'action (cadr ps))) "2")))
8273             (push (cdr (assq 'name (cadr ps))) files)
8274             (setcdr ps (cddr ps)))
8275           (when files
8276             (when (not (string-match "%s" action))
8277               (push " " files))
8278             (push " " files)
8279             (when (assq 'execute (car ps))
8280               (setcdr (assq 'execute (car ps))
8281                       (funcall (if (string-match "%s" action)
8282                                    'format 'concat)
8283                                action
8284                                (mapconcat
8285                                 (lambda (f)
8286                                   (if (equal f " ")
8287                                       f
8288                                     (gnus-quote-arg-for-sh-or-csh f)))
8289                                 files " ")))))
8290           (setq ps (cdr ps)))))
8291     (if (and gnus-view-pseudos (not not-view))
8292         (while pslist
8293           (when (assq 'execute (car pslist))
8294             (gnus-execute-command (cdr (assq 'execute (car pslist)))
8295                                   (eq gnus-view-pseudos 'not-confirm)))
8296           (setq pslist (cdr pslist)))
8297       (save-excursion
8298         (while pslist
8299           (setq after-article (or (cdr (assq 'article (car pslist)))
8300                                   (gnus-summary-article-number)))
8301           (gnus-summary-goto-subject after-article)
8302           (forward-line 1)
8303           (setq b (point))
8304           (insert "    " (file-name-nondirectory
8305                           (cdr (assq 'name (car pslist))))
8306                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
8307           (setq e (point))
8308           (forward-line -1)             ; back to `b'
8309           (gnus-add-text-properties
8310            b (1- e) (list 'gnus-number gnus-reffed-article-number
8311                           gnus-mouse-face-prop gnus-mouse-face))
8312           (gnus-data-enter
8313            after-article gnus-reffed-article-number
8314            gnus-unread-mark b (car pslist) 0 (- e b))
8315           (push gnus-reffed-article-number gnus-newsgroup-unreads)
8316           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
8317           (setq pslist (cdr pslist)))))))
8318
8319 (defun gnus-pseudos< (p1 p2)
8320   (let ((c1 (cdr (assq 'action p1)))
8321         (c2 (cdr (assq 'action p2))))
8322     (and c1 c2 (string< c1 c2))))
8323
8324 (defun gnus-request-pseudo-article (props)
8325   (cond ((assq 'execute props)
8326          (gnus-execute-command (cdr (assq 'execute props)))))
8327   (let ((gnus-current-article (gnus-summary-article-number)))
8328     (run-hooks 'gnus-mark-article-hook)))
8329
8330 (defun gnus-execute-command (command &optional automatic)
8331   (save-excursion
8332     (gnus-article-setup-buffer)
8333     (set-buffer gnus-article-buffer)
8334     (setq buffer-read-only nil)
8335     (let ((command (if automatic command (read-string "Command: " command)))
8336           ;; Just binding this here doesn't help, because there might
8337           ;; be output from the process after exiting the scope of 
8338           ;; this `let'.
8339           ;; (buffer-read-only nil)
8340           )
8341       (erase-buffer)
8342       (insert "$ " command "\n\n")
8343       (if gnus-view-pseudo-asynchronously
8344           (start-process "gnus-execute" nil shell-file-name
8345                          shell-command-switch command)
8346         (call-process shell-file-name nil t nil
8347                       shell-command-switch command)))))
8348
8349 ;; Summary kill commands.
8350
8351 (defun gnus-summary-edit-global-kill (article)
8352   "Edit the \"global\" kill file."
8353   (interactive (list (gnus-summary-article-number)))
8354   (gnus-set-global-variables)
8355   (gnus-group-edit-global-kill article))
8356
8357 (defun gnus-summary-edit-local-kill ()
8358   "Edit a local kill file applied to the current newsgroup."
8359   (interactive)
8360   (gnus-set-global-variables)
8361   (setq gnus-current-headers (gnus-summary-article-header))
8362   (gnus-set-global-variables)
8363   (gnus-group-edit-local-kill
8364    (gnus-summary-article-number) gnus-newsgroup-name))
8365
8366 ;;; Header reading.
8367
8368 (defun gnus-read-header (id &optional header)
8369   "Read the headers of article ID and enter them into the Gnus system."
8370   (let ((group gnus-newsgroup-name)
8371         (gnus-override-method 
8372          (and (gnus-news-group-p gnus-newsgroup-name)
8373               gnus-refer-article-method))
8374         where)
8375     ;; First we check to see whether the header in question is already
8376     ;; fetched.
8377     (if (stringp id)
8378         ;; This is a Message-ID.
8379         (setq header (or header (gnus-id-to-header id)))
8380       ;; This is an article number.
8381       (setq header (or header (gnus-summary-article-header id))))
8382     (if (and header
8383              (not (gnus-summary-article-sparse-p (mail-header-number header))))
8384         ;; We have found the header.
8385         header
8386       ;; We have to really fetch the header to this article.
8387       (save-excursion
8388         (set-buffer nntp-server-buffer)
8389         (when (setq where (gnus-request-head id group))
8390           (nnheader-fold-continuation-lines)
8391           (goto-char (point-max))
8392           (insert ".\n")
8393           (goto-char (point-min))
8394           (insert "211 ")
8395           (princ (cond
8396                   ((numberp id) id)
8397                   ((cdr where) (cdr where))
8398                   (header (mail-header-number header))
8399                   (t gnus-reffed-article-number))
8400                  (current-buffer))
8401           (insert " Article retrieved.\n"))
8402         (if (or (not where)
8403                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
8404             ()                          ; Malformed head.
8405           (unless (gnus-summary-article-sparse-p (mail-header-number header))
8406             (when (and (stringp id)
8407                        (not (string= (gnus-group-real-name group)
8408                                      (car where))))
8409               ;; If we fetched by Message-ID and the article came
8410               ;; from a different group, we fudge some bogus article
8411               ;; numbers for this article.
8412               (mail-header-set-number header gnus-reffed-article-number))
8413             (save-excursion
8414               (set-buffer gnus-summary-buffer)
8415               (decf gnus-reffed-article-number)
8416               (gnus-remove-header (mail-header-number header))
8417               (push header gnus-newsgroup-headers)
8418               (setq gnus-current-headers header)
8419               (push (mail-header-number header) gnus-newsgroup-limit)))
8420           header)))))
8421
8422 (defun gnus-remove-header (number)
8423   "Remove header NUMBER from `gnus-newsgroup-headers'."
8424   (if (and gnus-newsgroup-headers
8425            (= number (mail-header-number (car gnus-newsgroup-headers))))
8426       (pop gnus-newsgroup-headers)
8427     (let ((headers gnus-newsgroup-headers))
8428       (while (and (cdr headers)
8429                   (not (= number (mail-header-number (cadr headers)))))
8430         (pop headers))
8431       (when (cdr headers)
8432         (setcdr headers (cddr headers))))))
8433
8434 ;;;
8435 ;;; summary highlights
8436 ;;;
8437
8438 (defun gnus-highlight-selected-summary ()
8439   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
8440   ;; Highlight selected article in summary buffer
8441   (when gnus-summary-selected-face
8442     (save-excursion
8443       (let* ((beg (progn (beginning-of-line) (point)))
8444              (end (progn (end-of-line) (point)))
8445              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
8446              (from (if (get-text-property beg gnus-mouse-face-prop)
8447                        beg
8448                      (or (next-single-property-change 
8449                           beg gnus-mouse-face-prop nil end)
8450                          beg)))
8451              (to
8452               (if (= from end)
8453                   (- from 2)
8454                 (or (next-single-property-change
8455                      from gnus-mouse-face-prop nil end)
8456                     end))))
8457         ;; If no mouse-face prop on line we will have to = from = end,
8458         ;; so we highlight the entire line instead.
8459         (when (= (+ to 2) from)
8460           (setq from beg)
8461           (setq to end))
8462         (if gnus-newsgroup-selected-overlay
8463             ;; Move old overlay.
8464             (gnus-move-overlay
8465              gnus-newsgroup-selected-overlay from to (current-buffer))
8466           ;; Create new overlay.
8467           (gnus-overlay-put
8468            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
8469            'face gnus-summary-selected-face))))))
8470
8471 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
8472 (defun gnus-summary-highlight-line ()
8473   "Highlight current line according to `gnus-summary-highlight'."
8474   (let* ((list gnus-summary-highlight)
8475          (p (point))
8476          (end (progn (end-of-line) (point)))
8477          ;; now find out where the line starts and leave point there.
8478          (beg (progn (beginning-of-line) (point)))
8479          (article (gnus-summary-article-number))
8480          (score (or (cdr (assq (or article gnus-current-article)
8481                                gnus-newsgroup-scored))
8482                     gnus-summary-default-score 0))
8483          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
8484          (inhibit-read-only t))
8485     ;; Eval the cars of the lists until we find a match.
8486     (let ((default gnus-summary-default-score))
8487       (while (and list
8488                   (not (eval (caar list))))
8489         (setq list (cdr list))))
8490     (let ((face (cdar list)))
8491       (unless (eq face (get-text-property beg 'face))
8492         (gnus-put-text-property 
8493          beg end 'face 
8494          (setq face (if (boundp face) (symbol-value face) face)))
8495         (when gnus-summary-highlight-line-function
8496           (funcall gnus-summary-highlight-line-function article face))))
8497     (goto-char p)))
8498
8499 (defun gnus-update-read-articles (group unread)
8500   "Update the list of read articles in GROUP."
8501   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
8502          (entry (gnus-gethash group gnus-newsrc-hashtb))
8503          (info (nth 2 entry))
8504          (prev 1)
8505          (unread (sort (copy-sequence unread) '<))
8506          read)
8507     (if (or (not info) (not active))
8508         ;; There is no info on this group if it was, in fact,
8509         ;; killed.  Gnus stores no information on killed groups, so
8510         ;; there's nothing to be done.
8511         ;; One could store the information somewhere temporarily,
8512         ;; perhaps...  Hmmm...
8513         ()
8514       ;; Remove any negative articles numbers.
8515       (while (and unread (< (car unread) 0))
8516         (setq unread (cdr unread)))
8517       ;; Remove any expired article numbers
8518       (while (and unread (< (car unread) (car active)))
8519         (setq unread (cdr unread)))
8520       ;; Compute the ranges of read articles by looking at the list of
8521       ;; unread articles.
8522       (while unread
8523         (when (/= (car unread) prev)
8524           (push (if (= prev (1- (car unread))) prev
8525                   (cons prev (1- (car unread))))
8526                 read))
8527         (setq prev (1+ (car unread)))
8528         (setq unread (cdr unread)))
8529       (when (<= prev (cdr active))
8530         (push (cons prev (cdr active)) read))
8531       (save-excursion
8532         (set-buffer gnus-group-buffer)
8533         (gnus-undo-register
8534           `(progn
8535              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
8536              (gnus-info-set-read ',info ',(gnus-info-read info))
8537              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
8538              (gnus-group-update-group ,group t))))
8539       ;; Enter this list into the group info.
8540       (gnus-info-set-read
8541        info (if (> (length read) 1) (nreverse read) read))
8542       ;; Set the number of unread articles in gnus-newsrc-hashtb.
8543       (gnus-get-unread-articles-in-group info (gnus-active group))
8544       t)))
8545
8546 (defun gnus-offer-save-summaries ()
8547   "Offer to save all active summary buffers."
8548   (save-excursion
8549     (let ((buflist (buffer-list))
8550           buffers bufname)
8551       ;; Go through all buffers and find all summaries.
8552       (while buflist
8553         (and (setq bufname (buffer-name (car buflist)))
8554              (string-match "Summary" bufname)
8555              (save-excursion
8556                (set-buffer bufname)
8557                ;; We check that this is, indeed, a summary buffer.
8558                (and (eq major-mode 'gnus-summary-mode)
8559                     ;; Also make sure this isn't bogus.
8560                     gnus-newsgroup-prepared
8561                     ;; Also make sure that this isn't a dead summary buffer.
8562                     (not gnus-dead-summary-mode)))
8563              (push bufname buffers))
8564         (setq buflist (cdr buflist)))
8565       ;; Go through all these summary buffers and offer to save them.
8566       (when buffers
8567         (map-y-or-n-p
8568          "Update summary buffer %s? "
8569          (lambda (buf) (switch-to-buffer buf) (gnus-summary-exit))
8570          buffers)))))
8571
8572 (provide 'gnus-sum)
8573
8574 (run-hooks 'gnus-sum-load-hook)
8575
8576 ;;; gnus-sum.el ends here