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