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