*** 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
130   'gnus-gather-threads-by-subject
131   "Function used for gathering loose threads.
132 There are two pre-defined functions: `gnus-gather-threads-by-subject',
133 which only takes Subjects into consideration; and
134 `gnus-gather-threads-by-references', which compared the References
135 headers of the articles to find matches."
136   :group 'gnus-thread
137   :type '(set (function-item gnus-gather-threads-by-subject)
138               (function-item gnus-gather-threads-by-references)
139               (function :tag "other")))
140
141 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
142 (defcustom gnus-summary-same-subject ""
143   "*String indicating that the current article has the same subject as the previous.
144 This variable will only be used if the value of
145 `gnus-summary-make-false-root' is `empty'."
146   :group 'gnus-summary-format
147   :type 'string)
148
149 (defcustom gnus-summary-goto-unread t
150   "*If t, marking commands will go to the next unread article.
151 If `never', commands that usually go to the next unread article, will
152 go to the next article, whether it is read or not.
153 If nil, only the marking commands will go to the next (un)read article."
154   :group 'gnus-summary-marks
155   :link '(custom-manual "(gnus)Setting Marks")
156   :type '(choice (const :tag "off" nil)
157                  (const never)
158                  (sexp :menu-tag "on" t)))
159
160 (defcustom gnus-summary-default-score 0
161   "*Default article score level.
162 All scores generated by the score files will be added to this score.
163 If this variable is nil, scoring will be disabled."
164   :group 'gnus-score-default
165   :type '(choice (const :tag "disable")
166                  integer))
167
168 (defcustom gnus-summary-zcore-fuzz 0
169   "*Fuzziness factor for the zcore in the summary buffer.
170 Articles with scores closer than this to `gnus-summary-default-score'
171 will not be marked."
172   :group 'gnus-summary-format
173   :type 'integer)
174
175 (defcustom gnus-simplify-subject-fuzzy-regexp nil
176   "*Strings to be removed when doing fuzzy matches.
177 This can either be a regular expression or list of regular expressions
178 that will be removed from subject strings if fuzzy subject
179 simplification is selected."
180   :group 'gnus-thread
181   :type '(repeat regexp))
182
183 (defcustom gnus-show-threads t
184   "*If non-nil, display threads in summary mode."
185   :group 'gnus-thread
186   :type 'boolean)
187
188 (defcustom gnus-thread-hide-subtree nil
189   "*If non-nil, hide all threads initially.
190 If threads are hidden, you have to run the command
191 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
192 to expose hidden threads."
193   :group 'gnus-thread
194   :type 'boolean)
195
196 (defcustom gnus-thread-hide-killed t
197   "*If non-nil, hide killed threads automatically."
198   :group 'gnus-thread
199   :type 'boolean)
200
201 (defcustom gnus-thread-ignore-subject nil
202   "*If non-nil, ignore subjects and do all threading based on the Reference header.
203 If nil, which is the default, articles that have different subjects
204 from their parents will start separate threads."
205   :group 'gnus-thread
206   :type 'boolean)
207
208 (defcustom gnus-thread-operation-ignore-subject t
209   "*If non-nil, subjects will be ignored when doing thread commands.
210 This affects commands like `gnus-summary-kill-thread' and
211 `gnus-summary-lower-thread'.
212
213 If this variable is nil, articles in the same thread with different
214 subjects will not be included in the operation in question.  If this
215 variable is `fuzzy', only articles that have subjects that are fuzzily
216 equal will be included."
217   :group 'gnus-thread
218   :type '(choice (const :tag "off" nil)
219                  (const fuzzy)
220                  (sexp :tag "on" t)))
221
222 (defcustom gnus-thread-indent-level 4
223   "*Number that says how much each sub-thread should be indented."
224   :group 'gnus-thread
225   :type 'integer)
226
227 (defcustom gnus-auto-extend-newsgroup t
228   "*If non-nil, extend newsgroup forward and backward when requested."
229   :group 'gnus-summary-choose
230   :type 'boolean)
231
232 (defcustom gnus-auto-select-first t
233   "*If nil, don't select the first unread article when entering a group.
234 If this variable is `best', select the highest-scored unread article
235 in the group.  If neither nil nor `best', select the first unread
236 article.
237
238 If you want to prevent automatic selection of the first unread article
239 in some newsgroups, set the variable to nil in
240 `gnus-select-group-hook'."
241   :group 'gnus-group-select
242   :type '(choice (const :tag "none" nil)
243                  (const best)
244                  (sexp :menu-tag "first" t)))
245
246 (defcustom gnus-auto-select-next t
247   "*If non-nil, offer to go to the next group from the end of the previous.
248 If the value is t and the next newsgroup is empty, Gnus will exit
249 summary mode and go back to group mode.  If the value is neither nil
250 nor t, Gnus will select the following unread newsgroup.  In
251 particular, if the value is the symbol `quietly', the next unread
252 newsgroup will be selected without any confirmation, and if it is
253 `almost-quietly', the next group will be selected without any
254 confirmation if you are located on the last article in the group.
255 Finally, if this variable is `slightly-quietly', the `Z n' command
256 will go to the next group without confirmation."
257   :group 'gnus-summary-maneuvering
258   :type '(choice (const :tag "off" nil)
259                  (const quietly)
260                  (const almost-quietly)
261                  (const slightly-quietly)
262                  (sexp :menu-tag "on" t)))
263
264 (defcustom gnus-auto-select-same nil
265   "*If non-nil, select the next article with the same subject."
266   :group 'gnus-summary-maneuvering
267   :type 'boolean)
268
269 (defcustom gnus-summary-check-current nil
270   "*If non-nil, consider the current article when moving.
271 The \"unread\" movement commands will stay on the same line if the
272 current article is unread."
273   :group 'gnus-summary-maneuvering
274   :type 'boolean)
275
276 (defcustom gnus-auto-center-summary t
277   "*If non-nil, always center the current summary buffer.
278 In particular, if `vertical' do only vertical recentering.  If non-nil
279 and non-`vertical', do both horizontal and vertical recentering."
280   :group 'gnus-summary-maneuvering
281   :type '(choice (const :tag "none" nil)
282                  (const vertical)
283                  (sexp :menu-tag "both" t)))
284
285 (defcustom gnus-show-all-headers nil
286   "*If non-nil, don't hide any headers."
287   :group 'gnus-article-hiding
288   :group 'gnus-article-headers
289   :type 'boolean)
290
291 (defcustom gnus-summary-ignore-duplicates nil
292   "*If non-nil, ignore articles with identical Message-ID headers."
293   :group 'gnus-summary
294   :type 'boolean)
295   
296 (defcustom gnus-single-article-buffer t
297   "*If non-nil, display all articles in the same buffer.
298 If nil, each group will get its own article buffer."
299   :group 'gnus-article-various
300   :type 'boolean)
301
302 (defcustom gnus-break-pages t
303   "*If non-nil, do page breaking on articles.
304 The page delimiter is specified by the `gnus-page-delimiter'
305 variable."
306   :group 'gnus-article-various
307   :type 'boolean)
308
309 (defcustom gnus-show-mime nil
310   "*If non-nil, do mime processing of articles.
311 The articles will simply be fed to the function given by
312 `gnus-show-mime-method'."
313   :group 'gnus-article-mime
314   :type 'boolean)
315
316 (defcustom gnus-move-split-methods nil
317   "*Variable used to suggest where articles are to be moved to.
318 It uses the same syntax as the `gnus-split-methods' variable."
319   :group 'gnus-summary-mail
320   :type '(repeat (choice (list function)
321                          (cons regexp (repeat string))
322                          sexp)))
323
324 (defcustom gnus-unread-mark ? 
325   "*Mark used for unread articles."
326   :group 'gnus-summary-marks
327   :type 'character)
328
329 (defcustom gnus-ticked-mark ?!
330   "*Mark used for ticked articles."
331   :group 'gnus-summary-marks
332   :type 'character)
333
334 (defcustom gnus-dormant-mark ??
335   "*Mark used for dormant articles."
336   :group 'gnus-summary-marks
337   :type 'character)
338
339 (defcustom gnus-del-mark ?r
340   "*Mark used for del'd articles."
341   :group 'gnus-summary-marks
342   :type 'character)
343
344 (defcustom gnus-read-mark ?R
345   "*Mark used for read articles."
346   :group 'gnus-summary-marks
347   :type 'character)
348
349 (defcustom gnus-expirable-mark ?E
350   "*Mark used for expirable articles."
351   :group 'gnus-summary-marks
352   :type 'character)
353
354 (defcustom gnus-killed-mark ?K
355   "*Mark used for killed articles."
356   :group 'gnus-summary-marks
357   :type 'character)
358
359 (defcustom gnus-souped-mark ?F
360   "*Mark used for killed articles."
361   :group 'gnus-summary-marks
362   :type 'character)
363
364 (defcustom gnus-kill-file-mark ?X
365   "*Mark used for articles killed by kill files."
366   :group 'gnus-summary-marks
367   :type 'character)
368
369 (defcustom gnus-low-score-mark ?Y
370   "*Mark used for articles with a low score."
371   :group 'gnus-summary-marks
372   :type 'character)
373
374 (defcustom gnus-catchup-mark ?C
375   "*Mark used for articles that are caught up."
376   :group 'gnus-summary-marks
377   :type 'character)
378
379 (defcustom gnus-replied-mark ?A
380   "*Mark used for articles that have been replied to."
381   :group 'gnus-summary-marks
382   :type 'character)
383
384 (defcustom gnus-cached-mark ?*
385   "*Mark used for articles that are in the cache."
386   :group 'gnus-summary-marks
387   :type 'character)
388
389 (defcustom gnus-saved-mark ?S
390   "*Mark used for articles that have been saved to."
391   :group 'gnus-summary-marks
392   :type 'character)
393
394 (defcustom gnus-ancient-mark ?O
395   "*Mark used for ancient articles."
396   :group 'gnus-summary-marks
397   :type 'character)
398
399 (defcustom gnus-sparse-mark ?Q
400   "*Mark used for sparsely reffed articles."
401   :group 'gnus-summary-marks
402   :type 'character)
403
404 (defcustom gnus-canceled-mark ?G
405   "*Mark used for canceled articles."
406   :group 'gnus-summary-marks
407   :type 'character)
408
409 (defcustom gnus-duplicate-mark ?M
410   "*Mark used for duplicate articles."
411   :group 'gnus-summary-marks
412   :type 'character)
413
414 (defcustom gnus-score-over-mark ?+
415   "*Score mark used for articles with high scores."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-score-below-mark ?-
420   "*Score mark used for articles with low scores."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-empty-thread-mark ? 
425   "*There is no thread under the article."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-not-empty-thread-mark ?=
430   "*There is a thread under the article."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-view-pseudo-asynchronously nil
435   "*If non-nil, Gnus will view pseudo-articles asynchronously."
436   :group 'gnus-extract-view
437   :type 'boolean)
438
439 (defcustom gnus-view-pseudos nil
440   "*If `automatic', pseudo-articles will be viewed automatically.
441 If `not-confirm', pseudos will be viewed automatically, and the user
442 will not be asked to confirm the command."
443   :group 'gnus-extract-view
444   :type '(choice (const :tag "off" nil)
445                  (const automatic)
446                  (const not-confirm)))
447
448 (defcustom gnus-view-pseudos-separately t
449   "*If non-nil, one pseudo-article will be created for each file to be viewed.
450 If nil, all files that use the same viewing command will be given as a
451 list of parameters to that command."
452   :group 'gnus-extract-view
453   :type 'boolean)
454
455 (defcustom gnus-insert-pseudo-articles t
456   "*If non-nil, insert pseudo-articles when decoding articles."
457   :group 'gnus-extract-view
458   :type 'boolean)
459
460 (defcustom gnus-summary-dummy-line-format
461   "*  %(:                          :%) %S\n"
462   "*The format specification for the dummy roots in the summary buffer.
463 It works along the same lines as a normal formatting string,
464 with some simple extensions.
465
466 %S  The subject"
467   :group 'gnus-threading
468   :type 'string)
469
470 (defcustom gnus-summary-mode-line-format "Gnus: %%b [%A] %Z"
471   "*The format specification for the summary mode line.
472 It works along the same lines as a normal formatting string,
473 with some simple extensions:
474
475 %G  Group name
476 %p  Unprefixed group name
477 %A  Current article number
478 %V  Gnus version
479 %U  Number of unread articles in the group
480 %e  Number of unselected articles in the group
481 %Z  A string with unread/unselected article counts
482 %g  Shortish group name
483 %S  Subject of the current article
484 %u  User-defined spec
485 %s  Current score file name
486 %d  Number of dormant articles
487 %r  Number of articles that have been marked as read in this session
488 %E  Number of articles expunged by the score files"
489   :group 'gnus-summary-format
490   :type 'string)
491
492 (defcustom gnus-summary-mark-below 0
493   "*Mark all articles with a score below this variable as read.
494 This variable is local to each summary buffer and usually set by the
495 score file."
496   :group 'gnus-score-default
497   :type 'integer)
498
499 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
500   "*List of functions used for sorting articles in the summary buffer.
501 This variable is only used when not using a threaded display."
502   :group 'gnus-summary-sort
503   :type '(repeat (choice (function-item gnus-article-sort-by-number)
504                          (function-item gnus-article-sort-by-author)
505                          (function-item gnus-article-sort-by-subject)
506                          (function-item gnus-article-sort-by-date)
507                          (function-item gnus-article-sort-by-score)
508                          (function :tag "other"))))
509
510 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
511   "*List of functions used for sorting threads in the summary buffer.
512 By default, threads are sorted by article number.
513
514 Each function takes two threads and return non-nil if the first thread
515 should be sorted before the other.  If you use more than one function,
516 the primary sort function should be the last.  You should probably
517 always include `gnus-thread-sort-by-number' in the list of sorting
518 functions -- preferably first.
519
520 Ready-made functions include `gnus-thread-sort-by-number',
521 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
522 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
523 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
524   :group 'gnus-summary-sort
525   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
526                          (function-item gnus-thread-sort-by-author)
527                          (function-item gnus-thread-sort-by-subject)
528                          (function-item gnus-thread-sort-by-date)
529                          (function-item gnus-thread-sort-by-score)
530                          (function-item gnus-thread-sort-by-total-score)
531                          (function :tag "other"))))
532
533 (defcustom gnus-thread-score-function '+
534   "*Function used for calculating the total score of a thread.
535
536 The function is called with the scores of the article and each
537 subthread and should then return the score of the thread.
538
539 Some functions you can use are `+', `max', or `min'."
540   :group 'gnus-summary-sort
541   :type 'function)
542
543 (defcustom gnus-summary-expunge-below nil
544   "All articles that have a score less than this variable will be expunged."
545   :group 'gnus-score-default
546   :type '(choice (const :tag "off" nil)
547                  integer))
548
549 (defcustom gnus-thread-expunge-below nil
550   "All threads that have a total score less than this variable will be expunged.
551 See `gnus-thread-score-function' for en explanation of what a
552 \"thread score\" is."
553   :group 'gnus-treading
554   :group 'gnus-score-default
555   :type '(choice (const :tag "off" nil)
556                  integer))
557
558 (defcustom gnus-summary-mode-hook nil
559   "*A hook for Gnus summary mode.
560 This hook is run before any variables are set in the summary buffer."
561   :group 'gnus-summary-various
562   :type 'hook)
563
564 (defcustom gnus-summary-menu-hook nil
565   "*Hook run after the creation of the summary mode menu."
566   :group 'gnus-summary-visual
567   :type 'hook)
568
569 (defcustom gnus-summary-exit-hook nil
570   "*A hook called on exit from the summary buffer.
571 It will be called with point in the group buffer."
572   :group 'gnus-summary-exit
573   :type 'hook)
574
575 (defcustom gnus-summary-prepare-hook nil
576   "*A hook called after the summary buffer has been generated.
577 If you want to modify the summary buffer, you can use this hook."
578   :group 'gnus-summary-various
579   :type 'hook)
580
581 (defcustom gnus-summary-generate-hook nil
582   "*A hook run just before generating the summary buffer.
583 This hook is commonly used to customize threading variables and the
584 like."
585   :group 'gnus-summary-various
586   :type 'hook)
587
588 (defcustom gnus-select-group-hook nil
589   "*A hook called when a newsgroup is selected.
590
591 If you'd like to simplify subjects like the
592 `gnus-summary-next-same-subject' command does, you can use the
593 following hook:
594
595  (setq gnus-select-group-hook
596       (list
597         (lambda ()
598           (mapcar (lambda (header)
599                      (mail-header-set-subject
600                       header
601                       (gnus-simplify-subject
602                        (mail-header-subject header) 're-only)))
603                   gnus-newsgroup-headers))))"
604   :group 'gnus-group-select
605   :type 'hook)
606
607 (defcustom gnus-select-article-hook nil
608   "*A hook called when an article is selected."
609   :group 'gnus-summary-choose
610   :type 'hook)
611
612 (defcustom gnus-visual-mark-article-hook
613   (list 'gnus-highlight-selected-summary)
614   "*Hook run after selecting an article in the summary buffer.
615 It is meant to be used for highlighting the article in some way.  It
616 is not run if `gnus-visual' is nil."
617   :group 'gnus-summary-visual
618   :type 'hook)
619
620 (defcustom gnus-parse-headers-hook
621   (list 'gnus-decode-rfc1522)
622   "*A hook called before parsing the headers."
623   :group 'gnus-various
624   :type 'hook)
625
626 (defcustom gnus-exit-group-hook nil
627   "*A hook called when exiting (not quitting) summary mode."
628   :group 'gnus-various
629   :type 'hook)
630
631 (defcustom gnus-summary-update-hook
632   (list 'gnus-summary-highlight-line)
633   "*A hook called when a summary line is changed.
634 The hook will not be called if `gnus-visual' is nil.
635
636 The default function `gnus-summary-highlight-line' will
637 highlight the line according to the `gnus-summary-highlight'
638 variable."
639   :group 'gnus-summary-visual
640   :type 'hook)
641
642 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
643   "*A hook called when an article is selected for the first time.
644 The hook is intended to mark an article as read (or unread)
645 automatically when it is selected."
646   :group 'gnus-summary-choose
647   :type 'hook)
648
649 (defcustom gnus-group-no-more-groups-hook nil
650   "*A hook run when returning to group mode having no more (unread) groups."
651   :group 'gnus-group-select
652   :type 'hook)
653
654 (defcustom gnus-ps-print-hook nil
655   "*A hook run before ps-printing something from Gnus."
656   :group 'gnus-summary
657   :type 'hook)
658
659 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
660   "Face used for highlighting the current article in the summary buffer."
661   :group 'gnus-summary-visual
662   :type 'face)
663
664 (defcustom gnus-summary-highlight
665   '(((= mark gnus-canceled-mark)
666      . gnus-summary-cancelled-face)
667     ((and (> score default)
668           (or (= mark gnus-dormant-mark)
669               (= mark gnus-ticked-mark)))
670      . gnus-summary-high-ticked-face)
671     ((and (< score default)
672           (or (= mark gnus-dormant-mark)
673               (= mark gnus-ticked-mark)))
674      . gnus-summary-low-ticked-face)
675     ((or (= mark gnus-dormant-mark)
676          (= mark gnus-ticked-mark))
677      . gnus-summary-normal-ticked-face)
678     ((and (> score default) (= mark gnus-ancient-mark))
679      . gnus-summary-high-ancient-face)
680     ((and (< score default) (= mark gnus-ancient-mark))
681      . gnus-summary-low-ancient-face)
682     ((= mark gnus-ancient-mark)
683      . gnus-summary-normal-ancient-face)
684     ((and (> score default) (= mark gnus-unread-mark))
685      . gnus-summary-high-unread-face)
686     ((and (< score default) (= mark gnus-unread-mark))
687      . gnus-summary-low-unread-face)
688     ((and (= mark gnus-unread-mark))
689      . gnus-summary-normal-unread-face)
690     ((> score default)
691      . gnus-summary-high-read-face)
692     ((< score default)
693      . gnus-summary-low-read-face)
694     (t
695      . gnus-summary-normal-read-face))
696   "Controls the highlighting of summary buffer lines.
697
698 A list of (FORM . FACE) pairs.  When deciding how a a particular
699 summary line should be displayed, each form is evaluated.  The content
700 of the face field after the first true form is used.  You can change
701 how those summary lines are displayed, by editing the face field.
702
703 You can use the following variables in the FORM field.
704
705 score:   The articles score
706 default: The default article score.
707 below:   The score below which articles are automatically marked as read.
708 mark:    The articles mark."
709   :group 'gnus-summary-visual
710   :type '(repeat (cons (sexp :tag "Form" nil)
711                        face)))
712
713
714 ;;; Internal variables
715
716 (defvar gnus-scores-exclude-files nil)
717 (defvar gnus-page-broken nil)
718
719 (defvar gnus-original-article nil)
720 (defvar gnus-article-internal-prepare-hook nil)
721 (defvar gnus-newsgroup-process-stack nil)
722
723 (defvar gnus-thread-indent-array nil)
724 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
725
726 ;; Avoid highlighting in kill files.
727 (defvar gnus-summary-inhibit-highlight nil)
728 (defvar gnus-newsgroup-selected-overlay nil)
729 (defvar gnus-inhibit-limiting nil)
730 (defvar gnus-newsgroup-adaptive-score-file nil)
731 (defvar gnus-current-score-file nil)
732 (defvar gnus-current-move-group nil)
733 (defvar gnus-current-copy-group nil)
734 (defvar gnus-current-crosspost-group nil)
735
736 (defvar gnus-newsgroup-dependencies nil)
737 (defvar gnus-newsgroup-adaptive nil)
738 (defvar gnus-summary-display-article-function nil)
739 (defvar gnus-summary-highlight-line-function nil
740   "Function called after highlighting a summary line.")
741
742 (defvar gnus-summary-line-format-alist
743   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
744     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
745     (?s gnus-tmp-subject-or-nil ?s)
746     (?n gnus-tmp-name ?s)
747     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
748         ?s)
749     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
750             gnus-tmp-from) ?s)
751     (?F gnus-tmp-from ?s)
752     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
753     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
754     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
755     (?o (gnus-date-iso8601 gnus-tmp-header) ?s)
756     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
757     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
758     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
759     (?L gnus-tmp-lines ?d)
760     (?I gnus-tmp-indentation ?s)
761     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
762     (?R gnus-tmp-replied ?c)
763     (?\[ gnus-tmp-opening-bracket ?c)
764     (?\] gnus-tmp-closing-bracket ?c)
765     (?\> (make-string gnus-tmp-level ? ) ?s)
766     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
767     (?i gnus-tmp-score ?d)
768     (?z gnus-tmp-score-char ?c)
769     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
770     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
771     (?U gnus-tmp-unread ?c)
772     (?t (gnus-summary-number-of-articles-in-thread
773          (and (boundp 'thread) (car thread)) gnus-tmp-level)
774         ?d)
775     (?e (gnus-summary-number-of-articles-in-thread
776          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
777         ?c)
778     (?u gnus-tmp-user-defined ?s)
779     (?P (gnus-pick-line-number) ?d))
780   "An alist of format specifications that can appear in summary lines,
781 and what variables they correspond with, along with the type of the
782 variable (string, integer, character, etc).")
783
784 (defvar gnus-summary-dummy-line-format-alist
785   `((?S gnus-tmp-subject ?s)
786     (?N gnus-tmp-number ?d)
787     (?u gnus-tmp-user-defined ?s)))
788
789 (defvar gnus-summary-mode-line-format-alist
790   `((?G gnus-tmp-group-name ?s)
791     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
792     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
793     (?A gnus-tmp-article-number ?d)
794     (?Z gnus-tmp-unread-and-unselected ?s)
795     (?V gnus-version ?s)
796     (?U gnus-tmp-unread-and-unticked ?d)
797     (?S gnus-tmp-subject ?s)
798     (?e gnus-tmp-unselected ?d)
799     (?u gnus-tmp-user-defined ?s)
800     (?d (length gnus-newsgroup-dormant) ?d)
801     (?t (length gnus-newsgroup-marked) ?d)
802     (?r (length gnus-newsgroup-reads) ?d)
803     (?E gnus-newsgroup-expunged-tally ?d)
804     (?s (gnus-current-score-file-nondirectory) ?s)))
805
806 (defvar gnus-last-search-regexp nil
807   "Default regexp for article search command.")
808
809 (defvar gnus-last-shell-command nil
810   "Default shell command on article.")
811
812 (defvar gnus-newsgroup-begin nil)
813 (defvar gnus-newsgroup-end nil)
814 (defvar gnus-newsgroup-last-rmail nil)
815 (defvar gnus-newsgroup-last-mail nil)
816 (defvar gnus-newsgroup-last-folder nil)
817 (defvar gnus-newsgroup-last-file nil)
818 (defvar gnus-newsgroup-auto-expire nil)
819 (defvar gnus-newsgroup-active nil)
820
821 (defvar gnus-newsgroup-data nil)
822 (defvar gnus-newsgroup-data-reverse nil)
823 (defvar gnus-newsgroup-limit nil)
824 (defvar gnus-newsgroup-limits nil)
825
826 (defvar gnus-newsgroup-unreads nil
827   "List of unread articles in the current newsgroup.")
828
829 (defvar gnus-newsgroup-unselected nil
830   "List of unselected unread articles in the current newsgroup.")
831
832 (defvar gnus-newsgroup-reads nil
833   "Alist of read articles and article marks in the current newsgroup.")
834
835 (defvar gnus-newsgroup-expunged-tally nil)
836
837 (defvar gnus-newsgroup-marked nil
838   "List of ticked articles in the current newsgroup (a subset of unread art).")
839
840 (defvar gnus-newsgroup-killed nil
841   "List of ranges of articles that have been through the scoring process.")
842
843 (defvar gnus-newsgroup-cached nil
844   "List of articles that come from the article cache.")
845
846 (defvar gnus-newsgroup-saved nil
847   "List of articles that have been saved.")
848
849 (defvar gnus-newsgroup-kill-headers nil)
850
851 (defvar gnus-newsgroup-replied nil
852   "List of articles that have been replied to in the current newsgroup.")
853
854 (defvar gnus-newsgroup-expirable nil
855   "List of articles in the current newsgroup that can be expired.")
856
857 (defvar gnus-newsgroup-processable nil
858   "List of articles in the current newsgroup that can be processed.")
859
860 (defvar gnus-newsgroup-bookmarks nil
861   "List of articles in the current newsgroup that have bookmarks.")
862
863 (defvar gnus-newsgroup-dormant nil
864   "List of dormant articles in the current newsgroup.")
865
866 (defvar gnus-newsgroup-scored nil
867   "List of scored articles in the current newsgroup.")
868
869 (defvar gnus-newsgroup-headers nil
870   "List of article headers in the current newsgroup.")
871
872 (defvar gnus-newsgroup-threads nil)
873
874 (defvar gnus-newsgroup-prepared nil
875   "Whether the current group has been prepared properly.")
876
877 (defvar gnus-newsgroup-ancient nil
878   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
879
880 (defvar gnus-newsgroup-sparse nil)
881
882 (defvar gnus-current-article nil)
883 (defvar gnus-article-current nil)
884 (defvar gnus-current-headers nil)
885 (defvar gnus-have-all-headers nil)
886 (defvar gnus-last-article nil)
887 (defvar gnus-newsgroup-history nil)
888
889 (defconst gnus-summary-local-variables
890   '(gnus-newsgroup-name
891     gnus-newsgroup-begin gnus-newsgroup-end
892     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
893     gnus-newsgroup-last-folder gnus-newsgroup-last-file
894     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
895     gnus-newsgroup-unselected gnus-newsgroup-marked
896     gnus-newsgroup-reads gnus-newsgroup-saved
897     gnus-newsgroup-replied gnus-newsgroup-expirable
898     gnus-newsgroup-processable gnus-newsgroup-killed
899     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
900     gnus-newsgroup-headers gnus-newsgroup-threads
901     gnus-newsgroup-prepared gnus-summary-highlight-line-function
902     gnus-current-article gnus-current-headers gnus-have-all-headers
903     gnus-last-article gnus-article-internal-prepare-hook
904     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
905     gnus-newsgroup-scored gnus-newsgroup-kill-headers
906     gnus-thread-expunge-below
907     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
908     (gnus-summary-mark-below . global)
909     gnus-newsgroup-active gnus-scores-exclude-files
910     gnus-newsgroup-history gnus-newsgroup-ancient
911     gnus-newsgroup-sparse gnus-newsgroup-process-stack
912     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
913     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
914     (gnus-newsgroup-expunged-tally . 0)
915     gnus-cache-removable-articles gnus-newsgroup-cached
916     gnus-newsgroup-data gnus-newsgroup-data-reverse
917     gnus-newsgroup-limit gnus-newsgroup-limits)
918   "Variables that are buffer-local to the summary buffers.")
919
920 ;; Byte-compiler warning.
921 (defvar gnus-article-mode-map)
922
923 ;; Subject simplification.
924
925 (defsubst gnus-simplify-subject-re (subject)
926   "Remove \"Re:\" from subject lines."
927   (if (string-match "^[Rr][Ee]: *" subject)
928       (substring subject (match-end 0))
929     subject))
930
931 (defun gnus-simplify-subject (subject &optional re-only)
932   "Remove `Re:' and words in parentheses.
933 If RE-ONLY is non-nil, strip leading `Re:'s only."
934   (let ((case-fold-search t))           ;Ignore case.
935     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
936     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
937       (setq subject (substring subject (match-end 0))))
938     ;; Remove uninteresting prefixes.
939     (when (and (not re-only)
940                gnus-simplify-ignored-prefixes
941                (string-match gnus-simplify-ignored-prefixes subject))
942       (setq subject (substring subject (match-end 0))))
943     ;; Remove words in parentheses from end.
944     (unless re-only
945       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
946         (setq subject (substring subject 0 (match-beginning 0)))))
947     ;; Return subject string.
948     subject))
949
950 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
951 ;; all whitespace.
952 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
953   (goto-char (point-min))
954   (while (re-search-forward regexp nil t)
955       (replace-match (or newtext ""))))
956
957 (defun gnus-simplify-buffer-fuzzy ()
958   "Simplify string in the buffer fuzzily.
959 The string in the accessible portion of the current buffer is simplified.
960 It is assumed to be a single-line subject.
961 Whitespace is generally cleaned up, and miscellaneous leading/trailing
962 matter is removed.  Additional things can be deleted by setting
963 gnus-simplify-subject-fuzzy-regexp."
964   (let ((case-fold-search t)
965         (modified-tick))
966     (gnus-simplify-buffer-fuzzy-step "\t" " ")
967
968     (while (not (eq modified-tick (buffer-modified-tick)))
969       (setq modified-tick (buffer-modified-tick))
970       (cond
971        ((listp gnus-simplify-subject-fuzzy-regexp)
972         (mapcar 'gnus-simplify-buffer-fuzzy-step
973                 gnus-simplify-subject-fuzzy-regexp))
974        (gnus-simplify-subject-fuzzy-regexp
975         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
976       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
977       (gnus-simplify-buffer-fuzzy-step
978        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
979       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
980
981     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
982     (gnus-simplify-buffer-fuzzy-step "  +" " ")
983     (gnus-simplify-buffer-fuzzy-step " $")
984     (gnus-simplify-buffer-fuzzy-step "^ +")))
985
986 (defun gnus-simplify-subject-fuzzy (subject)
987   "Simplify a subject string fuzzily.
988 See gnus-simplify-buffer-fuzzy for details."
989   (save-excursion
990     (gnus-set-work-buffer)
991     (let ((case-fold-search t))
992       (insert subject)
993       (inline (gnus-simplify-buffer-fuzzy))
994       (buffer-string))))
995
996 (defsubst gnus-simplify-subject-fully (subject)
997   "Simplify a subject string according to gnus-summary-gather-subject-limit."
998   (cond
999    ((null gnus-summary-gather-subject-limit)
1000     (gnus-simplify-subject-re subject))
1001    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1002     (gnus-simplify-subject-fuzzy subject))
1003    ((numberp gnus-summary-gather-subject-limit)
1004     (gnus-limit-string (gnus-simplify-subject-re subject)
1005                        gnus-summary-gather-subject-limit))
1006    (t
1007     subject)))
1008
1009 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1010   "Check whether two subjects are equal.  If optional argument
1011 simple-first is t, first argument is already simplified."
1012   (cond
1013    ((null simple-first)
1014     (equal (gnus-simplify-subject-fully s1)
1015            (gnus-simplify-subject-fully s2)))
1016    (t
1017     (equal s1
1018            (gnus-simplify-subject-fully s2)))))
1019
1020 (defun gnus-summary-bubble-group ()
1021   "Increase the score of the current group.
1022 This is a handy function to add to `gnus-summary-exit-hook' to
1023 increase the score of each group you read."
1024   (gnus-group-add-score gnus-newsgroup-name))
1025
1026 \f
1027 ;;;
1028 ;;; Gnus summary mode
1029 ;;;
1030
1031 (put 'gnus-summary-mode 'mode-class 'special)
1032
1033 (when t
1034   ;; Non-orthogonal keys
1035
1036   (gnus-define-keys gnus-summary-mode-map
1037     " " gnus-summary-next-page
1038     "\177" gnus-summary-prev-page
1039     [delete] gnus-summary-prev-page
1040     "\r" gnus-summary-scroll-up
1041     "n" gnus-summary-next-unread-article
1042     "p" gnus-summary-prev-unread-article
1043     "N" gnus-summary-next-article
1044     "P" gnus-summary-prev-article
1045     "\M-\C-n" gnus-summary-next-same-subject
1046     "\M-\C-p" gnus-summary-prev-same-subject
1047     "\M-n" gnus-summary-next-unread-subject
1048     "\M-p" gnus-summary-prev-unread-subject
1049     "." gnus-summary-first-unread-article
1050     "," gnus-summary-best-unread-article
1051     "\M-s" gnus-summary-search-article-forward
1052     "\M-r" gnus-summary-search-article-backward
1053     "<" gnus-summary-beginning-of-article
1054     ">" gnus-summary-end-of-article
1055     "j" gnus-summary-goto-article
1056     "^" gnus-summary-refer-parent-article
1057     "\M-^" gnus-summary-refer-article
1058     "u" gnus-summary-tick-article-forward
1059     "!" gnus-summary-tick-article-forward
1060     "U" gnus-summary-tick-article-backward
1061     "d" gnus-summary-mark-as-read-forward
1062     "D" gnus-summary-mark-as-read-backward
1063     "E" gnus-summary-mark-as-expirable
1064     "\M-u" gnus-summary-clear-mark-forward
1065     "\M-U" gnus-summary-clear-mark-backward
1066     "k" gnus-summary-kill-same-subject-and-select
1067     "\C-k" gnus-summary-kill-same-subject
1068     "\M-\C-k" gnus-summary-kill-thread
1069     "\M-\C-l" gnus-summary-lower-thread
1070     "e" gnus-summary-edit-article
1071     "#" gnus-summary-mark-as-processable
1072     "\M-#" gnus-summary-unmark-as-processable
1073     "\M-\C-t" gnus-summary-toggle-threads
1074     "\M-\C-s" gnus-summary-show-thread
1075     "\M-\C-h" gnus-summary-hide-thread
1076     "\M-\C-f" gnus-summary-next-thread
1077     "\M-\C-b" gnus-summary-prev-thread
1078     "\M-\C-u" gnus-summary-up-thread
1079     "\M-\C-d" gnus-summary-down-thread
1080     "&" gnus-summary-execute-command
1081     "c" gnus-summary-catchup-and-exit
1082     "\C-w" gnus-summary-mark-region-as-read
1083     "\C-t" gnus-summary-toggle-truncation
1084     "?" gnus-summary-mark-as-dormant
1085     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1086     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1087     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1088     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1089     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1090     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1091     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1092     "=" gnus-summary-expand-window
1093     "\C-x\C-s" gnus-summary-reselect-current-group
1094     "\M-g" gnus-summary-rescan-group
1095     "w" gnus-summary-stop-page-breaking
1096     "\C-c\C-r" gnus-summary-caesar-message
1097     "\M-t" gnus-summary-toggle-mime
1098     "f" gnus-summary-followup
1099     "F" gnus-summary-followup-with-original
1100     "C" gnus-summary-cancel-article
1101     "r" gnus-summary-reply
1102     "R" gnus-summary-reply-with-original
1103     "\C-c\C-f" gnus-summary-mail-forward
1104     "o" gnus-summary-save-article
1105     "\C-o" gnus-summary-save-article-mail
1106     "|" gnus-summary-pipe-output
1107     "\M-k" gnus-summary-edit-local-kill
1108     "\M-K" gnus-summary-edit-global-kill
1109     ;; "V" gnus-version
1110     "\C-c\C-d" gnus-summary-describe-group
1111     "q" gnus-summary-exit
1112     "Q" gnus-summary-exit-no-update
1113     "\C-c\C-i" gnus-info-find-node
1114     gnus-mouse-2 gnus-mouse-pick-article
1115     "m" gnus-summary-mail-other-window
1116     "a" gnus-summary-post-news
1117     "x" gnus-summary-limit-to-unread
1118     "s" gnus-summary-isearch-article
1119     "t" gnus-article-hide-headers
1120     "g" gnus-summary-show-article
1121     "l" gnus-summary-goto-last-article
1122     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1123     "\C-d" gnus-summary-enter-digest-group
1124     "\M-\C-d" gnus-summary-read-document
1125     "\C-c\C-b" gnus-bug
1126     "*" gnus-cache-enter-article
1127     "\M-*" gnus-cache-remove-article
1128     "\M-&" gnus-summary-universal-argument
1129     "\C-l" gnus-recenter
1130     "I" gnus-summary-increase-score
1131     "L" gnus-summary-lower-score
1132
1133     "V" gnus-summary-score-map
1134     "X" gnus-uu-extract-map
1135     "S" gnus-summary-send-map)
1136
1137   ;; Sort of orthogonal keymap
1138   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1139     "t" gnus-summary-tick-article-forward
1140     "!" gnus-summary-tick-article-forward
1141     "d" gnus-summary-mark-as-read-forward
1142     "r" gnus-summary-mark-as-read-forward
1143     "c" gnus-summary-clear-mark-forward
1144     " " gnus-summary-clear-mark-forward
1145     "e" gnus-summary-mark-as-expirable
1146     "x" gnus-summary-mark-as-expirable
1147     "?" gnus-summary-mark-as-dormant
1148     "b" gnus-summary-set-bookmark
1149     "B" gnus-summary-remove-bookmark
1150     "#" gnus-summary-mark-as-processable
1151     "\M-#" gnus-summary-unmark-as-processable
1152     "S" gnus-summary-limit-include-expunged
1153     "C" gnus-summary-catchup
1154     "H" gnus-summary-catchup-to-here
1155     "\C-c" gnus-summary-catchup-all
1156     "k" gnus-summary-kill-same-subject-and-select
1157     "K" gnus-summary-kill-same-subject
1158     "P" gnus-uu-mark-map)
1159
1160   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1161     "c" gnus-summary-clear-above
1162     "u" gnus-summary-tick-above
1163     "m" gnus-summary-mark-above
1164     "k" gnus-summary-kill-below)
1165
1166   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1167     "/" gnus-summary-limit-to-subject
1168     "n" gnus-summary-limit-to-articles
1169     "w" gnus-summary-pop-limit
1170     "s" gnus-summary-limit-to-subject
1171     "a" gnus-summary-limit-to-author
1172     "u" gnus-summary-limit-to-unread
1173     "m" gnus-summary-limit-to-marks
1174     "v" gnus-summary-limit-to-score
1175     "D" gnus-summary-limit-include-dormant
1176     "d" gnus-summary-limit-exclude-dormant
1177     "t" gnus-summary-limit-to-age
1178     "E" gnus-summary-limit-include-expunged
1179     "c" gnus-summary-limit-exclude-childless-dormant
1180     "C" gnus-summary-limit-mark-excluded-as-read)
1181
1182   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1183     "n" gnus-summary-next-unread-article
1184     "p" gnus-summary-prev-unread-article
1185     "N" gnus-summary-next-article
1186     "P" gnus-summary-prev-article
1187     "\C-n" gnus-summary-next-same-subject
1188     "\C-p" gnus-summary-prev-same-subject
1189     "\M-n" gnus-summary-next-unread-subject
1190     "\M-p" gnus-summary-prev-unread-subject
1191     "f" gnus-summary-first-unread-article
1192     "b" gnus-summary-best-unread-article
1193     "j" gnus-summary-goto-article
1194     "g" gnus-summary-goto-subject
1195     "l" gnus-summary-goto-last-article
1196     "p" gnus-summary-pop-article)
1197
1198   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1199     "k" gnus-summary-kill-thread
1200     "l" gnus-summary-lower-thread
1201     "i" gnus-summary-raise-thread
1202     "T" gnus-summary-toggle-threads
1203     "t" gnus-summary-rethread-current
1204     "^" gnus-summary-reparent-thread
1205     "s" gnus-summary-show-thread
1206     "S" gnus-summary-show-all-threads
1207     "h" gnus-summary-hide-thread
1208     "H" gnus-summary-hide-all-threads
1209     "n" gnus-summary-next-thread
1210     "p" gnus-summary-prev-thread
1211     "u" gnus-summary-up-thread
1212     "o" gnus-summary-top-thread
1213     "d" gnus-summary-down-thread
1214     "#" gnus-uu-mark-thread
1215     "\M-#" gnus-uu-unmark-thread)
1216
1217   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1218     "g" gnus-summary-prepare
1219     "c" gnus-summary-insert-cached-articles)
1220
1221   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1222     "c" gnus-summary-catchup-and-exit
1223     "C" gnus-summary-catchup-all-and-exit
1224     "E" gnus-summary-exit-no-update
1225     "Q" gnus-summary-exit
1226     "Z" gnus-summary-exit
1227     "n" gnus-summary-catchup-and-goto-next-group
1228     "R" gnus-summary-reselect-current-group
1229     "G" gnus-summary-rescan-group
1230     "N" gnus-summary-next-group
1231     "s" gnus-summary-save-newsrc
1232     "P" gnus-summary-prev-group)
1233
1234   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1235     " " gnus-summary-next-page
1236     "n" gnus-summary-next-page
1237     "\177" gnus-summary-prev-page
1238     [delete] gnus-summary-prev-page
1239     "p" gnus-summary-prev-page
1240     "\r" gnus-summary-scroll-up
1241     "<" gnus-summary-beginning-of-article
1242     ">" gnus-summary-end-of-article
1243     "b" gnus-summary-beginning-of-article
1244     "e" gnus-summary-end-of-article
1245     "^" gnus-summary-refer-parent-article
1246     "r" gnus-summary-refer-parent-article
1247     "R" gnus-summary-refer-references
1248     "g" gnus-summary-show-article
1249     "s" gnus-summary-isearch-article
1250     "P" gnus-summary-print-article)
1251
1252   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1253     "b" gnus-article-add-buttons
1254     "B" gnus-article-add-buttons-to-head
1255     "o" gnus-article-treat-overstrike
1256     "e" gnus-article-emphasize
1257     "w" gnus-article-fill-cited-article
1258     "c" gnus-article-remove-cr
1259     "q" gnus-article-de-quoted-unreadable
1260     "f" gnus-article-display-x-face
1261     "l" gnus-summary-stop-page-breaking
1262     "r" gnus-summary-caesar-message
1263     "t" gnus-article-hide-headers
1264     "v" gnus-summary-verbose-headers
1265     "m" gnus-summary-toggle-mime
1266     "h" gnus-article-treat-html)
1267
1268   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1269     "a" gnus-article-hide
1270     "h" gnus-article-hide-headers
1271     "b" gnus-article-hide-boring-headers
1272     "s" gnus-article-hide-signature
1273     "c" gnus-article-hide-citation
1274     "p" gnus-article-hide-pgp
1275     "P" gnus-article-hide-pem
1276     "\C-c" gnus-article-hide-citation-maybe)
1277
1278   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1279     "a" gnus-article-highlight
1280     "h" gnus-article-highlight-headers
1281     "c" gnus-article-highlight-citation
1282     "s" gnus-article-highlight-signature)
1283
1284   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1285     "z" gnus-article-date-ut
1286     "u" gnus-article-date-ut
1287     "l" gnus-article-date-local
1288     "e" gnus-article-date-lapsed
1289     "o" gnus-article-date-original
1290     "s" gnus-article-date-user)
1291
1292   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1293     "t" gnus-article-remove-trailing-blank-lines
1294     "l" gnus-article-strip-leading-blank-lines
1295     "m" gnus-article-strip-multiple-blank-lines
1296     "a" gnus-article-strip-blank-lines
1297     "s" gnus-article-strip-leading-space)
1298
1299   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1300     "v" gnus-version
1301     "f" gnus-summary-fetch-faq
1302     "d" gnus-summary-describe-group
1303     "h" gnus-summary-describe-briefly
1304     "i" gnus-info-find-node)
1305
1306   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1307     "e" gnus-summary-expire-articles
1308     "\M-\C-e" gnus-summary-expire-articles-now
1309     "\177" gnus-summary-delete-article
1310     [delete] gnus-summary-delete-article
1311     "m" gnus-summary-move-article
1312     "r" gnus-summary-respool-article
1313     "w" gnus-summary-edit-article
1314     "c" gnus-summary-copy-article
1315     "B" gnus-summary-crosspost-article
1316     "q" gnus-summary-respool-query
1317     "i" gnus-summary-import-article
1318     "p" gnus-summary-article-posted-p)
1319
1320   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1321     "o" gnus-summary-save-article
1322     "m" gnus-summary-save-article-mail
1323     "F" gnus-summary-write-article-file
1324     "r" gnus-summary-save-article-rmail
1325     "f" gnus-summary-save-article-file
1326     "b" gnus-summary-save-article-body-file
1327     "h" gnus-summary-save-article-folder
1328     "v" gnus-summary-save-article-vm
1329     "p" gnus-summary-pipe-output
1330     "s" gnus-soup-add-article))
1331
1332 (defun gnus-summary-make-menu-bar ()
1333   (gnus-turn-off-edit-menu 'summary)
1334
1335   (unless (boundp 'gnus-summary-misc-menu)
1336
1337     (easy-menu-define
1338      gnus-summary-kill-menu gnus-summary-mode-map ""
1339      (cons
1340       "Score"
1341       (nconc
1342        (list
1343         ["Enter score..." gnus-summary-score-entry t]
1344         ["Customize" gnus-score-customize t])
1345        (gnus-make-score-map 'increase)
1346        (gnus-make-score-map 'lower)
1347        '(("Mark"
1348           ["Kill below" gnus-summary-kill-below t]
1349           ["Mark above" gnus-summary-mark-above t]
1350           ["Tick above" gnus-summary-tick-above t]
1351           ["Clear above" gnus-summary-clear-above t])
1352          ["Current score" gnus-summary-current-score t]
1353          ["Set score" gnus-summary-set-score t]
1354          ["Switch current score file..." gnus-score-change-score-file t]
1355          ["Set mark below..." gnus-score-set-mark-below t]
1356          ["Set expunge below..." gnus-score-set-expunge-below t]
1357          ["Edit current score file" gnus-score-edit-current-scores t]
1358          ["Edit score file" gnus-score-edit-file t]
1359          ["Trace score" gnus-score-find-trace t]
1360          ["Find words" gnus-score-find-favourite-words t]
1361          ["Rescore buffer" gnus-summary-rescore t]
1362          ["Increase score..." gnus-summary-increase-score t]
1363          ["Lower score..." gnus-summary-lower-score t]))))
1364
1365     '(("Default header"
1366        ["Ask" (gnus-score-set-default 'gnus-score-default-header nil)
1367         :style radio
1368         :selected (null gnus-score-default-header)]
1369        ["From" (gnus-score-set-default 'gnus-score-default-header 'a)
1370         :style radio
1371         :selected (eq gnus-score-default-header 'a)]
1372        ["Subject" (gnus-score-set-default 'gnus-score-default-header 's)
1373         :style radio
1374         :selected (eq gnus-score-default-header 's)]
1375        ["Article body"
1376         (gnus-score-set-default 'gnus-score-default-header 'b)
1377         :style radio
1378         :selected (eq gnus-score-default-header 'b )]
1379        ["All headers"
1380         (gnus-score-set-default 'gnus-score-default-header 'h)
1381         :style radio
1382         :selected (eq gnus-score-default-header 'h )]
1383        ["Message-ID" (gnus-score-set-default 'gnus-score-default-header 'i)
1384         :style radio
1385         :selected (eq gnus-score-default-header 'i )]
1386        ["Thread" (gnus-score-set-default 'gnus-score-default-header 't)
1387         :style radio
1388         :selected (eq gnus-score-default-header 't )]
1389        ["Crossposting"
1390         (gnus-score-set-default 'gnus-score-default-header 'x)
1391         :style radio
1392         :selected (eq gnus-score-default-header 'x )]
1393        ["Lines" (gnus-score-set-default 'gnus-score-default-header 'l)
1394         :style radio
1395         :selected (eq gnus-score-default-header 'l )]
1396        ["Date" (gnus-score-set-default 'gnus-score-default-header 'd)
1397         :style radio
1398         :selected (eq gnus-score-default-header 'd )]
1399        ["Followups to author"
1400         (gnus-score-set-default 'gnus-score-default-header 'f)
1401         :style radio
1402         :selected (eq gnus-score-default-header 'f )])
1403       ("Default type"
1404        ["Ask" (gnus-score-set-default 'gnus-score-default-type nil)
1405         :style radio
1406         :selected (null gnus-score-default-type)]
1407        ;; The `:active' key is commented out in the following,
1408        ;; because the GNU Emacs hack to support radio buttons use
1409        ;; active to indicate which button is selected.
1410        ["Substring" (gnus-score-set-default 'gnus-score-default-type 's)
1411         :style radio
1412         ;; :active (not (memq gnus-score-default-header '(l d)))
1413         :selected (eq gnus-score-default-type 's)]
1414        ["Regexp" (gnus-score-set-default 'gnus-score-default-type 'r)
1415         :style radio
1416         ;; :active (not (memq gnus-score-default-header '(l d)))
1417         :selected (eq gnus-score-default-type 'r)]
1418        ["Exact" (gnus-score-set-default 'gnus-score-default-type 'e)
1419         :style radio
1420         ;; :active (not (memq gnus-score-default-header '(l d)))
1421         :selected (eq gnus-score-default-type 'e)]
1422        ["Fuzzy" (gnus-score-set-default 'gnus-score-default-type 'f)
1423         :style radio
1424         ;; :active (not (memq gnus-score-default-header '(l d)))
1425         :selected (eq gnus-score-default-type 'f)]
1426        ["Before date" (gnus-score-set-default 'gnus-score-default-type 'b)
1427         :style radio
1428         ;; :active (eq (gnus-score-default-header 'd))
1429         :selected (eq gnus-score-default-type 'b)]
1430        ["At date" (gnus-score-set-default 'gnus-score-default-type 'n)
1431         :style radio
1432         ;; :active (eq (gnus-score-default-header 'd))
1433         :selected (eq gnus-score-default-type 'n)]
1434        ["After date" (gnus-score-set-default 'gnus-score-default-type 'a)
1435         :style radio
1436         ;; :active (eq (gnus-score-default-header 'd))
1437         :selected (eq gnus-score-default-type 'a)]
1438        ["Less than number"
1439         (gnus-score-set-default 'gnus-score-default-type '<)
1440         :style radio
1441         ;; :active (eq (gnus-score-default-header 'l))
1442         :selected (eq gnus-score-default-type '<)]
1443        ["Equal to number"
1444         (gnus-score-set-default 'gnus-score-default-type '=)
1445         :style radio
1446         ;; :active (eq (gnus-score-default-header 'l))
1447         :selected (eq gnus-score-default-type '=)]
1448        ["Greater than number"
1449         (gnus-score-set-default 'gnus-score-default-type '>)
1450         :style radio
1451         ;; :active (eq (gnus-score-default-header 'l))
1452         :selected (eq gnus-score-default-type '>)])
1453       ["Default fold" gnus-score-default-fold-toggle
1454        :style toggle
1455        :selected gnus-score-default-fold]
1456       ("Default duration"
1457        ["Ask" (gnus-score-set-default 'gnus-score-default-duration nil)
1458         :style radio
1459         :selected (null gnus-score-default-duration)]
1460        ["Permanent"
1461         (gnus-score-set-default 'gnus-score-default-duration 'p)
1462         :style radio
1463         :selected (eq gnus-score-default-duration 'p)]
1464        ["Temporary"
1465         (gnus-score-set-default 'gnus-score-default-duration 't)
1466         :style radio
1467         :selected (eq gnus-score-default-duration 't)]
1468        ["Immediate"
1469         (gnus-score-set-default 'gnus-score-default-duration 'i)
1470         :style radio
1471         :selected (eq gnus-score-default-duration 'i)]))
1472
1473     (easy-menu-define
1474      gnus-summary-article-menu gnus-summary-mode-map ""
1475      '("Article"
1476        ("Hide"
1477         ["All" gnus-article-hide t]
1478         ["Headers" gnus-article-hide-headers t]
1479         ["Signature" gnus-article-hide-signature t]
1480         ["Citation" gnus-article-hide-citation t]
1481         ["PGP" gnus-article-hide-pgp t]
1482         ["Boring headers" gnus-article-hide-boring-headers t])
1483        ("Highlight"
1484         ["All" gnus-article-highlight t]
1485         ["Headers" gnus-article-highlight-headers t]
1486         ["Signature" gnus-article-highlight-signature t]
1487         ["Citation" gnus-article-highlight-citation t])
1488        ("Date"
1489         ["Local" gnus-article-date-local t]
1490         ["UT" gnus-article-date-ut t]
1491         ["Original" gnus-article-date-original t]
1492         ["Lapsed" gnus-article-date-lapsed t]
1493         ["User-defined" gnus-article-date-user t])
1494        ("Washing"
1495         ("Remove Blanks"
1496          ["Leading" gnus-article-strip-leading-blank-lines t]
1497          ["Multiple" gnus-article-strip-multiple-blank-lines t]
1498          ["Trailing" gnus-article-remove-trailing-blank-lines t]
1499          ["All of the above" gnus-article-strip-blank-lines t]
1500          ["Leading space" gnus-article-strip-leading-space t])
1501         ["Overstrike" gnus-article-treat-overstrike t]
1502         ["Emphasis" gnus-article-emphasize t]
1503         ["Word wrap" gnus-article-fill-cited-article t]
1504         ["CR" gnus-article-remove-cr t]
1505         ["Show X-Face" gnus-article-display-x-face t]
1506         ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1507         ["UnHTMLize" gnus-article-treat-html t]
1508         ["Rot 13" gnus-summary-caesar-message t]
1509         ["Unix pipe" gnus-summary-pipe-message t]
1510         ["Add buttons" gnus-article-add-buttons t]
1511         ["Add buttons to head" gnus-article-add-buttons-to-head t]
1512         ["Stop page breaking" gnus-summary-stop-page-breaking t]
1513         ["Toggle MIME" gnus-summary-toggle-mime t]
1514         ["Verbose header" gnus-summary-verbose-headers t]
1515         ["Toggle header" gnus-summary-toggle-header t])
1516        ("Output"
1517         ["Save in default format" gnus-summary-save-article t]
1518         ["Save in file" gnus-summary-save-article-file t]
1519         ["Save in Unix mail format" gnus-summary-save-article-mail t]
1520         ["Write to file" gnus-summary-write-article-mail t]
1521         ["Save in MH folder" gnus-summary-save-article-folder t]
1522         ["Save in VM folder" gnus-summary-save-article-vm t]
1523         ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1524         ["Save body in file" gnus-summary-save-article-body-file t]
1525         ["Pipe through a filter" gnus-summary-pipe-output t]
1526         ["Add to SOUP packet" gnus-soup-add-article t]
1527         ["Print" gnus-summary-print-article t])
1528        ("Backend"
1529         ["Respool article..." gnus-summary-respool-article t]
1530         ["Move article..." gnus-summary-move-article
1531          (gnus-check-backend-function
1532           'request-move-article gnus-newsgroup-name)]
1533         ["Copy article..." gnus-summary-copy-article t]
1534         ["Crosspost article..." gnus-summary-crosspost-article
1535          (gnus-check-backend-function
1536           'request-replace-article gnus-newsgroup-name)]
1537         ["Import file..." gnus-summary-import-article t]
1538         ["Check if posted" gnus-summary-article-posted-p t]
1539         ["Edit article" gnus-summary-edit-article
1540          (not (gnus-group-read-only-p))]
1541         ["Delete article" gnus-summary-delete-article
1542          (gnus-check-backend-function
1543           'request-expire-articles gnus-newsgroup-name)]
1544         ["Query respool" gnus-summary-respool-query t]
1545         ["Delete expirable articles" gnus-summary-expire-articles-now
1546          (gnus-check-backend-function
1547           'request-expire-articles gnus-newsgroup-name)])
1548        ("Extract"
1549         ["Uudecode" gnus-uu-decode-uu t]
1550         ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1551         ["Unshar" gnus-uu-decode-unshar t]
1552         ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1553         ["Save" gnus-uu-decode-save t]
1554         ["Binhex" gnus-uu-decode-binhex t]
1555         ["Postscript" gnus-uu-decode-postscript t])
1556        ("Cache"
1557         ["Enter article" gnus-cache-enter-article t]
1558         ["Remove article" gnus-cache-remove-article t])
1559        ["Enter digest buffer" gnus-summary-enter-digest-group t]
1560        ["Isearch article..." gnus-summary-isearch-article t]
1561        ["Beginning of the article" gnus-summary-beginning-of-article t]
1562        ["End of the article" gnus-summary-end-of-article t]
1563        ["Fetch parent of article" gnus-summary-refer-parent-article t]
1564        ["Fetch referenced articles" gnus-summary-refer-references t]
1565        ["Fetch article with id..." gnus-summary-refer-article t]
1566        ["Redisplay" gnus-summary-show-article t]))
1567
1568     (easy-menu-define
1569      gnus-summary-thread-menu gnus-summary-mode-map ""
1570      '("Threads"
1571        ["Toggle threading" gnus-summary-toggle-threads t]
1572        ["Hide threads" gnus-summary-hide-all-threads t]
1573        ["Show threads" gnus-summary-show-all-threads t]
1574        ["Hide thread" gnus-summary-hide-thread t]
1575        ["Show thread" gnus-summary-show-thread t]
1576        ["Go to next thread" gnus-summary-next-thread t]
1577        ["Go to previous thread" gnus-summary-prev-thread t]
1578        ["Go down thread" gnus-summary-down-thread t]
1579        ["Go up thread" gnus-summary-up-thread t]
1580        ["Top of thread" gnus-summary-top-thread t]
1581        ["Mark thread as read" gnus-summary-kill-thread t]
1582        ["Lower thread score" gnus-summary-lower-thread t]
1583        ["Raise thread score" gnus-summary-raise-thread t]
1584        ["Rethread current" gnus-summary-rethread-current t]
1585        ))
1586
1587     (easy-menu-define
1588      gnus-summary-post-menu gnus-summary-mode-map ""
1589      '("Post"
1590        ["Post an article" gnus-summary-post-news t]
1591        ["Followup" gnus-summary-followup t]
1592        ["Followup and yank" gnus-summary-followup-with-original t]
1593        ["Supersede article" gnus-summary-supersede-article t]
1594        ["Cancel article" gnus-summary-cancel-article t]
1595        ["Reply" gnus-summary-reply t]
1596        ["Reply and yank" gnus-summary-reply-with-original t]
1597        ["Wide reply" gnus-summary-wide-reply t]
1598        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
1599        ["Mail forward" gnus-summary-mail-forward t]
1600        ["Post forward" gnus-summary-post-forward t]
1601        ["Digest and mail" gnus-uu-digest-mail-forward t]
1602        ["Digest and post" gnus-uu-digest-post-forward t]
1603        ["Resend message" gnus-summary-resend-message t]
1604        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1605        ["Send a mail" gnus-summary-mail-other-window t]
1606        ["Uuencode and post" gnus-uu-post-news t]
1607        ["Followup via news" gnus-summary-followup-to-mail t]
1608        ["Followup via news and yank"
1609         gnus-summary-followup-to-mail-with-original t]
1610        ;;("Draft"
1611        ;;["Send" gnus-summary-send-draft t]
1612        ;;["Send bounced" gnus-resend-bounced-mail t])
1613        ))
1614
1615     (easy-menu-define
1616      gnus-summary-misc-menu gnus-summary-mode-map ""
1617      '("Misc"
1618        ("Mark Read"
1619         ["Mark as read" gnus-summary-mark-as-read-forward t]
1620         ["Mark same subject and select"
1621          gnus-summary-kill-same-subject-and-select t]
1622         ["Mark same subject" gnus-summary-kill-same-subject t]
1623         ["Catchup" gnus-summary-catchup t]
1624         ["Catchup all" gnus-summary-catchup-all t]
1625         ["Catchup to here" gnus-summary-catchup-to-here t]
1626         ["Catchup region" gnus-summary-mark-region-as-read t]
1627         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1628        ("Mark Various"
1629         ["Tick" gnus-summary-tick-article-forward t]
1630         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1631         ["Remove marks" gnus-summary-clear-mark-forward t]
1632         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1633         ["Set bookmark" gnus-summary-set-bookmark t]
1634         ["Remove bookmark" gnus-summary-remove-bookmark t])
1635        ("Mark Limit"
1636         ["Marks..." gnus-summary-limit-to-marks t]
1637         ["Subject..." gnus-summary-limit-to-subject t]
1638         ["Author..." gnus-summary-limit-to-author t]
1639         ["Age..." gnus-summary-limit-to-age t]
1640         ["Score" gnus-summary-limit-to-score t]
1641         ["Unread" gnus-summary-limit-to-unread t]
1642         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1643         ["Articles" gnus-summary-limit-to-articles t]
1644         ["Pop limit" gnus-summary-pop-limit t]
1645         ["Show dormant" gnus-summary-limit-include-dormant t]
1646         ["Hide childless dormant"
1647          gnus-summary-limit-exclude-childless-dormant t]
1648         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1649         ["Show expunged" gnus-summary-show-all-expunged t])
1650        ("Process Mark"
1651         ["Set mark" gnus-summary-mark-as-processable t]
1652         ["Remove mark" gnus-summary-unmark-as-processable t]
1653         ["Remove all marks" gnus-summary-unmark-all-processable t]
1654         ["Mark above" gnus-uu-mark-over t]
1655         ["Mark series" gnus-uu-mark-series t]
1656         ["Mark region" gnus-uu-mark-region t]
1657         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1658         ["Mark all" gnus-uu-mark-all t]
1659         ["Mark buffer" gnus-uu-mark-buffer t]
1660         ["Mark sparse" gnus-uu-mark-sparse t]
1661         ["Mark thread" gnus-uu-mark-thread t]
1662         ["Unmark thread" gnus-uu-unmark-thread t]
1663         ("Process Mark Sets"
1664          ["Kill" gnus-summary-kill-process-mark t]
1665          ["Yank" gnus-summary-yank-process-mark
1666           gnus-newsgroup-process-stack]
1667          ["Save" gnus-summary-save-process-mark t]))
1668        ("Scroll article"
1669         ["Page forward" gnus-summary-next-page t]
1670         ["Page backward" gnus-summary-prev-page t]
1671         ["Line forward" gnus-summary-scroll-up t])
1672        ("Move"
1673         ["Next unread article" gnus-summary-next-unread-article t]
1674         ["Previous unread article" gnus-summary-prev-unread-article t]
1675         ["Next article" gnus-summary-next-article t]
1676         ["Previous article" gnus-summary-prev-article t]
1677         ["Next unread subject" gnus-summary-next-unread-subject t]
1678         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1679         ["Next article same subject" gnus-summary-next-same-subject t]
1680         ["Previous article same subject" gnus-summary-prev-same-subject t]
1681         ["First unread article" gnus-summary-first-unread-article t]
1682         ["Best unread article" gnus-summary-best-unread-article t]
1683         ["Go to subject number..." gnus-summary-goto-subject t]
1684         ["Go to article number..." gnus-summary-goto-article t]
1685         ["Go to the last article" gnus-summary-goto-last-article t]
1686         ["Pop article off history" gnus-summary-pop-article t])
1687        ("Sort"
1688         ["Sort by number" gnus-summary-sort-by-number t]
1689         ["Sort by author" gnus-summary-sort-by-author t]
1690         ["Sort by subject" gnus-summary-sort-by-subject t]
1691         ["Sort by date" gnus-summary-sort-by-date t]
1692         ["Sort by score" gnus-summary-sort-by-score t]
1693         ["Sort by lines" gnus-summary-sort-by-lines t])
1694        ("Help"
1695         ["Fetch group FAQ" gnus-summary-fetch-faq t]
1696         ["Describe group" gnus-summary-describe-group t]
1697         ["Read manual" gnus-info-find-node t])
1698        ("Modes"
1699         ["Pick and read" gnus-pick-mode t]
1700         ["Binary" gnus-binary-mode t])
1701        ("Regeneration"
1702         ["Regenerate" gnus-summary-prepare t]
1703         ["Insert cached articles" gnus-summary-insert-cached-articles t]
1704         ["Toggle threading" gnus-summary-toggle-threads t])
1705        ["Filter articles..." gnus-summary-execute-command t]
1706        ["Run command on subjects..." gnus-summary-universal-argument t]
1707        ["Search articles forward..." gnus-summary-search-article-forward t]
1708        ["Search articles backward..." gnus-summary-search-article-backward t]
1709        ["Toggle line truncation" gnus-summary-toggle-truncation t]
1710        ["Expand window" gnus-summary-expand-window t]
1711        ["Expire expirable articles" gnus-summary-expire-articles
1712         (gnus-check-backend-function
1713          'request-expire-articles gnus-newsgroup-name)]
1714        ["Edit local kill file" gnus-summary-edit-local-kill t]
1715        ["Edit main kill file" gnus-summary-edit-global-kill t]
1716        ("Exit"
1717         ["Catchup and exit" gnus-summary-catchup-and-exit t]
1718         ["Catchup all and exit" gnus-summary-catchup-and-exit t]
1719         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
1720         ["Exit group" gnus-summary-exit t]
1721         ["Exit group without updating" gnus-summary-exit-no-update t]
1722         ["Exit and goto next group" gnus-summary-next-group t]
1723         ["Exit and goto prev group" gnus-summary-prev-group t]
1724         ["Reselect group" gnus-summary-reselect-current-group t]
1725         ["Rescan group" gnus-summary-rescan-group t]
1726         ["Update dribble" gnus-summary-save-newsrc t])))
1727
1728     (run-hooks 'gnus-summary-menu-hook)))
1729
1730 (defun gnus-score-set-default (var value)
1731   "A version of set that updates the GNU Emacs menu-bar."
1732   (set var value)
1733   ;; It is the message that forces the active status to be updated.
1734   (message ""))
1735
1736 (defun gnus-make-score-map (type)
1737   "Make a summary score map of type TYPE."
1738   (if t
1739       nil
1740     (let ((headers '(("author" "from" string)
1741                      ("subject" "subject" string)
1742                      ("article body" "body" string)
1743                      ("article head" "head" string)
1744                      ("xref" "xref" string)
1745                      ("lines" "lines" number)
1746                      ("followups to author" "followup" string)))
1747           (types '((number ("less than" <)
1748                            ("greater than" >)
1749                            ("equal" =))
1750                    (string ("substring" s)
1751                            ("exact string" e)
1752                            ("fuzzy string" f)
1753                            ("regexp" r))))
1754           (perms '(("temporary" (current-time-string))
1755                    ("permanent" nil)
1756                    ("immediate" now)))
1757           header)
1758       (list
1759        (apply
1760         'nconc
1761         (list
1762          (if (eq type 'lower)
1763              "Lower score"
1764            "Increase score"))
1765         (let (outh)
1766           (while headers
1767             (setq header (car headers))
1768             (setq outh
1769                   (cons
1770                    (apply
1771                     'nconc
1772                     (list (car header))
1773                     (let ((ts (cdr (assoc (nth 2 header) types)))
1774                           outt)
1775                       (while ts
1776                         (setq outt
1777                               (cons
1778                                (apply
1779                                 'nconc
1780                                 (list (caar ts))
1781                                 (let ((ps perms)
1782                                       outp)
1783                                   (while ps
1784                                     (setq outp
1785                                           (cons
1786                                            (vector
1787                                             (caar ps)
1788                                             (list
1789                                              'gnus-summary-score-entry
1790                                              (nth 1 header)
1791                                              (if (or (string= (nth 1 header)
1792                                                               "head")
1793                                                      (string= (nth 1 header)
1794                                                               "body"))
1795                                                  ""
1796                                                (list 'gnus-summary-header
1797                                                      (nth 1 header)))
1798                                              (list 'quote (nth 1 (car ts)))
1799                                              (list 'gnus-score-default nil)
1800                                              (nth 1 (car ps))
1801                                              t)
1802                                             t)
1803                                            outp))
1804                                     (setq ps (cdr ps)))
1805                                   (list (nreverse outp))))
1806                                outt))
1807                         (setq ts (cdr ts)))
1808                       (list (nreverse outt))))
1809                    outh))
1810             (setq headers (cdr headers)))
1811           (list (nreverse outh))))))))
1812
1813 \f
1814
1815 (defun gnus-summary-mode (&optional group)
1816   "Major mode for reading articles.
1817
1818 All normal editing commands are switched off.
1819 \\<gnus-summary-mode-map>
1820 Each line in this buffer represents one article.  To read an
1821 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
1822 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
1823 respectively.
1824
1825 You can also post articles and send mail from this buffer.  To
1826 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
1827 of an article, type `\\[gnus-summary-reply]'.
1828
1829 There are approx. one gazillion commands you can execute in this
1830 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
1831
1832 The following commands are available:
1833
1834 \\{gnus-summary-mode-map}"
1835   (interactive)
1836   (when (gnus-visual-p 'summary-menu 'menu)
1837     (gnus-summary-make-menu-bar))
1838   (kill-all-local-variables)
1839   (gnus-summary-make-local-variables)
1840   (gnus-make-thread-indent-array)
1841   (gnus-simplify-mode-line)
1842   (setq major-mode 'gnus-summary-mode)
1843   (setq mode-name "Summary")
1844   (make-local-variable 'minor-mode-alist)
1845   (use-local-map gnus-summary-mode-map)
1846   (buffer-disable-undo (current-buffer))
1847   (setq buffer-read-only t)             ;Disable modification
1848   (setq truncate-lines t)
1849   (setq selective-display t)
1850   (setq selective-display-ellipses t)   ;Display `...'
1851   (gnus-summary-set-display-table)
1852   (gnus-set-default-directory)
1853   (setq gnus-newsgroup-name group)
1854   (make-local-variable 'gnus-summary-line-format)
1855   (make-local-variable 'gnus-summary-line-format-spec)
1856   (make-local-variable 'gnus-summary-mark-positions)
1857   (make-local-hook 'post-command-hook)
1858   (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
1859   (run-hooks 'gnus-summary-mode-hook)
1860   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
1861   (gnus-update-summary-mark-positions))
1862
1863 (defun gnus-summary-make-local-variables ()
1864   "Make all the local summary buffer variables."
1865   (let ((locals gnus-summary-local-variables)
1866         global local)
1867     (while (setq local (pop locals))
1868       (if (consp local)
1869           (progn
1870             (if (eq (cdr local) 'global)
1871                 ;; Copy the global value of the variable.
1872                 (setq global (symbol-value (car local)))
1873               ;; Use the value from the list.
1874               (setq global (eval (cdr local))))
1875             (make-local-variable (car local))
1876             (set (car local) global))
1877         ;; Simple nil-valued local variable.
1878         (make-local-variable local)
1879         (set local nil)))))
1880
1881 (defun gnus-summary-clear-local-variables ()
1882   (let ((locals gnus-summary-local-variables))
1883     (while locals
1884       (if (consp (car locals))
1885           (and (vectorp (caar locals))
1886                (set (caar locals) nil))
1887         (and (vectorp (car locals))
1888              (set (car locals) nil)))
1889       (setq locals (cdr locals)))))
1890
1891 ;; Summary data functions.
1892
1893 (defmacro gnus-data-number (data)
1894   `(car ,data))
1895
1896 (defmacro gnus-data-set-number (data number)
1897   `(setcar ,data ,number))
1898
1899 (defmacro gnus-data-mark (data)
1900   `(nth 1 ,data))
1901
1902 (defmacro gnus-data-set-mark (data mark)
1903   `(setcar (nthcdr 1 ,data) ,mark))
1904
1905 (defmacro gnus-data-pos (data)
1906   `(nth 2 ,data))
1907
1908 (defmacro gnus-data-set-pos (data pos)
1909   `(setcar (nthcdr 2 ,data) ,pos))
1910
1911 (defmacro gnus-data-header (data)
1912   `(nth 3 ,data))
1913
1914 (defmacro gnus-data-set-header (data header)
1915   `(setf (nth 3 ,data) ,header))
1916
1917 (defmacro gnus-data-level (data)
1918   `(nth 4 ,data))
1919
1920 (defmacro gnus-data-unread-p (data)
1921   `(= (nth 1 ,data) gnus-unread-mark))
1922
1923 (defmacro gnus-data-read-p (data)
1924   `(/= (nth 1 ,data) gnus-unread-mark))
1925
1926 (defmacro gnus-data-pseudo-p (data)
1927   `(consp (nth 3 ,data)))
1928
1929 (defmacro gnus-data-find (number)
1930   `(assq ,number gnus-newsgroup-data))
1931
1932 (defmacro gnus-data-find-list (number &optional data)
1933   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
1934      (memq (assq ,number bdata)
1935            bdata)))
1936
1937 (defmacro gnus-data-make (number mark pos header level)
1938   `(list ,number ,mark ,pos ,header ,level))
1939
1940 (defun gnus-data-enter (after-article number mark pos header level offset)
1941   (let ((data (gnus-data-find-list after-article)))
1942     (unless data
1943       (error "No such article: %d" after-article))
1944     (setcdr data (cons (gnus-data-make number mark pos header level)
1945                        (cdr data)))
1946     (setq gnus-newsgroup-data-reverse nil)
1947     (gnus-data-update-list (cddr data) offset)))
1948
1949 (defun gnus-data-enter-list (after-article list &optional offset)
1950   (when list
1951     (let ((data (and after-article (gnus-data-find-list after-article)))
1952           (ilist list))
1953       (or data (not after-article) (error "No such article: %d" after-article))
1954       ;; Find the last element in the list to be spliced into the main
1955       ;; list.
1956       (while (cdr list)
1957         (setq list (cdr list)))
1958       (if (not data)
1959           (progn
1960             (setcdr list gnus-newsgroup-data)
1961             (setq gnus-newsgroup-data ilist)
1962             (when offset
1963               (gnus-data-update-list (cdr list) offset)))
1964         (setcdr list (cdr data))
1965         (setcdr data ilist)
1966         (when offset
1967           (gnus-data-update-list (cdr list) offset)))
1968       (setq gnus-newsgroup-data-reverse nil))))
1969
1970 (defun gnus-data-remove (article &optional offset)
1971   (let ((data gnus-newsgroup-data))
1972     (if (= (gnus-data-number (car data)) article)
1973         (progn
1974           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
1975                 gnus-newsgroup-data-reverse nil)
1976           (when offset
1977             (gnus-data-update-list gnus-newsgroup-data offset)))
1978       (while (cdr data)
1979         (when (= (gnus-data-number (cadr data)) article)
1980           (setcdr data (cddr data))
1981           (when offset
1982             (gnus-data-update-list (cdr data) offset))
1983           (setq data nil
1984                 gnus-newsgroup-data-reverse nil))
1985         (setq data (cdr data))))))
1986
1987 (defmacro gnus-data-list (backward)
1988   `(if ,backward
1989        (or gnus-newsgroup-data-reverse
1990            (setq gnus-newsgroup-data-reverse
1991                  (reverse gnus-newsgroup-data)))
1992      gnus-newsgroup-data))
1993
1994 (defun gnus-data-update-list (data offset)
1995   "Add OFFSET to the POS of all data entries in DATA."
1996   (while data
1997     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
1998     (setq data (cdr data))))
1999
2000 (defun gnus-data-compute-positions ()
2001   "Compute the positions of all articles."
2002   (let ((data gnus-newsgroup-data)
2003         pos)
2004     (while data
2005       (when (setq pos (text-property-any
2006                        (point-min) (point-max)
2007                        'gnus-number (gnus-data-number (car data))))
2008         (gnus-data-set-pos (car data) (+ pos 3)))
2009       (setq data (cdr data)))))
2010
2011 (defun gnus-summary-article-pseudo-p (article)
2012   "Say whether this article is a pseudo article or not."
2013   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2014
2015 (defmacro gnus-summary-article-sparse-p (article)
2016   "Say whether this article is a sparse article or not."
2017   ` (memq ,article gnus-newsgroup-sparse))
2018
2019 (defmacro gnus-summary-article-ancient-p (article)
2020   "Say whether this article is a sparse article or not."
2021   `(memq ,article gnus-newsgroup-ancient))
2022
2023 (defun gnus-article-parent-p (number)
2024   "Say whether this article is a parent or not."
2025   (let ((data (gnus-data-find-list number)))
2026     (and (cdr data)                     ; There has to be an article after...
2027          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2028             (gnus-data-level (nth 1 data))))))
2029
2030 (defun gnus-article-children (number)
2031   "Return a list of all children to NUMBER."
2032   (let* ((data (gnus-data-find-list number))
2033          (level (gnus-data-level (car data)))
2034          children)
2035     (setq data (cdr data))
2036     (while (and data
2037                 (= (gnus-data-level (car data)) (1+ level)))
2038       (push (gnus-data-number (car data)) children)
2039       (setq data (cdr data)))
2040     children))
2041
2042 (defmacro gnus-summary-skip-intangible ()
2043   "If the current article is intangible, then jump to a different article."
2044   '(let ((to (get-text-property (point) 'gnus-intangible)))
2045      (and to (gnus-summary-goto-subject to))))
2046
2047 (defmacro gnus-summary-article-intangible-p ()
2048   "Say whether this article is intangible or not."
2049   '(get-text-property (point) 'gnus-intangible))
2050
2051 (defun gnus-article-read-p (article)
2052   "Say whether ARTICLE is read or not."
2053   (not (or (memq article gnus-newsgroup-marked)
2054            (memq article gnus-newsgroup-unreads)
2055            (memq article gnus-newsgroup-unselected)
2056            (memq article gnus-newsgroup-dormant))))
2057
2058 ;; Some summary mode macros.
2059
2060 (defmacro gnus-summary-article-number ()
2061   "The article number of the article on the current line.
2062 If there isn's an article number here, then we return the current
2063 article number."
2064   '(progn
2065      (gnus-summary-skip-intangible)
2066      (or (get-text-property (point) 'gnus-number)
2067          (gnus-summary-last-subject))))
2068
2069 (defmacro gnus-summary-article-header (&optional number)
2070   `(gnus-data-header (gnus-data-find
2071                       ,(or number '(gnus-summary-article-number)))))
2072
2073 (defmacro gnus-summary-thread-level (&optional number)
2074   `(if (and (eq gnus-summary-make-false-root 'dummy)
2075             (get-text-property (point) 'gnus-intangible))
2076        0
2077      (gnus-data-level (gnus-data-find
2078                        ,(or number '(gnus-summary-article-number))))))
2079
2080 (defmacro gnus-summary-article-mark (&optional number)
2081   `(gnus-data-mark (gnus-data-find
2082                     ,(or number '(gnus-summary-article-number)))))
2083
2084 (defmacro gnus-summary-article-pos (&optional number)
2085   `(gnus-data-pos (gnus-data-find
2086                    ,(or number '(gnus-summary-article-number)))))
2087
2088 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2089 (defmacro gnus-summary-article-subject (&optional number)
2090   "Return current subject string or nil if nothing."
2091   `(let ((headers
2092           ,(if number
2093                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2094              '(gnus-data-header (assq (gnus-summary-article-number)
2095                                       gnus-newsgroup-data)))))
2096      (and headers
2097           (vectorp headers)
2098           (mail-header-subject headers))))
2099
2100 (defmacro gnus-summary-article-score (&optional number)
2101   "Return current article score."
2102   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2103                   gnus-newsgroup-scored))
2104        gnus-summary-default-score 0))
2105
2106 (defun gnus-summary-article-children (&optional number)
2107   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2108          (level (gnus-data-level (car data)))
2109          l children)
2110     (while (and (setq data (cdr data))
2111                 (> (setq l (gnus-data-level (car data))) level))
2112       (and (= (1+ level) l)
2113            (push (gnus-data-number (car data))
2114                  children)))
2115     (nreverse children)))
2116
2117 (defun gnus-summary-article-parent (&optional number)
2118   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2119                                     (gnus-data-list t)))
2120          (level (gnus-data-level (car data))))
2121     (if (zerop level)
2122         ()                              ; This is a root.
2123       ;; We search until we find an article with a level less than
2124       ;; this one.  That function has to be the parent.
2125       (while (and (setq data (cdr data))
2126                   (not (< (gnus-data-level (car data)) level))))
2127       (and data (gnus-data-number (car data))))))
2128
2129 (defun gnus-unread-mark-p (mark)
2130   "Say whether MARK is the unread mark."
2131   (= mark gnus-unread-mark))
2132
2133 (defun gnus-read-mark-p (mark)
2134   "Say whether MARK is one of the marks that mark as read.
2135 This is all marks except unread, ticked, dormant, and expirable."
2136   (not (or (= mark gnus-unread-mark)
2137            (= mark gnus-ticked-mark)
2138            (= mark gnus-dormant-mark)
2139            (= mark gnus-expirable-mark))))
2140
2141 (defmacro gnus-article-mark (number)
2142   `(cond
2143     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2144     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2145     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2146     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2147     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2148            gnus-ancient-mark))))
2149
2150 ;; Saving hidden threads.
2151
2152 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2153 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2154
2155 (defmacro gnus-save-hidden-threads (&rest forms)
2156   "Save hidden threads, eval FORMS, and restore the hidden threads."
2157   (let ((config (make-symbol "config")))
2158     `(let ((,config (gnus-hidden-threads-configuration)))
2159        (unwind-protect
2160            (save-excursion
2161              ,@forms)
2162          (gnus-restore-hidden-threads-configuration ,config)))))
2163
2164 (defun gnus-hidden-threads-configuration ()
2165   "Return the current hidden threads configuration."
2166   (save-excursion
2167     (let (config)
2168       (goto-char (point-min))
2169       (while (search-forward "\r" nil t)
2170         (push (1- (point)) config))
2171       config)))
2172
2173 (defun gnus-restore-hidden-threads-configuration (config)
2174   "Restore hidden threads configuration from CONFIG."
2175   (let (point buffer-read-only)
2176     (while (setq point (pop config))
2177       (when (and (< point (point-max))
2178                  (goto-char point)
2179                  (= (following-char) ?\n))
2180         (subst-char-in-region point (1+ point) ?\n ?\r)))))
2181
2182 ;; Various summary mode internalish functions.
2183
2184 (defun gnus-mouse-pick-article (e)
2185   (interactive "e")
2186   (mouse-set-point e)
2187   (gnus-summary-next-page nil t))
2188
2189 (defun gnus-summary-set-display-table ()
2190   ;; Change the display table.  Odd characters have a tendency to mess
2191   ;; up nicely formatted displays - we make all possible glyphs
2192   ;; display only a single character.
2193
2194   ;; We start from the standard display table, if any.
2195   (let ((table (or (copy-sequence standard-display-table)
2196                    (make-display-table)))
2197         (i 32))
2198     ;; Nix out all the control chars...
2199     (while (>= (setq i (1- i)) 0)
2200       (aset table i [??]))
2201     ;; ... but not newline and cr, of course.  (cr is necessary for the
2202     ;; selective display).
2203     (aset table ?\n nil)
2204     (aset table ?\r nil)
2205     ;; We nix out any glyphs over 126 that are not set already.
2206     (let ((i 256))
2207       (while (>= (setq i (1- i)) 127)
2208         ;; Only modify if the entry is nil.
2209         (unless (aref table i)
2210           (aset table i [??]))))
2211     (setq buffer-display-table table)))
2212
2213 (defun gnus-summary-setup-buffer (group)
2214   "Initialize summary buffer."
2215   (let ((buffer (concat "*Summary " group "*")))
2216     (if (get-buffer buffer)
2217         (progn
2218           (set-buffer buffer)
2219           (setq gnus-summary-buffer (current-buffer))
2220           (not gnus-newsgroup-prepared))
2221       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2222       (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
2223       (gnus-add-current-to-buffer-list)
2224       (gnus-summary-mode group)
2225       (when gnus-carpal
2226         (gnus-carpal-setup-buffer 'summary))
2227       (unless gnus-single-article-buffer
2228         (make-local-variable 'gnus-article-buffer)
2229         (make-local-variable 'gnus-article-current)
2230         (make-local-variable 'gnus-original-article-buffer))
2231       (setq gnus-newsgroup-name group)
2232       t)))
2233
2234 (defun gnus-set-global-variables ()
2235   ;; Set the global equivalents of the summary buffer-local variables
2236   ;; to the latest values they had.  These reflect the summary buffer
2237   ;; that was in action when the last article was fetched.
2238   (when (eq major-mode 'gnus-summary-mode)
2239     (setq gnus-summary-buffer (current-buffer))
2240     (let ((name gnus-newsgroup-name)
2241           (marked gnus-newsgroup-marked)
2242           (unread gnus-newsgroup-unreads)
2243           (headers gnus-current-headers)
2244           (data gnus-newsgroup-data)
2245           (summary gnus-summary-buffer)
2246           (article-buffer gnus-article-buffer)
2247           (original gnus-original-article-buffer)
2248           (gac gnus-article-current)
2249           (reffed gnus-reffed-article-number)
2250           (score-file gnus-current-score-file))
2251       (save-excursion
2252         (set-buffer gnus-group-buffer)
2253         (setq gnus-newsgroup-name name)
2254         (setq gnus-newsgroup-marked marked)
2255         (setq gnus-newsgroup-unreads unread)
2256         (setq gnus-current-headers headers)
2257         (setq gnus-newsgroup-data data)
2258         (setq gnus-article-current gac)
2259         (setq gnus-summary-buffer summary)
2260         (setq gnus-article-buffer article-buffer)
2261         (setq gnus-original-article-buffer original)
2262         (setq gnus-reffed-article-number reffed)
2263         (setq gnus-current-score-file score-file)
2264         ;; The article buffer also has local variables.
2265         (when (gnus-buffer-live-p gnus-article-buffer)
2266           (set-buffer gnus-article-buffer)
2267           (setq gnus-summary-buffer summary))))))
2268
2269 (defun gnus-summary-article-unread-p (article)
2270   "Say whether ARTICLE is unread or not."
2271   (memq article gnus-newsgroup-unreads))
2272
2273 (defun gnus-summary-first-article-p (&optional article)
2274   "Return whether ARTICLE is the first article in the buffer."
2275   (if (not (setq article (or article (gnus-summary-article-number))))
2276       nil
2277     (eq article (caar gnus-newsgroup-data))))
2278
2279 (defun gnus-summary-last-article-p (&optional article)
2280   "Return whether ARTICLE is the last article in the buffer."
2281   (if (not (setq article (or article (gnus-summary-article-number))))
2282       t         ; All non-existent numbers are the last article.  :-)
2283     (not (cdr (gnus-data-find-list article)))))
2284
2285 (defun gnus-make-thread-indent-array ()
2286   (let ((n 200))
2287     (unless (and gnus-thread-indent-array
2288                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2289       (setq gnus-thread-indent-array (make-vector 201 "")
2290             gnus-thread-indent-array-level gnus-thread-indent-level)
2291       (while (>= n 0)
2292         (aset gnus-thread-indent-array n
2293               (make-string (* n gnus-thread-indent-level) ? ))
2294         (setq n (1- n))))))
2295
2296 (defun gnus-update-summary-mark-positions ()
2297   "Compute where the summary marks are to go."
2298   (save-excursion
2299     (when (and gnus-summary-buffer
2300                (get-buffer gnus-summary-buffer)
2301                (buffer-name (get-buffer gnus-summary-buffer)))
2302       (set-buffer gnus-summary-buffer))
2303     (let ((gnus-replied-mark 129)
2304           (gnus-score-below-mark 130)
2305           (gnus-score-over-mark 130)
2306           (spec gnus-summary-line-format-spec)
2307           thread gnus-visual pos)
2308       (save-excursion
2309         (gnus-set-work-buffer)
2310         (let ((gnus-summary-line-format-spec spec))
2311           (gnus-summary-insert-line
2312            [0 "" "" "" "" "" 0 0 ""]  0 nil 128 t nil "" nil 1)
2313           (goto-char (point-min))
2314           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2315                                              (- (point) 2)))))
2316           (goto-char (point-min))
2317           (push (cons 'replied (and (search-forward "\201" nil t)
2318                                     (- (point) 2)))
2319                 pos)
2320           (goto-char (point-min))
2321           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2322                 pos)))
2323       (setq gnus-summary-mark-positions pos))))
2324
2325 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2326   "Insert a dummy root in the summary buffer."
2327   (beginning-of-line)
2328   (gnus-add-text-properties
2329    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2330    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2331
2332 (defun gnus-summary-insert-line (gnus-tmp-header
2333                                  gnus-tmp-level gnus-tmp-current
2334                                  gnus-tmp-unread gnus-tmp-replied
2335                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2336                                  &optional gnus-tmp-dummy gnus-tmp-score
2337                                  gnus-tmp-process)
2338   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2339          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2340          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2341          (gnus-tmp-score-char
2342           (if (or (null gnus-summary-default-score)
2343                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2344                       gnus-summary-zcore-fuzz))
2345               ? 
2346             (if (< gnus-tmp-score gnus-summary-default-score)
2347                 gnus-score-below-mark gnus-score-over-mark)))
2348          (gnus-tmp-replied
2349           (cond (gnus-tmp-process gnus-process-mark)
2350                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2351                  gnus-cached-mark)
2352                 (gnus-tmp-replied gnus-replied-mark)
2353                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2354                  gnus-saved-mark)
2355                 (t gnus-unread-mark)))
2356          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2357          (gnus-tmp-name
2358           (cond
2359            ((string-match "<[^>]+> *$" gnus-tmp-from)
2360             (let ((beg (match-beginning 0)))
2361               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2362                        (substring gnus-tmp-from (1+ (match-beginning 0))
2363                                   (1- (match-end 0))))
2364                   (substring gnus-tmp-from 0 beg))))
2365            ((string-match "(.+)" gnus-tmp-from)
2366             (substring gnus-tmp-from
2367                        (1+ (match-beginning 0)) (1- (match-end 0))))
2368            (t gnus-tmp-from)))
2369          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2370          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2371          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2372          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2373          (buffer-read-only nil))
2374     (when (string= gnus-tmp-name "")
2375       (setq gnus-tmp-name gnus-tmp-from))
2376     (unless (numberp gnus-tmp-lines)
2377       (setq gnus-tmp-lines 0))
2378     (gnus-put-text-property
2379      (point)
2380      (progn (eval gnus-summary-line-format-spec) (point))
2381      'gnus-number gnus-tmp-number)
2382     (when (gnus-visual-p 'summary-highlight 'highlight)
2383       (forward-line -1)
2384       (run-hooks 'gnus-summary-update-hook)
2385       (forward-line 1))))
2386
2387 (defun gnus-summary-update-line (&optional dont-update)
2388   ;; Update summary line after change.
2389   (when (and gnus-summary-default-score
2390              (not gnus-summary-inhibit-highlight))
2391     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2392            (article (gnus-summary-article-number))
2393            (score (gnus-summary-article-score article)))
2394       (unless dont-update
2395         (if (and gnus-summary-mark-below
2396                  (< (gnus-summary-article-score)
2397                     gnus-summary-mark-below))
2398             ;; This article has a low score, so we mark it as read.
2399             (when (memq article gnus-newsgroup-unreads)
2400               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2401           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2402             ;; This article was previously marked as read on account
2403             ;; of a low score, but now it has risen, so we mark it as
2404             ;; unread.
2405             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2406         (gnus-summary-update-mark
2407          (if (or (null gnus-summary-default-score)
2408                  (<= (abs (- score gnus-summary-default-score))
2409                      gnus-summary-zcore-fuzz))
2410              ? 
2411            (if (< score gnus-summary-default-score)
2412                gnus-score-below-mark gnus-score-over-mark))
2413          'score))
2414       ;; Do visual highlighting.
2415       (when (gnus-visual-p 'summary-highlight 'highlight)
2416         (run-hooks 'gnus-summary-update-hook)))))
2417
2418 (defvar gnus-tmp-new-adopts nil)
2419
2420 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2421   "Return the number of articles in THREAD.
2422 This may be 0 in some cases -- if none of the articles in
2423 the thread are to be displayed."
2424   (let* ((number
2425           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2426           (cond
2427            ((not (listp thread))
2428             1)
2429            ((and (consp thread) (cdr thread))
2430             (apply
2431              '+ 1 (mapcar
2432                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2433            ((null thread)
2434             1)
2435            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2436             1)
2437            (t 0))))
2438     (when (and level (zerop level) gnus-tmp-new-adopts)
2439       (incf number
2440             (apply '+ (mapcar
2441                        'gnus-summary-number-of-articles-in-thread
2442                        gnus-tmp-new-adopts))))
2443     (if char
2444         (if (> number 1) gnus-not-empty-thread-mark
2445           gnus-empty-thread-mark)
2446       number)))
2447
2448 (defun gnus-summary-set-local-parameters (group)
2449   "Go through the local params of GROUP and set all variable specs in that list."
2450   (let ((params (gnus-group-find-parameter group))
2451         elem)
2452     (while params
2453       (setq elem (car params)
2454             params (cdr params))
2455       (and (consp elem)                 ; Has to be a cons.
2456            (consp (cdr elem))           ; The cdr has to be a list.
2457            (symbolp (car elem))         ; Has to be a symbol in there.
2458            (not (memq (car elem)
2459                       '(quit-config to-address to-list to-group)))
2460            (ignore-errors               ; So we set it.
2461              (make-local-variable (car elem))
2462              (set (car elem) (eval (nth 1 elem))))))))
2463
2464 (defun gnus-summary-read-group (group &optional show-all no-article
2465                                       kill-buffer no-display)
2466   "Start reading news in newsgroup GROUP.
2467 If SHOW-ALL is non-nil, already read articles are also listed.
2468 If NO-ARTICLE is non-nil, no article is selected initially.
2469 If NO-DISPLAY, don't generate a summary buffer."
2470   (let (result)
2471     (while (and group
2472                 (null (setq result
2473                             (let ((gnus-auto-select-next nil))
2474                               (gnus-summary-read-group-1
2475                                group show-all no-article
2476                                kill-buffer no-display))))
2477                 (eq gnus-auto-select-next 'quietly))
2478       (set-buffer gnus-group-buffer)
2479       (if (not (equal group (gnus-group-group-name)))
2480           (setq group (gnus-group-group-name))
2481         (setq group nil)))
2482     result))
2483
2484 (defun gnus-summary-read-group-1 (group show-all no-article
2485                                         kill-buffer no-display)
2486   ;; Killed foreign groups can't be entered.
2487   (when (and (not (gnus-group-native-p group))
2488              (not (gnus-gethash group gnus-newsrc-hashtb)))
2489     (error "Dead non-native groups can't be entered"))
2490   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2491   (let* ((new-group (gnus-summary-setup-buffer group))
2492          (quit-config (gnus-group-quit-config group))
2493          (did-select (and new-group (gnus-select-newsgroup group show-all))))
2494     (cond
2495      ;; This summary buffer exists already, so we just select it.
2496      ((not new-group)
2497       (gnus-set-global-variables)
2498       (when kill-buffer
2499         (gnus-kill-or-deaden-summary kill-buffer))
2500       (gnus-configure-windows 'summary 'force)
2501       (gnus-set-mode-line 'summary)
2502       (gnus-summary-position-point)
2503       (message "")
2504       t)
2505      ;; We couldn't select this group.
2506      ((null did-select)
2507       (when (and (eq major-mode 'gnus-summary-mode)
2508                  (not (equal (current-buffer) kill-buffer)))
2509         (kill-buffer (current-buffer))
2510         (if (not quit-config)
2511             (progn
2512               (set-buffer gnus-group-buffer)
2513               (gnus-group-jump-to-group group)
2514               (gnus-group-next-unread-group 1))
2515           (gnus-handle-ephemeral-exit quit-config)))
2516       (gnus-message 3 "Can't select group")
2517       nil)
2518      ;; The user did a `C-g' while prompting for number of articles,
2519      ;; so we exit this group.
2520      ((eq did-select 'quit)
2521       (and (eq major-mode 'gnus-summary-mode)
2522            (not (equal (current-buffer) kill-buffer))
2523            (kill-buffer (current-buffer)))
2524       (when kill-buffer
2525         (gnus-kill-or-deaden-summary kill-buffer))
2526       (if (not quit-config)
2527           (progn
2528             (set-buffer gnus-group-buffer)
2529             (gnus-group-jump-to-group group)
2530             (gnus-group-next-unread-group 1)
2531             (gnus-configure-windows 'group 'force))
2532         (gnus-handle-ephemeral-exit quit-config))
2533       ;; Finally signal the quit.
2534       (signal 'quit nil))
2535      ;; The group was successfully selected.
2536      (t
2537       (gnus-set-global-variables)
2538       ;; Save the active value in effect when the group was entered.
2539       (setq gnus-newsgroup-active
2540             (gnus-copy-sequence
2541              (gnus-active gnus-newsgroup-name)))
2542       ;; You can change the summary buffer in some way with this hook.
2543       (run-hooks 'gnus-select-group-hook)
2544       ;; Set any local variables in the group parameters.
2545       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2546       (gnus-update-format-specifications
2547        nil 'summary 'summary-mode 'summary-dummy)
2548       ;; Do score processing.
2549       (when gnus-use-scoring
2550         (gnus-possibly-score-headers))
2551       ;; Check whether to fill in the gaps in the threads.
2552       (when gnus-build-sparse-threads
2553         (gnus-build-sparse-threads))
2554       ;; Find the initial limit.
2555       (if gnus-show-threads
2556           (if show-all
2557               (let ((gnus-newsgroup-dormant nil))
2558                 (gnus-summary-initial-limit show-all))
2559             (gnus-summary-initial-limit show-all))
2560         (setq gnus-newsgroup-limit
2561               (mapcar
2562                (lambda (header) (mail-header-number header))
2563                gnus-newsgroup-headers)))
2564       ;; Generate the summary buffer.
2565       (unless no-display
2566         (gnus-summary-prepare))
2567       (when gnus-use-trees
2568         (gnus-tree-open group)
2569         (setq gnus-summary-highlight-line-function
2570               'gnus-tree-highlight-article))
2571       ;; If the summary buffer is empty, but there are some low-scored
2572       ;; articles or some excluded dormants, we include these in the
2573       ;; buffer.
2574       (when (and (zerop (buffer-size))
2575                  (not no-display))
2576         (cond (gnus-newsgroup-dormant
2577                (gnus-summary-limit-include-dormant))
2578               ((and gnus-newsgroup-scored show-all)
2579                (gnus-summary-limit-include-expunged t))))
2580       ;; Function `gnus-apply-kill-file' must be called in this hook.
2581       (run-hooks 'gnus-apply-kill-hook)
2582       (if (and (zerop (buffer-size))
2583                (not no-display))
2584           (progn
2585             ;; This newsgroup is empty.
2586             (gnus-summary-catchup-and-exit nil t)
2587             (gnus-message 6 "No unread news")
2588             (when kill-buffer
2589               (gnus-kill-or-deaden-summary kill-buffer))
2590             ;; Return nil from this function.
2591             nil)
2592         ;; Hide conversation thread subtrees.  We cannot do this in
2593         ;; gnus-summary-prepare-hook since kill processing may not
2594         ;; work with hidden articles.
2595         (and gnus-show-threads
2596              gnus-thread-hide-subtree
2597              (gnus-summary-hide-all-threads))
2598         ;; Show first unread article if requested.
2599         (if (and (not no-article)
2600                  (not no-display)
2601                  gnus-newsgroup-unreads
2602                  gnus-auto-select-first)
2603             (unless (if (eq gnus-auto-select-first 'best)
2604                         (gnus-summary-best-unread-article)
2605                       (gnus-summary-first-unread-article))
2606               (gnus-configure-windows 'summary))
2607           ;; Don't select any articles, just move point to the first
2608           ;; article in the group.
2609           (goto-char (point-min))
2610           (gnus-summary-position-point)
2611           (gnus-set-mode-line 'summary)
2612           (gnus-configure-windows 'summary 'force))
2613         (when kill-buffer
2614           (gnus-kill-or-deaden-summary kill-buffer))
2615         (when (get-buffer-window gnus-group-buffer t)
2616           ;; Gotta use windows, because recenter does weird stuff if
2617           ;; the current buffer ain't the displayed window.
2618           (let ((owin (selected-window)))
2619             (select-window (get-buffer-window gnus-group-buffer t))
2620             (when (gnus-group-goto-group group)
2621               (recenter))
2622             (select-window owin)))
2623         ;; Mark this buffer as "prepared".
2624         (setq gnus-newsgroup-prepared t)
2625         t)))))
2626
2627 (defun gnus-summary-prepare ()
2628   "Generate the summary buffer."
2629   (interactive)
2630   (let ((buffer-read-only nil))
2631     (erase-buffer)
2632     (setq gnus-newsgroup-data nil
2633           gnus-newsgroup-data-reverse nil)
2634     (run-hooks 'gnus-summary-generate-hook)
2635     ;; Generate the buffer, either with threads or without.
2636     (when gnus-newsgroup-headers
2637       (gnus-summary-prepare-threads
2638        (if gnus-show-threads
2639            (gnus-sort-gathered-threads
2640             (funcall gnus-summary-thread-gathering-function
2641                      (gnus-sort-threads
2642                       (gnus-cut-threads (gnus-make-threads)))))
2643          ;; Unthreaded display.
2644          (gnus-sort-articles gnus-newsgroup-headers))))
2645     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
2646     ;; Call hooks for modifying summary buffer.
2647     (goto-char (point-min))
2648     (run-hooks 'gnus-summary-prepare-hook)))
2649
2650 (defsubst gnus-general-simplify-subject (subject)
2651   "Simply subject by the same rules as gnus-gather-threads-by-subject."
2652   (setq subject
2653         (cond
2654          ;; Truncate the subject.
2655          ((numberp gnus-summary-gather-subject-limit)
2656           (setq subject (gnus-simplify-subject-re subject))
2657           (if (> (length subject) gnus-summary-gather-subject-limit)
2658               (substring subject 0 gnus-summary-gather-subject-limit)
2659             subject))
2660          ;; Fuzzily simplify it.
2661          ((eq 'fuzzy gnus-summary-gather-subject-limit)
2662           (gnus-simplify-subject-fuzzy subject))
2663          ;; Just remove the leading "Re:".
2664          (t
2665           (gnus-simplify-subject-re subject))))
2666
2667   (if (and gnus-summary-gather-exclude-subject
2668            (string-match gnus-summary-gather-exclude-subject subject))
2669       nil                               ; This article shouldn't be gathered
2670     subject))
2671
2672 (defun gnus-summary-simplify-subject-query ()
2673   "Query where the respool algorithm would put this article."
2674   (interactive)
2675   (gnus-set-global-variables)
2676   (gnus-summary-select-article)
2677   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
2678
2679 (defun gnus-gather-threads-by-subject (threads)
2680   "Gather threads by looking at Subject headers."
2681   (if (not gnus-summary-make-false-root)
2682       threads
2683     (let ((hashtb (gnus-make-hashtable 1024))
2684           (prev threads)
2685           (result threads)
2686           subject hthread whole-subject)
2687       (while threads
2688         (setq subject (gnus-general-simplify-subject
2689                        (setq whole-subject (mail-header-subject
2690                                             (caar threads)))))
2691         (when subject
2692           (if (setq hthread (gnus-gethash subject hashtb))
2693               (progn
2694                 ;; We enter a dummy root into the thread, if we
2695                 ;; haven't done that already.
2696                 (unless (stringp (caar hthread))
2697                   (setcar hthread (list whole-subject (car hthread))))
2698                 ;; We add this new gathered thread to this gathered
2699                 ;; thread.
2700                 (setcdr (car hthread)
2701                         (nconc (cdar hthread) (list (car threads))))
2702                 ;; Remove it from the list of threads.
2703                 (setcdr prev (cdr threads))
2704                 (setq threads prev))
2705             ;; Enter this thread into the hash table.
2706             (gnus-sethash subject threads hashtb)))
2707         (setq prev threads)
2708         (setq threads (cdr threads)))
2709       result)))
2710
2711 (defun gnus-gather-threads-by-references (threads)
2712   "Gather threads by looking at References headers."
2713   (let ((idhashtb (gnus-make-hashtable 1024))
2714         (thhashtb (gnus-make-hashtable 1024))
2715         (prev threads)
2716         (result threads)
2717         ids references id gthread gid entered ref)
2718     (while threads
2719       (when (setq references (mail-header-references (caar threads)))
2720         (setq id (mail-header-id (caar threads))
2721               ids (gnus-split-references references)
2722               entered nil)
2723         (while (setq ref (pop ids))
2724           (setq ids (delete ref ids))
2725           (if (not (setq gid (gnus-gethash ref idhashtb)))
2726               (progn
2727                 (gnus-sethash ref id idhashtb)
2728                 (gnus-sethash id threads thhashtb))
2729             (setq gthread (gnus-gethash gid thhashtb))
2730             (unless entered
2731               ;; We enter a dummy root into the thread, if we
2732               ;; haven't done that already.
2733               (unless (stringp (caar gthread))
2734                 (setcar gthread (list (mail-header-subject (caar gthread))
2735                                       (car gthread))))
2736               ;; We add this new gathered thread to this gathered
2737               ;; thread.
2738               (setcdr (car gthread)
2739                       (nconc (cdar gthread) (list (car threads)))))
2740             ;; Add it into the thread hash table.
2741             (gnus-sethash id gthread thhashtb)
2742             (setq entered t)
2743             ;; Remove it from the list of threads.
2744             (setcdr prev (cdr threads))
2745             (setq threads prev))))
2746       (setq prev threads)
2747       (setq threads (cdr threads)))
2748     result))
2749
2750 (defun gnus-sort-gathered-threads (threads)
2751   "Sort subtreads inside each gathered thread by article number."
2752   (let ((result threads))
2753     (while threads
2754       (when (stringp (caar threads))
2755         (setcdr (car threads)
2756                 (sort (cdar threads) 'gnus-thread-sort-by-number)))
2757       (setq threads (cdr threads)))
2758     result))
2759
2760 (defun gnus-thread-loop-p (root thread)
2761   "Say whether ROOT is in THREAD."
2762   (let ((th (cdr thread)))
2763     (while (and th
2764                 (not (eq (caar th) root)))
2765       (pop th))
2766     (if th
2767         ;; We have found a loop.
2768         (let (ref-dep)
2769           (setcdr thread (delq (car th) (cdr thread)))
2770           (if (boundp (setq ref-dep (intern "none"
2771                                             gnus-newsgroup-dependencies)))
2772               (setcdr (symbol-value ref-dep)
2773                       (nconc (cdr (symbol-value ref-dep))
2774                              (list (car th))))
2775             (set ref-dep (list nil (car th))))
2776           1)
2777       ;; Recurse down into the sub-threads and look for loops.
2778       (apply '+
2779              (mapcar
2780               (lambda (thread) (gnus-thread-loop-p root thread))
2781               (cdr thread))))))
2782
2783 (defun gnus-make-threads ()
2784   "Go through the dependency hashtb and find the roots.  Return all threads."
2785   (let (threads)
2786     (while (catch 'infloop
2787              (mapatoms
2788               (lambda (refs)
2789                 ;; Deal with self-referencing References loops.
2790                 (when (and (car (symbol-value refs))
2791                            (not (zerop
2792                                  (apply
2793                                   '+
2794                                   (mapcar
2795                                    (lambda (thread)
2796                                      (gnus-thread-loop-p
2797                                       (car (symbol-value refs)) thread))
2798                                    (cdr (symbol-value refs)))))))
2799                   (setq threads nil)
2800                   (throw 'infloop t))
2801                 (unless (car (symbol-value refs))
2802                   ;; These threads do not refer back to any other articles,
2803                   ;; so they're roots.
2804                   (setq threads (append (cdr (symbol-value refs)) threads))))
2805               gnus-newsgroup-dependencies)))
2806     threads))
2807
2808 (defun gnus-build-sparse-threads ()
2809   (let ((headers gnus-newsgroup-headers)
2810         (deps gnus-newsgroup-dependencies)
2811         header references generation relations
2812         cthread subject child end pthread relation)
2813     ;; First we create an alist of generations/relations, where
2814     ;; generations is how much we trust the relation, and the relation
2815     ;; is parent/child.
2816     (gnus-message 7 "Making sparse threads...")
2817     (save-excursion
2818       (nnheader-set-temp-buffer " *gnus sparse threads*")
2819       (while (setq header (pop headers))
2820         (when (and (setq references (mail-header-references header))
2821                    (not (string= references "")))
2822           (insert references)
2823           (setq child (mail-header-id header)
2824                 subject (mail-header-subject header))
2825           (setq generation 0)
2826           (while (search-backward ">" nil t)
2827             (setq end (1+ (point)))
2828             (when (search-backward "<" nil t)
2829               (push (list (incf generation)
2830                           child (setq child (buffer-substring (point) end))
2831                           subject)
2832                     relations)))
2833           (push (list (1+ generation) child nil subject) relations)
2834           (erase-buffer)))
2835       (kill-buffer (current-buffer)))
2836     ;; Sort over trustworthiness.
2837     (setq relations (sort relations (lambda (r1 r2) (< (car r1) (car r2)))))
2838     (while (setq relation (pop relations))
2839       (when (if (boundp (setq cthread (intern (cadr relation) deps)))
2840                 (unless (car (symbol-value cthread))
2841                   ;; Make this article the parent of these threads.
2842                   (setcar (symbol-value cthread)
2843                           (vector gnus-reffed-article-number
2844                                   (cadddr relation)
2845                                   "" ""
2846                                   (cadr relation)
2847                                   (or (caddr relation) "") 0 0 "")))
2848               (set cthread (list (vector gnus-reffed-article-number
2849                                          (cadddr relation)
2850                                          "" "" (cadr relation)
2851                                          (or (caddr relation) "") 0 0 ""))))
2852         (push gnus-reffed-article-number gnus-newsgroup-limit)
2853         (push gnus-reffed-article-number gnus-newsgroup-sparse)
2854         (push (cons gnus-reffed-article-number gnus-sparse-mark)
2855               gnus-newsgroup-reads)
2856         (decf gnus-reffed-article-number)
2857         ;; Make this new thread the child of its parent.
2858         (if (boundp (setq pthread (intern (or (caddr relation) "none") deps)))
2859             (setcdr (symbol-value pthread)
2860                     (nconc (cdr (symbol-value pthread))
2861                            (list (symbol-value cthread))))
2862           (set pthread (list nil (symbol-value cthread))))))
2863     (gnus-message 7 "Making sparse threads...done")))
2864
2865 (defun gnus-build-old-threads ()
2866   ;; Look at all the articles that refer back to old articles, and
2867   ;; fetch the headers for the articles that aren't there.  This will
2868   ;; build complete threads - if the roots haven't been expired by the
2869   ;; server, that is.
2870   (let (id heads)
2871     (mapatoms
2872      (lambda (refs)
2873        (when (not (car (symbol-value refs)))
2874          (setq heads (cdr (symbol-value refs)))
2875          (while heads
2876            (if (memq (mail-header-number (caar heads))
2877                      gnus-newsgroup-dormant)
2878                (setq heads (cdr heads))
2879              (setq id (symbol-name refs))
2880              (while (and (setq id (gnus-build-get-header id))
2881                          (not (car (gnus-gethash
2882                                     id gnus-newsgroup-dependencies)))))
2883              (setq heads nil)))))
2884      gnus-newsgroup-dependencies)))
2885
2886 (defun gnus-build-get-header (id)
2887   ;; Look through the buffer of NOV lines and find the header to
2888   ;; ID.  Enter this line into the dependencies hash table, and return
2889   ;; the id of the parent article (if any).
2890   (let ((deps gnus-newsgroup-dependencies)
2891         found header)
2892     (prog1
2893         (save-excursion
2894           (set-buffer nntp-server-buffer)
2895           (let ((case-fold-search nil))
2896             (goto-char (point-min))
2897             (while (and (not found)
2898                         (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        ;; Only insert the Subject string when it's different
2943        ;; from the previous Subject string.
2944        (if (gnus-subject-equal
2945             (condition-case ()
2946                 (mail-header-subject
2947                  (gnus-data-header
2948                   (cadr
2949                    (gnus-data-find-list
2950                     article
2951                     (gnus-data-list t)))))
2952               ;; Error on the side of excessive subjects.
2953               (error (mail-header-subject header)))
2954             (mail-header-subject header))
2955            (mail-header-subject header)
2956          "")
2957        nil (cdr (assq article gnus-newsgroup-scored))
2958        (memq article gnus-newsgroup-processable))
2959       (when length
2960         (gnus-data-update-list
2961          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
2962
2963 (defun gnus-summary-update-article (article &optional iheader)
2964   "Update ARTICLE in the summary buffer."
2965   (set-buffer gnus-summary-buffer)
2966   (let* ((header (or iheader (gnus-summary-article-header article)))
2967          (id (mail-header-id header))
2968          (data (gnus-data-find article))
2969          (thread (gnus-id-to-thread id))
2970          (references (mail-header-references header))
2971          (parent
2972           (gnus-id-to-thread
2973            (or (gnus-parent-id
2974                 (when (and references
2975                            (not (equal "" references)))
2976                   references))
2977                "none")))
2978          (buffer-read-only nil)
2979          (old (car thread))
2980          (number (mail-header-number header))
2981          pos)
2982     (when thread
2983       ;; !!! Should this be in or not?
2984       (unless iheader
2985         (setcar thread nil))
2986       (when parent
2987         (delq thread parent))
2988       (if (gnus-summary-insert-subject id header iheader)
2989           ;; Set the (possibly) new article number in the data structure.
2990           (gnus-data-set-number data (gnus-id-to-article id))
2991         (setcar thread old)
2992         nil))))
2993
2994 (defun gnus-rebuild-thread (id)
2995   "Rebuild the thread containing ID."
2996   (let ((buffer-read-only nil)
2997         old-pos current thread data)
2998     (if (not gnus-show-threads)
2999         (setq thread (list (car (gnus-id-to-thread id))))
3000       ;; Get the thread this article is part of.
3001       (setq thread (gnus-remove-thread id)))
3002     (setq old-pos (gnus-point-at-bol))
3003     (setq current (save-excursion
3004                     (and (zerop (forward-line -1))
3005                          (gnus-summary-article-number))))
3006     ;; If this is a gathered thread, we have to go some re-gathering.
3007     (when (stringp (car thread))
3008       (let ((subject (car thread))
3009             roots thr)
3010         (setq thread (cdr thread))
3011         (while thread
3012           (unless (memq (setq thr (gnus-id-to-thread
3013                                    (gnus-root-id
3014                                     (mail-header-id (caar thread)))))
3015                         roots)
3016             (push thr roots))
3017           (setq thread (cdr thread)))
3018         ;; We now have all (unique) roots.
3019         (if (= (length roots) 1)
3020             ;; All the loose roots are now one solid root.
3021             (setq thread (car roots))
3022           (setq thread (cons subject (gnus-sort-threads roots))))))
3023     (let (threads)
3024       ;; We then insert this thread into the summary buffer.
3025       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3026         (if gnus-show-threads
3027             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3028           (gnus-summary-prepare-unthreaded thread))
3029         (setq data (nreverse gnus-newsgroup-data))
3030         (setq threads gnus-newsgroup-threads))
3031       ;; We splice the new data into the data structure.
3032       (gnus-data-enter-list current data (- (point) old-pos))
3033       (setq gnus-newsgroup-threads (nconc threads gnus-newsgroup-threads)))))
3034
3035 (defun gnus-number-to-header (number)
3036   "Return the header for article NUMBER."
3037   (let ((headers gnus-newsgroup-headers))
3038     (while (and headers
3039                 (not (= number (mail-header-number (car headers)))))
3040       (pop headers))
3041     (when headers
3042       (car headers))))
3043
3044 (defun gnus-parent-headers (headers &optional generation)
3045   "Return the headers of the GENERATIONeth parent of HEADERS."
3046   (unless generation
3047     (setq generation 1))
3048   (let (references parent)
3049     (while (and headers (not (zerop generation)))
3050       (setq references (mail-header-references headers))
3051       (when (and references
3052                  (setq parent (gnus-parent-id references))
3053                  (setq headers (car (gnus-id-to-thread parent))))
3054         (decf generation)))
3055     headers))
3056
3057 (defun gnus-id-to-thread (id)
3058   "Return the (sub-)thread where ID appears."
3059   (gnus-gethash id gnus-newsgroup-dependencies))
3060
3061 (defun gnus-id-to-article (id)
3062   "Return the article number of ID."
3063   (let ((thread (gnus-id-to-thread id)))
3064     (when (and thread
3065                (car thread))
3066       (mail-header-number (car thread)))))
3067
3068 (defun gnus-id-to-header (id)
3069   "Return the article headers of ID."
3070   (car (gnus-id-to-thread id)))
3071
3072 (defun gnus-article-displayed-root-p (article)
3073   "Say whether ARTICLE is a root(ish) article."
3074   (let ((level (gnus-summary-thread-level article))
3075         (refs (mail-header-references  (gnus-summary-article-header article)))
3076         particle)
3077     (cond
3078      ((null level) nil)
3079      ((zerop level) t)
3080      ((null refs) t)
3081      ((null (gnus-parent-id refs)) t)
3082      ((and (= 1 level)
3083            (null (setq particle (gnus-id-to-article
3084                                  (gnus-parent-id refs))))
3085            (null (gnus-summary-thread-level particle)))))))
3086
3087 (defun gnus-root-id (id)
3088   "Return the id of the root of the thread where ID appears."
3089   (let (last-id prev)
3090     (while (and id (setq prev (car (gnus-gethash
3091                                     id gnus-newsgroup-dependencies))))
3092       (setq last-id id
3093             id (gnus-parent-id (mail-header-references prev))))
3094     last-id))
3095
3096 (defun gnus-remove-thread (id &optional dont-remove)
3097   "Remove the thread that has ID in it."
3098   (let ((dep gnus-newsgroup-dependencies)
3099         headers thread last-id)
3100     ;; First go up in this thread until we find the root.
3101     (setq last-id (gnus-root-id id))
3102     (setq headers (list (car (gnus-id-to-thread last-id))
3103                         (caadr (gnus-id-to-thread last-id))))
3104     ;; We have now found the real root of this thread.  It might have
3105     ;; been gathered into some loose thread, so we have to search
3106     ;; through the threads to find the thread we wanted.
3107     (let ((threads gnus-newsgroup-threads)
3108           sub)
3109       (while threads
3110         (setq sub (car threads))
3111         (if (stringp (car sub))
3112             ;; This is a gathered thread, so we look at the roots
3113             ;; below it to find whether this article is in this
3114             ;; gathered root.
3115             (progn
3116               (setq sub (cdr sub))
3117               (while sub
3118                 (when (member (caar sub) headers)
3119                   (setq thread (car threads)
3120                         threads nil
3121                         sub nil))
3122                 (setq sub (cdr sub))))
3123           ;; It's an ordinary thread, so we check it.
3124           (when (eq (car sub) (car headers))
3125             (setq thread sub
3126                   threads nil)))
3127         (setq threads (cdr threads)))
3128       ;; If this article is in no thread, then it's a root.
3129       (if thread
3130           (unless dont-remove
3131             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3132         (setq thread (gnus-gethash last-id dep)))
3133       (when thread
3134         (prog1
3135             thread                      ; We return this thread.
3136           (unless dont-remove
3137             (if (stringp (car thread))
3138                 (progn
3139                   ;; If we use dummy roots, then we have to remove the
3140                   ;; dummy root as well.
3141                   (when (eq gnus-summary-make-false-root 'dummy)
3142                     (gnus-delete-line)
3143                     (gnus-data-compute-positions))
3144                   (setq thread (cdr thread))
3145                   (while thread
3146                     (gnus-remove-thread-1 (car thread))
3147                     (setq thread (cdr thread))))
3148               (gnus-remove-thread-1 thread))))))))
3149
3150 (defun gnus-remove-thread-1 (thread)
3151   "Remove the thread THREAD recursively."
3152   (let ((number (mail-header-number (pop thread)))
3153         d)
3154     (setq thread (reverse thread))
3155     (while thread
3156       (gnus-remove-thread-1 (pop thread)))
3157     (when (setq d (gnus-data-find number))
3158       (goto-char (gnus-data-pos d))
3159       (gnus-data-remove
3160        number
3161        (- (gnus-point-at-bol)
3162           (prog1
3163               (1+ (gnus-point-at-eol))
3164             (gnus-delete-line)))))))
3165
3166 (defun gnus-sort-threads (threads)
3167   "Sort THREADS."
3168   (if (not gnus-thread-sort-functions)
3169       threads
3170     (gnus-message 7 "Sorting threads...")
3171     (prog1
3172         (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
3173       (gnus-message 7 "Sorting threads...done"))))
3174
3175 (defun gnus-sort-articles (articles)
3176   "Sort ARTICLES."
3177   (when gnus-article-sort-functions
3178     (gnus-message 7 "Sorting articles...")
3179     (prog1
3180         (setq gnus-newsgroup-headers
3181               (sort articles (gnus-make-sort-function
3182                               gnus-article-sort-functions)))
3183       (gnus-message 7 "Sorting articles...done"))))
3184
3185 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3186 (defmacro gnus-thread-header (thread)
3187   ;; Return header of first article in THREAD.
3188   ;; Note that THREAD must never, ever be anything else than a variable -
3189   ;; using some other form will lead to serious barfage.
3190   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3191   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3192   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
3193         (vector thread) 2))
3194
3195 (defsubst gnus-article-sort-by-number (h1 h2)
3196   "Sort articles by article number."
3197   (< (mail-header-number h1)
3198      (mail-header-number h2)))
3199
3200 (defun gnus-thread-sort-by-number (h1 h2)
3201   "Sort threads by root article number."
3202   (gnus-article-sort-by-number
3203    (gnus-thread-header h1) (gnus-thread-header h2)))
3204
3205 (defsubst gnus-article-sort-by-lines (h1 h2)
3206   "Sort articles by article Lines header."
3207   (< (mail-header-lines h1)
3208      (mail-header-lines h2)))
3209
3210 (defun gnus-thread-sort-by-lines (h1 h2)
3211   "Sort threads by root article Lines header."
3212   (gnus-article-sort-by-lines
3213    (gnus-thread-header h1) (gnus-thread-header h2)))
3214
3215 (defsubst gnus-article-sort-by-author (h1 h2)
3216   "Sort articles by root author."
3217   (string-lessp
3218    (let ((extract (funcall
3219                    gnus-extract-address-components
3220                    (mail-header-from h1))))
3221      (or (car extract) (cadr extract) ""))
3222    (let ((extract (funcall
3223                    gnus-extract-address-components
3224                    (mail-header-from h2))))
3225      (or (car extract) (cadr extract) ""))))
3226
3227 (defun gnus-thread-sort-by-author (h1 h2)
3228   "Sort threads by root author."
3229   (gnus-article-sort-by-author
3230    (gnus-thread-header h1)  (gnus-thread-header h2)))
3231
3232 (defsubst gnus-article-sort-by-subject (h1 h2)
3233   "Sort articles by root subject."
3234   (string-lessp
3235    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3236    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3237
3238 (defun gnus-thread-sort-by-subject (h1 h2)
3239   "Sort threads by root subject."
3240   (gnus-article-sort-by-subject
3241    (gnus-thread-header h1) (gnus-thread-header h2)))
3242
3243 (defsubst gnus-article-sort-by-date (h1 h2)
3244   "Sort articles by root article date."
3245   (gnus-time-less
3246    (gnus-date-get-time (mail-header-date h1))
3247    (gnus-date-get-time (mail-header-date h2))))
3248
3249 (defun gnus-thread-sort-by-date (h1 h2)
3250   "Sort threads by root article date."
3251   (gnus-article-sort-by-date
3252    (gnus-thread-header h1) (gnus-thread-header h2)))
3253
3254 (defsubst gnus-article-sort-by-score (h1 h2)
3255   "Sort articles by root article score.
3256 Unscored articles will be counted as having a score of zero."
3257   (> (or (cdr (assq (mail-header-number h1)
3258                     gnus-newsgroup-scored))
3259          gnus-summary-default-score 0)
3260      (or (cdr (assq (mail-header-number h2)
3261                     gnus-newsgroup-scored))
3262          gnus-summary-default-score 0)))
3263
3264 (defun gnus-thread-sort-by-score (h1 h2)
3265   "Sort threads by root article score."
3266   (gnus-article-sort-by-score
3267    (gnus-thread-header h1) (gnus-thread-header h2)))
3268
3269 (defun gnus-thread-sort-by-total-score (h1 h2)
3270   "Sort threads by the sum of all scores in the thread.
3271 Unscored articles will be counted as having a score of zero."
3272   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3273
3274 (defun gnus-thread-total-score (thread)
3275   ;;  This function find the total score of THREAD.
3276   (cond ((null thread)
3277          0)
3278         ((consp thread)
3279          (if (stringp (car thread))
3280              (apply gnus-thread-score-function 0
3281                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3282            (gnus-thread-total-score-1 thread)))
3283         (t
3284          (gnus-thread-total-score-1 (list thread)))))
3285
3286 (defun gnus-thread-total-score-1 (root)
3287   ;; This function find the total score of the thread below ROOT.
3288   (setq root (car root))
3289   (apply gnus-thread-score-function
3290          (or (append
3291               (mapcar 'gnus-thread-total-score
3292                       (cdr (gnus-gethash (mail-header-id root)
3293                                          gnus-newsgroup-dependencies)))
3294               (when (> (mail-header-number root) 0)
3295                 (list (or (cdr (assq (mail-header-number root)
3296                                      gnus-newsgroup-scored))
3297                           gnus-summary-default-score 0))))
3298              (list gnus-summary-default-score)
3299              '(0))))
3300
3301 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3302 (defvar gnus-tmp-prev-subject nil)
3303 (defvar gnus-tmp-false-parent nil)
3304 (defvar gnus-tmp-root-expunged nil)
3305 (defvar gnus-tmp-dummy-line nil)
3306
3307 (defun gnus-summary-prepare-threads (threads)
3308   "Prepare summary buffer from THREADS and indentation LEVEL.
3309 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3310 or a straight list of headers."
3311   (gnus-message 7 "Generating summary...")
3312
3313   (setq gnus-newsgroup-threads threads)
3314   (beginning-of-line)
3315
3316   (let ((gnus-tmp-level 0)
3317         (default-score (or gnus-summary-default-score 0))
3318         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3319         thread number subject stack state gnus-tmp-gathered beg-match
3320         new-roots gnus-tmp-new-adopts thread-end
3321         gnus-tmp-header gnus-tmp-unread
3322         gnus-tmp-replied gnus-tmp-subject-or-nil
3323         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3324         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3325         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3326
3327     (setq gnus-tmp-prev-subject nil)
3328
3329     (if (vectorp (car threads))
3330         ;; If this is a straight (sic) list of headers, then a
3331         ;; threaded summary display isn't required, so we just create
3332         ;; an unthreaded one.
3333         (gnus-summary-prepare-unthreaded threads)
3334
3335       ;; Do the threaded display.
3336
3337       (while (or threads stack gnus-tmp-new-adopts new-roots)
3338
3339         (if (and (= gnus-tmp-level 0)
3340                  (not (setq gnus-tmp-dummy-line nil))
3341                  (or (not stack)
3342                      (= (caar stack) 0))
3343                  (not gnus-tmp-false-parent)
3344                  (or gnus-tmp-new-adopts new-roots))
3345             (if gnus-tmp-new-adopts
3346                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3347                       thread (list (car gnus-tmp-new-adopts))
3348                       gnus-tmp-header (caar thread)
3349                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3350               (when new-roots
3351                 (setq thread (list (car new-roots))
3352                       gnus-tmp-header (caar thread)
3353                       new-roots (cdr new-roots))))
3354
3355           (if threads
3356               ;; If there are some threads, we do them before the
3357               ;; threads on the stack.
3358               (setq thread threads
3359                     gnus-tmp-header (caar thread))
3360             ;; There were no current threads, so we pop something off
3361             ;; the stack.
3362             (setq state (car stack)
3363                   gnus-tmp-level (car state)
3364                   thread (cdr state)
3365                   stack (cdr stack)
3366                   gnus-tmp-header (caar thread))))
3367
3368         (setq gnus-tmp-false-parent nil)
3369         (setq gnus-tmp-root-expunged nil)
3370         (setq thread-end nil)
3371
3372         (if (stringp gnus-tmp-header)
3373             ;; The header is a dummy root.
3374             (cond
3375              ((eq gnus-summary-make-false-root 'adopt)
3376               ;; We let the first article adopt the rest.
3377               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3378                                                (cddar thread)))
3379               (setq gnus-tmp-gathered
3380                     (nconc (mapcar
3381                             (lambda (h) (mail-header-number (car h)))
3382                             (cddar thread))
3383                            gnus-tmp-gathered))
3384               (setq thread (cons (list (caar thread)
3385                                        (cadar thread))
3386                                  (cdr thread)))
3387               (setq gnus-tmp-level -1
3388                     gnus-tmp-false-parent t))
3389              ((eq gnus-summary-make-false-root 'empty)
3390               ;; We print adopted articles with empty subject fields.
3391               (setq gnus-tmp-gathered
3392                     (nconc (mapcar
3393                             (lambda (h) (mail-header-number (car h)))
3394                             (cddar thread))
3395                            gnus-tmp-gathered))
3396               (setq gnus-tmp-level -1))
3397              ((eq gnus-summary-make-false-root 'dummy)
3398               ;; We remember that we probably want to output a dummy
3399               ;; root.
3400               (setq gnus-tmp-dummy-line gnus-tmp-header)
3401               (setq gnus-tmp-prev-subject gnus-tmp-header))
3402              (t
3403               ;; We do not make a root for the gathered
3404               ;; sub-threads at all.
3405               (setq gnus-tmp-level -1)))
3406
3407           (setq number (mail-header-number gnus-tmp-header)
3408                 subject (mail-header-subject gnus-tmp-header))
3409
3410           (cond
3411            ;; If the thread has changed subject, we might want to make
3412            ;; this subthread into a root.
3413            ((and (null gnus-thread-ignore-subject)
3414                  (not (zerop gnus-tmp-level))
3415                  gnus-tmp-prev-subject
3416                  (not (inline
3417                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
3418             (setq new-roots (nconc new-roots (list (car thread)))
3419                   thread-end t
3420                   gnus-tmp-header nil))
3421            ;; If the article lies outside the current limit,
3422            ;; then we do not display it.
3423            ((not (memq number gnus-newsgroup-limit))
3424             (setq gnus-tmp-gathered
3425                   (nconc (mapcar
3426                           (lambda (h) (mail-header-number (car h)))
3427                           (cdar thread))
3428                          gnus-tmp-gathered))
3429             (setq gnus-tmp-new-adopts (if (cdar thread)
3430                                           (append gnus-tmp-new-adopts
3431                                                   (cdar thread))
3432                                         gnus-tmp-new-adopts)
3433                   thread-end t
3434                   gnus-tmp-header nil)
3435             (when (zerop gnus-tmp-level)
3436               (setq gnus-tmp-root-expunged t)))
3437            ;; Perhaps this article is to be marked as read?
3438            ((and gnus-summary-mark-below
3439                  (< (or (cdr (assq number gnus-newsgroup-scored))
3440                         default-score)
3441                     gnus-summary-mark-below)
3442                  ;; Don't touch sparse articles.
3443                  (not (gnus-summary-article-sparse-p number))
3444                  (not (gnus-summary-article-ancient-p number)))
3445             (setq gnus-newsgroup-unreads
3446                   (delq number gnus-newsgroup-unreads))
3447             (if gnus-newsgroup-auto-expire
3448                 (push number gnus-newsgroup-expirable)
3449               (push (cons number gnus-low-score-mark)
3450                     gnus-newsgroup-reads))))
3451
3452           (when gnus-tmp-header
3453             ;; We may have an old dummy line to output before this
3454             ;; article.
3455             (when gnus-tmp-dummy-line
3456               (gnus-summary-insert-dummy-line
3457                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
3458               (setq gnus-tmp-dummy-line nil))
3459
3460             ;; Compute the mark.
3461             (setq gnus-tmp-unread (gnus-article-mark number))
3462
3463             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
3464                                   gnus-tmp-header gnus-tmp-level)
3465                   gnus-newsgroup-data)
3466
3467             ;; Actually insert the line.
3468             (setq
3469              gnus-tmp-subject-or-nil
3470              (cond
3471               ((and gnus-thread-ignore-subject
3472                     gnus-tmp-prev-subject
3473                     (not (inline (gnus-subject-equal
3474                                   gnus-tmp-prev-subject subject))))
3475                subject)
3476               ((zerop gnus-tmp-level)
3477                (if (and (eq gnus-summary-make-false-root 'empty)
3478                         (memq number gnus-tmp-gathered)
3479                         gnus-tmp-prev-subject
3480                         (inline (gnus-subject-equal
3481                                  gnus-tmp-prev-subject subject)))
3482                    gnus-summary-same-subject
3483                  subject))
3484               (t gnus-summary-same-subject)))
3485             (if (and (eq gnus-summary-make-false-root 'adopt)
3486                      (= gnus-tmp-level 1)
3487                      (memq number gnus-tmp-gathered))
3488                 (setq gnus-tmp-opening-bracket ?\<
3489                       gnus-tmp-closing-bracket ?\>)
3490               (setq gnus-tmp-opening-bracket ?\[
3491                     gnus-tmp-closing-bracket ?\]))
3492             (setq
3493              gnus-tmp-indentation
3494              (aref gnus-thread-indent-array gnus-tmp-level)
3495              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
3496              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
3497                                 gnus-summary-default-score 0)
3498              gnus-tmp-score-char
3499              (if (or (null gnus-summary-default-score)
3500                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3501                          gnus-summary-zcore-fuzz))
3502                  ? 
3503                (if (< gnus-tmp-score gnus-summary-default-score)
3504                    gnus-score-below-mark gnus-score-over-mark))
3505              gnus-tmp-replied
3506              (cond ((memq number gnus-newsgroup-processable)
3507                     gnus-process-mark)
3508                    ((memq number gnus-newsgroup-cached)
3509                     gnus-cached-mark)
3510                    ((memq number gnus-newsgroup-replied)
3511                     gnus-replied-mark)
3512                    ((memq number gnus-newsgroup-saved)
3513                     gnus-saved-mark)
3514                    (t gnus-unread-mark))
3515              gnus-tmp-from (mail-header-from gnus-tmp-header)
3516              gnus-tmp-name
3517              (cond
3518               ((string-match "<[^>]+> *$" gnus-tmp-from)
3519                (setq beg-match (match-beginning 0))
3520                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
3521                         (substring gnus-tmp-from (1+ (match-beginning 0))
3522                                    (1- (match-end 0))))
3523                    (substring gnus-tmp-from 0 beg-match)))
3524               ((string-match "(.+)" gnus-tmp-from)
3525                (substring gnus-tmp-from
3526                           (1+ (match-beginning 0)) (1- (match-end 0))))
3527               (t gnus-tmp-from)))
3528             (when (string= gnus-tmp-name "")
3529               (setq gnus-tmp-name gnus-tmp-from))
3530             (unless (numberp gnus-tmp-lines)
3531               (setq gnus-tmp-lines 0))
3532             (gnus-put-text-property
3533              (point)
3534              (progn (eval gnus-summary-line-format-spec) (point))
3535              'gnus-number number)
3536             (when gnus-visual-p
3537               (forward-line -1)
3538               (run-hooks 'gnus-summary-update-hook)
3539               (forward-line 1))
3540
3541             (setq gnus-tmp-prev-subject subject)))
3542
3543         (when (nth 1 thread)
3544           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
3545         (incf gnus-tmp-level)
3546         (setq threads (if thread-end nil (cdar thread)))
3547         (unless threads
3548           (setq gnus-tmp-level 0)))))
3549   (gnus-message 7 "Generating summary...done"))
3550
3551 (defun gnus-summary-prepare-unthreaded (headers)
3552   "Generate an unthreaded summary buffer based on HEADERS."
3553   (let (header number mark)
3554
3555     (beginning-of-line)
3556
3557     (while headers
3558       ;; We may have to root out some bad articles...
3559       (when (memq (setq number (mail-header-number
3560                                 (setq header (pop headers))))
3561                   gnus-newsgroup-limit)
3562         ;; Mark article as read when it has a low score.
3563         (when (and gnus-summary-mark-below
3564                    (< (or (cdr (assq number gnus-newsgroup-scored))
3565                           gnus-summary-default-score 0)
3566                       gnus-summary-mark-below)
3567                    (not (gnus-summary-article-ancient-p number)))
3568           (setq gnus-newsgroup-unreads
3569                 (delq number gnus-newsgroup-unreads))
3570           (if gnus-newsgroup-auto-expire
3571               (push number gnus-newsgroup-expirable)
3572             (push (cons number gnus-low-score-mark)
3573                   gnus-newsgroup-reads)))
3574
3575         (setq mark (gnus-article-mark number))
3576         (push (gnus-data-make number mark (1+ (point)) header 0)
3577               gnus-newsgroup-data)
3578         (gnus-summary-insert-line
3579          header 0 number
3580          mark (memq number gnus-newsgroup-replied)
3581          (memq number gnus-newsgroup-expirable)
3582          (mail-header-subject header) nil
3583          (cdr (assq number gnus-newsgroup-scored))
3584          (memq number gnus-newsgroup-processable))))))
3585
3586 (defun gnus-select-newsgroup (group &optional read-all)
3587   "Select newsgroup GROUP.
3588 If READ-ALL is non-nil, all articles in the group are selected."
3589   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
3590          ;;!!! Dirty hack; should be removed.
3591          (gnus-summary-ignore-duplicates
3592           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
3593               t
3594             gnus-summary-ignore-duplicates))
3595          (info (nth 2 entry))
3596          articles fetched-articles cached)
3597
3598     (unless (gnus-check-server
3599              (setq gnus-current-select-method
3600                    (gnus-find-method-for-group group)))
3601       (error "Couldn't open server"))
3602
3603     (or (and entry (not (eq (car entry) t))) ; Either it's active...
3604         (gnus-activate-group group)     ; Or we can activate it...
3605         (progn                          ; Or we bug out.
3606           (when (equal major-mode 'gnus-summary-mode)
3607             (kill-buffer (current-buffer)))
3608           (error "Couldn't request group %s: %s"
3609                  group (gnus-status-message group))))
3610
3611     (unless (gnus-request-group group t)
3612       (when (equal major-mode 'gnus-summary-mode)
3613         (kill-buffer (current-buffer)))
3614       (error "Couldn't request group %s: %s"
3615              group (gnus-status-message group)))
3616
3617     (setq gnus-newsgroup-name group)
3618     (setq gnus-newsgroup-unselected nil)
3619     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
3620
3621     ;; Adjust and set lists of article marks.
3622     (when info
3623       (gnus-adjust-marked-articles info))
3624
3625     ;; Kludge to avoid having cached articles nixed out in virtual groups.
3626     (when (gnus-virtual-group-p group)
3627       (setq cached gnus-newsgroup-cached))
3628
3629     (setq gnus-newsgroup-unreads
3630           (gnus-set-difference
3631            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
3632            gnus-newsgroup-dormant))
3633
3634     (setq gnus-newsgroup-processable nil)
3635
3636     (gnus-update-read-articles group gnus-newsgroup-unreads)
3637     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
3638       (gnus-group-update-group group))
3639
3640     (setq articles (gnus-articles-to-read group read-all))
3641
3642     (cond
3643      ((null articles)
3644       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
3645       'quit)
3646      ((eq articles 0) nil)
3647      (t
3648       ;; Init the dependencies hash table.
3649       (setq gnus-newsgroup-dependencies
3650             (gnus-make-hashtable (length articles)))
3651       ;; Retrieve the headers and read them in.
3652       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
3653       (setq gnus-newsgroup-headers
3654             (if (eq 'nov
3655                     (setq gnus-headers-retrieved-by
3656                           (gnus-retrieve-headers
3657                            articles gnus-newsgroup-name
3658                            ;; We might want to fetch old headers, but
3659                            ;; not if there is only 1 article.
3660                            (and gnus-fetch-old-headers
3661                                 (or (and
3662                                      (not (eq gnus-fetch-old-headers 'some))
3663                                      (not (numberp gnus-fetch-old-headers)))
3664                                     (> (length articles) 1))))))
3665                 (gnus-get-newsgroup-headers-xover
3666                  articles nil nil gnus-newsgroup-name t)
3667               (gnus-get-newsgroup-headers)))
3668       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
3669
3670       ;; Kludge to avoid having cached articles nixed out in virtual groups.
3671       (when cached
3672         (setq gnus-newsgroup-cached cached))
3673
3674       ;; Suppress duplicates?
3675       (when gnus-suppress-duplicates
3676         (gnus-dup-suppress-articles))
3677
3678       ;; Set the initial limit.
3679       (setq gnus-newsgroup-limit (copy-sequence articles))
3680       ;; Remove canceled articles from the list of unread articles.
3681       (setq gnus-newsgroup-unreads
3682             (gnus-set-sorted-intersection
3683              gnus-newsgroup-unreads
3684              (setq fetched-articles
3685                    (mapcar (lambda (headers) (mail-header-number headers))
3686                            gnus-newsgroup-headers))))
3687       ;; Removed marked articles that do not exist.
3688       (gnus-update-missing-marks
3689        (gnus-sorted-complement fetched-articles articles))
3690       ;; We might want to build some more threads first.
3691       (and gnus-fetch-old-headers
3692            (eq gnus-headers-retrieved-by 'nov)
3693            (gnus-build-old-threads))
3694       ;; Check whether auto-expire is to be done in this group.
3695       (setq gnus-newsgroup-auto-expire
3696             (gnus-group-auto-expirable-p group))
3697       ;; Set up the article buffer now, if necessary.
3698       (unless gnus-single-article-buffer
3699         (gnus-article-setup-buffer))
3700       ;; First and last article in this newsgroup.
3701       (when gnus-newsgroup-headers
3702         (setq gnus-newsgroup-begin
3703               (mail-header-number (car gnus-newsgroup-headers))
3704               gnus-newsgroup-end
3705               (mail-header-number
3706                (gnus-last-element gnus-newsgroup-headers))))
3707       ;; GROUP is successfully selected.
3708       (or gnus-newsgroup-headers t)))))
3709
3710 (defun gnus-articles-to-read (group &optional read-all)
3711   ;; Find out what articles the user wants to read.
3712   (let* ((articles
3713           ;; Select all articles if `read-all' is non-nil, or if there
3714           ;; are no unread articles.
3715           (if (or read-all
3716                   (and (zerop (length gnus-newsgroup-marked))
3717                        (zerop (length gnus-newsgroup-unreads)))
3718                   (eq (gnus-group-find-parameter group 'display)
3719                       'all))
3720               (gnus-uncompress-range (gnus-active group))
3721             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
3722                           (copy-sequence gnus-newsgroup-unreads))
3723                   '<)))
3724          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
3725          (scored (length scored-list))
3726          (number (length articles))
3727          (marked (+ (length gnus-newsgroup-marked)
3728                     (length gnus-newsgroup-dormant)))
3729          (select
3730           (cond
3731            ((numberp read-all)
3732             read-all)
3733            (t
3734             (condition-case ()
3735                 (cond
3736                  ((and (or (<= scored marked) (= scored number))
3737                        (numberp gnus-large-newsgroup)
3738                        (> number gnus-large-newsgroup))
3739                   (let ((input
3740                          (read-string
3741                           (format
3742                            "How many articles from %s (default %d): "
3743                            (gnus-limit-string gnus-newsgroup-name 35)
3744                            number))))
3745                     (if (string-match "^[ \t]*$" input) number input)))
3746                  ((and (> scored marked) (< scored number)
3747                        (> (- scored number) 20))
3748                   (let ((input
3749                          (read-string
3750                           (format "%s %s (%d scored, %d total): "
3751                                   "How many articles from"
3752                                   group scored number))))
3753                     (if (string-match "^[ \t]*$" input)
3754                         number input)))
3755                  (t number))
3756               (quit nil))))))
3757     (setq select (if (stringp select) (string-to-number select) select))
3758     (if (or (null select) (zerop select))
3759         select
3760       (if (and (not (zerop scored)) (<= (abs select) scored))
3761           (progn
3762             (setq articles (sort scored-list '<))
3763             (setq number (length articles)))
3764         (setq articles (copy-sequence articles)))
3765
3766       (when (< (abs select) number)
3767         (if (< select 0)
3768             ;; Select the N oldest articles.
3769             (setcdr (nthcdr (1- (abs select)) articles) nil)
3770           ;; Select the N most recent articles.
3771           (setq articles (nthcdr (- number select) articles))))
3772       (setq gnus-newsgroup-unselected
3773             (gnus-sorted-intersection
3774              gnus-newsgroup-unreads
3775              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
3776       articles)))
3777
3778 (defun gnus-killed-articles (killed articles)
3779   (let (out)
3780     (while articles
3781       (when (inline (gnus-member-of-range (car articles) killed))
3782         (push (car articles) out))
3783       (setq articles (cdr articles)))
3784     out))
3785
3786 (defun gnus-uncompress-marks (marks)
3787   "Uncompress the mark ranges in MARKS."
3788   (let ((uncompressed '(score bookmark))
3789         out)
3790     (while marks
3791       (if (memq (caar marks) uncompressed)
3792           (push (car marks) out)
3793         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
3794       (setq marks (cdr marks)))
3795     out))
3796
3797 (defun gnus-adjust-marked-articles (info)
3798   "Set all article lists and remove all marks that are no longer legal."
3799   (let* ((marked-lists (gnus-info-marks info))
3800          (active (gnus-active (gnus-info-group info)))
3801          (min (car active))
3802          (max (cdr active))
3803          (types gnus-article-mark-lists)
3804          (uncompressed '(score bookmark killed))
3805          marks var articles article mark)
3806
3807     (while marked-lists
3808       (setq marks (pop marked-lists))
3809       (set (setq var (intern (format "gnus-newsgroup-%s"
3810                                      (car (rassq (setq mark (car marks))
3811                                                  types)))))
3812            (if (memq (car marks) uncompressed) (cdr marks)
3813              (gnus-uncompress-range (cdr marks))))
3814
3815       (setq articles (symbol-value var))
3816
3817       ;; All articles have to be subsets of the active articles.
3818       (cond
3819        ;; Adjust "simple" lists.
3820        ((memq mark '(tick dormant expirable reply save))
3821         (while articles
3822           (when (or (< (setq article (pop articles)) min) (> article max))
3823             (set var (delq article (symbol-value var))))))
3824        ;; Adjust assocs.
3825        ((memq mark uncompressed)
3826         (while articles
3827           (when (or (not (consp (setq article (pop articles))))
3828                     (< (car article) min)
3829                     (> (car article) max))
3830             (set var (delq article (symbol-value var))))))))))
3831
3832 (defun gnus-update-missing-marks (missing)
3833   "Go through the list of MISSING articles and remove them mark lists."
3834   (when missing
3835     (let ((types gnus-article-mark-lists)
3836           var m)
3837       ;; Go through all types.
3838       (while types
3839         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
3840         (when (symbol-value var)
3841           ;; This list has articles.  So we delete all missing articles
3842           ;; from it.
3843           (setq m missing)
3844           (while m
3845             (set var (delq (pop m) (symbol-value var)))))))))
3846
3847 (defun gnus-update-marks ()
3848   "Enter the various lists of marked articles into the newsgroup info list."
3849   (let ((types gnus-article-mark-lists)
3850         (info (gnus-get-info gnus-newsgroup-name))
3851         (uncompressed '(score bookmark killed))
3852         type list newmarked symbol)
3853     (when info
3854       ;; Add all marks lists that are non-nil to the list of marks lists.
3855       (while (setq type (pop types))
3856         (when (setq list (symbol-value
3857                           (setq symbol
3858                                 (intern (format "gnus-newsgroup-%s"
3859                                                 (car type))))))
3860
3861           ;; Get rid of the entries of the articles that have the
3862           ;; default score.
3863           (when (and (eq (cdr type) 'score)
3864                      gnus-save-score
3865                      list)
3866             (let* ((arts list)
3867                    (prev (cons nil list))
3868                    (all prev))
3869               (while arts
3870                 (if (or (not (consp (car arts)))
3871                         (= (cdar arts) gnus-summary-default-score))
3872                     (setcdr prev (cdr arts))
3873                   (setq prev arts))
3874                 (setq arts (cdr arts)))
3875               (setq list (cdr all))))
3876
3877           (push (cons (cdr type)
3878                       (if (memq (cdr type) uncompressed) list
3879                         (gnus-compress-sequence
3880                          (set symbol (sort list '<)) t)))
3881                 newmarked)))
3882
3883       ;; Enter these new marks into the info of the group.
3884       (if (nthcdr 3 info)
3885           (setcar (nthcdr 3 info) newmarked)
3886         ;; Add the marks lists to the end of the info.
3887         (when newmarked
3888           (setcdr (nthcdr 2 info) (list newmarked))))
3889
3890       ;; Cut off the end of the info if there's nothing else there.
3891       (let ((i 5))
3892         (while (and (> i 2)
3893                     (not (nth i info)))
3894           (when (nthcdr (decf i) info)
3895             (setcdr (nthcdr i info) nil)))))))
3896
3897 (defun gnus-set-mode-line (where)
3898   "This function sets the mode line of the article or summary buffers.
3899 If WHERE is `summary', the summary mode line format will be used."
3900   ;; Is this mode line one we keep updated?
3901   (when (memq where gnus-updated-mode-lines)
3902     (let (mode-string)
3903       (save-excursion
3904         ;; We evaluate this in the summary buffer since these
3905         ;; variables are buffer-local to that buffer.
3906         (set-buffer gnus-summary-buffer)
3907         ;; We bind all these variables that are used in the `eval' form
3908         ;; below.
3909         (let* ((mformat (symbol-value
3910                          (intern
3911                           (format "gnus-%s-mode-line-format-spec" where))))
3912                (gnus-tmp-group-name gnus-newsgroup-name)
3913                (gnus-tmp-article-number (or gnus-current-article 0))
3914                (gnus-tmp-unread gnus-newsgroup-unreads)
3915                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
3916                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
3917                (gnus-tmp-unread-and-unselected
3918                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
3919                             (zerop gnus-tmp-unselected))
3920                        "")
3921                       ((zerop gnus-tmp-unselected)
3922                        (format "{%d more}" gnus-tmp-unread-and-unticked))
3923                       (t (format "{%d(+%d) more}"
3924                                  gnus-tmp-unread-and-unticked
3925                                  gnus-tmp-unselected))))
3926                (gnus-tmp-subject
3927                 (if (and gnus-current-headers
3928                          (vectorp gnus-current-headers))
3929                     (gnus-mode-string-quote
3930                      (mail-header-subject gnus-current-headers))
3931                   ""))
3932                bufname-length max-len
3933                gnus-tmp-header);; passed as argument to any user-format-funcs
3934           (setq mode-string (eval mformat))
3935           (setq bufname-length (if (string-match "%b" mode-string)
3936                                    (- (length
3937                                        (buffer-name
3938                                         (if (eq where 'summary)
3939                                             nil
3940                                           (get-buffer gnus-article-buffer))))
3941                                       2)
3942                                  0))
3943           (setq max-len (max 4 (if gnus-mode-non-string-length
3944                                    (- (window-width)
3945                                       gnus-mode-non-string-length
3946                                       bufname-length)
3947                                  (length mode-string))))
3948           ;; We might have to chop a bit of the string off...
3949           (when (> (length mode-string) max-len)
3950             (setq mode-string
3951                   (concat (gnus-truncate-string mode-string (- max-len 3))
3952                           "...")))
3953           ;; Pad the mode string a bit.
3954           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
3955       ;; Update the mode line.
3956       (setq mode-line-buffer-identification
3957             (gnus-mode-line-buffer-identification (list mode-string)))
3958       (set-buffer-modified-p t))))
3959
3960 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
3961   "Go through the HEADERS list and add all Xrefs to a hash table.
3962 The resulting hash table is returned, or nil if no Xrefs were found."
3963   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
3964          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
3965          (xref-hashtb (gnus-make-hashtable))
3966          start group entry number xrefs header)
3967     (while headers
3968       (setq header (pop headers))
3969       (when (and (setq xrefs (mail-header-xref header))
3970                  (not (memq (setq number (mail-header-number header))
3971                             unreads)))
3972         (setq start 0)
3973         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
3974           (setq start (match-end 0))
3975           (setq group (if prefix
3976                           (concat prefix (substring xrefs (match-beginning 1)
3977                                                     (match-end 1)))
3978                         (substring xrefs (match-beginning 1) (match-end 1))))
3979           (setq number
3980                 (string-to-int (substring xrefs (match-beginning 2)
3981                                           (match-end 2))))
3982           (if (setq entry (gnus-gethash group xref-hashtb))
3983               (setcdr entry (cons number (cdr entry)))
3984             (gnus-sethash group (cons number nil) xref-hashtb)))))
3985     (and start xref-hashtb)))
3986
3987 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
3988   "Look through all the headers and mark the Xrefs as read."
3989   (let ((virtual (gnus-virtual-group-p from-newsgroup))
3990         name entry info xref-hashtb idlist method nth4)
3991     (save-excursion
3992       (set-buffer gnus-group-buffer)
3993       (when (setq xref-hashtb
3994                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
3995         (mapatoms
3996          (lambda (group)
3997            (unless (string= from-newsgroup (setq name (symbol-name group)))
3998              (setq idlist (symbol-value group))
3999              ;; Dead groups are not updated.
4000              (and (prog1
4001                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4002                             info (nth 2 entry))
4003                     (when (stringp (setq nth4 (gnus-info-method info)))
4004                       (setq nth4 (gnus-server-to-method nth4))))
4005                   ;; Only do the xrefs if the group has the same
4006                   ;; select method as the group we have just read.
4007                   (or (gnus-methods-equal-p
4008                        nth4 (gnus-find-method-for-group from-newsgroup))
4009                       virtual
4010                       (equal nth4 (setq method (gnus-find-method-for-group
4011                                                 from-newsgroup)))
4012                       (and (equal (car nth4) (car method))
4013                            (equal (nth 1 nth4) (nth 1 method))))
4014                   gnus-use-cross-reference
4015                   (or (not (eq gnus-use-cross-reference t))
4016                       virtual
4017                       ;; Only do cross-references on subscribed
4018                       ;; groups, if that is what is wanted.
4019                       (<= (gnus-info-level info) gnus-level-subscribed))
4020                   (gnus-group-make-articles-read name idlist))))
4021          xref-hashtb)))))
4022
4023 (defun gnus-group-make-articles-read (group articles)
4024   "Update the info of GROUP to say that ARTICLES are read."
4025   (let* ((num 0)
4026          (entry (gnus-gethash group gnus-newsrc-hashtb))
4027          (info (nth 2 entry))
4028          (active (gnus-active group))
4029          range)
4030     ;; First peel off all illegal article numbers.
4031     (when active
4032       (let ((ids articles)
4033             id first)
4034         (while (setq id (pop ids))
4035           (when (and first (> id (cdr active)))
4036             ;; We'll end up in this situation in one particular
4037             ;; obscure situation.  If you re-scan a group and get
4038             ;; a new article that is cross-posted to a different
4039             ;; group that has not been re-scanned, you might get
4040             ;; crossposted article that has a higher number than
4041             ;; Gnus believes possible.  So we re-activate this
4042             ;; group as well.  This might mean doing the
4043             ;; crossposting thingy will *increase* the number
4044             ;; of articles in some groups.  Tsk, tsk.
4045             (setq active (or (gnus-activate-group group) active)))
4046           (when (or (> id (cdr active))
4047                     (< id (car active)))
4048             (setq articles (delq id articles))))))
4049     (save-excursion
4050       (set-buffer gnus-group-buffer)
4051       (gnus-undo-register
4052         `(progn
4053            (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4054            (gnus-info-set-read ',info ',(gnus-info-read info))
4055            (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4056            (gnus-group-update-group ,group t))))
4057     ;; If the read list is nil, we init it.
4058     (and active
4059          (null (gnus-info-read info))
4060          (> (car active) 1)
4061          (gnus-info-set-read info (cons 1 (1- (car active)))))
4062     ;; Then we add the read articles to the range.
4063     (gnus-info-set-read
4064      info
4065      (setq range
4066            (gnus-add-to-range
4067             (gnus-info-read info) (setq articles (sort articles '<)))))
4068     ;; Then we have to re-compute how many unread
4069     ;; articles there are in this group.
4070     (when active
4071       (cond
4072        ((not range)
4073         (setq num (- (1+ (cdr active)) (car active))))
4074        ((not (listp (cdr range)))
4075         (setq num (- (cdr active) (- (1+ (cdr range))
4076                                      (car range)))))
4077        (t
4078         (while range
4079           (if (numberp (car range))
4080               (setq num (1+ num))
4081             (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4082           (setq range (cdr range)))
4083         (setq num (- (cdr active) num))))
4084       ;; Update the number of unread articles.
4085       (setcar entry num)
4086       ;; Update the group buffer.
4087       (gnus-group-update-group group t))))
4088
4089 (defun gnus-methods-equal-p (m1 m2)
4090   (let ((m1 (or m1 gnus-select-method))
4091         (m2 (or m2 gnus-select-method)))
4092     (or (equal m1 m2)
4093         (and (eq (car m1) (car m2))
4094              (or (not (memq 'address (assoc (symbol-name (car m1))
4095                                             gnus-valid-select-methods)))
4096                  (equal (nth 1 m1) (nth 1 m2)))))))
4097
4098 (defvar gnus-newsgroup-none-id 0)
4099
4100 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4101   (let ((cur nntp-server-buffer)
4102         (dependencies
4103          (or dependencies
4104              (save-excursion (set-buffer gnus-summary-buffer)
4105                              gnus-newsgroup-dependencies)))
4106         headers id id-dep ref-dep end ref)
4107     (save-excursion
4108       (set-buffer nntp-server-buffer)
4109       ;; Translate all TAB characters into SPACE characters.
4110       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4111       (run-hooks 'gnus-parse-headers-hook)
4112       (let ((case-fold-search t)
4113             in-reply-to header p lines)
4114         (goto-char (point-min))
4115         ;; Search to the beginning of the next header.  Error messages
4116         ;; do not begin with 2 or 3.
4117         (while (re-search-forward "^[23][0-9]+ " nil t)
4118           (setq id nil
4119                 ref nil)
4120           ;; This implementation of this function, with nine
4121           ;; search-forwards instead of the one re-search-forward and
4122           ;; a case (which basically was the old function) is actually
4123           ;; about twice as fast, even though it looks messier.  You
4124           ;; can't have everything, I guess.  Speed and elegance
4125           ;; doesn't always go hand in hand.
4126           (setq
4127            header
4128            (vector
4129             ;; Number.
4130             (prog1
4131                 (read cur)
4132               (end-of-line)
4133               (setq p (point))
4134               (narrow-to-region (point)
4135                                 (or (and (search-forward "\n.\n" nil t)
4136                                          (- (point) 2))
4137                                     (point))))
4138             ;; Subject.
4139             (progn
4140               (goto-char p)
4141               (if (search-forward "\nsubject: " nil t)
4142                   (nnheader-header-value) "(none)"))
4143             ;; From.
4144             (progn
4145               (goto-char p)
4146               (if (search-forward "\nfrom: " nil t)
4147                   (nnheader-header-value) "(nobody)"))
4148             ;; Date.
4149             (progn
4150               (goto-char p)
4151               (if (search-forward "\ndate: " nil t)
4152                   (nnheader-header-value) ""))
4153             ;; Message-ID.
4154             (progn
4155               (goto-char p)
4156               (setq id (if (search-forward "\nmessage-id:" nil t)
4157                            (buffer-substring
4158                             (1- (or (search-forward "<" nil t) (point)))
4159                             (or (search-forward ">" nil t) (point)))
4160                          ;; If there was no message-id, we just fake one
4161                          ;; to make subsequent routines simpler.
4162                          (nnheader-generate-fake-message-id))))
4163             ;; References.
4164             (progn
4165               (goto-char p)
4166               (if (search-forward "\nreferences: " nil t)
4167                   (progn
4168                     (setq end (point))
4169                     (prog1
4170                         (nnheader-header-value)
4171                       (setq ref
4172                             (buffer-substring
4173                              (progn
4174                                (end-of-line)
4175                                (search-backward ">" end t)
4176                                (1+ (point)))
4177                              (progn
4178                                (search-backward "<" end t)
4179                                (point))))))
4180                 ;; Get the references from the in-reply-to header if there
4181                 ;; were no references and the in-reply-to header looks
4182                 ;; promising.
4183                 (if (and (search-forward "\nin-reply-to: " nil t)
4184                          (setq in-reply-to (nnheader-header-value))
4185                          (string-match "<[^>]+>" in-reply-to))
4186                     (setq ref (substring in-reply-to (match-beginning 0)
4187                                          (match-end 0)))
4188                   (setq ref nil))))
4189             ;; Chars.
4190             0
4191             ;; Lines.
4192             (progn
4193               (goto-char p)
4194               (if (search-forward "\nlines: " nil t)
4195                   (if (numberp (setq lines (read cur)))
4196                       lines 0)
4197                 0))
4198             ;; Xref.
4199             (progn
4200               (goto-char p)
4201               (and (search-forward "\nxref: " nil t)
4202                    (nnheader-header-value)))))
4203           (when (equal id ref)
4204             (setq ref nil))
4205           ;; We do the threading while we read the headers.  The
4206           ;; message-id and the last reference are both entered into
4207           ;; the same hash table.  Some tippy-toeing around has to be
4208           ;; done in case an article has arrived before the article
4209           ;; which it refers to.
4210           (if (boundp (setq id-dep (intern id dependencies)))
4211               (if (and (car (symbol-value id-dep))
4212                        (not force-new))
4213                   ;; An article with this Message-ID has already been seen.
4214                   (if gnus-summary-ignore-duplicates
4215                       ;; We ignore this one, except we add
4216                       ;; any additional Xrefs (in case the two articles
4217                       ;; came from different servers).
4218                       (progn
4219                         (mail-header-set-xref
4220                          (car (symbol-value id-dep))
4221                          (concat (or (mail-header-xref
4222                                       (car (symbol-value id-dep)))
4223                                      "")
4224                                  (or (mail-header-xref header) "")))
4225                         (setq header nil))
4226                     ;; We rename the Message-ID.
4227                     (set
4228                      (setq id-dep (intern (setq id (nnmail-message-id))
4229                                           dependencies))
4230                      (list header))
4231                     (mail-header-set-id header id))
4232                 (setcar (symbol-value id-dep) header))
4233             (set id-dep (list header)))
4234           (when  header
4235             (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
4236                 (setcdr (symbol-value ref-dep)
4237                         (nconc (cdr (symbol-value ref-dep))
4238                                (list (symbol-value id-dep))))
4239               (set ref-dep (list nil (symbol-value id-dep))))
4240             (push header headers))
4241           (goto-char (point-max))
4242           (widen))
4243         (nreverse headers)))))
4244
4245 ;; The following macros and functions were written by Felix Lee
4246 ;; <flee@cse.psu.edu>.
4247
4248 (defmacro gnus-nov-read-integer ()
4249   '(prog1
4250        (if (= (following-char) ?\t)
4251            0
4252          (let ((num (ignore-errors (read buffer))))
4253            (if (numberp num) num 0)))
4254      (unless (eobp)
4255        (forward-char 1))))
4256
4257 (defmacro gnus-nov-skip-field ()
4258   '(search-forward "\t" eol 'move))
4259
4260 (defmacro gnus-nov-field ()
4261   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
4262
4263 ;; (defvar gnus-nov-none-counter 0)
4264
4265 ;; This function has to be called with point after the article number
4266 ;; on the beginning of the line.
4267 (defun gnus-nov-parse-line (number dependencies &optional force-new)
4268   (let ((eol (gnus-point-at-eol))
4269         (buffer (current-buffer))
4270         header ref id id-dep ref-dep)
4271
4272     ;; overview: [num subject from date id refs chars lines misc]
4273     (unwind-protect
4274         (progn
4275           (narrow-to-region (point) eol)
4276           (unless (eobp)
4277             (forward-char))
4278
4279           (setq header
4280                 (vector
4281                  number                 ; number
4282                  (gnus-nov-field)       ; subject
4283                  (gnus-nov-field)       ; from
4284                  (gnus-nov-field)       ; date
4285                  (setq id (or (gnus-nov-field)
4286                               (nnheader-generate-fake-message-id))) ; id
4287                  (progn
4288                    (let ((beg (point)))
4289                      (search-forward "\t" eol)
4290                      (if (search-backward ">" beg t)
4291                          (setq ref
4292                                (buffer-substring
4293                                 (1+ (point))
4294                                 (search-backward "<" beg t)))
4295                        (setq ref nil))
4296                      (goto-char beg))
4297                    (gnus-nov-field))    ; refs
4298                  (gnus-nov-read-integer) ; chars
4299                  (gnus-nov-read-integer) ; lines
4300                  (if (= (following-char) ?\n)
4301                      nil
4302                    (gnus-nov-field))))) ; misc
4303
4304       (widen))
4305
4306     ;; We build the thread tree.
4307     (when (equal id ref)
4308       ;; This article refers back to itself.  Naughty, naughty.
4309       (setq ref nil))
4310     (if (boundp (setq id-dep (intern id dependencies)))
4311         (if (and (car (symbol-value id-dep))
4312                  (not force-new))
4313             ;; An article with this Message-ID has already been seen.
4314             (if gnus-summary-ignore-duplicates
4315                 ;; We ignore this one, except we add any additional
4316                 ;; Xrefs (in case the two articles came from different
4317                 ;; servers.
4318                 (progn
4319                   (mail-header-set-xref
4320                    (car (symbol-value id-dep))
4321                    (concat (or (mail-header-xref
4322                                 (car (symbol-value id-dep)))
4323                                "")
4324                            (or (mail-header-xref header) "")))
4325                   (setq header nil))
4326               ;; We rename the Message-ID.
4327               (set
4328                (setq id-dep (intern (setq id (nnmail-message-id))
4329                                     dependencies))
4330                (list header))
4331               (mail-header-set-id header id))
4332           (setcar (symbol-value id-dep) header))
4333       (set id-dep (list header)))
4334     (when header
4335       (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
4336           (setcdr (symbol-value ref-dep)
4337                   (nconc (cdr (symbol-value ref-dep))
4338                          (list (symbol-value id-dep))))
4339         (set ref-dep (list nil (symbol-value id-dep)))))
4340     header))
4341
4342 ;; Goes through the xover lines and returns a list of vectors
4343 (defun gnus-get-newsgroup-headers-xover (sequence &optional
4344                                                   force-new dependencies
4345                                                   group also-fetch-heads)
4346   "Parse the news overview data in the server buffer, and return a
4347 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4348   ;; Get the Xref when the users reads the articles since most/some
4349   ;; NNTP servers do not include Xrefs when using XOVER.
4350   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4351   (let ((cur nntp-server-buffer)
4352         (dependencies (or dependencies gnus-newsgroup-dependencies))
4353         number headers header)
4354     (save-excursion
4355       (set-buffer nntp-server-buffer)
4356       ;; Allow the user to mangle the headers before parsing them.
4357       (run-hooks 'gnus-parse-headers-hook)
4358       (goto-char (point-min))
4359       (while (not (eobp))
4360         (condition-case ()
4361             (while (and sequence (not (eobp)))
4362               (setq number (read cur))
4363               (while (and sequence
4364                           (< (car sequence) number))
4365                 (setq sequence (cdr sequence)))
4366               (and sequence
4367                    (eq number (car sequence))
4368                    (progn
4369                      (setq sequence (cdr sequence))
4370                      (setq header (inline
4371                                     (gnus-nov-parse-line
4372                                      number dependencies force-new))))
4373                    (push header headers))
4374               (forward-line 1))
4375           (error
4376            (gnus-error 4 "Strange nov line (%d)"
4377                        (count-lines (point-min) (point)))))
4378         (forward-line 1))
4379       ;; A common bug in inn is that if you have posted an article and
4380       ;; then retrieves the active file, it will answer correctly --
4381       ;; the new article is included.  However, a NOV entry for the
4382       ;; article may not have been generated yet, so this may fail.
4383       ;; We work around this problem by retrieving the last few
4384       ;; headers using HEAD.
4385       (if (or (not also-fetch-heads)
4386               (not sequence))
4387           ;; We (probably) got all the headers.
4388           (nreverse headers)
4389         (let ((gnus-nov-is-evil t))
4390           (nconc
4391            (nreverse headers)
4392            (when (gnus-retrieve-headers sequence group)
4393              (gnus-get-newsgroup-headers))))))))
4394
4395 (defun gnus-article-get-xrefs ()
4396   "Fill in the Xref value in `gnus-current-headers', if necessary.
4397 This is meant to be called in `gnus-article-internal-prepare-hook'."
4398   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4399                                  gnus-current-headers)))
4400     (or (not gnus-use-cross-reference)
4401         (not headers)
4402         (and (mail-header-xref headers)
4403              (not (string= (mail-header-xref headers) "")))
4404         (let ((case-fold-search t)
4405               xref)
4406           (save-restriction
4407             (nnheader-narrow-to-headers)
4408             (goto-char (point-min))
4409             (when (or (and (eq (downcase (following-char)) ?x)
4410                            (looking-at "Xref:"))
4411                       (search-forward "\nXref:" nil t))
4412               (goto-char (1+ (match-end 0)))
4413               (setq xref (buffer-substring (point)
4414                                            (progn (end-of-line) (point))))
4415               (mail-header-set-xref headers xref)))))))
4416
4417 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4418   "Find article ID and insert the summary line for that article."
4419   (let ((header (if (and old-header use-old-header)
4420                     old-header (gnus-read-header id)))
4421         (number (and (numberp id) id))
4422         pos d)
4423     (when header
4424       ;; Rebuild the thread that this article is part of and go to the
4425       ;; article we have fetched.
4426       (when (and (not gnus-show-threads)
4427                  old-header)
4428         (when (setq d (gnus-data-find (mail-header-number old-header)))
4429           (goto-char (gnus-data-pos d))
4430           (gnus-data-remove
4431            number
4432            (- (gnus-point-at-bol)
4433               (prog1
4434                   (1+ (gnus-point-at-eol))
4435                 (gnus-delete-line))))))
4436       (when old-header
4437         (mail-header-set-number header (mail-header-number old-header)))
4438       (setq gnus-newsgroup-sparse
4439             (delq (setq number (mail-header-number header))
4440                   gnus-newsgroup-sparse))
4441       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4442       (gnus-rebuild-thread (mail-header-id header))
4443       (gnus-summary-goto-subject number nil t))
4444     (when (and (numberp number)
4445                (> number 0))
4446       ;; We have to update the boundaries even if we can't fetch the
4447       ;; article if ID is a number -- so that the next `P' or `N'
4448       ;; command will fetch the previous (or next) article even
4449       ;; if the one we tried to fetch this time has been canceled.
4450       (when (> number gnus-newsgroup-end)
4451         (setq gnus-newsgroup-end number))
4452       (when (< number gnus-newsgroup-begin)
4453         (setq gnus-newsgroup-begin number))
4454       (setq gnus-newsgroup-unselected
4455             (delq number gnus-newsgroup-unselected)))
4456     ;; Report back a success?
4457     (and header (mail-header-number header))))
4458
4459 ;;; Process/prefix in the summary buffer
4460
4461 (defun gnus-summary-work-articles (n)
4462   "Return a list of articles to be worked upon.  The prefix argument,
4463 the list of process marked articles, and the current article will be
4464 taken into consideration."
4465   (cond
4466    (n
4467     ;; A numerical prefix has been given.
4468     (setq n (prefix-numeric-value n))
4469     (let ((backward (< n 0))
4470           (n (abs (prefix-numeric-value n)))
4471           articles article)
4472       (save-excursion
4473         (while
4474             (and (> n 0)
4475                  (push (setq article (gnus-summary-article-number))
4476                        articles)
4477                  (if backward
4478                      (gnus-summary-find-prev nil article)
4479                    (gnus-summary-find-next nil article)))
4480           (decf n)))
4481       (nreverse articles)))
4482    ((gnus-region-active-p)
4483     ;; Work on the region between point and mark.
4484     (let ((max (max (point) (mark)))
4485           articles article)
4486       (save-excursion
4487         (goto-char (min (point) (mark)))
4488         (while
4489             (and
4490              (push (setq article (gnus-summary-article-number)) articles)
4491              (gnus-summary-find-next nil article)
4492              (< (point) max)))
4493         (nreverse articles))))
4494    (gnus-newsgroup-processable
4495     ;; There are process-marked articles present.
4496     ;; Save current state.
4497     (gnus-summary-save-process-mark)
4498     ;; Return the list.
4499     (reverse gnus-newsgroup-processable))
4500    (t
4501     ;; Just return the current article.
4502     (list (gnus-summary-article-number)))))
4503
4504 (defun gnus-summary-save-process-mark ()
4505   "Push the current set of process marked articles on the stack."
4506   (interactive)
4507   (push (copy-sequence gnus-newsgroup-processable)
4508         gnus-newsgroup-process-stack))
4509
4510 (defun gnus-summary-kill-process-mark ()
4511   "Push the current set of process marked articles on the stack and unmark."
4512   (interactive)
4513   (gnus-summary-save-process-mark)
4514   (gnus-summary-unmark-all-processable))
4515
4516 (defun gnus-summary-yank-process-mark ()
4517   "Pop the last process mark state off the stack and restore it."
4518   (interactive)
4519   (unless gnus-newsgroup-process-stack
4520     (error "Empty mark stack"))
4521   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4522
4523 (defun gnus-summary-process-mark-set (set)
4524   "Make SET into the current process marked articles."
4525   (gnus-summary-unmark-all-processable)
4526   (while set
4527     (gnus-summary-set-process-mark (pop set))))
4528
4529 ;;; Searching and stuff
4530
4531 (defun gnus-summary-search-group (&optional backward use-level)
4532   "Search for next unread newsgroup.
4533 If optional argument BACKWARD is non-nil, search backward instead."
4534   (save-excursion
4535     (set-buffer gnus-group-buffer)
4536     (when (gnus-group-search-forward
4537            backward nil (if use-level (gnus-group-group-level) nil))
4538       (gnus-group-group-name))))
4539
4540 (defun gnus-summary-best-group (&optional exclude-group)
4541   "Find the name of the best unread group.
4542 If EXCLUDE-GROUP, do not go to this group."
4543   (save-excursion
4544     (set-buffer gnus-group-buffer)
4545     (save-excursion
4546       (gnus-group-best-unread-group exclude-group))))
4547
4548 (defun gnus-summary-find-next (&optional unread article backward)
4549   (if backward (gnus-summary-find-prev)
4550     (let* ((dummy (gnus-summary-article-intangible-p))
4551            (article (or article (gnus-summary-article-number)))
4552            (arts (gnus-data-find-list article))
4553            result)
4554       (when (and (not dummy)
4555                  (or (not gnus-summary-check-current)
4556                      (not unread)
4557                      (not (gnus-data-unread-p (car arts)))))
4558         (setq arts (cdr arts)))
4559       (when (setq result
4560                   (if unread
4561                       (progn
4562                         (while arts
4563                           (when (gnus-data-unread-p (car arts))
4564                             (setq result (car arts)
4565                                   arts nil))
4566                           (setq arts (cdr arts)))
4567                         result)
4568                     (car arts)))
4569         (goto-char (gnus-data-pos result))
4570         (gnus-data-number result)))))
4571
4572 (defun gnus-summary-find-prev (&optional unread article)
4573   (let* ((eobp (eobp))
4574          (article (or article (gnus-summary-article-number)))
4575          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
4576          result)
4577     (when (and (not eobp)
4578                (or (not gnus-summary-check-current)
4579                    (not unread)
4580                    (not (gnus-data-unread-p (car arts)))))
4581       (setq arts (cdr arts)))
4582     (when (setq result
4583                 (if unread
4584                     (progn
4585                       (while arts
4586                         (when (gnus-data-unread-p (car arts))
4587                           (setq result (car arts)
4588                                 arts nil))
4589                         (setq arts (cdr arts)))
4590                       result)
4591                   (car arts)))
4592       (goto-char (gnus-data-pos result))
4593       (gnus-data-number result))))
4594
4595 (defun gnus-summary-find-subject (subject &optional unread backward article)
4596   (let* ((simp-subject (gnus-simplify-subject-fully subject))
4597          (article (or article (gnus-summary-article-number)))
4598          (articles (gnus-data-list backward))
4599          (arts (gnus-data-find-list article articles))
4600          result)
4601     (when (or (not gnus-summary-check-current)
4602               (not unread)
4603               (not (gnus-data-unread-p (car arts))))
4604       (setq arts (cdr arts)))
4605     (while arts
4606       (and (or (not unread)
4607                (gnus-data-unread-p (car arts)))
4608            (vectorp (gnus-data-header (car arts)))
4609            (gnus-subject-equal
4610             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
4611            (setq result (car arts)
4612                  arts nil))
4613       (setq arts (cdr arts)))
4614     (and result
4615          (goto-char (gnus-data-pos result))
4616          (gnus-data-number result))))
4617
4618 (defun gnus-summary-search-forward (&optional unread subject backward)
4619   "Search forward for an article.
4620 If UNREAD, look for unread articles.  If SUBJECT, look for
4621 articles with that subject.  If BACKWARD, search backward instead."
4622   (cond (subject (gnus-summary-find-subject subject unread backward))
4623         (backward (gnus-summary-find-prev unread))
4624         (t (gnus-summary-find-next unread))))
4625
4626 (defun gnus-recenter (&optional n)
4627   "Center point in window and redisplay frame.
4628 Also do horizontal recentering."
4629   (interactive "P")
4630   (when (and gnus-auto-center-summary
4631              (not (eq gnus-auto-center-summary 'vertical)))
4632     (gnus-horizontal-recenter))
4633   (recenter n))
4634
4635 (defun gnus-summary-recenter ()
4636   "Center point in the summary window.
4637 If `gnus-auto-center-summary' is nil, or the article buffer isn't
4638 displayed, no centering will be performed."
4639   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
4640   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
4641   (let* ((top (cond ((< (window-height) 4) 0)
4642                     ((< (window-height) 7) 1)
4643                     (t 2)))
4644          (height (1- (window-height)))
4645          (bottom (save-excursion (goto-char (point-max))
4646                                  (forward-line (- height))
4647                                  (point)))
4648          (window (get-buffer-window (current-buffer))))
4649     ;; The user has to want it.
4650     (when gnus-auto-center-summary
4651       (when (get-buffer-window gnus-article-buffer)
4652         ;; Only do recentering when the article buffer is displayed,
4653         ;; Set the window start to either `bottom', which is the biggest
4654         ;; possible valid number, or the second line from the top,
4655         ;; whichever is the least.
4656         (set-window-start
4657          window (min bottom (save-excursion
4658                               (forward-line (- top)) (point)))))
4659       ;; Do horizontal recentering while we're at it.
4660       (when (and (get-buffer-window (current-buffer) t)
4661                  (not (eq gnus-auto-center-summary 'vertical)))
4662         (let ((selected (selected-window)))
4663           (select-window (get-buffer-window (current-buffer) t))
4664           (gnus-summary-position-point)
4665           (gnus-horizontal-recenter)
4666           (select-window selected))))))
4667
4668 (defun gnus-summary-jump-to-group (newsgroup)
4669   "Move point to NEWSGROUP in group mode buffer."
4670   ;; Keep update point of group mode buffer if visible.
4671   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
4672       (save-window-excursion
4673         ;; Take care of tree window mode.
4674         (when (get-buffer-window gnus-group-buffer)
4675           (pop-to-buffer gnus-group-buffer))
4676         (gnus-group-jump-to-group newsgroup))
4677     (save-excursion
4678       ;; Take care of tree window mode.
4679       (if (get-buffer-window gnus-group-buffer)
4680           (pop-to-buffer gnus-group-buffer)
4681         (set-buffer gnus-group-buffer))
4682       (gnus-group-jump-to-group newsgroup))))
4683
4684 ;; This function returns a list of article numbers based on the
4685 ;; difference between the ranges of read articles in this group and
4686 ;; the range of active articles.
4687 (defun gnus-list-of-unread-articles (group)
4688   (let* ((read (gnus-info-read (gnus-get-info group)))
4689          (active (or (gnus-active group) (gnus-activate-group group)))
4690          (last (cdr active))
4691          first nlast unread)
4692     ;; If none are read, then all are unread.
4693     (if (not read)
4694         (setq first (car active))
4695       ;; If the range of read articles is a single range, then the
4696       ;; first unread article is the article after the last read
4697       ;; article.  Sounds logical, doesn't it?
4698       (if (not (listp (cdr read)))
4699           (setq first (1+ (cdr read)))
4700         ;; `read' is a list of ranges.
4701         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
4702                                   (caar read)))
4703                   1)
4704           (setq first 1))
4705         (while read
4706           (when first
4707             (while (< first nlast)
4708               (push first unread)
4709               (setq first (1+ first))))
4710           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
4711           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
4712           (setq read (cdr read)))))
4713     ;; And add the last unread articles.
4714     (while (<= first last)
4715       (push first unread)
4716       (setq first (1+ first)))
4717     ;; Return the list of unread articles.
4718     (nreverse unread)))
4719
4720 (defun gnus-list-of-read-articles (group)
4721   "Return a list of unread, unticked and non-dormant articles."
4722   (let* ((info (gnus-get-info group))
4723          (marked (gnus-info-marks info))
4724          (active (gnus-active group)))
4725     (and info active
4726          (gnus-set-difference
4727           (gnus-sorted-complement
4728            (gnus-uncompress-range active)
4729            (gnus-list-of-unread-articles group))
4730           (append
4731            (gnus-uncompress-range (cdr (assq 'dormant marked)))
4732            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
4733
4734 ;; Various summary commands
4735
4736 (defun gnus-summary-universal-argument (arg)
4737   "Perform any operation on all articles that are process/prefixed."
4738   (interactive "P")
4739   (gnus-set-global-variables)
4740   (let ((articles (gnus-summary-work-articles arg))
4741         func article)
4742     (if (eq
4743          (setq
4744           func
4745           (key-binding
4746            (read-key-sequence
4747             (substitute-command-keys
4748              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
4749              ))))
4750          'undefined)
4751         (gnus-error 1 "Undefined key")
4752       (save-excursion
4753         (while articles
4754           (gnus-summary-goto-subject (setq article (pop articles)))
4755           (let (gnus-newsgroup-processable)
4756             (command-execute func))
4757           (gnus-summary-remove-process-mark article)))))
4758   (gnus-summary-position-point))
4759
4760 (defun gnus-summary-toggle-truncation (&optional arg)
4761   "Toggle truncation of summary lines.
4762 With arg, turn line truncation on iff arg is positive."
4763   (interactive "P")
4764   (setq truncate-lines
4765         (if (null arg) (not truncate-lines)
4766           (> (prefix-numeric-value arg) 0)))
4767   (redraw-display))
4768
4769 (defun gnus-summary-reselect-current-group (&optional all rescan)
4770   "Exit and then reselect the current newsgroup.
4771 The prefix argument ALL means to select all articles."
4772   (interactive "P")
4773   (gnus-set-global-variables)
4774   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
4775     (error "Ephemeral groups can't be reselected"))
4776   (let ((current-subject (gnus-summary-article-number))
4777         (group gnus-newsgroup-name))
4778     (setq gnus-newsgroup-begin nil)
4779     (gnus-summary-exit)
4780     ;; We have to adjust the point of group mode buffer because
4781     ;; point was moved to the next unread newsgroup by exiting.
4782     (gnus-summary-jump-to-group group)
4783     (when rescan
4784       (save-excursion
4785         (gnus-group-get-new-news-this-group 1)))
4786     (gnus-group-read-group all t)
4787     (gnus-summary-goto-subject current-subject nil t)))
4788
4789 (defun gnus-summary-rescan-group (&optional all)
4790   "Exit the newsgroup, ask for new articles, and select the newsgroup."
4791   (interactive "P")
4792   (gnus-summary-reselect-current-group all t))
4793
4794 (defun gnus-summary-update-info (&optional non-destructive)
4795   (save-excursion
4796     (let ((group gnus-newsgroup-name))
4797       (when gnus-newsgroup-kill-headers
4798         (setq gnus-newsgroup-killed
4799               (gnus-compress-sequence
4800                (nconc
4801                 (gnus-set-sorted-intersection
4802                  (gnus-uncompress-range gnus-newsgroup-killed)
4803                  (setq gnus-newsgroup-unselected
4804                        (sort gnus-newsgroup-unselected '<)))
4805                 (setq gnus-newsgroup-unreads
4806                       (sort gnus-newsgroup-unreads '<)))
4807                t)))
4808       (unless (listp (cdr gnus-newsgroup-killed))
4809         (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
4810       (let ((headers gnus-newsgroup-headers))
4811         (when (and (not gnus-save-score)
4812                    (not non-destructive))
4813           (setq gnus-newsgroup-scored nil))
4814         ;; Set the new ranges of read articles.
4815         (gnus-update-read-articles
4816          group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
4817         ;; Set the current article marks.
4818         (gnus-update-marks)
4819         ;; Do the cross-ref thing.
4820         (when gnus-use-cross-reference
4821           (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
4822         ;; Do adaptive scoring, and possibly save score files.
4823         (when gnus-newsgroup-adaptive
4824           (gnus-score-adaptive))
4825         (when gnus-use-scoring
4826           (gnus-score-save))
4827         ;; Do not switch windows but change the buffer to work.
4828         (set-buffer gnus-group-buffer)
4829         (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
4830           (gnus-group-update-group group))))))
4831
4832 (defun gnus-summary-save-newsrc (&optional force)
4833   "Save the current number of read/marked articles in the dribble buffer.
4834 The dribble buffer will then be saved.
4835 If FORCE (the prefix), also save the .newsrc file(s)."
4836   (interactive "P")
4837   (gnus-summary-update-info t)
4838   (if force
4839       (gnus-save-newsrc-file)
4840     (gnus-dribble-save)))
4841
4842 (defun gnus-summary-exit (&optional temporary)
4843   "Exit reading current newsgroup, and then return to group selection mode.
4844 gnus-exit-group-hook is called with no arguments if that value is non-nil."
4845   (interactive)
4846   (gnus-set-global-variables)
4847   (gnus-kill-save-kill-buffer)
4848   (let* ((group gnus-newsgroup-name)
4849          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
4850          (mode major-mode)
4851          (buf (current-buffer)))
4852     (run-hooks 'gnus-summary-prepare-exit-hook)
4853     ;; If we have several article buffers, we kill them at exit.
4854     (unless gnus-single-article-buffer
4855       (gnus-kill-buffer gnus-original-article-buffer)
4856       (setq gnus-article-current nil))
4857     (when gnus-use-cache
4858       (gnus-cache-possibly-remove-articles)
4859       (gnus-cache-save-buffers))
4860     (gnus-async-prefetch-remove-group group)
4861     (when gnus-suppress-duplicates
4862       (gnus-dup-enter-articles))
4863     (when gnus-use-trees
4864       (gnus-tree-close group))
4865     ;; Make all changes in this group permanent.
4866     (unless quit-config
4867       (run-hooks 'gnus-exit-group-hook)
4868       (gnus-summary-update-info))
4869     (gnus-close-group group)
4870     ;; Make sure where I was, and go to next newsgroup.
4871     (set-buffer gnus-group-buffer)
4872     (unless quit-config
4873       (gnus-group-jump-to-group group))
4874     (run-hooks 'gnus-summary-exit-hook)
4875     (unless quit-config
4876       (gnus-group-next-unread-group 1))
4877     (if temporary
4878         nil                             ;Nothing to do.
4879       ;; If we have several article buffers, we kill them at exit.
4880       (unless gnus-single-article-buffer
4881         (gnus-kill-buffer gnus-article-buffer)
4882         (gnus-kill-buffer gnus-original-article-buffer)
4883         (setq gnus-article-current nil))
4884       (set-buffer buf)
4885       (if (not gnus-kill-summary-on-exit)
4886           (gnus-deaden-summary)
4887         ;; We set all buffer-local variables to nil.  It is unclear why
4888         ;; this is needed, but if we don't, buffer-local variables are
4889         ;; not garbage-collected, it seems.  This would the lead to en
4890         ;; ever-growing Emacs.
4891         (gnus-summary-clear-local-variables)
4892         (when (get-buffer gnus-article-buffer)
4893           (bury-buffer gnus-article-buffer))
4894         ;; We clear the global counterparts of the buffer-local
4895         ;; variables as well, just to be on the safe side.
4896         (set-buffer gnus-group-buffer)
4897         (gnus-summary-clear-local-variables)
4898         ;; Return to group mode buffer.
4899         (when (eq mode 'gnus-summary-mode)
4900           (gnus-kill-buffer buf)))
4901       (setq gnus-current-select-method gnus-select-method)
4902       (pop-to-buffer gnus-group-buffer)
4903       ;; Clear the current group name.
4904       (if (not quit-config)
4905           (progn
4906             (gnus-group-jump-to-group group)
4907             (gnus-group-next-unread-group 1)
4908             (gnus-configure-windows 'group 'force))
4909         (gnus-handle-ephemeral-exit quit-config))
4910       (unless quit-config
4911         (setq gnus-newsgroup-name nil)))))
4912
4913 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
4914 (defun gnus-summary-exit-no-update (&optional no-questions)
4915   "Quit reading current newsgroup without updating read article info."
4916   (interactive)
4917   (gnus-set-global-variables)
4918   (let* ((group gnus-newsgroup-name)
4919          (quit-config (gnus-group-quit-config group)))
4920     (when (or no-questions
4921               gnus-expert-user
4922               (gnus-y-or-n-p "Discard changes to this group and exit? "))
4923       ;; If we have several article buffers, we kill them at exit.
4924       (unless gnus-single-article-buffer
4925         (gnus-kill-buffer gnus-article-buffer)
4926         (gnus-kill-buffer gnus-original-article-buffer)
4927         (setq gnus-article-current nil))
4928       (if (not gnus-kill-summary-on-exit)
4929           (gnus-deaden-summary)
4930         (gnus-close-group group)
4931         (gnus-summary-clear-local-variables)
4932         (set-buffer gnus-group-buffer)
4933         (gnus-summary-clear-local-variables)
4934         (when (get-buffer gnus-summary-buffer)
4935           (kill-buffer gnus-summary-buffer)))
4936       (unless gnus-single-article-buffer
4937         (setq gnus-article-current nil))
4938       (when gnus-use-trees
4939         (gnus-tree-close group))
4940       (gnus-async-prefetch-remove-group group)
4941       (when (get-buffer gnus-article-buffer)
4942         (bury-buffer gnus-article-buffer))
4943       ;; Return to the group buffer.
4944       (gnus-configure-windows 'group 'force)
4945       ;; Clear the current group name.
4946       (setq gnus-newsgroup-name nil)
4947       (when (equal (gnus-group-group-name) group)
4948         (gnus-group-next-unread-group 1))
4949       (when quit-config
4950         (gnus-handle-ephemeral-exit quit-config)))))
4951
4952 (defun gnus-handle-ephemeral-exit (quit-config)
4953   "Handle movement when leaving an ephemeral group.  The state
4954 which existed when entering the ephemeral is reset."
4955   (if (not (buffer-name (car quit-config)))
4956       (gnus-configure-windows 'group 'force)
4957     (set-buffer (car quit-config))
4958     (cond ((eq major-mode 'gnus-summary-mode)
4959            (gnus-set-global-variables))
4960           ((eq major-mode 'gnus-article-mode)
4961            (save-excursion
4962              ;; The `gnus-summary-buffer' variable may point
4963              ;; to the old summary buffer when using a single
4964              ;; article buffer.
4965              (unless (gnus-buffer-live-p gnus-summary-buffer)
4966                (set-buffer gnus-group-buffer))
4967              (set-buffer gnus-summary-buffer)
4968              (gnus-set-global-variables))))
4969     (if (or (eq (cdr quit-config) 'article)
4970             (eq (cdr quit-config) 'pick))
4971         (progn
4972           ;; The current article may be from the ephemeral group
4973           ;; thus it is best that we reload this article
4974           (gnus-summary-show-article)
4975           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
4976               (gnus-configure-windows 'pick 'force)
4977             (gnus-configure-windows (cdr quit-config) 'force)))
4978       (gnus-configure-windows (cdr quit-config) 'force))
4979     (when (eq major-mode 'gnus-summary-mode)
4980       (gnus-summary-next-subject 1 nil t)
4981       (gnus-summary-recenter)
4982       (gnus-summary-position-point))))
4983
4984 ;;; Dead summaries.
4985
4986 (defvar gnus-dead-summary-mode-map nil)
4987
4988 (unless gnus-dead-summary-mode-map
4989   (setq gnus-dead-summary-mode-map (make-keymap))
4990   (suppress-keymap gnus-dead-summary-mode-map)
4991   (substitute-key-definition
4992    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
4993   (let ((keys '("\C-d" "\r" "\177")))
4994     (while keys
4995       (define-key gnus-dead-summary-mode-map
4996         (pop keys) 'gnus-summary-wake-up-the-dead))))
4997
4998 (defvar gnus-dead-summary-mode nil
4999   "Minor mode for Gnus summary buffers.")
5000
5001 (defun gnus-dead-summary-mode (&optional arg)
5002   "Minor mode for Gnus summary buffers."
5003   (interactive "P")
5004   (when (eq major-mode 'gnus-summary-mode)
5005     (make-local-variable 'gnus-dead-summary-mode)
5006     (setq gnus-dead-summary-mode
5007           (if (null arg) (not gnus-dead-summary-mode)
5008             (> (prefix-numeric-value arg) 0)))
5009     (when gnus-dead-summary-mode
5010       (unless (assq 'gnus-dead-summary-mode minor-mode-alist)
5011         (push '(gnus-dead-summary-mode " Dead") minor-mode-alist))
5012       (unless (assq 'gnus-dead-summary-mode minor-mode-map-alist)
5013         (push (cons 'gnus-dead-summary-mode gnus-dead-summary-mode-map)
5014               minor-mode-map-alist)))))
5015
5016 (defun gnus-deaden-summary ()
5017   "Make the current summary buffer into a dead summary buffer."
5018   ;; Kill any previous dead summary buffer.
5019   (when (and gnus-dead-summary
5020              (buffer-name gnus-dead-summary))
5021     (save-excursion
5022       (set-buffer gnus-dead-summary)
5023       (when gnus-dead-summary-mode
5024         (kill-buffer (current-buffer)))))
5025   ;; Make this the current dead summary.
5026   (setq gnus-dead-summary (current-buffer))
5027   (gnus-dead-summary-mode 1)
5028   (let ((name (buffer-name)))
5029     (when (string-match "Summary" name)
5030       (rename-buffer
5031        (concat (substring name 0 (match-beginning 0)) "Dead "
5032                (substring name (match-beginning 0)))
5033        t))))
5034
5035 (defun gnus-kill-or-deaden-summary (buffer)
5036   "Kill or deaden the summary BUFFER."
5037   (when (and (buffer-name buffer)
5038              (not gnus-single-article-buffer))
5039     (save-excursion
5040       (set-buffer buffer)
5041       (gnus-kill-buffer gnus-article-buffer)
5042       (gnus-kill-buffer gnus-original-article-buffer)))
5043   (cond (gnus-kill-summary-on-exit
5044          (when (and gnus-use-trees
5045                     (and (get-buffer buffer)
5046                          (buffer-name (get-buffer buffer))))
5047            (save-excursion
5048              (set-buffer (get-buffer buffer))
5049              (gnus-tree-close gnus-newsgroup-name)))
5050          (gnus-kill-buffer buffer))
5051         ((and (get-buffer buffer)
5052               (buffer-name (get-buffer buffer)))
5053          (save-excursion
5054            (set-buffer buffer)
5055            (gnus-deaden-summary)))))
5056
5057 (defun gnus-summary-wake-up-the-dead (&rest args)
5058   "Wake up the dead summary buffer."
5059   (interactive)
5060   (gnus-dead-summary-mode -1)
5061   (let ((name (buffer-name)))
5062     (when (string-match "Dead " name)
5063       (rename-buffer
5064        (concat (substring name 0 (match-beginning 0))
5065                (substring name (match-end 0)))
5066        t)))
5067   (gnus-message 3 "This dead summary is now alive again"))
5068
5069 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5070 (defun gnus-summary-fetch-faq (&optional faq-dir)
5071   "Fetch the FAQ for the current group.
5072 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5073 in."
5074   (interactive
5075    (list
5076     (when current-prefix-arg
5077       (completing-read
5078        "Faq dir: " (and (listp gnus-group-faq-directory)
5079                         gnus-group-faq-directory)))))
5080   (let (gnus-faq-buffer)
5081     (when (setq gnus-faq-buffer
5082                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5083       (gnus-configure-windows 'summary-faq))))
5084
5085 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5086 (defun gnus-summary-describe-group (&optional force)
5087   "Describe the current newsgroup."
5088   (interactive "P")
5089   (gnus-group-describe-group force gnus-newsgroup-name))
5090
5091 (defun gnus-summary-describe-briefly ()
5092   "Describe summary mode commands briefly."
5093   (interactive)
5094   (gnus-message 6
5095                 (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")))
5096
5097 ;; Walking around group mode buffer from summary mode.
5098
5099 (defun gnus-summary-next-group (&optional no-article target-group backward)
5100   "Exit current newsgroup and then select next unread newsgroup.
5101 If prefix argument NO-ARTICLE is non-nil, no article is selected
5102 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5103 previous group instead."
5104   (interactive "P")
5105   (gnus-set-global-variables)
5106   ;; Stop pre-fetching.
5107   (gnus-async-halt-prefetch)
5108   (let ((current-group gnus-newsgroup-name)
5109         (current-buffer (current-buffer))
5110         entered)
5111     ;; First we semi-exit this group to update Xrefs and all variables.
5112     ;; We can't do a real exit, because the window conf must remain
5113     ;; the same in case the user is prompted for info, and we don't
5114     ;; want the window conf to change before that...
5115     (gnus-summary-exit t)
5116     (while (not entered)
5117       ;; Then we find what group we are supposed to enter.
5118       (set-buffer gnus-group-buffer)
5119       (gnus-group-jump-to-group current-group)
5120       (setq target-group
5121             (or target-group
5122                 (if (eq gnus-keep-same-level 'best)
5123                     (gnus-summary-best-group gnus-newsgroup-name)
5124                   (gnus-summary-search-group backward gnus-keep-same-level))))
5125       (if (not target-group)
5126           ;; There are no further groups, so we return to the group
5127           ;; buffer.
5128           (progn
5129             (gnus-message 5 "Returning to the group buffer")
5130             (setq entered t)
5131             (when (buffer-live-p current-buffer)
5132               (set-buffer current-buffer)
5133               (gnus-summary-exit))
5134             (run-hooks 'gnus-group-no-more-groups-hook))
5135         ;; We try to enter the target group.
5136         (gnus-group-jump-to-group target-group)
5137         (let ((unreads (gnus-group-group-unread)))
5138           (if (and (or (eq t unreads)
5139                        (and unreads (not (zerop unreads))))
5140                    (gnus-summary-read-group
5141                     target-group nil no-article current-buffer))
5142               (setq entered t)
5143             (setq current-group target-group
5144                   target-group nil)))))))
5145
5146 (defun gnus-summary-prev-group (&optional no-article)
5147   "Exit current newsgroup and then select previous unread newsgroup.
5148 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5149   (interactive "P")
5150   (gnus-summary-next-group no-article nil t))
5151
5152 ;; Walking around summary lines.
5153
5154 (defun gnus-summary-first-subject (&optional unread)
5155   "Go to the first unread subject.
5156 If UNREAD is non-nil, go to the first unread article.
5157 Returns the article selected or nil if there are no unread articles."
5158   (interactive "P")
5159   (prog1
5160       (cond
5161        ;; Empty summary.
5162        ((null gnus-newsgroup-data)
5163         (gnus-message 3 "No articles in the group")
5164         nil)
5165        ;; Pick the first article.
5166        ((not unread)
5167         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5168         (gnus-data-number (car gnus-newsgroup-data)))
5169        ;; No unread articles.
5170        ((null gnus-newsgroup-unreads)
5171         (gnus-message 3 "No more unread articles")
5172         nil)
5173        ;; Find the first unread article.
5174        (t
5175         (let ((data gnus-newsgroup-data))
5176           (while (and data
5177                       (not (gnus-data-unread-p (car data))))
5178             (setq data (cdr data)))
5179           (when data
5180             (goto-char (gnus-data-pos (car data)))
5181             (gnus-data-number (car data))))))
5182     (gnus-summary-position-point)))
5183
5184 (defun gnus-summary-next-subject (n &optional unread dont-display)
5185   "Go to next N'th summary line.
5186 If N is negative, go to the previous N'th subject line.
5187 If UNREAD is non-nil, only unread articles are selected.
5188 The difference between N and the actual number of steps taken is
5189 returned."
5190   (interactive "p")
5191   (let ((backward (< n 0))
5192         (n (abs n)))
5193     (while (and (> n 0)
5194                 (if backward
5195                     (gnus-summary-find-prev unread)
5196                   (gnus-summary-find-next unread)))
5197       (setq n (1- n)))
5198     (when (/= 0 n)
5199       (gnus-message 7 "No more%s articles"
5200                     (if unread " unread" "")))
5201     (unless dont-display
5202       (gnus-summary-recenter)
5203       (gnus-summary-position-point))
5204     n))
5205
5206 (defun gnus-summary-next-unread-subject (n)
5207   "Go to next N'th unread summary line."
5208   (interactive "p")
5209   (gnus-summary-next-subject n t))
5210
5211 (defun gnus-summary-prev-subject (n &optional unread)
5212   "Go to previous N'th summary line.
5213 If optional argument UNREAD is non-nil, only unread article is selected."
5214   (interactive "p")
5215   (gnus-summary-next-subject (- n) unread))
5216
5217 (defun gnus-summary-prev-unread-subject (n)
5218   "Go to previous N'th unread summary line."
5219   (interactive "p")
5220   (gnus-summary-next-subject (- n) t))
5221
5222 (defun gnus-summary-goto-subject (article &optional force silent)
5223   "Go the subject line of ARTICLE.
5224 If FORCE, also allow jumping to articles not currently shown."
5225   (interactive "nArticle number: ")
5226   (let ((b (point))
5227         (data (gnus-data-find article)))
5228     ;; We read in the article if we have to.
5229     (and (not data)
5230          force
5231          (gnus-summary-insert-subject article (and (vectorp force) force) t)
5232          (setq data (gnus-data-find article)))
5233     (goto-char b)
5234     (if (not data)
5235         (progn
5236           (unless silent
5237             (gnus-message 3 "Can't find article %d" article))
5238           nil)
5239       (goto-char (gnus-data-pos data))
5240       article)))
5241
5242 ;; Walking around summary lines with displaying articles.
5243
5244 (defun gnus-summary-expand-window (&optional arg)
5245   "Make the summary buffer take up the entire Emacs frame.
5246 Given a prefix, will force an `article' buffer configuration."
5247   (interactive "P")
5248   (gnus-set-global-variables)
5249   (if arg
5250       (gnus-configure-windows 'article 'force)
5251     (gnus-configure-windows 'summary 'force)))
5252
5253 (defun gnus-summary-display-article (article &optional all-header)
5254   "Display ARTICLE in article buffer."
5255   (gnus-set-global-variables)
5256   (if (null article)
5257       nil
5258     (prog1
5259         (if gnus-summary-display-article-function
5260             (funcall gnus-summary-display-article-function article all-header)
5261           (gnus-article-prepare article all-header))
5262       (run-hooks 'gnus-select-article-hook)
5263       (when (and gnus-current-article
5264                  (not (zerop gnus-current-article)))
5265         (gnus-summary-goto-subject gnus-current-article))
5266       (gnus-summary-recenter)
5267       (when (and gnus-use-trees gnus-show-threads)
5268         (gnus-possibly-generate-tree article)
5269         (gnus-highlight-selected-tree article))
5270       ;; Successfully display article.
5271       (gnus-article-set-window-start
5272        (cdr (assq article gnus-newsgroup-bookmarks))))))
5273
5274 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5275   "Select the current article.
5276 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5277 non-nil, the article will be re-fetched even if it already present in
5278 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5279 be displayed."
5280   ;; Make sure we are in the summary buffer to work around bbdb bug.
5281   (unless (eq major-mode 'gnus-summary-mode)
5282     (set-buffer gnus-summary-buffer))
5283   (let ((article (or article (gnus-summary-article-number)))
5284         (all-headers (not (not all-headers))) ;Must be T or NIL.
5285         gnus-summary-display-article-function
5286         did)
5287     (and (not pseudo)
5288          (gnus-summary-article-pseudo-p article)
5289          (error "This is a pseudo-article."))
5290     (prog1
5291         (save-excursion
5292           (set-buffer gnus-summary-buffer)
5293           (if (or (and gnus-single-article-buffer
5294                        (or (null gnus-current-article)
5295                            (null gnus-article-current)
5296                            (null (get-buffer gnus-article-buffer))
5297                            (not (eq article (cdr gnus-article-current)))
5298                            (not (equal (car gnus-article-current)
5299                                        gnus-newsgroup-name))))
5300                   (and (not gnus-single-article-buffer)
5301                        (or (null gnus-current-article)
5302                            (not (eq gnus-current-article article))))
5303                   force)
5304               ;; The requested article is different from the current article.
5305               (prog1
5306                   (gnus-summary-display-article article all-headers)
5307                 (setq did article))
5308             (when (or all-headers gnus-show-all-headers)
5309               (gnus-article-show-all-headers))
5310             'old))
5311       (when did
5312         (gnus-article-set-window-start
5313          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5314
5315 (defun gnus-summary-set-current-mark (&optional current-mark)
5316   "Obsolete function."
5317   nil)
5318
5319 (defun gnus-summary-next-article (&optional unread subject backward push)
5320   "Select the next article.
5321 If UNREAD, only unread articles are selected.
5322 If SUBJECT, only articles with SUBJECT are selected.
5323 If BACKWARD, the previous article is selected instead of the next."
5324   (interactive "P")
5325   (gnus-set-global-variables)
5326   (cond
5327    ;; Is there such an article?
5328    ((and (gnus-summary-search-forward unread subject backward)
5329          (or (gnus-summary-display-article (gnus-summary-article-number))
5330              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5331     (gnus-summary-position-point))
5332    ;; If not, we try the first unread, if that is wanted.
5333    ((and subject
5334          gnus-auto-select-same
5335          (gnus-summary-first-unread-article))
5336     (gnus-summary-position-point)
5337     (gnus-message 6 "Wrapped"))
5338    ;; Try to get next/previous article not displayed in this group.
5339    ((and gnus-auto-extend-newsgroup
5340          (not unread) (not subject))
5341     (gnus-summary-goto-article
5342      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5343      nil t))
5344    ;; Go to next/previous group.
5345    (t
5346     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5347       (gnus-summary-jump-to-group gnus-newsgroup-name))
5348     (let ((cmd last-command-char)
5349           (point
5350            (save-excursion
5351              (set-buffer gnus-group-buffer)
5352              (point)))
5353           (group
5354            (if (eq gnus-keep-same-level 'best)
5355                (gnus-summary-best-group gnus-newsgroup-name)
5356              (gnus-summary-search-group backward gnus-keep-same-level))))
5357       ;; For some reason, the group window gets selected.  We change
5358       ;; it back.
5359       (select-window (get-buffer-window (current-buffer)))
5360       ;; Select next unread newsgroup automagically.
5361       (cond
5362        ((or (not gnus-auto-select-next)
5363             (not cmd))
5364         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5365        ((or (eq gnus-auto-select-next 'quietly)
5366             (and (eq gnus-auto-select-next 'slightly-quietly)
5367                  push)
5368             (and (eq gnus-auto-select-next 'almost-quietly)
5369                  (gnus-summary-last-article-p)))
5370         ;; Select quietly.
5371         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5372             (gnus-summary-exit)
5373           (gnus-message 7 "No more%s articles (%s)..."
5374                         (if unread " unread" "")
5375                         (if group (concat "selecting " group)
5376                           "exiting"))
5377           (gnus-summary-next-group nil group backward)))
5378        (t
5379         (when (gnus-key-press-event-p last-input-event)
5380           (gnus-summary-walk-group-buffer
5381            gnus-newsgroup-name cmd unread backward point))))))))
5382
5383 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5384   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5385                       (?\C-p (gnus-group-prev-unread-group 1))))
5386         (cursor-in-echo-area t)
5387         keve key group ended)
5388     (save-excursion
5389       (set-buffer gnus-group-buffer)
5390       (goto-char start)
5391       (setq group
5392             (if (eq gnus-keep-same-level 'best)
5393                 (gnus-summary-best-group gnus-newsgroup-name)
5394               (gnus-summary-search-group backward gnus-keep-same-level))))
5395     (while (not ended)
5396       (gnus-message
5397        5 "No more%s articles%s" (if unread " unread" "")
5398        (if (and group
5399                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5400            (format " (Type %s for %s [%s])"
5401                    (single-key-description cmd) group
5402                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5403          (format " (Type %s to exit %s)"
5404                  (single-key-description cmd)
5405                  gnus-newsgroup-name)))
5406       ;; Confirm auto selection.
5407       (setq key (car (setq keve (gnus-read-event-char))))
5408       (setq ended t)
5409       (cond
5410        ((assq key keystrokes)
5411         (let ((obuf (current-buffer)))
5412           (switch-to-buffer gnus-group-buffer)
5413           (when group
5414             (gnus-group-jump-to-group group))
5415           (eval (cadr (assq key keystrokes)))
5416           (setq group (gnus-group-group-name))
5417           (switch-to-buffer obuf))
5418         (setq ended nil))
5419        ((equal key cmd)
5420         (if (or (not group)
5421                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5422             (gnus-summary-exit)
5423           (gnus-summary-next-group nil group backward)))
5424        (t
5425         (push (cdr keve) unread-command-events))))))
5426
5427 (defun gnus-summary-next-unread-article ()
5428   "Select unread article after current one."
5429   (interactive)
5430   (gnus-summary-next-article
5431    (or (not (eq gnus-summary-goto-unread 'never))
5432        (gnus-summary-last-article-p (gnus-summary-article-number)))
5433    (and gnus-auto-select-same
5434         (gnus-summary-article-subject))))
5435
5436 (defun gnus-summary-prev-article (&optional unread subject)
5437   "Select the article after the current one.
5438 If UNREAD is non-nil, only unread articles are selected."
5439   (interactive "P")
5440   (gnus-summary-next-article unread subject t))
5441
5442 (defun gnus-summary-prev-unread-article ()
5443   "Select unread article before current one."
5444   (interactive)
5445   (gnus-summary-prev-article
5446    (or (not (eq gnus-summary-goto-unread 'never))
5447        (gnus-summary-first-article-p (gnus-summary-article-number)))
5448    (and gnus-auto-select-same
5449         (gnus-summary-article-subject))))
5450
5451 (defun gnus-summary-next-page (&optional lines circular)
5452   "Show next page of the selected article.
5453 If at the end of the current article, select the next article.
5454 LINES says how many lines should be scrolled up.
5455
5456 If CIRCULAR is non-nil, go to the start of the article instead of
5457 selecting the next article when reaching the end of the current
5458 article."
5459   (interactive "P")
5460   (setq gnus-summary-buffer (current-buffer))
5461   (gnus-set-global-variables)
5462   (let ((article (gnus-summary-article-number))
5463         (article-window (get-buffer-window gnus-article-buffer t))
5464         endp)
5465     (gnus-configure-windows 'article)
5466     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5467         (if (and (eq gnus-summary-goto-unread 'never)
5468                  (not (gnus-summary-last-article-p article)))
5469             (gnus-summary-next-article)
5470           (gnus-summary-next-unread-article))
5471       (if (or (null gnus-current-article)
5472               (null gnus-article-current)
5473               (/= article (cdr gnus-article-current))
5474               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5475           ;; Selected subject is different from current article's.
5476           (gnus-summary-display-article article)
5477         (when article-window
5478           (gnus-eval-in-buffer-window gnus-article-buffer
5479             (setq endp (gnus-article-next-page lines)))
5480           (when endp
5481             (cond (circular
5482                    (gnus-summary-beginning-of-article))
5483                   (lines
5484                    (gnus-message 3 "End of message"))
5485                   ((null lines)
5486                    (if (and (eq gnus-summary-goto-unread 'never)
5487                             (not (gnus-summary-last-article-p article)))
5488                        (gnus-summary-next-article)
5489                      (gnus-summary-next-unread-article))))))))
5490     (gnus-summary-recenter)
5491     (gnus-summary-position-point)))
5492
5493 (defun gnus-summary-prev-page (&optional lines move)
5494   "Show previous page of selected article.
5495 Argument LINES specifies lines to be scrolled down.
5496 If MOVE, move to the previous unread article if point is at
5497 the beginning of the buffer."
5498   (interactive "P")
5499   (gnus-set-global-variables)
5500   (let ((article (gnus-summary-article-number))
5501         (article-window (get-buffer-window gnus-article-buffer t))
5502         endp)
5503     (gnus-configure-windows 'article)
5504     (if (or (null gnus-current-article)
5505             (null gnus-article-current)
5506             (/= article (cdr gnus-article-current))
5507             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5508         ;; Selected subject is different from current article's.
5509         (gnus-summary-display-article article)
5510       (gnus-summary-recenter)
5511       (when article-window
5512         (gnus-eval-in-buffer-window gnus-article-buffer
5513           (setq endp (gnus-article-prev-page lines)))
5514         (when (and move endp)
5515           (cond (lines
5516                  (gnus-message 3 "Beginning of message"))
5517                 ((null lines)
5518                  (if (and (eq gnus-summary-goto-unread 'never)
5519                           (not (gnus-summary-first-article-p article)))
5520                      (gnus-summary-prev-article)
5521                    (gnus-summary-prev-unread-article))))))))
5522   (gnus-summary-position-point))
5523
5524 (defun gnus-summary-prev-page-or-article (&optional lines)
5525   "Show previous page of selected article.
5526 Argument LINES specifies lines to be scrolled down.
5527 If at the beginning of the article, go to the next article."
5528   (interactive "P")
5529   (gnus-summary-prev-page lines t))
5530
5531 (defun gnus-summary-scroll-up (lines)
5532   "Scroll up (or down) one line current article.
5533 Argument LINES specifies lines to be scrolled up (or down if negative)."
5534   (interactive "p")
5535   (gnus-set-global-variables)
5536   (gnus-configure-windows 'article)
5537   (gnus-summary-show-thread)
5538   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
5539     (gnus-eval-in-buffer-window gnus-article-buffer
5540       (cond ((> lines 0)
5541              (when (gnus-article-next-page lines)
5542                (gnus-message 3 "End of message")))
5543             ((< lines 0)
5544              (gnus-article-prev-page (- lines))))))
5545   (gnus-summary-recenter)
5546   (gnus-summary-position-point))
5547
5548 (defun gnus-summary-next-same-subject ()
5549   "Select next article which has the same subject as current one."
5550   (interactive)
5551   (gnus-set-global-variables)
5552   (gnus-summary-next-article nil (gnus-summary-article-subject)))
5553
5554 (defun gnus-summary-prev-same-subject ()
5555   "Select previous article which has the same subject as current one."
5556   (interactive)
5557   (gnus-set-global-variables)
5558   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
5559
5560 (defun gnus-summary-next-unread-same-subject ()
5561   "Select next unread article which has the same subject as current one."
5562   (interactive)
5563   (gnus-set-global-variables)
5564   (gnus-summary-next-article t (gnus-summary-article-subject)))
5565
5566 (defun gnus-summary-prev-unread-same-subject ()
5567   "Select previous unread article which has the same subject as current one."
5568   (interactive)
5569   (gnus-set-global-variables)
5570   (gnus-summary-prev-article t (gnus-summary-article-subject)))
5571
5572 (defun gnus-summary-first-unread-article ()
5573   "Select the first unread article.
5574 Return nil if there are no unread articles."
5575   (interactive)
5576   (gnus-set-global-variables)
5577   (prog1
5578       (when (gnus-summary-first-subject t)
5579         (gnus-summary-show-thread)
5580         (gnus-summary-first-subject t)
5581         (gnus-summary-display-article (gnus-summary-article-number)))
5582     (gnus-summary-position-point)))
5583
5584 (defun gnus-summary-first-article ()
5585   "Select the first article.
5586 Return nil if there are no articles."
5587   (interactive)
5588   (gnus-set-global-variables)
5589   (prog1
5590       (when (gnus-summary-first-subject)
5591       (gnus-summary-show-thread)
5592       (gnus-summary-first-subject)
5593       (gnus-summary-display-article (gnus-summary-article-number)))
5594     (gnus-summary-position-point)))
5595