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