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