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