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