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