28c877806a622aa5f6ac776a8c3334c375563d23
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
40
41 (defcustom gnus-kill-summary-on-exit t
42   "*If non-nil, kill the summary buffer when you exit from it.
43 If nil, the summary will become a \"*Dead Summary*\" buffer, and
44 it will be killed sometime later."
45   :group 'gnus-summary-exit
46   :type 'boolean)
47
48 (defcustom gnus-fetch-old-headers nil
49   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
50 If an unread article in the group refers to an older, already read (or
51 just marked as read) article, the old article will not normally be
52 displayed in the Summary buffer.  If this variable is non-nil, Gnus
53 will attempt to grab the headers to the old articles, and thereby
54 build complete threads.  If it has the value `some', only enough
55 headers to connect otherwise loose threads will be displayed.  This
56 variable can also be a number.  In that case, no more than that number
57 of old headers will be fetched.  If it has the value `invisible', all
58 old headers will be fetched, but none will be displayed.
59
60 The server has to support NOV for any of this to work."
61   :group 'gnus-thread
62   :type '(choice (const :tag "off" nil)
63                  (const some)
64                  number
65                  (sexp :menu-tag "other" t)))
66
67 (defcustom gnus-refer-thread-limit 200
68   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
69 If t, fetch all the available old headers."
70   :group 'gnus-thread
71   :type '(choice number
72                  (sexp :menu-tag "other" t)))
73
74 (defcustom gnus-summary-make-false-root 'adopt
75   "*nil means that Gnus won't gather loose threads.
76 If the root of a thread has expired or been read in a previous
77 session, the information necessary to build a complete thread has been
78 lost.  Instead of having many small sub-threads from this original thread
79 scattered all over the summary buffer, Gnus can gather them.
80
81 If non-nil, Gnus will try to gather all loose sub-threads from an
82 original thread into one large thread.
83
84 If this variable is non-nil, it should be one of `none', `adopt',
85 `dummy' or `empty'.
86
87 If this variable is `none', Gnus will not make a false root, but just
88 present the sub-threads after another.
89 If this variable is `dummy', Gnus will create a dummy root that will
90 have all the sub-threads as children.
91 If this variable is `adopt', Gnus will make one of the \"children\"
92 the parent and mark all the step-children as such.
93 If this variable is `empty', the \"children\" are printed with empty
94 subject fields.  (Or rather, they will be printed with a string
95 given by the `gnus-summary-same-subject' variable.)"
96   :group 'gnus-thread
97   :type '(choice (const :tag "off" nil)
98                  (const none)
99                  (const dummy)
100                  (const adopt)
101                  (const empty)))
102
103 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
104   "*A regexp to match subjects to be excluded from loose thread gathering.
105 As loose thread gathering is done on subjects only, that means that
106 there can be many false gatherings performed.  By rooting out certain
107 common subjects, gathering might become saner."
108   :group 'gnus-thread
109   :type 'regexp)
110
111 (defcustom gnus-summary-gather-subject-limit nil
112   "*Maximum length of subject comparisons when gathering loose threads.
113 Use nil to compare full subjects.  Setting this variable to a low
114 number will help gather threads that have been corrupted by
115 newsreaders chopping off subject lines, but it might also mean that
116 unrelated articles that have subject that happen to begin with the
117 same few characters will be incorrectly gathered.
118
119 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
120 comparing subjects."
121   :group 'gnus-thread
122   :type '(choice (const :tag "off" nil)
123                  (const fuzzy)
124                  (sexp :menu-tag "on" t)))
125
126 (defcustom gnus-simplify-subject-functions nil
127   "List of functions taking a string argument that simplify subjects.
128 The functions are applied recursively.
129
130 Useful functions to put in this list include: `gnus-simplify-subject-re',
131 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
132   :group 'gnus-thread
133   :type '(repeat function))
134
135 (defcustom gnus-simplify-ignored-prefixes nil
136   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
137   :group 'gnus-thread
138   :type '(choice (const :tag "off" nil)
139                  regexp))
140
141 (defcustom gnus-build-sparse-threads nil
142   "*If non-nil, fill in the gaps in threads.
143 If `some', only fill in the gaps that are needed to tie loose threads
144 together.  If `more', fill in all leaf nodes that Gnus can find.  If
145 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
146   :group 'gnus-thread
147   :type '(choice (const :tag "off" nil)
148                  (const some)
149                  (const more)
150                  (sexp :menu-tag "all" t)))
151
152 (defcustom gnus-summary-thread-gathering-function
153   'gnus-gather-threads-by-subject
154   "*Function used for gathering loose threads.
155 There are two pre-defined functions: `gnus-gather-threads-by-subject',
156 which only takes Subjects into consideration; and
157 `gnus-gather-threads-by-references', which compared the References
158 headers of the articles to find matches."
159   :group 'gnus-thread
160   :type '(radio (function-item gnus-gather-threads-by-subject)
161                 (function-item gnus-gather-threads-by-references)
162                 (function :tag "other")))
163
164 (defcustom gnus-summary-same-subject ""
165   "*String indicating that the current article has the same subject as the previous.
166 This variable will only be used if the value of
167 `gnus-summary-make-false-root' is `empty'."
168   :group 'gnus-summary-format
169   :type 'string)
170
171 (defcustom gnus-summary-goto-unread t
172   "*If t, many commands will go to the next unread article.
173 This applies to marking commands as well as other commands that
174 \"naturally\" select the next article, like, for instance, `SPC' at
175 the end of an article.
176
177 If nil, the marking commands do NOT go to the next unread article
178 (they go to the next article instead).  If `never', commands that
179 usually go to the next unread article, will go to the next article,
180 whether it is read or not."
181   :group 'gnus-summary-marks
182   :link '(custom-manual "(gnus)Setting Marks")
183   :type '(choice (const :tag "off" nil)
184                  (const never)
185                  (sexp :menu-tag "on" t)))
186
187 (defcustom gnus-summary-default-score 0
188   "*Default article score level.
189 All scores generated by the score files will be added to this score.
190 If this variable is nil, scoring will be disabled."
191   :group 'gnus-score-default
192   :type '(choice (const :tag "disable")
193                  integer))
194
195 (defcustom gnus-summary-zcore-fuzz 0
196   "*Fuzziness factor for the zcore in the summary buffer.
197 Articles with scores closer than this to `gnus-summary-default-score'
198 will not be marked."
199   :group 'gnus-summary-format
200   :type 'integer)
201
202 (defcustom gnus-simplify-subject-fuzzy-regexp nil
203   "*Strings to be removed when doing fuzzy matches.
204 This can either be a regular expression or list of regular expressions
205 that will be removed from subject strings if fuzzy subject
206 simplification is selected."
207   :group 'gnus-thread
208   :type '(repeat regexp))
209
210 (defcustom gnus-show-threads t
211   "*If non-nil, display threads in summary mode."
212   :group 'gnus-thread
213   :type 'boolean)
214
215 (defcustom gnus-thread-hide-subtree nil
216   "*If non-nil, hide all threads initially.
217 If threads are hidden, you have to run the command
218 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
219 to expose hidden threads."
220   :group 'gnus-thread
221   :type 'boolean)
222
223 (defcustom gnus-thread-hide-killed t
224   "*If non-nil, hide killed threads automatically."
225   :group 'gnus-thread
226   :type 'boolean)
227
228 (defcustom gnus-thread-ignore-subject t
229   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
230 If nil, articles that have different subjects from their parents will
231 start separate threads."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-operation-ignore-subject t
236   "*If non-nil, subjects will be ignored when doing thread commands.
237 This affects commands like `gnus-summary-kill-thread' and
238 `gnus-summary-lower-thread'.
239
240 If this variable is nil, articles in the same thread with different
241 subjects will not be included in the operation in question.  If this
242 variable is `fuzzy', only articles that have subjects that are fuzzily
243 equal will be included."
244   :group 'gnus-thread
245   :type '(choice (const :tag "off" nil)
246                  (const fuzzy)
247                  (sexp :tag "on" t)))
248
249 (defcustom gnus-thread-indent-level 4
250   "*Number that says how much each sub-thread should be indented."
251   :group 'gnus-thread
252   :type 'integer)
253
254 (defcustom gnus-auto-extend-newsgroup t
255   "*If non-nil, extend newsgroup forward and backward when requested."
256   :group 'gnus-summary-choose
257   :type 'boolean)
258
259 (defcustom gnus-auto-select-first t
260   "*If nil, don't select the first unread article when entering a group.
261 If this variable is `best', select the highest-scored unread article
262 in the group.  If t, select the first unread article.
263
264 This variable can also be a function to place point on a likely
265 subject line.  Useful values include `gnus-summary-first-unread-subject',
266 `gnus-summary-first-unread-article' and
267 `gnus-summary-best-unread-article'.
268
269 If you want to prevent automatic selection of the first unread article
270 in some newsgroups, set the variable to nil in
271 `gnus-select-group-hook'."
272   :group 'gnus-group-select
273   :type '(choice (const :tag "none" nil)
274                  (const best)
275                  (sexp :menu-tag "first" t)
276                  (function-item gnus-summary-first-unread-subject)
277                  (function-item gnus-summary-first-unread-article)
278                  (function-item gnus-summary-best-unread-article)))
279
280 (defcustom gnus-auto-select-next t
281   "*If non-nil, offer to go to the next group from the end of the previous.
282 If the value is t and the next newsgroup is empty, Gnus will exit
283 summary mode and go back to group mode.  If the value is neither nil
284 nor t, Gnus will select the following unread newsgroup.  In
285 particular, if the value is the symbol `quietly', the next unread
286 newsgroup will be selected without any confirmation, and if it is
287 `almost-quietly', the next group will be selected without any
288 confirmation if you are located on the last article in the group.
289 Finally, if this variable is `slightly-quietly', the `Z n' command
290 will go to the next group without confirmation."
291   :group 'gnus-summary-maneuvering
292   :type '(choice (const :tag "off" nil)
293                  (const quietly)
294                  (const almost-quietly)
295                  (const slightly-quietly)
296                  (sexp :menu-tag "on" t)))
297
298 (defcustom gnus-auto-select-same nil
299   "*If non-nil, select the next article with the same subject.
300 If there are no more articles with the same subject, go to
301 the first unread article."
302   :group 'gnus-summary-maneuvering
303   :type 'boolean)
304
305 (defcustom gnus-summary-check-current nil
306   "*If non-nil, consider the current article when moving.
307 The \"unread\" movement commands will stay on the same line if the
308 current article is unread."
309   :group 'gnus-summary-maneuvering
310   :type 'boolean)
311
312 (defcustom gnus-auto-center-summary t
313   "*If non-nil, always center the current summary buffer.
314 In particular, if `vertical' do only vertical recentering.  If non-nil
315 and non-`vertical', do both horizontal and vertical recentering."
316   :group 'gnus-summary-maneuvering
317   :type '(choice (const :tag "none" nil)
318                  (const vertical)
319                  (integer :tag "height")
320                  (sexp :menu-tag "both" t)))
321
322 (defcustom gnus-show-all-headers nil
323   "*If non-nil, don't hide any headers."
324   :group 'gnus-article-hiding
325   :group 'gnus-article-headers
326   :type 'boolean)
327
328 (defcustom gnus-summary-ignore-duplicates nil
329   "*If non-nil, ignore articles with identical Message-ID headers."
330   :group 'gnus-summary
331   :type 'boolean)
332
333 (defcustom gnus-single-article-buffer t
334   "*If non-nil, display all articles in the same buffer.
335 If nil, each group will get its own article buffer."
336   :group 'gnus-article-various
337   :type 'boolean)
338
339 (defcustom gnus-break-pages t
340   "*If non-nil, do page breaking on articles.
341 The page delimiter is specified by the `gnus-page-delimiter'
342 variable."
343   :group 'gnus-article-various
344   :type 'boolean)
345
346 (defcustom gnus-move-split-methods nil
347   "*Variable used to suggest where articles are to be moved to.
348 It uses the same syntax as the `gnus-split-methods' variable."
349   :group 'gnus-summary-mail
350   :type '(repeat (choice (list :value (fun) function)
351                          (cons :value ("" "") regexp (repeat string))
352                          (sexp :value nil))))
353
354 (defcustom gnus-unread-mark ?  ;Whitespace
355   "*Mark used for unread articles."
356   :group 'gnus-summary-marks
357   :type 'character)
358
359 (defcustom gnus-ticked-mark ?!
360   "*Mark used for ticked articles."
361   :group 'gnus-summary-marks
362   :type 'character)
363
364 (defcustom gnus-dormant-mark ??
365   "*Mark used for dormant articles."
366   :group 'gnus-summary-marks
367   :type 'character)
368
369 (defcustom gnus-del-mark ?r
370   "*Mark used for del'd articles."
371   :group 'gnus-summary-marks
372   :type 'character)
373
374 (defcustom gnus-read-mark ?R
375   "*Mark used for read articles."
376   :group 'gnus-summary-marks
377   :type 'character)
378
379 (defcustom gnus-expirable-mark ?E
380   "*Mark used for expirable articles."
381   :group 'gnus-summary-marks
382   :type 'character)
383
384 (defcustom gnus-killed-mark ?K
385   "*Mark used for killed articles."
386   :group 'gnus-summary-marks
387   :type 'character)
388
389 (defcustom gnus-souped-mark ?F
390   "*Mark used for killed articles."
391   :group 'gnus-summary-marks
392   :type 'character)
393
394 (defcustom gnus-kill-file-mark ?X
395   "*Mark used for articles killed by kill files."
396   :group 'gnus-summary-marks
397   :type 'character)
398
399 (defcustom gnus-low-score-mark ?Y
400   "*Mark used for articles with a low score."
401   :group 'gnus-summary-marks
402   :type 'character)
403
404 (defcustom gnus-catchup-mark ?C
405   "*Mark used for articles that are caught up."
406   :group 'gnus-summary-marks
407   :type 'character)
408
409 (defcustom gnus-replied-mark ?A
410   "*Mark used for articles that have been replied to."
411   :group 'gnus-summary-marks
412   :type 'character)
413
414 (defcustom gnus-cached-mark ?*
415   "*Mark used for articles that are in the cache."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-saved-mark ?S
420   "*Mark used for articles that have been saved to."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-ancient-mark ?O
425   "*Mark used for ancient articles."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-sparse-mark ?Q
430   "*Mark used for sparsely reffed articles."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-canceled-mark ?G
435   "*Mark used for canceled articles."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-duplicate-mark ?M
440   "*Mark used for duplicate articles."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-undownloaded-mark ?@
445   "*Mark used for articles that weren't downloaded."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-downloadable-mark ?%
450   "*Mark used for articles that are to be downloaded."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-unsendable-mark ?=
455   "*Mark used for articles that won't be sent."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-score-over-mark ?+
460   "*Score mark used for articles with high scores."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-score-below-mark ?-
465   "*Score mark used for articles with low scores."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-empty-thread-mark ?  ;Whitespace
470   "*There is no thread under the article."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-not-empty-thread-mark ?=
475   "*There is a thread under the article."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-view-pseudo-asynchronously nil
480   "*If non-nil, Gnus will view pseudo-articles asynchronously."
481   :group 'gnus-extract-view
482   :type 'boolean)
483
484 (defcustom gnus-auto-expirable-marks
485   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
486         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
487         gnus-souped-mark gnus-duplicate-mark)
488   "*The list of marks converted into expiration if a group is auto-expirable."
489   :group 'gnus-summary
490   :type '(repeat character))
491
492 (defcustom gnus-inhibit-user-auto-expire t
493   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
494   :group 'gnus-summary
495   :type 'boolean)
496
497 (defcustom gnus-view-pseudos nil
498   "*If `automatic', pseudo-articles will be viewed automatically.
499 If `not-confirm', pseudos will be viewed automatically, and the user
500 will not be asked to confirm the command."
501   :group 'gnus-extract-view
502   :type '(choice (const :tag "off" nil)
503                  (const automatic)
504                  (const not-confirm)))
505
506 (defcustom gnus-view-pseudos-separately t
507   "*If non-nil, one pseudo-article will be created for each file to be viewed.
508 If nil, all files that use the same viewing command will be given as a
509 list of parameters to that command."
510   :group 'gnus-extract-view
511   :type 'boolean)
512
513 (defcustom gnus-insert-pseudo-articles t
514   "*If non-nil, insert pseudo-articles when decoding articles."
515   :group 'gnus-extract-view
516   :type 'boolean)
517
518 (defcustom gnus-summary-dummy-line-format
519   "  %(:                          :%) %S\n"
520   "*The format specification for the dummy roots in the summary buffer.
521 It works along the same lines as a normal formatting string,
522 with some simple extensions.
523
524 %S  The subject"
525   :group 'gnus-threading
526   :type 'string)
527
528 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
529   "*The format specification for the summary mode line.
530 It works along the same lines as a normal formatting string,
531 with some simple extensions:
532
533 %G  Group name
534 %p  Unprefixed group name
535 %A  Current article number
536 %z  Current article score
537 %V  Gnus version
538 %U  Number of unread articles in the group
539 %e  Number of unselected articles in the group
540 %Z  A string with unread/unselected article counts
541 %g  Shortish group name
542 %S  Subject of the current article
543 %u  User-defined spec
544 %s  Current score file name
545 %d  Number of dormant articles
546 %r  Number of articles that have been marked as read in this session
547 %E  Number of articles expunged by the score files"
548   :group 'gnus-summary-format
549   :type 'string)
550
551 (defcustom gnus-list-identifiers nil
552   "Regexp that matches list identifiers to be removed from subject.
553 This can also be a list of regexps."
554   :group 'gnus-summary-format
555   :group 'gnus-article-hiding
556   :type '(choice (const :tag "none" nil)
557                  (regexp :value ".*")
558                  (repeat :value (".*") regexp)))
559
560 (defcustom gnus-summary-mark-below 0
561   "*Mark all articles with a score below this variable as read.
562 This variable is local to each summary buffer and usually set by the
563 score file."
564   :group 'gnus-score-default
565   :type 'integer)
566
567 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
568   "*List of functions used for sorting articles in the summary buffer.
569 This variable is only used when not using a threaded display."
570   :group 'gnus-summary-sort
571   :type '(repeat (choice (function-item gnus-article-sort-by-number)
572                          (function-item gnus-article-sort-by-author)
573                          (function-item gnus-article-sort-by-subject)
574                          (function-item gnus-article-sort-by-date)
575                          (function-item gnus-article-sort-by-score)
576                          (function :tag "other"))))
577
578 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
579   "*List of functions used for sorting threads in the summary buffer.
580 By default, threads are sorted by article number.
581
582 Each function takes two threads and return non-nil if the first thread
583 should be sorted before the other.  If you use more than one function,
584 the primary sort function should be the last.  You should probably
585 always include `gnus-thread-sort-by-number' in the list of sorting
586 functions -- preferably first.
587
588 Ready-made functions include `gnus-thread-sort-by-number',
589 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
590 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
591 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
592   :group 'gnus-summary-sort
593   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
594                          (function-item gnus-thread-sort-by-author)
595                          (function-item gnus-thread-sort-by-subject)
596                          (function-item gnus-thread-sort-by-date)
597                          (function-item gnus-thread-sort-by-score)
598                          (function-item gnus-thread-sort-by-total-score)
599                          (function :tag "other"))))
600
601 (defcustom gnus-thread-score-function '+
602   "*Function used for calculating the total score of a thread.
603
604 The function is called with the scores of the article and each
605 subthread and should then return the score of the thread.
606
607 Some functions you can use are `+', `max', or `min'."
608   :group 'gnus-summary-sort
609   :type 'function)
610
611 (defcustom gnus-summary-expunge-below nil
612   "All articles that have a score less than this variable will be expunged.
613 This variable is local to the summary buffers."
614   :group 'gnus-score-default
615   :type '(choice (const :tag "off" nil)
616                  integer))
617
618 (defcustom gnus-thread-expunge-below nil
619   "All threads that have a total score less than this variable will be expunged.
620 See `gnus-thread-score-function' for en explanation of what a
621 \"thread score\" is.
622
623 This variable is local to the summary buffers."
624   :group 'gnus-threading
625   :group 'gnus-score-default
626   :type '(choice (const :tag "off" nil)
627                  integer))
628
629 (defcustom gnus-summary-mode-hook nil
630   "*A hook for Gnus summary mode.
631 This hook is run before any variables are set in the summary buffer."
632   :group 'gnus-summary-various
633   :type 'hook)
634
635 (defcustom gnus-summary-menu-hook nil
636   "*Hook run after the creation of the summary mode menu."
637   :group 'gnus-summary-visual
638   :type 'hook)
639
640 (defcustom gnus-summary-exit-hook nil
641   "*A hook called on exit from the summary buffer.
642 It will be called with point in the group buffer."
643   :group 'gnus-summary-exit
644   :type 'hook)
645
646 (defcustom gnus-summary-prepare-hook nil
647   "*A hook called after the summary buffer has been generated.
648 If you want to modify the summary buffer, you can use this hook."
649   :group 'gnus-summary-various
650   :type 'hook)
651
652 (defcustom gnus-summary-prepared-hook nil
653   "*A hook called as the last thing after the summary buffer has been generated."
654   :group 'gnus-summary-various
655   :type 'hook)
656
657 (defcustom gnus-summary-generate-hook nil
658   "*A hook run just before generating the summary buffer.
659 This hook is commonly used to customize threading variables and the
660 like."
661   :group 'gnus-summary-various
662   :type 'hook)
663
664 (defcustom gnus-select-group-hook nil
665   "*A hook called when a newsgroup is selected.
666
667 If you'd like to simplify subjects like the
668 `gnus-summary-next-same-subject' command does, you can use the
669 following hook:
670
671  (setq gnus-select-group-hook
672       (list
673         (lambda ()
674           (mapcar (lambda (header)
675                      (mail-header-set-subject
676                       header
677                       (gnus-simplify-subject
678                        (mail-header-subject header) 're-only)))
679                   gnus-newsgroup-headers))))"
680   :group 'gnus-group-select
681   :type 'hook)
682
683 (defcustom gnus-select-article-hook nil
684   "*A hook called when an article is selected."
685   :group 'gnus-summary-choose
686   :type 'hook)
687
688 (defcustom gnus-visual-mark-article-hook
689   (list 'gnus-highlight-selected-summary)
690   "*Hook run after selecting an article in the summary buffer.
691 It is meant to be used for highlighting the article in some way.  It
692 is not run if `gnus-visual' is nil."
693   :group 'gnus-summary-visual
694   :type 'hook)
695
696 (defcustom gnus-parse-headers-hook nil
697   "*A hook called before parsing the headers."
698   :group 'gnus-various
699   :type 'hook)
700
701 (defcustom gnus-exit-group-hook nil
702   "*A hook called when exiting summary mode.
703 This hook is not called from the non-updating exit commands like `Q'."
704   :group 'gnus-various
705   :type 'hook)
706
707 (defcustom gnus-summary-update-hook
708   (list 'gnus-summary-highlight-line)
709   "*A hook called when a summary line is changed.
710 The hook will not be called if `gnus-visual' is nil.
711
712 The default function `gnus-summary-highlight-line' will
713 highlight the line according to the `gnus-summary-highlight'
714 variable."
715   :group 'gnus-summary-visual
716   :type 'hook)
717
718 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
719   "*A hook called when an article is selected for the first time.
720 The hook is intended to mark an article as read (or unread)
721 automatically when it is selected."
722   :group 'gnus-summary-choose
723   :type 'hook)
724
725 (defcustom gnus-group-no-more-groups-hook nil
726   "*A hook run when returning to group mode having no more (unread) groups."
727   :group 'gnus-group-select
728   :type 'hook)
729
730 (defcustom gnus-ps-print-hook nil
731   "*A hook run before ps-printing something from Gnus."
732   :group 'gnus-summary
733   :type 'hook)
734
735 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
736   "Face used for highlighting the current article in the summary buffer."
737   :group 'gnus-summary-visual
738   :type 'face)
739
740 (defcustom gnus-summary-highlight
741   '(((= mark gnus-canceled-mark)
742      . gnus-summary-cancelled-face)
743     ((and (> score default)
744           (or (= mark gnus-dormant-mark)
745               (= mark gnus-ticked-mark)))
746      . gnus-summary-high-ticked-face)
747     ((and (< score default)
748           (or (= mark gnus-dormant-mark)
749               (= mark gnus-ticked-mark)))
750      . gnus-summary-low-ticked-face)
751     ((or (= mark gnus-dormant-mark)
752          (= mark gnus-ticked-mark))
753      . gnus-summary-normal-ticked-face)
754     ((and (> score default) (= mark gnus-ancient-mark))
755      . gnus-summary-high-ancient-face)
756     ((and (< score default) (= mark gnus-ancient-mark))
757      . gnus-summary-low-ancient-face)
758     ((= mark gnus-ancient-mark)
759      . gnus-summary-normal-ancient-face)
760     ((and (> score default) (= mark gnus-unread-mark))
761      . gnus-summary-high-unread-face)
762     ((and (< score default) (= mark gnus-unread-mark))
763      . gnus-summary-low-unread-face)
764     ((= mark gnus-unread-mark)
765      . gnus-summary-normal-unread-face)
766     ((and (> score default) (memq mark (list gnus-downloadable-mark
767                                              gnus-undownloaded-mark)))
768      . gnus-summary-high-unread-face)
769     ((and (< score default) (memq mark (list gnus-downloadable-mark
770                                              gnus-undownloaded-mark)))
771      . gnus-summary-low-unread-face)
772     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
773      . gnus-summary-normal-unread-face)
774     ((> score default)
775      . gnus-summary-high-read-face)
776     ((< score default)
777      . gnus-summary-low-read-face)
778     (t
779      . gnus-summary-normal-read-face))
780   "*Controls the highlighting of summary buffer lines.
781
782 A list of (FORM . FACE) pairs.  When deciding how a a particular
783 summary line should be displayed, each form is evaluated.  The content
784 of the face field after the first true form is used.  You can change
785 how those summary lines are displayed, by editing the face field.
786
787 You can use the following variables in the FORM field.
788
789 score:   The articles score
790 default: The default article score.
791 below:   The score below which articles are automatically marked as read.
792 mark:    The articles mark."
793   :group 'gnus-summary-visual
794   :type '(repeat (cons (sexp :tag "Form" nil)
795                        face)))
796
797 (defcustom gnus-alter-header-function nil
798   "Function called to allow alteration of article header structures.
799 The function is called with one parameter, the article header vector,
800 which it may alter in any way.")
801
802 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
803   "Variable that says which function should be used to decode a string with encoded words.")
804
805 (defcustom gnus-extra-headers nil
806   "*Extra headers to parse."
807   :group 'gnus-summary
808   :type '(repeat symbol))
809
810 (defcustom gnus-ignored-from-addresses
811   (and user-mail-address (regexp-quote user-mail-address))
812   "*Regexp of From headers that may be suppressed in favor of To headers."
813   :group 'gnus-summary
814   :type 'regexp)
815
816 (defcustom gnus-group-charset-alist
817   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
818     ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
819     ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
820     ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
821     ("^relcom\\>" koi8-r)
822     ("^fido7\\>" koi8-r)
823     ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
824     ("^israel\\>" iso-8859-1)
825     ("^han\\>" euc-kr)
826     ("^alt.chinese.text.big5\\>" chinese-big5)
827     ("^soc.culture.vietnamese\\>" vietnamese-viqr)
828     ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
829     (".*" iso-8859-1))
830   "Alist of regexps (to match group names) and default charsets to be used when reading."
831   :type '(repeat (list (regexp :tag "Group")
832                        (symbol :tag "Charset")))
833   :group 'gnus-charset)
834
835 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
836   "List of charsets that should be ignored.
837 When these charsets are used in the \"charset\" parameter, the
838 default charset will be used instead."
839   :type '(repeat symbol)
840   :group 'gnus-charset)
841
842 (defcustom gnus-group-ignored-charsets-alist 
843   '(("alt\\.chinese\\.text" iso-8859-1))
844   "Alist of regexps (to match group names) and charsets that should be ignored.
845 When these charsets are used in the \"charset\" parameter, the
846 default charset will be used instead."
847   :type '(repeat (cons (regexp :tag "Group")
848                        (repeat symbol)))
849   :group 'gnus-charset)
850
851 (defcustom gnus-group-highlight-words-alist nil
852   "Alist of group regexps and highlight regexps.
853 This variable uses the same syntax as `gnus-emphasis-alist'."
854   :type '(repeat (cons (regexp :tag "Group")
855                        (repeat (list (regexp :tag "Highlight regexp")
856                                      (number :tag "Group for entire word" 0)
857                                      (number :tag "Group for displayed part" 0)
858                                      (symbol :tag "Face" 
859                                              gnus-emphasis-highlight-words)))))
860   :group 'gnus-summary-visual)
861
862 (defcustom gnus-summary-show-article-charset-alist
863   nil
864   "Alist of number and charset.
865 The article will be shown with the charset corresponding to the
866 numbered argument.
867 For example: ((1 . cn-gb-2312) (2 . big5))."
868   :type '(repeat (cons (number :tag "Argument" 1)
869                        (symbol :tag "Charset")))
870   :group 'gnus-charset)
871
872 (defcustom gnus-preserve-marks t
873   "Whether marks are preserved when moving, copying and respooling messages."
874   :type 'boolean
875   :group 'gnus-summary-marks)
876
877 (defcustom gnus-alter-articles-to-read-function nil
878   "Function to be called to alter the list of articles to be selected."
879   :type 'function
880   :group 'gnus-summary)
881
882 ;;; Internal variables
883
884 (defvar gnus-article-mime-handles nil)
885 (defvar gnus-article-decoded-p nil)
886 (defvar gnus-scores-exclude-files nil)
887 (defvar gnus-page-broken nil)
888 (defvar gnus-inhibit-mime-unbuttonizing nil)
889
890 (defvar gnus-original-article nil)
891 (defvar gnus-article-internal-prepare-hook nil)
892 (defvar gnus-newsgroup-process-stack nil)
893
894 (defvar gnus-thread-indent-array nil)
895 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
896 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
897   "Function called to sort the articles within a thread after it has been gathered together.")
898
899 ;; Avoid highlighting in kill files.
900 (defvar gnus-summary-inhibit-highlight nil)
901 (defvar gnus-newsgroup-selected-overlay nil)
902 (defvar gnus-inhibit-limiting nil)
903 (defvar gnus-newsgroup-adaptive-score-file nil)
904 (defvar gnus-current-score-file nil)
905 (defvar gnus-current-move-group nil)
906 (defvar gnus-current-copy-group nil)
907 (defvar gnus-current-crosspost-group nil)
908
909 (defvar gnus-newsgroup-dependencies nil)
910 (defvar gnus-newsgroup-adaptive nil)
911 (defvar gnus-summary-display-article-function nil)
912 (defvar gnus-summary-highlight-line-function nil
913   "Function called after highlighting a summary line.")
914
915 (defvar gnus-summary-line-format-alist
916   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
917     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
918     (?s gnus-tmp-subject-or-nil ?s)
919     (?n gnus-tmp-name ?s)
920     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
921         ?s)
922     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
923             gnus-tmp-from) ?s)
924     (?F gnus-tmp-from ?s)
925     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
926     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
927     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
928     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
929     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
930     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
931     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
932     (?L gnus-tmp-lines ?d)
933     (?I gnus-tmp-indentation ?s)
934     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
935     (?R gnus-tmp-replied ?c)
936     (?\[ gnus-tmp-opening-bracket ?c)
937     (?\] gnus-tmp-closing-bracket ?c)
938     (?\> (make-string gnus-tmp-level ? ) ?s)
939     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
940     (?i gnus-tmp-score ?d)
941     (?z gnus-tmp-score-char ?c)
942     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
943     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
944     (?U gnus-tmp-unread ?c)
945     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
946     (?t (gnus-summary-number-of-articles-in-thread
947          (and (boundp 'thread) (car thread)) gnus-tmp-level)
948         ?d)
949     (?e (gnus-summary-number-of-articles-in-thread
950          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
951         ?c)
952     (?u gnus-tmp-user-defined ?s)
953     (?P (gnus-pick-line-number) ?d))
954   "An alist of format specifications that can appear in summary lines,
955 and what variables they correspond with, along with the type of the
956 variable (string, integer, character, etc).")
957
958 (defvar gnus-summary-dummy-line-format-alist
959   `((?S gnus-tmp-subject ?s)
960     (?N gnus-tmp-number ?d)
961     (?u gnus-tmp-user-defined ?s)))
962
963 (defvar gnus-summary-mode-line-format-alist
964   `((?G gnus-tmp-group-name ?s)
965     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
966     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
967     (?A gnus-tmp-article-number ?d)
968     (?Z gnus-tmp-unread-and-unselected ?s)
969     (?V gnus-version ?s)
970     (?U gnus-tmp-unread-and-unticked ?d)
971     (?S gnus-tmp-subject ?s)
972     (?e gnus-tmp-unselected ?d)
973     (?u gnus-tmp-user-defined ?s)
974     (?d (length gnus-newsgroup-dormant) ?d)
975     (?t (length gnus-newsgroup-marked) ?d)
976     (?r (length gnus-newsgroup-reads) ?d)
977     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
978     (?E gnus-newsgroup-expunged-tally ?d)
979     (?s (gnus-current-score-file-nondirectory) ?s)))
980
981 (defvar gnus-last-search-regexp nil
982   "Default regexp for article search command.")
983
984 (defvar gnus-last-shell-command nil
985   "Default shell command on article.")
986
987 (defvar gnus-newsgroup-begin nil)
988 (defvar gnus-newsgroup-end nil)
989 (defvar gnus-newsgroup-last-rmail nil)
990 (defvar gnus-newsgroup-last-mail nil)
991 (defvar gnus-newsgroup-last-folder nil)
992 (defvar gnus-newsgroup-last-file nil)
993 (defvar gnus-newsgroup-auto-expire nil)
994 (defvar gnus-newsgroup-active nil)
995
996 (defvar gnus-newsgroup-data nil)
997 (defvar gnus-newsgroup-data-reverse nil)
998 (defvar gnus-newsgroup-limit nil)
999 (defvar gnus-newsgroup-limits nil)
1000
1001 (defvar gnus-newsgroup-unreads nil
1002   "List of unread articles in the current newsgroup.")
1003
1004 (defvar gnus-newsgroup-unselected nil
1005   "List of unselected unread articles in the current newsgroup.")
1006
1007 (defvar gnus-newsgroup-reads nil
1008   "Alist of read articles and article marks in the current newsgroup.")
1009
1010 (defvar gnus-newsgroup-expunged-tally nil)
1011
1012 (defvar gnus-newsgroup-marked nil
1013   "List of ticked articles in the current newsgroup (a subset of unread art).")
1014
1015 (defvar gnus-newsgroup-killed nil
1016   "List of ranges of articles that have been through the scoring process.")
1017
1018 (defvar gnus-newsgroup-cached nil
1019   "List of articles that come from the article cache.")
1020
1021 (defvar gnus-newsgroup-saved nil
1022   "List of articles that have been saved.")
1023
1024 (defvar gnus-newsgroup-kill-headers nil)
1025
1026 (defvar gnus-newsgroup-replied nil
1027   "List of articles that have been replied to in the current newsgroup.")
1028
1029 (defvar gnus-newsgroup-expirable nil
1030   "List of articles in the current newsgroup that can be expired.")
1031
1032 (defvar gnus-newsgroup-processable nil
1033   "List of articles in the current newsgroup that can be processed.")
1034
1035 (defvar gnus-newsgroup-downloadable nil
1036   "List of articles in the current newsgroup that can be processed.")
1037
1038 (defvar gnus-newsgroup-undownloaded nil
1039   "List of articles in the current newsgroup that haven't been downloaded..")
1040
1041 (defvar gnus-newsgroup-unsendable nil
1042   "List of articles in the current newsgroup that won't be sent.")
1043
1044 (defvar gnus-newsgroup-bookmarks nil
1045   "List of articles in the current newsgroup that have bookmarks.")
1046
1047 (defvar gnus-newsgroup-dormant nil
1048   "List of dormant articles in the current newsgroup.")
1049
1050 (defvar gnus-newsgroup-scored nil
1051   "List of scored articles in the current newsgroup.")
1052
1053 (defvar gnus-newsgroup-headers nil
1054   "List of article headers in the current newsgroup.")
1055
1056 (defvar gnus-newsgroup-threads nil)
1057
1058 (defvar gnus-newsgroup-prepared nil
1059   "Whether the current group has been prepared properly.")
1060
1061 (defvar gnus-newsgroup-ancient nil
1062   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1063
1064 (defvar gnus-newsgroup-sparse nil)
1065
1066 (defvar gnus-current-article nil)
1067 (defvar gnus-article-current nil)
1068 (defvar gnus-current-headers nil)
1069 (defvar gnus-have-all-headers nil)
1070 (defvar gnus-last-article nil)
1071 (defvar gnus-newsgroup-history nil)
1072 (defvar gnus-newsgroup-charset nil)
1073 (defvar gnus-newsgroup-ephemeral-charset nil)
1074 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1075
1076 (defconst gnus-summary-local-variables
1077   '(gnus-newsgroup-name
1078     gnus-newsgroup-begin gnus-newsgroup-end
1079     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1080     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1081     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1082     gnus-newsgroup-unselected gnus-newsgroup-marked
1083     gnus-newsgroup-reads gnus-newsgroup-saved
1084     gnus-newsgroup-replied gnus-newsgroup-expirable
1085     gnus-newsgroup-processable gnus-newsgroup-killed
1086     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1087     gnus-newsgroup-unsendable
1088     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1089     gnus-newsgroup-headers gnus-newsgroup-threads
1090     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1091     gnus-current-article gnus-current-headers gnus-have-all-headers
1092     gnus-last-article gnus-article-internal-prepare-hook
1093     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1094     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1095     gnus-thread-expunge-below
1096     gnus-score-alist gnus-current-score-file
1097     (gnus-summary-expunge-below . global)
1098     (gnus-summary-mark-below . global)
1099     gnus-newsgroup-active gnus-scores-exclude-files
1100     gnus-newsgroup-history gnus-newsgroup-ancient
1101     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1102     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1103     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1104     (gnus-newsgroup-expunged-tally . 0)
1105     gnus-cache-removable-articles gnus-newsgroup-cached
1106     gnus-newsgroup-data gnus-newsgroup-data-reverse
1107     gnus-newsgroup-limit gnus-newsgroup-limits
1108     gnus-newsgroup-charset)
1109   "Variables that are buffer-local to the summary buffers.")
1110
1111 ;; Byte-compiler warning.
1112 (defvar gnus-article-mode-map)
1113
1114 ;; MIME stuff.
1115
1116 (defvar gnus-decode-encoded-word-methods
1117   '(mail-decode-encoded-word-string)
1118   "List of methods used to decode encoded words.
1119
1120 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item is
1121 FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1122 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1123 whose names match REGEXP.
1124
1125 For example:
1126 ((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1127  mail-decode-encoded-word-string
1128  (\"chinese\" . rfc1843-decode-string))
1129 ")
1130
1131 (defvar gnus-decode-encoded-word-methods-cache nil)
1132
1133 (defun gnus-multi-decode-encoded-word-string (string)
1134   "Apply the functions from `gnus-encoded-word-methods' that match."
1135   (unless (and gnus-decode-encoded-word-methods-cache
1136                (eq gnus-newsgroup-name
1137                    (car gnus-decode-encoded-word-methods-cache)))
1138     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1139     (mapcar (lambda (x)
1140               (if (symbolp x)
1141                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1142                 (if (and gnus-newsgroup-name
1143                          (string-match (car x) gnus-newsgroup-name))
1144                     (nconc gnus-decode-encoded-word-methods-cache
1145                            (list (cdr x))))))
1146           gnus-decode-encoded-word-methods))
1147   (let ((xlist gnus-decode-encoded-word-methods-cache))
1148     (pop xlist)
1149     (while xlist
1150       (setq string (funcall (pop xlist) string))))
1151   string)
1152
1153 ;; Subject simplification.
1154
1155 (defun gnus-simplify-whitespace (str)
1156   "Remove excessive whitespace."
1157   (let ((mystr str))
1158     ;; Multiple spaces.
1159     (while (string-match "[ \t][ \t]+" mystr)
1160       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1161                           " "
1162                           (substring mystr (match-end 0)))))
1163     ;; Leading spaces.
1164     (when (string-match "^[ \t]+" mystr)
1165       (setq mystr (substring mystr (match-end 0))))
1166     ;; Trailing spaces.
1167     (when (string-match "[ \t]+$" mystr)
1168       (setq mystr (substring mystr 0 (match-beginning 0))))
1169     mystr))
1170
1171 (defsubst gnus-simplify-subject-re (subject)
1172   "Remove \"Re:\" from subject lines."
1173   (if (string-match "^[Rr][Ee]: *" subject)
1174       (substring subject (match-end 0))
1175     subject))
1176
1177 (defun gnus-simplify-subject (subject &optional re-only)
1178   "Remove `Re:' and words in parentheses.
1179 If RE-ONLY is non-nil, strip leading `Re:'s only."
1180   (let ((case-fold-search t))           ;Ignore case.
1181     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1182     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1183       (setq subject (substring subject (match-end 0))))
1184     ;; Remove uninteresting prefixes.
1185     (when (and (not re-only)
1186                gnus-simplify-ignored-prefixes
1187                (string-match gnus-simplify-ignored-prefixes subject))
1188       (setq subject (substring subject (match-end 0))))
1189     ;; Remove words in parentheses from end.
1190     (unless re-only
1191       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1192         (setq subject (substring subject 0 (match-beginning 0)))))
1193     ;; Return subject string.
1194     subject))
1195
1196 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1197 ;; all whitespace.
1198 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1199   (goto-char (point-min))
1200   (while (re-search-forward regexp nil t)
1201     (replace-match (or newtext ""))))
1202
1203 (defun gnus-simplify-buffer-fuzzy ()
1204   "Simplify string in the buffer fuzzily.
1205 The string in the accessible portion of the current buffer is simplified.
1206 It is assumed to be a single-line subject.
1207 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1208 matter is removed.  Additional things can be deleted by setting
1209 gnus-simplify-subject-fuzzy-regexp."
1210   (let ((case-fold-search t)
1211         (modified-tick))
1212     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1213
1214     (while (not (eq modified-tick (buffer-modified-tick)))
1215       (setq modified-tick (buffer-modified-tick))
1216       (cond
1217        ((listp gnus-simplify-subject-fuzzy-regexp)
1218         (mapcar 'gnus-simplify-buffer-fuzzy-step
1219                 gnus-simplify-subject-fuzzy-regexp))
1220        (gnus-simplify-subject-fuzzy-regexp
1221         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1222       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1223       (gnus-simplify-buffer-fuzzy-step
1224        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1225       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1226
1227     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1228     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1229     (gnus-simplify-buffer-fuzzy-step " $")
1230     (gnus-simplify-buffer-fuzzy-step "^ +")))
1231
1232 (defun gnus-simplify-subject-fuzzy (subject)
1233   "Simplify a subject string fuzzily.
1234 See `gnus-simplify-buffer-fuzzy' for details."
1235   (save-excursion
1236     (gnus-set-work-buffer)
1237     (let ((case-fold-search t))
1238       ;; Remove uninteresting prefixes.
1239       (when (and gnus-simplify-ignored-prefixes
1240                  (string-match gnus-simplify-ignored-prefixes subject))
1241         (setq subject (substring subject (match-end 0))))
1242       (insert subject)
1243       (inline (gnus-simplify-buffer-fuzzy))
1244       (buffer-string))))
1245
1246 (defsubst gnus-simplify-subject-fully (subject)
1247   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1248   (cond
1249    (gnus-simplify-subject-functions
1250     (gnus-map-function gnus-simplify-subject-functions subject))
1251    ((null gnus-summary-gather-subject-limit)
1252     (gnus-simplify-subject-re subject))
1253    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1254     (gnus-simplify-subject-fuzzy subject))
1255    ((numberp gnus-summary-gather-subject-limit)
1256     (gnus-limit-string (gnus-simplify-subject-re subject)
1257                        gnus-summary-gather-subject-limit))
1258    (t
1259     subject)))
1260
1261 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1262   "Check whether two subjects are equal.
1263 If optional argument simple-first is t, first argument is already
1264 simplified."
1265   (cond
1266    ((null simple-first)
1267     (equal (gnus-simplify-subject-fully s1)
1268            (gnus-simplify-subject-fully s2)))
1269    (t
1270     (equal s1
1271            (gnus-simplify-subject-fully s2)))))
1272
1273 (defun gnus-summary-bubble-group ()
1274   "Increase the score of the current group.
1275 This is a handy function to add to `gnus-summary-exit-hook' to
1276 increase the score of each group you read."
1277   (gnus-group-add-score gnus-newsgroup-name))
1278
1279 \f
1280 ;;;
1281 ;;; Gnus summary mode
1282 ;;;
1283
1284 (put 'gnus-summary-mode 'mode-class 'special)
1285
1286 (when t
1287   ;; Non-orthogonal keys
1288
1289   (gnus-define-keys gnus-summary-mode-map
1290     " " gnus-summary-next-page
1291     "\177" gnus-summary-prev-page
1292     [delete] gnus-summary-prev-page
1293     [backspace] gnus-summary-prev-page
1294     "\r" gnus-summary-scroll-up
1295     "\M-\r" gnus-summary-scroll-down
1296     "n" gnus-summary-next-unread-article
1297     "p" gnus-summary-prev-unread-article
1298     "N" gnus-summary-next-article
1299     "P" gnus-summary-prev-article
1300     "\M-\C-n" gnus-summary-next-same-subject
1301     "\M-\C-p" gnus-summary-prev-same-subject
1302     "\M-n" gnus-summary-next-unread-subject
1303     "\M-p" gnus-summary-prev-unread-subject
1304     "." gnus-summary-first-unread-article
1305     "," gnus-summary-best-unread-article
1306     "\M-s" gnus-summary-search-article-forward
1307     "\M-r" gnus-summary-search-article-backward
1308     "<" gnus-summary-beginning-of-article
1309     ">" gnus-summary-end-of-article
1310     "j" gnus-summary-goto-article
1311     "^" gnus-summary-refer-parent-article
1312     "\M-^" gnus-summary-refer-article
1313     "u" gnus-summary-tick-article-forward
1314     "!" gnus-summary-tick-article-forward
1315     "U" gnus-summary-tick-article-backward
1316     "d" gnus-summary-mark-as-read-forward
1317     "D" gnus-summary-mark-as-read-backward
1318     "E" gnus-summary-mark-as-expirable
1319     "\M-u" gnus-summary-clear-mark-forward
1320     "\M-U" gnus-summary-clear-mark-backward
1321     "k" gnus-summary-kill-same-subject-and-select
1322     "\C-k" gnus-summary-kill-same-subject
1323     "\M-\C-k" gnus-summary-kill-thread
1324     "\M-\C-l" gnus-summary-lower-thread
1325     "e" gnus-summary-edit-article
1326     "#" gnus-summary-mark-as-processable
1327     "\M-#" gnus-summary-unmark-as-processable
1328     "\M-\C-t" gnus-summary-toggle-threads
1329     "\M-\C-s" gnus-summary-show-thread
1330     "\M-\C-h" gnus-summary-hide-thread
1331     "\M-\C-f" gnus-summary-next-thread
1332     "\M-\C-b" gnus-summary-prev-thread
1333     [(meta down)] gnus-summary-next-thread
1334     [(meta up)] gnus-summary-prev-thread
1335     "\M-\C-u" gnus-summary-up-thread
1336     "\M-\C-d" gnus-summary-down-thread
1337     "&" gnus-summary-execute-command
1338     "c" gnus-summary-catchup-and-exit
1339     "\C-w" gnus-summary-mark-region-as-read
1340     "\C-t" gnus-summary-toggle-truncation
1341     "?" gnus-summary-mark-as-dormant
1342     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1343     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1344     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1345     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1346     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1347     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1348     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1349     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1350     "=" gnus-summary-expand-window
1351     "\C-x\C-s" gnus-summary-reselect-current-group
1352     "\M-g" gnus-summary-rescan-group
1353     "w" gnus-summary-stop-page-breaking
1354     "\C-c\C-r" gnus-summary-caesar-message
1355     "f" gnus-summary-followup
1356     "F" gnus-summary-followup-with-original
1357     "C" gnus-summary-cancel-article
1358     "r" gnus-summary-reply
1359     "R" gnus-summary-reply-with-original
1360     "\C-c\C-f" gnus-summary-mail-forward
1361     "o" gnus-summary-save-article
1362     "\C-o" gnus-summary-save-article-mail
1363     "|" gnus-summary-pipe-output
1364     "\M-k" gnus-summary-edit-local-kill
1365     "\M-K" gnus-summary-edit-global-kill
1366     ;; "V" gnus-version
1367     "\C-c\C-d" gnus-summary-describe-group
1368     "q" gnus-summary-exit
1369     "Q" gnus-summary-exit-no-update
1370     "\C-c\C-i" gnus-info-find-node
1371     gnus-mouse-2 gnus-mouse-pick-article
1372     "m" gnus-summary-mail-other-window
1373     "a" gnus-summary-post-news
1374     "x" gnus-summary-limit-to-unread
1375     "s" gnus-summary-isearch-article
1376     "t" gnus-summary-toggle-header
1377     "g" gnus-summary-show-article
1378     "l" gnus-summary-goto-last-article
1379     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1380     "\C-d" gnus-summary-enter-digest-group
1381     "\M-\C-d" gnus-summary-read-document
1382     "\M-\C-e" gnus-summary-edit-parameters
1383     "\M-\C-a" gnus-summary-customize-parameters
1384     "\C-c\C-b" gnus-bug
1385     "*" gnus-cache-enter-article
1386     "\M-*" gnus-cache-remove-article
1387     "\M-&" gnus-summary-universal-argument
1388     "\C-l" gnus-recenter
1389     "I" gnus-summary-increase-score
1390     "L" gnus-summary-lower-score
1391     "\M-i" gnus-symbolic-argument
1392     "h" gnus-summary-select-article-buffer
1393
1394     "b" gnus-article-view-part
1395     "\M-t" gnus-summary-toggle-display-buttonized
1396
1397     "V" gnus-summary-score-map
1398     "X" gnus-uu-extract-map
1399     "S" gnus-summary-send-map)
1400
1401   ;; Sort of orthogonal keymap
1402   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1403     "t" gnus-summary-tick-article-forward
1404     "!" gnus-summary-tick-article-forward
1405     "d" gnus-summary-mark-as-read-forward
1406     "r" gnus-summary-mark-as-read-forward
1407     "c" gnus-summary-clear-mark-forward
1408     " " gnus-summary-clear-mark-forward
1409     "e" gnus-summary-mark-as-expirable
1410     "x" gnus-summary-mark-as-expirable
1411     "?" gnus-summary-mark-as-dormant
1412     "b" gnus-summary-set-bookmark
1413     "B" gnus-summary-remove-bookmark
1414     "#" gnus-summary-mark-as-processable
1415     "\M-#" gnus-summary-unmark-as-processable
1416     "S" gnus-summary-limit-include-expunged
1417     "C" gnus-summary-catchup
1418     "H" gnus-summary-catchup-to-here
1419     "\C-c" gnus-summary-catchup-all
1420     "k" gnus-summary-kill-same-subject-and-select
1421     "K" gnus-summary-kill-same-subject
1422     "P" gnus-uu-mark-map)
1423
1424   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1425     "c" gnus-summary-clear-above
1426     "u" gnus-summary-tick-above
1427     "m" gnus-summary-mark-above
1428     "k" gnus-summary-kill-below)
1429
1430   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1431     "/" gnus-summary-limit-to-subject
1432     "n" gnus-summary-limit-to-articles
1433     "w" gnus-summary-pop-limit
1434     "s" gnus-summary-limit-to-subject
1435     "a" gnus-summary-limit-to-author
1436     "u" gnus-summary-limit-to-unread
1437     "m" gnus-summary-limit-to-marks
1438     "M" gnus-summary-limit-exclude-marks
1439     "v" gnus-summary-limit-to-score
1440     "*" gnus-summary-limit-include-cached
1441     "D" gnus-summary-limit-include-dormant
1442     "T" gnus-summary-limit-include-thread
1443     "d" gnus-summary-limit-exclude-dormant
1444     "t" gnus-summary-limit-to-age
1445     "x" gnus-summary-limit-to-extra 
1446     "E" gnus-summary-limit-include-expunged
1447     "c" gnus-summary-limit-exclude-childless-dormant
1448     "C" gnus-summary-limit-mark-excluded-as-read)
1449
1450   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1451     "n" gnus-summary-next-unread-article
1452     "p" gnus-summary-prev-unread-article
1453     "N" gnus-summary-next-article
1454     "P" gnus-summary-prev-article
1455     "\C-n" gnus-summary-next-same-subject
1456     "\C-p" gnus-summary-prev-same-subject
1457     "\M-n" gnus-summary-next-unread-subject
1458     "\M-p" gnus-summary-prev-unread-subject
1459     "f" gnus-summary-first-unread-article
1460     "b" gnus-summary-best-unread-article
1461     "j" gnus-summary-goto-article
1462     "g" gnus-summary-goto-subject
1463     "l" gnus-summary-goto-last-article
1464     "o" gnus-summary-pop-article)
1465
1466   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1467     "k" gnus-summary-kill-thread
1468     "l" gnus-summary-lower-thread
1469     "i" gnus-summary-raise-thread
1470     "T" gnus-summary-toggle-threads
1471     "t" gnus-summary-rethread-current
1472     "^" gnus-summary-reparent-thread
1473     "s" gnus-summary-show-thread
1474     "S" gnus-summary-show-all-threads
1475     "h" gnus-summary-hide-thread
1476     "H" gnus-summary-hide-all-threads
1477     "n" gnus-summary-next-thread
1478     "p" gnus-summary-prev-thread
1479     "u" gnus-summary-up-thread
1480     "o" gnus-summary-top-thread
1481     "d" gnus-summary-down-thread
1482     "#" gnus-uu-mark-thread
1483     "\M-#" gnus-uu-unmark-thread)
1484
1485   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1486     "g" gnus-summary-prepare
1487     "c" gnus-summary-insert-cached-articles)
1488
1489   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1490     "c" gnus-summary-catchup-and-exit
1491     "C" gnus-summary-catchup-all-and-exit
1492     "E" gnus-summary-exit-no-update
1493     "Q" gnus-summary-exit
1494     "Z" gnus-summary-exit
1495     "n" gnus-summary-catchup-and-goto-next-group
1496     "R" gnus-summary-reselect-current-group
1497     "G" gnus-summary-rescan-group
1498     "N" gnus-summary-next-group
1499     "s" gnus-summary-save-newsrc
1500     "P" gnus-summary-prev-group)
1501
1502   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1503     " " gnus-summary-next-page
1504     "n" gnus-summary-next-page
1505     "\177" gnus-summary-prev-page
1506     [delete] gnus-summary-prev-page
1507     "p" gnus-summary-prev-page
1508     "\r" gnus-summary-scroll-up
1509     "\M-\r" gnus-summary-scroll-down
1510     "<" gnus-summary-beginning-of-article
1511     ">" gnus-summary-end-of-article
1512     "b" gnus-summary-beginning-of-article
1513     "e" gnus-summary-end-of-article
1514     "^" gnus-summary-refer-parent-article
1515     "r" gnus-summary-refer-parent-article
1516     "D" gnus-summary-enter-digest-group
1517     "R" gnus-summary-refer-references
1518     "T" gnus-summary-refer-thread
1519     "g" gnus-summary-show-article
1520     "s" gnus-summary-isearch-article
1521     "P" gnus-summary-print-article
1522     "t" gnus-article-babel)
1523
1524   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1525     "b" gnus-article-add-buttons
1526     "B" gnus-article-add-buttons-to-head
1527     "o" gnus-article-treat-overstrike
1528     "e" gnus-article-emphasize
1529     "w" gnus-article-fill-cited-article
1530     "Q" gnus-article-fill-long-lines
1531     "C" gnus-article-capitalize-sentences
1532     "c" gnus-article-remove-cr
1533     "q" gnus-article-de-quoted-unreadable
1534     "6" gnus-article-de-base64-unreadable
1535     "Z" gnus-article-decode-HZ
1536     "h" gnus-article-wash-html
1537     "f" gnus-article-display-x-face
1538     "l" gnus-summary-stop-page-breaking
1539     "r" gnus-summary-caesar-message
1540     "t" gnus-article-hide-headers
1541     "v" gnus-summary-verbose-headers
1542     "H" gnus-article-strip-headers-in-body
1543     "d" gnus-article-treat-dumbquotes)
1544
1545   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1546     "a" gnus-article-hide
1547     "h" gnus-article-hide-headers
1548     "b" gnus-article-hide-boring-headers
1549     "s" gnus-article-hide-signature
1550     "c" gnus-article-hide-citation
1551     "C" gnus-article-hide-citation-in-followups
1552     "l" gnus-article-hide-list-identifiers
1553     "p" gnus-article-hide-pgp
1554     "B" gnus-article-strip-banner
1555     "P" gnus-article-hide-pem
1556     "\C-c" gnus-article-hide-citation-maybe)
1557
1558   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1559     "a" gnus-article-highlight
1560     "h" gnus-article-highlight-headers
1561     "c" gnus-article-highlight-citation
1562     "s" gnus-article-highlight-signature)
1563
1564   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1565     "w" gnus-article-decode-mime-words
1566     "c" gnus-article-decode-charset
1567     "v" gnus-mime-view-all-parts
1568     "b" gnus-article-view-part)
1569
1570   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1571     "z" gnus-article-date-ut
1572     "u" gnus-article-date-ut
1573     "l" gnus-article-date-local
1574     "e" gnus-article-date-lapsed
1575     "o" gnus-article-date-original
1576     "i" gnus-article-date-iso8601
1577     "s" gnus-article-date-user)
1578
1579   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1580     "t" gnus-article-remove-trailing-blank-lines
1581     "l" gnus-article-strip-leading-blank-lines
1582     "m" gnus-article-strip-multiple-blank-lines
1583     "a" gnus-article-strip-blank-lines
1584     "A" gnus-article-strip-all-blank-lines
1585     "s" gnus-article-strip-leading-space
1586     "e" gnus-article-strip-trailing-space)
1587
1588   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1589     "v" gnus-version
1590     "f" gnus-summary-fetch-faq
1591     "d" gnus-summary-describe-group
1592     "h" gnus-summary-describe-briefly
1593     "i" gnus-info-find-node)
1594
1595   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1596     "e" gnus-summary-expire-articles
1597     "\M-\C-e" gnus-summary-expire-articles-now
1598     "\177" gnus-summary-delete-article
1599     [delete] gnus-summary-delete-article
1600     [backspace] gnus-summary-delete-article
1601     "m" gnus-summary-move-article
1602     "r" gnus-summary-respool-article
1603     "w" gnus-summary-edit-article
1604     "c" gnus-summary-copy-article
1605     "B" gnus-summary-crosspost-article
1606     "q" gnus-summary-respool-query
1607     "t" gnus-summary-respool-trace
1608     "i" gnus-summary-import-article
1609     "p" gnus-summary-article-posted-p)
1610
1611   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1612     "o" gnus-summary-save-article
1613     "m" gnus-summary-save-article-mail
1614     "F" gnus-summary-write-article-file
1615     "r" gnus-summary-save-article-rmail
1616     "f" gnus-summary-save-article-file
1617     "b" gnus-summary-save-article-body-file
1618     "h" gnus-summary-save-article-folder
1619     "v" gnus-summary-save-article-vm
1620     "p" gnus-summary-pipe-output
1621     "s" gnus-soup-add-article)
1622
1623   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1624     "b" gnus-summary-display-buttonized
1625     "m" gnus-summary-repair-multipart
1626     "v" gnus-article-view-part
1627     "o" gnus-article-save-part
1628     "c" gnus-article-copy-part
1629     "e" gnus-article-externalize-part
1630     "i" gnus-article-inline-part
1631     "|" gnus-article-pipe-part))
1632
1633 (defun gnus-summary-make-menu-bar ()
1634   (gnus-turn-off-edit-menu 'summary)
1635
1636   (unless (boundp 'gnus-summary-misc-menu)
1637
1638     (easy-menu-define
1639      gnus-summary-kill-menu gnus-summary-mode-map ""
1640      (cons
1641       "Score"
1642       (nconc
1643        (list
1644         ["Enter score..." gnus-summary-score-entry t]
1645         ["Customize" gnus-score-customize t])
1646        (gnus-make-score-map 'increase)
1647        (gnus-make-score-map 'lower)
1648        '(("Mark"
1649           ["Kill below" gnus-summary-kill-below t]
1650           ["Mark above" gnus-summary-mark-above t]
1651           ["Tick above" gnus-summary-tick-above t]
1652           ["Clear above" gnus-summary-clear-above t])
1653          ["Current score" gnus-summary-current-score t]
1654          ["Set score" gnus-summary-set-score t]
1655          ["Switch current score file..." gnus-score-change-score-file t]
1656          ["Set mark below..." gnus-score-set-mark-below t]
1657          ["Set expunge below..." gnus-score-set-expunge-below t]
1658          ["Edit current score file" gnus-score-edit-current-scores t]
1659          ["Edit score file" gnus-score-edit-file t]
1660          ["Trace score" gnus-score-find-trace t]
1661          ["Find words" gnus-score-find-favourite-words t]
1662          ["Rescore buffer" gnus-summary-rescore t]
1663          ["Increase score..." gnus-summary-increase-score t]
1664          ["Lower score..." gnus-summary-lower-score t]))))
1665
1666     ;; Define both the Article menu in the summary buffer and the equivalent
1667     ;; Commands menu in the article buffer here for consistency.
1668     (let ((innards
1669            '(("Hide"
1670               ["All" gnus-article-hide t]
1671               ["Headers" gnus-article-hide-headers t]
1672               ["Signature" gnus-article-hide-signature t]
1673               ["Citation" gnus-article-hide-citation t]
1674               ["List identifiers" gnus-article-hide-list-identifiers t]
1675               ["PGP" gnus-article-hide-pgp t]
1676               ["Banner" gnus-article-strip-banner t]
1677               ["Boring headers" gnus-article-hide-boring-headers t])
1678              ("Highlight"
1679               ["All" gnus-article-highlight t]
1680               ["Headers" gnus-article-highlight-headers t]
1681               ["Signature" gnus-article-highlight-signature t]
1682               ["Citation" gnus-article-highlight-citation t])
1683              ("MIME"
1684               ["Words" gnus-article-decode-mime-words t]
1685               ["Charset" gnus-article-decode-charset t]
1686               ["QP" gnus-article-de-quoted-unreadable t]
1687               ["Base64" gnus-article-de-base64-unreadable t]
1688               ["View all" gnus-mime-view-all-parts t])
1689              ("Date"
1690               ["Local" gnus-article-date-local t]
1691               ["ISO8601" gnus-article-date-iso8601 t]
1692               ["UT" gnus-article-date-ut t]
1693               ["Original" gnus-article-date-original t]
1694               ["Lapsed" gnus-article-date-lapsed t]
1695               ["User-defined" gnus-article-date-user t])
1696              ("Washing"
1697               ("Remove Blanks"
1698                ["Leading" gnus-article-strip-leading-blank-lines t]
1699                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1700                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1701                ["All of the above" gnus-article-strip-blank-lines t]
1702                ["All" gnus-article-strip-all-blank-lines t]
1703                ["Leading space" gnus-article-strip-leading-space t]
1704                ["Trailing space" gnus-article-strip-trailing-space t])
1705               ["Overstrike" gnus-article-treat-overstrike t]
1706               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1707               ["Emphasis" gnus-article-emphasize t]
1708               ["Word wrap" gnus-article-fill-cited-article t]
1709               ["Fill long lines" gnus-article-fill-long-lines t]
1710               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1711               ["CR" gnus-article-remove-cr t]
1712               ["Show X-Face" gnus-article-display-x-face t]
1713               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1714               ["Base64" gnus-article-de-base64-unreadable t]
1715               ["Rot 13" gnus-summary-caesar-message t]
1716               ["Unix pipe" gnus-summary-pipe-message t]
1717               ["Add buttons" gnus-article-add-buttons t]
1718               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1719               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1720               ["Verbose header" gnus-summary-verbose-headers t]
1721               ["Toggle header" gnus-summary-toggle-header t]
1722               ["Html" gnus-article-wash-html t]
1723               ["HZ" gnus-article-decode-HZ t])
1724              ("Output"
1725               ["Save in default format" gnus-summary-save-article t]
1726               ["Save in file" gnus-summary-save-article-file t]
1727               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1728               ["Save in MH folder" gnus-summary-save-article-folder t]
1729               ["Save in VM folder" gnus-summary-save-article-vm t]
1730               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1731               ["Save body in file" gnus-summary-save-article-body-file t]
1732               ["Pipe through a filter" gnus-summary-pipe-output t]
1733               ["Add to SOUP packet" gnus-soup-add-article t]
1734               ["Print" gnus-summary-print-article t])
1735              ("Backend"
1736               ["Respool article..." gnus-summary-respool-article t]
1737               ["Move article..." gnus-summary-move-article
1738                (gnus-check-backend-function
1739                 'request-move-article gnus-newsgroup-name)]
1740               ["Copy article..." gnus-summary-copy-article t]
1741               ["Crosspost article..." gnus-summary-crosspost-article
1742                (gnus-check-backend-function
1743                 'request-replace-article gnus-newsgroup-name)]
1744               ["Import file..." gnus-summary-import-article t]
1745               ["Check if posted" gnus-summary-article-posted-p t]
1746               ["Edit article" gnus-summary-edit-article
1747                (not (gnus-group-read-only-p))]
1748               ["Delete article" gnus-summary-delete-article
1749                (gnus-check-backend-function
1750                 'request-expire-articles gnus-newsgroup-name)]
1751               ["Query respool" gnus-summary-respool-query t]
1752               ["Trace respool" gnus-summary-respool-trace t]
1753               ["Delete expirable articles" gnus-summary-expire-articles-now
1754                (gnus-check-backend-function
1755                 'request-expire-articles gnus-newsgroup-name)])
1756              ("Extract"
1757               ["Uudecode" gnus-uu-decode-uu t]
1758               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1759               ["Unshar" gnus-uu-decode-unshar t]
1760               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1761               ["Save" gnus-uu-decode-save t]
1762               ["Binhex" gnus-uu-decode-binhex t]
1763               ["Postscript" gnus-uu-decode-postscript t])
1764              ("Cache"
1765               ["Enter article" gnus-cache-enter-article t]
1766               ["Remove article" gnus-cache-remove-article t])
1767              ["Translate" gnus-article-babel t]
1768              ["Select article buffer" gnus-summary-select-article-buffer t]
1769              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1770              ["Isearch article..." gnus-summary-isearch-article t]
1771              ["Beginning of the article" gnus-summary-beginning-of-article t]
1772              ["End of the article" gnus-summary-end-of-article t]
1773              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1774              ["Fetch referenced articles" gnus-summary-refer-references t]
1775              ["Fetch current thread" gnus-summary-refer-thread t]
1776              ["Fetch article with id..." gnus-summary-refer-article t]
1777              ["Redisplay" gnus-summary-show-article t])))
1778       (easy-menu-define
1779        gnus-summary-article-menu gnus-summary-mode-map ""
1780        (cons "Article" innards))
1781
1782       (easy-menu-define
1783        gnus-article-commands-menu gnus-article-mode-map ""
1784        (cons "Commands" innards)))
1785
1786     (easy-menu-define
1787      gnus-summary-thread-menu gnus-summary-mode-map ""
1788      '("Threads"
1789        ["Toggle threading" gnus-summary-toggle-threads t]
1790        ["Hide threads" gnus-summary-hide-all-threads t]
1791        ["Show threads" gnus-summary-show-all-threads t]
1792        ["Hide thread" gnus-summary-hide-thread t]
1793        ["Show thread" gnus-summary-show-thread t]
1794        ["Go to next thread" gnus-summary-next-thread t]
1795        ["Go to previous thread" gnus-summary-prev-thread t]
1796        ["Go down thread" gnus-summary-down-thread t]
1797        ["Go up thread" gnus-summary-up-thread t]
1798        ["Top of thread" gnus-summary-top-thread t]
1799        ["Mark thread as read" gnus-summary-kill-thread t]
1800        ["Lower thread score" gnus-summary-lower-thread t]
1801        ["Raise thread score" gnus-summary-raise-thread t]
1802        ["Rethread current" gnus-summary-rethread-current t]))
1803
1804     (easy-menu-define
1805      gnus-summary-post-menu gnus-summary-mode-map ""
1806      '("Post"
1807        ["Post an article" gnus-summary-post-news t]
1808        ["Followup" gnus-summary-followup t]
1809        ["Followup and yank" gnus-summary-followup-with-original t]
1810        ["Supersede article" gnus-summary-supersede-article t]
1811        ["Cancel article" gnus-summary-cancel-article t]
1812        ["Reply" gnus-summary-reply t]
1813        ["Reply and yank" gnus-summary-reply-with-original t]
1814        ["Wide reply" gnus-summary-wide-reply t]
1815        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
1816        ["Mail forward" gnus-summary-mail-forward t]
1817        ["Post forward" gnus-summary-post-forward t]
1818        ["Digest and mail" gnus-uu-digest-mail-forward t]
1819        ["Digest and post" gnus-uu-digest-post-forward t]
1820        ["Resend message" gnus-summary-resend-message t]
1821        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1822        ["Send a mail" gnus-summary-mail-other-window t]
1823        ["Uuencode and post" gnus-uu-post-news t]
1824        ["Followup via news" gnus-summary-followup-to-mail t]
1825        ["Followup via news and yank"
1826         gnus-summary-followup-to-mail-with-original t]
1827        ;;("Draft"
1828        ;;["Send" gnus-summary-send-draft t]
1829        ;;["Send bounced" gnus-resend-bounced-mail t])
1830        ))
1831
1832     (easy-menu-define
1833      gnus-summary-misc-menu gnus-summary-mode-map ""
1834      '("Misc"
1835        ("Mark Read"
1836         ["Mark as read" gnus-summary-mark-as-read-forward t]
1837         ["Mark same subject and select"
1838          gnus-summary-kill-same-subject-and-select t]
1839         ["Mark same subject" gnus-summary-kill-same-subject t]
1840         ["Catchup" gnus-summary-catchup t]
1841         ["Catchup all" gnus-summary-catchup-all t]
1842         ["Catchup to here" gnus-summary-catchup-to-here t]
1843         ["Catchup region" gnus-summary-mark-region-as-read t]
1844         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1845        ("Mark Various"
1846         ["Tick" gnus-summary-tick-article-forward t]
1847         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1848         ["Remove marks" gnus-summary-clear-mark-forward t]
1849         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1850         ["Set bookmark" gnus-summary-set-bookmark t]
1851         ["Remove bookmark" gnus-summary-remove-bookmark t])
1852        ("Mark Limit"
1853         ["Marks..." gnus-summary-limit-to-marks t]
1854         ["Subject..." gnus-summary-limit-to-subject t]
1855         ["Author..." gnus-summary-limit-to-author t]
1856         ["Age..." gnus-summary-limit-to-age t]
1857         ["Extra..." gnus-summary-limit-to-extra t]
1858         ["Score" gnus-summary-limit-to-score t]
1859         ["Unread" gnus-summary-limit-to-unread t]
1860         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1861         ["Articles" gnus-summary-limit-to-articles t]
1862         ["Pop limit" gnus-summary-pop-limit t]
1863         ["Show dormant" gnus-summary-limit-include-dormant t]
1864         ["Hide childless dormant"
1865          gnus-summary-limit-exclude-childless-dormant t]
1866         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1867         ["Hide marked" gnus-summary-limit-exclude-marks t]
1868         ["Show expunged" gnus-summary-show-all-expunged t])
1869        ("Process Mark"
1870         ["Set mark" gnus-summary-mark-as-processable t]
1871         ["Remove mark" gnus-summary-unmark-as-processable t]
1872         ["Remove all marks" gnus-summary-unmark-all-processable t]
1873         ["Mark above" gnus-uu-mark-over t]
1874         ["Mark series" gnus-uu-mark-series t]
1875         ["Mark region" gnus-uu-mark-region t]
1876         ["Unmark region" gnus-uu-unmark-region t]
1877         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1878         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1879         ["Mark all" gnus-uu-mark-all t]
1880         ["Mark buffer" gnus-uu-mark-buffer t]
1881         ["Mark sparse" gnus-uu-mark-sparse t]
1882         ["Mark thread" gnus-uu-mark-thread t]
1883         ["Unmark thread" gnus-uu-unmark-thread t]
1884         ("Process Mark Sets"
1885          ["Kill" gnus-summary-kill-process-mark t]
1886          ["Yank" gnus-summary-yank-process-mark
1887           gnus-newsgroup-process-stack]
1888          ["Save" gnus-summary-save-process-mark t]))
1889        ("Scroll article"
1890         ["Page forward" gnus-summary-next-page t]
1891         ["Page backward" gnus-summary-prev-page t]
1892         ["Line forward" gnus-summary-scroll-up t])
1893        ("Move"
1894         ["Next unread article" gnus-summary-next-unread-article t]
1895         ["Previous unread article" gnus-summary-prev-unread-article t]
1896         ["Next article" gnus-summary-next-article t]
1897         ["Previous article" gnus-summary-prev-article t]
1898         ["Next unread subject" gnus-summary-next-unread-subject t]
1899         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1900         ["Next article same subject" gnus-summary-next-same-subject t]
1901         ["Previous article same subject" gnus-summary-prev-same-subject t]
1902         ["First unread article" gnus-summary-first-unread-article t]
1903         ["Best unread article" gnus-summary-best-unread-article t]
1904         ["Go to subject number..." gnus-summary-goto-subject t]
1905         ["Go to article number..." gnus-summary-goto-article t]
1906         ["Go to the last article" gnus-summary-goto-last-article t]
1907         ["Pop article off history" gnus-summary-pop-article t])
1908        ("Sort"
1909         ["Sort by number" gnus-summary-sort-by-number t]
1910         ["Sort by author" gnus-summary-sort-by-author t]
1911         ["Sort by subject" gnus-summary-sort-by-subject t]
1912         ["Sort by date" gnus-summary-sort-by-date t]
1913         ["Sort by score" gnus-summary-sort-by-score t]
1914         ["Sort by lines" gnus-summary-sort-by-lines t]
1915         ["Sort by characters" gnus-summary-sort-by-chars t])
1916        ("Help"
1917         ["Fetch group FAQ" gnus-summary-fetch-faq t]
1918         ["Describe group" gnus-summary-describe-group t]
1919         ["Read manual" gnus-info-find-node t])
1920        ("Modes"
1921         ["Pick and read" gnus-pick-mode t]
1922         ["Binary" gnus-binary-mode t])
1923        ("Regeneration"
1924         ["Regenerate" gnus-summary-prepare t]
1925         ["Insert cached articles" gnus-summary-insert-cached-articles t]
1926         ["Toggle threading" gnus-summary-toggle-threads t])
1927        ["Filter articles..." gnus-summary-execute-command t]
1928        ["Run command on subjects..." gnus-summary-universal-argument t]
1929        ["Search articles forward..." gnus-summary-search-article-forward t]
1930        ["Search articles backward..." gnus-summary-search-article-backward t]
1931        ["Toggle line truncation" gnus-summary-toggle-truncation t]
1932        ["Expand window" gnus-summary-expand-window t]
1933        ["Expire expirable articles" gnus-summary-expire-articles
1934         (gnus-check-backend-function
1935          'request-expire-articles gnus-newsgroup-name)]
1936        ["Edit local kill file" gnus-summary-edit-local-kill t]
1937        ["Edit main kill file" gnus-summary-edit-global-kill t]
1938        ["Edit group parameters" gnus-summary-edit-parameters t]
1939        ["Customize group parameters" gnus-summary-customize-parameters t]
1940        ["Send a bug report" gnus-bug t]
1941        ("Exit"
1942         ["Catchup and exit" gnus-summary-catchup-and-exit t]
1943         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
1944         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
1945         ["Exit group" gnus-summary-exit t]
1946         ["Exit group without updating" gnus-summary-exit-no-update t]
1947         ["Exit and goto next group" gnus-summary-next-group t]
1948         ["Exit and goto prev group" gnus-summary-prev-group t]
1949         ["Reselect group" gnus-summary-reselect-current-group t]
1950         ["Rescan group" gnus-summary-rescan-group t]
1951         ["Update dribble" gnus-summary-save-newsrc t])))
1952
1953     (gnus-run-hooks 'gnus-summary-menu-hook)))
1954
1955 (defun gnus-score-set-default (var value)
1956   "A version of set that updates the GNU Emacs menu-bar."
1957   (set var value)
1958   ;; It is the message that forces the active status to be updated.
1959   (message ""))
1960
1961 (defun gnus-make-score-map (type)
1962   "Make a summary score map of type TYPE."
1963   (if t
1964       nil
1965     (let ((headers '(("author" "from" string)
1966                      ("subject" "subject" string)
1967                      ("article body" "body" string)
1968                      ("article head" "head" string)
1969                      ("xref" "xref" string)
1970                      ("extra header" "extra" string)
1971                      ("lines" "lines" number)
1972                      ("followups to author" "followup" string)))
1973           (types '((number ("less than" <)
1974                            ("greater than" >)
1975                            ("equal" =))
1976                    (string ("substring" s)
1977                            ("exact string" e)
1978                            ("fuzzy string" f)
1979                            ("regexp" r))))
1980           (perms '(("temporary" (current-time-string))
1981                    ("permanent" nil)
1982                    ("immediate" now)))
1983           header)
1984       (list
1985        (apply
1986         'nconc
1987         (list
1988          (if (eq type 'lower)
1989              "Lower score"
1990            "Increase score"))
1991         (let (outh)
1992           (while headers
1993             (setq header (car headers))
1994             (setq outh
1995                   (cons
1996                    (apply
1997                     'nconc
1998                     (list (car header))
1999                     (let ((ts (cdr (assoc (nth 2 header) types)))
2000                           outt)
2001                       (while ts
2002                         (setq outt
2003                               (cons
2004                                (apply
2005                                 'nconc
2006                                 (list (caar ts))
2007                                 (let ((ps perms)
2008                                       outp)
2009                                   (while ps
2010                                     (setq outp
2011                                           (cons
2012                                            (vector
2013                                             (caar ps)
2014                                             (list
2015                                              'gnus-summary-score-entry
2016                                              (nth 1 header)
2017                                              (if (or (string= (nth 1 header)
2018                                                               "head")
2019                                                      (string= (nth 1 header)
2020                                                               "body"))
2021                                                  ""
2022                                                (list 'gnus-summary-header
2023                                                      (nth 1 header)))
2024                                              (list 'quote (nth 1 (car ts)))
2025                                              (list 'gnus-score-delta-default
2026                                                    nil)
2027                                              (nth 1 (car ps))
2028                                              t)
2029                                             t)
2030                                            outp))
2031                                     (setq ps (cdr ps)))
2032                                   (list (nreverse outp))))
2033                                outt))
2034                         (setq ts (cdr ts)))
2035                       (list (nreverse outt))))
2036                    outh))
2037             (setq headers (cdr headers)))
2038           (list (nreverse outh))))))))
2039
2040 \f
2041
2042 (defun gnus-summary-mode (&optional group)
2043   "Major mode for reading articles.
2044
2045 All normal editing commands are switched off.
2046 \\<gnus-summary-mode-map>
2047 Each line in this buffer represents one article.  To read an
2048 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2049 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2050 respectively.
2051
2052 You can also post articles and send mail from this buffer.  To
2053 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2054 of an article, type `\\[gnus-summary-reply]'.
2055
2056 There are approx. one gazillion commands you can execute in this
2057 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2058
2059 The following commands are available:
2060
2061 \\{gnus-summary-mode-map}"
2062   (interactive)
2063   (when (gnus-visual-p 'summary-menu 'menu)
2064     (gnus-summary-make-menu-bar))
2065   (kill-all-local-variables)
2066   (gnus-summary-make-local-variables)
2067   (gnus-make-thread-indent-array)
2068   (gnus-simplify-mode-line)
2069   (setq major-mode 'gnus-summary-mode)
2070   (setq mode-name "Summary")
2071   (make-local-variable 'minor-mode-alist)
2072   (use-local-map gnus-summary-mode-map)
2073   (buffer-disable-undo)
2074   (setq buffer-read-only t)             ;Disable modification
2075   (setq truncate-lines t)
2076   (setq selective-display t)
2077   (setq selective-display-ellipses t)   ;Display `...'
2078   (gnus-summary-set-display-table)
2079   (gnus-set-default-directory)
2080   (setq gnus-newsgroup-name group)
2081   (make-local-variable 'gnus-summary-line-format)
2082   (make-local-variable 'gnus-summary-line-format-spec)
2083   (make-local-variable 'gnus-summary-dummy-line-format)
2084   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2085   (make-local-variable 'gnus-summary-mark-positions)
2086   (make-local-hook 'pre-command-hook)
2087   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2088   (gnus-run-hooks 'gnus-summary-mode-hook)
2089   (mm-enable-multibyte)
2090   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2091   (gnus-update-summary-mark-positions))
2092
2093 (defun gnus-summary-make-local-variables ()
2094   "Make all the local summary buffer variables."
2095   (let (global)
2096     (dolist (local gnus-summary-local-variables)
2097       (if (consp local)
2098           (progn
2099             (if (eq (cdr local) 'global)
2100                 ;; Copy the global value of the variable.
2101                 (setq global (symbol-value (car local)))
2102               ;; Use the value from the list.
2103               (setq global (eval (cdr local))))
2104             (set (make-local-variable (car local)) global))
2105         ;; Simple nil-valued local variable.
2106         (set (make-local-variable local) nil)))))
2107
2108 (defun gnus-summary-clear-local-variables ()
2109   (let ((locals gnus-summary-local-variables))
2110     (while locals
2111       (if (consp (car locals))
2112           (and (vectorp (caar locals))
2113                (set (caar locals) nil))
2114         (and (vectorp (car locals))
2115              (set (car locals) nil)))
2116       (setq locals (cdr locals)))))
2117
2118 ;; Summary data functions.
2119
2120 (defmacro gnus-data-number (data)
2121   `(car ,data))
2122
2123 (defmacro gnus-data-set-number (data number)
2124   `(setcar ,data ,number))
2125
2126 (defmacro gnus-data-mark (data)
2127   `(nth 1 ,data))
2128
2129 (defmacro gnus-data-set-mark (data mark)
2130   `(setcar (nthcdr 1 ,data) ,mark))
2131
2132 (defmacro gnus-data-pos (data)
2133   `(nth 2 ,data))
2134
2135 (defmacro gnus-data-set-pos (data pos)
2136   `(setcar (nthcdr 2 ,data) ,pos))
2137
2138 (defmacro gnus-data-header (data)
2139   `(nth 3 ,data))
2140
2141 (defmacro gnus-data-set-header (data header)
2142   `(setf (nth 3 ,data) ,header))
2143
2144 (defmacro gnus-data-level (data)
2145   `(nth 4 ,data))
2146
2147 (defmacro gnus-data-unread-p (data)
2148   `(= (nth 1 ,data) gnus-unread-mark))
2149
2150 (defmacro gnus-data-read-p (data)
2151   `(/= (nth 1 ,data) gnus-unread-mark))
2152
2153 (defmacro gnus-data-pseudo-p (data)
2154   `(consp (nth 3 ,data)))
2155
2156 (defmacro gnus-data-find (number)
2157   `(assq ,number gnus-newsgroup-data))
2158
2159 (defmacro gnus-data-find-list (number &optional data)
2160   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2161      (memq (assq ,number bdata)
2162            bdata)))
2163
2164 (defmacro gnus-data-make (number mark pos header level)
2165   `(list ,number ,mark ,pos ,header ,level))
2166
2167 (defun gnus-data-enter (after-article number mark pos header level offset)
2168   (let ((data (gnus-data-find-list after-article)))
2169     (unless data
2170       (error "No such article: %d" after-article))
2171     (setcdr data (cons (gnus-data-make number mark pos header level)
2172                        (cdr data)))
2173     (setq gnus-newsgroup-data-reverse nil)
2174     (gnus-data-update-list (cddr data) offset)))
2175
2176 (defun gnus-data-enter-list (after-article list &optional offset)
2177   (when list
2178     (let ((data (and after-article (gnus-data-find-list after-article)))
2179           (ilist list))
2180       (if (not (or data
2181                    after-article))
2182           (let ((odata gnus-newsgroup-data))
2183             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2184             (when offset
2185               (gnus-data-update-list odata offset)))
2186         ;; Find the last element in the list to be spliced into the main
2187         ;; list.
2188         (while (cdr list)
2189           (setq list (cdr list)))
2190         (if (not data)
2191             (progn
2192               (setcdr list gnus-newsgroup-data)
2193               (setq gnus-newsgroup-data ilist)
2194               (when offset
2195                 (gnus-data-update-list (cdr list) offset)))
2196           (setcdr list (cdr data))
2197           (setcdr data ilist)
2198           (when offset
2199             (gnus-data-update-list (cdr list) offset))))
2200       (setq gnus-newsgroup-data-reverse nil))))
2201
2202 (defun gnus-data-remove (article &optional offset)
2203   (let ((data gnus-newsgroup-data))
2204     (if (= (gnus-data-number (car data)) article)
2205         (progn
2206           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2207                 gnus-newsgroup-data-reverse nil)
2208           (when offset
2209             (gnus-data-update-list gnus-newsgroup-data offset)))
2210       (while (cdr data)
2211         (when (= (gnus-data-number (cadr data)) article)
2212           (setcdr data (cddr data))
2213           (when offset
2214             (gnus-data-update-list (cdr data) offset))
2215           (setq data nil
2216                 gnus-newsgroup-data-reverse nil))
2217         (setq data (cdr data))))))
2218
2219 (defmacro gnus-data-list (backward)
2220   `(if ,backward
2221        (or gnus-newsgroup-data-reverse
2222            (setq gnus-newsgroup-data-reverse
2223                  (reverse gnus-newsgroup-data)))
2224      gnus-newsgroup-data))
2225
2226 (defun gnus-data-update-list (data offset)
2227   "Add OFFSET to the POS of all data entries in DATA."
2228   (setq gnus-newsgroup-data-reverse nil)
2229   (while data
2230     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2231     (setq data (cdr data))))
2232
2233 (defun gnus-summary-article-pseudo-p (article)
2234   "Say whether this article is a pseudo article or not."
2235   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2236
2237 (defmacro gnus-summary-article-sparse-p (article)
2238   "Say whether this article is a sparse article or not."
2239   `(memq ,article gnus-newsgroup-sparse))
2240
2241 (defmacro gnus-summary-article-ancient-p (article)
2242   "Say whether this article is a sparse article or not."
2243   `(memq ,article gnus-newsgroup-ancient))
2244
2245 (defun gnus-article-parent-p (number)
2246   "Say whether this article is a parent or not."
2247   (let ((data (gnus-data-find-list number)))
2248     (and (cdr data)                     ; There has to be an article after...
2249          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2250             (gnus-data-level (nth 1 data))))))
2251
2252 (defun gnus-article-children (number)
2253   "Return a list of all children to NUMBER."
2254   (let* ((data (gnus-data-find-list number))
2255          (level (gnus-data-level (car data)))
2256          children)
2257     (setq data (cdr data))
2258     (while (and data
2259                 (= (gnus-data-level (car data)) (1+ level)))
2260       (push (gnus-data-number (car data)) children)
2261       (setq data (cdr data)))
2262     children))
2263
2264 (defmacro gnus-summary-skip-intangible ()
2265   "If the current article is intangible, then jump to a different article."
2266   '(let ((to (get-text-property (point) 'gnus-intangible)))
2267      (and to (gnus-summary-goto-subject to))))
2268
2269 (defmacro gnus-summary-article-intangible-p ()
2270   "Say whether this article is intangible or not."
2271   '(get-text-property (point) 'gnus-intangible))
2272
2273 (defun gnus-article-read-p (article)
2274   "Say whether ARTICLE is read or not."
2275   (not (or (memq article gnus-newsgroup-marked)
2276            (memq article gnus-newsgroup-unreads)
2277            (memq article gnus-newsgroup-unselected)
2278            (memq article gnus-newsgroup-dormant))))
2279
2280 ;; Some summary mode macros.
2281
2282 (defmacro gnus-summary-article-number ()
2283   "The article number of the article on the current line.
2284 If there isn's an article number here, then we return the current
2285 article number."
2286   '(progn
2287      (gnus-summary-skip-intangible)
2288      (or (get-text-property (point) 'gnus-number)
2289          (gnus-summary-last-subject))))
2290
2291 (defmacro gnus-summary-article-header (&optional number)
2292   "Return the header of article NUMBER."
2293   `(gnus-data-header (gnus-data-find
2294                       ,(or number '(gnus-summary-article-number)))))
2295
2296 (defmacro gnus-summary-thread-level (&optional number)
2297   "Return the level of thread that starts with article NUMBER."
2298   `(if (and (eq gnus-summary-make-false-root 'dummy)
2299             (get-text-property (point) 'gnus-intangible))
2300        0
2301      (gnus-data-level (gnus-data-find
2302                        ,(or number '(gnus-summary-article-number))))))
2303
2304 (defmacro gnus-summary-article-mark (&optional number)
2305   "Return the mark of article NUMBER."
2306   `(gnus-data-mark (gnus-data-find
2307                     ,(or number '(gnus-summary-article-number)))))
2308
2309 (defmacro gnus-summary-article-pos (&optional number)
2310   "Return the position of the line of article NUMBER."
2311   `(gnus-data-pos (gnus-data-find
2312                    ,(or number '(gnus-summary-article-number)))))
2313
2314 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2315 (defmacro gnus-summary-article-subject (&optional number)
2316   "Return current subject string or nil if nothing."
2317   `(let ((headers
2318           ,(if number
2319                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2320              '(gnus-data-header (assq (gnus-summary-article-number)
2321                                       gnus-newsgroup-data)))))
2322      (and headers
2323           (vectorp headers)
2324           (mail-header-subject headers))))
2325
2326 (defmacro gnus-summary-article-score (&optional number)
2327   "Return current article score."
2328   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2329                   gnus-newsgroup-scored))
2330        gnus-summary-default-score 0))
2331
2332 (defun gnus-summary-article-children (&optional number)
2333   "Return a list of article numbers that are children of article NUMBER."
2334   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2335          (level (gnus-data-level (car data)))
2336          l children)
2337     (while (and (setq data (cdr data))
2338                 (> (setq l (gnus-data-level (car data))) level))
2339       (and (= (1+ level) l)
2340            (push (gnus-data-number (car data))
2341                  children)))
2342     (nreverse children)))
2343
2344 (defun gnus-summary-article-parent (&optional number)
2345   "Return the article number of the parent of article NUMBER."
2346   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2347                                     (gnus-data-list t)))
2348          (level (gnus-data-level (car data))))
2349     (if (zerop level)
2350         ()                              ; This is a root.
2351       ;; We search until we find an article with a level less than
2352       ;; this one.  That function has to be the parent.
2353       (while (and (setq data (cdr data))
2354                   (not (< (gnus-data-level (car data)) level))))
2355       (and data (gnus-data-number (car data))))))
2356
2357 (defun gnus-unread-mark-p (mark)
2358   "Say whether MARK is the unread mark."
2359   (= mark gnus-unread-mark))
2360
2361 (defun gnus-read-mark-p (mark)
2362   "Say whether MARK is one of the marks that mark as read.
2363 This is all marks except unread, ticked, dormant, and expirable."
2364   (not (or (= mark gnus-unread-mark)
2365            (= mark gnus-ticked-mark)
2366            (= mark gnus-dormant-mark)
2367            (= mark gnus-expirable-mark))))
2368
2369 (defmacro gnus-article-mark (number)
2370   "Return the MARK of article NUMBER.
2371 This macro should only be used when computing the mark the \"first\"
2372 time; i.e., when generating the summary lines.  After that,
2373 `gnus-summary-article-mark' should be used to examine the
2374 marks of articles."
2375   `(cond
2376     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2377     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2378     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2379     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2380     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2381     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2382     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2383     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2384            gnus-ancient-mark))))
2385
2386 ;; Saving hidden threads.
2387
2388 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2389 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2390
2391 (defmacro gnus-save-hidden-threads (&rest forms)
2392   "Save hidden threads, eval FORMS, and restore the hidden threads."
2393   (let ((config (make-symbol "config")))
2394     `(let ((,config (gnus-hidden-threads-configuration)))
2395        (unwind-protect
2396            (save-excursion
2397              ,@forms)
2398          (gnus-restore-hidden-threads-configuration ,config)))))
2399
2400 (defun gnus-data-compute-positions ()
2401   "Compute the positions of all articles."
2402   (setq gnus-newsgroup-data-reverse nil)
2403   (let ((data gnus-newsgroup-data))
2404     (save-excursion
2405       (gnus-save-hidden-threads
2406         (gnus-summary-show-all-threads)
2407         (goto-char (point-min))
2408         (while data
2409           (while (get-text-property (point) 'gnus-intangible)
2410             (forward-line 1))
2411           (gnus-data-set-pos (car data) (+ (point) 3))
2412           (setq data (cdr data))
2413           (forward-line 1))))))
2414
2415 (defun gnus-hidden-threads-configuration ()
2416   "Return the current hidden threads configuration."
2417   (save-excursion
2418     (let (config)
2419       (goto-char (point-min))
2420       (while (search-forward "\r" nil t)
2421         (push (1- (point)) config))
2422       config)))
2423
2424 (defun gnus-restore-hidden-threads-configuration (config)
2425   "Restore hidden threads configuration from CONFIG."
2426   (let (point buffer-read-only)
2427     (while (setq point (pop config))
2428       (when (and (< point (point-max))
2429                  (goto-char point)
2430                  (eq (char-after) ?\n))
2431         (subst-char-in-region point (1+ point) ?\n ?\r)))))
2432
2433 ;; Various summary mode internalish functions.
2434
2435 (defun gnus-mouse-pick-article (e)
2436   (interactive "e")
2437   (mouse-set-point e)
2438   (gnus-summary-next-page nil t))
2439
2440 (defun gnus-summary-set-display-table ()
2441   ;; Change the display table.  Odd characters have a tendency to mess
2442   ;; up nicely formatted displays - we make all possible glyphs
2443   ;; display only a single character.
2444
2445   ;; We start from the standard display table, if any.
2446   (let ((table (or (copy-sequence standard-display-table)
2447                    (make-display-table)))
2448         (i 32))
2449     ;; Nix out all the control chars...
2450     (while (>= (setq i (1- i)) 0)
2451       (aset table i [??]))
2452     ;; ... but not newline and cr, of course.  (cr is necessary for the
2453     ;; selective display).
2454     (aset table ?\n nil)
2455     (aset table ?\r nil)
2456     ;; We keep TAB as well.
2457     (aset table ?\t nil)
2458     ;; We nix out any glyphs over 126 that are not set already.
2459     (let ((i 256))
2460       (while (>= (setq i (1- i)) 127)
2461         ;; Only modify if the entry is nil.
2462         (unless (aref table i)
2463           (aset table i [??]))))
2464     (setq buffer-display-table table)))
2465
2466 (defun gnus-summary-setup-buffer (group)
2467   "Initialize summary buffer."
2468   (let ((buffer (concat "*Summary " group "*")))
2469     (if (get-buffer buffer)
2470         (progn
2471           (set-buffer buffer)
2472           (setq gnus-summary-buffer (current-buffer))
2473           (not gnus-newsgroup-prepared))
2474       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2475       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2476       (gnus-summary-mode group)
2477       (when gnus-carpal
2478         (gnus-carpal-setup-buffer 'summary))
2479       (unless gnus-single-article-buffer
2480         (make-local-variable 'gnus-article-buffer)
2481         (make-local-variable 'gnus-article-current)
2482         (make-local-variable 'gnus-original-article-buffer))
2483       (setq gnus-newsgroup-name group)
2484       t)))
2485
2486 (defun gnus-set-global-variables ()
2487   ;; Set the global equivalents of the summary buffer-local variables
2488   ;; to the latest values they had.  These reflect the summary buffer
2489   ;; that was in action when the last article was fetched.
2490   (when (eq major-mode 'gnus-summary-mode)
2491     (setq gnus-summary-buffer (current-buffer))
2492     (let ((name gnus-newsgroup-name)
2493           (marked gnus-newsgroup-marked)
2494           (unread gnus-newsgroup-unreads)
2495           (headers gnus-current-headers)
2496           (data gnus-newsgroup-data)
2497           (summary gnus-summary-buffer)
2498           (article-buffer gnus-article-buffer)
2499           (original gnus-original-article-buffer)
2500           (gac gnus-article-current)
2501           (reffed gnus-reffed-article-number)
2502           (score-file gnus-current-score-file)
2503           (default-charset gnus-newsgroup-charset))
2504       (save-excursion
2505         (set-buffer gnus-group-buffer)
2506         (setq gnus-newsgroup-name name
2507               gnus-newsgroup-marked marked
2508               gnus-newsgroup-unreads unread
2509               gnus-current-headers headers
2510               gnus-newsgroup-data data
2511               gnus-article-current gac
2512               gnus-summary-buffer summary
2513               gnus-article-buffer article-buffer
2514               gnus-original-article-buffer original
2515               gnus-reffed-article-number reffed
2516               gnus-current-score-file score-file
2517               gnus-newsgroup-charset default-charset)
2518         ;; The article buffer also has local variables.
2519         (when (gnus-buffer-live-p gnus-article-buffer)
2520           (set-buffer gnus-article-buffer)
2521           (setq gnus-summary-buffer summary))))))
2522
2523 (defun gnus-summary-article-unread-p (article)
2524   "Say whether ARTICLE is unread or not."
2525   (memq article gnus-newsgroup-unreads))
2526
2527 (defun gnus-summary-first-article-p (&optional article)
2528   "Return whether ARTICLE is the first article in the buffer."
2529   (if (not (setq article (or article (gnus-summary-article-number))))
2530       nil
2531     (eq article (caar gnus-newsgroup-data))))
2532
2533 (defun gnus-summary-last-article-p (&optional article)
2534   "Return whether ARTICLE is the last article in the buffer."
2535   (if (not (setq article (or article (gnus-summary-article-number))))
2536       ;; All non-existent numbers are the last article.  :-)
2537       t
2538     (not (cdr (gnus-data-find-list article)))))
2539
2540 (defun gnus-make-thread-indent-array ()
2541   (let ((n 200))
2542     (unless (and gnus-thread-indent-array
2543                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2544       (setq gnus-thread-indent-array (make-vector 201 "")
2545             gnus-thread-indent-array-level gnus-thread-indent-level)
2546       (while (>= n 0)
2547         (aset gnus-thread-indent-array n
2548               (make-string (* n gnus-thread-indent-level) ? ))
2549         (setq n (1- n))))))
2550
2551 (defun gnus-update-summary-mark-positions ()
2552   "Compute where the summary marks are to go."
2553   (save-excursion
2554     (when (gnus-buffer-exists-p gnus-summary-buffer)
2555       (set-buffer gnus-summary-buffer))
2556     (let ((gnus-replied-mark 129)
2557           (gnus-score-below-mark 130)
2558           (gnus-score-over-mark 130)
2559           (gnus-download-mark 131)
2560           (spec gnus-summary-line-format-spec)
2561           gnus-visual pos)
2562       (save-excursion
2563         (gnus-set-work-buffer)
2564         (let ((gnus-summary-line-format-spec spec)
2565               (gnus-newsgroup-downloadable '((0 . t))))
2566           (gnus-summary-insert-line
2567            [0 "" "" "" "" "" 0 0 "" nil]  0 nil 128 t nil "" nil 1)
2568           (goto-char (point-min))
2569           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2570                                              (- (point) 2)))))
2571           (goto-char (point-min))
2572           (push (cons 'replied (and (search-forward "\201" nil t)
2573                                     (- (point) 2)))
2574                 pos)
2575           (goto-char (point-min))
2576           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2577                 pos)
2578           (goto-char (point-min))
2579           (push (cons 'download
2580                       (and (search-forward "\203" nil t) (- (point) 2)))
2581                 pos)))
2582       (setq gnus-summary-mark-positions pos))))
2583
2584 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2585   "Insert a dummy root in the summary buffer."
2586   (beginning-of-line)
2587   (gnus-add-text-properties
2588    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2589    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2590
2591 (defun gnus-summary-from-or-to-or-newsgroups (header)
2592   (let ((to (cdr (assq 'To (mail-header-extra header))))
2593         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2594         (mail-parse-charset gnus-newsgroup-charset)
2595         (mail-parse-ignored-charsets 
2596          (save-excursion (set-buffer gnus-summary-buffer)
2597                          gnus-newsgroup-ignored-charsets)))
2598     (cond
2599      ((and to
2600            gnus-ignored-from-addresses
2601            (string-match gnus-ignored-from-addresses
2602                          (mail-header-from header)))
2603       (concat "-> "
2604               (or (car (funcall gnus-extract-address-components
2605                                 (funcall
2606                                  gnus-decode-encoded-word-function to)))
2607                   (funcall gnus-decode-encoded-word-function to))))
2608      ((and newsgroups
2609            gnus-ignored-from-addresses
2610            (string-match gnus-ignored-from-addresses
2611                          (mail-header-from header)))
2612       (concat "=> " newsgroups))
2613      (t
2614       (or (car (funcall gnus-extract-address-components
2615                         (mail-header-from header)))
2616           (mail-header-from header))))))
2617
2618 (defun gnus-summary-insert-line (gnus-tmp-header
2619                                  gnus-tmp-level gnus-tmp-current
2620                                  gnus-tmp-unread gnus-tmp-replied
2621                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2622                                  &optional gnus-tmp-dummy gnus-tmp-score
2623                                  gnus-tmp-process)
2624   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2625          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2626          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2627          (gnus-tmp-score-char
2628           (if (or (null gnus-summary-default-score)
2629                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2630                       gnus-summary-zcore-fuzz))
2631               ?  ;Whitespace
2632             (if (< gnus-tmp-score gnus-summary-default-score)
2633                 gnus-score-below-mark gnus-score-over-mark)))
2634          (gnus-tmp-replied
2635           (cond (gnus-tmp-process gnus-process-mark)
2636                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2637                  gnus-cached-mark)
2638                 (gnus-tmp-replied gnus-replied-mark)
2639                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2640                  gnus-saved-mark)
2641                 (t gnus-unread-mark)))
2642          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2643          (gnus-tmp-name
2644           (cond
2645            ((string-match "<[^>]+> *$" gnus-tmp-from)
2646             (let ((beg (match-beginning 0)))
2647               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2648                        (substring gnus-tmp-from (1+ (match-beginning 0))
2649                                   (1- (match-end 0))))
2650                   (substring gnus-tmp-from 0 beg))))
2651            ((string-match "(.+)" gnus-tmp-from)
2652             (substring gnus-tmp-from
2653                        (1+ (match-beginning 0)) (1- (match-end 0))))
2654            (t gnus-tmp-from)))
2655          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2656          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2657          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2658          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2659          (buffer-read-only nil))
2660     (when (string= gnus-tmp-name "")
2661       (setq gnus-tmp-name gnus-tmp-from))
2662     (unless (numberp gnus-tmp-lines)
2663       (setq gnus-tmp-lines 0))
2664     (gnus-put-text-property
2665      (point)
2666      (progn (eval gnus-summary-line-format-spec) (point))
2667      'gnus-number gnus-tmp-number)
2668     (when (gnus-visual-p 'summary-highlight 'highlight)
2669       (forward-line -1)
2670       (gnus-run-hooks 'gnus-summary-update-hook)
2671       (forward-line 1))))
2672
2673 (defun gnus-summary-update-line (&optional dont-update)
2674   ;; Update summary line after change.
2675   (when (and gnus-summary-default-score
2676              (not gnus-summary-inhibit-highlight))
2677     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2678            (article (gnus-summary-article-number))
2679            (score (gnus-summary-article-score article)))
2680       (unless dont-update
2681         (if (and gnus-summary-mark-below
2682                  (< (gnus-summary-article-score)
2683                     gnus-summary-mark-below))
2684             ;; This article has a low score, so we mark it as read.
2685             (when (memq article gnus-newsgroup-unreads)
2686               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2687           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2688             ;; This article was previously marked as read on account
2689             ;; of a low score, but now it has risen, so we mark it as
2690             ;; unread.
2691             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2692         (gnus-summary-update-mark
2693          (if (or (null gnus-summary-default-score)
2694                  (<= (abs (- score gnus-summary-default-score))
2695                      gnus-summary-zcore-fuzz))
2696              ?  ;Whitespace
2697            (if (< score gnus-summary-default-score)
2698                gnus-score-below-mark gnus-score-over-mark))
2699          'score))
2700       ;; Do visual highlighting.
2701       (when (gnus-visual-p 'summary-highlight 'highlight)
2702         (gnus-run-hooks 'gnus-summary-update-hook)))))
2703
2704 (defvar gnus-tmp-new-adopts nil)
2705
2706 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2707   "Return the number of articles in THREAD.
2708 This may be 0 in some cases -- if none of the articles in
2709 the thread are to be displayed."
2710   (let* ((number
2711           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2712           (cond
2713            ((not (listp thread))
2714             1)
2715            ((and (consp thread) (cdr thread))
2716             (apply
2717              '+ 1 (mapcar
2718                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2719            ((null thread)
2720             1)
2721            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2722             1)
2723            (t 0))))
2724     (when (and level (zerop level) gnus-tmp-new-adopts)
2725       (incf number
2726             (apply '+ (mapcar
2727                        'gnus-summary-number-of-articles-in-thread
2728                        gnus-tmp-new-adopts))))
2729     (if char
2730         (if (> number 1) gnus-not-empty-thread-mark
2731           gnus-empty-thread-mark)
2732       number)))
2733
2734 (defun gnus-summary-set-local-parameters (group)
2735   "Go through the local params of GROUP and set all variable specs in that list."
2736   (let ((params (gnus-group-find-parameter group))
2737         elem)
2738     (while params
2739       (setq elem (car params)
2740             params (cdr params))
2741       (and (consp elem)                 ; Has to be a cons.
2742            (consp (cdr elem))           ; The cdr has to be a list.
2743            (symbolp (car elem))         ; Has to be a symbol in there.
2744            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2745            (ignore-errors               ; So we set it.
2746              (make-local-variable (car elem))
2747              (set (car elem) (eval (nth 1 elem))))))))
2748
2749 (defun gnus-summary-read-group (group &optional show-all no-article
2750                                       kill-buffer no-display backward
2751                                       select-articles)
2752   "Start reading news in newsgroup GROUP.
2753 If SHOW-ALL is non-nil, already read articles are also listed.
2754 If NO-ARTICLE is non-nil, no article is selected initially.
2755 If NO-DISPLAY, don't generate a summary buffer."
2756   (let (result)
2757     (while (and group
2758                 (null (setq result
2759                             (let ((gnus-auto-select-next nil))
2760                               (or (gnus-summary-read-group-1
2761                                    group show-all no-article
2762                                    kill-buffer no-display
2763                                    select-articles)
2764                                   (setq show-all nil
2765                                         select-articles nil)))))
2766                 (eq gnus-auto-select-next 'quietly))
2767       (set-buffer gnus-group-buffer)
2768       ;; The entry function called above goes to the next
2769       ;; group automatically, so we go two groups back
2770       ;; if we are searching for the previous group.
2771       (when backward
2772         (gnus-group-prev-unread-group 2))
2773       (if (not (equal group (gnus-group-group-name)))
2774           (setq group (gnus-group-group-name))
2775         (setq group nil)))
2776     result))
2777
2778 (defun gnus-summary-read-group-1 (group show-all no-article
2779                                         kill-buffer no-display
2780                                         &optional select-articles)
2781   ;; Killed foreign groups can't be entered.
2782   (when (and (not (gnus-group-native-p group))
2783              (not (gnus-gethash group gnus-newsrc-hashtb)))
2784     (error "Dead non-native groups can't be entered"))
2785   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2786   (let* ((new-group (gnus-summary-setup-buffer group))
2787          (quit-config (gnus-group-quit-config group))
2788          (did-select (and new-group (gnus-select-newsgroup
2789                                      group show-all select-articles))))
2790     (cond
2791      ;; This summary buffer exists already, so we just select it.
2792      ((not new-group)
2793       (gnus-set-global-variables)
2794       (when kill-buffer
2795         (gnus-kill-or-deaden-summary kill-buffer))
2796       (gnus-configure-windows 'summary 'force)
2797       (gnus-set-mode-line 'summary)
2798       (gnus-summary-position-point)
2799       (message "")
2800       t)
2801      ;; We couldn't select this group.
2802      ((null did-select)
2803       (when (and (eq major-mode 'gnus-summary-mode)
2804                  (not (equal (current-buffer) kill-buffer)))
2805         (kill-buffer (current-buffer))
2806         (if (not quit-config)
2807             (progn
2808               ;; Update the info -- marks might need to be removed,
2809               ;; for instance.
2810               (gnus-summary-update-info)
2811               (set-buffer gnus-group-buffer)
2812               (gnus-group-jump-to-group group)
2813               (gnus-group-next-unread-group 1))
2814           (gnus-handle-ephemeral-exit quit-config)))
2815       (gnus-message 3 "Can't select group")
2816       nil)
2817      ;; The user did a `C-g' while prompting for number of articles,
2818      ;; so we exit this group.
2819      ((eq did-select 'quit)
2820       (and (eq major-mode 'gnus-summary-mode)
2821            (not (equal (current-buffer) kill-buffer))
2822            (kill-buffer (current-buffer)))
2823       (when kill-buffer
2824         (gnus-kill-or-deaden-summary kill-buffer))
2825       (if (not quit-config)
2826           (progn
2827             (set-buffer gnus-group-buffer)
2828             (gnus-group-jump-to-group group)
2829             (gnus-group-next-unread-group 1)
2830             (gnus-configure-windows 'group 'force))
2831         (gnus-handle-ephemeral-exit quit-config))
2832       ;; Finally signal the quit.
2833       (signal 'quit nil))
2834      ;; The group was successfully selected.
2835      (t
2836       (gnus-set-global-variables)
2837       ;; Save the active value in effect when the group was entered.
2838       (setq gnus-newsgroup-active
2839             (gnus-copy-sequence
2840              (gnus-active gnus-newsgroup-name)))
2841       ;; You can change the summary buffer in some way with this hook.
2842       (gnus-run-hooks 'gnus-select-group-hook)
2843       ;; Set any local variables in the group parameters.
2844       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2845       (gnus-update-format-specifications
2846        nil 'summary 'summary-mode 'summary-dummy)
2847       (gnus-update-summary-mark-positions)
2848       ;; Do score processing.
2849       (when gnus-use-scoring
2850         (gnus-possibly-score-headers))
2851       ;; Check whether to fill in the gaps in the threads.
2852       (when gnus-build-sparse-threads
2853         (gnus-build-sparse-threads))
2854       ;; Find the initial limit.
2855       (if gnus-show-threads
2856           (if show-all
2857               (let ((gnus-newsgroup-dormant nil))
2858                 (gnus-summary-initial-limit show-all))
2859             (gnus-summary-initial-limit show-all))
2860         ;; When untreaded, all articles are always shown.
2861         (setq gnus-newsgroup-limit
2862               (mapcar
2863                (lambda (header) (mail-header-number header))
2864                gnus-newsgroup-headers)))
2865       ;; Generate the summary buffer.
2866       (unless no-display
2867         (gnus-summary-prepare))
2868       (when gnus-use-trees
2869         (gnus-tree-open group)
2870         (setq gnus-summary-highlight-line-function
2871               'gnus-tree-highlight-article))
2872       ;; If the summary buffer is empty, but there are some low-scored
2873       ;; articles or some excluded dormants, we include these in the
2874       ;; buffer.
2875       (when (and (zerop (buffer-size))
2876                  (not no-display))
2877         (cond (gnus-newsgroup-dormant
2878                (gnus-summary-limit-include-dormant))
2879               ((and gnus-newsgroup-scored show-all)
2880                (gnus-summary-limit-include-expunged t))))
2881       ;; Function `gnus-apply-kill-file' must be called in this hook.
2882       (gnus-run-hooks 'gnus-apply-kill-hook)
2883       (if (and (zerop (buffer-size))
2884                (not no-display))
2885           (progn
2886             ;; This newsgroup is empty.
2887             (gnus-summary-catchup-and-exit nil t)
2888             (gnus-message 6 "No unread news")
2889             (when kill-buffer
2890               (gnus-kill-or-deaden-summary kill-buffer))
2891             ;; Return nil from this function.
2892             nil)
2893         ;; Hide conversation thread subtrees.  We cannot do this in
2894         ;; gnus-summary-prepare-hook since kill processing may not
2895         ;; work with hidden articles.
2896         (and gnus-show-threads
2897              gnus-thread-hide-subtree
2898              (gnus-summary-hide-all-threads))
2899         (when kill-buffer
2900           (gnus-kill-or-deaden-summary kill-buffer))
2901         ;; Show first unread article if requested.
2902         (if (and (not no-article)
2903                  (not no-display)
2904                  gnus-newsgroup-unreads
2905                  gnus-auto-select-first)
2906             (progn
2907               (gnus-configure-windows 'summary)
2908               (cond
2909                ((eq gnus-auto-select-first 'best)
2910                 (gnus-summary-best-unread-article))
2911                ((eq gnus-auto-select-first t)
2912                 (gnus-summary-first-unread-article))
2913                ((gnus-functionp gnus-auto-select-first)
2914                 (funcall gnus-auto-select-first))))
2915           ;; Don't select any articles, just move point to the first
2916           ;; article in the group.
2917           (goto-char (point-min))
2918           (gnus-summary-position-point)
2919           (gnus-configure-windows 'summary 'force)
2920           (gnus-set-mode-line 'summary))
2921         (when (get-buffer-window gnus-group-buffer t)
2922           ;; Gotta use windows, because recenter does weird stuff if
2923           ;; the current buffer ain't the displayed window.
2924           (let ((owin (selected-window)))
2925             (select-window (get-buffer-window gnus-group-buffer t))
2926             (when (gnus-group-goto-group group)
2927               (recenter))
2928             (select-window owin)))
2929         ;; Mark this buffer as "prepared".
2930         (setq gnus-newsgroup-prepared t)
2931         (gnus-run-hooks 'gnus-summary-prepared-hook)
2932         t)))))
2933
2934 (defun gnus-summary-prepare ()
2935   "Generate the summary buffer."
2936   (interactive)
2937   (let ((buffer-read-only nil))
2938     (erase-buffer)
2939     (setq gnus-newsgroup-data nil
2940           gnus-newsgroup-data-reverse nil)
2941     (gnus-run-hooks 'gnus-summary-generate-hook)
2942     ;; Generate the buffer, either with threads or without.
2943     (when gnus-newsgroup-headers
2944       (gnus-summary-prepare-threads
2945        (if gnus-show-threads
2946            (gnus-sort-gathered-threads
2947             (funcall gnus-summary-thread-gathering-function
2948                      (gnus-sort-threads
2949                       (gnus-cut-threads (gnus-make-threads)))))
2950          ;; Unthreaded display.
2951          (gnus-sort-articles gnus-newsgroup-headers))))
2952     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
2953     ;; Call hooks for modifying summary buffer.
2954     (goto-char (point-min))
2955     (gnus-run-hooks 'gnus-summary-prepare-hook)))
2956
2957 (defsubst gnus-general-simplify-subject (subject)
2958   "Simply subject by the same rules as gnus-gather-threads-by-subject."
2959   (setq subject
2960         (cond
2961          ;; Truncate the subject.
2962          (gnus-simplify-subject-functions
2963           (gnus-map-function gnus-simplify-subject-functions subject))
2964          ((numberp gnus-summary-gather-subject-limit)
2965           (setq subject (gnus-simplify-subject-re subject))
2966           (if (> (length subject) gnus-summary-gather-subject-limit)
2967               (substring subject 0 gnus-summary-gather-subject-limit)
2968             subject))
2969          ;; Fuzzily simplify it.
2970          ((eq 'fuzzy gnus-summary-gather-subject-limit)
2971           (gnus-simplify-subject-fuzzy subject))
2972          ;; Just remove the leading "Re:".
2973          (t
2974           (gnus-simplify-subject-re subject))))
2975
2976   (if (and gnus-summary-gather-exclude-subject
2977            (string-match gnus-summary-gather-exclude-subject subject))
2978       nil                               ; This article shouldn't be gathered
2979     subject))
2980
2981 (defun gnus-summary-simplify-subject-query ()
2982   "Query where the respool algorithm would put this article."
2983   (interactive)
2984   (gnus-summary-select-article)
2985   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
2986
2987 (defun gnus-gather-threads-by-subject (threads)
2988   "Gather threads by looking at Subject headers."
2989   (if (not gnus-summary-make-false-root)
2990       threads
2991     (let ((hashtb (gnus-make-hashtable 1024))
2992           (prev threads)
2993           (result threads)
2994           subject hthread whole-subject)
2995       (while threads
2996         (setq subject (gnus-general-simplify-subject
2997                        (setq whole-subject (mail-header-subject
2998                                             (caar threads)))))
2999         (when subject
3000           (if (setq hthread (gnus-gethash subject hashtb))
3001               (progn
3002                 ;; We enter a dummy root into the thread, if we
3003                 ;; haven't done that already.
3004                 (unless (stringp (caar hthread))
3005                   (setcar hthread (list whole-subject (car hthread))))
3006                 ;; We add this new gathered thread to this gathered
3007                 ;; thread.
3008                 (setcdr (car hthread)
3009                         (nconc (cdar hthread) (list (car threads))))
3010                 ;; Remove it from the list of threads.
3011                 (setcdr prev (cdr threads))
3012                 (setq threads prev))
3013             ;; Enter this thread into the hash table.
3014             (gnus-sethash subject threads hashtb)))
3015         (setq prev threads)
3016         (setq threads (cdr threads)))
3017       result)))
3018
3019 (defun gnus-gather-threads-by-references (threads)
3020   "Gather threads by looking at References headers."
3021   (let ((idhashtb (gnus-make-hashtable 1024))
3022         (thhashtb (gnus-make-hashtable 1024))
3023         (prev threads)
3024         (result threads)
3025         ids references id gthread gid entered ref)
3026     (while threads
3027       (when (setq references (mail-header-references (caar threads)))
3028         (setq id (mail-header-id (caar threads))
3029               ids (gnus-split-references references)
3030               entered nil)
3031         (while (setq ref (pop ids))
3032           (setq ids (delete ref ids))
3033           (if (not (setq gid (gnus-gethash ref idhashtb)))
3034               (progn
3035                 (gnus-sethash ref id idhashtb)
3036                 (gnus-sethash id threads thhashtb))
3037             (setq gthread (gnus-gethash gid thhashtb))
3038             (unless entered
3039               ;; We enter a dummy root into the thread, if we
3040               ;; haven't done that already.
3041               (unless (stringp (caar gthread))
3042                 (setcar gthread (list (mail-header-subject (caar gthread))
3043                                       (car gthread))))
3044               ;; We add this new gathered thread to this gathered
3045               ;; thread.
3046               (setcdr (car gthread)
3047                       (nconc (cdar gthread) (list (car threads)))))
3048             ;; Add it into the thread hash table.
3049             (gnus-sethash id gthread thhashtb)
3050             (setq entered t)
3051             ;; Remove it from the list of threads.
3052             (setcdr prev (cdr threads))
3053             (setq threads prev))))
3054       (setq prev threads)
3055       (setq threads (cdr threads)))
3056     result))
3057
3058 (defun gnus-sort-gathered-threads (threads)
3059   "Sort subtreads inside each gathered thread by article number."
3060   (let ((result threads))
3061     (while threads
3062       (when (stringp (caar threads))
3063         (setcdr (car threads)
3064                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3065       (setq threads (cdr threads)))
3066     result))
3067
3068 (defun gnus-thread-loop-p (root thread)
3069   "Say whether ROOT is in THREAD."
3070   (let ((stack (list thread))
3071         (infloop 0)
3072         th)
3073     (while (setq thread (pop stack))
3074       (setq th (cdr thread))
3075       (while (and th
3076                   (not (eq (caar th) root)))
3077         (pop th))
3078       (if th
3079           ;; We have found a loop.
3080           (let (ref-dep)
3081             (setcdr thread (delq (car th) (cdr thread)))
3082             (if (boundp (setq ref-dep (intern "none"
3083                                               gnus-newsgroup-dependencies)))
3084                 (setcdr (symbol-value ref-dep)
3085                         (nconc (cdr (symbol-value ref-dep))
3086                                (list (car th))))
3087               (set ref-dep (list nil (car th))))
3088             (setq infloop 1
3089                   stack nil))
3090         ;; Push all the subthreads onto the stack.
3091         (push (cdr thread) stack)))
3092     infloop))
3093
3094 (defun gnus-make-threads ()
3095   "Go through the dependency hashtb and find the roots.  Return all threads."
3096   (let (threads)
3097     (while (catch 'infloop
3098              (mapatoms
3099               (lambda (refs)
3100                 ;; Deal with self-referencing References loops.
3101                 (when (and (car (symbol-value refs))
3102                            (not (zerop
3103                                  (apply
3104                                   '+
3105                                   (mapcar
3106                                    (lambda (thread)
3107                                      (gnus-thread-loop-p
3108                                       (car (symbol-value refs)) thread))
3109                                    (cdr (symbol-value refs)))))))
3110                   (setq threads nil)
3111                   (throw 'infloop t))
3112                 (unless (car (symbol-value refs))
3113                   ;; These threads do not refer back to any other articles,
3114                   ;; so they're roots.
3115                   (setq threads (append (cdr (symbol-value refs)) threads))))
3116               gnus-newsgroup-dependencies)))
3117     threads))
3118
3119 ;; Build the thread tree.
3120 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3121   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3122
3123 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3124 if it was already present.
3125
3126 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3127 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3128 Message-IDs will be renamed be renamed to a unique Message-ID before
3129 being entered.
3130
3131 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3132   (let* ((id (mail-header-id header))
3133          (id-dep (and id (intern id dependencies)))
3134          ref ref-dep ref-header)
3135     ;; Enter this `header' in the `dependencies' table.
3136     (cond
3137      ((not id-dep)
3138       (setq header nil))
3139      ;; The first two cases do the normal part: enter a new `header'
3140      ;; in the `dependencies' table.
3141      ((not (boundp id-dep))
3142       (set id-dep (list header)))
3143      ((null (car (symbol-value id-dep)))
3144       (setcar (symbol-value id-dep) header))
3145
3146      ;; From here the `header' was already present in the
3147      ;; `dependencies' table.
3148      (force-new
3149       ;; Overrides an existing entry;
3150       ;; just set the header part of the entry.
3151       (setcar (symbol-value id-dep) header))
3152
3153      ;; Renames the existing `header' to a unique Message-ID.
3154      ((not gnus-summary-ignore-duplicates)
3155       ;; An article with this Message-ID has already been seen.
3156       ;; We rename the Message-ID.
3157       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3158            (list header))
3159       (mail-header-set-id header id))
3160
3161      ;; The last case ignores an existing entry, except it adds any
3162      ;; additional Xrefs (in case the two articles came from different
3163      ;; servers.
3164      ;; Also sets `header' to `nil' meaning that the `dependencies'
3165      ;; table was *not* modified.
3166      (t
3167       (mail-header-set-xref
3168        (car (symbol-value id-dep))
3169        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3170                    "")
3171                (or (mail-header-xref header) "")))
3172       (setq header nil)))
3173
3174     (when header
3175       ;; First check if that we are not creating a References loop.
3176       (setq ref (gnus-parent-id (mail-header-references header)))
3177       (while (and ref
3178                   (setq ref-dep (intern-soft ref dependencies))
3179                   (boundp ref-dep)
3180                   (setq ref-header (car (symbol-value ref-dep))))
3181         (if (string= id ref)
3182             ;; Yuk!  This is a reference loop.  Make the article be a
3183             ;; root article.
3184             (progn
3185               (mail-header-set-references (car (symbol-value id-dep)) "none")
3186               (setq ref nil))
3187           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3188       (setq ref (gnus-parent-id (mail-header-references header)))
3189       (setq ref-dep (intern (or ref "none") dependencies))
3190       (if (boundp ref-dep)
3191           (setcdr (symbol-value ref-dep)
3192                   (nconc (cdr (symbol-value ref-dep))
3193                          (list (symbol-value id-dep))))
3194         (set ref-dep (list nil (symbol-value id-dep)))))
3195     header))
3196
3197 (defun gnus-build-sparse-threads ()
3198   (let ((headers gnus-newsgroup-headers)
3199         (mail-parse-charset gnus-newsgroup-charset)
3200         (gnus-summary-ignore-duplicates t)
3201         header references generation relations
3202         subject child end new-child date)
3203     ;; First we create an alist of generations/relations, where
3204     ;; generations is how much we trust the relation, and the relation
3205     ;; is parent/child.
3206     (gnus-message 7 "Making sparse threads...")
3207     (save-excursion
3208       (nnheader-set-temp-buffer " *gnus sparse threads*")
3209       (while (setq header (pop headers))
3210         (when (and (setq references (mail-header-references header))
3211                    (not (string= references "")))
3212           (insert references)
3213           (setq child (mail-header-id header)
3214                 subject (mail-header-subject header)
3215                 date (mail-header-date header)
3216                 generation 0)
3217           (while (search-backward ">" nil t)
3218             (setq end (1+ (point)))
3219             (when (search-backward "<" nil t)
3220               (setq new-child (buffer-substring (point) end))
3221               (push (list (incf generation)
3222                           child (setq child new-child)
3223                           subject date)
3224                     relations)))
3225           (when child
3226             (push (list (1+ generation) child nil subject) relations))
3227           (erase-buffer)))
3228       (kill-buffer (current-buffer)))
3229     ;; Sort over trustworthiness.
3230     (mapcar
3231      (lambda (relation)
3232        (when (gnus-dependencies-add-header
3233               (make-full-mail-header
3234                gnus-reffed-article-number
3235                (nth 3 relation) "" (or (nth 4 relation) "")
3236                (nth 1 relation)
3237                (or (nth 2 relation) "") 0 0 "")
3238               gnus-newsgroup-dependencies nil)
3239          (push gnus-reffed-article-number gnus-newsgroup-limit)
3240          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3241          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3242                gnus-newsgroup-reads)
3243          (decf gnus-reffed-article-number)))
3244      (sort relations 'car-less-than-car))
3245     (gnus-message 7 "Making sparse threads...done")))
3246
3247 (defun gnus-build-old-threads ()
3248   ;; Look at all the articles that refer back to old articles, and
3249   ;; fetch the headers for the articles that aren't there.  This will
3250   ;; build complete threads - if the roots haven't been expired by the
3251   ;; server, that is.
3252   (let ((mail-parse-charset gnus-newsgroup-charset)
3253         id heads)
3254     (mapatoms
3255      (lambda (refs)
3256        (when (not (car (symbol-value refs)))
3257          (setq heads (cdr (symbol-value refs)))
3258          (while heads
3259            (if (memq (mail-header-number (caar heads))
3260                      gnus-newsgroup-dormant)
3261                (setq heads (cdr heads))
3262              (setq id (symbol-name refs))
3263              (while (and (setq id (gnus-build-get-header id))
3264                          (not (car (gnus-id-to-thread id)))))
3265              (setq heads nil)))))
3266      gnus-newsgroup-dependencies)))
3267
3268 ;; This function has to be called with point after the article number
3269 ;; on the beginning of the line.
3270 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3271   (let ((eol (gnus-point-at-eol))
3272         (buffer (current-buffer))
3273         header)
3274
3275     ;; overview: [num subject from date id refs chars lines misc]
3276     (unwind-protect
3277         (progn
3278           (narrow-to-region (point) eol)
3279           (unless (eobp)
3280             (forward-char))
3281
3282           (setq header
3283                 (make-full-mail-header
3284                  number                 ; number
3285                  (funcall gnus-decode-encoded-word-function
3286                           (nnheader-nov-field)) ; subject
3287                  (funcall gnus-decode-encoded-word-function
3288                           (nnheader-nov-field)) ; from
3289                  (nnheader-nov-field)   ; date
3290                  (nnheader-nov-read-message-id) ; id
3291                  (nnheader-nov-field)   ; refs
3292                  (nnheader-nov-read-integer) ; chars
3293                  (nnheader-nov-read-integer) ; lines
3294                  (unless (eobp)
3295                    (nnheader-nov-field)) ; misc
3296                  (nnheader-nov-parse-extra)))) ; extra
3297
3298       (widen))
3299
3300     (when gnus-alter-header-function
3301       (funcall gnus-alter-header-function header))
3302     (gnus-dependencies-add-header header dependencies force-new)))
3303
3304 (defun gnus-build-get-header (id)
3305   ;; Look through the buffer of NOV lines and find the header to
3306   ;; ID.  Enter this line into the dependencies hash table, and return
3307   ;; the id of the parent article (if any).
3308   (let ((deps gnus-newsgroup-dependencies)
3309         found header)
3310     (prog1
3311         (save-excursion
3312           (set-buffer nntp-server-buffer)
3313           (let ((case-fold-search nil))
3314             (goto-char (point-min))
3315             (while (and (not found)
3316                         (search-forward id nil t))
3317               (beginning-of-line)
3318               (setq found (looking-at
3319                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3320                                    (regexp-quote id))))
3321               (or found (beginning-of-line 2)))
3322             (when found
3323               (beginning-of-line)
3324               (and
3325                (setq header (gnus-nov-parse-line
3326                              (read (current-buffer)) deps))
3327                (gnus-parent-id (mail-header-references header))))))
3328       (when header
3329         (let ((number (mail-header-number header)))
3330           (push number gnus-newsgroup-limit)
3331           (push header gnus-newsgroup-headers)
3332           (if (memq number gnus-newsgroup-unselected)
3333               (progn
3334                 (push number gnus-newsgroup-unreads)
3335                 (setq gnus-newsgroup-unselected
3336                       (delq number gnus-newsgroup-unselected)))
3337             (push number gnus-newsgroup-ancient)))))))
3338
3339 (defun gnus-build-all-threads ()
3340   "Read all the headers."
3341   (let ((gnus-summary-ignore-duplicates t)
3342         (mail-parse-charset gnus-newsgroup-charset)
3343         (dependencies gnus-newsgroup-dependencies)
3344         header article)
3345     (save-excursion
3346       (set-buffer nntp-server-buffer)
3347       (let ((case-fold-search nil))
3348         (goto-char (point-min))
3349         (while (not (eobp))
3350           (ignore-errors
3351             (setq article (read (current-buffer))
3352                   header (gnus-nov-parse-line article dependencies)))
3353           (when header
3354             (save-excursion
3355               (set-buffer gnus-summary-buffer)
3356               (push header gnus-newsgroup-headers)
3357               (if (memq (setq article (mail-header-number header))
3358                         gnus-newsgroup-unselected)
3359                   (progn
3360                     (push article gnus-newsgroup-unreads)
3361                     (setq gnus-newsgroup-unselected
3362                           (delq article gnus-newsgroup-unselected)))
3363                 (push article gnus-newsgroup-ancient)))
3364             (forward-line 1)))))))
3365
3366 (defun gnus-summary-update-article-line (article header)
3367   "Update the line for ARTICLE using HEADERS."
3368   (let* ((id (mail-header-id header))
3369          (thread (gnus-id-to-thread id)))
3370     (unless thread
3371       (error "Article in no thread"))
3372     ;; Update the thread.
3373     (setcar thread header)
3374     (gnus-summary-goto-subject article)
3375     (let* ((datal (gnus-data-find-list article))
3376            (data (car datal))
3377            (length (when (cdr datal)
3378                      (- (gnus-data-pos data)
3379                         (gnus-data-pos (cadr datal)))))
3380            (buffer-read-only nil)
3381            (level (gnus-summary-thread-level)))
3382       (gnus-delete-line)
3383       (gnus-summary-insert-line
3384        header level nil (gnus-article-mark article)
3385        (memq article gnus-newsgroup-replied)
3386        (memq article gnus-newsgroup-expirable)
3387        ;; Only insert the Subject string when it's different
3388        ;; from the previous Subject string.
3389        (if (and
3390             gnus-show-threads
3391             (gnus-subject-equal
3392              (condition-case ()
3393                  (mail-header-subject
3394                   (gnus-data-header
3395                    (cadr
3396                     (gnus-data-find-list
3397                      article
3398                      (gnus-data-list t)))))
3399                ;; Error on the side of excessive subjects.
3400                (error ""))
3401              (mail-header-subject header)))
3402            ""
3403          (mail-header-subject header))
3404        nil (cdr (assq article gnus-newsgroup-scored))
3405        (memq article gnus-newsgroup-processable))
3406       (when length
3407         (gnus-data-update-list
3408          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3409
3410 (defun gnus-summary-update-article (article &optional iheader)
3411   "Update ARTICLE in the summary buffer."
3412   (set-buffer gnus-summary-buffer)
3413   (let* ((header (gnus-summary-article-header article))
3414          (id (mail-header-id header))
3415          (data (gnus-data-find article))
3416          (thread (gnus-id-to-thread id))
3417          (references (mail-header-references header))
3418          (parent
3419           (gnus-id-to-thread
3420            (or (gnus-parent-id
3421                 (when (and references
3422                            (not (equal "" references)))
3423                   references))
3424                "none")))
3425          (buffer-read-only nil)
3426          (old (car thread)))
3427     (when thread
3428       (unless iheader
3429         (setcar thread nil)
3430         (when parent
3431           (delq thread parent)))
3432       (if (gnus-summary-insert-subject id header)
3433           ;; Set the (possibly) new article number in the data structure.
3434           (gnus-data-set-number data (gnus-id-to-article id))
3435         (setcar thread old)
3436         nil))))
3437
3438 (defun gnus-rebuild-thread (id &optional line)
3439   "Rebuild the thread containing ID.
3440 If LINE, insert the rebuilt thread starting on line LINE."
3441   (let ((buffer-read-only nil)
3442         old-pos current thread data)
3443     (if (not gnus-show-threads)
3444         (setq thread (list (car (gnus-id-to-thread id))))
3445       ;; Get the thread this article is part of.
3446       (setq thread (gnus-remove-thread id)))
3447     (setq old-pos (gnus-point-at-bol))
3448     (setq current (save-excursion
3449                     (and (zerop (forward-line -1))
3450                          (gnus-summary-article-number))))
3451     ;; If this is a gathered thread, we have to go some re-gathering.
3452     (when (stringp (car thread))
3453       (let ((subject (car thread))
3454             roots thr)
3455         (setq thread (cdr thread))
3456         (while thread
3457           (unless (memq (setq thr (gnus-id-to-thread
3458                                    (gnus-root-id
3459                                     (mail-header-id (caar thread)))))
3460                         roots)
3461             (push thr roots))
3462           (setq thread (cdr thread)))
3463         ;; We now have all (unique) roots.
3464         (if (= (length roots) 1)
3465             ;; All the loose roots are now one solid root.
3466             (setq thread (car roots))
3467           (setq thread (cons subject (gnus-sort-threads roots))))))
3468     (let (threads)
3469       ;; We then insert this thread into the summary buffer.
3470       (when line
3471         (goto-char (point-min))
3472         (forward-line (1- line)))
3473       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3474         (if gnus-show-threads
3475             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3476           (gnus-summary-prepare-unthreaded thread))
3477         (setq data (nreverse gnus-newsgroup-data))
3478         (setq threads gnus-newsgroup-threads))
3479       ;; We splice the new data into the data structure.
3480       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3481       ;;!!! then we want to insert at the beginning of the buffer.
3482       ;;!!! That happens to be true with Gnus now, but that may
3483       ;;!!! change in the future.  Perhaps.
3484       (gnus-data-enter-list
3485        (if line nil current) data (- (point) old-pos))
3486       (setq gnus-newsgroup-threads
3487             (nconc threads gnus-newsgroup-threads))
3488       (gnus-data-compute-positions))))
3489
3490 (defun gnus-number-to-header (number)
3491   "Return the header for article NUMBER."
3492   (let ((headers gnus-newsgroup-headers))
3493     (while (and headers
3494                 (not (= number (mail-header-number (car headers)))))
3495       (pop headers))
3496     (when headers
3497       (car headers))))
3498
3499 (defun gnus-parent-headers (in-headers &optional generation)
3500   "Return the headers of the GENERATIONeth parent of HEADERS."
3501   (unless generation
3502     (setq generation 1))
3503   (let ((parent t)
3504         (headers in-headers)
3505         references)
3506     (while (and parent
3507                 (not (zerop generation))
3508                 (setq references (mail-header-references headers)))
3509       (setq headers (if (and references
3510                              (setq parent (gnus-parent-id references)))
3511                         (car (gnus-id-to-thread parent))
3512                       nil))
3513       (decf generation))
3514     (and (not (eq headers in-headers))
3515          headers)))
3516
3517 (defun gnus-id-to-thread (id)
3518   "Return the (sub-)thread where ID appears."
3519   (gnus-gethash id gnus-newsgroup-dependencies))
3520
3521 (defun gnus-id-to-article (id)
3522   "Return the article number of ID."
3523   (let ((thread (gnus-id-to-thread id)))
3524     (when (and thread
3525                (car thread))
3526       (mail-header-number (car thread)))))
3527
3528 (defun gnus-id-to-header (id)
3529   "Return the article headers of ID."
3530   (car (gnus-id-to-thread id)))
3531
3532 (defun gnus-article-displayed-root-p (article)
3533   "Say whether ARTICLE is a root(ish) article."
3534   (let ((level (gnus-summary-thread-level article))
3535         (refs (mail-header-references  (gnus-summary-article-header article)))
3536         particle)
3537     (cond
3538      ((null level) nil)
3539      ((zerop level) t)
3540      ((null refs) t)
3541      ((null (gnus-parent-id refs)) t)
3542      ((and (= 1 level)
3543            (null (setq particle (gnus-id-to-article
3544                                  (gnus-parent-id refs))))
3545            (null (gnus-summary-thread-level particle)))))))
3546
3547 (defun gnus-root-id (id)
3548   "Return the id of the root of the thread where ID appears."
3549   (let (last-id prev)
3550     (while (and id (setq prev (car (gnus-id-to-thread id))))
3551       (setq last-id id
3552             id (gnus-parent-id (mail-header-references prev))))
3553     last-id))
3554
3555 (defun gnus-articles-in-thread (thread)
3556   "Return the list of articles in THREAD."
3557   (cons (mail-header-number (car thread))
3558         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3559
3560 (defun gnus-remove-thread (id &optional dont-remove)
3561   "Remove the thread that has ID in it."
3562   (let (headers thread last-id)
3563     ;; First go up in this thread until we find the root.
3564     (setq last-id (gnus-root-id id)
3565           headers (message-flatten-list (gnus-id-to-thread last-id)))
3566     ;; We have now found the real root of this thread.  It might have
3567     ;; been gathered into some loose thread, so we have to search
3568     ;; through the threads to find the thread we wanted.
3569     (let ((threads gnus-newsgroup-threads)
3570           sub)
3571       (while threads
3572         (setq sub (car threads))
3573         (if (stringp (car sub))
3574             ;; This is a gathered thread, so we look at the roots
3575             ;; below it to find whether this article is in this
3576             ;; gathered root.
3577             (progn
3578               (setq sub (cdr sub))
3579               (while sub
3580                 (when (member (caar sub) headers)
3581                   (setq thread (car threads)
3582                         threads nil
3583                         sub nil))
3584                 (setq sub (cdr sub))))
3585           ;; It's an ordinary thread, so we check it.
3586           (when (eq (car sub) (car headers))
3587             (setq thread sub
3588                   threads nil)))
3589         (setq threads (cdr threads)))
3590       ;; If this article is in no thread, then it's a root.
3591       (if thread
3592           (unless dont-remove
3593             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3594         (setq thread (gnus-id-to-thread last-id)))
3595       (when thread
3596         (prog1
3597             thread                      ; We return this thread.
3598           (unless dont-remove
3599             (if (stringp (car thread))
3600                 (progn
3601                   ;; If we use dummy roots, then we have to remove the
3602                   ;; dummy root as well.
3603                   (when (eq gnus-summary-make-false-root 'dummy)
3604                     ;; We go to the dummy root by going to
3605                     ;; the first sub-"thread", and then one line up.
3606                     (gnus-summary-goto-article
3607                      (mail-header-number (caadr thread)))
3608                     (forward-line -1)
3609                     (gnus-delete-line)
3610                     (gnus-data-compute-positions))
3611                   (setq thread (cdr thread))
3612                   (while thread
3613                     (gnus-remove-thread-1 (car thread))
3614                     (setq thread (cdr thread))))
3615               (gnus-remove-thread-1 thread))))))))
3616
3617 (defun gnus-remove-thread-1 (thread)
3618   "Remove the thread THREAD recursively."
3619   (let ((number (mail-header-number (pop thread)))
3620         d)
3621     (setq thread (reverse thread))
3622     (while thread
3623       (gnus-remove-thread-1 (pop thread)))
3624     (when (setq d (gnus-data-find number))
3625       (goto-char (gnus-data-pos d))
3626       (gnus-summary-show-thread)
3627       (gnus-data-remove
3628        number
3629        (- (gnus-point-at-bol)
3630           (prog1
3631               (1+ (gnus-point-at-eol))
3632             (gnus-delete-line)))))))
3633
3634 (defun gnus-sort-threads (threads)
3635   "Sort THREADS."
3636   (if (not gnus-thread-sort-functions)
3637       threads
3638     (gnus-message 8 "Sorting threads...")
3639     (prog1
3640         (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
3641       (gnus-message 8 "Sorting threads...done"))))
3642
3643 (defun gnus-sort-articles (articles)
3644   "Sort ARTICLES."
3645   (when gnus-article-sort-functions
3646     (gnus-message 7 "Sorting articles...")
3647     (prog1
3648         (setq gnus-newsgroup-headers
3649               (sort articles (gnus-make-sort-function
3650                               gnus-article-sort-functions)))
3651       (gnus-message 7 "Sorting articles...done"))))
3652
3653 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3654 (defmacro gnus-thread-header (thread)
3655   ;; Return header of first article in THREAD.
3656   ;; Note that THREAD must never, ever be anything else than a variable -
3657   ;; using some other form will lead to serious barfage.
3658   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3659   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3660   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" 
3661         (vector thread) 2))
3662
3663 (defsubst gnus-article-sort-by-number (h1 h2)
3664   "Sort articles by article number."
3665   (< (mail-header-number h1)
3666      (mail-header-number h2)))
3667
3668 (defun gnus-thread-sort-by-number (h1 h2)
3669   "Sort threads by root article number."
3670   (gnus-article-sort-by-number
3671    (gnus-thread-header h1) (gnus-thread-header h2)))
3672
3673 (defsubst gnus-article-sort-by-lines (h1 h2)
3674   "Sort articles by article Lines header."
3675   (< (mail-header-lines h1)
3676      (mail-header-lines h2)))
3677
3678 (defun gnus-thread-sort-by-lines (h1 h2)
3679   "Sort threads by root article Lines header."
3680   (gnus-article-sort-by-lines
3681    (gnus-thread-header h1) (gnus-thread-header h2)))
3682
3683 (defsubst gnus-article-sort-by-chars (h1 h2)
3684   "Sort articles by octet length."
3685   (< (mail-header-chars h1)
3686      (mail-header-chars h2)))
3687
3688 (defun gnus-thread-sort-by-chars (h1 h2)
3689   "Sort threads by root article octet length."
3690   (gnus-article-sort-by-chars
3691    (gnus-thread-header h1) (gnus-thread-header h2)))
3692
3693 (defsubst gnus-article-sort-by-author (h1 h2)
3694   "Sort articles by root author."
3695   (string-lessp
3696    (let ((extract (funcall
3697                    gnus-extract-address-components
3698                    (mail-header-from h1))))
3699      (or (car extract) (cadr extract) ""))
3700    (let ((extract (funcall
3701                    gnus-extract-address-components
3702                    (mail-header-from h2))))
3703      (or (car extract) (cadr extract) ""))))
3704
3705 (defun gnus-thread-sort-by-author (h1 h2)
3706   "Sort threads by root author."
3707   (gnus-article-sort-by-author
3708    (gnus-thread-header h1)  (gnus-thread-header h2)))
3709
3710 (defsubst gnus-article-sort-by-subject (h1 h2)
3711   "Sort articles by root subject."
3712   (string-lessp
3713    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3714    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3715
3716 (defun gnus-thread-sort-by-subject (h1 h2)
3717   "Sort threads by root subject."
3718   (gnus-article-sort-by-subject
3719    (gnus-thread-header h1) (gnus-thread-header h2)))
3720
3721 (defsubst gnus-article-sort-by-date (h1 h2)
3722   "Sort articles by root article date."
3723   (time-less-p
3724    (gnus-date-get-time (mail-header-date h1))
3725    (gnus-date-get-time (mail-header-date h2))))
3726
3727 (defun gnus-thread-sort-by-date (h1 h2)
3728   "Sort threads by root article date."
3729   (gnus-article-sort-by-date
3730    (gnus-thread-header h1) (gnus-thread-header h2)))
3731
3732 (defsubst gnus-article-sort-by-score (h1 h2)
3733   "Sort articles by root article score.
3734 Unscored articles will be counted as having a score of zero."
3735   (> (or (cdr (assq (mail-header-number h1)
3736                     gnus-newsgroup-scored))
3737          gnus-summary-default-score 0)
3738      (or (cdr (assq (mail-header-number h2)
3739                     gnus-newsgroup-scored))
3740          gnus-summary-default-score 0)))
3741
3742 (defun gnus-thread-sort-by-score (h1 h2)
3743   "Sort threads by root article score."
3744   (gnus-article-sort-by-score
3745    (gnus-thread-header h1) (gnus-thread-header h2)))
3746
3747 (defun gnus-thread-sort-by-total-score (h1 h2)
3748   "Sort threads by the sum of all scores in the thread.
3749 Unscored articles will be counted as having a score of zero."
3750   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3751
3752 (defun gnus-thread-total-score (thread)
3753   ;; This function find the total score of THREAD.
3754   (cond ((null thread)
3755          0)
3756         ((consp thread)
3757          (if (stringp (car thread))
3758              (apply gnus-thread-score-function 0
3759                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3760            (gnus-thread-total-score-1 thread)))
3761         (t
3762          (gnus-thread-total-score-1 (list thread)))))
3763
3764 (defun gnus-thread-total-score-1 (root)
3765   ;; This function find the total score of the thread below ROOT.
3766   (setq root (car root))
3767   (apply gnus-thread-score-function
3768          (or (append
3769               (mapcar 'gnus-thread-total-score
3770                       (cdr (gnus-id-to-thread (mail-header-id root))))
3771               (when (> (mail-header-number root) 0)
3772                 (list (or (cdr (assq (mail-header-number root)
3773                                      gnus-newsgroup-scored))
3774                           gnus-summary-default-score 0))))
3775              (list gnus-summary-default-score)
3776              '(0))))
3777
3778 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3779 (defvar gnus-tmp-prev-subject nil)
3780 (defvar gnus-tmp-false-parent nil)
3781 (defvar gnus-tmp-root-expunged nil)
3782 (defvar gnus-tmp-dummy-line nil)
3783
3784 (defvar gnus-tmp-header)
3785 (defun gnus-extra-header (type &optional header)
3786   "Return the extra header of TYPE."
3787   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3788       ""))
3789
3790 (defun gnus-summary-prepare-threads (threads)
3791   "Prepare summary buffer from THREADS and indentation LEVEL.
3792 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3793 or a straight list of headers."
3794   (gnus-message 7 "Generating summary...")
3795
3796   (setq gnus-newsgroup-threads threads)
3797   (beginning-of-line)
3798
3799   (let ((gnus-tmp-level 0)
3800         (default-score (or gnus-summary-default-score 0))
3801         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3802         thread number subject stack state gnus-tmp-gathered beg-match
3803         new-roots gnus-tmp-new-adopts thread-end
3804         gnus-tmp-header gnus-tmp-unread
3805         gnus-tmp-replied gnus-tmp-subject-or-nil
3806         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3807         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3808         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3809
3810     (setq gnus-tmp-prev-subject nil)
3811
3812     (if (vectorp (car threads))
3813         ;; If this is a straight (sic) list of headers, then a
3814         ;; threaded summary display isn't required, so we just create
3815         ;; an unthreaded one.
3816         (gnus-summary-prepare-unthreaded threads)
3817
3818       ;; Do the threaded display.
3819
3820       (while (or threads stack gnus-tmp-new-adopts new-roots)
3821
3822         (if (and (= gnus-tmp-level 0)
3823                  (or (not stack)
3824                      (= (caar stack) 0))
3825                  (not gnus-tmp-false-parent)
3826                  (or gnus-tmp-new-adopts new-roots))
3827             (if gnus-tmp-new-adopts
3828                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3829                       thread (list (car gnus-tmp-new-adopts))
3830                       gnus-tmp-header (caar thread)
3831                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3832               (when new-roots
3833                 (setq thread (list (car new-roots))
3834                       gnus-tmp-header (caar thread)
3835                       new-roots (cdr new-roots))))
3836
3837           (if threads
3838               ;; If there are some threads, we do them before the
3839               ;; threads on the stack.
3840               (setq thread threads
3841                     gnus-tmp-header (caar thread))
3842             ;; There were no current threads, so we pop something off
3843             ;; the stack.
3844             (setq state (car stack)
3845                   gnus-tmp-level (car state)
3846                   thread (cdr state)
3847                   stack (cdr stack)
3848                   gnus-tmp-header (caar thread))))
3849
3850         (setq gnus-tmp-false-parent nil)
3851         (setq gnus-tmp-root-expunged nil)
3852         (setq thread-end nil)
3853
3854         (if (stringp gnus-tmp-header)
3855             ;; The header is a dummy root.
3856             (cond
3857              ((eq gnus-summary-make-false-root 'adopt)
3858               ;; We let the first article adopt the rest.
3859               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3860                                                (cddar thread)))
3861               (setq gnus-tmp-gathered
3862                     (nconc (mapcar
3863                             (lambda (h) (mail-header-number (car h)))
3864                             (cddar thread))
3865                            gnus-tmp-gathered))
3866               (setq thread (cons (list (caar thread)
3867                                        (cadar thread))
3868                                  (cdr thread)))
3869               (setq gnus-tmp-level -1
3870                     gnus-tmp-false-parent t))
3871              ((eq gnus-summary-make-false-root 'empty)
3872               ;; We print adopted articles with empty subject fields.
3873               (setq gnus-tmp-gathered
3874                     (nconc (mapcar
3875                             (lambda (h) (mail-header-number (car h)))
3876                             (cddar thread))
3877                            gnus-tmp-gathered))
3878               (setq gnus-tmp-level -1))
3879              ((eq gnus-summary-make-false-root 'dummy)
3880               ;; We remember that we probably want to output a dummy
3881               ;; root.
3882               (setq gnus-tmp-dummy-line gnus-tmp-header)
3883               (setq gnus-tmp-prev-subject gnus-tmp-header))
3884              (t
3885               ;; We do not make a root for the gathered
3886               ;; sub-threads at all.
3887               (setq gnus-tmp-level -1)))
3888
3889           (setq number (mail-header-number gnus-tmp-header)
3890                 subject (mail-header-subject gnus-tmp-header))
3891
3892           (cond
3893            ;; If the thread has changed subject, we might want to make
3894            ;; this subthread into a root.
3895            ((and (null gnus-thread-ignore-subject)
3896                  (not (zerop gnus-tmp-level))
3897                  gnus-tmp-prev-subject
3898                  (not (inline
3899                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
3900             (setq new-roots (nconc new-roots (list (car thread)))
3901                   thread-end t
3902                   gnus-tmp-header nil))
3903            ;; If the article lies outside the current limit,
3904            ;; then we do not display it.
3905            ((not (memq number gnus-newsgroup-limit))
3906             (setq gnus-tmp-gathered
3907                   (nconc (mapcar
3908                           (lambda (h) (mail-header-number (car h)))
3909                           (cdar thread))
3910                          gnus-tmp-gathered))
3911             (setq gnus-tmp-new-adopts (if (cdar thread)
3912                                           (append gnus-tmp-new-adopts
3913                                                   (cdar thread))
3914                                         gnus-tmp-new-adopts)
3915                   thread-end t
3916                   gnus-tmp-header nil)
3917             (when (zerop gnus-tmp-level)
3918               (setq gnus-tmp-root-expunged t)))
3919            ;; Perhaps this article is to be marked as read?
3920            ((and gnus-summary-mark-below
3921                  (< (or (cdr (assq number gnus-newsgroup-scored))
3922                         default-score)
3923                     gnus-summary-mark-below)
3924                  ;; Don't touch sparse articles.
3925                  (not (gnus-summary-article-sparse-p number))
3926                  (not (gnus-summary-article-ancient-p number)))
3927             (setq gnus-newsgroup-unreads
3928                   (delq number gnus-newsgroup-unreads))
3929             (if gnus-newsgroup-auto-expire
3930                 (push number gnus-newsgroup-expirable)
3931               (push (cons number gnus-low-score-mark)
3932                     gnus-newsgroup-reads))))
3933
3934           (when gnus-tmp-header
3935             ;; We may have an old dummy line to output before this
3936             ;; article.
3937             (when (and gnus-tmp-dummy-line
3938                        (gnus-subject-equal
3939                         gnus-tmp-dummy-line
3940                         (mail-header-subject gnus-tmp-header)))
3941               (gnus-summary-insert-dummy-line
3942                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
3943               (setq gnus-tmp-dummy-line nil))
3944
3945             ;; Compute the mark.
3946             (setq gnus-tmp-unread (gnus-article-mark number))
3947
3948             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
3949                                   gnus-tmp-header gnus-tmp-level)
3950                   gnus-newsgroup-data)
3951
3952             ;; Actually insert the line.
3953             (setq
3954              gnus-tmp-subject-or-nil
3955              (cond
3956               ((and gnus-thread-ignore-subject
3957                     gnus-tmp-prev-subject
3958                     (not (inline (gnus-subject-equal
3959                                   gnus-tmp-prev-subject subject))))
3960                subject)
3961               ((zerop gnus-tmp-level)
3962                (if (and (eq gnus-summary-make-false-root 'empty)
3963                         (memq number gnus-tmp-gathered)
3964                         gnus-tmp-prev-subject
3965                         (inline (gnus-subject-equal
3966                                  gnus-tmp-prev-subject subject)))
3967                    gnus-summary-same-subject
3968                  subject))
3969               (t gnus-summary-same-subject)))
3970             (if (and (eq gnus-summary-make-false-root 'adopt)
3971                      (= gnus-tmp-level 1)
3972                      (memq number gnus-tmp-gathered))
3973                 (setq gnus-tmp-opening-bracket ?\<
3974                       gnus-tmp-closing-bracket ?\>)
3975               (setq gnus-tmp-opening-bracket ?\[
3976                     gnus-tmp-closing-bracket ?\]))
3977             (setq
3978              gnus-tmp-indentation
3979              (aref gnus-thread-indent-array gnus-tmp-level)
3980              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
3981              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
3982                                 gnus-summary-default-score 0)
3983              gnus-tmp-score-char
3984              (if (or (null gnus-summary-default-score)
3985                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3986                          gnus-summary-zcore-fuzz))
3987                  ?  ;Whitespace
3988                (if (< gnus-tmp-score gnus-summary-default-score)
3989                    gnus-score-below-mark gnus-score-over-mark))
3990              gnus-tmp-replied
3991              (cond ((memq number gnus-newsgroup-processable)
3992                     gnus-process-mark)
3993                    ((memq number gnus-newsgroup-cached)
3994                     gnus-cached-mark)
3995                    ((memq number gnus-newsgroup-replied)
3996                     gnus-replied-mark)
3997                    ((memq number gnus-newsgroup-saved)
3998                     gnus-saved-mark)
3999                    (t gnus-unread-mark))
4000              gnus-tmp-from (mail-header-from gnus-tmp-header)
4001              gnus-tmp-name
4002              (cond
4003               ((string-match "<[^>]+> *$" gnus-tmp-from)
4004                (setq beg-match (match-beginning 0))
4005                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
4006                         (substring gnus-tmp-from (1+ (match-beginning 0))
4007                                    (1- (match-end 0))))
4008                    (substring gnus-tmp-from 0 beg-match)))
4009               ((string-match "(.+)" gnus-tmp-from)
4010                (substring gnus-tmp-from
4011                           (1+ (match-beginning 0)) (1- (match-end 0))))
4012               (t gnus-tmp-from)))
4013             (when (string= gnus-tmp-name "")
4014               (setq gnus-tmp-name gnus-tmp-from))
4015             (unless (numberp gnus-tmp-lines)
4016               (setq gnus-tmp-lines 0))
4017             (gnus-put-text-property
4018              (point)
4019              (progn (eval gnus-summary-line-format-spec) (point))
4020              'gnus-number number)
4021             (when gnus-visual-p
4022               (forward-line -1)
4023               (gnus-run-hooks 'gnus-summary-update-hook)
4024               (forward-line 1))
4025
4026             (setq gnus-tmp-prev-subject subject)))
4027
4028         (when (nth 1 thread)
4029           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4030         (incf gnus-tmp-level)
4031         (setq threads (if thread-end nil (cdar thread)))
4032         (unless threads
4033           (setq gnus-tmp-level 0)))))
4034   (gnus-message 7 "Generating summary...done"))
4035
4036 (defun gnus-summary-prepare-unthreaded (headers)
4037   "Generate an unthreaded summary buffer based on HEADERS."
4038   (let (header number mark)
4039
4040     (beginning-of-line)
4041
4042     (while headers
4043       ;; We may have to root out some bad articles...
4044       (when (memq (setq number (mail-header-number
4045                                 (setq header (pop headers))))
4046                   gnus-newsgroup-limit)
4047         ;; Mark article as read when it has a low score.
4048         (when (and gnus-summary-mark-below
4049                    (< (or (cdr (assq number gnus-newsgroup-scored))
4050                           gnus-summary-default-score 0)
4051                       gnus-summary-mark-below)
4052                    (not (gnus-summary-article-ancient-p number)))
4053           (setq gnus-newsgroup-unreads
4054                 (delq number gnus-newsgroup-unreads))
4055           (if gnus-newsgroup-auto-expire
4056               (push number gnus-newsgroup-expirable)
4057             (push (cons number gnus-low-score-mark)
4058                   gnus-newsgroup-reads)))
4059
4060         (setq mark (gnus-article-mark number))
4061         (push (gnus-data-make number mark (1+ (point)) header 0)
4062               gnus-newsgroup-data)
4063         (gnus-summary-insert-line
4064          header 0 number
4065          mark (memq number gnus-newsgroup-replied)
4066          (memq number gnus-newsgroup-expirable)
4067          (mail-header-subject header) nil
4068          (cdr (assq number gnus-newsgroup-scored))
4069          (memq number gnus-newsgroup-processable))))))
4070
4071 (defun gnus-summary-remove-list-identifiers ()
4072   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4073   (let ((regexp (if (stringp gnus-list-identifiers)
4074                     gnus-list-identifiers
4075                   (mapconcat 'identity gnus-list-identifiers " *\\|"))))
4076     (dolist (header gnus-newsgroup-headers)
4077       (when (string-match (concat "\\(Re: +\\)?\\(" regexp " *\\)")
4078                           (mail-header-subject header))
4079         (mail-header-set-subject
4080          header (concat (substring (mail-header-subject header)
4081                                    0 (match-beginning 2))
4082                         (substring (mail-header-subject header)
4083                                    (match-end 2))))))))
4084
4085 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4086   "Select newsgroup GROUP.
4087 If READ-ALL is non-nil, all articles in the group are selected.
4088 If SELECT-ARTICLES, only select those articles from GROUP."
4089   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4090          ;;!!! Dirty hack; should be removed.
4091          (gnus-summary-ignore-duplicates
4092           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4093               t
4094             gnus-summary-ignore-duplicates))
4095          (info (nth 2 entry))
4096          articles fetched-articles cached)
4097
4098     (unless (gnus-check-server
4099              (setq gnus-current-select-method
4100                    (gnus-find-method-for-group group)))
4101       (error "Couldn't open server"))
4102
4103     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4104         (gnus-activate-group group)     ; Or we can activate it...
4105         (progn                          ; Or we bug out.
4106           (when (equal major-mode 'gnus-summary-mode)
4107             (kill-buffer (current-buffer)))
4108           (error "Couldn't request group %s: %s"
4109                  group (gnus-status-message group))))
4110
4111     (unless (gnus-request-group group t)
4112       (when (equal major-mode 'gnus-summary-mode)
4113         (kill-buffer (current-buffer)))
4114       (error "Couldn't request group %s: %s"
4115              group (gnus-status-message group)))
4116
4117     (setq gnus-newsgroup-name group)
4118     (setq gnus-newsgroup-unselected nil)
4119     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4120     (gnus-summary-setup-default-charset)
4121
4122     ;; Adjust and set lists of article marks.
4123     (when info
4124       (gnus-adjust-marked-articles info))
4125
4126     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4127     (when (gnus-virtual-group-p group)
4128       (setq cached gnus-newsgroup-cached))
4129
4130     (setq gnus-newsgroup-unreads
4131           (gnus-set-difference
4132            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4133            gnus-newsgroup-dormant))
4134
4135     (setq gnus-newsgroup-processable nil)
4136
4137     (gnus-update-read-articles group gnus-newsgroup-unreads)
4138
4139     (if (setq articles select-articles)
4140         (setq gnus-newsgroup-unselected
4141               (gnus-sorted-intersection
4142                gnus-newsgroup-unreads
4143                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4144       (setq articles (gnus-articles-to-read group read-all)))
4145
4146     (cond
4147      ((null articles)
4148       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4149       'quit)
4150      ((eq articles 0) nil)
4151      (t
4152       ;; Init the dependencies hash table.
4153       (setq gnus-newsgroup-dependencies
4154             (gnus-make-hashtable (length articles)))
4155       (gnus-set-global-variables)
4156       ;; Retrieve the headers and read them in.
4157       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4158       (setq gnus-newsgroup-headers
4159             (if (eq 'nov
4160                     (setq gnus-headers-retrieved-by
4161                           (gnus-retrieve-headers
4162                            articles gnus-newsgroup-name
4163                            ;; We might want to fetch old headers, but
4164                            ;; not if there is only 1 article.
4165                            (and (or (and
4166                                      (not (eq gnus-fetch-old-headers 'some))
4167                                      (not (numberp gnus-fetch-old-headers)))
4168                                     (> (length articles) 1))
4169                                 gnus-fetch-old-headers))))
4170                 (gnus-get-newsgroup-headers-xover
4171                  articles nil nil gnus-newsgroup-name t)
4172               (gnus-get-newsgroup-headers)))
4173       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4174
4175       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4176       (when cached
4177         (setq gnus-newsgroup-cached cached))
4178
4179       ;; Suppress duplicates?
4180       (when gnus-suppress-duplicates
4181         (gnus-dup-suppress-articles))
4182
4183       ;; Set the initial limit.
4184       (setq gnus-newsgroup-limit (copy-sequence articles))
4185       ;; Remove canceled articles from the list of unread articles.
4186       (setq gnus-newsgroup-unreads
4187             (gnus-set-sorted-intersection
4188              gnus-newsgroup-unreads
4189              (setq fetched-articles
4190                    (mapcar (lambda (headers) (mail-header-number headers))
4191                            gnus-newsgroup-headers))))
4192       ;; Removed marked articles that do not exist.
4193       (gnus-update-missing-marks
4194        (gnus-sorted-complement fetched-articles articles))
4195       ;; We might want to build some more threads first.
4196       (when (and gnus-fetch-old-headers
4197                  (eq gnus-headers-retrieved-by 'nov))
4198         (if (eq gnus-fetch-old-headers 'invisible)
4199             (gnus-build-all-threads)
4200           (gnus-build-old-threads)))
4201       ;; Let the Gnus agent mark articles as read.
4202       (when gnus-agent
4203         (gnus-agent-get-undownloaded-list))
4204       ;; Remove list identifiers from subject
4205       (when gnus-list-identifiers
4206         (gnus-summary-remove-list-identifiers))
4207       ;; Check whether auto-expire is to be done in this group.
4208       (setq gnus-newsgroup-auto-expire
4209             (gnus-group-auto-expirable-p group))
4210       ;; Set up the article buffer now, if necessary.
4211       (unless gnus-single-article-buffer
4212         (gnus-article-setup-buffer))
4213       ;; First and last article in this newsgroup.
4214       (when gnus-newsgroup-headers
4215         (setq gnus-newsgroup-begin
4216               (mail-header-number (car gnus-newsgroup-headers))
4217               gnus-newsgroup-end
4218               (mail-header-number
4219                (gnus-last-element gnus-newsgroup-headers))))
4220       ;; GROUP is successfully selected.
4221       (or gnus-newsgroup-headers t)))))
4222
4223 (defun gnus-articles-to-read (group &optional read-all)
4224   ;; Find out what articles the user wants to read.
4225   (let* ((articles
4226           ;; Select all articles if `read-all' is non-nil, or if there
4227           ;; are no unread articles.
4228           (if (or read-all
4229                   (and (zerop (length gnus-newsgroup-marked))
4230                        (zerop (length gnus-newsgroup-unreads)))
4231                   (eq (gnus-group-find-parameter group 'display)
4232                       'all))
4233               (or
4234                (gnus-uncompress-range (gnus-active group))
4235                (gnus-cache-articles-in-group group))
4236             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4237                           (copy-sequence gnus-newsgroup-unreads))
4238                   '<)))
4239          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4240          (scored (length scored-list))
4241          (number (length articles))
4242          (marked (+ (length gnus-newsgroup-marked)
4243                     (length gnus-newsgroup-dormant)))
4244          (select
4245           (cond
4246            ((numberp read-all)
4247             read-all)
4248            (t
4249             (condition-case ()
4250                 (cond
4251                  ((and (or (<= scored marked) (= scored number))
4252                        (numberp gnus-large-newsgroup)
4253                        (> number gnus-large-newsgroup))
4254                   (let ((input
4255                          (read-string
4256                           (format
4257                            "How many articles from %s (default %d): "
4258                            (gnus-limit-string gnus-newsgroup-name 35)
4259                            number))))
4260                     (if (string-match "^[ \t]*$" input) number input)))
4261                  ((and (> scored marked) (< scored number)
4262                        (> (- scored number) 20))
4263                   (let ((input
4264                          (read-string
4265                           (format "%s %s (%d scored, %d total): "
4266                                   "How many articles from"
4267                                   group scored number))))
4268                     (if (string-match "^[ \t]*$" input)
4269                         number input)))
4270                  (t number))
4271               (quit nil))))))
4272     (setq select (if (stringp select) (string-to-number select) select))
4273     (if (or (null select) (zerop select))
4274         select
4275       (if (and (not (zerop scored)) (<= (abs select) scored))
4276           (progn
4277             (setq articles (sort scored-list '<))
4278             (setq number (length articles)))
4279         (setq articles (copy-sequence articles)))
4280
4281       (when (< (abs select) number)
4282         (if (< select 0)
4283             ;; Select the N oldest articles.
4284             (setcdr (nthcdr (1- (abs select)) articles) nil)
4285           ;; Select the N most recent articles.
4286           (setq articles (nthcdr (- number select) articles))))
4287       (setq gnus-newsgroup-unselected
4288             (gnus-sorted-intersection
4289              gnus-newsgroup-unreads
4290              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4291       (when gnus-alter-articles-to-read-function
4292         (setq gnus-newsgroup-unreads
4293               (sort 
4294                (funcall gnus-alter-articles-to-read-function
4295                         gnus-newsgroup-name gnus-newsgroup-unreads)
4296                '<)))
4297       articles)))
4298
4299 (defun gnus-killed-articles (killed articles)
4300   (let (out)
4301     (while articles
4302       (when (inline (gnus-member-of-range (car articles) killed))
4303         (push (car articles) out))
4304       (setq articles (cdr articles)))
4305     out))
4306
4307 (defun gnus-uncompress-marks (marks)
4308   "Uncompress the mark ranges in MARKS."
4309   (let ((uncompressed '(score bookmark))
4310         out)
4311     (while marks
4312       (if (memq (caar marks) uncompressed)
4313           (push (car marks) out)
4314         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4315       (setq marks (cdr marks)))
4316     out))
4317
4318 (defun gnus-adjust-marked-articles (info)
4319   "Set all article lists and remove all marks that are no longer valid."
4320   (let* ((marked-lists (gnus-info-marks info))
4321          (active (gnus-active (gnus-info-group info)))
4322          (min (car active))
4323          (max (cdr active))
4324          (types gnus-article-mark-lists)
4325          (uncompressed '(score bookmark killed))
4326          marks var articles article mark)
4327
4328     (while marked-lists
4329       (setq marks (pop marked-lists))
4330       (set (setq var (intern (format "gnus-newsgroup-%s"
4331                                      (car (rassq (setq mark (car marks))
4332                                                  types)))))
4333            (if (memq (car marks) uncompressed) (cdr marks)
4334              (gnus-uncompress-range (cdr marks))))
4335
4336       (setq articles (symbol-value var))
4337
4338       ;; All articles have to be subsets of the active articles.
4339       (cond
4340        ;; Adjust "simple" lists.
4341        ((memq mark '(tick dormant expire reply save))
4342         (while articles
4343           (when (or (< (setq article (pop articles)) min) (> article max))
4344             (set var (delq article (symbol-value var))))))
4345        ;; Adjust assocs.
4346        ((memq mark uncompressed)
4347         (when (not (listp (cdr (symbol-value var))))
4348           (set var (list (symbol-value var))))
4349         (when (not (listp (cdr articles)))
4350           (setq articles (list articles)))
4351         (while articles
4352           (when (or (not (consp (setq article (pop articles))))
4353                     (< (car article) min)
4354                     (> (car article) max))
4355             (set var (delq article (symbol-value var))))))))))
4356
4357 (defun gnus-update-missing-marks (missing)
4358   "Go through the list of MISSING articles and remove them from the mark lists."
4359   (when missing
4360     (let ((types gnus-article-mark-lists)
4361           var m)
4362       ;; Go through all types.
4363       (while types
4364         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4365         (when (symbol-value var)
4366           ;; This list has articles.  So we delete all missing articles
4367           ;; from it.
4368           (setq m missing)
4369           (while m
4370             (set var (delq (pop m) (symbol-value var)))))))))
4371
4372 (defun gnus-update-marks ()
4373   "Enter the various lists of marked articles into the newsgroup info list."
4374   (let ((types gnus-article-mark-lists)
4375         (info (gnus-get-info gnus-newsgroup-name))
4376         (uncompressed '(score bookmark killed))
4377         type list newmarked symbol delta-marks)
4378     (when info
4379       ;; Add all marks lists to the list of marks lists.
4380       (while (setq type (pop types))
4381         (setq list (symbol-value
4382                     (setq symbol
4383                           (intern (format "gnus-newsgroup-%s"
4384                                           (car type))))))
4385
4386         (when list
4387           ;; Get rid of the entries of the articles that have the
4388           ;; default score.
4389           (when (and (eq (cdr type) 'score)
4390                      gnus-save-score
4391                      list)
4392             (let* ((arts list)
4393                    (prev (cons nil list))
4394                    (all prev))
4395               (while arts
4396                 (if (or (not (consp (car arts)))
4397                         (= (cdar arts) gnus-summary-default-score))
4398                     (setcdr prev (cdr arts))
4399                   (setq prev arts))
4400                 (setq arts (cdr arts)))
4401               (setq list (cdr all)))))
4402
4403         (unless (memq (cdr type) uncompressed)
4404           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4405        
4406         (when (gnus-check-backend-function
4407                'request-set-mark gnus-newsgroup-name)
4408           ;; uncompressed:s are not proper flags (they are cons cells)
4409           ;; cache is a internal gnus flag
4410           (unless (memq (cdr type) (cons 'cache uncompressed))
4411             (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4412                    (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4413                    (add (gnus-remove-from-range
4414                          (gnus-copy-sequence list) old)))
4415               (when add
4416                 (push (list add 'add (list (cdr type))) delta-marks))
4417               (when del
4418                 (push (list del 'del (list (cdr type))) delta-marks)))))
4419           
4420         (when list
4421           (push (cons (cdr type) list) newmarked)))
4422
4423       (when delta-marks
4424         (unless (gnus-check-group gnus-newsgroup-name)
4425           (error "Can't open server for %s" gnus-newsgroup-name))
4426         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4427           
4428       ;; Enter these new marks into the info of the group.
4429       (if (nthcdr 3 info)
4430           (setcar (nthcdr 3 info) newmarked)
4431         ;; Add the marks lists to the end of the info.
4432         (when newmarked
4433           (setcdr (nthcdr 2 info) (list newmarked))))
4434
4435       ;; Cut off the end of the info if there's nothing else there.
4436       (let ((i 5))
4437         (while (and (> i 2)
4438                     (not (nth i info)))
4439           (when (nthcdr (decf i) info)
4440             (setcdr (nthcdr i info) nil)))))))
4441
4442 (defun gnus-set-mode-line (where)
4443   "This function sets the mode line of the article or summary buffers.
4444 If WHERE is `summary', the summary mode line format will be used."
4445   ;; Is this mode line one we keep updated?
4446   (when (and (memq where gnus-updated-mode-lines)
4447              (symbol-value
4448               (intern (format "gnus-%s-mode-line-format-spec" where))))
4449     (let (mode-string)
4450       (save-excursion
4451         ;; We evaluate this in the summary buffer since these
4452         ;; variables are buffer-local to that buffer.
4453         (set-buffer gnus-summary-buffer)
4454         ;; We bind all these variables that are used in the `eval' form
4455         ;; below.
4456         (let* ((mformat (symbol-value
4457                          (intern
4458                           (format "gnus-%s-mode-line-format-spec" where))))
4459                (gnus-tmp-group-name gnus-newsgroup-name)
4460                (gnus-tmp-article-number (or gnus-current-article 0))
4461                (gnus-tmp-unread gnus-newsgroup-unreads)
4462                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4463                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4464                (gnus-tmp-unread-and-unselected
4465                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4466                             (zerop gnus-tmp-unselected))
4467                        "")
4468                       ((zerop gnus-tmp-unselected)
4469                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4470                       (t (format "{%d(+%d) more}"
4471                                  gnus-tmp-unread-and-unticked
4472                                  gnus-tmp-unselected))))
4473                (gnus-tmp-subject
4474                 (if (and gnus-current-headers
4475                          (vectorp gnus-current-headers))
4476                     (gnus-mode-string-quote
4477                      (mail-header-subject gnus-current-headers))
4478                   ""))
4479                bufname-length max-len
4480                gnus-tmp-header);; passed as argument to any user-format-funcs
4481           (setq mode-string (eval mformat))
4482           (setq bufname-length (if (string-match "%b" mode-string)
4483                                    (- (length
4484                                        (buffer-name
4485                                         (if (eq where 'summary)
4486                                             nil
4487                                           (get-buffer gnus-article-buffer))))
4488                                       2)
4489                                  0))
4490           (setq max-len (max 4 (if gnus-mode-non-string-length
4491                                    (- (window-width)
4492                                       gnus-mode-non-string-length
4493                                       bufname-length)
4494                                  (length mode-string))))
4495           ;; We might have to chop a bit of the string off...
4496           (when (> (length mode-string) max-len)
4497             (setq mode-string
4498                   (concat (truncate-string-to-width mode-string (- max-len 3))
4499                           "...")))
4500           ;; Pad the mode string a bit.
4501           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4502       ;; Update the mode line.
4503       (setq mode-line-buffer-identification
4504             (gnus-mode-line-buffer-identification (list mode-string)))
4505       (set-buffer-modified-p t))))
4506
4507 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4508   "Go through the HEADERS list and add all Xrefs to a hash table.
4509 The resulting hash table is returned, or nil if no Xrefs were found."
4510   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4511          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4512          (xref-hashtb (gnus-make-hashtable))
4513          start group entry number xrefs header)
4514     (while headers
4515       (setq header (pop headers))
4516       (when (and (setq xrefs (mail-header-xref header))
4517                  (not (memq (setq number (mail-header-number header))
4518                             unreads)))
4519         (setq start 0)
4520         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4521           (setq start (match-end 0))
4522           (setq group (if prefix
4523                           (concat prefix (substring xrefs (match-beginning 1)
4524                                                     (match-end 1)))
4525                         (substring xrefs (match-beginning 1) (match-end 1))))
4526           (setq number
4527                 (string-to-int (substring xrefs (match-beginning 2)
4528                                           (match-end 2))))
4529           (if (setq entry (gnus-gethash group xref-hashtb))
4530               (setcdr entry (cons number (cdr entry)))
4531             (gnus-sethash group (cons number nil) xref-hashtb)))))
4532     (and start xref-hashtb)))
4533
4534 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4535   "Look through all the headers and mark the Xrefs as read."
4536   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4537         name entry info xref-hashtb idlist method nth4)
4538     (save-excursion
4539       (set-buffer gnus-group-buffer)
4540       (when (setq xref-hashtb
4541                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4542         (mapatoms
4543          (lambda (group)
4544            (unless (string= from-newsgroup (setq name (symbol-name group)))
4545              (setq idlist (symbol-value group))
4546              ;; Dead groups are not updated.
4547              (and (prog1
4548                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4549                             info (nth 2 entry))
4550                     (when (stringp (setq nth4 (gnus-info-method info)))
4551                       (setq nth4 (gnus-server-to-method nth4))))
4552                   ;; Only do the xrefs if the group has the same
4553                   ;; select method as the group we have just read.
4554                   (or (gnus-methods-equal-p
4555                        nth4 (gnus-find-method-for-group from-newsgroup))
4556                       virtual
4557                       (equal nth4 (setq method (gnus-find-method-for-group
4558                                                 from-newsgroup)))
4559                       (and (equal (car nth4) (car method))
4560                            (equal (nth 1 nth4) (nth 1 method))))
4561                   gnus-use-cross-reference
4562                   (or (not (eq gnus-use-cross-reference t))
4563                       virtual
4564                       ;; Only do cross-references on subscribed
4565                       ;; groups, if that is what is wanted.
4566                       (<= (gnus-info-level info) gnus-level-subscribed))
4567                   (gnus-group-make-articles-read name idlist))))
4568          xref-hashtb)))))
4569
4570 (defun gnus-compute-read-articles (group articles)
4571   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4572          (info (nth 2 entry))
4573          (active (gnus-active group))
4574          ninfo)
4575     (when entry
4576       ;; First peel off all invalid article numbers.
4577       (when active
4578         (let ((ids articles)
4579               id first)
4580           (while (setq id (pop ids))
4581             (when (and first (> id (cdr active)))
4582               ;; We'll end up in this situation in one particular
4583               ;; obscure situation.  If you re-scan a group and get
4584               ;; a new article that is cross-posted to a different
4585               ;; group that has not been re-scanned, you might get
4586               ;; crossposted article that has a higher number than
4587               ;; Gnus believes possible.  So we re-activate this
4588               ;; group as well.  This might mean doing the
4589               ;; crossposting thingy will *increase* the number
4590               ;; of articles in some groups.  Tsk, tsk.
4591               (setq active (or (gnus-activate-group group) active)))
4592             (when (or (> id (cdr active))
4593                       (< id (car active)))
4594               (setq articles (delq id articles))))))
4595       ;; If the read list is nil, we init it.
4596       (if (and active
4597                (null (gnus-info-read info))
4598                (> (car active) 1))
4599           (setq ninfo (cons 1 (1- (car active))))
4600         (setq ninfo (gnus-info-read info)))
4601       ;; Then we add the read articles to the range.
4602       (gnus-add-to-range
4603        ninfo (setq articles (sort articles '<))))))
4604
4605 (defun gnus-group-make-articles-read (group articles)
4606   "Update the info of GROUP to say that ARTICLES are read."
4607   (let* ((num 0)
4608          (entry (gnus-gethash group gnus-newsrc-hashtb))
4609          (info (nth 2 entry))
4610          (active (gnus-active group))
4611          range)
4612     (when entry
4613       (setq range (gnus-compute-read-articles group articles))
4614       (save-excursion
4615         (set-buffer gnus-group-buffer)
4616         (gnus-undo-register
4617           `(progn
4618              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4619              (gnus-info-set-read ',info ',(gnus-info-read info))
4620              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4621              (gnus-group-update-group ,group t))))
4622       ;; Add the read articles to the range.
4623       (gnus-info-set-read info range)
4624       ;; Then we have to re-compute how many unread
4625       ;; articles there are in this group.
4626       (when active
4627         (cond
4628          ((not range)
4629           (setq num (- (1+ (cdr active)) (car active))))
4630          ((not (listp (cdr range)))
4631           (setq num (- (cdr active) (- (1+ (cdr range))
4632                                        (car range)))))
4633          (t
4634           (while range
4635             (if (numberp (car range))
4636                 (setq num (1+ num))
4637               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4638             (setq range (cdr range)))
4639           (setq num (- (cdr active) num))))
4640         ;; Update the number of unread articles.
4641         (setcar entry num)
4642         ;; Update the group buffer.
4643         (gnus-group-update-group group t)))))
4644
4645 (defvar gnus-newsgroup-none-id 0)
4646
4647 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4648   (let ((cur nntp-server-buffer)
4649         (dependencies
4650          (or dependencies
4651              (save-excursion (set-buffer gnus-summary-buffer)
4652                              gnus-newsgroup-dependencies)))
4653         headers id end ref
4654         (mail-parse-charset gnus-newsgroup-charset)
4655         (mail-parse-ignored-charsets 
4656          (save-excursion (condition-case nil
4657                              (set-buffer gnus-summary-buffer)
4658                            (error))
4659                          gnus-newsgroup-ignored-charsets)))
4660     (save-excursion
4661       (set-buffer nntp-server-buffer)
4662       ;; Translate all TAB characters into SPACE characters.
4663       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4664       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4665       (gnus-run-hooks 'gnus-parse-headers-hook)
4666       (let ((case-fold-search t)
4667             in-reply-to header p lines chars)
4668         (goto-char (point-min))
4669         ;; Search to the beginning of the next header.  Error messages
4670         ;; do not begin with 2 or 3.
4671         (while (re-search-forward "^[23][0-9]+ " nil t)
4672           (setq id nil
4673                 ref nil)
4674           ;; This implementation of this function, with nine
4675           ;; search-forwards instead of the one re-search-forward and
4676           ;; a case (which basically was the old function) is actually
4677           ;; about twice as fast, even though it looks messier.  You
4678           ;; can't have everything, I guess.  Speed and elegance
4679           ;; doesn't always go hand in hand.
4680           (setq
4681            header
4682            (vector
4683             ;; Number.
4684             (prog1
4685                 (read cur)
4686               (end-of-line)
4687               (setq p (point))
4688               (narrow-to-region (point)
4689                                 (or (and (search-forward "\n.\n" nil t)
4690                                          (- (point) 2))
4691                                     (point))))
4692             ;; Subject.
4693             (progn
4694               (goto-char p)
4695               (if (search-forward "\nsubject: " nil t)
4696                   (funcall gnus-decode-encoded-word-function
4697                            (nnheader-header-value))
4698                 "(none)"))
4699             ;; From.
4700             (progn
4701               (goto-char p)
4702               (if (search-forward "\nfrom: " nil t)
4703                   (funcall gnus-decode-encoded-word-function
4704                            (nnheader-header-value))
4705                 "(nobody)"))
4706             ;; Date.
4707             (progn
4708               (goto-char p)
4709               (if (search-forward "\ndate: " nil t)
4710                   (nnheader-header-value) ""))
4711             ;; Message-ID.
4712             (progn
4713               (goto-char p)
4714               (setq id (if (re-search-forward
4715                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4716                            ;; We do it this way to make sure the Message-ID
4717                            ;; is (somewhat) syntactically valid.
4718                            (buffer-substring (match-beginning 1)
4719                                              (match-end 1))
4720                          ;; If there was no message-id, we just fake one
4721                          ;; to make subsequent routines simpler.
4722                          (nnheader-generate-fake-message-id))))
4723             ;; References.
4724             (progn
4725               (goto-char p)
4726               (if (search-forward "\nreferences: " nil t)
4727                   (progn
4728                     (setq end (point))
4729                     (prog1
4730                         (nnheader-header-value)
4731                       (setq ref
4732                             (buffer-substring
4733                              (progn
4734                                (end-of-line)
4735                                (search-backward ">" end t)
4736                                (1+ (point)))
4737                              (progn
4738                                (search-backward "<" end t)
4739                                (point))))))
4740                 ;; Get the references from the in-reply-to header if there
4741                 ;; were no references and the in-reply-to header looks
4742                 ;; promising.
4743                 (if (and (search-forward "\nin-reply-to: " nil t)
4744                          (setq in-reply-to (nnheader-header-value))
4745                          (string-match "<[^>]+>" in-reply-to))
4746                     (let (ref2)
4747                       (setq ref (substring in-reply-to (match-beginning 0)
4748                                            (match-end 0)))
4749                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4750                         (setq ref2 (substring in-reply-to (match-beginning 0)
4751                                               (match-end 0)))
4752                         (when (> (length ref2) (length ref))
4753                           (setq ref ref2)))
4754                       ref)
4755                   (setq ref nil))))
4756             ;; Chars.
4757             (progn
4758               (goto-char p)
4759               (if (search-forward "\nchars: " nil t)
4760                   (if (numberp (setq chars (ignore-errors (read cur))))
4761                       chars 0)
4762                 0))
4763             ;; Lines.
4764             (progn
4765               (goto-char p)
4766               (if (search-forward "\nlines: " nil t)
4767                   (if (numberp (setq lines (ignore-errors (read cur))))
4768                       lines 0)
4769                 0))
4770             ;; Xref.
4771             (progn
4772               (goto-char p)
4773               (and (search-forward "\nxref: " nil t)
4774                    (nnheader-header-value)))
4775             ;; Extra.
4776             (when gnus-extra-headers
4777               (let ((extra gnus-extra-headers)
4778                     out)
4779                 (while extra
4780                   (goto-char p)
4781                   (when (search-forward
4782                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4783                     (push (cons (car extra) (nnheader-header-value))
4784                           out))
4785                   (pop extra))
4786                 out))))
4787           (when (equal id ref)
4788             (setq ref nil))
4789
4790           (when gnus-alter-header-function
4791             (funcall gnus-alter-header-function header)
4792             (setq id (mail-header-id header)
4793                   ref (gnus-parent-id (mail-header-references header))))
4794
4795           (when (setq header
4796                       (gnus-dependencies-add-header
4797                        header dependencies force-new))
4798             (push header headers))
4799           (goto-char (point-max))
4800           (widen))
4801         (nreverse headers)))))
4802
4803 ;; Goes through the xover lines and returns a list of vectors
4804 (defun gnus-get-newsgroup-headers-xover (sequence &optional
4805                                                   force-new dependencies
4806                                                   group also-fetch-heads)
4807   "Parse the news overview data in the server buffer, and return a
4808 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4809   ;; Get the Xref when the users reads the articles since most/some
4810   ;; NNTP servers do not include Xrefs when using XOVER.
4811   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4812   (let ((mail-parse-charset gnus-newsgroup-charset)
4813         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
4814         (cur nntp-server-buffer)
4815         (dependencies (or dependencies gnus-newsgroup-dependencies))
4816         number headers header)
4817     (save-excursion
4818       (set-buffer nntp-server-buffer)
4819       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4820       ;; Allow the user to mangle the headers before parsing them.
4821       (gnus-run-hooks 'gnus-parse-headers-hook)
4822       (goto-char (point-min))
4823       (while (not (eobp))
4824         (condition-case ()
4825             (while (and sequence (not (eobp)))
4826               (setq number (read cur))
4827               (while (and sequence
4828                           (< (car sequence) number))
4829                 (setq sequence (cdr sequence)))
4830               (and sequence
4831                    (eq number (car sequence))
4832                    (progn
4833                      (setq sequence (cdr sequence))
4834                      (setq header (inline
4835                                     (gnus-nov-parse-line
4836                                      number dependencies force-new))))
4837                    (push header headers))
4838               (forward-line 1))
4839           (error
4840            (gnus-error 4 "Strange nov line (%d)"
4841                        (count-lines (point-min) (point)))))
4842         (forward-line 1))
4843       ;; A common bug in inn is that if you have posted an article and
4844       ;; then retrieves the active file, it will answer correctly --
4845       ;; the new article is included.  However, a NOV entry for the
4846       ;; article may not have been generated yet, so this may fail.
4847       ;; We work around this problem by retrieving the last few
4848       ;; headers using HEAD.
4849       (if (or (not also-fetch-heads)
4850               (not sequence))
4851           ;; We (probably) got all the headers.
4852           (nreverse headers)
4853         (let ((gnus-nov-is-evil t))
4854           (nconc
4855            (nreverse headers)
4856            (when (gnus-retrieve-headers sequence group)
4857              (gnus-get-newsgroup-headers))))))))
4858
4859 (defun gnus-article-get-xrefs ()
4860   "Fill in the Xref value in `gnus-current-headers', if necessary.
4861 This is meant to be called in `gnus-article-internal-prepare-hook'."
4862   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4863                                  gnus-current-headers)))
4864     (or (not gnus-use-cross-reference)
4865         (not headers)
4866         (and (mail-header-xref headers)
4867              (not (string= (mail-header-xref headers) "")))
4868         (let ((case-fold-search t)
4869               xref)
4870           (save-restriction
4871             (nnheader-narrow-to-headers)
4872             (goto-char (point-min))
4873             (when (or (and (not (eobp))
4874                            (eq (downcase (char-after)) ?x)
4875                            (looking-at "Xref:"))
4876                       (search-forward "\nXref:" nil t))
4877               (goto-char (1+ (match-end 0)))
4878               (setq xref (buffer-substring (point)
4879                                            (progn (end-of-line) (point))))
4880               (mail-header-set-xref headers xref)))))))
4881
4882 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4883   "Find article ID and insert the summary line for that article.
4884 OLD-HEADER can either be a header or a line number to insert
4885 the subject line on."
4886   (let* ((line (and (numberp old-header) old-header))
4887          (old-header (and (vectorp old-header) old-header))
4888          (header (cond ((and old-header use-old-header)
4889                         old-header)
4890                        ((and (numberp id)
4891                              (gnus-number-to-header id))
4892                         (gnus-number-to-header id))
4893                        (t
4894                         (gnus-read-header id))))
4895          (number (and (numberp id) id))
4896          d)
4897     (when header
4898       ;; Rebuild the thread that this article is part of and go to the
4899       ;; article we have fetched.
4900       (when (and (not gnus-show-threads)
4901                  old-header)
4902         (when (and number
4903                    (setq d (gnus-data-find (mail-header-number old-header))))
4904           (goto-char (gnus-data-pos d))
4905           (gnus-data-remove
4906            number
4907            (- (gnus-point-at-bol)
4908               (prog1
4909                   (1+ (gnus-point-at-eol))
4910                 (gnus-delete-line))))))
4911       (when old-header
4912         (mail-header-set-number header (mail-header-number old-header)))
4913       (setq gnus-newsgroup-sparse
4914             (delq (setq number (mail-header-number header))
4915                   gnus-newsgroup-sparse))
4916       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4917       (push number gnus-newsgroup-limit)
4918       (gnus-rebuild-thread (mail-header-id header) line)
4919       (gnus-summary-goto-subject number nil t))
4920     (when (and (numberp number)
4921                (> number 0))
4922       ;; We have to update the boundaries even if we can't fetch the
4923       ;; article if ID is a number -- so that the next `P' or `N'
4924       ;; command will fetch the previous (or next) article even
4925       ;; if the one we tried to fetch this time has been canceled.
4926       (when (> number gnus-newsgroup-end)
4927         (setq gnus-newsgroup-end number))
4928       (when (< number gnus-newsgroup-begin)
4929         (setq gnus-newsgroup-begin number))
4930       (setq gnus-newsgroup-unselected
4931             (delq number gnus-newsgroup-unselected)))
4932     ;; Report back a success?
4933     (and header (mail-header-number header))))
4934
4935 ;;; Process/prefix in the summary buffer
4936
4937 (defun gnus-summary-work-articles (n)
4938   "Return a list of articles to be worked upon.
4939 The prefix argument, the list of process marked articles, and the
4940 current article will be taken into consideration."
4941   (save-excursion
4942     (set-buffer gnus-summary-buffer)
4943     (cond
4944      (n
4945       ;; A numerical prefix has been given.
4946       (setq n (prefix-numeric-value n))
4947       (let ((backward (< n 0))
4948             (n (abs (prefix-numeric-value n)))
4949             articles article)
4950         (save-excursion
4951           (while
4952               (and (> n 0)
4953                    (push (setq article (gnus-summary-article-number))
4954                          articles)
4955                    (if backward
4956                        (gnus-summary-find-prev nil article)
4957                      (gnus-summary-find-next nil article)))
4958             (decf n)))
4959         (nreverse articles)))
4960      ((and (gnus-region-active-p) (mark))
4961       (message "region active")
4962       ;; Work on the region between point and mark.
4963       (let ((max (max (point) (mark)))
4964             articles article)
4965         (save-excursion
4966           (goto-char (min (min (point) (mark))))
4967           (while
4968               (and
4969                (push (setq article (gnus-summary-article-number)) articles)
4970                (gnus-summary-find-next nil article)
4971                (< (point) max)))
4972           (nreverse articles))))
4973      (gnus-newsgroup-processable
4974       ;; There are process-marked articles present.
4975       ;; Save current state.
4976       (gnus-summary-save-process-mark)
4977       ;; Return the list.
4978       (reverse gnus-newsgroup-processable))
4979      (t
4980       ;; Just return the current article.
4981       (list (gnus-summary-article-number))))))
4982
4983 (defmacro gnus-summary-iterate (arg &rest forms)
4984   "Iterate over the process/prefixed articles and do FORMS.
4985 ARG is the interactive prefix given to the command.  FORMS will be
4986 executed with point over the summary line of the articles."
4987   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
4988     `(let ((,articles (gnus-summary-work-articles ,arg)))
4989        (while ,articles
4990          (gnus-summary-goto-subject (car ,articles))
4991          ,@forms
4992          (pop ,articles)))))
4993
4994 (put 'gnus-summary-iterate 'lisp-indent-function 1)
4995 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
4996
4997 (defun gnus-summary-save-process-mark ()
4998   "Push the current set of process marked articles on the stack."
4999   (interactive)
5000   (push (copy-sequence gnus-newsgroup-processable)
5001         gnus-newsgroup-process-stack))
5002
5003 (defun gnus-summary-kill-process-mark ()
5004   "Push the current set of process marked articles on the stack and unmark."
5005   (interactive)
5006   (gnus-summary-save-process-mark)
5007   (gnus-summary-unmark-all-processable))
5008
5009 (defun gnus-summary-yank-process-mark ()
5010   "Pop the last process mark state off the stack and restore it."
5011   (interactive)
5012   (unless gnus-newsgroup-process-stack
5013     (error "Empty mark stack"))
5014   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5015
5016 (defun gnus-summary-process-mark-set (set)
5017   "Make SET into the current process marked articles."
5018   (gnus-summary-unmark-all-processable)
5019   (while set
5020     (gnus-summary-set-process-mark (pop set))))
5021
5022 ;;; Searching and stuff
5023
5024 (defun gnus-summary-search-group (&optional backward use-level)
5025   "Search for next unread newsgroup.
5026 If optional argument BACKWARD is non-nil, search backward instead."
5027   (save-excursion
5028     (set-buffer gnus-group-buffer)
5029     (when (gnus-group-search-forward
5030            backward nil (if use-level (gnus-group-group-level) nil))
5031       (gnus-group-group-name))))
5032
5033 (defun gnus-summary-best-group (&optional exclude-group)
5034   "Find the name of the best unread group.
5035 If EXCLUDE-GROUP, do not go to this group."
5036   (save-excursion
5037     (set-buffer gnus-group-buffer)
5038     (save-excursion
5039       (gnus-group-best-unread-group exclude-group))))
5040
5041 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5042   (if backward (gnus-summary-find-prev)
5043     (let* ((dummy (gnus-summary-article-intangible-p))
5044            (article (or article (gnus-summary-article-number)))
5045            (arts (gnus-data-find-list article))
5046            result)
5047       (when (and (not dummy)
5048                  (or (not gnus-summary-check-current)
5049                      (not unread)
5050                      (not (gnus-data-unread-p (car arts)))))
5051         (setq arts (cdr arts)))
5052       (when (setq result
5053                   (if unread
5054                       (progn
5055                         (while arts
5056                           (when (or (and undownloaded
5057                                          (eq gnus-undownloaded-mark
5058                                              (gnus-data-mark (car arts))))
5059                                     (gnus-data-unread-p (car arts)))
5060                             (setq result (car arts)
5061                                   arts nil))
5062                           (setq arts (cdr arts)))
5063                         result)
5064                     (car arts)))
5065         (goto-char (gnus-data-pos result))
5066         (gnus-data-number result)))))
5067
5068 (defun gnus-summary-find-prev (&optional unread article)
5069   (let* ((eobp (eobp))
5070          (article (or article (gnus-summary-article-number)))
5071          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5072          result)
5073     (when (and (not eobp)
5074                (or (not gnus-summary-check-current)
5075                    (not unread)
5076                    (not (gnus-data-unread-p (car arts)))))
5077       (setq arts (cdr arts)))
5078     (when (setq result
5079                 (if unread
5080                     (progn
5081                       (while arts
5082                         (when (gnus-data-unread-p (car arts))
5083                           (setq result (car arts)
5084                                 arts nil))
5085                         (setq arts (cdr arts)))
5086                       result)
5087                   (car arts)))
5088       (goto-char (gnus-data-pos result))
5089       (gnus-data-number result))))
5090
5091 (defun gnus-summary-find-subject (subject &optional unread backward article)
5092   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5093          (article (or article (gnus-summary-article-number)))
5094          (articles (gnus-data-list backward))
5095          (arts (gnus-data-find-list article articles))
5096          result)
5097     (when (or (not gnus-summary-check-current)
5098               (not unread)
5099               (not (gnus-data-unread-p (car arts))))
5100       (setq arts (cdr arts)))
5101     (while arts
5102       (and (or (not unread)
5103                (gnus-data-unread-p (car arts)))
5104            (vectorp (gnus-data-header (car arts)))
5105            (gnus-subject-equal
5106             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5107            (setq result (car arts)
5108                  arts nil))
5109       (setq arts (cdr arts)))
5110     (and result
5111          (goto-char (gnus-data-pos result))
5112          (gnus-data-number result))))
5113
5114 (defun gnus-summary-search-forward (&optional unread subject backward)
5115   "Search forward for an article.
5116 If UNREAD, look for unread articles.  If SUBJECT, look for
5117 articles with that subject.  If BACKWARD, search backward instead."
5118   (cond (subject (gnus-summary-find-subject subject unread backward))
5119         (backward (gnus-summary-find-prev unread))
5120         (t (gnus-summary-find-next unread))))
5121
5122 (defun gnus-recenter (&optional n)
5123   "Center point in window and redisplay frame.
5124 Also do horizontal recentering."
5125   (interactive "P")
5126   (when (and nil
5127              gnus-auto-center-summary
5128              (not (eq gnus-auto-center-summary 'vertical)))
5129     (gnus-horizontal-recenter))
5130   (recenter n))
5131
5132 (defun gnus-summary-recenter ()
5133   "Center point in the summary window.
5134 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5135 displayed, no centering will be performed."
5136   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5137   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5138   (interactive)
5139   (let* ((top (cond ((< (window-height) 4) 0)
5140                     ((< (window-height) 7) 1)
5141                     (t (if (numberp gnus-auto-center-summary)
5142                            gnus-auto-center-summary
5143                          2))))
5144          (height (1- (window-height)))
5145          (bottom (save-excursion (goto-char (point-max))
5146                                  (forward-line (- height))
5147                                  (point)))
5148          (window (get-buffer-window (current-buffer))))
5149     ;; The user has to want it.
5150     (when gnus-auto-center-summary
5151       (when (get-buffer-window gnus-article-buffer)
5152         ;; Only do recentering when the article buffer is displayed,
5153         ;; Set the window start to either `bottom', which is the biggest
5154         ;; possible valid number, or the second line from the top,
5155         ;; whichever is the least.
5156         (set-window-start
5157          window (min bottom (save-excursion
5158                               (forward-line (- top)) (point)))
5159          t))
5160       ;; Do horizontal recentering while we're at it.
5161       (when (and (get-buffer-window (current-buffer) t)
5162                  (not (eq gnus-auto-center-summary 'vertical)))
5163         (let ((selected (selected-window)))
5164           (select-window (get-buffer-window (current-buffer) t))
5165           (gnus-summary-position-point)
5166           (gnus-horizontal-recenter)
5167           (select-window selected))))))
5168
5169 (defun gnus-summary-jump-to-group (newsgroup)
5170   "Move point to NEWSGROUP in group mode buffer."
5171   ;; Keep update point of group mode buffer if visible.
5172   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5173       (save-window-excursion
5174         ;; Take care of tree window mode.
5175         (when (get-buffer-window gnus-group-buffer)
5176           (pop-to-buffer gnus-group-buffer))
5177         (gnus-group-jump-to-group newsgroup))
5178     (save-excursion
5179       ;; Take care of tree window mode.
5180       (if (get-buffer-window gnus-group-buffer)
5181           (pop-to-buffer gnus-group-buffer)
5182         (set-buffer gnus-group-buffer))
5183       (gnus-group-jump-to-group newsgroup))))
5184
5185 ;; This function returns a list of article numbers based on the
5186 ;; difference between the ranges of read articles in this group and
5187 ;; the range of active articles.
5188 (defun gnus-list-of-unread-articles (group)
5189   (let* ((read (gnus-info-read (gnus-get-info group)))
5190          (active (or (gnus-active group) (gnus-activate-group group)))
5191          (last (cdr active))
5192          first nlast unread)
5193     ;; If none are read, then all are unread.
5194     (if (not read)
5195         (setq first (car active))
5196       ;; If the range of read articles is a single range, then the
5197       ;; first unread article is the article after the last read
5198       ;; article.  Sounds logical, doesn't it?
5199       (if (and (not (listp (cdr read)))
5200                (or (< (car read) (car active))
5201                    (progn (setq read (list read))
5202                           nil)))
5203           (setq first (max (car active) (1+ (cdr read))))
5204         ;; `read' is a list of ranges.
5205         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5206                                   (caar read)))
5207                   1)
5208           (setq first (car active)))
5209         (while read
5210           (when first
5211             (while (< first nlast)
5212               (push first unread)
5213               (setq first (1+ first))))
5214           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5215           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5216           (setq read (cdr read)))))
5217     ;; And add the last unread articles.
5218     (while (<= first last)
5219       (push first unread)
5220       (setq first (1+ first)))
5221     ;; Return the list of unread articles.
5222     (delq 0 (nreverse unread))))
5223
5224 (defun gnus-list-of-read-articles (group)
5225   "Return a list of unread, unticked and non-dormant articles."
5226   (let* ((info (gnus-get-info group))
5227          (marked (gnus-info-marks info))
5228          (active (gnus-active group)))
5229     (and info active
5230          (gnus-set-difference
5231           (gnus-sorted-complement
5232            (gnus-uncompress-range active)
5233            (gnus-list-of-unread-articles group))
5234           (append
5235            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5236            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5237
5238 ;; Various summary commands
5239
5240 (defun gnus-summary-select-article-buffer ()
5241   "Reconfigure windows to show article buffer."
5242   (interactive)
5243   (if (not (gnus-buffer-live-p gnus-article-buffer))
5244       (error "There is no article buffer for this summary buffer")
5245     (gnus-configure-windows 'article)
5246     (select-window (get-buffer-window gnus-article-buffer))))
5247
5248 (defun gnus-summary-universal-argument (arg)
5249   "Perform any operation on all articles that are process/prefixed."
5250   (interactive "P")
5251   (let ((articles (gnus-summary-work-articles arg))
5252         func article)
5253     (if (eq
5254          (setq
5255           func
5256           (key-binding
5257            (read-key-sequence
5258             (substitute-command-keys
5259              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5260          'undefined)
5261         (gnus-error 1 "Undefined key")
5262       (save-excursion
5263         (while articles
5264           (gnus-summary-goto-subject (setq article (pop articles)))
5265           (let (gnus-newsgroup-processable)
5266             (command-execute func))
5267           (gnus-summary-remove-process-mark article)))))
5268   (gnus-summary-position-point))
5269
5270 (defun gnus-summary-toggle-truncation (&optional arg)
5271   "Toggle truncation of summary lines.
5272 With arg, turn line truncation on iff arg is positive."
5273   (interactive "P")
5274   (setq truncate-lines
5275         (if (null arg) (not truncate-lines)
5276           (> (prefix-numeric-value arg) 0)))
5277   (redraw-display))
5278
5279 (defun gnus-summary-reselect-current-group (&optional all rescan)
5280   "Exit and then reselect the current newsgroup.
5281 The prefix argument ALL means to select all articles."
5282   (interactive "P")
5283   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5284     (error "Ephemeral groups can't be reselected"))
5285   (let ((current-subject (gnus-summary-article-number))
5286         (group gnus-newsgroup-name))
5287     (setq gnus-newsgroup-begin nil)
5288     (gnus-summary-exit)
5289     ;; We have to adjust the point of group mode buffer because
5290     ;; point was moved to the next unread newsgroup by exiting.
5291     (gnus-summary-jump-to-group group)
5292     (when rescan
5293       (save-excursion
5294         (gnus-group-get-new-news-this-group 1)))
5295     (gnus-group-read-group all t)
5296     (gnus-summary-goto-subject current-subject nil t)))
5297
5298 (defun gnus-summary-rescan-group (&optional all)
5299   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5300   (interactive "P")
5301   (gnus-summary-reselect-current-group all t))
5302
5303 (defun gnus-summary-update-info (&optional non-destructive)
5304   (save-excursion
5305     (let ((group gnus-newsgroup-name))
5306       (when group
5307         (when gnus-newsgroup-kill-headers
5308           (setq gnus-newsgroup-killed
5309                 (gnus-compress-sequence
5310                  (nconc
5311                   (gnus-set-sorted-intersection
5312                    (gnus-uncompress-range gnus-newsgroup-killed)
5313                    (setq gnus-newsgroup-unselected
5314                          (sort gnus-newsgroup-unselected '<)))
5315                   (setq gnus-newsgroup-unreads
5316                         (sort gnus-newsgroup-unreads '<)))
5317                  t)))
5318         (unless (listp (cdr gnus-newsgroup-killed))
5319           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5320         (let ((headers gnus-newsgroup-headers))
5321           ;; Set the new ranges of read articles.
5322           (save-excursion
5323             (set-buffer gnus-group-buffer)
5324             (gnus-undo-force-boundary))
5325           (gnus-update-read-articles
5326            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5327           ;; Set the current article marks.
5328           (let ((gnus-newsgroup-scored
5329                  (if (and (not gnus-save-score)
5330                           (not non-destructive))
5331                      nil
5332                    gnus-newsgroup-scored)))
5333             (save-excursion
5334               (gnus-update-marks)))
5335           ;; Do the cross-ref thing.
5336           (when gnus-use-cross-reference
5337             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5338           ;; Do not switch windows but change the buffer to work.
5339           (set-buffer gnus-group-buffer)
5340           (unless (gnus-ephemeral-group-p group)
5341             (gnus-group-update-group group)))))))
5342
5343 (defun gnus-summary-save-newsrc (&optional force)
5344   "Save the current number of read/marked articles in the dribble buffer.
5345 The dribble buffer will then be saved.
5346 If FORCE (the prefix), also save the .newsrc file(s)."
5347   (interactive "P")
5348   (gnus-summary-update-info t)
5349   (if force
5350       (gnus-save-newsrc-file)
5351     (gnus-dribble-save)))
5352
5353 (defun gnus-summary-exit (&optional temporary)
5354   "Exit reading current newsgroup, and then return to group selection mode.
5355 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5356   (interactive)
5357   (gnus-set-global-variables)
5358   (when (gnus-buffer-live-p gnus-article-buffer)
5359     (save-excursion
5360       (set-buffer gnus-article-buffer)
5361       (mm-destroy-parts gnus-article-mime-handles)))
5362   (gnus-kill-save-kill-buffer)
5363   (gnus-async-halt-prefetch)
5364   (let* ((group gnus-newsgroup-name)
5365          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5366          (mode major-mode)
5367          (group-point nil)
5368          (buf (current-buffer)))
5369     (unless quit-config
5370       ;; Do adaptive scoring, and possibly save score files.
5371       (when gnus-newsgroup-adaptive
5372         (gnus-score-adaptive))
5373       (when gnus-use-scoring
5374         (gnus-score-save)))
5375     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5376     ;; If we have several article buffers, we kill them at exit.
5377     (unless gnus-single-article-buffer
5378       (gnus-kill-buffer gnus-original-article-buffer)
5379       (setq gnus-article-current nil))
5380     (when gnus-use-cache
5381       (gnus-cache-possibly-remove-articles)
5382       (gnus-cache-save-buffers))
5383     (gnus-async-prefetch-remove-group group)
5384     (when gnus-suppress-duplicates
5385       (gnus-dup-enter-articles))
5386     (when gnus-use-trees
5387       (gnus-tree-close group))
5388     (when gnus-use-cache
5389       (gnus-cache-write-active))
5390     ;; Remove entries for this group.
5391     (nnmail-purge-split-history (gnus-group-real-name group))
5392     ;; Make all changes in this group permanent.
5393     (unless quit-config
5394       (gnus-run-hooks 'gnus-exit-group-hook)
5395       (gnus-summary-update-info))
5396     (gnus-close-group group)
5397     ;; Make sure where we were, and go to next newsgroup.
5398     (set-buffer gnus-group-buffer)
5399     (unless quit-config
5400       (gnus-group-jump-to-group group))
5401     (gnus-run-hooks 'gnus-summary-exit-hook)
5402     (unless (or quit-config
5403                 ;; If this group has disappeared from the summary
5404                 ;; buffer, don't skip forwards.
5405                 (not (string= group (gnus-group-group-name))))
5406       (gnus-group-next-unread-group 1))
5407     (setq group-point (point))
5408     (if temporary
5409         nil                             ;Nothing to do.
5410       ;; If we have several article buffers, we kill them at exit.
5411       (unless gnus-single-article-buffer
5412         (gnus-kill-buffer gnus-article-buffer)
5413         (gnus-kill-buffer gnus-original-article-buffer)
5414         (setq gnus-article-current nil))
5415       (set-buffer buf)
5416       (if (not gnus-kill-summary-on-exit)
5417           (gnus-deaden-summary)
5418         ;; We set all buffer-local variables to nil.  It is unclear why
5419         ;; this is needed, but if we don't, buffer-local variables are
5420         ;; not garbage-collected, it seems.  This would the lead to en
5421         ;; ever-growing Emacs.
5422         (gnus-summary-clear-local-variables)
5423         (when (get-buffer gnus-article-buffer)
5424           (bury-buffer gnus-article-buffer))
5425         ;; We clear the global counterparts of the buffer-local
5426         ;; variables as well, just to be on the safe side.
5427         (set-buffer gnus-group-buffer)
5428         (gnus-summary-clear-local-variables)
5429         ;; Return to group mode buffer.
5430         (when (eq mode 'gnus-summary-mode)
5431           (gnus-kill-buffer buf)))
5432       (setq gnus-current-select-method gnus-select-method)
5433       (pop-to-buffer gnus-group-buffer)
5434       (if (not quit-config)
5435           (progn
5436             (goto-char group-point)
5437             (gnus-configure-windows 'group 'force))
5438         (gnus-handle-ephemeral-exit quit-config))
5439       ;; Clear the current group name.
5440       (unless quit-config
5441         (setq gnus-newsgroup-name nil)))))
5442
5443 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5444 (defun gnus-summary-exit-no-update (&optional no-questions)
5445   "Quit reading current newsgroup without updating read article info."
5446   (interactive)
5447   (let* ((group gnus-newsgroup-name)
5448          (quit-config (gnus-group-quit-config group)))
5449     (when (or no-questions
5450               gnus-expert-user
5451               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5452       (gnus-async-halt-prefetch)
5453       (mapcar 'funcall
5454               (delq 'gnus-summary-expire-articles
5455                     (copy-sequence gnus-summary-prepare-exit-hook)))
5456       (when (gnus-buffer-live-p gnus-article-buffer)
5457         (save-excursion
5458           (set-buffer gnus-article-buffer)
5459           (mm-destroy-parts gnus-article-mime-handles)))
5460       ;; If we have several article buffers, we kill them at exit.
5461       (unless gnus-single-article-buffer
5462         (gnus-kill-buffer gnus-article-buffer)
5463         (gnus-kill-buffer gnus-original-article-buffer)
5464         (setq gnus-article-current nil))
5465       (if (not gnus-kill-summary-on-exit)
5466           (gnus-deaden-summary)
5467         (gnus-close-group group)
5468         (gnus-summary-clear-local-variables)
5469         (set-buffer gnus-group-buffer)
5470         (gnus-summary-clear-local-variables)
5471         (when (get-buffer gnus-summary-buffer)
5472           (kill-buffer gnus-summary-buffer)))
5473       (unless gnus-single-article-buffer
5474         (setq gnus-article-current nil))
5475       (when gnus-use-trees
5476         (gnus-tree-close group))
5477       (gnus-async-prefetch-remove-group group)
5478       (when (get-buffer gnus-article-buffer)
5479         (bury-buffer gnus-article-buffer))
5480       ;; Return to the group buffer.
5481       (gnus-configure-windows 'group 'force)
5482       ;; Clear the current group name.
5483       (setq gnus-newsgroup-name nil)
5484       (when (equal (gnus-group-group-name) group)
5485         (gnus-group-next-unread-group 1))
5486       (when quit-config
5487         (gnus-handle-ephemeral-exit quit-config)))))
5488
5489 (defun gnus-handle-ephemeral-exit (quit-config)
5490   "Handle movement when leaving an ephemeral group.
5491 The state which existed when entering the ephemeral is reset."
5492   (if (not (buffer-name (car quit-config)))
5493       (gnus-configure-windows 'group 'force)
5494     (set-buffer (car quit-config))
5495     (cond ((eq major-mode 'gnus-summary-mode)
5496            (gnus-set-global-variables))
5497           ((eq major-mode 'gnus-article-mode)
5498            (save-excursion
5499              ;; The `gnus-summary-buffer' variable may point
5500              ;; to the old summary buffer when using a single
5501              ;; article buffer.
5502              (unless (gnus-buffer-live-p gnus-summary-buffer)
5503                (set-buffer gnus-group-buffer))
5504              (set-buffer gnus-summary-buffer)
5505              (gnus-set-global-variables))))
5506     (if (or (eq (cdr quit-config) 'article)
5507             (eq (cdr quit-config) 'pick))
5508         (progn
5509           ;; The current article may be from the ephemeral group
5510           ;; thus it is best that we reload this article
5511           (gnus-summary-show-article)
5512           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5513               (gnus-configure-windows 'pick 'force)
5514             (gnus-configure-windows (cdr quit-config) 'force)))
5515       (gnus-configure-windows (cdr quit-config) 'force))
5516     (when (eq major-mode 'gnus-summary-mode)
5517       (gnus-summary-next-subject 1 nil t)
5518       (gnus-summary-recenter)
5519       (gnus-summary-position-point))))
5520
5521 ;;; Dead summaries.
5522
5523 (defvar gnus-dead-summary-mode-map nil)
5524
5525 (unless gnus-dead-summary-mode-map
5526   (setq gnus-dead-summary-mode-map (make-keymap))
5527   (suppress-keymap gnus-dead-summary-mode-map)
5528   (substitute-key-definition
5529    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5530   (let ((keys '("\C-d" "\r" "\177" [delete])))
5531     (while keys
5532       (define-key gnus-dead-summary-mode-map
5533         (pop keys) 'gnus-summary-wake-up-the-dead))))
5534
5535 (defvar gnus-dead-summary-mode nil
5536   "Minor mode for Gnus summary buffers.")
5537
5538 (defun gnus-dead-summary-mode (&optional arg)
5539   "Minor mode for Gnus summary buffers."
5540   (interactive "P")
5541   (when (eq major-mode 'gnus-summary-mode)
5542     (make-local-variable 'gnus-dead-summary-mode)
5543     (setq gnus-dead-summary-mode
5544           (if (null arg) (not gnus-dead-summary-mode)
5545             (> (prefix-numeric-value arg) 0)))
5546     (when gnus-dead-summary-mode
5547       (gnus-add-minor-mode
5548        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5549
5550 (defun gnus-deaden-summary ()
5551   "Make the current summary buffer into a dead summary buffer."
5552   ;; Kill any previous dead summary buffer.
5553   (when (and gnus-dead-summary
5554              (buffer-name gnus-dead-summary))
5555     (save-excursion
5556       (set-buffer gnus-dead-summary)
5557       (when gnus-dead-summary-mode
5558         (kill-buffer (current-buffer)))))
5559   ;; Make this the current dead summary.
5560   (setq gnus-dead-summary (current-buffer))
5561   (gnus-dead-summary-mode 1)
5562   (let ((name (buffer-name)))
5563     (when (string-match "Summary" name)
5564       (rename-buffer
5565        (concat (substring name 0 (match-beginning 0)) "Dead "
5566                (substring name (match-beginning 0)))
5567        t)
5568       (bury-buffer))))
5569
5570 (defun gnus-kill-or-deaden-summary (buffer)
5571   "Kill or deaden the summary BUFFER."
5572   (save-excursion
5573     (when (and (buffer-name buffer)
5574                (not gnus-single-article-buffer))
5575       (save-excursion
5576         (set-buffer buffer)
5577         (gnus-kill-buffer gnus-article-buffer)
5578         (gnus-kill-buffer gnus-original-article-buffer)))
5579     (cond (gnus-kill-summary-on-exit
5580            (when (and gnus-use-trees
5581                       (gnus-buffer-exists-p buffer))
5582              (save-excursion
5583                (set-buffer buffer)
5584                (gnus-tree-close gnus-newsgroup-name)))
5585            (gnus-kill-buffer buffer))
5586           ((gnus-buffer-exists-p buffer)
5587            (save-excursion
5588              (set-buffer buffer)
5589              (gnus-deaden-summary))))))
5590
5591 (defun gnus-summary-wake-up-the-dead (&rest args)
5592   "Wake up the dead summary buffer."
5593   (interactive)
5594   (gnus-dead-summary-mode -1)
5595   (let ((name (buffer-name)))
5596     (when (string-match "Dead " name)
5597       (rename-buffer
5598        (concat (substring name 0 (match-beginning 0))
5599                (substring name (match-end 0)))
5600        t)))
5601   (gnus-message 3 "This dead summary is now alive again"))
5602
5603 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5604 (defun gnus-summary-fetch-faq (&optional faq-dir)
5605   "Fetch the FAQ for the current group.
5606 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5607 in."
5608   (interactive
5609    (list
5610     (when current-prefix-arg
5611       (completing-read
5612        "Faq dir: " (and (listp gnus-group-faq-directory)
5613                         (mapcar (lambda (file) (list file))
5614                                 gnus-group-faq-directory))))))
5615   (let (gnus-faq-buffer)
5616     (when (setq gnus-faq-buffer
5617                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5618       (gnus-configure-windows 'summary-faq))))
5619
5620 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5621 (defun gnus-summary-describe-group (&optional force)
5622   "Describe the current newsgroup."
5623   (interactive "P")
5624   (gnus-group-describe-group force gnus-newsgroup-name))
5625
5626 (defun gnus-summary-describe-briefly ()
5627   "Describe summary mode commands briefly."
5628   (interactive)
5629   (gnus-message 6 (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")))
5630
5631 ;; Walking around group mode buffer from summary mode.
5632
5633 (defun gnus-summary-next-group (&optional no-article target-group backward)
5634   "Exit current newsgroup and then select next unread newsgroup.
5635 If prefix argument NO-ARTICLE is non-nil, no article is selected
5636 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5637 previous group instead."
5638   (interactive "P")
5639   ;; Stop pre-fetching.
5640   (gnus-async-halt-prefetch)
5641   (let ((current-group gnus-newsgroup-name)
5642         (current-buffer (current-buffer))
5643         entered)
5644     ;; First we semi-exit this group to update Xrefs and all variables.
5645     ;; We can't do a real exit, because the window conf must remain
5646     ;; the same in case the user is prompted for info, and we don't
5647     ;; want the window conf to change before that...
5648     (gnus-summary-exit t)
5649     (while (not entered)
5650       ;; Then we find what group we are supposed to enter.
5651       (set-buffer gnus-group-buffer)
5652       (gnus-group-jump-to-group current-group)
5653       (setq target-group
5654             (or target-group
5655                 (if (eq gnus-keep-same-level 'best)
5656                     (gnus-summary-best-group gnus-newsgroup-name)
5657                   (gnus-summary-search-group backward gnus-keep-same-level))))
5658       (if (not target-group)
5659           ;; There are no further groups, so we return to the group
5660           ;; buffer.
5661           (progn
5662             (gnus-message 5 "Returning to the group buffer")
5663             (setq entered t)
5664             (when (gnus-buffer-live-p current-buffer)
5665               (set-buffer current-buffer)
5666               (gnus-summary-exit))
5667             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5668         ;; We try to enter the target group.
5669         (gnus-group-jump-to-group target-group)
5670         (let ((unreads (gnus-group-group-unread)))
5671           (if (and (or (eq t unreads)
5672                        (and unreads (not (zerop unreads))))
5673                    (gnus-summary-read-group
5674                     target-group nil no-article
5675                     (and (buffer-name current-buffer) current-buffer)
5676                     nil backward))
5677               (setq entered t)
5678             (setq current-group target-group
5679                   target-group nil)))))))
5680
5681 (defun gnus-summary-prev-group (&optional no-article)
5682   "Exit current newsgroup and then select previous unread newsgroup.
5683 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5684   (interactive "P")
5685   (gnus-summary-next-group no-article nil t))
5686
5687 ;; Walking around summary lines.
5688
5689 (defun gnus-summary-first-subject (&optional unread undownloaded)
5690   "Go to the first unread subject.
5691 If UNREAD is non-nil, go to the first unread article.
5692 Returns the article selected or nil if there are no unread articles."
5693   (interactive "P")
5694   (prog1
5695       (cond
5696        ;; Empty summary.
5697        ((null gnus-newsgroup-data)
5698         (gnus-message 3 "No articles in the group")
5699         nil)
5700        ;; Pick the first article.
5701        ((not unread)
5702         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5703         (gnus-data-number (car gnus-newsgroup-data)))
5704        ;; No unread articles.
5705        ((null gnus-newsgroup-unreads)
5706         (gnus-message 3 "No more unread articles")
5707         nil)
5708        ;; Find the first unread article.
5709        (t
5710         (let ((data gnus-newsgroup-data))
5711           (while (and data
5712                       (and (not (and undownloaded
5713                                      (eq gnus-undownloaded-mark
5714                                          (gnus-data-mark (car data)))))
5715                            (not (gnus-data-unread-p (car data)))))
5716             (setq data (cdr data)))
5717           (when data
5718             (goto-char (gnus-data-pos (car data)))
5719             (gnus-data-number (car data))))))
5720     (gnus-summary-position-point)))
5721
5722 (defun gnus-summary-next-subject (n &optional unread dont-display)
5723   "Go to next N'th summary line.
5724 If N is negative, go to the previous N'th subject line.
5725 If UNREAD is non-nil, only unread articles are selected.
5726 The difference between N and the actual number of steps taken is
5727 returned."
5728   (interactive "p")
5729   (let ((backward (< n 0))
5730         (n (abs n)))
5731     (while (and (> n 0)
5732                 (if backward
5733                     (gnus-summary-find-prev unread)
5734                   (gnus-summary-find-next unread)))
5735       (unless (zerop (setq n (1- n)))
5736         (gnus-summary-show-thread)))
5737     (when (/= 0 n)
5738       (gnus-message 7 "No more%s articles"
5739                     (if unread " unread" "")))
5740     (unless dont-display
5741       (gnus-summary-recenter)
5742       (gnus-summary-position-point))
5743     n))
5744
5745 (defun gnus-summary-next-unread-subject (n)
5746   "Go to next N'th unread summary line."
5747   (interactive "p")
5748   (gnus-summary-next-subject n t))
5749
5750 (defun gnus-summary-prev-subject (n &optional unread)
5751   "Go to previous N'th summary line.
5752 If optional argument UNREAD is non-nil, only unread article is selected."
5753   (interactive "p")
5754   (gnus-summary-next-subject (- n) unread))
5755
5756 (defun gnus-summary-prev-unread-subject (n)
5757   "Go to previous N'th unread summary line."
5758   (interactive "p")
5759   (gnus-summary-next-subject (- n) t))
5760
5761 (defun gnus-summary-goto-subject (article &optional force silent)
5762   "Go the subject line of ARTICLE.
5763 If FORCE, also allow jumping to articles not currently shown."
5764   (interactive "nArticle number: ")
5765   (let ((b (point))
5766         (data (gnus-data-find article)))
5767     ;; We read in the article if we have to.
5768     (and (not data)
5769          force
5770          (gnus-summary-insert-subject
5771           article
5772           (if (or (numberp force) (vectorp force)) force)
5773           t)
5774          (setq data (gnus-data-find article)))
5775     (goto-char b)
5776     (if (not data)
5777         (progn
5778           (unless silent
5779             (gnus-message 3 "Can't find article %d" article))
5780           nil)
5781       (goto-char (gnus-data-pos data))
5782       (gnus-summary-position-point)
5783       article)))
5784
5785 ;; Walking around summary lines with displaying articles.
5786
5787 (defun gnus-summary-expand-window (&optional arg)
5788   "Make the summary buffer take up the entire Emacs frame.
5789 Given a prefix, will force an `article' buffer configuration."
5790   (interactive "P")
5791   (if arg
5792       (gnus-configure-windows 'article 'force)
5793     (gnus-configure-windows 'summary 'force)))
5794
5795 (defun gnus-summary-display-article (article &optional all-header)
5796   "Display ARTICLE in article buffer."
5797   (gnus-set-global-variables)
5798   (if (null article)
5799       nil
5800     (prog1
5801         (if gnus-summary-display-article-function
5802             (funcall gnus-summary-display-article-function article all-header)
5803           (gnus-article-prepare article all-header))
5804       (gnus-run-hooks 'gnus-select-article-hook)
5805       (when (and gnus-current-article
5806                  (not (zerop gnus-current-article)))
5807         (gnus-summary-goto-subject gnus-current-article))
5808       (gnus-summary-recenter)
5809       (when (and gnus-use-trees gnus-show-threads)
5810         (gnus-possibly-generate-tree article)
5811         (gnus-highlight-selected-tree article))
5812       ;; Successfully display article.
5813       (gnus-article-set-window-start
5814        (cdr (assq article gnus-newsgroup-bookmarks))))))
5815
5816 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5817   "Select the current article.
5818 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5819 non-nil, the article will be re-fetched even if it already present in
5820 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5821 be displayed."
5822   ;; Make sure we are in the summary buffer to work around bbdb bug.
5823   (unless (eq major-mode 'gnus-summary-mode)
5824     (set-buffer gnus-summary-buffer))
5825   (let ((article (or article (gnus-summary-article-number)))
5826         (all-headers (not (not all-headers))) ;Must be T or NIL.
5827         gnus-summary-display-article-function)
5828     (and (not pseudo)
5829          (gnus-summary-article-pseudo-p article)
5830          (error "This is a pseudo-article"))
5831     (save-excursion
5832       (set-buffer gnus-summary-buffer)
5833       (if (or (and gnus-single-article-buffer
5834                    (or (null gnus-current-article)
5835                        (null gnus-article-current)
5836                        (null (get-buffer gnus-article-buffer))
5837                        (not (eq article (cdr gnus-article-current)))
5838                        (not (equal (car gnus-article-current)
5839                                    gnus-newsgroup-name))))
5840               (and (not gnus-single-article-buffer)
5841                    (or (null gnus-current-article)
5842                        (not (eq gnus-current-article article))))
5843               force)
5844           ;; The requested article is different from the current article.
5845           (progn
5846             (when (gnus-buffer-live-p gnus-article-buffer)
5847               (with-current-buffer gnus-article-buffer
5848                 (mm-enable-multibyte)))
5849             (gnus-summary-display-article article all-headers)
5850             (when (gnus-buffer-live-p gnus-article-buffer)
5851               (with-current-buffer gnus-article-buffer
5852                 (if (not gnus-article-decoded-p) ;; a local variable
5853                     (mm-disable-multibyte))))
5854             (when (or all-headers gnus-show-all-headers)
5855               (gnus-article-show-all-headers))
5856             (gnus-article-set-window-start
5857              (cdr (assq article gnus-newsgroup-bookmarks)))
5858             article)
5859         (when (or all-headers gnus-show-all-headers)
5860           (gnus-article-show-all-headers))
5861         'old))))
5862
5863 (defun gnus-summary-set-current-mark (&optional current-mark)
5864   "Obsolete function."
5865   nil)
5866
5867 (defun gnus-summary-next-article (&optional unread subject backward push)
5868   "Select the next article.
5869 If UNREAD, only unread articles are selected.
5870 If SUBJECT, only articles with SUBJECT are selected.
5871 If BACKWARD, the previous article is selected instead of the next."
5872   (interactive "P")
5873   (cond
5874    ;; Is there such an article?
5875    ((and (gnus-summary-search-forward unread subject backward)
5876          (or (gnus-summary-display-article (gnus-summary-article-number))
5877              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5878     (gnus-summary-position-point))
5879    ;; If not, we try the first unread, if that is wanted.
5880    ((and subject
5881          gnus-auto-select-same
5882          (gnus-summary-first-unread-article))
5883     (gnus-summary-position-point)
5884     (gnus-message 6 "Wrapped"))
5885    ;; Try to get next/previous article not displayed in this group.
5886    ((and gnus-auto-extend-newsgroup
5887          (not unread) (not subject))
5888     (gnus-summary-goto-article
5889      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5890      nil (count-lines (point-min) (point))))
5891    ;; Go to next/previous group.
5892    (t
5893     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5894       (gnus-summary-jump-to-group gnus-newsgroup-name))
5895     (let ((cmd last-command-char)
5896           (point
5897            (save-excursion
5898              (set-buffer gnus-group-buffer)
5899              (point)))
5900           (group
5901            (if (eq gnus-keep-same-level 'best)
5902                (gnus-summary-best-group gnus-newsgroup-name)
5903              (gnus-summary-search-group backward gnus-keep-same-level))))
5904       ;; For some reason, the group window gets selected.  We change
5905       ;; it back.
5906       (select-window (get-buffer-window (current-buffer)))
5907       ;; Select next unread newsgroup automagically.
5908       (cond
5909        ((or (not gnus-auto-select-next)
5910             (not cmd))
5911         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5912        ((or (eq gnus-auto-select-next 'quietly)
5913             (and (eq gnus-auto-select-next 'slightly-quietly)
5914                  push)
5915             (and (eq gnus-auto-select-next 'almost-quietly)
5916                  (gnus-summary-last-article-p)))
5917         ;; Select quietly.
5918         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5919             (gnus-summary-exit)
5920           (gnus-message 7 "No more%s articles (%s)..."
5921                         (if unread " unread" "")
5922                         (if group (concat "selecting " group)
5923                           "exiting"))
5924           (gnus-summary-next-group nil group backward)))
5925        (t
5926         (when (gnus-key-press-event-p last-input-event)
5927           (gnus-summary-walk-group-buffer
5928            gnus-newsgroup-name cmd unread backward point))))))))
5929
5930 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5931   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5932                       (?\C-p (gnus-group-prev-unread-group 1))))
5933         (cursor-in-echo-area t)
5934         keve key group ended)
5935     (save-excursion
5936       (set-buffer gnus-group-buffer)
5937       (goto-char start)
5938       (setq group
5939             (if (eq gnus-keep-same-level 'best)
5940                 (gnus-summary-best-group gnus-newsgroup-name)
5941               (gnus-summary-search-group backward gnus-keep-same-level))))
5942     (while (not ended)
5943       (gnus-message
5944        5 "No more%s articles%s" (if unread " unread" "")
5945        (if (and group
5946                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5947            (format " (Type %s for %s [%s])"
5948                    (single-key-description cmd) group
5949                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5950          (format " (Type %s to exit %s)"
5951                  (single-key-description cmd)
5952                  gnus-newsgroup-name)))
5953       ;; Confirm auto selection.
5954       (setq key (car (setq keve (gnus-read-event-char))))
5955       (setq ended t)
5956       (cond
5957        ((assq key keystrokes)
5958         (let ((obuf (current-buffer)))
5959           (switch-to-buffer gnus-group-buffer)
5960           (when group
5961             (gnus-group-jump-to-group group))
5962           (eval (cadr (assq key keystrokes)))
5963           (setq group (gnus-group-group-name))
5964           (switch-to-buffer obuf))
5965         (setq ended nil))
5966        ((equal key cmd)
5967         (if (or (not group)
5968                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5969             (gnus-summary-exit)
5970           (gnus-summary-next-group nil group backward)))
5971        (t
5972         (push (cdr keve) unread-command-events))))))
5973
5974 (defun gnus-summary-next-unread-article ()
5975   "Select unread article after current one."
5976   (interactive)
5977   (gnus-summary-next-article
5978    (or (not (eq gnus-summary-goto-unread 'never))
5979        (gnus-summary-last-article-p (gnus-summary-article-number)))
5980    (and gnus-auto-select-same
5981         (gnus-summary-article-subject))))
5982
5983 (defun gnus-summary-prev-article (&optional unread subject)
5984   "Select the article after the current one.
5985 If UNREAD is non-nil, only unread articles are selected."
5986   (interactive "P")
5987   (gnus-summary-next-article unread subject t))
5988
5989 (defun gnus-summary-prev-unread-article ()
5990   "Select unread article before current one."
5991   (interactive)
5992   (gnus-summary-prev-article
5993    (or (not (eq gnus-summary-goto-unread 'never))
5994        (gnus-summary-first-article-p (gnus-summary-article-number)))
5995    (and gnus-auto-select-same
5996         (gnus-summary-article-subject))))
5997
5998 (defun gnus-summary-next-page (&optional lines circular)
5999   "Show next page of the selected article.
6000 If at the end of the current article, select the next article.
6001 LINES says how many lines should be scrolled up.
6002
6003 If CIRCULAR is non-nil, go to the start of the article instead of
6004 selecting the next article when reaching the end of the current
6005 article."
6006   (interactive "P")
6007   (setq gnus-summary-buffer (current-buffer))
6008   (gnus-set-global-variables)
6009   (let ((article (gnus-summary-article-number))
6010         (article-window (get-buffer-window gnus-article-buffer t))
6011         endp)
6012     ;; If the buffer is empty, we have no article.
6013     (unless article
6014       (error "No article to select"))
6015     (gnus-configure-windows 'article)
6016     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6017         (if (and (eq gnus-summary-goto-unread 'never)
6018                  (not (gnus-summary-last-article-p article)))
6019             (gnus-summary-next-article)
6020           (gnus-summary-next-unread-article))
6021       (if (or (null gnus-current-article)
6022               (null gnus-article-current)
6023               (/= article (cdr gnus-article-current))
6024               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6025           ;; Selected subject is different from current article's.
6026           (gnus-summary-display-article article)
6027         (when article-window
6028           (gnus-eval-in-buffer-window gnus-article-buffer
6029             (setq endp (gnus-article-next-page lines)))
6030           (when endp
6031             (cond (circular
6032                    (gnus-summary-beginning-of-article))
6033                   (lines
6034                    (gnus-message 3 "End of message"))
6035                   ((null lines)
6036                    (if (and (eq gnus-summary-goto-unread 'never)
6037                             (not (gnus-summary-last-article-p article)))
6038                        (gnus-summary-next-article)
6039                      (gnus-summary-next-unread-article))))))))
6040     (gnus-summary-recenter)
6041     (gnus-summary-position-point)))
6042
6043 (defun gnus-summary-prev-page (&optional lines move)
6044   "Show previous page of selected article.
6045 Argument LINES specifies lines to be scrolled down.
6046 If MOVE, move to the previous unread article if point is at
6047 the beginning of the buffer."
6048   (interactive "P")
6049   (let ((article (gnus-summary-article-number))
6050         (article-window (get-buffer-window gnus-article-buffer t))
6051         endp)
6052     (gnus-configure-windows 'article)
6053     (if (or (null gnus-current-article)
6054             (null gnus-article-current)
6055             (/= article (cdr gnus-article-current))
6056             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6057         ;; Selected subject is different from current article's.
6058         (gnus-summary-display-article article)
6059       (gnus-summary-recenter)
6060       (when article-window
6061         (gnus-eval-in-buffer-window gnus-article-buffer
6062           (setq endp (gnus-article-prev-page lines)))
6063         (when (and move endp)
6064           (cond (lines
6065                  (gnus-message 3 "Beginning of message"))
6066                 ((null lines)
6067                  (if (and (eq gnus-summary-goto-unread 'never)
6068                           (not (gnus-summary-first-article-p article)))
6069                      (gnus-summary-prev-article)
6070                    (gnus-summary-prev-unread-article))))))))
6071   (gnus-summary-position-point))
6072
6073 (defun gnus-summary-prev-page-or-article (&optional lines)
6074   "Show previous page of selected article.
6075 Argument LINES specifies lines to be scrolled down.
6076 If at the beginning of the article, go to the next article."
6077   (interactive "P")
6078   (gnus-summary-prev-page lines t))
6079
6080 (defun gnus-summary-scroll-up (lines)
6081   "Scroll up (or down) one line current article.
6082 Argument LINES specifies lines to be scrolled up (or down if negative)."
6083   (interactive "p")
6084   (gnus-configure-windows 'article)
6085   (gnus-summary-show-thread)
6086   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6087     (gnus-eval-in-buffer-window gnus-article-buffer
6088       (cond ((> lines 0)
6089              (when (gnus-article-next-page lines)
6090                (gnus-message 3 "End of message")))
6091             ((< lines 0)
6092              (gnus-article-prev-page (- lines))))))
6093   (gnus-summary-recenter)
6094   (gnus-summary-position-point))
6095
6096 (defun gnus-summary-scroll-down (lines)
6097   "Scroll down (or up) one line current article.
6098 Argument LINES specifies lines to be scrolled down (or up if negative)."
6099   (interactive "p")
6100   (gnus-summary-scroll-up (- lines)))
6101
6102 (defun gnus-summary-next-same-subject ()
6103   "Select next article which has the same subject as current one."
6104   (interactive)
6105   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6106
6107 (defun gnus-summary-prev-same-subject ()
6108   "Select previous article which has the same subject as current one."
6109   (interactive)
6110   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6111
6112 (defun gnus-summary-next-unread-same-subject ()
6113   "Select next unread article which has the same subject as current one."
6114   (interactive)
6115   (gnus-summary-next-article t (gnus-summary-article-subject)))
6116
6117 (defun gnus-summary-prev-unread-same-subject ()
6118   "Select previous unread article which has the same subject as current one."
6119   (interactive)
6120   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6121
6122 (defun gnus-summary-first-unread-article ()
6123   "Select the first unread article.
6124 Return nil if there are no unread articles."
6125   (interactive)
6126   (prog1
6127       (when (gnus-summary-first-subject t)
6128         (gnus-summary-show-thread)
6129         (gnus-summary-first-subject t)
6130         (gnus-summary-display-article (gnus-summary-article-number)))
6131     (gnus-summary-position-point)))
6132
6133 (defun gnus-summary-first-unread-subject ()
6134   "Place the point on the subject line of the first unread article.
6135 Return nil if there are no unread articles."
6136   (interactive)
6137   (prog1
6138       (when (gnus-summary-first-subject t)
6139         (gnus-summary-show-thread)
6140         (gnus-summary-first-subject t))
6141     (gnus-summary-position-point)))
6142
6143 (defun gnus-summary-first-article ()
6144   "Select the first article.
6145 Return nil if there are no articles."
6146   (interactive)
6147   (prog1
6148       (when (gnus-summary-first-subject)
6149         (gnus-summary-show-thread)
6150         (gnus-summary-first-subject)
6151         (gnus-summary-display-article (gnus-summary-article-number)))
6152     (gnus-summary-position-point)))
6153
6154 (defun gnus-summary-best-unread-article ()
6155   "Select the unread article with the highest score."
6156   (interactive)
6157   (let ((best -1000000)
6158         (data gnus-newsgroup-data)
6159         article score)
6160     (while data
6161       (and (gnus-data-unread-p (car data))
6162            (> (setq score
6163                     (gnus-summary-article-score (gnus-data-number (car data))))
6164               best)
6165            (setq best score
6166                  article (gnus-data-number (car data))))
6167       (setq data (cdr data)))
6168     (prog1
6169         (if article
6170             (gnus-summary-goto-article article)
6171           (error "No unread articles"))
6172       (gnus-summary-position-point))))
6173
6174 (defun gnus-summary-last-subject ()
6175   "Go to the last displayed subject line in the group."
6176   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6177     (when article
6178       (gnus-summary-goto-subject article))))
6179
6180 (defun gnus-summary-goto-article (article &optional all-headers force)
6181   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6182 If ALL-HEADERS is non-nil, no header lines are hidden.
6183 If FORCE, go to the article even if it isn't displayed.  If FORCE
6184 is a number, it is the line the article is to be displayed on."
6185   (interactive
6186    (list
6187     (completing-read
6188      "Article number or Message-ID: "
6189      (mapcar (lambda (number) (list (int-to-string number)))
6190              gnus-newsgroup-limit))
6191     current-prefix-arg
6192     t))
6193   (prog1
6194       (if (and (stringp article)
6195                (string-match "@" article))
6196           (gnus-summary-refer-article article)
6197         (when (stringp article)
6198           (setq article (string-to-number article)))
6199         (if (gnus-summary-goto-subject article force)
6200             (gnus-summary-display-article article all-headers)
6201           (gnus-message 4 "Couldn't go to article %s" article) nil))
6202     (gnus-summary-position-point)))
6203
6204 (defun gnus-summary-goto-last-article ()
6205   "Go to the previously read article."
6206   (interactive)
6207   (prog1
6208       (when gnus-last-article
6209         (gnus-summary-goto-article gnus-last-article nil t))
6210     (gnus-summary-position-point)))
6211
6212 (defun gnus-summary-pop-article (number)
6213   "Pop one article off the history and go to the previous.
6214 NUMBER articles will be popped off."
6215   (interactive "p")
6216   (let (to)
6217     (setq gnus-newsgroup-history
6218           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6219     (if to
6220         (gnus-summary-goto-article (car to) nil t)
6221       (error "Article history empty")))
6222   (gnus-summary-position-point))
6223
6224 ;; Summary commands and functions for limiting the summary buffer.
6225
6226 (defun gnus-summary-limit-to-articles (n)
6227   "Limit the summary buffer to the next N articles.
6228 If not given a prefix, use the process marked articles instead."
6229   (interactive "P")
6230   (prog1
6231       (let ((articles (gnus-summary-work-articles n)))
6232         (setq gnus-newsgroup-processable nil)
6233         (gnus-summary-limit articles))
6234     (gnus-summary-position-point)))
6235
6236 (defun gnus-summary-pop-limit (&optional total)
6237   "Restore the previous limit.
6238 If given a prefix, remove all limits."
6239   (interactive "P")
6240   (when total
6241     (setq gnus-newsgroup-limits
6242           (list (mapcar (lambda (h) (mail-header-number h))
6243                         gnus-newsgroup-headers))))
6244   (unless gnus-newsgroup-limits
6245     (error "No limit to pop"))
6246   (prog1
6247       (gnus-summary-limit nil 'pop)
6248     (gnus-summary-position-point)))
6249
6250 (defun gnus-summary-limit-to-subject (subject &optional header)
6251   "Limit the summary buffer to articles that have subjects that match a regexp."
6252   (interactive "sLimit to subject (regexp): ")
6253   (unless header
6254     (setq header "subject"))
6255   (when (not (equal "" subject))
6256     (prog1
6257         (let ((articles (gnus-summary-find-matching
6258                          (or header "subject") subject 'all)))
6259           (unless articles
6260             (error "Found no matches for \"%s\"" subject))
6261           (gnus-summary-limit articles))
6262       (gnus-summary-position-point))))
6263
6264 (defun gnus-summary-limit-to-author (from)
6265   "Limit the summary buffer to articles that have authors that match a regexp."
6266   (interactive "sLimit to author (regexp): ")
6267   (gnus-summary-limit-to-subject from "from"))
6268
6269 (defun gnus-summary-limit-to-age (age &optional younger-p)
6270   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6271 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6272 articles that are younger than AGE days."
6273   (interactive
6274    (let ((younger current-prefix-arg)
6275          (days-got nil)
6276          days)
6277      (while (not days-got)
6278        (setq days (if younger
6279                       (read-string "Limit to articles within (in days): ")
6280                     (read-string "Limit to articles old than (in days): ")))
6281        (when (> (length days) 0)
6282          (setq days (read days)))
6283        (if (numberp days)
6284            (setq days-got t)
6285          (message "Please enter a number.")
6286          (sleep-for 1)))
6287      (list days younger)))
6288   (prog1
6289       (let ((data gnus-newsgroup-data)
6290             (cutoff (days-to-time age))
6291             articles d date is-younger)
6292         (while (setq d (pop data))
6293           (when (and (vectorp (gnus-data-header d))
6294                      (setq date (mail-header-date (gnus-data-header d))))
6295             (setq is-younger (time-less-p
6296                               (time-since (condition-case ()
6297                                               (date-to-time date)
6298                                             (error '(0 0))))
6299                               cutoff))
6300             (when (if younger-p
6301                       is-younger
6302                     (not is-younger))
6303               (push (gnus-data-number d) articles))))
6304         (gnus-summary-limit (nreverse articles)))
6305     (gnus-summary-position-point)))
6306
6307 (defun gnus-summary-limit-to-extra (header regexp)
6308   "Limit the summary buffer to articles that match an 'extra' header."
6309   (interactive
6310    (let ((header
6311           (intern
6312            (gnus-completing-read
6313             (symbol-name (car gnus-extra-headers))      
6314             "Limit extra header:"       
6315             (mapcar (lambda (x) 
6316                       (cons (symbol-name x) x))
6317                     gnus-extra-headers)
6318             nil                 
6319             t))))
6320      (list header
6321            (read-string (format "Limit to header %s (regexp): " header)))))
6322   (when (not (equal "" regexp))
6323     (prog1
6324         (let ((articles (gnus-summary-find-matching
6325                          (cons 'extra header) regexp 'all)))
6326           (unless articles
6327             (error "Found no matches for \"%s\"" regexp))
6328           (gnus-summary-limit articles))
6329       (gnus-summary-position-point))))
6330
6331 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6332 (make-obsolete
6333  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6334
6335 (defun gnus-summary-limit-to-unread (&optional all)
6336   "Limit the summary buffer to articles that are not marked as read.
6337 If ALL is non-nil, limit strictly to unread articles."
6338   (interactive "P")
6339   (if all
6340       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6341     (gnus-summary-limit-to-marks
6342      ;; Concat all the marks that say that an article is read and have
6343      ;; those removed.
6344      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6345            gnus-killed-mark gnus-kill-file-mark
6346            gnus-low-score-mark gnus-expirable-mark
6347            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6348            gnus-duplicate-mark gnus-souped-mark)
6349      'reverse)))
6350
6351 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6352 (make-obsolete 'gnus-summary-delete-marked-with
6353                'gnus-summary-limit-exlude-marks)
6354
6355 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6356   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6357 If REVERSE, limit the summary buffer to articles that are marked
6358 with MARKS.  MARKS can either be a string of marks or a list of marks.
6359 Returns how many articles were removed."
6360   (interactive "sMarks: ")
6361   (gnus-summary-limit-to-marks marks t))
6362
6363 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6364   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6365 If REVERSE (the prefix), limit the summary buffer to articles that are
6366 not marked with MARKS.  MARKS can either be a string of marks or a
6367 list of marks.
6368 Returns how many articles were removed."
6369   (interactive "sMarks: \nP")
6370   (prog1
6371       (let ((data gnus-newsgroup-data)
6372             (marks (if (listp marks) marks
6373                      (append marks nil))) ; Transform to list.
6374             articles)
6375         (while data
6376           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6377                   (memq (gnus-data-mark (car data)) marks))
6378             (push (gnus-data-number (car data)) articles))
6379           (setq data (cdr data)))
6380         (gnus-summary-limit articles))
6381     (gnus-summary-position-point)))
6382
6383 (defun gnus-summary-limit-to-score (&optional score)
6384   "Limit to articles with score at or above SCORE."
6385   (interactive "P")
6386   (setq score (if score
6387                   (prefix-numeric-value score)
6388                 (or gnus-summary-default-score 0)))
6389   (let ((data gnus-newsgroup-data)
6390         articles)
6391     (while data
6392       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6393                 score)
6394         (push (gnus-data-number (car data)) articles))
6395       (setq data (cdr data)))
6396     (prog1
6397         (gnus-summary-limit articles)
6398       (gnus-summary-position-point))))
6399
6400 (defun gnus-summary-limit-include-thread (id)
6401   "Display all the hidden articles that in the current thread."
6402   (interactive (list (mail-header-id (gnus-summary-article-header))))
6403   (let ((articles (gnus-articles-in-thread
6404                    (gnus-id-to-thread (gnus-root-id id)))))
6405     (prog1
6406         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6407       (gnus-summary-position-point))))
6408
6409 (defun gnus-summary-limit-include-dormant ()
6410   "Display all the hidden articles that are marked as dormant.
6411 Note that this command only works on a subset of the articles currently
6412 fetched for this group."
6413   (interactive)
6414   (unless gnus-newsgroup-dormant
6415     (error "There are no dormant articles in this group"))
6416   (prog1
6417       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6418     (gnus-summary-position-point)))
6419
6420 (defun gnus-summary-limit-exclude-dormant ()
6421   "Hide all dormant articles."
6422   (interactive)
6423   (prog1
6424       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6425     (gnus-summary-position-point)))
6426
6427 (defun gnus-summary-limit-exclude-childless-dormant ()
6428   "Hide all dormant articles that have no children."
6429   (interactive)
6430   (let ((data (gnus-data-list t))
6431         articles d children)
6432     ;; Find all articles that are either not dormant or have
6433     ;; children.
6434     (while (setq d (pop data))
6435       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6436                 (and (setq children
6437                            (gnus-article-children (gnus-data-number d)))
6438                      (let (found)
6439                        (while children
6440                          (when (memq (car children) articles)
6441                            (setq children nil
6442                                  found t))
6443                          (pop children))
6444                        found)))
6445         (push (gnus-data-number d) articles)))
6446     ;; Do the limiting.
6447     (prog1
6448         (gnus-summary-limit articles)
6449       (gnus-summary-position-point))))
6450
6451 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6452   "Mark all unread excluded articles as read.
6453 If ALL, mark even excluded ticked and dormants as read."
6454   (interactive "P")
6455   (let ((articles (gnus-sorted-complement
6456                    (sort
6457                     (mapcar (lambda (h) (mail-header-number h))
6458                             gnus-newsgroup-headers)
6459                     '<)
6460                    (sort gnus-newsgroup-limit '<)))
6461         article)
6462     (setq gnus-newsgroup-unreads
6463           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6464     (if all
6465         (setq gnus-newsgroup-dormant nil
6466               gnus-newsgroup-marked nil
6467               gnus-newsgroup-reads
6468               (nconc
6469                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6470                gnus-newsgroup-reads))
6471       (while (setq article (pop articles))
6472         (unless (or (memq article gnus-newsgroup-dormant)
6473                     (memq article gnus-newsgroup-marked))
6474           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6475
6476 (defun gnus-summary-limit (articles &optional pop)
6477   (if pop
6478       ;; We pop the previous limit off the stack and use that.
6479       (setq articles (car gnus-newsgroup-limits)
6480             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6481     ;; We use the new limit, so we push the old limit on the stack.
6482     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6483   ;; Set the limit.
6484   (setq gnus-newsgroup-limit articles)
6485   (let ((total (length gnus-newsgroup-data))
6486         (data (gnus-data-find-list (gnus-summary-article-number)))
6487         (gnus-summary-mark-below nil)   ; Inhibit this.
6488         found)
6489     ;; This will do all the work of generating the new summary buffer
6490     ;; according to the new limit.
6491     (gnus-summary-prepare)
6492     ;; Hide any threads, possibly.
6493     (and gnus-show-threads
6494          gnus-thread-hide-subtree
6495          (gnus-summary-hide-all-threads))
6496     ;; Try to return to the article you were at, or one in the
6497     ;; neighborhood.
6498     (when data
6499       ;; We try to find some article after the current one.
6500       (while data
6501         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6502           (setq data nil
6503                 found t))
6504         (setq data (cdr data))))
6505     (unless found
6506       ;; If there is no data, that means that we were after the last
6507       ;; article.  The same goes when we can't find any articles
6508       ;; after the current one.
6509       (goto-char (point-max))
6510       (gnus-summary-find-prev))
6511     (gnus-set-mode-line 'summary)
6512     ;; We return how many articles were removed from the summary
6513     ;; buffer as a result of the new limit.
6514     (- total (length gnus-newsgroup-data))))
6515
6516 (defsubst gnus-invisible-cut-children (threads)
6517   (let ((num 0))
6518     (while threads
6519       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6520         (incf num))
6521       (pop threads))
6522     (< num 2)))
6523
6524 (defsubst gnus-cut-thread (thread)
6525   "Go forwards in the thread until we find an article that we want to display."
6526   (when (or (eq gnus-fetch-old-headers 'some)
6527             (eq gnus-fetch-old-headers 'invisible)
6528             (numberp gnus-fetch-old-headers)
6529             (eq gnus-build-sparse-threads 'some)
6530             (eq gnus-build-sparse-threads 'more))
6531     ;; Deal with old-fetched headers and sparse threads.
6532     (while (and
6533             thread
6534             (or
6535              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6536              (gnus-summary-article-ancient-p
6537               (mail-header-number (car thread))))
6538             (if (or (<= (length (cdr thread)) 1)
6539                     (eq gnus-fetch-old-headers 'invisible))
6540                 (setq gnus-newsgroup-limit
6541                       (delq (mail-header-number (car thread))
6542                             gnus-newsgroup-limit)
6543                       thread (cadr thread))
6544               (when (gnus-invisible-cut-children (cdr thread))
6545                 (let ((th (cdr thread)))
6546                   (while th
6547                     (if (memq (mail-header-number (caar th))
6548                               gnus-newsgroup-limit)
6549                         (setq thread (car th)
6550                               th nil)
6551                       (setq th (cdr th))))))))))
6552   thread)
6553
6554 (defun gnus-cut-threads (threads)
6555   "Cut off all uninteresting articles from the beginning of threads."
6556   (when (or (eq gnus-fetch-old-headers 'some)
6557             (eq gnus-fetch-old-headers 'invisible)
6558             (numberp gnus-fetch-old-headers)
6559             (eq gnus-build-sparse-threads 'some)
6560             (eq gnus-build-sparse-threads 'more))
6561     (let ((th threads))
6562       (while th
6563         (setcar th (gnus-cut-thread (car th)))
6564         (setq th (cdr th)))))
6565   ;; Remove nixed out threads.
6566   (delq nil threads))
6567
6568 (defun gnus-summary-initial-limit (&optional show-if-empty)
6569   "Figure out what the initial limit is supposed to be on group entry.
6570 This entails weeding out unwanted dormants, low-scored articles,
6571 fetch-old-headers verbiage, and so on."
6572   ;; Most groups have nothing to remove.
6573   (if (or gnus-inhibit-limiting
6574           (and (null gnus-newsgroup-dormant)
6575                (not (eq gnus-fetch-old-headers 'some))
6576                (not (numberp gnus-fetch-old-headers))
6577                (not (eq gnus-fetch-old-headers 'invisible))
6578                (null gnus-summary-expunge-below)
6579                (not (eq gnus-build-sparse-threads 'some))
6580                (not (eq gnus-build-sparse-threads 'more))
6581                (null gnus-thread-expunge-below)
6582                (not gnus-use-nocem)))
6583       ()                                ; Do nothing.
6584     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6585     (setq gnus-newsgroup-limit nil)
6586     (mapatoms
6587      (lambda (node)
6588        (unless (car (symbol-value node))
6589          ;; These threads have no parents -- they are roots.
6590          (let ((nodes (cdr (symbol-value node)))
6591                thread)
6592            (while nodes
6593              (if (and gnus-thread-expunge-below
6594                       (< (gnus-thread-total-score (car nodes))
6595                          gnus-thread-expunge-below))
6596                  (gnus-expunge-thread (pop nodes))
6597                (setq thread (pop nodes))
6598                (gnus-summary-limit-children thread))))))
6599      gnus-newsgroup-dependencies)
6600     ;; If this limitation resulted in an empty group, we might
6601     ;; pop the previous limit and use it instead.
6602     (when (and (not gnus-newsgroup-limit)
6603                show-if-empty)
6604       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6605     gnus-newsgroup-limit))
6606
6607 (defun gnus-summary-limit-children (thread)
6608   "Return 1 if this subthread is visible and 0 if it is not."
6609   ;; First we get the number of visible children to this thread.  This
6610   ;; is done by recursing down the thread using this function, so this
6611   ;; will really go down to a leaf article first, before slowly
6612   ;; working its way up towards the root.
6613   (when thread
6614     (let ((children
6615            (if (cdr thread)
6616                (apply '+ (mapcar 'gnus-summary-limit-children
6617                                  (cdr thread)))
6618              0))
6619           (number (mail-header-number (car thread)))
6620           score)
6621       (if (and
6622            (not (memq number gnus-newsgroup-marked))
6623            (or
6624             ;; If this article is dormant and has absolutely no visible
6625             ;; children, then this article isn't visible.
6626             (and (memq number gnus-newsgroup-dormant)
6627                  (zerop children))
6628             ;; If this is "fetch-old-headered" and there is no
6629             ;; visible children, then we don't want this article.
6630             (and (or (eq gnus-fetch-old-headers 'some)
6631                      (numberp gnus-fetch-old-headers))
6632                  (gnus-summary-article-ancient-p number)
6633                  (zerop children))
6634             ;; If this is "fetch-old-headered" and `invisible', then
6635             ;; we don't want this article.
6636             (and (eq gnus-fetch-old-headers 'invisible)
6637                  (gnus-summary-article-ancient-p number))
6638             ;; If this is a sparsely inserted article with no children,
6639             ;; we don't want it.
6640             (and (eq gnus-build-sparse-threads 'some)
6641                  (gnus-summary-article-sparse-p number)
6642                  (zerop children))
6643             ;; If we use expunging, and this article is really
6644             ;; low-scored, then we don't want this article.
6645             (when (and gnus-summary-expunge-below
6646                        (< (setq score
6647                                 (or (cdr (assq number gnus-newsgroup-scored))
6648                                     gnus-summary-default-score))
6649                           gnus-summary-expunge-below))
6650               ;; We increase the expunge-tally here, but that has
6651               ;; nothing to do with the limits, really.
6652               (incf gnus-newsgroup-expunged-tally)
6653               ;; We also mark as read here, if that's wanted.
6654               (when (and gnus-summary-mark-below
6655                          (< score gnus-summary-mark-below))
6656                 (setq gnus-newsgroup-unreads
6657                       (delq number gnus-newsgroup-unreads))
6658                 (if gnus-newsgroup-auto-expire
6659                     (push number gnus-newsgroup-expirable)
6660                   (push (cons number gnus-low-score-mark)
6661                         gnus-newsgroup-reads)))
6662               t)
6663             ;; Check NoCeM things.
6664             (if (and gnus-use-nocem
6665                      (gnus-nocem-unwanted-article-p
6666                       (mail-header-id (car thread))))
6667                 (progn
6668                   (setq gnus-newsgroup-unreads
6669                         (delq number gnus-newsgroup-unreads))
6670                   t))))
6671           ;; Nope, invisible article.
6672           0
6673         ;; Ok, this article is to be visible, so we add it to the limit
6674         ;; and return 1.
6675         (push number gnus-newsgroup-limit)
6676         1))))
6677
6678 (defun gnus-expunge-thread (thread)
6679   "Mark all articles in THREAD as read."
6680   (let* ((number (mail-header-number (car thread))))
6681     (incf gnus-newsgroup-expunged-tally)
6682     ;; We also mark as read here, if that's wanted.
6683     (setq gnus-newsgroup-unreads
6684           (delq number gnus-newsgroup-unreads))
6685     (if gnus-newsgroup-auto-expire
6686         (push number gnus-newsgroup-expirable)
6687       (push (cons number gnus-low-score-mark)
6688             gnus-newsgroup-reads)))
6689   ;; Go recursively through all subthreads.
6690   (mapcar 'gnus-expunge-thread (cdr thread)))
6691
6692 ;; Summary article oriented commands
6693
6694 (defun gnus-summary-refer-parent-article (n)
6695   "Refer parent article N times.
6696 If N is negative, go to ancestor -N instead.
6697 The difference between N and the number of articles fetched is returned."
6698   (interactive "p")
6699   (let ((skip 1)
6700         error header ref)
6701     (when (not (natnump n))
6702       (setq skip (abs n)
6703             n 1))
6704     (while (and (> n 0)
6705                 (not error))
6706       (setq header (gnus-summary-article-header))
6707       (if (and (eq (mail-header-number header)
6708                    (cdr gnus-article-current))
6709                (equal gnus-newsgroup-name
6710                       (car gnus-article-current)))
6711           ;; If we try to find the parent of the currently
6712           ;; displayed article, then we take a look at the actual
6713           ;; References header, since this is slightly more
6714           ;; reliable than the References field we got from the
6715           ;; server.
6716           (save-excursion
6717             (set-buffer gnus-original-article-buffer)
6718             (nnheader-narrow-to-headers)
6719             (unless (setq ref (message-fetch-field "references"))
6720               (setq ref (message-fetch-field "in-reply-to")))
6721             (widen))
6722         (setq ref
6723               ;; It's not the current article, so we take a bet on
6724               ;; the value we got from the server.
6725               (mail-header-references header)))
6726       (if (and ref
6727                (not (equal ref "")))
6728           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6729             (gnus-message 1 "Couldn't find parent"))
6730         (gnus-message 1 "No references in article %d"
6731                       (gnus-summary-article-number))
6732         (setq error t))
6733       (decf n))
6734     (gnus-summary-position-point)
6735     n))
6736
6737 (defun gnus-summary-refer-references ()
6738   "Fetch all articles mentioned in the References header.
6739 Return the number of articles fetched."
6740   (interactive)
6741   (let ((ref (mail-header-references (gnus-summary-article-header)))
6742         (current (gnus-summary-article-number))
6743         (n 0))
6744     (if (or (not ref)
6745             (equal ref ""))
6746         (error "No References in the current article")
6747       ;; For each Message-ID in the References header...
6748       (while (string-match "<[^>]*>" ref)
6749         (incf n)
6750         ;; ... fetch that article.
6751         (gnus-summary-refer-article
6752          (prog1 (match-string 0 ref)
6753            (setq ref (substring ref (match-end 0))))))
6754       (gnus-summary-goto-subject current)
6755       (gnus-summary-position-point)
6756       n)))
6757
6758 (defun gnus-summary-refer-thread (&optional limit)
6759   "Fetch all articles in the current thread.
6760 If LIMIT (the numerical prefix), fetch that many old headers instead
6761 of what's specified by the `gnus-refer-thread-limit' variable."
6762   (interactive "P")
6763   (let ((id (mail-header-id (gnus-summary-article-header)))
6764         (limit (if limit (prefix-numeric-value limit)
6765                  gnus-refer-thread-limit)))
6766     ;; We want to fetch LIMIT *old* headers, but we also have to
6767     ;; re-fetch all the headers in the current buffer, because many of
6768     ;; them may be undisplayed.  So we adjust LIMIT.
6769     (when (numberp limit)
6770       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6771     (unless (eq gnus-fetch-old-headers 'invisible)
6772       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6773       ;; Retrieve the headers and read them in.
6774       (if (eq (gnus-retrieve-headers
6775                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6776               'nov)
6777           (gnus-build-all-threads)
6778         (error "Can't fetch thread from backends that don't support NOV"))
6779       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6780     (gnus-summary-limit-include-thread id)))
6781
6782 (defun gnus-summary-refer-article (message-id)
6783   "Fetch an article specified by MESSAGE-ID."
6784   (interactive "sMessage-ID: ")
6785   (when (and (stringp message-id)
6786              (not (zerop (length message-id))))
6787     ;; Construct the correct Message-ID if necessary.
6788     ;; Suggested by tale@pawl.rpi.edu.
6789     (unless (string-match "^<" message-id)
6790       (setq message-id (concat "<" message-id)))
6791     (unless (string-match ">$" message-id)
6792       (setq message-id (concat message-id ">")))
6793     (let* ((header (gnus-id-to-header message-id))
6794            (sparse (and header
6795                         (gnus-summary-article-sparse-p
6796                          (mail-header-number header))
6797                         (memq (mail-header-number header)
6798                               gnus-newsgroup-limit)))
6799            number)
6800       (cond
6801        ;; If the article is present in the buffer we just go to it.
6802        ((and header
6803              (or (not (gnus-summary-article-sparse-p
6804                        (mail-header-number header)))
6805                  sparse))
6806         (prog1
6807             (gnus-summary-goto-article
6808              (mail-header-number header) nil t)
6809           (when sparse
6810             (gnus-summary-update-article (mail-header-number header)))))
6811        (t
6812         ;; We fetch the article.
6813         (catch 'found
6814           (dolist (gnus-override-method (gnus-refer-article-methods))
6815             (gnus-check-server gnus-override-method)
6816             ;; Fetch the header, and display the article.
6817             (when (setq number (gnus-summary-insert-subject message-id))
6818               (gnus-summary-select-article nil nil nil number)
6819               (throw 'found t)))
6820           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
6821
6822 (defun gnus-refer-article-methods ()
6823   "Return a list of referrable methods."
6824   (cond
6825    ;; No method, so we default to current and native.
6826    ((null gnus-refer-article-method)
6827     (list gnus-current-select-method gnus-select-method))
6828    ;; Current.
6829    ((eq 'current gnus-refer-article-method)
6830     (list gnus-current-select-method))
6831    ;; List of select methods.
6832    ((not (stringp (cadr gnus-refer-article-method)))
6833     (let (out)
6834       (dolist (method gnus-refer-article-method)
6835         (push (if (eq 'current method)
6836                   gnus-current-select-method
6837                 method)
6838               out))
6839       (nreverse out)))
6840    ;; One single select method.
6841    (t
6842     (list gnus-refer-article-method))))
6843
6844 (defun gnus-summary-edit-parameters ()
6845   "Edit the group parameters of the current group."
6846   (interactive)
6847   (gnus-group-edit-group gnus-newsgroup-name 'params))
6848
6849 (defun gnus-summary-customize-parameters ()
6850   "Customize the group parameters of the current group."
6851   (interactive)
6852   (gnus-group-customize gnus-newsgroup-name))
6853
6854 (defun gnus-summary-enter-digest-group (&optional force)
6855   "Enter an nndoc group based on the current article.
6856 If FORCE, force a digest interpretation.  If not, try
6857 to guess what the document format is."
6858   (interactive "P")
6859   (let ((conf gnus-current-window-configuration))
6860     (save-excursion
6861       (gnus-summary-select-article))
6862     (setq gnus-current-window-configuration conf)
6863     (let* ((name (format "%s-%d"
6864                          (gnus-group-prefixed-name
6865                           gnus-newsgroup-name (list 'nndoc ""))
6866                          (save-excursion
6867                            (set-buffer gnus-summary-buffer)
6868                            gnus-current-article)))
6869            (ogroup gnus-newsgroup-name)
6870            (params (append (gnus-info-params (gnus-get-info ogroup))
6871                            (list (cons 'to-group ogroup))
6872                            (list (cons 'save-article-group ogroup))))
6873            (case-fold-search t)
6874            (buf (current-buffer))
6875            dig to-address)
6876       (save-excursion
6877         (set-buffer gnus-original-article-buffer)
6878         ;; Have the digest group inherit the main mail address of
6879         ;; the parent article.
6880         (when (setq to-address (or (message-fetch-field "reply-to")
6881                                    (message-fetch-field "from")))
6882           (setq params (append (list (cons 'to-address to-address)))))
6883         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6884         (insert-buffer-substring gnus-original-article-buffer)
6885         ;; Remove lines that may lead nndoc to misinterpret the
6886         ;; document type.
6887         (narrow-to-region
6888          (goto-char (point-min))
6889          (or (search-forward "\n\n" nil t) (point)))
6890         (goto-char (point-min))
6891         (delete-matching-lines "^Path:\\|^From ")
6892         (widen))
6893       (unwind-protect
6894           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
6895                     (gnus-newsgroup-ephemeral-ignored-charsets
6896                      gnus-newsgroup-ignored-charsets))
6897                 (gnus-group-read-ephemeral-group
6898                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6899                               (nndoc-article-type
6900                                ,(if force 'mbox 'guess))) t))
6901               ;; Make all postings to this group go to the parent group.
6902               (nconc (gnus-info-params (gnus-get-info name))
6903                      params)
6904             ;; Couldn't select this doc group.
6905             (switch-to-buffer buf)
6906             (gnus-set-global-variables)
6907             (gnus-configure-windows 'summary)
6908             (gnus-message 3 "Article couldn't be entered?"))
6909         (kill-buffer dig)))))
6910
6911 (defun gnus-summary-read-document (n)
6912   "Open a new group based on the current article(s).
6913 This will allow you to read digests and other similar
6914 documents as newsgroups.
6915 Obeys the standard process/prefix convention."
6916   (interactive "P")
6917   (let* ((articles (gnus-summary-work-articles n))
6918          (ogroup gnus-newsgroup-name)
6919          (params (append (gnus-info-params (gnus-get-info ogroup))
6920                          (list (cons 'to-group ogroup))))
6921          article group egroup groups vgroup)
6922     (while (setq article (pop articles))
6923       (setq group (format "%s-%d" gnus-newsgroup-name article))
6924       (gnus-summary-remove-process-mark article)
6925       (when (gnus-summary-display-article article)
6926         (save-excursion
6927           (with-temp-buffer
6928             (insert-buffer-substring gnus-original-article-buffer)
6929             ;; Remove some headers that may lead nndoc to make
6930             ;; the wrong guess.
6931             (message-narrow-to-head)
6932             (goto-char (point-min))
6933             (delete-matching-lines "^\\(Path\\):\\|^From ")
6934             (widen)
6935             (if (setq egroup
6936                       (gnus-group-read-ephemeral-group
6937                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6938                                      (nndoc-article-type guess))
6939                        t nil t))
6940                 (progn
6941                   ;; Make all postings to this group go to the parent group.
6942                   (nconc (gnus-info-params (gnus-get-info egroup))
6943                          params)
6944                   (push egroup groups))
6945               ;; Couldn't select this doc group.
6946               (gnus-error 3 "Article couldn't be entered"))))))
6947     ;; Now we have selected all the documents.
6948     (cond
6949      ((not groups)
6950       (error "None of the articles could be interpreted as documents"))
6951      ((gnus-group-read-ephemeral-group
6952        (setq vgroup (format
6953                      "nnvirtual:%s-%s" gnus-newsgroup-name
6954                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6955        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6956        t
6957        (cons (current-buffer) 'summary)))
6958      (t
6959       (error "Couldn't select virtual nndoc group")))))
6960
6961 (defun gnus-summary-isearch-article (&optional regexp-p)
6962   "Do incremental search forward on the current article.
6963 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6964   (interactive "P")
6965   (gnus-summary-select-article)
6966   (gnus-configure-windows 'article)
6967   (gnus-eval-in-buffer-window gnus-article-buffer
6968     (save-restriction
6969       (widen)
6970       (isearch-forward regexp-p))))
6971
6972 (defun gnus-summary-search-article-forward (regexp &optional backward)
6973   "Search for an article containing REGEXP forward.
6974 If BACKWARD, search backward instead."
6975   (interactive
6976    (list (read-string
6977           (format "Search article %s (regexp%s): "
6978                   (if current-prefix-arg "backward" "forward")
6979                   (if gnus-last-search-regexp
6980                       (concat ", default " gnus-last-search-regexp)
6981                     "")))
6982          current-prefix-arg))
6983   (if (string-equal regexp "")
6984       (setq regexp (or gnus-last-search-regexp ""))
6985     (setq gnus-last-search-regexp regexp))
6986   (if (gnus-summary-search-article regexp backward)
6987       (gnus-summary-show-thread)
6988     (error "Search failed: \"%s\"" regexp)))
6989
6990 (defun gnus-summary-search-article-backward (regexp)
6991   "Search for an article containing REGEXP backward."
6992   (interactive
6993    (list (read-string
6994           (format "Search article backward (regexp%s): "
6995                   (if gnus-last-search-regexp
6996                       (concat ", default " gnus-last-search-regexp)
6997                     "")))))
6998   (gnus-summary-search-article-forward regexp 'backward))
6999
7000 (defun gnus-summary-search-article (regexp &optional backward)
7001   "Search for an article containing REGEXP.
7002 Optional argument BACKWARD means do search for backward.
7003 `gnus-select-article-hook' is not called during the search."
7004   ;; We have to require this here to make sure that the following
7005   ;; dynamic binding isn't shadowed by autoloading.
7006   (require 'gnus-async)
7007   (require 'gnus-art)
7008   (let ((gnus-select-article-hook nil)  ;Disable hook.
7009         (gnus-article-prepare-hook nil)
7010         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7011         (gnus-use-article-prefetch nil)
7012         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7013         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7014         (sum (current-buffer))
7015         (gnus-display-mime-function nil)
7016         (found nil)
7017         point)
7018     (gnus-save-hidden-threads
7019       (gnus-summary-select-article)
7020       (set-buffer gnus-article-buffer)
7021       (goto-char (window-point (get-buffer-window (current-buffer))))
7022       (when backward
7023         (forward-line -1))
7024       (while (not found)
7025         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7026         (if (if backward
7027                 (re-search-backward regexp nil t)
7028               (re-search-forward regexp nil t))
7029             ;; We found the regexp.
7030             (progn
7031               (setq found 'found)
7032               (beginning-of-line)
7033               (set-window-start
7034                (get-buffer-window (current-buffer))
7035                (point))
7036               (forward-line 1)
7037               (set-window-point
7038                (get-buffer-window (current-buffer))
7039                (point))
7040               (set-buffer sum)
7041               (setq point (point)))
7042           ;; We didn't find it, so we go to the next article.
7043           (set-buffer sum)
7044           (setq found 'not)
7045           (while (eq found 'not)
7046             (if (not (if backward (gnus-summary-find-prev)
7047                        (gnus-summary-find-next)))
7048                 ;; No more articles.
7049                 (setq found t)
7050               ;; Select the next article and adjust point.
7051               (unless (gnus-summary-article-sparse-p
7052                        (gnus-summary-article-number))
7053                 (setq found nil)
7054                 (gnus-summary-select-article)
7055                 (set-buffer gnus-article-buffer)
7056                 (widen)
7057                 (goto-char (if backward (point-max) (point-min))))))))
7058       (gnus-message 7 ""))
7059     ;; Return whether we found the regexp.
7060     (when (eq found 'found)
7061       (goto-char point)
7062       (gnus-summary-show-thread)
7063       (gnus-summary-goto-subject gnus-current-article)
7064       (gnus-summary-position-point)
7065       t)))
7066
7067 (defun gnus-summary-find-matching (header regexp &optional backward unread
7068                                           not-case-fold)
7069   "Return a list of all articles that match REGEXP on HEADER.
7070 The search stars on the current article and goes forwards unless
7071 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7072 If UNREAD is non-nil, only unread articles will
7073 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7074 in the comparisons."
7075   (let ((data (if (eq backward 'all) gnus-newsgroup-data
7076                 (gnus-data-find-list
7077                  (gnus-summary-article-number) (gnus-data-list backward))))
7078         (case-fold-search (not not-case-fold))
7079         articles d func)
7080     (if (consp header)
7081         (if (eq (car header) 'extra)
7082             (setq func
7083                   `(lambda (h)
7084                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7085                          "")))
7086           (error "%s is an invalid header" header))
7087       (unless (fboundp (intern (concat "mail-header-" header)))
7088         (error "%s is not a valid header" header))
7089       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7090     (while data
7091       (setq d (car data))
7092       (and (or (not unread)             ; We want all articles...
7093                (gnus-data-unread-p d))  ; Or just unreads.
7094            (vectorp (gnus-data-header d)) ; It's not a pseudo.
7095            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
7096            (push (gnus-data-number d) articles)) ; Success!
7097       (setq data (cdr data)))
7098     (nreverse articles)))
7099
7100 (defun gnus-summary-execute-command (header regexp command &optional backward)
7101   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7102 If HEADER is an empty string (or nil), the match is done on the entire
7103 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7104   (interactive
7105    (list (let ((completion-ignore-case t))
7106            (completing-read
7107             "Header name: "
7108             (mapcar (lambda (string) (list string))
7109                     '("Number" "Subject" "From" "Lines" "Date"
7110                       "Message-ID" "Xref" "References" "Body"))
7111             nil 'require-match))
7112          (read-string "Regexp: ")
7113          (read-key-sequence "Command: ")
7114          current-prefix-arg))
7115   (when (equal header "Body")
7116     (setq header ""))
7117   ;; Hidden thread subtrees must be searched as well.
7118   (gnus-summary-show-all-threads)
7119   ;; We don't want to change current point nor window configuration.
7120   (save-excursion
7121     (save-window-excursion
7122       (gnus-message 6 "Executing %s..." (key-description command))
7123       ;; We'd like to execute COMMAND interactively so as to give arguments.
7124       (gnus-execute header regexp
7125                     `(call-interactively ',(key-binding command))
7126                     backward)
7127       (gnus-message 6 "Executing %s...done" (key-description command)))))
7128
7129 (defun gnus-summary-beginning-of-article ()
7130   "Scroll the article back to the beginning."
7131   (interactive)
7132   (gnus-summary-select-article)
7133   (gnus-configure-windows 'article)
7134   (gnus-eval-in-buffer-window gnus-article-buffer
7135     (widen)
7136     (goto-char (point-min))
7137     (when gnus-page-broken
7138       (gnus-narrow-to-page))))
7139
7140 (defun gnus-summary-end-of-article ()
7141   "Scroll to the end of the article."
7142   (interactive)
7143   (gnus-summary-select-article)
7144   (gnus-configure-windows 'article)
7145   (gnus-eval-in-buffer-window gnus-article-buffer
7146     (widen)
7147     (goto-char (point-max))
7148     (recenter -3)
7149     (when gnus-page-broken
7150       (gnus-narrow-to-page))))
7151
7152 (defun gnus-summary-print-article (&optional filename n)
7153   "Generate and print a PostScript image of the N next (mail) articles.
7154
7155 If N is negative, print the N previous articles.  If N is nil and articles
7156 have been marked with the process mark, print these instead.
7157
7158 If the optional first argument FILENAME is nil, send the image to the
7159 printer.  If FILENAME is a string, save the PostScript image in a file with
7160 that name.  If FILENAME is a number, prompt the user for the name of the file
7161 to save in."
7162   (interactive (list (ps-print-preprint current-prefix-arg)
7163                      current-prefix-arg))
7164   (dolist (article (gnus-summary-work-articles n))
7165     (gnus-summary-select-article nil nil 'pseudo article)
7166     (gnus-eval-in-buffer-window gnus-article-buffer
7167       (let ((buffer (generate-new-buffer " *print*")))
7168         (unwind-protect
7169             (progn
7170               (copy-to-buffer buffer (point-min) (point-max))
7171               (set-buffer buffer)
7172               (gnus-article-delete-invisible-text)
7173               (let ((ps-left-header
7174                      (list
7175                       (concat "("
7176                               (mail-header-subject gnus-current-headers) ")")
7177                       (concat "("
7178                               (mail-header-from gnus-current-headers) ")")))
7179                     (ps-right-header
7180                      (list
7181                       "/pagenumberstring load"
7182                       (concat "("
7183                               (mail-header-date gnus-current-headers) ")"))))
7184                 (gnus-run-hooks 'gnus-ps-print-hook)
7185                 (save-excursion
7186                   (ps-print-buffer-with-faces filename))))
7187           (kill-buffer buffer))))))
7188
7189 (defun gnus-summary-show-article (&optional arg)
7190   "Force re-fetching of the current article.
7191 If ARG (the prefix) is a number, show the article with the charset 
7192 defined in `gnus-summary-show-article-charset-alist', or the charset
7193 inputed.
7194 If ARG (the prefix) is non-nil and not a number, show the raw article 
7195 without any article massaging functions being run."
7196   (interactive "P")
7197   (cond 
7198    ((numberp arg)
7199     (let ((gnus-newsgroup-charset 
7200            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7201                (read-coding-system "Charset: ")))
7202           (gnus-newsgroup-ignored-charsets 'gnus-all))
7203       (gnus-summary-select-article nil 'force)))
7204    ((not arg)
7205     ;; Select the article the normal way.
7206     (gnus-summary-select-article nil 'force))
7207    (t
7208     ;; We have to require this here to make sure that the following
7209     ;; dynamic binding isn't shadowed by autoloading.
7210     (require 'gnus-async)
7211     (require 'gnus-art)
7212     ;; Bind the article treatment functions to nil.
7213     (let ((gnus-have-all-headers t)
7214           gnus-article-prepare-hook
7215           gnus-article-decode-hook
7216           gnus-display-mime-function
7217           gnus-break-pages)
7218       ;; Destroy any MIME parts.
7219       (when (gnus-buffer-live-p gnus-article-buffer)
7220         (save-excursion
7221           (set-buffer gnus-article-buffer)
7222           (mm-destroy-parts gnus-article-mime-handles)))
7223       (gnus-summary-select-article nil 'force))))
7224   (gnus-summary-goto-subject gnus-current-article)
7225   (gnus-summary-position-point))
7226
7227 (defun gnus-summary-verbose-headers (&optional arg)
7228   "Toggle permanent full header display.
7229 If ARG is a positive number, turn header display on.
7230 If ARG is a negative number, turn header display off."
7231   (interactive "P")
7232   (setq gnus-show-all-headers
7233         (cond ((or (not (numberp arg))
7234                    (zerop arg))
7235                (not gnus-show-all-headers))
7236               ((natnump arg)
7237                t)))
7238   (gnus-summary-show-article))
7239
7240 (defun gnus-summary-toggle-header (&optional arg)
7241   "Show the headers if they are hidden, or hide them if they are shown.
7242 If ARG is a positive number, show the entire header.
7243 If ARG is a negative number, hide the unwanted header lines."
7244   (interactive "P")
7245   (save-excursion
7246     (set-buffer gnus-article-buffer)
7247     (save-restriction
7248       (let* ((buffer-read-only nil)
7249              (inhibit-point-motion-hooks t)
7250              hidden e)
7251         (setq hidden
7252               (if (numberp arg)
7253                   (>= arg 0)
7254                 (save-restriction 
7255                   (article-narrow-to-head)
7256                   (gnus-article-hidden-text-p 'headers))))
7257         (goto-char (point-min))
7258         (when (search-forward "\n\n" nil t)
7259           (delete-region (point-min) (1- (point))))
7260         (goto-char (point-min))
7261         (save-excursion
7262           (set-buffer gnus-original-article-buffer)
7263           (goto-char (point-min))
7264           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7265         (insert-buffer-substring gnus-original-article-buffer 1 e)
7266         (save-restriction
7267           (narrow-to-region (point-min) (point))
7268           (article-decode-encoded-words)
7269           (if  hidden
7270               (let ((gnus-treat-hide-headers nil)
7271                     (gnus-treat-hide-boring-headers nil))
7272                 (setq gnus-article-wash-types
7273                       (delq 'headers gnus-article-wash-types))
7274                 (gnus-treat-article 'head))
7275             (gnus-treat-article 'head)))
7276         (gnus-set-mode-line 'article)))))
7277
7278 (defun gnus-summary-show-all-headers ()
7279   "Make all header lines visible."
7280   (interactive)
7281   (gnus-article-show-all-headers))
7282
7283 (defun gnus-summary-caesar-message (&optional arg)
7284   "Caesar rotate the current article by 13.
7285 The numerical prefix specifies how many places to rotate each letter
7286 forward."
7287   (interactive "P")
7288   (gnus-summary-select-article)
7289   (let ((mail-header-separator ""))
7290     (gnus-eval-in-buffer-window gnus-article-buffer
7291       (save-restriction
7292         (widen)
7293         (let ((start (window-start))
7294               buffer-read-only)
7295           (message-caesar-buffer-body arg)
7296           (set-window-start (get-buffer-window (current-buffer)) start))))))
7297
7298 (defun gnus-summary-stop-page-breaking ()
7299   "Stop page breaking in the current article."
7300   (interactive)
7301   (gnus-summary-select-article)
7302   (gnus-eval-in-buffer-window gnus-article-buffer
7303     (widen)
7304     (when (gnus-visual-p 'page-marker)
7305       (let ((buffer-read-only nil))
7306         (gnus-remove-text-with-property 'gnus-prev)
7307         (gnus-remove-text-with-property 'gnus-next))
7308       (setq gnus-page-broken nil))))
7309
7310 (defun gnus-summary-move-article (&optional n to-newsgroup
7311                                             select-method action)
7312   "Move the current article to a different newsgroup.
7313 If N is a positive number, move the N next articles.
7314 If N is a negative number, move the N previous articles.
7315 If N is nil and any articles have been marked with the process mark,
7316 move those articles instead.
7317 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7318 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7319 re-spool using this method.
7320
7321 For this function to work, both the current newsgroup and the
7322 newsgroup that you want to move to have to support the `request-move'
7323 and `request-accept' functions.
7324
7325 ACTION can be either `move' (the default), `crosspost' or `copy'."
7326   (interactive "P")
7327   (unless action
7328     (setq action 'move))
7329   ;; Disable marking as read.
7330   (let (gnus-mark-article-hook)
7331     (save-window-excursion
7332       (gnus-summary-select-article)))
7333   ;; Check whether the source group supports the required functions.
7334   (cond ((and (eq action 'move)
7335               (not (gnus-check-backend-function
7336                     'request-move-article gnus-newsgroup-name)))
7337          (error "The current group does not support article moving"))
7338         ((and (eq action 'crosspost)
7339               (not (gnus-check-backend-function
7340                     'request-replace-article gnus-newsgroup-name)))
7341          (error "The current group does not support article editing")))
7342   (let ((articles (gnus-summary-work-articles n))
7343         (prefix (if (gnus-check-backend-function
7344                     'request-move-article gnus-newsgroup-name)
7345                     (gnus-group-real-prefix gnus-newsgroup-name)
7346                   ""))
7347         (names '((move "Move" "Moving")
7348                  (copy "Copy" "Copying")
7349                  (crosspost "Crosspost" "Crossposting")))
7350         (copy-buf (save-excursion
7351                     (nnheader-set-temp-buffer " *copy article*")))
7352         art-group to-method new-xref article to-groups)
7353     (unless (assq action names)
7354       (error "Unknown action %s" action))
7355     ;; Read the newsgroup name.
7356     (when (and (not to-newsgroup)
7357                (not select-method))
7358       (setq to-newsgroup
7359             (gnus-read-move-group-name
7360              (cadr (assq action names))
7361              (symbol-value (intern (format "gnus-current-%s-group" action)))
7362              articles prefix))
7363       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7364     (setq to-method (or select-method
7365                         (gnus-server-to-method
7366                          (gnus-group-method to-newsgroup))))
7367     ;; Check the method we are to move this article to...
7368     (unless (gnus-check-backend-function
7369              'request-accept-article (car to-method))
7370       (error "%s does not support article copying" (car to-method)))
7371     (unless (gnus-check-server to-method)
7372       (error "Can't open server %s" (car to-method)))
7373     (gnus-message 6 "%s to %s: %s..."
7374                   (caddr (assq action names))
7375                   (or (car select-method) to-newsgroup) articles)
7376     (while articles
7377       (setq article (pop articles))
7378       (setq
7379        art-group
7380        (cond
7381         ;; Move the article.
7382         ((eq action 'move)
7383          ;; Remove this article from future suppression.
7384          (gnus-dup-unsuppress-article article)
7385          (gnus-request-move-article
7386           article                       ; Article to move
7387           gnus-newsgroup-name           ; From newsgroup
7388           (nth 1 (gnus-find-method-for-group
7389                   gnus-newsgroup-name)) ; Server
7390           (list 'gnus-request-accept-article
7391                 to-newsgroup (list 'quote select-method)
7392                 (not articles) t)       ; Accept form
7393           (not articles)))              ; Only save nov last time
7394         ;; Copy the article.
7395         ((eq action 'copy)
7396          (save-excursion
7397            (set-buffer copy-buf)
7398            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7399              (gnus-request-accept-article
7400               to-newsgroup select-method (not articles) t))))
7401         ;; Crosspost the article.
7402         ((eq action 'crosspost)
7403          (let ((xref (message-tokenize-header
7404                       (mail-header-xref (gnus-summary-article-header article))
7405                       " ")))
7406            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7407                                   ":" article))
7408            (unless xref
7409              (setq xref (list (system-name))))
7410            (setq new-xref
7411                  (concat
7412                   (mapconcat 'identity
7413                              (delete "Xref:" (delete new-xref xref))
7414                              " ")
7415                   " " new-xref))
7416            (save-excursion
7417              (set-buffer copy-buf)
7418              ;; First put the article in the destination group.
7419              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7420              (when (consp (setq art-group
7421                                 (gnus-request-accept-article
7422                                  to-newsgroup select-method (not articles))))
7423                (setq new-xref (concat new-xref " " (car art-group)
7424                                       ":" (cdr art-group)))
7425                ;; Now we have the new Xrefs header, so we insert
7426                ;; it and replace the new article.
7427                (nnheader-replace-header "Xref" new-xref)
7428                (gnus-request-replace-article
7429                 (cdr art-group) to-newsgroup (current-buffer))
7430                art-group))))))
7431       (cond
7432        ((not art-group)
7433         (gnus-message 1 "Couldn't %s article %s: %s"
7434                       (cadr (assq action names)) article
7435                       (nnheader-get-report (car to-method))))
7436        ((eq art-group 'junk)
7437         (when (eq action 'move)
7438           (gnus-summary-mark-article article gnus-canceled-mark)
7439           (gnus-message 4 "Deleted article %s" article)))
7440        (t
7441         (let* ((pto-group (gnus-group-prefixed-name
7442                            (car art-group) to-method))
7443                (entry
7444                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7445                (info (nth 2 entry))
7446                (to-group (gnus-info-group info))
7447                to-marks)
7448           ;; Update the group that has been moved to.
7449           (when (and info
7450                      (memq action '(move copy)))
7451             (unless (member to-group to-groups)
7452               (push to-group to-groups))
7453
7454             (unless (memq article gnus-newsgroup-unreads)
7455               (push 'read to-marks)
7456               (gnus-info-set-read
7457                info (gnus-add-to-range (gnus-info-read info)
7458                                        (list (cdr art-group)))))
7459
7460             ;; See whether the article is to be put in the cache.
7461             (let ((marks gnus-article-mark-lists)
7462                   (to-article (cdr art-group)))
7463
7464               ;; Enter the article into the cache in the new group,
7465               ;; if that is required.
7466               (when gnus-use-cache
7467                 (gnus-cache-possibly-enter-article
7468                  to-group to-article
7469                  (memq article gnus-newsgroup-marked)
7470                  (memq article gnus-newsgroup-dormant)
7471                  (memq article gnus-newsgroup-unreads)))
7472
7473               (when gnus-preserve-marks 
7474                 ;; Copy any marks over to the new group.
7475                 (when (and (equal to-group gnus-newsgroup-name)
7476                            (not (memq article gnus-newsgroup-unreads)))
7477                   ;; Mark this article as read in this group.
7478                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7479                   (setcdr (gnus-active to-group) to-article)
7480                   (setcdr gnus-newsgroup-active to-article))
7481
7482                 (while marks
7483                   (when (memq article (symbol-value
7484                                        (intern (format "gnus-newsgroup-%s"
7485                                                        (caar marks)))))
7486                     (push (cdar marks) to-marks)
7487                     ;; If the other group is the same as this group,
7488                     ;; then we have to add the mark to the list.
7489                     (when (equal to-group gnus-newsgroup-name)
7490                       (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7491                            (cons to-article
7492                                  (symbol-value
7493                                   (intern (format "gnus-newsgroup-%s"
7494                                                   (caar marks)))))))
7495                     ;; Copy the marks to other group.
7496                     (gnus-add-marked-articles
7497                      to-group (cdar marks) (list to-article) info))
7498                   (setq marks (cdr marks)))
7499
7500                 (gnus-request-set-mark to-group (list (list (list to-article)
7501                                                             'set
7502                                                             to-marks))))
7503
7504               (gnus-dribble-enter
7505                (concat "(gnus-group-set-info '"
7506                        (gnus-prin1-to-string (gnus-get-info to-group))
7507                        ")"))))
7508
7509           ;; Update the Xref header in this article to point to
7510           ;; the new crossposted article we have just created.
7511           (when (eq action 'crosspost)
7512             (save-excursion
7513               (set-buffer copy-buf)
7514               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7515               (nnheader-replace-header "Xref" new-xref)
7516               (gnus-request-replace-article
7517                article gnus-newsgroup-name (current-buffer)))))
7518
7519         ;;;!!!Why is this necessary?
7520         (set-buffer gnus-summary-buffer)
7521
7522         (gnus-summary-goto-subject article)
7523         (when (eq action 'move)
7524           (gnus-summary-mark-article article gnus-canceled-mark))))
7525       (gnus-summary-remove-process-mark article))
7526     ;; Re-activate all groups that have been moved to.
7527     (while to-groups
7528       (save-excursion
7529         (set-buffer gnus-group-buffer)
7530         (when (gnus-group-goto-group (car to-groups) t)
7531           (gnus-group-get-new-news-this-group 1 t))
7532         (pop to-groups)))
7533
7534     (gnus-kill-buffer copy-buf)
7535     (gnus-summary-position-point)
7536     (gnus-set-mode-line 'summary)))
7537
7538 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7539   "Move the current article to a different newsgroup.
7540 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7541 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7542 re-spool using this method."
7543   (interactive "P")
7544   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7545
7546 (defun gnus-summary-crosspost-article (&optional n)
7547   "Crosspost the current article to some other group."
7548   (interactive "P")
7549   (gnus-summary-move-article n nil nil 'crosspost))
7550
7551 (defcustom gnus-summary-respool-default-method nil
7552   "Default method for respooling an article.
7553 If nil, use to the current newsgroup method."
7554   :type '(choice (gnus-select-method :value (nnml ""))
7555                  (const nil))
7556   :group 'gnus-summary-mail)
7557
7558 (defun gnus-summary-respool-article (&optional n method)
7559   "Respool the current article.
7560 The article will be squeezed through the mail spooling process again,
7561 which means that it will be put in some mail newsgroup or other
7562 depending on `nnmail-split-methods'.
7563 If N is a positive number, respool the N next articles.
7564 If N is a negative number, respool the N previous articles.
7565 If N is nil and any articles have been marked with the process mark,
7566 respool those articles instead.
7567
7568 Respooling can be done both from mail groups and \"real\" newsgroups.
7569 In the former case, the articles in question will be moved from the
7570 current group into whatever groups they are destined to.  In the
7571 latter case, they will be copied into the relevant groups."
7572   (interactive
7573    (list current-prefix-arg
7574          (let* ((methods (gnus-methods-using 'respool))
7575                 (methname
7576                  (symbol-name (or gnus-summary-respool-default-method
7577                                   (car (gnus-find-method-for-group
7578                                         gnus-newsgroup-name)))))
7579                 (method
7580                  (gnus-completing-read
7581                   methname "What backend do you want to use when respooling?"
7582                   methods nil t nil 'gnus-mail-method-history))
7583                 ms)
7584            (cond
7585             ((zerop (length (setq ms (gnus-servers-using-backend
7586                                       (intern method)))))
7587              (list (intern method) ""))
7588             ((= 1 (length ms))
7589              (car ms))
7590             (t
7591              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7592                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7593                            ms-alist))))))))
7594   (unless method
7595     (error "No method given for respooling"))
7596   (if (assoc (symbol-name
7597               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7598              (gnus-methods-using 'respool))
7599       (gnus-summary-move-article n nil method)
7600     (gnus-summary-copy-article n nil method)))
7601
7602 (defun gnus-summary-import-article (file)
7603   "Import an arbitrary file into a mail newsgroup."
7604   (interactive "fImport file: ")
7605   (let ((group gnus-newsgroup-name)
7606         (now (current-time))
7607         atts lines)
7608     (unless (gnus-check-backend-function 'request-accept-article group)
7609       (error "%s does not support article importing" group))
7610     (or (file-readable-p file)
7611         (not (file-regular-p file))
7612         (error "Can't read %s" file))
7613     (save-excursion
7614       (set-buffer (gnus-get-buffer-create " *import file*"))
7615       (erase-buffer)
7616       (insert-file-contents file)
7617       (goto-char (point-min))
7618       (unless (nnheader-article-p)
7619         ;; This doesn't look like an article, so we fudge some headers.
7620         (setq atts (file-attributes file)
7621               lines (count-lines (point-min) (point-max)))
7622         (insert "From: " (read-string "From: ") "\n"
7623                 "Subject: " (read-string "Subject: ") "\n"
7624                 "Date: " (message-make-date (nth 5 atts))
7625                 "\n"
7626                 "Message-ID: " (message-make-message-id) "\n"
7627                 "Lines: " (int-to-string lines) "\n"
7628                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7629       (gnus-request-accept-article group nil t)
7630       (kill-buffer (current-buffer)))))
7631
7632 (defun gnus-summary-article-posted-p ()
7633   "Say whether the current (mail) article is available from news as well.
7634 This will be the case if the article has both been mailed and posted."
7635   (interactive)
7636   (let ((id (mail-header-references (gnus-summary-article-header)))
7637         (gnus-override-method (car (gnus-refer-article-methods))))
7638     (if (gnus-request-head id "")
7639         (gnus-message 2 "The current message was found on %s"
7640                       gnus-override-method)
7641       (gnus-message 2 "The current message couldn't be found on %s"
7642                     gnus-override-method)
7643       nil)))
7644
7645 (defun gnus-summary-expire-articles (&optional now)
7646   "Expire all articles that are marked as expirable in the current group."
7647   (interactive)
7648   (when (gnus-check-backend-function
7649          'request-expire-articles gnus-newsgroup-name)
7650     ;; This backend supports expiry.
7651     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7652            (expirable (if total
7653                           (progn
7654                             ;; We need to update the info for
7655                             ;; this group for `gnus-list-of-read-articles'
7656                             ;; to give us the right answer.
7657                             (gnus-run-hooks 'gnus-exit-group-hook)
7658                             (gnus-summary-update-info)
7659                             (gnus-list-of-read-articles gnus-newsgroup-name))
7660                         (setq gnus-newsgroup-expirable
7661                               (sort gnus-newsgroup-expirable '<))))
7662            (expiry-wait (if now 'immediate
7663                           (gnus-group-find-parameter
7664                            gnus-newsgroup-name 'expiry-wait)))
7665            es)
7666       (when expirable
7667         ;; There are expirable articles in this group, so we run them
7668         ;; through the expiry process.
7669         (gnus-message 6 "Expiring articles...")
7670         (unless (gnus-check-group gnus-newsgroup-name)
7671           (error "Can't open server for %s" gnus-newsgroup-name))
7672         ;; The list of articles that weren't expired is returned.
7673         (save-excursion
7674           (if expiry-wait
7675               (let ((nnmail-expiry-wait-function nil)
7676                     (nnmail-expiry-wait expiry-wait))
7677                 (setq es (gnus-request-expire-articles
7678                           expirable gnus-newsgroup-name)))
7679             (setq es (gnus-request-expire-articles
7680                       expirable gnus-newsgroup-name))))
7681         (unless total
7682           (setq gnus-newsgroup-expirable es))
7683         ;; We go through the old list of expirable, and mark all
7684         ;; really expired articles as nonexistent.
7685         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
7686           (let ((gnus-use-cache nil))
7687             (while expirable
7688               (unless (memq (car expirable) es)
7689                 (when (gnus-data-find (car expirable))
7690                   (gnus-summary-mark-article
7691                    (car expirable) gnus-canceled-mark)))
7692               (setq expirable (cdr expirable)))))
7693         (gnus-message 6 "Expiring articles...done")))))
7694
7695 (defun gnus-summary-expire-articles-now ()
7696   "Expunge all expirable articles in the current group.
7697 This means that *all* articles that are marked as expirable will be
7698 deleted forever, right now."
7699   (interactive)
7700   (or gnus-expert-user
7701       (gnus-yes-or-no-p
7702        "Are you really, really, really sure you want to delete all these messages? ")
7703       (error "Phew!"))
7704   (gnus-summary-expire-articles t))
7705
7706 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7707 (defun gnus-summary-delete-article (&optional n)
7708   "Delete the N next (mail) articles.
7709 This command actually deletes articles.  This is not a marking
7710 command.  The article will disappear forever from your life, never to
7711 return.
7712 If N is negative, delete backwards.
7713 If N is nil and articles have been marked with the process mark,
7714 delete these instead."
7715   (interactive "P")
7716   (unless (gnus-check-backend-function 'request-expire-articles
7717                                        gnus-newsgroup-name)
7718     (error "The current newsgroup does not support article deletion"))
7719   ;; Compute the list of articles to delete.
7720   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
7721         not-deleted)
7722     (if (and gnus-novice-user
7723              (not (gnus-yes-or-no-p
7724                    (format "Do you really want to delete %s forever? "
7725                            (if (> (length articles) 1)
7726                                (format "these %s articles" (length articles))
7727                              "this article")))))
7728         ()
7729       ;; Delete the articles.
7730       (setq not-deleted (gnus-request-expire-articles
7731                          articles gnus-newsgroup-name 'force))
7732       (while articles
7733         (gnus-summary-remove-process-mark (car articles))
7734         ;; The backend might not have been able to delete the article
7735         ;; after all.
7736         (unless (memq (car articles) not-deleted)
7737           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7738         (setq articles (cdr articles)))
7739       (when not-deleted
7740         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7741     (gnus-summary-position-point)
7742     (gnus-set-mode-line 'summary)
7743     not-deleted))
7744
7745 (defun gnus-summary-edit-article (&optional arg)
7746   "Edit the current article.
7747 This will have permanent effect only in mail groups.
7748 If ARG is nil, edit the decoded articles.
7749 If ARG is 1, edit the raw articles. 
7750 If ARG is 2, edit the raw articles even in read-only groups.
7751 Otherwise, allow editing of articles even in read-only
7752 groups."
7753   (interactive "P")
7754   (let (force raw)
7755     (cond 
7756      ((null arg))
7757      ((eq arg 1) (setq raw t))
7758      ((eq arg 2) (setq raw t
7759                        force t))
7760      (t (setq force t)))
7761     (save-excursion
7762       (set-buffer gnus-summary-buffer)
7763       (let ((mail-parse-charset gnus-newsgroup-charset)
7764             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
7765         (gnus-set-global-variables)
7766         (when (and (not force)
7767                    (gnus-group-read-only-p))
7768           (error "The current newsgroup does not support article editing"))
7769         (gnus-summary-show-article t)
7770         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
7771           (with-current-buffer gnus-article-buffer
7772             (mm-enable-multibyte)))
7773         (gnus-article-edit-article
7774          (if raw 'ignore 'mime-to-mml)
7775          `(lambda (no-highlight)
7776             (let ((mail-parse-charset ',gnus-newsgroup-charset)
7777                   (mail-parse-ignored-charsets 
7778                    ',gnus-newsgroup-ignored-charsets))
7779               ,(if (not raw) '(mml-to-mime))
7780               (gnus-summary-edit-article-done
7781                ,(or (mail-header-references gnus-current-headers) "")
7782                ,(gnus-group-read-only-p) 
7783                ,gnus-summary-buffer no-highlight))))))))
7784
7785 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7786
7787 (defun gnus-summary-edit-article-done (&optional references read-only buffer
7788                                                  no-highlight)
7789   "Make edits to the current article permanent."
7790   (interactive)
7791   ;; Replace the article.
7792   (let ((buf (current-buffer)))
7793     (with-temp-buffer
7794       (insert-buffer-substring buf)
7795       (if (and (not read-only)
7796                (not (gnus-request-replace-article
7797                      (cdr gnus-article-current) (car gnus-article-current)
7798                      (current-buffer) t)))
7799           (error "Couldn't replace article")
7800         ;; Update the summary buffer.
7801         (if (and references
7802                  (equal (message-tokenize-header references " ")
7803                         (message-tokenize-header
7804                          (or (message-fetch-field "references") "") " ")))
7805             ;; We only have to update this line.
7806             (save-excursion
7807               (save-restriction
7808                 (message-narrow-to-head)
7809                 (let ((head (buffer-string))
7810                       header)
7811                   (with-temp-buffer
7812                     (insert (format "211 %d Article retrieved.\n"
7813                                     (cdr gnus-article-current)))
7814                     (insert head)
7815                     (insert ".\n")
7816                     (let ((nntp-server-buffer (current-buffer)))
7817                       (setq header (car (gnus-get-newsgroup-headers
7818                                          (save-excursion
7819                                            (set-buffer gnus-summary-buffer)
7820                                            gnus-newsgroup-dependencies)
7821                                          t))))
7822                     (save-excursion
7823                       (set-buffer gnus-summary-buffer)
7824                       (gnus-data-set-header
7825                        (gnus-data-find (cdr gnus-article-current))
7826                        header)
7827                       (gnus-summary-update-article-line
7828                        (cdr gnus-article-current) header))))))
7829           ;; Update threads.
7830           (set-buffer (or buffer gnus-summary-buffer))
7831           (gnus-summary-update-article (cdr gnus-article-current)))
7832         ;; Prettify the article buffer again.
7833         (unless no-highlight
7834           (save-excursion
7835             (set-buffer gnus-article-buffer)
7836             ;;;!!! Fix this -- article should be rehighlighted.
7837             ;;;(gnus-run-hooks 'gnus-article-display-hook)
7838             (set-buffer gnus-original-article-buffer)
7839             (gnus-request-article
7840              (cdr gnus-article-current)
7841              (car gnus-article-current) (current-buffer))))
7842         ;; Prettify the summary buffer line.
7843         (when (gnus-visual-p 'summary-highlight 'highlight)
7844           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
7845
7846 (defun gnus-summary-edit-wash (key)
7847   "Perform editing command KEY in the article buffer."
7848   (interactive
7849    (list
7850     (progn
7851       (message "%s" (concat (this-command-keys) "- "))
7852       (read-char))))
7853   (message "")
7854   (gnus-summary-edit-article)
7855   (execute-kbd-macro (concat (this-command-keys) key))
7856   (gnus-article-edit-done))
7857
7858 ;;; Respooling
7859
7860 (defun gnus-summary-respool-query (&optional silent trace)
7861   "Query where the respool algorithm would put this article."
7862   (interactive)
7863   (let (gnus-mark-article-hook)
7864     (gnus-summary-select-article)
7865     (save-excursion
7866       (set-buffer gnus-original-article-buffer)
7867       (save-restriction
7868         (message-narrow-to-head)
7869         (let ((groups (nnmail-article-group 'identity trace)))
7870           (unless silent
7871             (if groups
7872                 (message "This message would go to %s"
7873                          (mapconcat 'car groups ", "))
7874               (message "This message would go to no groups"))
7875             groups))))))
7876
7877 (defun gnus-summary-respool-trace ()
7878   "Trace where the respool algorithm would put this article.
7879 Display a buffer showing all fancy splitting patterns which matched."
7880   (interactive)
7881   (gnus-summary-respool-query nil t))
7882
7883 ;; Summary marking commands.
7884
7885 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7886   "Mark articles which has the same subject as read, and then select the next.
7887 If UNMARK is positive, remove any kind of mark.
7888 If UNMARK is negative, tick articles."
7889   (interactive "P")
7890   (when unmark
7891     (setq unmark (prefix-numeric-value unmark)))
7892   (let ((count
7893          (gnus-summary-mark-same-subject
7894           (gnus-summary-article-subject) unmark)))
7895     ;; Select next unread article.  If auto-select-same mode, should
7896     ;; select the first unread article.
7897     (gnus-summary-next-article t (and gnus-auto-select-same
7898                                       (gnus-summary-article-subject)))
7899     (gnus-message 7 "%d article%s marked as %s"
7900                   count (if (= count 1) " is" "s are")
7901                   (if unmark "unread" "read"))))
7902
7903 (defun gnus-summary-kill-same-subject (&optional unmark)
7904   "Mark articles which has the same subject as read.
7905 If UNMARK is positive, remove any kind of mark.
7906 If UNMARK is negative, tick articles."
7907   (interactive "P")
7908   (when unmark
7909     (setq unmark (prefix-numeric-value unmark)))
7910   (let ((count
7911          (gnus-summary-mark-same-subject
7912           (gnus-summary-article-subject) unmark)))
7913     ;; If marked as read, go to next unread subject.
7914     (when (null unmark)
7915       ;; Go to next unread subject.
7916       (gnus-summary-next-subject 1 t))
7917     (gnus-message 7 "%d articles are marked as %s"
7918                   count (if unmark "unread" "read"))))
7919
7920 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7921   "Mark articles with same SUBJECT as read, and return marked number.
7922 If optional argument UNMARK is positive, remove any kinds of marks.
7923 If optional argument UNMARK is negative, mark articles as unread instead."
7924   (let ((count 1))
7925     (save-excursion
7926       (cond
7927        ((null unmark)                   ; Mark as read.
7928         (while (and
7929                 (progn
7930                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7931                   (gnus-summary-show-thread) t)
7932                 (gnus-summary-find-subject subject))
7933           (setq count (1+ count))))
7934        ((> unmark 0)                    ; Tick.
7935         (while (and
7936                 (progn
7937                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7938                   (gnus-summary-show-thread) t)
7939                 (gnus-summary-find-subject subject))
7940           (setq count (1+ count))))
7941        (t                               ; Mark as unread.
7942         (while (and
7943                 (progn
7944                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7945                   (gnus-summary-show-thread) t)
7946                 (gnus-summary-find-subject subject))
7947           (setq count (1+ count)))))
7948       (gnus-set-mode-line 'summary)
7949       ;; Return the number of marked articles.
7950       count)))
7951
7952 (defun gnus-summary-mark-as-processable (n &optional unmark)
7953   "Set the process mark on the next N articles.
7954 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7955 the process mark instead.  The difference between N and the actual
7956 number of articles marked is returned."
7957   (interactive "p")
7958   (let ((backward (< n 0))
7959         (n (abs n)))
7960     (while (and
7961             (> n 0)
7962             (if unmark
7963                 (gnus-summary-remove-process-mark
7964                  (gnus-summary-article-number))
7965               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7966             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7967       (setq n (1- n)))
7968     (when (/= 0 n)
7969       (gnus-message 7 "No more articles"))
7970     (gnus-summary-recenter)
7971     (gnus-summary-position-point)
7972     n))
7973
7974 (defun gnus-summary-unmark-as-processable (n)
7975   "Remove the process mark from the next N articles.
7976 If N is negative, unmark backward instead.  The difference between N and
7977 the actual number of articles unmarked is returned."
7978   (interactive "p")
7979   (gnus-summary-mark-as-processable n t))
7980
7981 (defun gnus-summary-unmark-all-processable ()
7982   "Remove the process mark from all articles."
7983   (interactive)
7984   (save-excursion
7985     (while gnus-newsgroup-processable
7986       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7987   (gnus-summary-position-point))
7988
7989 (defun gnus-summary-mark-as-expirable (n)
7990   "Mark N articles forward as expirable.
7991 If N is negative, mark backward instead.  The difference between N and
7992 the actual number of articles marked is returned."
7993   (interactive "p")
7994   (gnus-summary-mark-forward n gnus-expirable-mark))
7995
7996 (defun gnus-summary-mark-article-as-replied (article)
7997   "Mark ARTICLE replied and update the summary line."
7998   (push article gnus-newsgroup-replied)
7999   (let ((buffer-read-only nil))
8000     (when (gnus-summary-goto-subject article nil t)
8001       (gnus-summary-update-secondary-mark article))))
8002
8003 (defun gnus-summary-set-bookmark (article)
8004   "Set a bookmark in current article."
8005   (interactive (list (gnus-summary-article-number)))
8006   (when (or (not (get-buffer gnus-article-buffer))
8007             (not gnus-current-article)
8008             (not gnus-article-current)
8009             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8010     (error "No current article selected"))
8011   ;; Remove old bookmark, if one exists.
8012   (let ((old (assq article gnus-newsgroup-bookmarks)))
8013     (when old
8014       (setq gnus-newsgroup-bookmarks
8015             (delq old gnus-newsgroup-bookmarks))))
8016   ;; Set the new bookmark, which is on the form
8017   ;; (article-number . line-number-in-body).
8018   (push
8019    (cons article
8020          (save-excursion
8021            (set-buffer gnus-article-buffer)
8022            (count-lines
8023             (min (point)
8024                  (save-excursion
8025                    (goto-char (point-min))
8026                    (search-forward "\n\n" nil t)
8027                    (point)))
8028             (point))))
8029    gnus-newsgroup-bookmarks)
8030   (gnus-message 6 "A bookmark has been added to the current article."))
8031
8032 (defun gnus-summary-remove-bookmark (article)
8033   "Remove the bookmark from the current article."
8034   (interactive (list (gnus-summary-article-number)))
8035   ;; Remove old bookmark, if one exists.
8036   (let ((old (assq article gnus-newsgroup-bookmarks)))
8037     (if old
8038         (progn
8039           (setq gnus-newsgroup-bookmarks
8040                 (delq old gnus-newsgroup-bookmarks))
8041           (gnus-message 6 "Removed bookmark."))
8042       (gnus-message 6 "No bookmark in current article."))))
8043
8044 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8045 (defun gnus-summary-mark-as-dormant (n)
8046   "Mark N articles forward as dormant.
8047 If N is negative, mark backward instead.  The difference between N and
8048 the actual number of articles marked is returned."
8049   (interactive "p")
8050   (gnus-summary-mark-forward n gnus-dormant-mark))
8051
8052 (defun gnus-summary-set-process-mark (article)
8053   "Set the process mark on ARTICLE and update the summary line."
8054   (setq gnus-newsgroup-processable
8055         (cons article
8056               (delq article gnus-newsgroup-processable)))
8057   (when (gnus-summary-goto-subject article)
8058     (gnus-summary-show-thread)
8059     (gnus-summary-goto-subject article)
8060     (gnus-summary-update-secondary-mark article)))
8061
8062 (defun gnus-summary-remove-process-mark (article)
8063   "Remove the process mark from ARTICLE and update the summary line."
8064   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8065   (when (gnus-summary-goto-subject article)
8066     (gnus-summary-show-thread)
8067     (gnus-summary-goto-subject article)
8068     (gnus-summary-update-secondary-mark article)))
8069
8070 (defun gnus-summary-set-saved-mark (article)
8071   "Set the process mark on ARTICLE and update the summary line."
8072   (push article gnus-newsgroup-saved)
8073   (when (gnus-summary-goto-subject article)
8074     (gnus-summary-update-secondary-mark article)))
8075
8076 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8077   "Mark N articles as read forwards.
8078 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8079 The difference between N and the actual number of articles marked is
8080 returned.
8081 Iff NO-EXPIRE, auto-expiry will be inhibited."
8082   (interactive "p")
8083   (gnus-summary-show-thread)
8084   (let ((backward (< n 0))
8085         (gnus-summary-goto-unread
8086          (and gnus-summary-goto-unread
8087               (not (eq gnus-summary-goto-unread 'never))
8088               (not (memq mark (list gnus-unread-mark
8089                                     gnus-ticked-mark gnus-dormant-mark)))))
8090         (n (abs n))
8091         (mark (or mark gnus-del-mark)))
8092     (while (and (> n 0)
8093                 (gnus-summary-mark-article nil mark no-expire)
8094                 (zerop (gnus-summary-next-subject
8095                         (if backward -1 1)
8096                         (and gnus-summary-goto-unread
8097                              (not (eq gnus-summary-goto-unread 'never)))
8098                         t)))
8099       (setq n (1- n)))
8100     (when (/= 0 n)
8101       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8102     (gnus-summary-recenter)
8103     (gnus-summary-position-point)
8104     (gnus-set-mode-line 'summary)
8105     n))
8106
8107 (defun gnus-summary-mark-article-as-read (mark)
8108   "Mark the current article quickly as read with MARK."
8109   (let ((article (gnus-summary-article-number)))
8110     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8111     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8112     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8113     (push (cons article mark) gnus-newsgroup-reads)
8114     ;; Possibly remove from cache, if that is used.
8115     (when gnus-use-cache
8116       (gnus-cache-enter-remove-article article))
8117     ;; Allow the backend to change the mark.
8118     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8119     ;; Check for auto-expiry.
8120     (when (and gnus-newsgroup-auto-expire
8121                (memq mark gnus-auto-expirable-marks))
8122       (setq mark gnus-expirable-mark)
8123       ;; Let the backend know about the mark change.
8124       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8125       (push article gnus-newsgroup-expirable))
8126     ;; Set the mark in the buffer.
8127     (gnus-summary-update-mark mark 'unread)
8128     t))
8129
8130 (defun gnus-summary-mark-article-as-unread (mark)
8131   "Mark the current article quickly as unread with MARK."
8132   (let* ((article (gnus-summary-article-number))
8133          (old-mark (gnus-summary-article-mark article)))
8134     ;; Allow the backend to change the mark.
8135     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8136     (if (eq mark old-mark)
8137         t
8138       (if (<= article 0)
8139           (progn
8140             (gnus-error 1 "Can't mark negative article numbers")
8141             nil)
8142         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8143         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8144         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8145         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8146         (cond ((= mark gnus-ticked-mark)
8147                (push article gnus-newsgroup-marked))
8148               ((= mark gnus-dormant-mark)
8149                (push article gnus-newsgroup-dormant))
8150               (t
8151                (push article gnus-newsgroup-unreads)))
8152         (gnus-pull article gnus-newsgroup-reads)
8153
8154         ;; See whether the article is to be put in the cache.
8155         (and gnus-use-cache
8156              (vectorp (gnus-summary-article-header article))
8157              (save-excursion
8158                (gnus-cache-possibly-enter-article
8159                 gnus-newsgroup-name article
8160                 (= mark gnus-ticked-mark)
8161                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8162
8163         ;; Fix the mark.
8164         (gnus-summary-update-mark mark 'unread)
8165         t))))
8166
8167 (defun gnus-summary-mark-article (&optional article mark no-expire)
8168   "Mark ARTICLE with MARK.  MARK can be any character.
8169 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8170 `??' (dormant) and `?E' (expirable).
8171 If MARK is nil, then the default character `?r' is used.
8172 If ARTICLE is nil, then the article on the current line will be
8173 marked.
8174 Iff NO-EXPIRE, auto-expiry will be inhibited."
8175   ;; The mark might be a string.
8176   (when (stringp mark)
8177     (setq mark (aref mark 0)))
8178   ;; If no mark is given, then we check auto-expiring.
8179   (when (null mark)
8180     (setq mark gnus-del-mark))
8181   (when (and (not no-expire)
8182              gnus-newsgroup-auto-expire
8183              (memq mark gnus-auto-expirable-marks))
8184     (setq mark gnus-expirable-mark))
8185   (let ((article (or article (gnus-summary-article-number)))
8186         (old-mark (gnus-summary-article-mark article)))
8187     ;; Allow the backend to change the mark.
8188     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8189     (if (eq mark old-mark)
8190         t
8191       (unless article
8192         (error "No article on current line"))
8193       (if (not (if (or (= mark gnus-unread-mark)
8194                        (= mark gnus-ticked-mark)
8195                        (= mark gnus-dormant-mark))
8196                    (gnus-mark-article-as-unread article mark)
8197                  (gnus-mark-article-as-read article mark)))
8198           t
8199         ;; See whether the article is to be put in the cache.
8200         (and gnus-use-cache
8201              (not (= mark gnus-canceled-mark))
8202              (vectorp (gnus-summary-article-header article))
8203              (save-excursion
8204                (gnus-cache-possibly-enter-article
8205                 gnus-newsgroup-name article
8206                 (= mark gnus-ticked-mark)
8207                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8208
8209         (when (gnus-summary-goto-subject article nil t)
8210           (let ((buffer-read-only nil))
8211             (gnus-summary-show-thread)
8212             ;; Fix the mark.
8213             (gnus-summary-update-mark mark 'unread)
8214             t))))))
8215
8216 (defun gnus-summary-update-secondary-mark (article)
8217   "Update the secondary (read, process, cache) mark."
8218   (gnus-summary-update-mark
8219    (cond ((memq article gnus-newsgroup-processable)
8220           gnus-process-mark)
8221          ((memq article gnus-newsgroup-cached)
8222           gnus-cached-mark)
8223          ((memq article gnus-newsgroup-replied)
8224           gnus-replied-mark)
8225          ((memq article gnus-newsgroup-saved)
8226           gnus-saved-mark)
8227          (t gnus-unread-mark))
8228    'replied)
8229   (when (gnus-visual-p 'summary-highlight 'highlight)
8230     (gnus-run-hooks 'gnus-summary-update-hook))
8231   t)
8232
8233 (defun gnus-summary-update-mark (mark type)
8234   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8235         (buffer-read-only nil))
8236     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8237     (when forward
8238       (when (looking-at "\r")
8239         (incf forward))
8240       (when (<= (+ forward (point)) (point-max))
8241         ;; Go to the right position on the line.
8242         (goto-char (+ forward (point)))
8243         ;; Replace the old mark with the new mark.
8244         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8245         ;; Optionally update the marks by some user rule.
8246         (when (eq type 'unread)
8247           (gnus-data-set-mark
8248            (gnus-data-find (gnus-summary-article-number)) mark)
8249           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
8250
8251 (defun gnus-mark-article-as-read (article &optional mark)
8252   "Enter ARTICLE in the pertinent lists and remove it from others."
8253   ;; Make the article expirable.
8254   (let ((mark (or mark gnus-del-mark)))
8255     (if (= mark gnus-expirable-mark)
8256         (push article gnus-newsgroup-expirable)
8257       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8258     ;; Remove from unread and marked lists.
8259     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8260     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8261     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8262     (push (cons article mark) gnus-newsgroup-reads)
8263     ;; Possibly remove from cache, if that is used.
8264     (when gnus-use-cache
8265       (gnus-cache-enter-remove-article article))
8266     t))
8267
8268 (defun gnus-mark-article-as-unread (article &optional mark)
8269   "Enter ARTICLE in the pertinent lists and remove it from others."
8270   (let ((mark (or mark gnus-ticked-mark)))
8271     (if (<= article 0)
8272         (progn
8273           (gnus-error 1 "Can't mark negative article numbers")
8274           nil)
8275       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8276             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8277             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8278             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8279
8280       ;; Unsuppress duplicates?
8281       (when gnus-suppress-duplicates
8282         (gnus-dup-unsuppress-article article))
8283
8284       (cond ((= mark gnus-ticked-mark)
8285              (push article gnus-newsgroup-marked))
8286             ((= mark gnus-dormant-mark)
8287              (push article gnus-newsgroup-dormant))
8288             (t
8289              (push article gnus-newsgroup-unreads)))
8290       (gnus-pull article gnus-newsgroup-reads)
8291       t)))
8292
8293 (defalias 'gnus-summary-mark-as-unread-forward
8294   'gnus-summary-tick-article-forward)
8295 (make-obsolete 'gnus-summary-mark-as-unread-forward
8296                'gnus-summary-tick-article-forward)
8297 (defun gnus-summary-tick-article-forward (n)
8298   "Tick N articles forwards.
8299 If N is negative, tick backwards instead.
8300 The difference between N and the number of articles ticked is returned."
8301   (interactive "p")
8302   (gnus-summary-mark-forward n gnus-ticked-mark))
8303
8304 (defalias 'gnus-summary-mark-as-unread-backward
8305   'gnus-summary-tick-article-backward)
8306 (make-obsolete 'gnus-summary-mark-as-unread-backward
8307                'gnus-summary-tick-article-backward)
8308 (defun gnus-summary-tick-article-backward (n)
8309   "Tick N articles backwards.
8310 The difference between N and the number of articles ticked is returned."
8311   (interactive "p")
8312   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8313
8314 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8315 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8316 (defun gnus-summary-tick-article (&optional article clear-mark)
8317   "Mark current article as unread.
8318 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8319 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8320   (interactive)
8321   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8322                                        gnus-ticked-mark)))
8323
8324 (defun gnus-summary-mark-as-read-forward (n)
8325   "Mark N articles as read forwards.
8326 If N is negative, mark backwards instead.
8327 The difference between N and the actual number of articles marked is
8328 returned."
8329   (interactive "p")
8330   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8331
8332 (defun gnus-summary-mark-as-read-backward (n)
8333   "Mark the N articles as read backwards.
8334 The difference between N and the actual number of articles marked is
8335 returned."
8336   (interactive "p")
8337   (gnus-summary-mark-forward
8338    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8339
8340 (defun gnus-summary-mark-as-read (&optional article mark)
8341   "Mark current article as read.
8342 ARTICLE specifies the article to be marked as read.
8343 MARK specifies a string to be inserted at the beginning of the line."
8344   (gnus-summary-mark-article article mark))
8345
8346 (defun gnus-summary-clear-mark-forward (n)
8347   "Clear marks from N articles forward.
8348 If N is negative, clear backward instead.
8349 The difference between N and the number of marks cleared is returned."
8350   (interactive "p")
8351   (gnus-summary-mark-forward n gnus-unread-mark))
8352
8353 (defun gnus-summary-clear-mark-backward (n)
8354   "Clear marks from N articles backward.
8355 The difference between N and the number of marks cleared is returned."
8356   (interactive "p")
8357   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8358
8359 (defun gnus-summary-mark-unread-as-read ()
8360   "Intended to be used by `gnus-summary-mark-article-hook'."
8361   (when (memq gnus-current-article gnus-newsgroup-unreads)
8362     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8363
8364 (defun gnus-summary-mark-read-and-unread-as-read ()
8365   "Intended to be used by `gnus-summary-mark-article-hook'."
8366   (let ((mark (gnus-summary-article-mark)))
8367     (when (or (gnus-unread-mark-p mark)
8368               (gnus-read-mark-p mark))
8369       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8370
8371 (defun gnus-summary-mark-region-as-read (point mark all)
8372   "Mark all unread articles between point and mark as read.
8373 If given a prefix, mark all articles between point and mark as read,
8374 even ticked and dormant ones."
8375   (interactive "r\nP")
8376   (save-excursion
8377     (let (article)
8378       (goto-char point)
8379       (beginning-of-line)
8380       (while (and
8381               (< (point) mark)
8382               (progn
8383                 (when (or all
8384                           (memq (setq article (gnus-summary-article-number))
8385                                 gnus-newsgroup-unreads))
8386                   (gnus-summary-mark-article article gnus-del-mark))
8387                 t)
8388               (gnus-summary-find-next))))))
8389
8390 (defun gnus-summary-mark-below (score mark)
8391   "Mark articles with score less than SCORE with MARK."
8392   (interactive "P\ncMark: ")
8393   (setq score (if score
8394                   (prefix-numeric-value score)
8395                 (or gnus-summary-default-score 0)))
8396   (save-excursion
8397     (set-buffer gnus-summary-buffer)
8398     (goto-char (point-min))
8399     (while
8400         (progn
8401           (and (< (gnus-summary-article-score) score)
8402                (gnus-summary-mark-article nil mark))
8403           (gnus-summary-find-next)))))
8404
8405 (defun gnus-summary-kill-below (&optional score)
8406   "Mark articles with score below SCORE as read."
8407   (interactive "P")
8408   (gnus-summary-mark-below score gnus-killed-mark))
8409
8410 (defun gnus-summary-clear-above (&optional score)
8411   "Clear all marks from articles with score above SCORE."
8412   (interactive "P")
8413   (gnus-summary-mark-above score gnus-unread-mark))
8414
8415 (defun gnus-summary-tick-above (&optional score)
8416   "Tick all articles with score above SCORE."
8417   (interactive "P")
8418   (gnus-summary-mark-above score gnus-ticked-mark))
8419
8420 (defun gnus-summary-mark-above (score mark)
8421   "Mark articles with score over SCORE with MARK."
8422   (interactive "P\ncMark: ")
8423   (setq score (if score
8424                   (prefix-numeric-value score)
8425                 (or gnus-summary-default-score 0)))
8426   (save-excursion
8427     (set-buffer gnus-summary-buffer)
8428     (goto-char (point-min))
8429     (while (and (progn
8430                   (when (> (gnus-summary-article-score) score)
8431                     (gnus-summary-mark-article nil mark))
8432                   t)
8433                 (gnus-summary-find-next)))))
8434
8435 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8436 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8437 (defun gnus-summary-limit-include-expunged (&optional no-error)
8438   "Display all the hidden articles that were expunged for low scores."
8439   (interactive)
8440   (let ((buffer-read-only nil))
8441     (let ((scored gnus-newsgroup-scored)
8442           headers h)
8443       (while scored
8444         (unless (gnus-summary-goto-subject (caar scored))
8445           (and (setq h (gnus-summary-article-header (caar scored)))
8446                (< (cdar scored) gnus-summary-expunge-below)
8447                (push h headers)))
8448         (setq scored (cdr scored)))
8449       (if (not headers)
8450           (when (not no-error)
8451             (error "No expunged articles hidden"))
8452         (goto-char (point-min))
8453         (gnus-summary-prepare-unthreaded (nreverse headers))
8454         (goto-char (point-min))
8455         (gnus-summary-position-point)
8456         t))))
8457
8458 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8459   "Mark all unread articles in this newsgroup as read.
8460 If prefix argument ALL is non-nil, ticked and dormant articles will
8461 also be marked as read.
8462 If QUIETLY is non-nil, no questions will be asked.
8463 If TO-HERE is non-nil, it should be a point in the buffer.  All
8464 articles before this point will be marked as read.
8465 Note that this function will only catch up the unread article
8466 in the current summary buffer limitation.
8467 The number of articles marked as read is returned."
8468   (interactive "P")
8469   (prog1
8470       (save-excursion
8471         (when (or quietly
8472                   (not gnus-interactive-catchup) ;Without confirmation?
8473                   gnus-expert-user
8474                   (gnus-y-or-n-p
8475                    (if all
8476                        "Mark absolutely all articles as read? "
8477                      "Mark all unread articles as read? ")))
8478           (if (and not-mark
8479                    (not gnus-newsgroup-adaptive)
8480                    (not gnus-newsgroup-auto-expire)
8481                    (not gnus-suppress-duplicates)
8482                    (or (not gnus-use-cache)
8483                        (eq gnus-use-cache 'passive)))
8484               (progn
8485                 (when all
8486                   (setq gnus-newsgroup-marked nil
8487                         gnus-newsgroup-dormant nil))
8488                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8489             ;; We actually mark all articles as canceled, which we
8490             ;; have to do when using auto-expiry or adaptive scoring.
8491             (gnus-summary-show-all-threads)
8492             (when (gnus-summary-first-subject (not all) t)
8493               (while (and
8494                       (if to-here (< (point) to-here) t)
8495                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8496                       (gnus-summary-find-next (not all) nil nil t))))
8497             (gnus-set-mode-line 'summary))
8498           t))
8499     (gnus-summary-position-point)))
8500
8501 (defun gnus-summary-catchup-to-here (&optional all)
8502   "Mark all unticked articles before the current one as read.
8503 If ALL is non-nil, also mark ticked and dormant articles as read."
8504   (interactive "P")
8505   (save-excursion
8506     (gnus-save-hidden-threads
8507       (let ((beg (point)))
8508         ;; We check that there are unread articles.
8509         (when (or all (gnus-summary-find-prev))
8510           (gnus-summary-catchup all t beg)))))
8511   (gnus-summary-position-point))
8512
8513 (defun gnus-summary-catchup-all (&optional quietly)
8514   "Mark all articles in this newsgroup as read."
8515   (interactive "P")
8516   (gnus-summary-catchup t quietly))
8517
8518 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8519   "Mark all unread articles in this group as read, then exit.
8520 If prefix argument ALL is non-nil, all articles are marked as read."
8521   (interactive "P")
8522   (when (gnus-summary-catchup all quietly nil 'fast)
8523     ;; Select next newsgroup or exit.
8524     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8525              (eq gnus-auto-select-next 'quietly))
8526         (gnus-summary-next-group nil)
8527       (gnus-summary-exit))))
8528
8529 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8530   "Mark all articles in this newsgroup as read, and then exit."
8531   (interactive "P")
8532   (gnus-summary-catchup-and-exit t quietly))
8533
8534 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8535   "Mark all articles in this group as read and select the next group.
8536 If given a prefix, mark all articles, unread as well as ticked, as
8537 read."
8538   (interactive "P")
8539   (save-excursion
8540     (gnus-summary-catchup all))
8541   (gnus-summary-next-group))
8542
8543 ;; Thread-based commands.
8544
8545 (defun gnus-summary-articles-in-thread (&optional article)
8546   "Return a list of all articles in the current thread.
8547 If ARTICLE is non-nil, return all articles in the thread that starts
8548 with that article."
8549   (let* ((article (or article (gnus-summary-article-number)))
8550          (data (gnus-data-find-list article))
8551          (top-level (gnus-data-level (car data)))
8552          (top-subject
8553           (cond ((null gnus-thread-operation-ignore-subject)
8554                  (gnus-simplify-subject-re
8555                   (mail-header-subject (gnus-data-header (car data)))))
8556                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8557                  (gnus-simplify-subject-fuzzy
8558                   (mail-header-subject (gnus-data-header (car data)))))
8559                 (t nil)))
8560          (end-point (save-excursion
8561                       (if (gnus-summary-go-to-next-thread)
8562                           (point) (point-max))))
8563          articles)
8564     (while (and data
8565                 (< (gnus-data-pos (car data)) end-point))
8566       (when (or (not top-subject)
8567                 (string= top-subject
8568                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8569                              (gnus-simplify-subject-fuzzy
8570                               (mail-header-subject
8571                                (gnus-data-header (car data))))
8572                            (gnus-simplify-subject-re
8573                             (mail-header-subject
8574                              (gnus-data-header (car data)))))))
8575         (push (gnus-data-number (car data)) articles))
8576       (unless (and (setq data (cdr data))
8577                    (> (gnus-data-level (car data)) top-level))
8578         (setq data nil)))
8579     ;; Return the list of articles.
8580     (nreverse articles)))
8581
8582 (defun gnus-summary-rethread-current ()
8583   "Rethread the thread the current article is part of."
8584   (interactive)
8585   (let* ((gnus-show-threads t)
8586          (article (gnus-summary-article-number))
8587          (id (mail-header-id (gnus-summary-article-header)))
8588          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8589     (unless id
8590       (error "No article on the current line"))
8591     (gnus-rebuild-thread id)
8592     (gnus-summary-goto-subject article)))
8593
8594 (defun gnus-summary-reparent-thread ()
8595   "Make the current article child of the marked (or previous) article.
8596
8597 Note that the re-threading will only work if `gnus-thread-ignore-subject'
8598 is non-nil or the Subject: of both articles are the same."
8599   (interactive)
8600   (unless (not (gnus-group-read-only-p))
8601     (error "The current newsgroup does not support article editing"))
8602   (unless (<= (length gnus-newsgroup-processable) 1)
8603     (error "No more than one article may be marked"))
8604   (save-window-excursion
8605     (let ((gnus-article-buffer " *reparent*")
8606           (current-article (gnus-summary-article-number))
8607           ;; First grab the marked article, otherwise one line up.
8608           (parent-article (if (not (null gnus-newsgroup-processable))
8609                               (car gnus-newsgroup-processable)
8610                             (save-excursion
8611                               (if (eq (forward-line -1) 0)
8612                                   (gnus-summary-article-number)
8613                                 (error "Beginning of summary buffer"))))))
8614       (unless (not (eq current-article parent-article))
8615         (error "An article may not be self-referential"))
8616       (let ((message-id (mail-header-id
8617                          (gnus-summary-article-header parent-article))))
8618         (unless (and message-id (not (equal message-id "")))
8619           (error "No message-id in desired parent"))
8620         (gnus-with-article current-article
8621           (goto-char (point-min))
8622           (if (re-search-forward "^References: " nil t)
8623               (progn
8624                 (re-search-forward "^[^ \t]" nil t)
8625                 (forward-line -1)
8626                 (end-of-line)
8627                 (insert " " message-id))
8628             (insert "References: " message-id "\n")))
8629         (set-buffer gnus-summary-buffer)
8630         (gnus-summary-unmark-all-processable)
8631         (gnus-summary-update-article current-article)
8632         (gnus-summary-rethread-current)
8633         (gnus-message 3 "Article %d is now the child of article %d"
8634                       current-article parent-article)))))
8635
8636 (defun gnus-summary-toggle-threads (&optional arg)
8637   "Toggle showing conversation threads.
8638 If ARG is positive number, turn showing conversation threads on."
8639   (interactive "P")
8640   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8641     (setq gnus-show-threads
8642           (if (null arg) (not gnus-show-threads)
8643             (> (prefix-numeric-value arg) 0)))
8644     (gnus-summary-prepare)
8645     (gnus-summary-goto-subject current)
8646     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8647     (gnus-summary-position-point)))
8648
8649 (defun gnus-summary-show-all-threads ()
8650   "Show all threads."
8651   (interactive)
8652   (save-excursion
8653     (let ((buffer-read-only nil))
8654       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8655   (gnus-summary-position-point))
8656
8657 (defun gnus-summary-show-thread ()
8658   "Show thread subtrees.
8659 Returns nil if no thread was there to be shown."
8660   (interactive)
8661   (let ((buffer-read-only nil)
8662         (orig (point))
8663         ;; first goto end then to beg, to have point at beg after let
8664         (end (progn (end-of-line) (point)))
8665         (beg (progn (beginning-of-line) (point))))
8666     (prog1
8667         ;; Any hidden lines here?
8668         (search-forward "\r" end t)
8669       (subst-char-in-region beg end ?\^M ?\n t)
8670       (goto-char orig)
8671       (gnus-summary-position-point))))
8672
8673 (defun gnus-summary-hide-all-threads ()
8674   "Hide all thread subtrees."
8675   (interactive)
8676   (save-excursion
8677     (goto-char (point-min))
8678     (gnus-summary-hide-thread)
8679     (while (zerop (gnus-summary-next-thread 1 t))
8680       (gnus-summary-hide-thread)))
8681   (gnus-summary-position-point))
8682
8683 (defun gnus-summary-hide-thread ()
8684   "Hide thread subtrees.
8685 Returns nil if no threads were there to be hidden."
8686   (interactive)
8687   (let ((buffer-read-only nil)
8688         (start (point))
8689         (article (gnus-summary-article-number)))
8690     (goto-char start)
8691     ;; Go forward until either the buffer ends or the subthread
8692     ;; ends.
8693     (when (and (not (eobp))
8694                (or (zerop (gnus-summary-next-thread 1 t))
8695                    (goto-char (point-max))))
8696       (prog1
8697           (if (and (> (point) start)
8698                    (search-backward "\n" start t))
8699               (progn
8700                 (subst-char-in-region start (point) ?\n ?\^M)
8701                 (gnus-summary-goto-subject article))
8702             (goto-char start)
8703             nil)))))
8704
8705 (defun gnus-summary-go-to-next-thread (&optional previous)
8706   "Go to the same level (or less) next thread.
8707 If PREVIOUS is non-nil, go to previous thread instead.
8708 Return the article number moved to, or nil if moving was impossible."
8709   (let ((level (gnus-summary-thread-level))
8710         (way (if previous -1 1))
8711         (beg (point)))
8712     (forward-line way)
8713     (while (and (not (eobp))
8714                 (< level (gnus-summary-thread-level)))
8715       (forward-line way))
8716     (if (eobp)
8717         (progn
8718           (goto-char beg)
8719           nil)
8720       (setq beg (point))
8721       (prog1
8722           (gnus-summary-article-number)
8723         (goto-char beg)))))
8724
8725 (defun gnus-summary-next-thread (n &optional silent)
8726   "Go to the same level next N'th thread.
8727 If N is negative, search backward instead.
8728 Returns the difference between N and the number of skips actually
8729 done.
8730
8731 If SILENT, don't output messages."
8732   (interactive "p")
8733   (let ((backward (< n 0))
8734         (n (abs n)))
8735     (while (and (> n 0)
8736                 (gnus-summary-go-to-next-thread backward))
8737       (decf n))
8738     (unless silent
8739       (gnus-summary-position-point))
8740     (when (and (not silent) (/= 0 n))
8741       (gnus-message 7 "No more threads"))
8742     n))
8743
8744 (defun gnus-summary-prev-thread (n)
8745   "Go to the same level previous N'th thread.
8746 Returns the difference between N and the number of skips actually
8747 done."
8748   (interactive "p")
8749   (gnus-summary-next-thread (- n)))
8750
8751 (defun gnus-summary-go-down-thread ()
8752   "Go down one level in the current thread."
8753   (let ((children (gnus-summary-article-children)))
8754     (when children
8755       (gnus-summary-goto-subject (car children)))))
8756
8757 (defun gnus-summary-go-up-thread ()
8758   "Go up one level in the current thread."
8759   (let ((parent (gnus-summary-article-parent)))
8760     (when parent
8761       (gnus-summary-goto-subject parent))))
8762
8763 (defun gnus-summary-down-thread (n)
8764   "Go down thread N steps.
8765 If N is negative, go up instead.
8766 Returns the difference between N and how many steps down that were
8767 taken."
8768   (interactive "p")
8769   (let ((up (< n 0))
8770         (n (abs n)))
8771     (while (and (> n 0)
8772                 (if up (gnus-summary-go-up-thread)
8773                   (gnus-summary-go-down-thread)))
8774       (setq n (1- n)))
8775     (gnus-summary-position-point)
8776     (when (/= 0 n)
8777       (gnus-message 7 "Can't go further"))
8778     n))
8779
8780 (defun gnus-summary-up-thread (n)
8781   "Go up thread N steps.
8782 If N is negative, go up instead.
8783 Returns the difference between N and how many steps down that were
8784 taken."
8785   (interactive "p")
8786   (gnus-summary-down-thread (- n)))
8787
8788 (defun gnus-summary-top-thread ()
8789   "Go to the top of the thread."
8790   (interactive)
8791   (while (gnus-summary-go-up-thread))
8792   (gnus-summary-article-number))
8793
8794 (defun gnus-summary-kill-thread (&optional unmark)
8795   "Mark articles under current thread as read.
8796 If the prefix argument is positive, remove any kinds of marks.
8797 If the prefix argument is negative, tick articles instead."
8798   (interactive "P")
8799   (when unmark
8800     (setq unmark (prefix-numeric-value unmark)))
8801   (let ((articles (gnus-summary-articles-in-thread)))
8802     (save-excursion
8803       ;; Expand the thread.
8804       (gnus-summary-show-thread)
8805       ;; Mark all the articles.
8806       (while articles
8807         (gnus-summary-goto-subject (car articles))
8808         (cond ((null unmark)
8809                (gnus-summary-mark-article-as-read gnus-killed-mark))
8810               ((> unmark 0)
8811                (gnus-summary-mark-article-as-unread gnus-unread-mark))
8812               (t
8813                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8814         (setq articles (cdr articles))))
8815     ;; Hide killed subtrees.
8816     (and (null unmark)
8817          gnus-thread-hide-killed
8818          (gnus-summary-hide-thread))
8819     ;; If marked as read, go to next unread subject.
8820     (when (null unmark)
8821       ;; Go to next unread subject.
8822       (gnus-summary-next-subject 1 t)))
8823   (gnus-set-mode-line 'summary))
8824
8825 ;; Summary sorting commands
8826
8827 (defun gnus-summary-sort-by-number (&optional reverse)
8828   "Sort the summary buffer by article number.
8829 Argument REVERSE means reverse order."
8830   (interactive "P")
8831   (gnus-summary-sort 'number reverse))
8832
8833 (defun gnus-summary-sort-by-author (&optional reverse)
8834   "Sort the summary buffer by author name alphabetically.
8835 If case-fold-search is non-nil, case of letters is ignored.
8836 Argument REVERSE means reverse order."
8837   (interactive "P")
8838   (gnus-summary-sort 'author reverse))
8839
8840 (defun gnus-summary-sort-by-subject (&optional reverse)
8841   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
8842 If case-fold-search is non-nil, case of letters is ignored.
8843 Argument REVERSE means reverse order."
8844   (interactive "P")
8845   (gnus-summary-sort 'subject reverse))
8846
8847 (defun gnus-summary-sort-by-date (&optional reverse)
8848   "Sort the summary buffer by date.
8849 Argument REVERSE means reverse order."
8850   (interactive "P")
8851   (gnus-summary-sort 'date reverse))
8852
8853 (defun gnus-summary-sort-by-score (&optional reverse)
8854   "Sort the summary buffer by score.
8855 Argument REVERSE means reverse order."
8856   (interactive "P")
8857   (gnus-summary-sort 'score reverse))
8858
8859 (defun gnus-summary-sort-by-lines (&optional reverse)
8860   "Sort the summary buffer by the number of lines.
8861 Argument REVERSE means reverse order."
8862   (interactive "P")
8863   (gnus-summary-sort 'lines reverse))
8864
8865 (defun gnus-summary-sort-by-chars (&optional reverse)
8866   "Sort the summary buffer by article length.
8867 Argument REVERSE means reverse order."
8868   (interactive "P")
8869   (gnus-summary-sort 'chars reverse))   
8870
8871 (defun gnus-summary-sort (predicate reverse)
8872   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8873   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8874          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8875          (gnus-thread-sort-functions
8876           (if (not reverse)
8877               thread
8878             `(lambda (t1 t2)
8879                (,thread t2 t1))))
8880          (gnus-article-sort-functions
8881           (if (not reverse)
8882               article
8883             `(lambda (t1 t2)
8884                (,article t2 t1))))
8885          (buffer-read-only)
8886          (gnus-summary-prepare-hook nil))
8887     ;; We do the sorting by regenerating the threads.
8888     (gnus-summary-prepare)
8889     ;; Hide subthreads if needed.
8890     (when (and gnus-show-threads gnus-thread-hide-subtree)
8891       (gnus-summary-hide-all-threads))))
8892
8893 ;; Summary saving commands.
8894
8895 (defun gnus-summary-save-article (&optional n not-saved)
8896   "Save the current article using the default saver function.
8897 If N is a positive number, save the N next articles.
8898 If N is a negative number, save the N previous articles.
8899 If N is nil and any articles have been marked with the process mark,
8900 save those articles instead.
8901 The variable `gnus-default-article-saver' specifies the saver function."
8902   (interactive "P")
8903   (let* ((articles (gnus-summary-work-articles n))
8904          (save-buffer (save-excursion
8905                         (nnheader-set-temp-buffer " *Gnus Save*")))
8906          (num (length articles))
8907          header file)
8908     (dolist (article articles)
8909       (setq header (gnus-summary-article-header article))
8910       (if (not (vectorp header))
8911           ;; This is a pseudo-article.
8912           (if (assq 'name header)
8913               (gnus-copy-file (cdr (assq 'name header)))
8914             (gnus-message 1 "Article %d is unsaveable" article))
8915         ;; This is a real article.
8916         (save-window-excursion
8917           (gnus-summary-select-article t nil nil article))
8918         (save-excursion
8919           (set-buffer save-buffer)
8920           (erase-buffer)
8921           (insert-buffer-substring gnus-original-article-buffer))
8922         (setq file (gnus-article-save save-buffer file num))
8923         (gnus-summary-remove-process-mark article)
8924         (unless not-saved
8925           (gnus-summary-set-saved-mark article))))
8926     (gnus-kill-buffer save-buffer)
8927     (gnus-summary-position-point)
8928     (gnus-set-mode-line 'summary)
8929     n))
8930
8931 (defun gnus-summary-pipe-output (&optional arg)
8932   "Pipe the current article to a subprocess.
8933 If N is a positive number, pipe the N next articles.
8934 If N is a negative number, pipe the N previous articles.
8935 If N is nil and any articles have been marked with the process mark,
8936 pipe those articles instead."
8937   (interactive "P")
8938   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8939     (gnus-summary-save-article arg t))
8940   (gnus-configure-windows 'pipe))
8941
8942 (defun gnus-summary-save-article-mail (&optional arg)
8943   "Append the current article to an mail file.
8944 If N is a positive number, save the N next articles.
8945 If N is a negative number, save the N previous articles.
8946 If N is nil and any articles have been marked with the process mark,
8947 save those articles instead."
8948   (interactive "P")
8949   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8950     (gnus-summary-save-article arg)))
8951
8952 (defun gnus-summary-save-article-rmail (&optional arg)
8953   "Append the current article to an rmail file.
8954 If N is a positive number, save the N next articles.
8955 If N is a negative number, save the N previous articles.
8956 If N is nil and any articles have been marked with the process mark,
8957 save those articles instead."
8958   (interactive "P")
8959   (let ((gnus-default-article-saver 'rmail-output-to-rmail-file))
8960     (gnus-summary-save-article arg)))
8961
8962 (defun gnus-summary-save-article-file (&optional arg)
8963   "Append the current article to a file.
8964 If N is a positive number, save the N next articles.
8965 If N is a negative number, save the N previous articles.
8966 If N is nil and any articles have been marked with the process mark,
8967 save those articles instead."
8968   (interactive "P")
8969   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8970     (gnus-summary-save-article arg)))
8971
8972 (defun gnus-summary-write-article-file (&optional arg)
8973   "Write the current article to a file, deleting the previous file.
8974 If N is a positive number, save the N next articles.
8975 If N is a negative number, save the N previous articles.
8976 If N is nil and any articles have been marked with the process mark,
8977 save those articles instead."
8978   (interactive "P")
8979   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8980     (gnus-summary-save-article arg)))
8981
8982 (defun gnus-summary-save-article-body-file (&optional arg)
8983   "Append the current article body to a file.
8984 If N is a positive number, save the N next articles.
8985 If N is a negative number, save the N previous articles.
8986 If N is nil and any articles have been marked with the process mark,
8987 save those articles instead."
8988   (interactive "P")
8989   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8990     (gnus-summary-save-article arg)))
8991
8992 (defun gnus-summary-pipe-message (program)
8993   "Pipe the current article through PROGRAM."
8994   (interactive "sProgram: ")
8995   (gnus-summary-select-article)
8996   (let ((mail-header-separator ""))
8997     (gnus-eval-in-buffer-window gnus-article-buffer
8998       (save-restriction
8999         (widen)
9000         (let ((start (window-start))
9001               buffer-read-only)
9002           (message-pipe-buffer-body program)
9003           (set-window-start (get-buffer-window (current-buffer)) start))))))
9004
9005 (defun gnus-get-split-value (methods)
9006   "Return a value based on the split METHODS."
9007   (let (split-name method result match)
9008     (when methods
9009       (save-excursion
9010         (set-buffer gnus-original-article-buffer)
9011         (save-restriction
9012           (nnheader-narrow-to-headers)
9013           (while methods
9014             (goto-char (point-min))
9015             (setq method (pop methods))
9016             (setq match (car method))
9017             (when (cond
9018                    ((stringp match)
9019                     ;; Regular expression.
9020                     (ignore-errors
9021                       (re-search-forward match nil t)))
9022                    ((gnus-functionp match)
9023                     ;; Function.
9024                     (save-restriction
9025                       (widen)
9026                       (setq result (funcall match gnus-newsgroup-name))))
9027                    ((consp match)
9028                     ;; Form.
9029                     (save-restriction
9030                       (widen)
9031                       (setq result (eval match)))))
9032               (setq split-name (append (cdr method) split-name))
9033               (cond ((stringp result)
9034                      (push (expand-file-name
9035                             result gnus-article-save-directory)
9036                            split-name))
9037                     ((consp result)
9038                      (setq split-name (append result split-name)))))))))
9039     (nreverse split-name)))
9040
9041 (defun gnus-valid-move-group-p (group)
9042   (and (boundp group)
9043        (symbol-name group)
9044        (symbol-value group)
9045        (gnus-get-function (gnus-find-method-for-group
9046                            (symbol-name group)) 'request-accept-article t)))
9047
9048 (defun gnus-read-move-group-name (prompt default articles prefix)
9049   "Read a group name."
9050   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9051          (minibuffer-confirm-incomplete nil) ; XEmacs
9052          (prom
9053           (format "%s %s to:"
9054                   prompt
9055                   (if (> (length articles) 1)
9056                       (format "these %d articles" (length articles))
9057                     "this article")))
9058          (to-newsgroup
9059           (cond
9060            ((null split-name)
9061             (gnus-completing-read default prom
9062                                   gnus-active-hashtb
9063                                   'gnus-valid-move-group-p
9064                                   nil prefix
9065                                   'gnus-group-history))
9066            ((= 1 (length split-name))
9067             (gnus-completing-read (car split-name) prom
9068                                   gnus-active-hashtb
9069                                   'gnus-valid-move-group-p
9070                                   nil nil
9071                                   'gnus-group-history))
9072            (t
9073             (gnus-completing-read nil prom
9074                                   (mapcar (lambda (el) (list el))
9075                                           (nreverse split-name))
9076                                   nil nil nil
9077                                   'gnus-group-history))))
9078          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
9079     (when to-newsgroup
9080       (if (or (string= to-newsgroup "")
9081               (string= to-newsgroup prefix))
9082           (setq to-newsgroup default))
9083       (unless to-newsgroup
9084         (error "No group name entered"))
9085       (or (gnus-active to-newsgroup)
9086           (gnus-activate-group to-newsgroup nil nil to-method)
9087           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
9088                                      to-newsgroup))
9089               (or (and (gnus-request-create-group to-newsgroup to-method)
9090                        (gnus-activate-group
9091                         to-newsgroup nil nil to-method)
9092                        (gnus-subscribe-group to-newsgroup))
9093                   (error "Couldn't create group %s" to-newsgroup)))
9094           (error "No such group: %s" to-newsgroup)))
9095     to-newsgroup))
9096
9097 (defun gnus-summary-save-parts (type dir n &optional reverse)
9098   "Save parts matching TYPE to DIR.
9099 If REVERSE, save parts that do not match TYPE."
9100   (interactive
9101    (list (read-string "Save parts of type: " "image/.*")
9102          (read-file-name "Save to directory: " nil nil t)
9103          current-prefix-arg))
9104   (gnus-summary-iterate n
9105     (let ((gnus-display-mime-function nil)
9106           (gnus-inhibit-treatment t))
9107       (gnus-summary-select-article))
9108     (save-excursion
9109       (set-buffer gnus-article-buffer)
9110       (let ((handles (or (mm-dissect-buffer) (mm-uu-dissect))))
9111         (when handles
9112           (gnus-summary-save-parts-1 type dir handles reverse)
9113           (mm-destroy-parts handles))))))
9114
9115 (defun gnus-summary-save-parts-1 (type dir handle reverse)
9116   (if (stringp (car handle))
9117       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9118               (cdr handle))
9119     (when (if reverse
9120               (not (string-match type (mm-handle-media-type handle)))
9121             (string-match type (mm-handle-media-type handle)))
9122       (let ((file (expand-file-name
9123                    (file-name-nondirectory
9124                     (or
9125                      (mail-content-type-get
9126                       (mm-handle-disposition handle) 'filename)
9127                      (concat gnus-newsgroup-name "." gnus-current-article)))
9128                    dir)))
9129         (unless (file-exists-p file)
9130           (mm-save-part-to-file handle file))))))
9131
9132 ;; Summary extract commands
9133
9134 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
9135   (let ((buffer-read-only nil)
9136         (article (gnus-summary-article-number))
9137         after-article b e)
9138     (unless (gnus-summary-goto-subject article)
9139       (error "No such article: %d" article))
9140     (gnus-summary-position-point)
9141     ;; If all commands are to be bunched up on one line, we collect
9142     ;; them here.
9143     (unless gnus-view-pseudos-separately
9144       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9145             files action)
9146         (while ps
9147           (setq action (cdr (assq 'action (car ps))))
9148           (setq files (list (cdr (assq 'name (car ps)))))
9149           (while (and ps (cdr ps)
9150                       (string= (or action "1")
9151                                (or (cdr (assq 'action (cadr ps))) "2")))
9152             (push (cdr (assq 'name (cadr ps))) files)
9153             (setcdr ps (cddr ps)))
9154           (when files
9155             (when (not (string-match "%s" action))
9156               (push " " files))
9157             (push " " files)
9158             (when (assq 'execute (car ps))
9159               (setcdr (assq 'execute (car ps))
9160                       (funcall (if (string-match "%s" action)
9161                                    'format 'concat)
9162                                action
9163                                (mapconcat
9164                                 (lambda (f)
9165                                   (if (equal f " ")
9166                                       f
9167                                     (mm-quote-arg f)))
9168                                 files " ")))))
9169           (setq ps (cdr ps)))))
9170     (if (and gnus-view-pseudos (not not-view))
9171         (while pslist
9172           (when (assq 'execute (car pslist))
9173             (gnus-execute-command (cdr (assq 'execute (car pslist)))
9174                                   (eq gnus-view-pseudos 'not-confirm)))
9175           (setq pslist (cdr pslist)))
9176       (save-excursion
9177         (while pslist
9178           (setq after-article (or (cdr (assq 'article (car pslist)))
9179                                   (gnus-summary-article-number)))
9180           (gnus-summary-goto-subject after-article)
9181           (forward-line 1)
9182           (setq b (point))
9183           (insert "    " (file-name-nondirectory
9184                           (cdr (assq 'name (car pslist))))
9185                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9186           (setq e (point))
9187           (forward-line -1)             ; back to `b'
9188           (gnus-add-text-properties
9189            b (1- e) (list 'gnus-number gnus-reffed-article-number
9190                           gnus-mouse-face-prop gnus-mouse-face))
9191           (gnus-data-enter
9192            after-article gnus-reffed-article-number
9193            gnus-unread-mark b (car pslist) 0 (- e b))
9194           (push gnus-reffed-article-number gnus-newsgroup-unreads)
9195           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9196           (setq pslist (cdr pslist)))))))
9197
9198 (defun gnus-pseudos< (p1 p2)
9199   (let ((c1 (cdr (assq 'action p1)))
9200         (c2 (cdr (assq 'action p2))))
9201     (and c1 c2 (string< c1 c2))))
9202
9203 (defun gnus-request-pseudo-article (props)
9204   (cond ((assq 'execute props)
9205          (gnus-execute-command (cdr (assq 'execute props)))))
9206   (let ((gnus-current-article (gnus-summary-article-number)))
9207     (gnus-run-hooks 'gnus-mark-article-hook)))
9208
9209 (defun gnus-execute-command (command &optional automatic)
9210   (save-excursion
9211     (gnus-article-setup-buffer)
9212     (set-buffer gnus-article-buffer)
9213     (setq buffer-read-only nil)
9214     (let ((command (if automatic command
9215                      (read-string "Command: " (cons command 0)))))
9216       (erase-buffer)
9217       (insert "$ " command "\n\n")
9218       (if gnus-view-pseudo-asynchronously
9219           (start-process "gnus-execute" (current-buffer) shell-file-name
9220                          shell-command-switch command)
9221         (call-process shell-file-name nil t nil
9222                       shell-command-switch command)))))
9223
9224 ;; Summary kill commands.
9225
9226 (defun gnus-summary-edit-global-kill (article)
9227   "Edit the \"global\" kill file."
9228   (interactive (list (gnus-summary-article-number)))
9229   (gnus-group-edit-global-kill article))
9230
9231 (defun gnus-summary-edit-local-kill ()
9232   "Edit a local kill file applied to the current newsgroup."
9233   (interactive)
9234   (setq gnus-current-headers (gnus-summary-article-header))
9235   (gnus-group-edit-local-kill
9236    (gnus-summary-article-number) gnus-newsgroup-name))
9237
9238 ;;; Header reading.
9239
9240 (defun gnus-read-header (id &optional header)
9241   "Read the headers of article ID and enter them into the Gnus system."
9242   (let ((group gnus-newsgroup-name)
9243         (gnus-override-method
9244          (or
9245           gnus-override-method
9246           (and (gnus-news-group-p gnus-newsgroup-name)
9247                (car (gnus-refer-article-methods)))))
9248         where)
9249     ;; First we check to see whether the header in question is already
9250     ;; fetched.
9251     (if (stringp id)
9252         ;; This is a Message-ID.
9253         (setq header (or header (gnus-id-to-header id)))
9254       ;; This is an article number.
9255       (setq header (or header (gnus-summary-article-header id))))
9256     (if (and header
9257              (not (gnus-summary-article-sparse-p (mail-header-number header))))
9258         ;; We have found the header.
9259         header
9260       ;; If this is a sparse article, we have to nix out its
9261       ;; previous entry in the thread hashtb.
9262       (when (and header
9263                  (gnus-summary-article-sparse-p (mail-header-number header)))
9264         (let* ((parent (gnus-parent-id (mail-header-references header)))
9265                (thread (and parent (gnus-id-to-thread parent))))
9266           (when thread
9267             (delq (assq header thread) thread))))
9268       ;; We have to really fetch the header to this article.
9269       (save-excursion
9270         (set-buffer nntp-server-buffer)
9271         (when (setq where (gnus-request-head id group))
9272           (nnheader-fold-continuation-lines)
9273           (goto-char (point-max))
9274           (insert ".\n")
9275           (goto-char (point-min))
9276           (insert "211 ")
9277           (princ (cond
9278                   ((numberp id) id)
9279                   ((cdr where) (cdr where))
9280                   (header (mail-header-number header))
9281                   (t gnus-reffed-article-number))
9282                  (current-buffer))
9283           (insert " Article retrieved.\n"))
9284         (if (or (not where)
9285                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9286             ()                          ; Malformed head.
9287           (unless (gnus-summary-article-sparse-p (mail-header-number header))
9288             (when (and (stringp id)
9289                        (not (string= (gnus-group-real-name group)
9290                                      (car where))))
9291               ;; If we fetched by Message-ID and the article came
9292               ;; from a different group, we fudge some bogus article
9293               ;; numbers for this article.
9294               (mail-header-set-number header gnus-reffed-article-number))
9295             (save-excursion
9296               (set-buffer gnus-summary-buffer)
9297               (decf gnus-reffed-article-number)
9298               (gnus-remove-header (mail-header-number header))
9299               (push header gnus-newsgroup-headers)
9300               (setq gnus-current-headers header)
9301               (push (mail-header-number header) gnus-newsgroup-limit)))
9302           header)))))
9303
9304 (defun gnus-remove-header (number)
9305   "Remove header NUMBER from `gnus-newsgroup-headers'."
9306   (if (and gnus-newsgroup-headers
9307            (= number (mail-header-number (car gnus-newsgroup-headers))))
9308       (pop gnus-newsgroup-headers)
9309     (let ((headers gnus-newsgroup-headers))
9310       (while (and (cdr headers)
9311                   (not (= number (mail-header-number (cadr headers)))))
9312         (pop headers))
9313       (when (cdr headers)
9314         (setcdr headers (cddr headers))))))
9315
9316 ;;;
9317 ;;; summary highlights
9318 ;;;
9319
9320 (defun gnus-highlight-selected-summary ()
9321   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9322   ;; Highlight selected article in summary buffer
9323   (when gnus-summary-selected-face
9324     (save-excursion
9325       (let* ((beg (progn (beginning-of-line) (point)))
9326              (end (progn (end-of-line) (point)))
9327              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9328              (from (if (get-text-property beg gnus-mouse-face-prop)
9329                        beg
9330                      (or (next-single-property-change
9331                           beg gnus-mouse-face-prop nil end)
9332                          beg)))
9333              (to
9334               (if (= from end)
9335                   (- from 2)
9336                 (or (next-single-property-change
9337                      from gnus-mouse-face-prop nil end)
9338                     end))))
9339         ;; If no mouse-face prop on line we will have to = from = end,
9340         ;; so we highlight the entire line instead.
9341         (when (= (+ to 2) from)
9342           (setq from beg)
9343           (setq to end))
9344         (if gnus-newsgroup-selected-overlay
9345             ;; Move old overlay.
9346             (gnus-move-overlay
9347              gnus-newsgroup-selected-overlay from to (current-buffer))
9348           ;; Create new overlay.
9349           (gnus-overlay-put
9350            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9351            'face gnus-summary-selected-face))))))
9352
9353 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9354 (defun gnus-summary-highlight-line ()
9355   "Highlight current line according to `gnus-summary-highlight'."
9356   (let* ((list gnus-summary-highlight)
9357          (p (point))
9358          (end (progn (end-of-line) (point)))
9359          ;; now find out where the line starts and leave point there.
9360          (beg (progn (beginning-of-line) (point)))
9361          (article (gnus-summary-article-number))
9362          (score (or (cdr (assq (or article gnus-current-article)
9363                                gnus-newsgroup-scored))
9364                     gnus-summary-default-score 0))
9365          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9366          (inhibit-read-only t))
9367     ;; Eval the cars of the lists until we find a match.
9368     (let ((default gnus-summary-default-score))
9369       (while (and list
9370                   (not (eval (caar list))))
9371         (setq list (cdr list))))
9372     (let ((face (cdar list)))
9373       (unless (eq face (get-text-property beg 'face))
9374         (gnus-put-text-property-excluding-characters-with-faces
9375          beg end 'face
9376          (setq face (if (boundp face) (symbol-value face) face)))
9377         (when gnus-summary-highlight-line-function
9378           (funcall gnus-summary-highlight-line-function article face))))
9379     (goto-char p)))
9380
9381 (defun gnus-update-read-articles (group unread &optional compute)
9382   "Update the list of read articles in GROUP."
9383   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9384          (entry (gnus-gethash group gnus-newsrc-hashtb))
9385          (info (nth 2 entry))
9386          (prev 1)
9387          (unread (sort (copy-sequence unread) '<))
9388          read)
9389     (if (or (not info) (not active))
9390         ;; There is no info on this group if it was, in fact,
9391         ;; killed.  Gnus stores no information on killed groups, so
9392         ;; there's nothing to be done.
9393         ;; One could store the information somewhere temporarily,
9394         ;; perhaps...  Hmmm...
9395         ()
9396       ;; Remove any negative articles numbers.
9397       (while (and unread (< (car unread) 0))
9398         (setq unread (cdr unread)))
9399       ;; Remove any expired article numbers
9400       (while (and unread (< (car unread) (car active)))
9401         (setq unread (cdr unread)))
9402       ;; Compute the ranges of read articles by looking at the list of
9403       ;; unread articles.
9404       (while unread
9405         (when (/= (car unread) prev)
9406           (push (if (= prev (1- (car unread))) prev
9407                   (cons prev (1- (car unread))))
9408                 read))
9409         (setq prev (1+ (car unread)))
9410         (setq unread (cdr unread)))
9411       (when (<= prev (cdr active))
9412         (push (cons prev (cdr active)) read))
9413       (setq read (if (> (length read) 1) (nreverse read) read))
9414       (if compute
9415           read
9416         (save-excursion
9417           (set-buffer gnus-group-buffer)
9418           (gnus-undo-register
9419             `(progn
9420                (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9421                (gnus-info-set-read ',info ',(gnus-info-read info))
9422                (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
9423                (gnus-group-update-group ,group t))))
9424         ;; Propagate the read marks to the backend.
9425         (if (gnus-check-backend-function 'request-set-mark group)
9426             (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9427                   (add (gnus-remove-from-range read (gnus-info-read info))))
9428               (when (or add del)
9429                 (unless (gnus-check-group group)
9430                   (error "Can't open server for %s" group))
9431                 (gnus-request-set-mark
9432                  group (delq nil (list (if add (list add 'add '(read)))
9433                                        (if del (list del 'del '(read)))))))))
9434         ;; Enter this list into the group info.
9435         (gnus-info-set-read info read)
9436         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9437         (gnus-get-unread-articles-in-group info (gnus-active group))
9438         t))))
9439
9440 (defun gnus-offer-save-summaries ()
9441   "Offer to save all active summary buffers."
9442   (save-excursion
9443     (let ((buflist (buffer-list))
9444           buffers bufname)
9445       ;; Go through all buffers and find all summaries.
9446       (while buflist
9447         (and (setq bufname (buffer-name (car buflist)))
9448              (string-match "Summary" bufname)
9449              (save-excursion
9450                (set-buffer bufname)
9451                ;; We check that this is, indeed, a summary buffer.
9452                (and (eq major-mode 'gnus-summary-mode)
9453                     ;; Also make sure this isn't bogus.
9454                     gnus-newsgroup-prepared
9455                     ;; Also make sure that this isn't a dead summary buffer.
9456                     (not gnus-dead-summary-mode)))
9457              (push bufname buffers))
9458         (setq buflist (cdr buflist)))
9459       ;; Go through all these summary buffers and offer to save them.
9460       (when buffers
9461         (map-y-or-n-p
9462          "Update summary buffer %s? "
9463          (lambda (buf)
9464            (switch-to-buffer buf)
9465            (gnus-summary-exit))
9466          buffers)))))
9467
9468 (defun gnus-summary-setup-default-charset ()
9469   "Setup newsgroup default charset."
9470   (if (equal gnus-newsgroup-name "nndraft:drafts")
9471       (setq gnus-newsgroup-charset nil)
9472     (let* ((name (and gnus-newsgroup-name
9473                       (gnus-group-real-name gnus-newsgroup-name)))
9474            (ignored-charsets 
9475             (or gnus-newsgroup-ephemeral-ignored-charsets
9476                 (append
9477                  (and gnus-newsgroup-name
9478                       (or (gnus-group-find-parameter gnus-newsgroup-name
9479                                                      'ignored-charsets t)
9480                           (let ((alist gnus-group-ignored-charsets-alist)
9481                                 elem (charsets nil))
9482                             (while (setq elem (pop alist))
9483                               (when (and name
9484                                          (string-match (car elem) name))
9485                                 (setq alist nil
9486                                       charsets (cdr elem))))
9487                             charsets)))
9488                  gnus-newsgroup-ignored-charsets))))
9489       (setq gnus-newsgroup-charset
9490             (or gnus-newsgroup-ephemeral-charset
9491                 (and gnus-newsgroup-name
9492                      (or (gnus-group-find-parameter gnus-newsgroup-name 'charset)
9493                          (let ((alist gnus-group-charset-alist)
9494                                elem charset)
9495                            (while (setq elem (pop alist))
9496                              (when (and name
9497                                         (string-match (car elem) name))
9498                                (setq alist nil
9499                                      charset (cadr elem))))
9500                            charset)))
9501                 gnus-default-charset))
9502       (set (make-local-variable 'gnus-newsgroup-ignored-charsets) 
9503            ignored-charsets))))
9504
9505 ;;;
9506 ;;; Mime Commands
9507 ;;;
9508
9509 (defun gnus-summary-display-buttonized (&optional show-all-parts)
9510   "Display the current article buffer fully MIME-buttonized.
9511 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
9512 treated as multipart/mixed."
9513   (interactive "P")
9514   (require 'gnus-art)
9515   (let ((gnus-unbuttonized-mime-types nil)
9516         (gnus-mime-display-multipart-as-mixed show-all-parts))
9517     (gnus-summary-show-article)))
9518
9519 (defun gnus-summary-repair-multipart (article)
9520   "Add a Content-Type header to a multipart article without one."
9521   (interactive (list (gnus-summary-article-number)))
9522   (gnus-with-article article
9523     (message-narrow-to-head)
9524     (goto-char (point-max))
9525     (widen)
9526     (when (search-forward "\n--" nil t)
9527       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
9528         (message-narrow-to-head)
9529         (message-remove-header "Mime-Version")
9530         (message-remove-header "Content-Type")
9531         (goto-char (point-max))
9532         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
9533                         separator))
9534         (insert "Mime-Version: 1.0\n")
9535         (widen))))
9536   (let (gnus-mark-article-hook)
9537     (gnus-summary-select-article t t nil article)))
9538
9539 (defun gnus-summary-toggle-display-buttonized ()
9540   "Toggle the buttonizing of the article buffer."
9541   (interactive)
9542   (require 'gnus-art)
9543   (if (setq gnus-inhibit-mime-unbuttonizing
9544             (not gnus-inhibit-mime-unbuttonizing))
9545       (let ((gnus-unbuttonized-mime-types nil))
9546         (gnus-summary-show-article))
9547     (gnus-summary-show-article)))
9548
9549 ;;;
9550 ;;; with article
9551 ;;;
9552
9553 (defmacro gnus-with-article (article &rest forms)
9554   "Select ARTICLE and perform FORMS in the original article buffer.
9555 Then replace the article with the result."
9556   `(progn
9557      ;; We don't want the article to be marked as read.
9558      (let (gnus-mark-article-hook)
9559        (gnus-summary-select-article t t nil ,article))
9560      (set-buffer gnus-original-article-buffer)
9561      ,@forms
9562      (if (not (gnus-check-backend-function
9563                'request-replace-article (car gnus-article-current)))
9564          (gnus-message 5 "Read-only group; not replacing")
9565        (unless (gnus-request-replace-article
9566                 ,article (car gnus-article-current)
9567                 (current-buffer) t)
9568          (error "Couldn't replace article")))
9569      ;; The cache and backlog have to be flushed somewhat.
9570      (when gnus-keep-backlog
9571        (gnus-backlog-remove-article
9572         (car gnus-article-current) (cdr gnus-article-current)))
9573      (when gnus-use-cache
9574        (gnus-cache-update-article
9575         (car gnus-article-current) (cdr gnus-article-current)))))
9576
9577 (put 'gnus-with-article 'lisp-indent-function 1)
9578 (put 'gnus-with-article 'edebug-form-spec '(form body))
9579
9580 ;;;
9581 ;;; Generic summary marking commands
9582 ;;;
9583
9584 (defvar gnus-summary-marking-alist
9585   '((read gnus-del-mark "d")
9586     (unread gnus-unread-mark "u")
9587     (ticked gnus-ticked-mark "!")
9588     (dormant gnus-dormant-mark "?")
9589     (expirable gnus-expirable-mark "e"))
9590   "An alist of names/marks/keystrokes.")
9591
9592 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
9593 (defvar gnus-summary-mark-map)
9594
9595 (defun gnus-summary-make-all-marking-commands ()
9596   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
9597   (dolist (elem gnus-summary-marking-alist)
9598     (apply 'gnus-summary-make-marking-command elem)))
9599
9600 (defun gnus-summary-make-marking-command (name mark keystroke)
9601   (let ((map (make-sparse-keymap)))
9602     (define-key gnus-summary-generic-mark-map keystroke map)
9603     (dolist (lway `((next "next" next nil "n")
9604                     (next-unread "next unread" next t "N")
9605                     (prev "previous" prev nil "p")
9606                     (prev-unread "previous unread" prev t "P")
9607                     (nomove "" nil nil ,keystroke)))
9608       (let ((func (gnus-summary-make-marking-command-1
9609                    mark (car lway) lway name)))
9610         (setq func (eval func))
9611         (define-key map (nth 4 lway) func)))))
9612       
9613 (defun gnus-summary-make-marking-command-1 (mark way lway name)      
9614   `(defun ,(intern
9615             (format "gnus-summary-put-mark-as-%s%s"
9616                     name (if (eq way 'nomove)
9617                              ""
9618                            (concat "-" (symbol-name way)))))
9619      (n)
9620      ,(format
9621        "Mark the current article as %s%s.
9622 If N, the prefix, then repeat N times.
9623 If N is negative, move in reverse order.
9624 The difference between N and the actual number of articles marked is
9625 returned."
9626        name (cadr lway))
9627      (interactive "p")
9628      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
9629     
9630 (defun gnus-summary-generic-mark (n mark move unread)
9631   "Mark N articles with MARK."
9632   (unless (eq major-mode 'gnus-summary-mode)
9633     (error "This command can only be used in the summary buffer"))
9634   (gnus-summary-show-thread)
9635   (let ((nummove
9636          (cond
9637           ((eq move 'next) 1)
9638           ((eq move 'prev) -1)
9639           (t 0))))
9640     (if (zerop nummove)
9641         (setq n 1)
9642       (when (< n 0)
9643         (setq n (abs n)
9644               nummove (* -1 nummove))))
9645     (while (and (> n 0)
9646                 (gnus-summary-mark-article nil mark)
9647                 (zerop (gnus-summary-next-subject nummove unread t)))
9648       (setq n (1- n)))
9649     (when (/= 0 n)
9650       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9651     (gnus-summary-recenter)
9652     (gnus-summary-position-point)
9653     (gnus-set-mode-line 'summary)
9654     n))
9655
9656 (gnus-summary-make-all-marking-commands)
9657
9658 (gnus-ems-redefine)
9659
9660 (provide 'gnus-sum)
9661
9662 (run-hooks 'gnus-sum-load-hook)
9663
9664 ;;; gnus-sum.el ends here