* gnus-art.el (gnus-article-treat-unfold-headers): Only fold when
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
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 ;; Recursive :-(.
40 ;; (require 'gnus-art)
41 (require 'nnoo)
42 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
43 (autoload 'gnus-cache-write-active "gnus-cache")
44 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
45 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
46 (autoload 'mm-uu-dissect "mm-uu")
47
48 (defcustom gnus-kill-summary-on-exit t
49   "*If non-nil, kill the summary buffer when you exit from it.
50 If nil, the summary will become a \"*Dead Summary*\" buffer, and
51 it will be killed sometime later."
52   :group 'gnus-summary-exit
53   :type 'boolean)
54
55 (defcustom gnus-fetch-old-headers nil
56   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
57 If an unread article in the group refers to an older, already read (or
58 just marked as read) article, the old article will not normally be
59 displayed in the Summary buffer.  If this variable is non-nil, Gnus
60 will attempt to grab the headers to the old articles, and thereby
61 build complete threads.  If it has the value `some', only enough
62 headers to connect otherwise loose threads will be displayed.  This
63 variable can also be a number.  In that case, no more than that number
64 of old headers will be fetched.  If it has the value `invisible', all
65 old headers will be fetched, but none will be displayed.
66
67 The server has to support NOV for any of this to work."
68   :group 'gnus-thread
69   :type '(choice (const :tag "off" nil)
70                  (const some)
71                  number
72                  (sexp :menu-tag "other" t)))
73
74 (defcustom gnus-refer-thread-limit 200
75   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
76 If t, fetch all the available old headers."
77   :group 'gnus-thread
78   :type '(choice number
79                  (sexp :menu-tag "other" t)))
80
81 (defcustom gnus-summary-make-false-root 'adopt
82   "*nil means that Gnus won't gather loose threads.
83 If the root of a thread has expired or been read in a previous
84 session, the information necessary to build a complete thread has been
85 lost.  Instead of having many small sub-threads from this original thread
86 scattered all over the summary buffer, Gnus can gather them.
87
88 If non-nil, Gnus will try to gather all loose sub-threads from an
89 original thread into one large thread.
90
91 If this variable is non-nil, it should be one of `none', `adopt',
92 `dummy' or `empty'.
93
94 If this variable is `none', Gnus will not make a false root, but just
95 present the sub-threads after another.
96 If this variable is `dummy', Gnus will create a dummy root that will
97 have all the sub-threads as children.
98 If this variable is `adopt', Gnus will make one of the \"children\"
99 the parent and mark all the step-children as such.
100 If this variable is `empty', the \"children\" are printed with empty
101 subject fields.  (Or rather, they will be printed with a string
102 given by the `gnus-summary-same-subject' variable.)"
103   :group 'gnus-thread
104   :type '(choice (const :tag "off" nil)
105                  (const none)
106                  (const dummy)
107                  (const adopt)
108                  (const empty)))
109
110 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
111   "*A regexp to match subjects to be excluded from loose thread gathering.
112 As loose thread gathering is done on subjects only, that means that
113 there can be many false gatherings performed.  By rooting out certain
114 common subjects, gathering might become saner."
115   :group 'gnus-thread
116   :type 'regexp)
117
118 (defcustom gnus-summary-gather-subject-limit nil
119   "*Maximum length of subject comparisons when gathering loose threads.
120 Use nil to compare full subjects.  Setting this variable to a low
121 number will help gather threads that have been corrupted by
122 newsreaders chopping off subject lines, but it might also mean that
123 unrelated articles that have subject that happen to begin with the
124 same few characters will be incorrectly gathered.
125
126 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
127 comparing subjects."
128   :group 'gnus-thread
129   :type '(choice (const :tag "off" nil)
130                  (const fuzzy)
131                  (sexp :menu-tag "on" t)))
132
133 (defcustom gnus-simplify-subject-functions nil
134   "List of functions taking a string argument that simplify subjects.
135 The functions are applied recursively.
136
137 Useful functions to put in this list include: `gnus-simplify-subject-re',
138 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
139   :group 'gnus-thread
140   :type '(repeat function))
141
142 (defcustom gnus-simplify-ignored-prefixes nil
143   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  regexp))
147
148 (defcustom gnus-build-sparse-threads nil
149   "*If non-nil, fill in the gaps in threads.
150 If `some', only fill in the gaps that are needed to tie loose threads
151 together.  If `more', fill in all leaf nodes that Gnus can find.  If
152 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const some)
156                  (const more)
157                  (sexp :menu-tag "all" t)))
158
159 (defcustom gnus-summary-thread-gathering-function
160   'gnus-gather-threads-by-subject
161   "*Function used for gathering loose threads.
162 There are two pre-defined functions: `gnus-gather-threads-by-subject',
163 which only takes Subjects into consideration; and
164 `gnus-gather-threads-by-references', which compared the References
165 headers of the articles to find matches."
166   :group 'gnus-thread
167   :type '(radio (function-item gnus-gather-threads-by-subject)
168                 (function-item gnus-gather-threads-by-references)
169                 (function :tag "other")))
170
171 (defcustom gnus-summary-same-subject ""
172   "*String indicating that the current article has the same subject as the previous.
173 This variable will only be used if the value of
174 `gnus-summary-make-false-root' is `empty'."
175   :group 'gnus-summary-format
176   :type 'string)
177
178 (defcustom gnus-summary-goto-unread t
179   "*If t, many commands will go to the next unread article.
180 This applies to marking commands as well as other commands that
181 \"naturally\" select the next article, like, for instance, `SPC' at
182 the end of an article.
183
184 If nil, the marking commands do NOT go to the next unread article
185 (they go to the next article instead).  If `never', commands that
186 usually go to the next unread article, will go to the next article,
187 whether it is read or not."
188   :group 'gnus-summary-marks
189   :link '(custom-manual "(gnus)Setting Marks")
190   :type '(choice (const :tag "off" nil)
191                  (const never)
192                  (sexp :menu-tag "on" t)))
193
194 (defcustom gnus-summary-default-score 0
195   "*Default article score level.
196 All scores generated by the score files will be added to this score.
197 If this variable is nil, scoring will be disabled."
198   :group 'gnus-score-default
199   :type '(choice (const :tag "disable")
200                  integer))
201
202 (defcustom gnus-summary-default-high-score 0
203   "*Default threshold for a high scored article.
204 An article will be highlighted as high scored if its score is greater
205 than this score."
206   :group 'gnus-score-default
207   :type 'integer)
208
209 (defcustom gnus-summary-default-low-score 0
210   "*Default threshold for a low scored article.
211 An article will be highlighted as low scored if its score is smaller
212 than this score."
213   :group 'gnus-score-default
214   :type 'integer)
215
216 (defcustom gnus-summary-zcore-fuzz 0
217   "*Fuzziness factor for the zcore in the summary buffer.
218 Articles with scores closer than this to `gnus-summary-default-score'
219 will not be marked."
220   :group 'gnus-summary-format
221   :type 'integer)
222
223 (defcustom gnus-simplify-subject-fuzzy-regexp nil
224   "*Strings to be removed when doing fuzzy matches.
225 This can either be a regular expression or list of regular expressions
226 that will be removed from subject strings if fuzzy subject
227 simplification is selected."
228   :group 'gnus-thread
229   :type '(repeat regexp))
230
231 (defcustom gnus-show-threads t
232   "*If non-nil, display threads in summary mode."
233   :group 'gnus-thread
234   :type 'boolean)
235
236 (defcustom gnus-thread-hide-subtree nil
237   "*If non-nil, hide all threads initially.
238 If threads are hidden, you have to run the command
239 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
240 to expose hidden threads."
241   :group 'gnus-thread
242   :type 'boolean)
243
244 (defcustom gnus-thread-hide-killed t
245   "*If non-nil, hide killed threads automatically."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-ignore-subject t
250   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
251 If nil, articles that have different subjects from their parents will
252 start separate threads."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-operation-ignore-subject t
257   "*If non-nil, subjects will be ignored when doing thread commands.
258 This affects commands like `gnus-summary-kill-thread' and
259 `gnus-summary-lower-thread'.
260
261 If this variable is nil, articles in the same thread with different
262 subjects will not be included in the operation in question.  If this
263 variable is `fuzzy', only articles that have subjects that are fuzzily
264 equal will be included."
265   :group 'gnus-thread
266   :type '(choice (const :tag "off" nil)
267                  (const fuzzy)
268                  (sexp :tag "on" t)))
269
270 (defcustom gnus-thread-indent-level 4
271   "*Number that says how much each sub-thread should be indented."
272   :group 'gnus-thread
273   :type 'integer)
274
275 (defcustom gnus-auto-extend-newsgroup t
276   "*If non-nil, extend newsgroup forward and backward when requested."
277   :group 'gnus-summary-choose
278   :type 'boolean)
279
280 (defcustom gnus-auto-select-first t
281   "*If non-nil, select the article under point.
282 Which article this is is controlled by the `gnus-auto-select-subject'
283 variable.
284
285 If you want to prevent automatic selection of articles in some
286 newsgroups, set the variable to nil in `gnus-select-group-hook'."
287   :group 'gnus-group-select
288   :type '(choice (const :tag "none" nil)
289                  (sexp :menu-tag "first" t)))
290
291 (defcustom gnus-auto-select-subject 'unread
292   "*Says what subject to place under point when entering a group.
293
294 This variable can either be the symbols `first' (place point on the
295 first subject), `unread' (place point on the subject line of the first
296 unread article), `best' (place point on the subject line of the
297 higest-scored article), `unseen' (place point on the subject line of
298 the first unseen article), or a function to be called to place point on
299 some subject line.."
300   :group 'gnus-group-select
301   :type '(choice (const best)
302                  (const unread)
303                  (const first)
304                  (const unseen)))
305
306 (defcustom gnus-auto-select-next t
307   "*If non-nil, offer to go to the next group from the end of the previous.
308 If the value is t and the next newsgroup is empty, Gnus will exit
309 summary mode and go back to group mode.  If the value is neither nil
310 nor t, Gnus will select the following unread newsgroup.  In
311 particular, if the value is the symbol `quietly', the next unread
312 newsgroup will be selected without any confirmation, and if it is
313 `almost-quietly', the next group will be selected without any
314 confirmation if you are located on the last article in the group.
315 Finally, if this variable is `slightly-quietly', the `Z n' command
316 will go to the next group without confirmation."
317   :group 'gnus-summary-maneuvering
318   :type '(choice (const :tag "off" nil)
319                  (const quietly)
320                  (const almost-quietly)
321                  (const slightly-quietly)
322                  (sexp :menu-tag "on" t)))
323
324 (defcustom gnus-auto-select-same nil
325   "*If non-nil, select the next article with the same subject.
326 If there are no more articles with the same subject, go to
327 the first unread article."
328   :group 'gnus-summary-maneuvering
329   :type 'boolean)
330
331 (defcustom gnus-summary-check-current nil
332   "*If non-nil, consider the current article when moving.
333 The \"unread\" movement commands will stay on the same line if the
334 current article is unread."
335   :group 'gnus-summary-maneuvering
336   :type 'boolean)
337
338 (defcustom gnus-auto-center-summary t
339   "*If non-nil, always center the current summary buffer.
340 In particular, if `vertical' do only vertical recentering.  If non-nil
341 and non-`vertical', do both horizontal and vertical recentering."
342   :group 'gnus-summary-maneuvering
343   :type '(choice (const :tag "none" nil)
344                  (const vertical)
345                  (integer :tag "height")
346                  (sexp :menu-tag "both" t)))
347
348 (defcustom gnus-show-all-headers nil
349   "*If non-nil, don't hide any headers."
350   :group 'gnus-article-hiding
351   :group 'gnus-article-headers
352   :type 'boolean)
353
354 (defcustom gnus-summary-ignore-duplicates nil
355   "*If non-nil, ignore articles with identical Message-ID headers."
356   :group 'gnus-summary
357   :type 'boolean)
358
359 (defcustom gnus-single-article-buffer t
360   "*If non-nil, display all articles in the same buffer.
361 If nil, each group will get its own article buffer."
362   :group 'gnus-article-various
363   :type 'boolean)
364
365 (defcustom gnus-break-pages t
366   "*If non-nil, do page breaking on articles.
367 The page delimiter is specified by the `gnus-page-delimiter'
368 variable."
369   :group 'gnus-article-various
370   :type 'boolean)
371
372 (defcustom gnus-move-split-methods nil
373   "*Variable used to suggest where articles are to be moved to.
374 It uses the same syntax as the `gnus-split-methods' variable.
375 However, whereas `gnus-split-methods' specifies file names as targets,
376 this variable specifies group names."
377   :group 'gnus-summary-mail
378   :type '(repeat (choice (list :value (fun) function)
379                          (cons :value ("" "") regexp (repeat string))
380                          (sexp :value nil))))
381
382 (defcustom gnus-unread-mark ?           ;Whitespace
383   "*Mark used for unread articles."
384   :group 'gnus-summary-marks
385   :type 'character)
386
387 (defcustom gnus-ticked-mark ?!
388   "*Mark used for ticked articles."
389   :group 'gnus-summary-marks
390   :type 'character)
391
392 (defcustom gnus-dormant-mark ??
393   "*Mark used for dormant articles."
394   :group 'gnus-summary-marks
395   :type 'character)
396
397 (defcustom gnus-del-mark ?r
398   "*Mark used for del'd articles."
399   :group 'gnus-summary-marks
400   :type 'character)
401
402 (defcustom gnus-read-mark ?R
403   "*Mark used for read articles."
404   :group 'gnus-summary-marks
405   :type 'character)
406
407 (defcustom gnus-expirable-mark ?E
408   "*Mark used for expirable articles."
409   :group 'gnus-summary-marks
410   :type 'character)
411
412 (defcustom gnus-killed-mark ?K
413   "*Mark used for killed articles."
414   :group 'gnus-summary-marks
415   :type 'character)
416
417 (defcustom gnus-souped-mark ?F
418   "*Mark used for souped articles."
419   :group 'gnus-summary-marks
420   :type 'character)
421
422 (defcustom gnus-kill-file-mark ?X
423   "*Mark used for articles killed by kill files."
424   :group 'gnus-summary-marks
425   :type 'character)
426
427 (defcustom gnus-low-score-mark ?Y
428   "*Mark used for articles with a low score."
429   :group 'gnus-summary-marks
430   :type 'character)
431
432 (defcustom gnus-catchup-mark ?C
433   "*Mark used for articles that are caught up."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-replied-mark ?A
438   "*Mark used for articles that have been replied to."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-forwarded-mark ?F
443   "*Mark used for articles that have been forwarded."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-recent-mark ?N
448   "*Mark used for articles that are recent."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-cached-mark ?*
453   "*Mark used for articles that are in the cache."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-saved-mark ?S
458   "*Mark used for articles that have been saved."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-unseen-mark ?.
463   "*Mark used for articles that haven't been seen."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-no-mark ?               ;Whitespace
468   "*Mark used for articles that have no other secondary mark."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-ancient-mark ?O
473   "*Mark used for ancient articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-sparse-mark ?Q
478   "*Mark used for sparsely reffed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-canceled-mark ?G
483   "*Mark used for canceled articles."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-duplicate-mark ?M
488   "*Mark used for duplicate articles."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-undownloaded-mark ?@
493   "*Mark used for articles that weren't downloaded."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-downloadable-mark ?%
498   "*Mark used for articles that are to be downloaded."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-unsendable-mark ?=
503   "*Mark used for articles that won't be sent."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-score-over-mark ?+
508   "*Score mark used for articles with high scores."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-score-below-mark ?-
513   "*Score mark used for articles with low scores."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-empty-thread-mark ?     ;Whitespace
518   "*There is no thread under the article."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-not-empty-thread-mark ?=
523   "*There is a thread under the article."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-view-pseudo-asynchronously nil
528   "*If non-nil, Gnus will view pseudo-articles asynchronously."
529   :group 'gnus-extract-view
530   :type 'boolean)
531
532 (defcustom gnus-auto-expirable-marks
533   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
534         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
535         gnus-souped-mark gnus-duplicate-mark)
536   "*The list of marks converted into expiration if a group is auto-expirable."
537   :version "21.1"
538   :group 'gnus-summary
539   :type '(repeat character))
540
541 (defcustom gnus-inhibit-user-auto-expire t
542   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
543   :version "21.1"
544   :group 'gnus-summary
545   :type 'boolean)
546
547 (defcustom gnus-view-pseudos nil
548   "*If `automatic', pseudo-articles will be viewed automatically.
549 If `not-confirm', pseudos will be viewed automatically, and the user
550 will not be asked to confirm the command."
551   :group 'gnus-extract-view
552   :type '(choice (const :tag "off" nil)
553                  (const automatic)
554                  (const not-confirm)))
555
556 (defcustom gnus-view-pseudos-separately t
557   "*If non-nil, one pseudo-article will be created for each file to be viewed.
558 If nil, all files that use the same viewing command will be given as a
559 list of parameters to that command."
560   :group 'gnus-extract-view
561   :type 'boolean)
562
563 (defcustom gnus-insert-pseudo-articles t
564   "*If non-nil, insert pseudo-articles when decoding articles."
565   :group 'gnus-extract-view
566   :type 'boolean)
567
568 (defcustom gnus-summary-dummy-line-format
569   "  %(:                          :%) %S\n"
570   "*The format specification for the dummy roots in the summary buffer.
571 It works along the same lines as a normal formatting string,
572 with some simple extensions.
573
574 %S  The subject"
575   :group 'gnus-threading
576   :type 'string)
577
578 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
579   "*The format specification for the summary mode line.
580 It works along the same lines as a normal formatting string,
581 with some simple extensions:
582
583 %G  Group name
584 %p  Unprefixed group name
585 %A  Current article number
586 %z  Current article score
587 %V  Gnus version
588 %U  Number of unread articles in the group
589 %e  Number of unselected articles in the group
590 %Z  A string with unread/unselected article counts
591 %g  Shortish group name
592 %S  Subject of the current article
593 %u  User-defined spec
594 %s  Current score file name
595 %d  Number of dormant articles
596 %r  Number of articles that have been marked as read in this session
597 %E  Number of articles expunged by the score files"
598   :group 'gnus-summary-format
599   :type 'string)
600
601 (defcustom gnus-list-identifiers nil
602   "Regexp that matches list identifiers to be removed from subject.
603 This can also be a list of regexps."
604   :version "21.1"
605   :group 'gnus-summary-format
606   :group 'gnus-article-hiding
607   :type '(choice (const :tag "none" nil)
608                  (regexp :value ".*")
609                  (repeat :value (".*") regexp)))
610
611 (defcustom gnus-summary-mark-below 0
612   "*Mark all articles with a score below this variable as read.
613 This variable is local to each summary buffer and usually set by the
614 score file."
615   :group 'gnus-score-default
616   :type 'integer)
617
618 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
619   "*List of functions used for sorting articles in the summary buffer.
620
621 Each function takes two articles and returns non-nil if the first
622 article should be sorted before the other.  If you use more than one
623 function, the primary sort function should be the last.  You should
624 probably always include `gnus-article-sort-by-number' in the list of
625 sorting functions -- preferably first.  Also note that sorting by date
626 is often much slower than sorting by number, and the sorting order is
627 very similar.  (Sorting by date means sorting by the time the message
628 was sent, sorting by number means sorting by arrival time.)
629
630 Ready-made functions include `gnus-article-sort-by-number',
631 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
632 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
633
634 When threading is turned on, the variable `gnus-thread-sort-functions'
635 controls how articles are sorted."
636   :group 'gnus-summary-sort
637   :type '(repeat (choice (function-item gnus-article-sort-by-number)
638                          (function-item gnus-article-sort-by-author)
639                          (function-item gnus-article-sort-by-subject)
640                          (function-item gnus-article-sort-by-date)
641                          (function-item gnus-article-sort-by-score)
642                          (function :tag "other"))))
643
644 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
645   "*List of functions used for sorting threads in the summary buffer.
646 By default, threads are sorted by article number.
647
648 Each function takes two threads and returns non-nil if the first
649 thread should be sorted before the other.  If you use more than one
650 function, the primary sort function should be the last.  You should
651 probably always include `gnus-thread-sort-by-number' in the list of
652 sorting functions -- preferably first.  Also note that sorting by date
653 is often much slower than sorting by number, and the sorting order is
654 very similar.  (Sorting by date means sorting by the time the message
655 was sent, sorting by number means sorting by arrival time.)
656
657 Ready-made functions include `gnus-thread-sort-by-number',
658 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
659 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
660 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
661
662 When threading is turned off, the variable
663 `gnus-article-sort-functions' controls how articles are sorted."
664   :group 'gnus-summary-sort
665   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
666                          (function-item gnus-thread-sort-by-author)
667                          (function-item gnus-thread-sort-by-subject)
668                          (function-item gnus-thread-sort-by-date)
669                          (function-item gnus-thread-sort-by-score)
670                          (function-item gnus-thread-sort-by-total-score)
671                          (function :tag "other"))))
672
673 (defcustom gnus-thread-score-function '+
674   "*Function used for calculating the total score of a thread.
675
676 The function is called with the scores of the article and each
677 subthread and should then return the score of the thread.
678
679 Some functions you can use are `+', `max', or `min'."
680   :group 'gnus-summary-sort
681   :type 'function)
682
683 (defcustom gnus-summary-expunge-below nil
684   "All articles that have a score less than this variable will be expunged.
685 This variable is local to the summary buffers."
686   :group 'gnus-score-default
687   :type '(choice (const :tag "off" nil)
688                  integer))
689
690 (defcustom gnus-thread-expunge-below nil
691   "All threads that have a total score less than this variable will be expunged.
692 See `gnus-thread-score-function' for en explanation of what a
693 \"thread score\" is.
694
695 This variable is local to the summary buffers."
696   :group 'gnus-threading
697   :group 'gnus-score-default
698   :type '(choice (const :tag "off" nil)
699                  integer))
700
701 (defcustom gnus-summary-mode-hook nil
702   "*A hook for Gnus summary mode.
703 This hook is run before any variables are set in the summary buffer."
704   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
705   :group 'gnus-summary-various
706   :type 'hook)
707
708 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
709 (when (featurep 'xemacs)
710   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
711   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
712   (add-hook 'gnus-summary-mode-hook
713             'gnus-xmas-switch-horizontal-scrollbar-off))
714
715 (defcustom gnus-summary-menu-hook nil
716   "*Hook run after the creation of the summary mode menu."
717   :group 'gnus-summary-visual
718   :type 'hook)
719
720 (defcustom gnus-summary-exit-hook nil
721   "*A hook called on exit from the summary buffer.
722 It will be called with point in the group buffer."
723   :group 'gnus-summary-exit
724   :type 'hook)
725
726 (defcustom gnus-summary-prepare-hook nil
727   "*A hook called after the summary buffer has been generated.
728 If you want to modify the summary buffer, you can use this hook."
729   :group 'gnus-summary-various
730   :type 'hook)
731
732 (defcustom gnus-summary-prepared-hook nil
733   "*A hook called as the last thing after the summary buffer has been generated."
734   :group 'gnus-summary-various
735   :type 'hook)
736
737 (defcustom gnus-summary-generate-hook nil
738   "*A hook run just before generating the summary buffer.
739 This hook is commonly used to customize threading variables and the
740 like."
741   :group 'gnus-summary-various
742   :type 'hook)
743
744 (defcustom gnus-select-group-hook nil
745   "*A hook called when a newsgroup is selected.
746
747 If you'd like to simplify subjects like the
748 `gnus-summary-next-same-subject' command does, you can use the
749 following hook:
750
751  (setq gnus-select-group-hook
752       (list
753         (lambda ()
754           (mapcar (lambda (header)
755                      (mail-header-set-subject
756                       header
757                       (gnus-simplify-subject
758                        (mail-header-subject header) 're-only)))
759                   gnus-newsgroup-headers))))"
760   :group 'gnus-group-select
761   :type 'hook)
762
763 (defcustom gnus-select-article-hook nil
764   "*A hook called when an article is selected."
765   :group 'gnus-summary-choose
766   :type 'hook)
767
768 (defcustom gnus-visual-mark-article-hook
769   (list 'gnus-highlight-selected-summary)
770   "*Hook run after selecting an article in the summary buffer.
771 It is meant to be used for highlighting the article in some way.  It
772 is not run if `gnus-visual' is nil."
773   :group 'gnus-summary-visual
774   :type 'hook)
775
776 (defcustom gnus-parse-headers-hook nil
777   "*A hook called before parsing the headers."
778   :group 'gnus-various
779   :type 'hook)
780
781 (defcustom gnus-exit-group-hook nil
782   "*A hook called when exiting summary mode.
783 This hook is not called from the non-updating exit commands like `Q'."
784   :group 'gnus-various
785   :type 'hook)
786
787 (defcustom gnus-summary-update-hook
788   (list 'gnus-summary-highlight-line)
789   "*A hook called when a summary line is changed.
790 The hook will not be called if `gnus-visual' is nil.
791
792 The default function `gnus-summary-highlight-line' will
793 highlight the line according to the `gnus-summary-highlight'
794 variable."
795   :group 'gnus-summary-visual
796   :type 'hook)
797
798 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
799   "*A hook called when an article is selected for the first time.
800 The hook is intended to mark an article as read (or unread)
801 automatically when it is selected."
802   :group 'gnus-summary-choose
803   :type 'hook)
804
805 (defcustom gnus-group-no-more-groups-hook nil
806   "*A hook run when returning to group mode having no more (unread) groups."
807   :group 'gnus-group-select
808   :type 'hook)
809
810 (defcustom gnus-ps-print-hook nil
811   "*A hook run before ps-printing something from Gnus."
812   :group 'gnus-summary
813   :type 'hook)
814
815 (defcustom gnus-summary-display-arrow
816   (and (fboundp 'display-graphic-p)
817        (display-graphic-p))
818   "*If non-nil, display an arrow highlighting the current article."
819   :version "21.1"
820   :group 'gnus-summary
821   :type 'boolean)
822
823 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
824   "Face used for highlighting the current article in the summary buffer."
825   :group 'gnus-summary-visual
826   :type 'face)
827
828 (defcustom gnus-summary-highlight
829   '(((= mark gnus-canceled-mark)
830      . gnus-summary-cancelled-face)
831     ((and (> score default-high)
832           (or (= mark gnus-dormant-mark)
833               (= mark gnus-ticked-mark)))
834      . gnus-summary-high-ticked-face)
835     ((and (< score default-low)
836           (or (= mark gnus-dormant-mark)
837               (= mark gnus-ticked-mark)))
838      . gnus-summary-low-ticked-face)
839     ((or (= mark gnus-dormant-mark)
840          (= mark gnus-ticked-mark))
841      . gnus-summary-normal-ticked-face)
842     ((and (> score default-high) (= mark gnus-ancient-mark))
843      . gnus-summary-high-ancient-face)
844     ((and (< score default-low) (= mark gnus-ancient-mark))
845      . gnus-summary-low-ancient-face)
846     ((= mark gnus-ancient-mark)
847      . gnus-summary-normal-ancient-face)
848     ((and (> score default-high) (= mark gnus-unread-mark))
849      . gnus-summary-high-unread-face)
850     ((and (< score default-low) (= mark gnus-unread-mark))
851      . gnus-summary-low-unread-face)
852     ((= mark gnus-unread-mark)
853      . gnus-summary-normal-unread-face)
854     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
855                                                   gnus-undownloaded-mark)))
856      . gnus-summary-high-unread-face)
857     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
858                                                  gnus-undownloaded-mark)))
859      . gnus-summary-low-unread-face)
860     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
861           (memq article gnus-newsgroup-unreads))
862      . gnus-summary-normal-unread-face)
863     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
864      . gnus-summary-normal-read-face)
865     ((> score default-high)
866      . gnus-summary-high-read-face)
867     ((< score default-low)
868      . gnus-summary-low-read-face)
869     (t
870      . gnus-summary-normal-read-face))
871   "*Controls the highlighting of summary buffer lines.
872
873 A list of (FORM . FACE) pairs.  When deciding how a a particular
874 summary line should be displayed, each form is evaluated.  The content
875 of the face field after the first true form is used.  You can change
876 how those summary lines are displayed, by editing the face field.
877
878 You can use the following variables in the FORM field.
879
880 score:        The article's score
881 default:      The default article score.
882 default-high: The default score for high scored articles.
883 default-low:  The default score for low scored articles.
884 below:        The score below which articles are automatically marked as read.
885 mark:         The articles mark."
886   :group 'gnus-summary-visual
887   :type '(repeat (cons (sexp :tag "Form" nil)
888                        face)))
889
890 (defcustom gnus-alter-header-function nil
891   "Function called to allow alteration of article header structures.
892 The function is called with one parameter, the article header vector,
893 which it may alter in any way.")
894
895 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
896   "Variable that says which function should be used to decode a string with encoded words.")
897
898 (defcustom gnus-extra-headers nil
899   "*Extra headers to parse."
900   :version "21.1"
901   :group 'gnus-summary
902   :type '(repeat symbol))
903
904 (defcustom gnus-ignored-from-addresses
905   (and user-mail-address (regexp-quote user-mail-address))
906   "*Regexp of From headers that may be suppressed in favor of To headers."
907   :version "21.1"
908   :group 'gnus-summary
909   :type 'regexp)
910
911 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
912   "List of charsets that should be ignored.
913 When these charsets are used in the \"charset\" parameter, the
914 default charset will be used instead."
915   :version "21.1"
916   :type '(repeat symbol)
917   :group 'gnus-charset)
918
919 (gnus-define-group-parameter
920  ignored-charsets
921  :type list
922  :function-document
923  "Return the ignored charsets of GROUP."
924  :variable gnus-group-ignored-charsets-alist
925  :variable-default
926  '(("alt\\.chinese\\.text" iso-8859-1))
927  :variable-document
928  "Alist of regexps (to match group names) and charsets that should be ignored.
929 When these charsets are used in the \"charset\" parameter, the
930 default charset will be used instead."
931  :variable-group gnus-charset
932  :variable-type '(repeat (cons (regexp :tag "Group")
933                                (repeat symbol)))
934  :parameter-type '(choice :tag "Ignored charsets"
935                           :value nil
936                           (repeat (symbol)))
937  :parameter-document       "\
938 List of charsets that should be ignored.
939
940 When these charsets are used in the \"charset\" parameter, the
941 default charset will be used instead.")
942
943 (defcustom gnus-group-highlight-words-alist nil
944   "Alist of group regexps and highlight regexps.
945 This variable uses the same syntax as `gnus-emphasis-alist'."
946   :version "21.1"
947   :type '(repeat (cons (regexp :tag "Group")
948                        (repeat (list (regexp :tag "Highlight regexp")
949                                      (number :tag "Group for entire word" 0)
950                                      (number :tag "Group for displayed part" 0)
951                                      (symbol :tag "Face"
952                                              gnus-emphasis-highlight-words)))))
953   :group 'gnus-summary-visual)
954
955 (defcustom gnus-summary-show-article-charset-alist
956   nil
957   "Alist of number and charset.
958 The article will be shown with the charset corresponding to the
959 numbered argument.
960 For example: ((1 . cn-gb-2312) (2 . big5))."
961   :version "21.1"
962   :type '(repeat (cons (number :tag "Argument" 1)
963                        (symbol :tag "Charset")))
964   :group 'gnus-charset)
965
966 (defcustom gnus-preserve-marks t
967   "Whether marks are preserved when moving, copying and respooling messages."
968   :version "21.1"
969   :type 'boolean
970   :group 'gnus-summary-marks)
971
972 (defcustom gnus-alter-articles-to-read-function nil
973   "Function to be called to alter the list of articles to be selected."
974   :type '(choice (const nil) function)
975   :group 'gnus-summary)
976
977 (defcustom gnus-orphan-score nil
978   "*All orphans get this score added.  Set in the score file."
979   :group 'gnus-score-default
980   :type '(choice (const nil)
981                  integer))
982
983 (defcustom gnus-summary-save-parts-default-mime "image/.*"
984   "*A regexp to match MIME parts when saving multiple parts of a message
985 with gnus-summary-save-parts (X m). This regexp will be used by default
986 when prompting the user for which type of files to save."
987   :group 'gnus-summary
988   :type 'regexp)
989
990
991 (defcustom gnus-summary-save-parts-default-mime "image/.*"
992   "*A regexp to match MIME parts when saving multiple parts of a message
993 with gnus-summary-save-parts (X m). This regexp will be used by default
994 when prompting the user for which type of files to save."
995   :group 'gnus-summary
996   :type 'regexp)
997
998 (defcustom gnus-read-all-available-headers nil
999   "Whether Gnus should parse all headers made available to it.
1000 This is mostly relevant for slow backends where the user may
1001 wish to widen the summary buffer to include all headers
1002 that were fetched.  Say, for nnultimate groups."
1003   :group 'gnus-summary
1004   :type '(choice boolean regexp))
1005
1006 (defcustom gnus-summary-muttprint-program "muttprint"
1007   "Command (and optional arguments) used to run Muttprint."
1008   :group 'gnus-summary
1009   :type 'string)
1010
1011 ;;; Internal variables
1012
1013 (defvar gnus-summary-display-cache nil)
1014 (defvar gnus-article-mime-handles nil)
1015 (defvar gnus-article-decoded-p nil)
1016 (defvar gnus-article-charset nil)
1017 (defvar gnus-article-ignored-charsets nil)
1018 (defvar gnus-scores-exclude-files nil)
1019 (defvar gnus-page-broken nil)
1020 (defvar gnus-inhibit-mime-unbuttonizing nil)
1021
1022 (defvar gnus-original-article nil)
1023 (defvar gnus-article-internal-prepare-hook nil)
1024 (defvar gnus-newsgroup-process-stack nil)
1025
1026 (defvar gnus-thread-indent-array nil)
1027 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1028 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1029   "Function called to sort the articles within a thread after it has been gathered together.")
1030
1031 (defvar gnus-summary-save-parts-type-history nil)
1032 (defvar gnus-summary-save-parts-last-directory nil)
1033
1034 (defvar gnus-summary-save-parts-type-history nil)
1035 (defvar gnus-summary-save-parts-last-directory nil)
1036
1037 ;; Avoid highlighting in kill files.
1038 (defvar gnus-summary-inhibit-highlight nil)
1039 (defvar gnus-newsgroup-selected-overlay nil)
1040 (defvar gnus-inhibit-limiting nil)
1041 (defvar gnus-newsgroup-adaptive-score-file nil)
1042 (defvar gnus-current-score-file nil)
1043 (defvar gnus-current-move-group nil)
1044 (defvar gnus-current-copy-group nil)
1045 (defvar gnus-current-crosspost-group nil)
1046 (defvar gnus-newsgroup-display nil)
1047
1048 (defvar gnus-newsgroup-dependencies nil)
1049 (defvar gnus-newsgroup-adaptive nil)
1050 (defvar gnus-summary-display-article-function nil)
1051 (defvar gnus-summary-highlight-line-function nil
1052   "Function called after highlighting a summary line.")
1053
1054 (defvar gnus-summary-line-format-alist
1055   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1056     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1057     (?s gnus-tmp-subject-or-nil ?s)
1058     (?n gnus-tmp-name ?s)
1059     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1060         ?s)
1061     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1062             gnus-tmp-from) ?s)
1063     (?F gnus-tmp-from ?s)
1064     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1065     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1066     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1067     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1068     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1069     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1070     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1071     (?L gnus-tmp-lines ?s)
1072     (?I gnus-tmp-indentation ?s)
1073     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1074     (?R gnus-tmp-replied ?c)
1075     (?\[ gnus-tmp-opening-bracket ?c)
1076     (?\] gnus-tmp-closing-bracket ?c)
1077     (?\> (make-string gnus-tmp-level ? ) ?s)
1078     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1079     (?i gnus-tmp-score ?d)
1080     (?z gnus-tmp-score-char ?c)
1081     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1082     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1083     (?U gnus-tmp-unread ?c)
1084     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1085         ?s)
1086     (?t (gnus-summary-number-of-articles-in-thread
1087          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1088         ?d)
1089     (?e (gnus-summary-number-of-articles-in-thread
1090          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1091         ?c)
1092     (?u gnus-tmp-user-defined ?s)
1093     (?P (gnus-pick-line-number) ?d)
1094     (?B gnus-tmp-thread-tree-header-string ?s)
1095     (user-date (gnus-user-date
1096                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1097   "An alist of format specifications that can appear in summary lines.
1098 These are paired with what variables they correspond with, along with
1099 the type of the variable (string, integer, character, etc).")
1100
1101 (defvar gnus-summary-dummy-line-format-alist
1102   `((?S gnus-tmp-subject ?s)
1103     (?N gnus-tmp-number ?d)
1104     (?u gnus-tmp-user-defined ?s)))
1105
1106 (defvar gnus-summary-mode-line-format-alist
1107   `((?G gnus-tmp-group-name ?s)
1108     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1109     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1110     (?A gnus-tmp-article-number ?d)
1111     (?Z gnus-tmp-unread-and-unselected ?s)
1112     (?V gnus-version ?s)
1113     (?U gnus-tmp-unread-and-unticked ?d)
1114     (?S gnus-tmp-subject ?s)
1115     (?e gnus-tmp-unselected ?d)
1116     (?u gnus-tmp-user-defined ?s)
1117     (?d (length gnus-newsgroup-dormant) ?d)
1118     (?t (length gnus-newsgroup-marked) ?d)
1119     (?r (length gnus-newsgroup-reads) ?d)
1120     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1121     (?E gnus-newsgroup-expunged-tally ?d)
1122     (?s (gnus-current-score-file-nondirectory) ?s)))
1123
1124 (defvar gnus-last-search-regexp nil
1125   "Default regexp for article search command.")
1126
1127 (defvar gnus-last-shell-command nil
1128   "Default shell command on article.")
1129
1130 (defvar gnus-newsgroup-begin nil)
1131 (defvar gnus-newsgroup-end nil)
1132 (defvar gnus-newsgroup-last-rmail nil)
1133 (defvar gnus-newsgroup-last-mail nil)
1134 (defvar gnus-newsgroup-last-folder nil)
1135 (defvar gnus-newsgroup-last-file nil)
1136 (defvar gnus-newsgroup-auto-expire nil)
1137 (defvar gnus-newsgroup-active nil)
1138
1139 (defvar gnus-newsgroup-data nil)
1140 (defvar gnus-newsgroup-data-reverse nil)
1141 (defvar gnus-newsgroup-limit nil)
1142 (defvar gnus-newsgroup-limits nil)
1143
1144 (defvar gnus-newsgroup-unreads nil
1145   "List of unread articles in the current newsgroup.")
1146
1147 (defvar gnus-newsgroup-unselected nil
1148   "List of unselected unread articles in the current newsgroup.")
1149
1150 (defvar gnus-newsgroup-reads nil
1151   "Alist of read articles and article marks in the current newsgroup.")
1152
1153 (defvar gnus-newsgroup-expunged-tally nil)
1154
1155 (defvar gnus-newsgroup-marked nil
1156   "List of ticked articles in the current newsgroup (a subset of unread art).")
1157
1158 (defvar gnus-newsgroup-killed nil
1159   "List of ranges of articles that have been through the scoring process.")
1160
1161 (defvar gnus-newsgroup-cached nil
1162   "List of articles that come from the article cache.")
1163
1164 (defvar gnus-newsgroup-saved nil
1165   "List of articles that have been saved.")
1166
1167 (defvar gnus-newsgroup-kill-headers nil)
1168
1169 (defvar gnus-newsgroup-replied nil
1170   "List of articles that have been replied to in the current newsgroup.")
1171
1172 (defvar gnus-newsgroup-forwarded nil
1173   "List of articles that have been forwarded in the current newsgroup.")
1174
1175 (defvar gnus-newsgroup-recent nil
1176   "List of articles that have are recent in the current newsgroup.")
1177
1178 (defvar gnus-newsgroup-expirable nil
1179   "List of articles in the current newsgroup that can be expired.")
1180
1181 (defvar gnus-newsgroup-processable nil
1182   "List of articles in the current newsgroup that can be processed.")
1183
1184 (defvar gnus-newsgroup-downloadable nil
1185   "List of articles in the current newsgroup that can be processed.")
1186
1187 (defvar gnus-newsgroup-undownloaded nil
1188   "List of articles in the current newsgroup that haven't been downloaded..")
1189
1190 (defvar gnus-newsgroup-unsendable nil
1191   "List of articles in the current newsgroup that won't be sent.")
1192
1193 (defvar gnus-newsgroup-bookmarks nil
1194   "List of articles in the current newsgroup that have bookmarks.")
1195
1196 (defvar gnus-newsgroup-dormant nil
1197   "List of dormant articles in the current newsgroup.")
1198
1199 (defvar gnus-newsgroup-unseen nil
1200   "List of unseen articles in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-seen nil
1203   "Range of seen articles in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-articles nil
1206   "List of articles in the current newsgroup.")
1207
1208 (defvar gnus-newsgroup-scored nil
1209   "List of scored articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-headers nil
1212   "List of article headers in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-threads nil)
1215
1216 (defvar gnus-newsgroup-prepared nil
1217   "Whether the current group has been prepared properly.")
1218
1219 (defvar gnus-newsgroup-ancient nil
1220   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-sparse nil)
1223
1224 (defvar gnus-current-article nil)
1225 (defvar gnus-article-current nil)
1226 (defvar gnus-current-headers nil)
1227 (defvar gnus-have-all-headers nil)
1228 (defvar gnus-last-article nil)
1229 (defvar gnus-newsgroup-history nil)
1230 (defvar gnus-newsgroup-charset nil)
1231 (defvar gnus-newsgroup-ephemeral-charset nil)
1232 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1233
1234 (defvar gnus-article-before-search nil)
1235
1236 (defconst gnus-summary-local-variables
1237   '(gnus-newsgroup-name
1238     gnus-newsgroup-begin gnus-newsgroup-end
1239     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1240     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1241     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1242     gnus-newsgroup-unselected gnus-newsgroup-marked
1243     gnus-newsgroup-reads gnus-newsgroup-saved
1244     gnus-newsgroup-replied gnus-newsgroup-forwarded
1245     gnus-newsgroup-recent
1246     gnus-newsgroup-expirable
1247     gnus-newsgroup-processable gnus-newsgroup-killed
1248     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1249     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1250     gnus-newsgroup-seen gnus-newsgroup-articles
1251     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1252     gnus-newsgroup-headers gnus-newsgroup-threads
1253     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1254     gnus-current-article gnus-current-headers gnus-have-all-headers
1255     gnus-last-article gnus-article-internal-prepare-hook
1256     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1257     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1258     gnus-thread-expunge-below
1259     gnus-score-alist gnus-current-score-file
1260     (gnus-summary-expunge-below . global)
1261     (gnus-summary-mark-below . global)
1262     (gnus-orphan-score . global)
1263     gnus-newsgroup-active gnus-scores-exclude-files
1264     gnus-newsgroup-history gnus-newsgroup-ancient
1265     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1266     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1267     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1268     (gnus-newsgroup-expunged-tally . 0)
1269     gnus-cache-removable-articles gnus-newsgroup-cached
1270     gnus-newsgroup-data gnus-newsgroup-data-reverse
1271     gnus-newsgroup-limit gnus-newsgroup-limits
1272     gnus-newsgroup-charset gnus-newsgroup-display)
1273   "Variables that are buffer-local to the summary buffers.")
1274
1275 (defvar gnus-newsgroup-variables nil
1276   "A list of variables that have separate values in different newsgroups.
1277 A list of newsgroup (summary buffer) local variables, or cons of
1278 variables and their default values (when the default values are not
1279 nil), that should be made global while the summary buffer is active.
1280 These variables can be used to set variables in the group parameters
1281 while still allowing them to affect operations done in other
1282 buffers. For example:
1283
1284 \(setq gnus-newsgroup-variables
1285      '(message-use-followup-to
1286        (gnus-visible-headers .
1287          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1288 ")
1289
1290 ;; Byte-compiler warning.
1291 (eval-when-compile (defvar gnus-article-mode-map))
1292
1293 ;; MIME stuff.
1294
1295 (defvar gnus-decode-encoded-word-methods
1296   '(mail-decode-encoded-word-string)
1297   "List of methods used to decode encoded words.
1298
1299 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1300 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1301 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1302 whose names match REGEXP.
1303
1304 For example:
1305 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1306  mail-decode-encoded-word-string
1307  (\"chinese\" . rfc1843-decode-string))")
1308
1309 (defvar gnus-decode-encoded-word-methods-cache nil)
1310
1311 (defun gnus-multi-decode-encoded-word-string (string)
1312   "Apply the functions from `gnus-encoded-word-methods' that match."
1313   (unless (and gnus-decode-encoded-word-methods-cache
1314                (eq gnus-newsgroup-name
1315                    (car gnus-decode-encoded-word-methods-cache)))
1316     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1317     (mapcar (lambda (x)
1318               (if (symbolp x)
1319                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1320                 (if (and gnus-newsgroup-name
1321                          (string-match (car x) gnus-newsgroup-name))
1322                     (nconc gnus-decode-encoded-word-methods-cache
1323                            (list (cdr x))))))
1324             gnus-decode-encoded-word-methods))
1325   (let ((xlist gnus-decode-encoded-word-methods-cache))
1326     (pop xlist)
1327     (while xlist
1328       (setq string (funcall (pop xlist) string))))
1329   string)
1330
1331 ;; Subject simplification.
1332
1333 (defun gnus-simplify-whitespace (str)
1334   "Remove excessive whitespace from STR."
1335   (let ((mystr str))
1336     ;; Multiple spaces.
1337     (while (string-match "[ \t][ \t]+" mystr)
1338       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1339                           " "
1340                           (substring mystr (match-end 0)))))
1341     ;; Leading spaces.
1342     (when (string-match "^[ \t]+" mystr)
1343       (setq mystr (substring mystr (match-end 0))))
1344     ;; Trailing spaces.
1345     (when (string-match "[ \t]+$" mystr)
1346       (setq mystr (substring mystr 0 (match-beginning 0))))
1347     mystr))
1348
1349 (defsubst gnus-simplify-subject-re (subject)
1350   "Remove \"Re:\" from subject lines."
1351   (if (string-match message-subject-re-regexp subject)
1352       (substring subject (match-end 0))
1353     subject))
1354
1355 (defun gnus-simplify-subject (subject &optional re-only)
1356   "Remove `Re:' and words in parentheses.
1357 If RE-ONLY is non-nil, strip leading `Re:'s only."
1358   (let ((case-fold-search t))           ;Ignore case.
1359     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1360     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1361       (setq subject (substring subject (match-end 0))))
1362     ;; Remove uninteresting prefixes.
1363     (when (and (not re-only)
1364                gnus-simplify-ignored-prefixes
1365                (string-match gnus-simplify-ignored-prefixes subject))
1366       (setq subject (substring subject (match-end 0))))
1367     ;; Remove words in parentheses from end.
1368     (unless re-only
1369       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1370         (setq subject (substring subject 0 (match-beginning 0)))))
1371     ;; Return subject string.
1372     subject))
1373
1374 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1375 ;; all whitespace.
1376 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1377   (goto-char (point-min))
1378   (while (re-search-forward regexp nil t)
1379     (replace-match (or newtext ""))))
1380
1381 (defun gnus-simplify-buffer-fuzzy ()
1382   "Simplify string in the buffer fuzzily.
1383 The string in the accessible portion of the current buffer is simplified.
1384 It is assumed to be a single-line subject.
1385 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1386 matter is removed.  Additional things can be deleted by setting
1387 `gnus-simplify-subject-fuzzy-regexp'."
1388   (let ((case-fold-search t)
1389         (modified-tick))
1390     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1391
1392     (while (not (eq modified-tick (buffer-modified-tick)))
1393       (setq modified-tick (buffer-modified-tick))
1394       (cond
1395        ((listp gnus-simplify-subject-fuzzy-regexp)
1396         (mapcar 'gnus-simplify-buffer-fuzzy-step
1397                 gnus-simplify-subject-fuzzy-regexp))
1398        (gnus-simplify-subject-fuzzy-regexp
1399         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1400       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1401       (gnus-simplify-buffer-fuzzy-step
1402        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1403       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1404
1405     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1406     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1407     (gnus-simplify-buffer-fuzzy-step " $")
1408     (gnus-simplify-buffer-fuzzy-step "^ +")))
1409
1410 (defun gnus-simplify-subject-fuzzy (subject)
1411   "Simplify a subject string fuzzily.
1412 See `gnus-simplify-buffer-fuzzy' for details."
1413   (save-excursion
1414     (gnus-set-work-buffer)
1415     (let ((case-fold-search t))
1416       ;; Remove uninteresting prefixes.
1417       (when (and gnus-simplify-ignored-prefixes
1418                  (string-match gnus-simplify-ignored-prefixes subject))
1419         (setq subject (substring subject (match-end 0))))
1420       (insert subject)
1421       (inline (gnus-simplify-buffer-fuzzy))
1422       (buffer-string))))
1423
1424 (defsubst gnus-simplify-subject-fully (subject)
1425   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1426   (cond
1427    (gnus-simplify-subject-functions
1428     (gnus-map-function gnus-simplify-subject-functions subject))
1429    ((null gnus-summary-gather-subject-limit)
1430     (gnus-simplify-subject-re subject))
1431    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1432     (gnus-simplify-subject-fuzzy subject))
1433    ((numberp gnus-summary-gather-subject-limit)
1434     (gnus-limit-string (gnus-simplify-subject-re subject)
1435                        gnus-summary-gather-subject-limit))
1436    (t
1437     subject)))
1438
1439 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1440   "Check whether two subjects are equal.
1441 If optional argument simple-first is t, first argument is already
1442 simplified."
1443   (cond
1444    ((null simple-first)
1445     (equal (gnus-simplify-subject-fully s1)
1446            (gnus-simplify-subject-fully s2)))
1447    (t
1448     (equal s1
1449            (gnus-simplify-subject-fully s2)))))
1450
1451 (defun gnus-summary-bubble-group ()
1452   "Increase the score of the current group.
1453 This is a handy function to add to `gnus-summary-exit-hook' to
1454 increase the score of each group you read."
1455   (gnus-group-add-score gnus-newsgroup-name))
1456
1457 \f
1458 ;;;
1459 ;;; Gnus summary mode
1460 ;;;
1461
1462 (put 'gnus-summary-mode 'mode-class 'special)
1463
1464 (defvar gnus-article-commands-menu)
1465
1466 (when t
1467   ;; Non-orthogonal keys
1468
1469   (gnus-define-keys gnus-summary-mode-map
1470     " " gnus-summary-next-page
1471     "\177" gnus-summary-prev-page
1472     [delete] gnus-summary-prev-page
1473     [backspace] gnus-summary-prev-page
1474     "\r" gnus-summary-scroll-up
1475     "\M-\r" gnus-summary-scroll-down
1476     "n" gnus-summary-next-unread-article
1477     "p" gnus-summary-prev-unread-article
1478     "N" gnus-summary-next-article
1479     "P" gnus-summary-prev-article
1480     "\M-\C-n" gnus-summary-next-same-subject
1481     "\M-\C-p" gnus-summary-prev-same-subject
1482     "\M-n" gnus-summary-next-unread-subject
1483     "\M-p" gnus-summary-prev-unread-subject
1484     "." gnus-summary-first-unread-article
1485     "," gnus-summary-best-unread-article
1486     "\M-s" gnus-summary-search-article-forward
1487     "\M-r" gnus-summary-search-article-backward
1488     "<" gnus-summary-beginning-of-article
1489     ">" gnus-summary-end-of-article
1490     "j" gnus-summary-goto-article
1491     "^" gnus-summary-refer-parent-article
1492     "\M-^" gnus-summary-refer-article
1493     "u" gnus-summary-tick-article-forward
1494     "!" gnus-summary-tick-article-forward
1495     "U" gnus-summary-tick-article-backward
1496     "d" gnus-summary-mark-as-read-forward
1497     "D" gnus-summary-mark-as-read-backward
1498     "E" gnus-summary-mark-as-expirable
1499     "\M-u" gnus-summary-clear-mark-forward
1500     "\M-U" gnus-summary-clear-mark-backward
1501     "k" gnus-summary-kill-same-subject-and-select
1502     "\C-k" gnus-summary-kill-same-subject
1503     "\M-\C-k" gnus-summary-kill-thread
1504     "\M-\C-l" gnus-summary-lower-thread
1505     "e" gnus-summary-edit-article
1506     "#" gnus-summary-mark-as-processable
1507     "\M-#" gnus-summary-unmark-as-processable
1508     "\M-\C-t" gnus-summary-toggle-threads
1509     "\M-\C-s" gnus-summary-show-thread
1510     "\M-\C-h" gnus-summary-hide-thread
1511     "\M-\C-f" gnus-summary-next-thread
1512     "\M-\C-b" gnus-summary-prev-thread
1513     [(meta down)] gnus-summary-next-thread
1514     [(meta up)] gnus-summary-prev-thread
1515     "\M-\C-u" gnus-summary-up-thread
1516     "\M-\C-d" gnus-summary-down-thread
1517     "&" gnus-summary-execute-command
1518     "c" gnus-summary-catchup-and-exit
1519     "\C-w" gnus-summary-mark-region-as-read
1520     "\C-t" gnus-summary-toggle-truncation
1521     "?" gnus-summary-mark-as-dormant
1522     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1523     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1524     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1525     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1526     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1527     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1528     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1529     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1530     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1531     "=" gnus-summary-expand-window
1532     "\C-x\C-s" gnus-summary-reselect-current-group
1533     "\M-g" gnus-summary-rescan-group
1534     "w" gnus-summary-stop-page-breaking
1535     "\C-c\C-r" gnus-summary-caesar-message
1536     "f" gnus-summary-followup
1537     "F" gnus-summary-followup-with-original
1538     "C" gnus-summary-cancel-article
1539     "r" gnus-summary-reply
1540     "R" gnus-summary-reply-with-original
1541     "\C-c\C-f" gnus-summary-mail-forward
1542     "o" gnus-summary-save-article
1543     "\C-o" gnus-summary-save-article-mail
1544     "|" gnus-summary-pipe-output
1545     "\M-k" gnus-summary-edit-local-kill
1546     "\M-K" gnus-summary-edit-global-kill
1547     ;; "V" gnus-version
1548     "\C-c\C-d" gnus-summary-describe-group
1549     "q" gnus-summary-exit
1550     "Q" gnus-summary-exit-no-update
1551     "\C-c\C-i" gnus-info-find-node
1552     gnus-mouse-2 gnus-mouse-pick-article
1553     "m" gnus-summary-mail-other-window
1554     "a" gnus-summary-post-news
1555     "i" gnus-summary-news-other-window
1556     "x" gnus-summary-limit-to-unread
1557     "s" gnus-summary-isearch-article
1558     "t" gnus-summary-toggle-header
1559     "g" gnus-summary-show-article
1560     "l" gnus-summary-goto-last-article
1561     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1562     "\C-d" gnus-summary-enter-digest-group
1563     "\M-\C-d" gnus-summary-read-document
1564     "\M-\C-e" gnus-summary-edit-parameters
1565     "\M-\C-a" gnus-summary-customize-parameters
1566     "\C-c\C-b" gnus-bug
1567     "*" gnus-cache-enter-article
1568     "\M-*" gnus-cache-remove-article
1569     "\M-&" gnus-summary-universal-argument
1570     "\C-l" gnus-recenter
1571     "I" gnus-summary-increase-score
1572     "L" gnus-summary-lower-score
1573     "\M-i" gnus-symbolic-argument
1574     "h" gnus-summary-select-article-buffer
1575
1576     "b" gnus-article-view-part
1577     "\M-t" gnus-summary-toggle-display-buttonized
1578
1579     "V" gnus-summary-score-map
1580     "X" gnus-uu-extract-map
1581     "S" gnus-summary-send-map)
1582
1583   ;; Sort of orthogonal keymap
1584   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1585     "t" gnus-summary-tick-article-forward
1586     "!" gnus-summary-tick-article-forward
1587     "d" gnus-summary-mark-as-read-forward
1588     "r" gnus-summary-mark-as-read-forward
1589     "c" gnus-summary-clear-mark-forward
1590     " " gnus-summary-clear-mark-forward
1591     "e" gnus-summary-mark-as-expirable
1592     "x" gnus-summary-mark-as-expirable
1593     "?" gnus-summary-mark-as-dormant
1594     "b" gnus-summary-set-bookmark
1595     "B" gnus-summary-remove-bookmark
1596     "#" gnus-summary-mark-as-processable
1597     "\M-#" gnus-summary-unmark-as-processable
1598     "S" gnus-summary-limit-include-expunged
1599     "C" gnus-summary-catchup
1600     "H" gnus-summary-catchup-to-here
1601     "h" gnus-summary-catchup-from-here
1602     "\C-c" gnus-summary-catchup-all
1603     "k" gnus-summary-kill-same-subject-and-select
1604     "K" gnus-summary-kill-same-subject
1605     "P" gnus-uu-mark-map)
1606
1607   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1608     "c" gnus-summary-clear-above
1609     "u" gnus-summary-tick-above
1610     "m" gnus-summary-mark-above
1611     "k" gnus-summary-kill-below)
1612
1613   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1614     "/" gnus-summary-limit-to-subject
1615     "n" gnus-summary-limit-to-articles
1616     "w" gnus-summary-pop-limit
1617     "s" gnus-summary-limit-to-subject
1618     "a" gnus-summary-limit-to-author
1619     "u" gnus-summary-limit-to-unread
1620     "m" gnus-summary-limit-to-marks
1621     "M" gnus-summary-limit-exclude-marks
1622     "v" gnus-summary-limit-to-score
1623     "*" gnus-summary-limit-include-cached
1624     "D" gnus-summary-limit-include-dormant
1625     "T" gnus-summary-limit-include-thread
1626     "d" gnus-summary-limit-exclude-dormant
1627     "t" gnus-summary-limit-to-age
1628     "x" gnus-summary-limit-to-extra
1629     "p" gnus-summary-limit-to-display-predicate
1630     "E" gnus-summary-limit-include-expunged
1631     "c" gnus-summary-limit-exclude-childless-dormant
1632     "C" gnus-summary-limit-mark-excluded-as-read
1633     "o" gnus-summary-insert-old-articles
1634     "N" gnus-summary-insert-new-articles)
1635
1636   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1637     "n" gnus-summary-next-unread-article
1638     "p" gnus-summary-prev-unread-article
1639     "N" gnus-summary-next-article
1640     "P" gnus-summary-prev-article
1641     "\C-n" gnus-summary-next-same-subject
1642     "\C-p" gnus-summary-prev-same-subject
1643     "\M-n" gnus-summary-next-unread-subject
1644     "\M-p" gnus-summary-prev-unread-subject
1645     "f" gnus-summary-first-unread-article
1646     "b" gnus-summary-best-unread-article
1647     "j" gnus-summary-goto-article
1648     "g" gnus-summary-goto-subject
1649     "l" gnus-summary-goto-last-article
1650     "o" gnus-summary-pop-article)
1651
1652   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1653     "k" gnus-summary-kill-thread
1654     "l" gnus-summary-lower-thread
1655     "i" gnus-summary-raise-thread
1656     "T" gnus-summary-toggle-threads
1657     "t" gnus-summary-rethread-current
1658     "^" gnus-summary-reparent-thread
1659     "s" gnus-summary-show-thread
1660     "S" gnus-summary-show-all-threads
1661     "h" gnus-summary-hide-thread
1662     "H" gnus-summary-hide-all-threads
1663     "n" gnus-summary-next-thread
1664     "p" gnus-summary-prev-thread
1665     "u" gnus-summary-up-thread
1666     "o" gnus-summary-top-thread
1667     "d" gnus-summary-down-thread
1668     "#" gnus-uu-mark-thread
1669     "\M-#" gnus-uu-unmark-thread)
1670
1671   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1672     "g" gnus-summary-prepare
1673     "c" gnus-summary-insert-cached-articles)
1674
1675   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1676     "c" gnus-summary-catchup-and-exit
1677     "C" gnus-summary-catchup-all-and-exit
1678     "E" gnus-summary-exit-no-update
1679     "Q" gnus-summary-exit
1680     "Z" gnus-summary-exit
1681     "n" gnus-summary-catchup-and-goto-next-group
1682     "R" gnus-summary-reselect-current-group
1683     "G" gnus-summary-rescan-group
1684     "N" gnus-summary-next-group
1685     "s" gnus-summary-save-newsrc
1686     "P" gnus-summary-prev-group)
1687
1688   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1689     " " gnus-summary-next-page
1690     "n" gnus-summary-next-page
1691     "\177" gnus-summary-prev-page
1692     [delete] gnus-summary-prev-page
1693     "p" gnus-summary-prev-page
1694     "\r" gnus-summary-scroll-up
1695     "\M-\r" gnus-summary-scroll-down
1696     "<" gnus-summary-beginning-of-article
1697     ">" gnus-summary-end-of-article
1698     "b" gnus-summary-beginning-of-article
1699     "e" gnus-summary-end-of-article
1700     "^" gnus-summary-refer-parent-article
1701     "r" gnus-summary-refer-parent-article
1702     "D" gnus-summary-enter-digest-group
1703     "R" gnus-summary-refer-references
1704     "T" gnus-summary-refer-thread
1705     "g" gnus-summary-show-article
1706     "s" gnus-summary-isearch-article
1707     "P" gnus-summary-print-article
1708     "M" gnus-mailing-list-insinuate
1709     "t" gnus-article-babel)
1710
1711   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1712     "b" gnus-article-add-buttons
1713     "B" gnus-article-add-buttons-to-head
1714     "o" gnus-article-treat-overstrike
1715     "e" gnus-article-emphasize
1716     "w" gnus-article-fill-cited-article
1717     "Q" gnus-article-fill-long-lines
1718     "C" gnus-article-capitalize-sentences
1719     "c" gnus-article-remove-cr
1720     "q" gnus-article-de-quoted-unreadable
1721     "6" gnus-article-de-base64-unreadable
1722     "Z" gnus-article-decode-HZ
1723     "h" gnus-article-wash-html
1724     "s" gnus-summary-force-verify-and-decrypt
1725     "f" gnus-article-display-x-face
1726     "l" gnus-summary-stop-page-breaking
1727     "r" gnus-summary-caesar-message
1728     "t" gnus-summary-toggle-header
1729     "g" gnus-summary-toggle-smiley
1730     "u" gnus-article-treat-unfold-headers
1731     "v" gnus-summary-verbose-headers
1732     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1733     "p" gnus-article-verify-x-pgp-sig
1734     "d" gnus-article-treat-dumbquotes)
1735
1736   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1737     "a" gnus-article-hide
1738     "h" gnus-article-hide-headers
1739     "b" gnus-article-hide-boring-headers
1740     "s" gnus-article-hide-signature
1741     "c" gnus-article-hide-citation
1742     "C" gnus-article-hide-citation-in-followups
1743     "l" gnus-article-hide-list-identifiers
1744     "p" gnus-article-hide-pgp
1745     "B" gnus-article-strip-banner
1746     "P" gnus-article-hide-pem
1747     "\C-c" gnus-article-hide-citation-maybe)
1748
1749   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1750     "a" gnus-article-highlight
1751     "h" gnus-article-highlight-headers
1752     "c" gnus-article-highlight-citation
1753     "s" gnus-article-highlight-signature)
1754
1755   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1756     "w" gnus-article-decode-mime-words
1757     "c" gnus-article-decode-charset
1758     "v" gnus-mime-view-all-parts
1759     "b" gnus-article-view-part)
1760
1761   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1762     "z" gnus-article-date-ut
1763     "u" gnus-article-date-ut
1764     "l" gnus-article-date-local
1765     "p" gnus-article-date-english
1766     "e" gnus-article-date-lapsed
1767     "o" gnus-article-date-original
1768     "i" gnus-article-date-iso8601
1769     "s" gnus-article-date-user)
1770
1771   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1772     "t" gnus-article-remove-trailing-blank-lines
1773     "l" gnus-article-strip-leading-blank-lines
1774     "m" gnus-article-strip-multiple-blank-lines
1775     "a" gnus-article-strip-blank-lines
1776     "A" gnus-article-strip-all-blank-lines
1777     "s" gnus-article-strip-leading-space
1778     "e" gnus-article-strip-trailing-space
1779     "w" gnus-article-remove-leading-whitespace)
1780
1781   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1782     "v" gnus-version
1783     "f" gnus-summary-fetch-faq
1784     "d" gnus-summary-describe-group
1785     "h" gnus-summary-describe-briefly
1786     "i" gnus-info-find-node)
1787
1788   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1789     "e" gnus-summary-expire-articles
1790     "\M-\C-e" gnus-summary-expire-articles-now
1791     "\177" gnus-summary-delete-article
1792     [delete] gnus-summary-delete-article
1793     [backspace] gnus-summary-delete-article
1794     "m" gnus-summary-move-article
1795     "r" gnus-summary-respool-article
1796     "w" gnus-summary-edit-article
1797     "c" gnus-summary-copy-article
1798     "B" gnus-summary-crosspost-article
1799     "q" gnus-summary-respool-query
1800     "t" gnus-summary-respool-trace
1801     "i" gnus-summary-import-article
1802     "I" gnus-summary-create-article
1803     "p" gnus-summary-article-posted-p)
1804
1805   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1806     "o" gnus-summary-save-article
1807     "m" gnus-summary-save-article-mail
1808     "F" gnus-summary-write-article-file
1809     "r" gnus-summary-save-article-rmail
1810     "f" gnus-summary-save-article-file
1811     "b" gnus-summary-save-article-body-file
1812     "h" gnus-summary-save-article-folder
1813     "v" gnus-summary-save-article-vm
1814     "p" gnus-summary-pipe-output
1815     "P" gnus-summary-muttprint
1816     "s" gnus-soup-add-article)
1817
1818   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1819     "b" gnus-summary-display-buttonized
1820     "m" gnus-summary-repair-multipart
1821     "v" gnus-article-view-part
1822     "o" gnus-article-save-part
1823     "c" gnus-article-copy-part
1824     "C" gnus-article-view-part-as-charset
1825     "e" gnus-article-externalize-part
1826     "E" gnus-article-encrypt-body
1827     "i" gnus-article-inline-part
1828     "|" gnus-article-pipe-part))
1829
1830 (defvar gnus-article-post-menu nil)
1831
1832 (defun gnus-summary-make-menu-bar ()
1833   (gnus-turn-off-edit-menu 'summary)
1834
1835   (unless (boundp 'gnus-summary-misc-menu)
1836
1837     (easy-menu-define
1838       gnus-summary-kill-menu gnus-summary-mode-map ""
1839       (cons
1840        "Score"
1841        (nconc
1842         (list
1843          ["Customize" gnus-score-customize t])
1844         (gnus-make-score-map 'increase)
1845         (gnus-make-score-map 'lower)
1846         '(("Mark"
1847            ["Kill below" gnus-summary-kill-below t]
1848            ["Mark above" gnus-summary-mark-above t]
1849            ["Tick above" gnus-summary-tick-above t]
1850            ["Clear above" gnus-summary-clear-above t])
1851           ["Current score" gnus-summary-current-score t]
1852           ["Set score" gnus-summary-set-score t]
1853           ["Switch current score file..." gnus-score-change-score-file t]
1854           ["Set mark below..." gnus-score-set-mark-below t]
1855           ["Set expunge below..." gnus-score-set-expunge-below t]
1856           ["Edit current score file" gnus-score-edit-current-scores t]
1857           ["Edit score file" gnus-score-edit-file t]
1858           ["Trace score" gnus-score-find-trace t]
1859           ["Find words" gnus-score-find-favourite-words t]
1860           ["Rescore buffer" gnus-summary-rescore t]
1861           ["Increase score..." gnus-summary-increase-score t]
1862           ["Lower score..." gnus-summary-lower-score t]))))
1863
1864     ;; Define both the Article menu in the summary buffer and the
1865     ;; equivalent Commands menu in the article buffer here for
1866     ;; consistency.
1867     (let ((innards
1868            `(("Hide"
1869               ["All" gnus-article-hide t]
1870               ["Headers" gnus-article-hide-headers t]
1871               ["Signature" gnus-article-hide-signature t]
1872               ["Citation" gnus-article-hide-citation t]
1873               ["List identifiers" gnus-article-hide-list-identifiers t]
1874               ["PGP" gnus-article-hide-pgp t]
1875               ["Banner" gnus-article-strip-banner t]
1876               ["Boring headers" gnus-article-hide-boring-headers t])
1877              ("Highlight"
1878               ["All" gnus-article-highlight t]
1879               ["Headers" gnus-article-highlight-headers t]
1880               ["Signature" gnus-article-highlight-signature t]
1881               ["Citation" gnus-article-highlight-citation t])
1882              ("MIME"
1883               ["Words" gnus-article-decode-mime-words t]
1884               ["Charset" gnus-article-decode-charset t]
1885               ["QP" gnus-article-de-quoted-unreadable t]
1886               ["Base64" gnus-article-de-base64-unreadable t]
1887               ["View all" gnus-mime-view-all-parts t]
1888               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1889               ["Encrypt body" gnus-article-encrypt-body t])
1890              ("Date"
1891               ["Local" gnus-article-date-local t]
1892               ["ISO8601" gnus-article-date-iso8601 t]
1893               ["UT" gnus-article-date-ut t]
1894               ["Original" gnus-article-date-original t]
1895               ["Lapsed" gnus-article-date-lapsed t]
1896               ["User-defined" gnus-article-date-user t])
1897              ("Washing"
1898               ("Remove Blanks"
1899                ["Leading" gnus-article-strip-leading-blank-lines t]
1900                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1901                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1902                ["All of the above" gnus-article-strip-blank-lines t]
1903                ["All" gnus-article-strip-all-blank-lines t]
1904                ["Leading space" gnus-article-strip-leading-space t]
1905                ["Trailing space" gnus-article-strip-trailing-space t]
1906                ["Leading space in headers"
1907                 gnus-article-remove-leading-whitespace t])
1908               ["Overstrike" gnus-article-treat-overstrike t]
1909               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1910               ["Emphasis" gnus-article-emphasize t]
1911               ["Word wrap" gnus-article-fill-cited-article t]
1912               ["Fill long lines" gnus-article-fill-long-lines t]
1913               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1914               ["CR" gnus-article-remove-cr t]
1915               ["Show X-Face" gnus-article-display-x-face t]
1916               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1917               ["Base64" gnus-article-de-base64-unreadable t]
1918               ["Rot 13" gnus-summary-caesar-message
1919                ,@(if (featurep 'xemacs) '(t)
1920                    '(:help "\"Caesar rotate\" article by 13"))]
1921               ["Unix pipe" gnus-summary-pipe-message t]
1922               ["Add buttons" gnus-article-add-buttons t]
1923               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1924               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1925               ["Verbose header" gnus-summary-verbose-headers t]
1926               ["Toggle header" gnus-summary-toggle-header t]
1927               ["Toggle smiley" gnus-summary-toggle-smiley t]
1928               ["Unfold headers" gnus-article-treat-unfold-headers t]
1929               ["Html" gnus-article-wash-html t]
1930               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1931               ["HZ" gnus-article-decode-HZ t])
1932              ("Output"
1933               ["Save in default format" gnus-summary-save-article
1934                ,@(if (featurep 'xemacs) '(t)
1935                    '(:help "Save article using default method"))]
1936               ["Save in file" gnus-summary-save-article-file
1937                ,@(if (featurep 'xemacs) '(t)
1938                    '(:help "Save article in file"))]
1939               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1940               ["Save in MH folder" gnus-summary-save-article-folder t]
1941               ["Save in VM folder" gnus-summary-save-article-vm t]
1942               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1943               ["Save body in file" gnus-summary-save-article-body-file t]
1944               ["Pipe through a filter" gnus-summary-pipe-output t]
1945               ["Add to SOUP packet" gnus-soup-add-article t]
1946               ["Print with Muttprint" gnus-summary-muttprint t]
1947               ["Print" gnus-summary-print-article t])
1948              ("Backend"
1949               ["Respool article..." gnus-summary-respool-article t]
1950               ["Move article..." gnus-summary-move-article
1951                (gnus-check-backend-function
1952                 'request-move-article gnus-newsgroup-name)]
1953               ["Copy article..." gnus-summary-copy-article t]
1954               ["Crosspost article..." gnus-summary-crosspost-article
1955                (gnus-check-backend-function
1956                 'request-replace-article gnus-newsgroup-name)]
1957               ["Import file..." gnus-summary-import-article t]
1958               ["Create article..." gnus-summary-create-article t]
1959               ["Check if posted" gnus-summary-article-posted-p t]
1960               ["Edit article" gnus-summary-edit-article
1961                (not (gnus-group-read-only-p))]
1962               ["Delete article" gnus-summary-delete-article
1963                (gnus-check-backend-function
1964                 'request-expire-articles gnus-newsgroup-name)]
1965               ["Query respool" gnus-summary-respool-query t]
1966               ["Trace respool" gnus-summary-respool-trace t]
1967               ["Delete expirable articles" gnus-summary-expire-articles-now
1968                (gnus-check-backend-function
1969                 'request-expire-articles gnus-newsgroup-name)])
1970              ("Extract"
1971               ["Uudecode" gnus-uu-decode-uu
1972                ,@(if (featurep 'xemacs) '(t)
1973                    '(:help "Decode uuencoded article(s)"))]
1974               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1975               ["Unshar" gnus-uu-decode-unshar t]
1976               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1977               ["Save" gnus-uu-decode-save t]
1978               ["Binhex" gnus-uu-decode-binhex t]
1979               ["Postscript" gnus-uu-decode-postscript t])
1980              ("Cache"
1981               ["Enter article" gnus-cache-enter-article t]
1982               ["Remove article" gnus-cache-remove-article t])
1983              ["Translate" gnus-article-babel t]
1984              ["Select article buffer" gnus-summary-select-article-buffer t]
1985              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1986              ["Isearch article..." gnus-summary-isearch-article t]
1987              ["Beginning of the article" gnus-summary-beginning-of-article t]
1988              ["End of the article" gnus-summary-end-of-article t]
1989              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1990              ["Fetch referenced articles" gnus-summary-refer-references t]
1991              ["Fetch current thread" gnus-summary-refer-thread t]
1992              ["Fetch article with id..." gnus-summary-refer-article t]
1993              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1994              ["Redisplay" gnus-summary-show-article t]
1995              ["Raw article" gnus-summary-show-raw-article t])))
1996       (easy-menu-define
1997         gnus-summary-article-menu gnus-summary-mode-map ""
1998         (cons "Article" innards))
1999
2000       (if (not (keymapp gnus-summary-article-menu))
2001           (easy-menu-define
2002             gnus-article-commands-menu gnus-article-mode-map ""
2003             (cons "Commands" innards))
2004         ;; in Emacs, don't share menu.
2005         (setq gnus-article-commands-menu
2006               (copy-keymap gnus-summary-article-menu))
2007         (define-key gnus-article-mode-map [menu-bar commands]
2008           (cons "Commands" gnus-article-commands-menu))))
2009
2010     (easy-menu-define
2011       gnus-summary-thread-menu gnus-summary-mode-map ""
2012       '("Threads"
2013         ["Toggle threading" gnus-summary-toggle-threads t]
2014         ["Hide threads" gnus-summary-hide-all-threads t]
2015         ["Show threads" gnus-summary-show-all-threads t]
2016         ["Hide thread" gnus-summary-hide-thread t]
2017         ["Show thread" gnus-summary-show-thread t]
2018         ["Go to next thread" gnus-summary-next-thread t]
2019         ["Go to previous thread" gnus-summary-prev-thread t]
2020         ["Go down thread" gnus-summary-down-thread t]
2021         ["Go up thread" gnus-summary-up-thread t]
2022         ["Top of thread" gnus-summary-top-thread t]
2023         ["Mark thread as read" gnus-summary-kill-thread t]
2024         ["Lower thread score" gnus-summary-lower-thread t]
2025         ["Raise thread score" gnus-summary-raise-thread t]
2026         ["Rethread current" gnus-summary-rethread-current t]))
2027
2028     (easy-menu-define
2029       gnus-summary-post-menu gnus-summary-mode-map ""
2030       `("Post"
2031         ["Send a message (mail or news)" gnus-summary-post-news
2032          ,@(if (featurep 'xemacs) '(t)
2033              '(:help "Post an article"))]
2034         ["Followup" gnus-summary-followup
2035          ,@(if (featurep 'xemacs) '(t)
2036              '(:help "Post followup to this article"))]
2037         ["Followup and yank" gnus-summary-followup-with-original
2038          ,@(if (featurep 'xemacs) '(t)
2039              '(:help "Post followup to this article, quoting its contents"))]
2040         ["Supersede article" gnus-summary-supersede-article t]
2041         ["Cancel article" gnus-summary-cancel-article
2042          ,@(if (featurep 'xemacs) '(t)
2043              '(:help "Cancel an article you posted"))]
2044         ["Reply" gnus-summary-reply t]
2045         ["Reply and yank" gnus-summary-reply-with-original t]
2046         ["Wide reply" gnus-summary-wide-reply t]
2047         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2048          ,@(if (featurep 'xemacs) '(t)
2049              '(:help "Mail a reply, quoting this article"))]
2050         ["Mail forward" gnus-summary-mail-forward t]
2051         ["Post forward" gnus-summary-post-forward t]
2052         ["Digest and mail" gnus-uu-digest-mail-forward t]
2053         ["Digest and post" gnus-uu-digest-post-forward t]
2054         ["Resend message" gnus-summary-resend-message t]
2055         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2056         ["Send a mail" gnus-summary-mail-other-window t]
2057         ["Create a local message" gnus-summary-news-other-window t]
2058         ["Uuencode and post" gnus-uu-post-news
2059          ,@(if (featurep 'xemacs) '(t)
2060              '(:help "Post a uuencoded article"))]
2061         ["Followup via news" gnus-summary-followup-to-mail t]
2062         ["Followup via news and yank"
2063          gnus-summary-followup-to-mail-with-original t]
2064         ;;("Draft"
2065         ;;["Send" gnus-summary-send-draft t]
2066         ;;["Send bounced" gnus-resend-bounced-mail t])
2067         ))
2068
2069     (cond
2070      ((not (keymapp gnus-summary-post-menu))
2071       (setq gnus-article-post-menu gnus-summary-post-menu))
2072      ((not gnus-article-post-menu)
2073       ;; Don't share post menu.
2074       (setq gnus-article-post-menu
2075             (copy-keymap gnus-summary-post-menu))))
2076     (define-key gnus-article-mode-map [menu-bar post]
2077       (cons "Post" gnus-article-post-menu))
2078
2079     (easy-menu-define
2080       gnus-summary-misc-menu gnus-summary-mode-map ""
2081       `("Gnus"
2082         ("Mark Read"
2083          ["Mark as read" gnus-summary-mark-as-read-forward t]
2084          ["Mark same subject and select"
2085           gnus-summary-kill-same-subject-and-select t]
2086          ["Mark same subject" gnus-summary-kill-same-subject t]
2087          ["Catchup" gnus-summary-catchup
2088           ,@(if (featurep 'xemacs) '(t)
2089               '(:help "Mark unread articles in this group as read"))]
2090          ["Catchup all" gnus-summary-catchup-all t]
2091          ["Catchup to here" gnus-summary-catchup-to-here t]
2092          ["Catchup from here" gnus-summary-catchup-from-here t]
2093          ["Catchup region" gnus-summary-mark-region-as-read t]
2094          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2095         ("Mark Various"
2096          ["Tick" gnus-summary-tick-article-forward t]
2097          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2098          ["Remove marks" gnus-summary-clear-mark-forward t]
2099          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2100          ["Set bookmark" gnus-summary-set-bookmark t]
2101          ["Remove bookmark" gnus-summary-remove-bookmark t])
2102         ("Limit to"
2103          ["Marks..." gnus-summary-limit-to-marks t]
2104          ["Subject..." gnus-summary-limit-to-subject t]
2105          ["Author..." gnus-summary-limit-to-author t]
2106          ["Age..." gnus-summary-limit-to-age t]
2107          ["Extra..." gnus-summary-limit-to-extra t]
2108          ["Score" gnus-summary-limit-to-score t]
2109          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2110          ["Unread" gnus-summary-limit-to-unread t]
2111          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2112          ["Articles" gnus-summary-limit-to-articles t]
2113          ["Pop limit" gnus-summary-pop-limit t]
2114          ["Show dormant" gnus-summary-limit-include-dormant t]
2115          ["Hide childless dormant"
2116           gnus-summary-limit-exclude-childless-dormant t]
2117          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2118          ["Hide marked" gnus-summary-limit-exclude-marks t]
2119          ["Show expunged" gnus-summary-limit-include-expunged t])
2120         ("Process Mark"
2121          ["Set mark" gnus-summary-mark-as-processable t]
2122          ["Remove mark" gnus-summary-unmark-as-processable t]
2123          ["Remove all marks" gnus-summary-unmark-all-processable t]
2124          ["Mark above" gnus-uu-mark-over t]
2125          ["Mark series" gnus-uu-mark-series t]
2126          ["Mark region" gnus-uu-mark-region t]
2127          ["Unmark region" gnus-uu-unmark-region t]
2128          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2129          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2130          ["Mark all" gnus-uu-mark-all t]
2131          ["Mark buffer" gnus-uu-mark-buffer t]
2132          ["Mark sparse" gnus-uu-mark-sparse t]
2133          ["Mark thread" gnus-uu-mark-thread t]
2134          ["Unmark thread" gnus-uu-unmark-thread t]
2135          ("Process Mark Sets"
2136           ["Kill" gnus-summary-kill-process-mark t]
2137           ["Yank" gnus-summary-yank-process-mark
2138            gnus-newsgroup-process-stack]
2139           ["Save" gnus-summary-save-process-mark t]))
2140         ("Scroll article"
2141          ["Page forward" gnus-summary-next-page
2142           ,@(if (featurep 'xemacs) '(t)
2143               '(:help "Show next page of article"))]
2144          ["Page backward" gnus-summary-prev-page
2145           ,@(if (featurep 'xemacs) '(t)
2146               '(:help "Show previous page of article"))]
2147          ["Line forward" gnus-summary-scroll-up t])
2148         ("Move"
2149          ["Next unread article" gnus-summary-next-unread-article t]
2150          ["Previous unread article" gnus-summary-prev-unread-article t]
2151          ["Next article" gnus-summary-next-article t]
2152          ["Previous article" gnus-summary-prev-article t]
2153          ["Next unread subject" gnus-summary-next-unread-subject t]
2154          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2155          ["Next article same subject" gnus-summary-next-same-subject t]
2156          ["Previous article same subject" gnus-summary-prev-same-subject t]
2157          ["First unread article" gnus-summary-first-unread-article t]
2158          ["Best unread article" gnus-summary-best-unread-article t]
2159          ["Go to subject number..." gnus-summary-goto-subject t]
2160          ["Go to article number..." gnus-summary-goto-article t]
2161          ["Go to the last article" gnus-summary-goto-last-article t]
2162          ["Pop article off history" gnus-summary-pop-article t])
2163         ("Sort"
2164          ["Sort by number" gnus-summary-sort-by-number t]
2165          ["Sort by author" gnus-summary-sort-by-author t]
2166          ["Sort by subject" gnus-summary-sort-by-subject t]
2167          ["Sort by date" gnus-summary-sort-by-date t]
2168          ["Sort by score" gnus-summary-sort-by-score t]
2169          ["Sort by lines" gnus-summary-sort-by-lines t]
2170          ["Sort by characters" gnus-summary-sort-by-chars t]
2171          ["Original sort" gnus-summary-sort-by-original t])
2172         ("Help"
2173          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2174          ["Describe group" gnus-summary-describe-group t]
2175          ["Read manual" gnus-info-find-node t])
2176         ("Modes"
2177          ["Pick and read" gnus-pick-mode t]
2178          ["Binary" gnus-binary-mode t])
2179         ("Regeneration"
2180          ["Regenerate" gnus-summary-prepare t]
2181          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2182          ["Toggle threading" gnus-summary-toggle-threads t])
2183         ["See old articles" gnus-summary-insert-old-articles t]
2184         ["See new articles" gnus-summary-insert-new-articles t]
2185         ["Filter articles..." gnus-summary-execute-command t]
2186         ["Run command on subjects..." gnus-summary-universal-argument t]
2187         ["Search articles forward..." gnus-summary-search-article-forward t]
2188         ["Search articles backward..." gnus-summary-search-article-backward t]
2189         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2190         ["Expand window" gnus-summary-expand-window t]
2191         ["Expire expirable articles" gnus-summary-expire-articles
2192          (gnus-check-backend-function
2193           'request-expire-articles gnus-newsgroup-name)]
2194         ["Edit local kill file" gnus-summary-edit-local-kill t]
2195         ["Edit main kill file" gnus-summary-edit-global-kill t]
2196         ["Edit group parameters" gnus-summary-edit-parameters t]
2197         ["Customize group parameters" gnus-summary-customize-parameters t]
2198         ["Send a bug report" gnus-bug t]
2199         ("Exit"
2200          ["Catchup and exit" gnus-summary-catchup-and-exit
2201           ,@(if (featurep 'xemacs) '(t)
2202               '(:help "Mark unread articles in this group as read, then exit"))]
2203          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2204          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2205          ["Exit group" gnus-summary-exit
2206           ,@(if (featurep 'xemacs) '(t)
2207               '(:help "Exit current group, return to group selection mode"))]
2208          ["Exit group without updating" gnus-summary-exit-no-update t]
2209          ["Exit and goto next group" gnus-summary-next-group t]
2210          ["Exit and goto prev group" gnus-summary-prev-group t]
2211          ["Reselect group" gnus-summary-reselect-current-group t]
2212          ["Rescan group" gnus-summary-rescan-group t]
2213          ["Update dribble" gnus-summary-save-newsrc t])))
2214
2215     (gnus-run-hooks 'gnus-summary-menu-hook)))
2216
2217 (defvar gnus-summary-tool-bar-map nil)
2218
2219 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2220 (defun gnus-summary-make-tool-bar ()
2221   (if (and (fboundp 'tool-bar-add-item-from-menu)
2222            (default-value 'tool-bar-mode)
2223            (not gnus-summary-tool-bar-map))
2224       (setq gnus-summary-tool-bar-map
2225             (let ((tool-bar-map (make-sparse-keymap))
2226                   (load-path (mm-image-load-path)))
2227               (tool-bar-add-item-from-menu
2228                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2229               (tool-bar-add-item-from-menu
2230                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2231               (tool-bar-add-item-from-menu
2232                'gnus-summary-post-news "post" gnus-summary-mode-map)
2233               (tool-bar-add-item-from-menu
2234                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2235               (tool-bar-add-item-from-menu
2236                'gnus-summary-followup "followup" gnus-summary-mode-map)
2237               (tool-bar-add-item-from-menu
2238                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2239               (tool-bar-add-item-from-menu
2240                'gnus-summary-reply "reply" gnus-summary-mode-map)
2241               (tool-bar-add-item-from-menu
2242                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2243               (tool-bar-add-item-from-menu
2244                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2245               (tool-bar-add-item-from-menu
2246                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2247               (tool-bar-add-item-from-menu
2248                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2249               (tool-bar-add-item-from-menu
2250                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2251               (tool-bar-add-item-from-menu
2252                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2253               (tool-bar-add-item-from-menu
2254                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2255               (tool-bar-add-item-from-menu
2256                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2257               tool-bar-map)))
2258   (if gnus-summary-tool-bar-map
2259       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2260
2261 (defun gnus-score-set-default (var value)
2262   "A version of set that updates the GNU Emacs menu-bar."
2263   (set var value)
2264   ;; It is the message that forces the active status to be updated.
2265   (message ""))
2266
2267 (defun gnus-make-score-map (type)
2268   "Make a summary score map of type TYPE."
2269   (if t
2270       nil
2271     (let ((headers '(("author" "from" string)
2272                      ("subject" "subject" string)
2273                      ("article body" "body" string)
2274                      ("article head" "head" string)
2275                      ("xref" "xref" string)
2276                      ("extra header" "extra" string)
2277                      ("lines" "lines" number)
2278                      ("followups to author" "followup" string)))
2279           (types '((number ("less than" <)
2280                            ("greater than" >)
2281                            ("equal" =))
2282                    (string ("substring" s)
2283                            ("exact string" e)
2284                            ("fuzzy string" f)
2285                            ("regexp" r))))
2286           (perms '(("temporary" (current-time-string))
2287                    ("permanent" nil)
2288                    ("immediate" now)))
2289           header)
2290       (list
2291        (apply
2292         'nconc
2293         (list
2294          (if (eq type 'lower)
2295              "Lower score"
2296            "Increase score"))
2297         (let (outh)
2298           (while headers
2299             (setq header (car headers))
2300             (setq outh
2301                   (cons
2302                    (apply
2303                     'nconc
2304                     (list (car header))
2305                     (let ((ts (cdr (assoc (nth 2 header) types)))
2306                           outt)
2307                       (while ts
2308                         (setq outt
2309                               (cons
2310                                (apply
2311                                 'nconc
2312                                 (list (caar ts))
2313                                 (let ((ps perms)
2314                                       outp)
2315                                   (while ps
2316                                     (setq outp
2317                                           (cons
2318                                            (vector
2319                                             (caar ps)
2320                                             (list
2321                                              'gnus-summary-score-entry
2322                                              (nth 1 header)
2323                                              (if (or (string= (nth 1 header)
2324                                                               "head")
2325                                                      (string= (nth 1 header)
2326                                                               "body"))
2327                                                  ""
2328                                                (list 'gnus-summary-header
2329                                                      (nth 1 header)))
2330                                              (list 'quote (nth 1 (car ts)))
2331                                              (list 'gnus-score-delta-default
2332                                                    nil)
2333                                              (nth 1 (car ps))
2334                                              t)
2335                                             t)
2336                                            outp))
2337                                     (setq ps (cdr ps)))
2338                                   (list (nreverse outp))))
2339                                outt))
2340                         (setq ts (cdr ts)))
2341                       (list (nreverse outt))))
2342                    outh))
2343             (setq headers (cdr headers)))
2344           (list (nreverse outh))))))))
2345
2346 \f
2347
2348 (defun gnus-summary-mode (&optional group)
2349   "Major mode for reading articles.
2350
2351 All normal editing commands are switched off.
2352 \\<gnus-summary-mode-map>
2353 Each line in this buffer represents one article.  To read an
2354 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2355 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2356 respectively.
2357
2358 You can also post articles and send mail from this buffer.  To
2359 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2360 of an article, type `\\[gnus-summary-reply]'.
2361
2362 There are approx. one gazillion commands you can execute in this
2363 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2364
2365 The following commands are available:
2366
2367 \\{gnus-summary-mode-map}"
2368   (interactive)
2369   (kill-all-local-variables)
2370   (when (gnus-visual-p 'summary-menu 'menu)
2371     (gnus-summary-make-menu-bar)
2372     (gnus-summary-make-tool-bar))
2373   (gnus-summary-make-local-variables)
2374   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2375     (gnus-summary-make-local-variables))
2376   (gnus-make-thread-indent-array)
2377   (gnus-simplify-mode-line)
2378   (setq major-mode 'gnus-summary-mode)
2379   (setq mode-name "Summary")
2380   (make-local-variable 'minor-mode-alist)
2381   (use-local-map gnus-summary-mode-map)
2382   (buffer-disable-undo)
2383   (setq buffer-read-only t)             ;Disable modification
2384   (setq truncate-lines t)
2385   (setq selective-display t)
2386   (setq selective-display-ellipses t)   ;Display `...'
2387   (gnus-summary-set-display-table)
2388   (gnus-set-default-directory)
2389   (setq gnus-newsgroup-name group)
2390   (make-local-variable 'gnus-summary-line-format)
2391   (make-local-variable 'gnus-summary-line-format-spec)
2392   (make-local-variable 'gnus-summary-dummy-line-format)
2393   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2394   (make-local-variable 'gnus-summary-mark-positions)
2395   (make-local-hook 'pre-command-hook)
2396   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2397   (gnus-run-hooks 'gnus-summary-mode-hook)
2398   (turn-on-gnus-mailing-list-mode)
2399   (mm-enable-multibyte-mule4)
2400   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2401   (gnus-update-summary-mark-positions))
2402
2403 (defun gnus-summary-make-local-variables ()
2404   "Make all the local summary buffer variables."
2405   (let (global)
2406     (dolist (local gnus-summary-local-variables)
2407       (if (consp local)
2408           (progn
2409             (if (eq (cdr local) 'global)
2410                 ;; Copy the global value of the variable.
2411                 (setq global (symbol-value (car local)))
2412               ;; Use the value from the list.
2413               (setq global (eval (cdr local))))
2414             (set (make-local-variable (car local)) global))
2415         ;; Simple nil-valued local variable.
2416         (set (make-local-variable local) nil)))))
2417
2418 (defun gnus-summary-clear-local-variables ()
2419   (let ((locals gnus-summary-local-variables))
2420     (while locals
2421       (if (consp (car locals))
2422           (and (vectorp (caar locals))
2423                (set (caar locals) nil))
2424         (and (vectorp (car locals))
2425              (set (car locals) nil)))
2426       (setq locals (cdr locals)))))
2427
2428 ;; Summary data functions.
2429
2430 (defmacro gnus-data-number (data)
2431   `(car ,data))
2432
2433 (defmacro gnus-data-set-number (data number)
2434   `(setcar ,data ,number))
2435
2436 (defmacro gnus-data-mark (data)
2437   `(nth 1 ,data))
2438
2439 (defmacro gnus-data-set-mark (data mark)
2440   `(setcar (nthcdr 1 ,data) ,mark))
2441
2442 (defmacro gnus-data-pos (data)
2443   `(nth 2 ,data))
2444
2445 (defmacro gnus-data-set-pos (data pos)
2446   `(setcar (nthcdr 2 ,data) ,pos))
2447
2448 (defmacro gnus-data-header (data)
2449   `(nth 3 ,data))
2450
2451 (defmacro gnus-data-set-header (data header)
2452   `(setf (nth 3 ,data) ,header))
2453
2454 (defmacro gnus-data-level (data)
2455   `(nth 4 ,data))
2456
2457 (defmacro gnus-data-unread-p (data)
2458   `(= (nth 1 ,data) gnus-unread-mark))
2459
2460 (defmacro gnus-data-read-p (data)
2461   `(/= (nth 1 ,data) gnus-unread-mark))
2462
2463 (defmacro gnus-data-pseudo-p (data)
2464   `(consp (nth 3 ,data)))
2465
2466 (defmacro gnus-data-find (number)
2467   `(assq ,number gnus-newsgroup-data))
2468
2469 (defmacro gnus-data-find-list (number &optional data)
2470   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2471      (memq (assq ,number bdata)
2472            bdata)))
2473
2474 (defmacro gnus-data-make (number mark pos header level)
2475   `(list ,number ,mark ,pos ,header ,level))
2476
2477 (defun gnus-data-enter (after-article number mark pos header level offset)
2478   (let ((data (gnus-data-find-list after-article)))
2479     (unless data
2480       (error "No such article: %d" after-article))
2481     (setcdr data (cons (gnus-data-make number mark pos header level)
2482                        (cdr data)))
2483     (setq gnus-newsgroup-data-reverse nil)
2484     (gnus-data-update-list (cddr data) offset)))
2485
2486 (defun gnus-data-enter-list (after-article list &optional offset)
2487   (when list
2488     (let ((data (and after-article (gnus-data-find-list after-article)))
2489           (ilist list))
2490       (if (not (or data
2491                    after-article))
2492           (let ((odata gnus-newsgroup-data))
2493             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2494             (when offset
2495               (gnus-data-update-list odata offset)))
2496       ;; Find the last element in the list to be spliced into the main
2497         ;; list.
2498         (while (cdr list)
2499           (setq list (cdr list)))
2500         (if (not data)
2501             (progn
2502               (setcdr list gnus-newsgroup-data)
2503               (setq gnus-newsgroup-data ilist)
2504               (when offset
2505                 (gnus-data-update-list (cdr list) offset)))
2506           (setcdr list (cdr data))
2507           (setcdr data ilist)
2508           (when offset
2509             (gnus-data-update-list (cdr list) offset))))
2510       (setq gnus-newsgroup-data-reverse nil))))
2511
2512 (defun gnus-data-remove (article &optional offset)
2513   (let ((data gnus-newsgroup-data))
2514     (if (= (gnus-data-number (car data)) article)
2515         (progn
2516           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2517                 gnus-newsgroup-data-reverse nil)
2518           (when offset
2519             (gnus-data-update-list gnus-newsgroup-data offset)))
2520       (while (cdr data)
2521         (when (= (gnus-data-number (cadr data)) article)
2522           (setcdr data (cddr data))
2523           (when offset
2524             (gnus-data-update-list (cdr data) offset))
2525           (setq data nil
2526                 gnus-newsgroup-data-reverse nil))
2527         (setq data (cdr data))))))
2528
2529 (defmacro gnus-data-list (backward)
2530   `(if ,backward
2531        (or gnus-newsgroup-data-reverse
2532            (setq gnus-newsgroup-data-reverse
2533                  (reverse gnus-newsgroup-data)))
2534      gnus-newsgroup-data))
2535
2536 (defun gnus-data-update-list (data offset)
2537   "Add OFFSET to the POS of all data entries in DATA."
2538   (setq gnus-newsgroup-data-reverse nil)
2539   (while data
2540     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2541     (setq data (cdr data))))
2542
2543 (defun gnus-summary-article-pseudo-p (article)
2544   "Say whether this article is a pseudo article or not."
2545   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2546
2547 (defmacro gnus-summary-article-sparse-p (article)
2548   "Say whether this article is a sparse article or not."
2549   `(memq ,article gnus-newsgroup-sparse))
2550
2551 (defmacro gnus-summary-article-ancient-p (article)
2552   "Say whether this article is a sparse article or not."
2553   `(memq ,article gnus-newsgroup-ancient))
2554
2555 (defun gnus-article-parent-p (number)
2556   "Say whether this article is a parent or not."
2557   (let ((data (gnus-data-find-list number)))
2558     (and (cdr data)              ; There has to be an article after...
2559          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2560             (gnus-data-level (nth 1 data))))))
2561
2562 (defun gnus-article-children (number)
2563   "Return a list of all children to NUMBER."
2564   (let* ((data (gnus-data-find-list number))
2565          (level (gnus-data-level (car data)))
2566          children)
2567     (setq data (cdr data))
2568     (while (and data
2569                 (= (gnus-data-level (car data)) (1+ level)))
2570       (push (gnus-data-number (car data)) children)
2571       (setq data (cdr data)))
2572     children))
2573
2574 (defmacro gnus-summary-skip-intangible ()
2575   "If the current article is intangible, then jump to a different article."
2576   '(let ((to (get-text-property (point) 'gnus-intangible)))
2577      (and to (gnus-summary-goto-subject to))))
2578
2579 (defmacro gnus-summary-article-intangible-p ()
2580   "Say whether this article is intangible or not."
2581   '(get-text-property (point) 'gnus-intangible))
2582
2583 (defun gnus-article-read-p (article)
2584   "Say whether ARTICLE is read or not."
2585   (not (or (memq article gnus-newsgroup-marked)
2586            (memq article gnus-newsgroup-unreads)
2587            (memq article gnus-newsgroup-unselected)
2588            (memq article gnus-newsgroup-dormant))))
2589
2590 ;; Some summary mode macros.
2591
2592 (defmacro gnus-summary-article-number ()
2593   "The article number of the article on the current line.
2594 If there isn's an article number here, then we return the current
2595 article number."
2596   '(progn
2597      (gnus-summary-skip-intangible)
2598      (or (get-text-property (point) 'gnus-number)
2599          (gnus-summary-last-subject))))
2600
2601 (defmacro gnus-summary-article-header (&optional number)
2602   "Return the header of article NUMBER."
2603   `(gnus-data-header (gnus-data-find
2604                       ,(or number '(gnus-summary-article-number)))))
2605
2606 (defmacro gnus-summary-thread-level (&optional number)
2607   "Return the level of thread that starts with article NUMBER."
2608   `(if (and (eq gnus-summary-make-false-root 'dummy)
2609             (get-text-property (point) 'gnus-intangible))
2610        0
2611      (gnus-data-level (gnus-data-find
2612                        ,(or number '(gnus-summary-article-number))))))
2613
2614 (defmacro gnus-summary-article-mark (&optional number)
2615   "Return the mark of article NUMBER."
2616   `(gnus-data-mark (gnus-data-find
2617                     ,(or number '(gnus-summary-article-number)))))
2618
2619 (defmacro gnus-summary-article-pos (&optional number)
2620   "Return the position of the line of article NUMBER."
2621   `(gnus-data-pos (gnus-data-find
2622                    ,(or number '(gnus-summary-article-number)))))
2623
2624 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2625 (defmacro gnus-summary-article-subject (&optional number)
2626   "Return current subject string or nil if nothing."
2627   `(let ((headers
2628           ,(if number
2629                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2630              '(gnus-data-header (assq (gnus-summary-article-number)
2631                                       gnus-newsgroup-data)))))
2632      (and headers
2633           (vectorp headers)
2634           (mail-header-subject headers))))
2635
2636 (defmacro gnus-summary-article-score (&optional number)
2637   "Return current article score."
2638   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2639                   gnus-newsgroup-scored))
2640        gnus-summary-default-score 0))
2641
2642 (defun gnus-summary-article-children (&optional number)
2643   "Return a list of article numbers that are children of article NUMBER."
2644   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2645          (level (gnus-data-level (car data)))
2646          l children)
2647     (while (and (setq data (cdr data))
2648                 (> (setq l (gnus-data-level (car data))) level))
2649       (and (= (1+ level) l)
2650            (push (gnus-data-number (car data))
2651                  children)))
2652     (nreverse children)))
2653
2654 (defun gnus-summary-article-parent (&optional number)
2655   "Return the article number of the parent of article NUMBER."
2656   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2657                                     (gnus-data-list t)))
2658          (level (gnus-data-level (car data))))
2659     (if (zerop level)
2660         ()                              ; This is a root.
2661       ;; We search until we find an article with a level less than
2662       ;; this one.  That function has to be the parent.
2663       (while (and (setq data (cdr data))
2664                   (not (< (gnus-data-level (car data)) level))))
2665       (and data (gnus-data-number (car data))))))
2666
2667 (defun gnus-unread-mark-p (mark)
2668   "Say whether MARK is the unread mark."
2669   (= mark gnus-unread-mark))
2670
2671 (defun gnus-read-mark-p (mark)
2672   "Say whether MARK is one of the marks that mark as read.
2673 This is all marks except unread, ticked, dormant, and expirable."
2674   (not (or (= mark gnus-unread-mark)
2675            (= mark gnus-ticked-mark)
2676            (= mark gnus-dormant-mark)
2677            (= mark gnus-expirable-mark))))
2678
2679 (defmacro gnus-article-mark (number)
2680   "Return the MARK of article NUMBER.
2681 This macro should only be used when computing the mark the \"first\"
2682 time; i.e., when generating the summary lines.  After that,
2683 `gnus-summary-article-mark' should be used to examine the
2684 marks of articles."
2685   `(cond
2686     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2687     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2688     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2689     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2690     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2691     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2692     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2693     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2694            gnus-ancient-mark))))
2695
2696 ;; Saving hidden threads.
2697
2698 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2699 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2700
2701 (defmacro gnus-save-hidden-threads (&rest forms)
2702   "Save hidden threads, eval FORMS, and restore the hidden threads."
2703   (let ((config (make-symbol "config")))
2704     `(let ((,config (gnus-hidden-threads-configuration)))
2705        (unwind-protect
2706            (save-excursion
2707              ,@forms)
2708          (gnus-restore-hidden-threads-configuration ,config)))))
2709
2710 (defun gnus-data-compute-positions ()
2711   "Compute the positions of all articles."
2712   (setq gnus-newsgroup-data-reverse nil)
2713   (let ((data gnus-newsgroup-data))
2714     (save-excursion
2715       (gnus-save-hidden-threads
2716         (gnus-summary-show-all-threads)
2717         (goto-char (point-min))
2718         (while data
2719           (while (get-text-property (point) 'gnus-intangible)
2720             (forward-line 1))
2721           (gnus-data-set-pos (car data) (+ (point) 3))
2722           (setq data (cdr data))
2723           (forward-line 1))))))
2724
2725 (defun gnus-hidden-threads-configuration ()
2726   "Return the current hidden threads configuration."
2727   (save-excursion
2728     (let (config)
2729       (goto-char (point-min))
2730       (while (search-forward "\r" nil t)
2731         (push (1- (point)) config))
2732       config)))
2733
2734 (defun gnus-restore-hidden-threads-configuration (config)
2735   "Restore hidden threads configuration from CONFIG."
2736   (save-excursion
2737     (let (point buffer-read-only)
2738       (while (setq point (pop config))
2739         (when (and (< point (point-max))
2740                    (goto-char point)
2741                    (eq (char-after) ?\n))
2742           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2743
2744 ;; Various summary mode internalish functions.
2745
2746 (defun gnus-mouse-pick-article (e)
2747   (interactive "e")
2748   (mouse-set-point e)
2749   (gnus-summary-next-page nil t))
2750
2751 (defun gnus-summary-set-display-table ()
2752   "Change the display table.
2753 Odd characters have a tendency to mess
2754 up nicely formatted displays - we make all possible glyphs
2755 display only a single character."
2756
2757   ;; We start from the standard display table, if any.
2758   (let ((table (or (copy-sequence standard-display-table)
2759                    (make-display-table)))
2760         (i 32))
2761     ;; Nix out all the control chars...
2762     (while (>= (setq i (1- i)) 0)
2763       (aset table i [??]))
2764    ;; ... but not newline and cr, of course.  (cr is necessary for the
2765     ;; selective display).
2766     (aset table ?\n nil)
2767     (aset table ?\r nil)
2768     ;; We keep TAB as well.
2769     (aset table ?\t nil)
2770     ;; We nix out any glyphs over 126 that are not set already.
2771     (let ((i 256))
2772       (while (>= (setq i (1- i)) 127)
2773         ;; Only modify if the entry is nil.
2774         (unless (aref table i)
2775           (aset table i [??]))))
2776     (setq buffer-display-table table)))
2777
2778 (defun gnus-summary-set-article-display-arrow (pos)
2779   "Update the overlay arrow to point to line at position POS."
2780   (when (and gnus-summary-display-arrow
2781              (boundp 'overlay-arrow-position)
2782              (boundp 'overlay-arrow-string))
2783     (save-excursion
2784       (goto-char pos)
2785       (beginning-of-line)
2786       (unless overlay-arrow-position
2787         (setq overlay-arrow-position (make-marker)))
2788       (setq overlay-arrow-string "=>"
2789             overlay-arrow-position (set-marker overlay-arrow-position
2790                                                (point)
2791                                                (current-buffer))))))
2792
2793 (defun gnus-summary-buffer-name (group)
2794   "Return the summary buffer name of GROUP."
2795   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2796
2797 (defun gnus-summary-setup-buffer (group)
2798   "Initialize summary buffer."
2799   (let ((buffer (gnus-summary-buffer-name group)))
2800     (if (get-buffer buffer)
2801         (progn
2802           (set-buffer buffer)
2803           (setq gnus-summary-buffer (current-buffer))
2804           (not gnus-newsgroup-prepared))
2805       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2806       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2807       (gnus-summary-mode group)
2808       (when gnus-carpal
2809         (gnus-carpal-setup-buffer 'summary))
2810       (unless gnus-single-article-buffer
2811         (make-local-variable 'gnus-article-buffer)
2812         (make-local-variable 'gnus-article-current)
2813         (make-local-variable 'gnus-original-article-buffer))
2814       (setq gnus-newsgroup-name group)
2815       ;; Set any local variables in the group parameters.
2816       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2817       t)))
2818
2819 (defun gnus-set-global-variables ()
2820   "Set the global equivalents of the buffer-local variables.
2821 They are set to the latest values they had.  These reflect the summary
2822 buffer that was in action when the last article was fetched."
2823   (when (eq major-mode 'gnus-summary-mode)
2824     (setq gnus-summary-buffer (current-buffer))
2825     (let ((name gnus-newsgroup-name)
2826           (marked gnus-newsgroup-marked)
2827           (unread gnus-newsgroup-unreads)
2828           (headers gnus-current-headers)
2829           (data gnus-newsgroup-data)
2830           (summary gnus-summary-buffer)
2831           (article-buffer gnus-article-buffer)
2832           (original gnus-original-article-buffer)
2833           (gac gnus-article-current)
2834           (reffed gnus-reffed-article-number)
2835           (score-file gnus-current-score-file)
2836           (default-charset gnus-newsgroup-charset)
2837           vlist)
2838       (let ((locals gnus-newsgroup-variables))
2839         (while locals
2840           (if (consp (car locals))
2841               (push (eval (caar locals)) vlist)
2842             (push (eval (car locals)) vlist))
2843           (setq locals (cdr locals)))
2844         (setq vlist (nreverse vlist)))
2845       (save-excursion
2846         (set-buffer gnus-group-buffer)
2847         (setq gnus-newsgroup-name name
2848               gnus-newsgroup-marked marked
2849               gnus-newsgroup-unreads unread
2850               gnus-current-headers headers
2851               gnus-newsgroup-data data
2852               gnus-article-current gac
2853               gnus-summary-buffer summary
2854               gnus-article-buffer article-buffer
2855               gnus-original-article-buffer original
2856               gnus-reffed-article-number reffed
2857               gnus-current-score-file score-file
2858               gnus-newsgroup-charset default-charset)
2859         (let ((locals gnus-newsgroup-variables))
2860           (while locals
2861             (if (consp (car locals))
2862                 (set (caar locals) (pop vlist))
2863               (set (car locals) (pop vlist)))
2864             (setq locals (cdr locals))))
2865         ;; The article buffer also has local variables.
2866         (when (gnus-buffer-live-p gnus-article-buffer)
2867           (set-buffer gnus-article-buffer)
2868           (setq gnus-summary-buffer summary))))))
2869
2870 (defun gnus-summary-article-unread-p (article)
2871   "Say whether ARTICLE is unread or not."
2872   (memq article gnus-newsgroup-unreads))
2873
2874 (defun gnus-summary-first-article-p (&optional article)
2875   "Return whether ARTICLE is the first article in the buffer."
2876   (if (not (setq article (or article (gnus-summary-article-number))))
2877       nil
2878     (eq article (caar gnus-newsgroup-data))))
2879
2880 (defun gnus-summary-last-article-p (&optional article)
2881   "Return whether ARTICLE is the last article in the buffer."
2882   (if (not (setq article (or article (gnus-summary-article-number))))
2883       ;; All non-existent numbers are the last article.  :-)
2884       t
2885     (not (cdr (gnus-data-find-list article)))))
2886
2887 (defun gnus-make-thread-indent-array ()
2888   (let ((n 200))
2889     (unless (and gnus-thread-indent-array
2890                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2891       (setq gnus-thread-indent-array (make-vector 201 "")
2892             gnus-thread-indent-array-level gnus-thread-indent-level)
2893       (while (>= n 0)
2894         (aset gnus-thread-indent-array n
2895               (make-string (* n gnus-thread-indent-level) ? ))
2896         (setq n (1- n))))))
2897
2898 (defun gnus-update-summary-mark-positions ()
2899   "Compute where the summary marks are to go."
2900   (save-excursion
2901     (when (gnus-buffer-exists-p gnus-summary-buffer)
2902       (set-buffer gnus-summary-buffer))
2903     (let ((gnus-replied-mark 129)
2904           (gnus-score-below-mark 130)
2905           (gnus-score-over-mark 130)
2906           (gnus-download-mark 131)
2907           (spec gnus-summary-line-format-spec)
2908           gnus-visual pos)
2909       (save-excursion
2910         (gnus-set-work-buffer)
2911         (let ((gnus-summary-line-format-spec spec)
2912               (gnus-newsgroup-downloadable '((0 . t))))
2913           (gnus-summary-insert-line
2914            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2915            0 nil 128 t nil "" nil 1)
2916           (goto-char (point-min))
2917           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2918                                              (- (point) 2)))))
2919           (goto-char (point-min))
2920           (push (cons 'replied (and (search-forward "\201" nil t)
2921                                     (- (point) 2)))
2922                 pos)
2923           (goto-char (point-min))
2924           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2925                 pos)
2926           (goto-char (point-min))
2927           (push (cons 'download
2928                       (and (search-forward "\203" nil t) (- (point) 2)))
2929                 pos)))
2930       (setq gnus-summary-mark-positions pos))))
2931
2932 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2933   "Insert a dummy root in the summary buffer."
2934   (beginning-of-line)
2935   (gnus-add-text-properties
2936    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2937    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2938
2939 (defun gnus-summary-extract-address-component (from)
2940   (or (car (funcall gnus-extract-address-components from))
2941       from))
2942
2943 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2944   (let ((mail-parse-charset gnus-newsgroup-charset)
2945         ; Is it really necessary to do this next part for each summary line?
2946         ; Luckily, doesn't seem to slow things down much.
2947         (mail-parse-ignored-charsets
2948          (save-excursion (set-buffer gnus-summary-buffer)
2949                          gnus-newsgroup-ignored-charsets)))
2950     (or
2951      (and gnus-ignored-from-addresses
2952           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2953           (let ((extra-headers (mail-header-extra header))
2954                 to
2955                 newsgroups)
2956             (cond
2957              ((setq to (cdr (assq 'To extra-headers)))
2958               (concat "-> "
2959                       (gnus-summary-extract-address-component
2960                        (funcall gnus-decode-encoded-word-function to))))
2961              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2962               (concat "=> " newsgroups)))))
2963      (gnus-summary-extract-address-component gnus-tmp-from))))
2964
2965 (defun gnus-summary-insert-line (gnus-tmp-header
2966                                  gnus-tmp-level gnus-tmp-current
2967                                  gnus-tmp-unread gnus-tmp-replied
2968                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2969                                  &optional gnus-tmp-dummy gnus-tmp-score
2970                                  gnus-tmp-process)
2971   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2972          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2973          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2974          (gnus-tmp-score-char
2975           (if (or (null gnus-summary-default-score)
2976                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2977                       gnus-summary-zcore-fuzz))
2978               ?                         ;Whitespace
2979             (if (< gnus-tmp-score gnus-summary-default-score)
2980                 gnus-score-below-mark gnus-score-over-mark)))
2981          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2982          (gnus-tmp-replied
2983           (cond (gnus-tmp-process gnus-process-mark)
2984                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2985                  gnus-cached-mark)
2986                 (gnus-tmp-replied gnus-replied-mark)
2987                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
2988                  gnus-forwarded-mark)
2989                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2990                  gnus-saved-mark)
2991                 ((memq gnus-tmp-number gnus-newsgroup-recent)
2992                  gnus-recent-mark)
2993                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
2994                  gnus-unseen-mark)
2995                 (t gnus-no-mark)))
2996          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2997          (gnus-tmp-name
2998           (cond
2999            ((string-match "<[^>]+> *$" gnus-tmp-from)
3000             (let ((beg (match-beginning 0)))
3001               (or (and (string-match "^\".+\"" gnus-tmp-from)
3002                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3003                   (substring gnus-tmp-from 0 beg))))
3004            ((string-match "(.+)" gnus-tmp-from)
3005             (substring gnus-tmp-from
3006                        (1+ (match-beginning 0)) (1- (match-end 0))))
3007            (t gnus-tmp-from)))
3008          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3009          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3010          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3011          (buffer-read-only nil))
3012     (when (string= gnus-tmp-name "")
3013       (setq gnus-tmp-name gnus-tmp-from))
3014     (unless (numberp gnus-tmp-lines)
3015       (setq gnus-tmp-lines -1))
3016     (if (= gnus-tmp-lines -1)
3017         (setq gnus-tmp-lines "?")
3018       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3019     (gnus-put-text-property
3020      (point)
3021      (progn (eval gnus-summary-line-format-spec) (point))
3022      'gnus-number gnus-tmp-number)
3023     (when (gnus-visual-p 'summary-highlight 'highlight)
3024       (forward-line -1)
3025       (gnus-run-hooks 'gnus-summary-update-hook)
3026       (forward-line 1))))
3027
3028 (defun gnus-summary-update-line (&optional dont-update)
3029   "Update summary line after change."
3030   (when (and gnus-summary-default-score
3031              (not gnus-summary-inhibit-highlight))
3032     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3033            (article (gnus-summary-article-number))
3034            (score (gnus-summary-article-score article)))
3035       (unless dont-update
3036         (if (and gnus-summary-mark-below
3037                  (< (gnus-summary-article-score)
3038                     gnus-summary-mark-below))
3039             ;; This article has a low score, so we mark it as read.
3040             (when (memq article gnus-newsgroup-unreads)
3041               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3042           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3043             ;; This article was previously marked as read on account
3044             ;; of a low score, but now it has risen, so we mark it as
3045             ;; unread.
3046             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3047         (gnus-summary-update-mark
3048          (if (or (null gnus-summary-default-score)
3049                  (<= (abs (- score gnus-summary-default-score))
3050                      gnus-summary-zcore-fuzz))
3051              ?                          ;Whitespace
3052            (if (< score gnus-summary-default-score)
3053                gnus-score-below-mark gnus-score-over-mark))
3054          'score))
3055       ;; Do visual highlighting.
3056       (when (gnus-visual-p 'summary-highlight 'highlight)
3057         (gnus-run-hooks 'gnus-summary-update-hook)))))
3058
3059 (defvar gnus-tmp-new-adopts nil)
3060
3061 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3062   "Return the number of articles in THREAD.
3063 This may be 0 in some cases -- if none of the articles in
3064 the thread are to be displayed."
3065   (let* ((number
3066          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3067           (cond
3068            ((not (listp thread))
3069             1)
3070            ((and (consp thread) (cdr thread))
3071             (apply
3072              '+ 1 (mapcar
3073                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3074            ((null thread)
3075             1)
3076            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3077             1)
3078            (t 0))))
3079     (when (and level (zerop level) gnus-tmp-new-adopts)
3080       (incf number
3081             (apply '+ (mapcar
3082                        'gnus-summary-number-of-articles-in-thread
3083                        gnus-tmp-new-adopts))))
3084     (if char
3085         (if (> number 1) gnus-not-empty-thread-mark
3086           gnus-empty-thread-mark)
3087       number)))
3088
3089 (defun gnus-summary-set-local-parameters (group)
3090   "Go through the local params of GROUP and set all variable specs in that list."
3091   (let ((params (gnus-group-find-parameter group))
3092         (vars '(quit-config))           ; Ignore quit-config.
3093         elem)
3094     (while params
3095       (setq elem (car params)
3096             params (cdr params))
3097       (and (consp elem)                 ; Has to be a cons.
3098            (consp (cdr elem))           ; The cdr has to be a list.
3099            (symbolp (car elem))         ; Has to be a symbol in there.
3100            (not (memq (car elem) vars))
3101            (ignore-errors               ; So we set it.
3102              (push (car elem) vars)
3103              (make-local-variable (car elem))
3104              (set (car elem) (eval (nth 1 elem))))))))
3105
3106 (defun gnus-summary-read-group (group &optional show-all no-article
3107                                       kill-buffer no-display backward
3108                                       select-articles)
3109   "Start reading news in newsgroup GROUP.
3110 If SHOW-ALL is non-nil, already read articles are also listed.
3111 If NO-ARTICLE is non-nil, no article is selected initially.
3112 If NO-DISPLAY, don't generate a summary buffer."
3113   (let (result)
3114     (while (and group
3115                 (null (setq result
3116                             (let ((gnus-auto-select-next nil))
3117                               (or (gnus-summary-read-group-1
3118                                    group show-all no-article
3119                                    kill-buffer no-display
3120                                    select-articles)
3121                                   (setq show-all nil
3122                                         select-articles nil)))))
3123                 (eq gnus-auto-select-next 'quietly))
3124       (set-buffer gnus-group-buffer)
3125       ;; The entry function called above goes to the next
3126       ;; group automatically, so we go two groups back
3127       ;; if we are searching for the previous group.
3128       (when backward
3129         (gnus-group-prev-unread-group 2))
3130       (if (not (equal group (gnus-group-group-name)))
3131           (setq group (gnus-group-group-name))
3132         (setq group nil)))
3133     result))
3134
3135 (defun gnus-summary-read-group-1 (group show-all no-article
3136                                         kill-buffer no-display
3137                                         &optional select-articles)
3138   ;; Killed foreign groups can't be entered.
3139   ;;  (when (and (not (gnus-group-native-p group))
3140   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3141   ;;    (error "Dead non-native groups can't be entered"))
3142   (gnus-message 5 "Retrieving newsgroup: %s..."
3143                 (gnus-group-decoded-name group))
3144   (let* ((new-group (gnus-summary-setup-buffer group))
3145          (quit-config (gnus-group-quit-config group))
3146          (did-select (and new-group (gnus-select-newsgroup
3147                                      group show-all select-articles))))
3148     (cond
3149      ;; This summary buffer exists already, so we just select it.
3150      ((not new-group)
3151       (gnus-set-global-variables)
3152       (when kill-buffer
3153         (gnus-kill-or-deaden-summary kill-buffer))
3154       (gnus-configure-windows 'summary 'force)
3155       (gnus-set-mode-line 'summary)
3156       (gnus-summary-position-point)
3157       (message "")
3158       t)
3159      ;; We couldn't select this group.
3160      ((null did-select)
3161       (when (and (eq major-mode 'gnus-summary-mode)
3162                  (not (equal (current-buffer) kill-buffer)))
3163         (kill-buffer (current-buffer))
3164         (if (not quit-config)
3165             (progn
3166               ;; Update the info -- marks might need to be removed,
3167               ;; for instance.
3168               (gnus-summary-update-info)
3169               (set-buffer gnus-group-buffer)
3170               (gnus-group-jump-to-group group)
3171               (gnus-group-next-unread-group 1))
3172           (gnus-handle-ephemeral-exit quit-config)))
3173       (let ((grpinfo (gnus-get-info group)))
3174         (if (null (gnus-info-read grpinfo))
3175             (gnus-message 3 "Group %s contains no messages"
3176                           (gnus-group-decoded-name group))
3177           (gnus-message 3 "Can't select group")))
3178       nil)
3179      ;; The user did a `C-g' while prompting for number of articles,
3180      ;; so we exit this group.
3181      ((eq did-select 'quit)
3182       (and (eq major-mode 'gnus-summary-mode)
3183            (not (equal (current-buffer) kill-buffer))
3184            (kill-buffer (current-buffer)))
3185       (when kill-buffer
3186         (gnus-kill-or-deaden-summary kill-buffer))
3187       (if (not quit-config)
3188           (progn
3189             (set-buffer gnus-group-buffer)
3190             (gnus-group-jump-to-group group)
3191             (gnus-group-next-unread-group 1)
3192             (gnus-configure-windows 'group 'force))
3193         (gnus-handle-ephemeral-exit quit-config))
3194       ;; Finally signal the quit.
3195       (signal 'quit nil))
3196      ;; The group was successfully selected.
3197      (t
3198       (gnus-set-global-variables)
3199       ;; Save the active value in effect when the group was entered.
3200       (setq gnus-newsgroup-active
3201             (gnus-copy-sequence
3202              (gnus-active gnus-newsgroup-name)))
3203       ;; You can change the summary buffer in some way with this hook.
3204       (gnus-run-hooks 'gnus-select-group-hook)
3205       (gnus-update-format-specifications
3206        nil 'summary 'summary-mode 'summary-dummy)
3207       (gnus-update-summary-mark-positions)
3208       ;; Do score processing.
3209       (when gnus-use-scoring
3210         (gnus-possibly-score-headers))
3211       ;; Check whether to fill in the gaps in the threads.
3212       (when gnus-build-sparse-threads
3213         (gnus-build-sparse-threads))
3214       ;; Find the initial limit.
3215       (if gnus-show-threads
3216           (if show-all
3217               (let ((gnus-newsgroup-dormant nil))
3218                 (gnus-summary-initial-limit show-all))
3219             (gnus-summary-initial-limit show-all))
3220         ;; When untreaded, all articles are always shown.
3221         (setq gnus-newsgroup-limit
3222               (mapcar
3223                (lambda (header) (mail-header-number header))
3224                gnus-newsgroup-headers)))
3225       ;; Generate the summary buffer.
3226       (unless no-display
3227         (gnus-summary-prepare))
3228       (when gnus-use-trees
3229         (gnus-tree-open group)
3230         (setq gnus-summary-highlight-line-function
3231               'gnus-tree-highlight-article))
3232       ;; If the summary buffer is empty, but there are some low-scored
3233       ;; articles or some excluded dormants, we include these in the
3234       ;; buffer.
3235       (when (and (zerop (buffer-size))
3236                  (not no-display))
3237         (cond (gnus-newsgroup-dormant
3238                (gnus-summary-limit-include-dormant))
3239               ((and gnus-newsgroup-scored show-all)
3240                (gnus-summary-limit-include-expunged t))))
3241       ;; Function `gnus-apply-kill-file' must be called in this hook.
3242       (gnus-run-hooks 'gnus-apply-kill-hook)
3243       (if (and (zerop (buffer-size))
3244                (not no-display))
3245           (progn
3246             ;; This newsgroup is empty.
3247             (gnus-summary-catchup-and-exit nil t)
3248             (gnus-message 6 "No unread news")
3249             (when kill-buffer
3250               (gnus-kill-or-deaden-summary kill-buffer))
3251             ;; Return nil from this function.
3252             nil)
3253         ;; Hide conversation thread subtrees.  We cannot do this in
3254         ;; gnus-summary-prepare-hook since kill processing may not
3255         ;; work with hidden articles.
3256         (and gnus-show-threads
3257              gnus-thread-hide-subtree
3258              (gnus-summary-hide-all-threads))
3259         (when kill-buffer
3260           (gnus-kill-or-deaden-summary kill-buffer))
3261         (gnus-summary-auto-select-subject)
3262         ;; Show first unread article if requested.
3263         (if (and (not no-article)
3264                  (not no-display)
3265                  gnus-newsgroup-unreads
3266                  gnus-auto-select-first)
3267             (progn
3268               (gnus-configure-windows 'summary)
3269               (gnus-summary-goto-article (gnus-summary-article-number)))
3270           ;; Don't select any articles.
3271           (gnus-summary-position-point)
3272           (gnus-configure-windows 'summary 'force)
3273           (gnus-set-mode-line 'summary))
3274         (when (get-buffer-window gnus-group-buffer t)
3275           ;; Gotta use windows, because recenter does weird stuff if
3276           ;; the current buffer ain't the displayed window.
3277           (let ((owin (selected-window)))
3278             (select-window (get-buffer-window gnus-group-buffer t))
3279             (when (gnus-group-goto-group group)
3280               (recenter))
3281             (select-window owin)))
3282         ;; Mark this buffer as "prepared".
3283         (setq gnus-newsgroup-prepared t)
3284         (gnus-run-hooks 'gnus-summary-prepared-hook)
3285         t)))))
3286
3287 (defun gnus-summary-auto-select-subject ()
3288   "Select the subject line on initial group entry."
3289   (goto-char (point-min))
3290   (cond
3291    ((eq gnus-auto-select-subject 'best)
3292     (gnus-summary-best-unread-subject))
3293    ((eq gnus-auto-select-subject 'unread)
3294     (gnus-summary-first-unread-subject))
3295    ((eq gnus-auto-select-subject 'unseen)
3296     (gnus-summary-first-unseen-subject))
3297    ((eq gnus-auto-select-subject 'first)
3298     ;; Do nothing.
3299     )
3300    ((gnus-functionp gnus-auto-select-subject)
3301     (funcall gnus-auto-select-subject))))
3302
3303 (defun gnus-summary-prepare ()
3304   "Generate the summary buffer."
3305   (interactive)
3306   (let ((buffer-read-only nil))
3307     (erase-buffer)
3308     (setq gnus-newsgroup-data nil
3309           gnus-newsgroup-data-reverse nil)
3310     (gnus-run-hooks 'gnus-summary-generate-hook)
3311     ;; Generate the buffer, either with threads or without.
3312     (when gnus-newsgroup-headers
3313       (gnus-summary-prepare-threads
3314        (if gnus-show-threads
3315            (gnus-sort-gathered-threads
3316             (funcall gnus-summary-thread-gathering-function
3317                      (gnus-sort-threads
3318                       (gnus-cut-threads (gnus-make-threads)))))
3319          ;; Unthreaded display.
3320          (gnus-sort-articles gnus-newsgroup-headers))))
3321     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3322     ;; Call hooks for modifying summary buffer.
3323     (goto-char (point-min))
3324     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3325
3326 (defsubst gnus-general-simplify-subject (subject)
3327   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3328   (setq subject
3329         (cond
3330          ;; Truncate the subject.
3331          (gnus-simplify-subject-functions
3332           (gnus-map-function gnus-simplify-subject-functions subject))
3333          ((numberp gnus-summary-gather-subject-limit)
3334           (setq subject (gnus-simplify-subject-re subject))
3335           (if (> (length subject) gnus-summary-gather-subject-limit)
3336               (substring subject 0 gnus-summary-gather-subject-limit)
3337             subject))
3338          ;; Fuzzily simplify it.
3339          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3340           (gnus-simplify-subject-fuzzy subject))
3341          ;; Just remove the leading "Re:".
3342          (t
3343           (gnus-simplify-subject-re subject))))
3344
3345   (if (and gnus-summary-gather-exclude-subject
3346            (string-match gnus-summary-gather-exclude-subject subject))
3347       nil                         ; This article shouldn't be gathered
3348     subject))
3349
3350 (defun gnus-summary-simplify-subject-query ()
3351   "Query where the respool algorithm would put this article."
3352   (interactive)
3353   (gnus-summary-select-article)
3354   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3355
3356 (defun gnus-gather-threads-by-subject (threads)
3357   "Gather threads by looking at Subject headers."
3358   (if (not gnus-summary-make-false-root)
3359       threads
3360     (let ((hashtb (gnus-make-hashtable 1024))
3361           (prev threads)
3362           (result threads)
3363           subject hthread whole-subject)
3364       (while threads
3365         (setq subject (gnus-general-simplify-subject
3366                        (setq whole-subject (mail-header-subject
3367                                             (caar threads)))))
3368         (when subject
3369           (if (setq hthread (gnus-gethash subject hashtb))
3370               (progn
3371                 ;; We enter a dummy root into the thread, if we
3372                 ;; haven't done that already.
3373                 (unless (stringp (caar hthread))
3374                   (setcar hthread (list whole-subject (car hthread))))
3375                 ;; We add this new gathered thread to this gathered
3376                 ;; thread.
3377                 (setcdr (car hthread)
3378                         (nconc (cdar hthread) (list (car threads))))
3379                 ;; Remove it from the list of threads.
3380                 (setcdr prev (cdr threads))
3381                 (setq threads prev))
3382             ;; Enter this thread into the hash table.
3383             (gnus-sethash subject threads hashtb)))
3384         (setq prev threads)
3385         (setq threads (cdr threads)))
3386       result)))
3387
3388 (defun gnus-gather-threads-by-references (threads)
3389   "Gather threads by looking at References headers."
3390   (let ((idhashtb (gnus-make-hashtable 1024))
3391         (thhashtb (gnus-make-hashtable 1024))
3392         (prev threads)
3393         (result threads)
3394         ids references id gthread gid entered ref)
3395     (while threads
3396       (when (setq references (mail-header-references (caar threads)))
3397         (setq id (mail-header-id (caar threads))
3398               ids (gnus-split-references references)
3399               entered nil)
3400         (while (setq ref (pop ids))
3401           (setq ids (delete ref ids))
3402           (if (not (setq gid (gnus-gethash ref idhashtb)))
3403               (progn
3404                 (gnus-sethash ref id idhashtb)
3405                 (gnus-sethash id threads thhashtb))
3406             (setq gthread (gnus-gethash gid thhashtb))
3407             (unless entered
3408               ;; We enter a dummy root into the thread, if we
3409               ;; haven't done that already.
3410               (unless (stringp (caar gthread))
3411                 (setcar gthread (list (mail-header-subject (caar gthread))
3412                                       (car gthread))))
3413               ;; We add this new gathered thread to this gathered
3414               ;; thread.
3415               (setcdr (car gthread)
3416                       (nconc (cdar gthread) (list (car threads)))))
3417             ;; Add it into the thread hash table.
3418             (gnus-sethash id gthread thhashtb)
3419             (setq entered t)
3420             ;; Remove it from the list of threads.
3421             (setcdr prev (cdr threads))
3422             (setq threads prev))))
3423       (setq prev threads)
3424       (setq threads (cdr threads)))
3425     result))
3426
3427 (defun gnus-sort-gathered-threads (threads)
3428   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3429   (let ((result threads))
3430     (while threads
3431       (when (stringp (caar threads))
3432         (setcdr (car threads)
3433                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3434       (setq threads (cdr threads)))
3435     result))
3436
3437 (defun gnus-thread-loop-p (root thread)
3438   "Say whether ROOT is in THREAD."
3439   (let ((stack (list thread))
3440         (infloop 0)
3441         th)
3442     (while (setq thread (pop stack))
3443       (setq th (cdr thread))
3444       (while (and th
3445                   (not (eq (caar th) root)))
3446         (pop th))
3447       (if th
3448           ;; We have found a loop.
3449           (let (ref-dep)
3450             (setcdr thread (delq (car th) (cdr thread)))
3451             (if (boundp (setq ref-dep (intern "none"
3452                                               gnus-newsgroup-dependencies)))
3453                 (setcdr (symbol-value ref-dep)
3454                         (nconc (cdr (symbol-value ref-dep))
3455                                (list (car th))))
3456               (set ref-dep (list nil (car th))))
3457             (setq infloop 1
3458                   stack nil))
3459         ;; Push all the subthreads onto the stack.
3460         (push (cdr thread) stack)))
3461     infloop))
3462
3463 (defun gnus-make-threads ()
3464   "Go through the dependency hashtb and find the roots.  Return all threads."
3465   (let (threads)
3466     (while (catch 'infloop
3467              (mapatoms
3468               (lambda (refs)
3469                 ;; Deal with self-referencing References loops.
3470                 (when (and (car (symbol-value refs))
3471                            (not (zerop
3472                                  (apply
3473                                   '+
3474                                   (mapcar
3475                                    (lambda (thread)
3476                                      (gnus-thread-loop-p
3477                                       (car (symbol-value refs)) thread))
3478                                    (cdr (symbol-value refs)))))))
3479                   (setq threads nil)
3480                   (throw 'infloop t))
3481                 (unless (car (symbol-value refs))
3482              ;; These threads do not refer back to any other articles,
3483                   ;; so they're roots.
3484                   (setq threads (append (cdr (symbol-value refs)) threads))))
3485               gnus-newsgroup-dependencies)))
3486     threads))
3487
3488 ;; Build the thread tree.
3489 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3490   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3491
3492 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3493 if it was already present.
3494
3495 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3496 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3497 Message-IDs will be renamed be renamed to a unique Message-ID before
3498 being entered.
3499
3500 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3501   (let* ((id (mail-header-id header))
3502          (id-dep (and id (intern id dependencies)))
3503          ref ref-dep ref-header)
3504     ;; Enter this `header' in the `dependencies' table.
3505     (cond
3506      ((not id-dep)
3507       (setq header nil))
3508      ;; The first two cases do the normal part: enter a new `header'
3509      ;; in the `dependencies' table.
3510      ((not (boundp id-dep))
3511       (set id-dep (list header)))
3512      ((null (car (symbol-value id-dep)))
3513       (setcar (symbol-value id-dep) header))
3514
3515      ;; From here the `header' was already present in the
3516      ;; `dependencies' table.
3517      (force-new
3518       ;; Overrides an existing entry;
3519       ;; just set the header part of the entry.
3520       (setcar (symbol-value id-dep) header))
3521
3522      ;; Renames the existing `header' to a unique Message-ID.
3523      ((not gnus-summary-ignore-duplicates)
3524       ;; An article with this Message-ID has already been seen.
3525       ;; We rename the Message-ID.
3526       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3527            (list header))
3528       (mail-header-set-id header id))
3529
3530      ;; The last case ignores an existing entry, except it adds any
3531      ;; additional Xrefs (in case the two articles came from different
3532      ;; servers.
3533      ;; Also sets `header' to `nil' meaning that the `dependencies'
3534      ;; table was *not* modified.
3535      (t
3536       (mail-header-set-xref
3537        (car (symbol-value id-dep))
3538        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3539                    "")
3540                (or (mail-header-xref header) "")))
3541       (setq header nil)))
3542
3543     (when header
3544       ;; First check if that we are not creating a References loop.
3545       (setq ref (gnus-parent-id (mail-header-references header)))
3546       (while (and ref
3547                   (setq ref-dep (intern-soft ref dependencies))
3548                   (boundp ref-dep)
3549                   (setq ref-header (car (symbol-value ref-dep))))
3550         (if (string= id ref)
3551             ;; Yuk!  This is a reference loop.  Make the article be a
3552             ;; root article.
3553             (progn
3554               (mail-header-set-references (car (symbol-value id-dep)) "none")
3555               (setq ref nil))
3556           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3557       (setq ref (gnus-parent-id (mail-header-references header)))
3558       (setq ref-dep (intern (or ref "none") dependencies))
3559       (if (boundp ref-dep)
3560           (setcdr (symbol-value ref-dep)
3561                   (nconc (cdr (symbol-value ref-dep))
3562                          (list (symbol-value id-dep))))
3563         (set ref-dep (list nil (symbol-value id-dep)))))
3564     header))
3565
3566 (defun gnus-build-sparse-threads ()
3567   (let ((headers gnus-newsgroup-headers)
3568         (mail-parse-charset gnus-newsgroup-charset)
3569         (gnus-summary-ignore-duplicates t)
3570         header references generation relations
3571         subject child end new-child date)
3572     ;; First we create an alist of generations/relations, where
3573     ;; generations is how much we trust the relation, and the relation
3574     ;; is parent/child.
3575     (gnus-message 7 "Making sparse threads...")
3576     (save-excursion
3577       (nnheader-set-temp-buffer " *gnus sparse threads*")
3578       (while (setq header (pop headers))
3579         (when (and (setq references (mail-header-references header))
3580                    (not (string= references "")))
3581           (insert references)
3582           (setq child (mail-header-id header)
3583                 subject (mail-header-subject header)
3584                 date (mail-header-date header)
3585                 generation 0)
3586           (while (search-backward ">" nil t)
3587             (setq end (1+ (point)))
3588             (when (search-backward "<" nil t)
3589               (setq new-child (buffer-substring (point) end))
3590               (push (list (incf generation)
3591                           child (setq child new-child)
3592                           subject date)
3593                     relations)))
3594           (when child
3595             (push (list (1+ generation) child nil subject) relations))
3596           (erase-buffer)))
3597       (kill-buffer (current-buffer)))
3598     ;; Sort over trustworthiness.
3599     (mapcar
3600      (lambda (relation)
3601        (when (gnus-dependencies-add-header
3602               (make-full-mail-header
3603                gnus-reffed-article-number
3604                (nth 3 relation) "" (or (nth 4 relation) "")
3605                (nth 1 relation)
3606                (or (nth 2 relation) "") 0 0 "")
3607               gnus-newsgroup-dependencies nil)
3608          (push gnus-reffed-article-number gnus-newsgroup-limit)
3609          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3610          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3611                gnus-newsgroup-reads)
3612          (decf gnus-reffed-article-number)))
3613      (sort relations 'car-less-than-car))
3614     (gnus-message 7 "Making sparse threads...done")))
3615
3616 (defun gnus-build-old-threads ()
3617   ;; Look at all the articles that refer back to old articles, and
3618   ;; fetch the headers for the articles that aren't there.  This will
3619   ;; build complete threads - if the roots haven't been expired by the
3620   ;; server, that is.
3621   (let ((mail-parse-charset gnus-newsgroup-charset)
3622         id heads)
3623     (mapatoms
3624      (lambda (refs)
3625        (when (not (car (symbol-value refs)))
3626          (setq heads (cdr (symbol-value refs)))
3627          (while heads
3628            (if (memq (mail-header-number (caar heads))
3629                      gnus-newsgroup-dormant)
3630                (setq heads (cdr heads))
3631              (setq id (symbol-name refs))
3632              (while (and (setq id (gnus-build-get-header id))
3633                          (not (car (gnus-id-to-thread id)))))
3634              (setq heads nil)))))
3635      gnus-newsgroup-dependencies)))
3636
3637 ;; This function has to be called with point after the article number
3638 ;; on the beginning of the line.
3639 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3640   (let ((eol (gnus-point-at-eol))
3641         (buffer (current-buffer))
3642         header)
3643
3644     ;; overview: [num subject from date id refs chars lines misc]
3645     (unwind-protect
3646         (progn
3647           (narrow-to-region (point) eol)
3648           (unless (eobp)
3649             (forward-char))
3650
3651           (setq header
3652                 (make-full-mail-header
3653                  number                 ; number
3654                  (funcall gnus-decode-encoded-word-function
3655                           (nnheader-nov-field)) ; subject
3656                  (funcall gnus-decode-encoded-word-function
3657                           (nnheader-nov-field)) ; from
3658                  (nnheader-nov-field)   ; date
3659                  (nnheader-nov-read-message-id) ; id
3660                  (nnheader-nov-field)   ; refs
3661                  (nnheader-nov-read-integer) ; chars
3662                  (nnheader-nov-read-integer) ; lines
3663                  (unless (eobp)
3664                    (if (looking-at "Xref: ")
3665                        (goto-char (match-end 0)))
3666                    (nnheader-nov-field)) ; Xref
3667                  (nnheader-nov-parse-extra)))) ; extra
3668
3669       (widen))
3670
3671     (when gnus-alter-header-function
3672       (funcall gnus-alter-header-function header))
3673     (gnus-dependencies-add-header header dependencies force-new)))
3674
3675 (defun gnus-build-get-header (id)
3676   "Look through the buffer of NOV lines and find the header to ID.
3677 Enter this line into the dependencies hash table, and return
3678 the id of the parent article (if any)."
3679   (let ((deps gnus-newsgroup-dependencies)
3680         found header)
3681     (prog1
3682         (save-excursion
3683           (set-buffer nntp-server-buffer)
3684           (let ((case-fold-search nil))
3685             (goto-char (point-min))
3686             (while (and (not found)
3687                         (search-forward id nil t))
3688               (beginning-of-line)
3689               (setq found (looking-at
3690                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3691                                    (regexp-quote id))))
3692               (or found (beginning-of-line 2)))
3693             (when found
3694               (beginning-of-line)
3695               (and
3696                (setq header (gnus-nov-parse-line
3697                              (read (current-buffer)) deps))
3698                (gnus-parent-id (mail-header-references header))))))
3699       (when header
3700         (let ((number (mail-header-number header)))
3701           (push number gnus-newsgroup-limit)
3702           (push header gnus-newsgroup-headers)
3703           (if (memq number gnus-newsgroup-unselected)
3704               (progn
3705                 (push number gnus-newsgroup-unreads)
3706                 (setq gnus-newsgroup-unselected
3707                       (delq number gnus-newsgroup-unselected)))
3708             (push number gnus-newsgroup-ancient)))))))
3709
3710 (defun gnus-build-all-threads ()
3711   "Read all the headers."
3712   (let ((gnus-summary-ignore-duplicates t)
3713         (mail-parse-charset gnus-newsgroup-charset)
3714         (dependencies gnus-newsgroup-dependencies)
3715         header article)
3716     (save-excursion
3717       (set-buffer nntp-server-buffer)
3718       (let ((case-fold-search nil))
3719         (goto-char (point-min))
3720         (while (not (eobp))
3721           (ignore-errors
3722             (setq article (read (current-buffer))
3723                   header (gnus-nov-parse-line article dependencies)))
3724           (when header
3725             (save-excursion
3726               (set-buffer gnus-summary-buffer)
3727               (push header gnus-newsgroup-headers)
3728               (if (memq (setq article (mail-header-number header))
3729                         gnus-newsgroup-unselected)
3730                   (progn
3731                     (push article gnus-newsgroup-unreads)
3732                     (setq gnus-newsgroup-unselected
3733                           (delq article gnus-newsgroup-unselected)))
3734                 (push article gnus-newsgroup-ancient)))
3735             (forward-line 1)))))))
3736
3737 (defun gnus-summary-update-article-line (article header)
3738   "Update the line for ARTICLE using HEADERS."
3739   (let* ((id (mail-header-id header))
3740          (thread (gnus-id-to-thread id)))
3741     (unless thread
3742       (error "Article in no thread"))
3743     ;; Update the thread.
3744     (setcar thread header)
3745     (gnus-summary-goto-subject article)
3746     (let* ((datal (gnus-data-find-list article))
3747            (data (car datal))
3748            (length (when (cdr datal)
3749                      (- (gnus-data-pos data)
3750                         (gnus-data-pos (cadr datal)))))
3751            (buffer-read-only nil)
3752            (level (gnus-summary-thread-level)))
3753       (gnus-delete-line)
3754       (gnus-summary-insert-line
3755        header level nil (gnus-article-mark article)
3756        (memq article gnus-newsgroup-replied)
3757        (memq article gnus-newsgroup-expirable)
3758        ;; Only insert the Subject string when it's different
3759        ;; from the previous Subject string.
3760        (if (and
3761             gnus-show-threads
3762             (gnus-subject-equal
3763              (condition-case ()
3764                  (mail-header-subject
3765                   (gnus-data-header
3766                    (cadr
3767                     (gnus-data-find-list
3768                      article
3769                      (gnus-data-list t)))))
3770                ;; Error on the side of excessive subjects.
3771                (error ""))
3772              (mail-header-subject header)))
3773            ""
3774          (mail-header-subject header))
3775        nil (cdr (assq article gnus-newsgroup-scored))
3776        (memq article gnus-newsgroup-processable))
3777       (when length
3778         (gnus-data-update-list
3779          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3780
3781 (defun gnus-summary-update-article (article &optional iheader)
3782   "Update ARTICLE in the summary buffer."
3783   (set-buffer gnus-summary-buffer)
3784   (let* ((header (gnus-summary-article-header article))
3785          (id (mail-header-id header))
3786          (data (gnus-data-find article))
3787          (thread (gnus-id-to-thread id))
3788          (references (mail-header-references header))
3789          (parent
3790           (gnus-id-to-thread
3791            (or (gnus-parent-id
3792                 (when (and references
3793                            (not (equal "" references)))
3794                   references))
3795                "none")))
3796          (buffer-read-only nil)
3797          (old (car thread)))
3798     (when thread
3799       (unless iheader
3800         (setcar thread nil)
3801         (when parent
3802           (delq thread parent)))
3803       (if (gnus-summary-insert-subject id header)
3804        ;; Set the (possibly) new article number in the data structure.
3805           (gnus-data-set-number data (gnus-id-to-article id))
3806         (setcar thread old)
3807         nil))))
3808
3809 (defun gnus-rebuild-thread (id &optional line)
3810   "Rebuild the thread containing ID.
3811 If LINE, insert the rebuilt thread starting on line LINE."
3812   (let ((buffer-read-only nil)
3813         old-pos current thread data)
3814     (if (not gnus-show-threads)
3815         (setq thread (list (car (gnus-id-to-thread id))))
3816       ;; Get the thread this article is part of.
3817       (setq thread (gnus-remove-thread id)))
3818     (setq old-pos (gnus-point-at-bol))
3819     (setq current (save-excursion
3820                     (and (re-search-backward "[\r\n]" nil t)
3821                          (gnus-summary-article-number))))
3822     ;; If this is a gathered thread, we have to go some re-gathering.
3823     (when (stringp (car thread))
3824       (let ((subject (car thread))
3825             roots thr)
3826         (setq thread (cdr thread))
3827         (while thread
3828           (unless (memq (setq thr (gnus-id-to-thread
3829                                    (gnus-root-id
3830                                     (mail-header-id (caar thread)))))
3831                         roots)
3832             (push thr roots))
3833           (setq thread (cdr thread)))
3834         ;; We now have all (unique) roots.
3835         (if (= (length roots) 1)
3836             ;; All the loose roots are now one solid root.
3837             (setq thread (car roots))
3838           (setq thread (cons subject (gnus-sort-threads roots))))))
3839     (let (threads)
3840       ;; We then insert this thread into the summary buffer.
3841       (when line
3842         (goto-char (point-min))
3843         (forward-line (1- line)))
3844       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3845         (if gnus-show-threads
3846             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3847           (gnus-summary-prepare-unthreaded thread))
3848         (setq data (nreverse gnus-newsgroup-data))
3849         (setq threads gnus-newsgroup-threads))
3850       ;; We splice the new data into the data structure.
3851       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3852       ;;!!! then we want to insert at the beginning of the buffer.
3853       ;;!!! That happens to be true with Gnus now, but that may
3854       ;;!!! change in the future.  Perhaps.
3855       (gnus-data-enter-list
3856        (if line nil current) data (- (point) old-pos))
3857       (setq gnus-newsgroup-threads
3858             (nconc threads gnus-newsgroup-threads))
3859       (gnus-data-compute-positions))))
3860
3861 (defun gnus-number-to-header (number)
3862   "Return the header for article NUMBER."
3863   (let ((headers gnus-newsgroup-headers))
3864     (while (and headers
3865                 (not (= number (mail-header-number (car headers)))))
3866       (pop headers))
3867     (when headers
3868       (car headers))))
3869
3870 (defun gnus-parent-headers (in-headers &optional generation)
3871   "Return the headers of the GENERATIONeth parent of HEADERS."
3872   (unless generation
3873     (setq generation 1))
3874   (let ((parent t)
3875         (headers in-headers)
3876         references)
3877     (while (and parent
3878                 (not (zerop generation))
3879                 (setq references (mail-header-references headers)))
3880       (setq headers (if (and references
3881                              (setq parent (gnus-parent-id references)))
3882                         (car (gnus-id-to-thread parent))
3883                       nil))
3884       (decf generation))
3885     (and (not (eq headers in-headers))
3886          headers)))
3887
3888 (defun gnus-id-to-thread (id)
3889   "Return the (sub-)thread where ID appears."
3890   (gnus-gethash id gnus-newsgroup-dependencies))
3891
3892 (defun gnus-id-to-article (id)
3893   "Return the article number of ID."
3894   (let ((thread (gnus-id-to-thread id)))
3895     (when (and thread
3896                (car thread))
3897       (mail-header-number (car thread)))))
3898
3899 (defun gnus-id-to-header (id)
3900   "Return the article headers of ID."
3901   (car (gnus-id-to-thread id)))
3902
3903 (defun gnus-article-displayed-root-p (article)
3904   "Say whether ARTICLE is a root(ish) article."
3905   (let ((level (gnus-summary-thread-level article))
3906         (refs (mail-header-references  (gnus-summary-article-header article)))
3907         particle)
3908     (cond
3909      ((null level) nil)
3910      ((zerop level) t)
3911      ((null refs) t)
3912      ((null (gnus-parent-id refs)) t)
3913      ((and (= 1 level)
3914            (null (setq particle (gnus-id-to-article
3915                                  (gnus-parent-id refs))))
3916            (null (gnus-summary-thread-level particle)))))))
3917
3918 (defun gnus-root-id (id)
3919   "Return the id of the root of the thread where ID appears."
3920   (let (last-id prev)
3921     (while (and id (setq prev (car (gnus-id-to-thread id))))
3922       (setq last-id id
3923             id (gnus-parent-id (mail-header-references prev))))
3924     last-id))
3925
3926 (defun gnus-articles-in-thread (thread)
3927   "Return the list of articles in THREAD."
3928   (cons (mail-header-number (car thread))
3929         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3930
3931 (defun gnus-remove-thread (id &optional dont-remove)
3932   "Remove the thread that has ID in it."
3933   (let (headers thread last-id)
3934     ;; First go up in this thread until we find the root.
3935     (setq last-id (gnus-root-id id)
3936           headers (message-flatten-list (gnus-id-to-thread last-id)))
3937     ;; We have now found the real root of this thread.  It might have
3938     ;; been gathered into some loose thread, so we have to search
3939     ;; through the threads to find the thread we wanted.
3940     (let ((threads gnus-newsgroup-threads)
3941           sub)
3942       (while threads
3943         (setq sub (car threads))
3944         (if (stringp (car sub))
3945             ;; This is a gathered thread, so we look at the roots
3946             ;; below it to find whether this article is in this
3947             ;; gathered root.
3948             (progn
3949               (setq sub (cdr sub))
3950               (while sub
3951                 (when (member (caar sub) headers)
3952                   (setq thread (car threads)
3953                         threads nil
3954                         sub nil))
3955                 (setq sub (cdr sub))))
3956           ;; It's an ordinary thread, so we check it.
3957           (when (eq (car sub) (car headers))
3958             (setq thread sub
3959                   threads nil)))
3960         (setq threads (cdr threads)))
3961       ;; If this article is in no thread, then it's a root.
3962       (if thread
3963           (unless dont-remove
3964             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3965         (setq thread (gnus-id-to-thread last-id)))
3966       (when thread
3967         (prog1
3968             thread                      ; We return this thread.
3969           (unless dont-remove
3970             (if (stringp (car thread))
3971                 (progn
3972                   ;; If we use dummy roots, then we have to remove the
3973                   ;; dummy root as well.
3974                   (when (eq gnus-summary-make-false-root 'dummy)
3975                     ;; We go to the dummy root by going to
3976                     ;; the first sub-"thread", and then one line up.
3977                     (gnus-summary-goto-article
3978                      (mail-header-number (caadr thread)))
3979                     (forward-line -1)
3980                     (gnus-delete-line)
3981                     (gnus-data-compute-positions))
3982                   (setq thread (cdr thread))
3983                   (while thread
3984                     (gnus-remove-thread-1 (car thread))
3985                     (setq thread (cdr thread))))
3986               (gnus-remove-thread-1 thread))))))))
3987
3988 (defun gnus-remove-thread-1 (thread)
3989   "Remove the thread THREAD recursively."
3990   (let ((number (mail-header-number (pop thread)))
3991         d)
3992     (setq thread (reverse thread))
3993     (while thread
3994       (gnus-remove-thread-1 (pop thread)))
3995     (when (setq d (gnus-data-find number))
3996       (goto-char (gnus-data-pos d))
3997       (gnus-summary-show-thread)
3998       (gnus-data-remove
3999        number
4000        (- (gnus-point-at-bol)
4001           (prog1
4002               (1+ (gnus-point-at-eol))
4003             (gnus-delete-line)))))))
4004
4005 (defun gnus-sort-threads-1 (threads func)
4006   (sort (mapcar (lambda (thread)
4007                   (cons (car thread)
4008                         (and (cdr thread)
4009                              (gnus-sort-threads-1 (cdr thread) func))))
4010                 threads) func))
4011
4012 (defun gnus-sort-threads (threads)
4013   "Sort THREADS."
4014   (if (not gnus-thread-sort-functions)
4015       threads
4016     (gnus-message 8 "Sorting threads...")
4017     (prog1
4018         (gnus-sort-threads-1
4019          threads
4020          (gnus-make-sort-function gnus-thread-sort-functions))
4021       (gnus-message 8 "Sorting threads...done"))))
4022
4023 (defun gnus-sort-articles (articles)
4024   "Sort ARTICLES."
4025   (when gnus-article-sort-functions
4026     (gnus-message 7 "Sorting articles...")
4027     (prog1
4028         (setq gnus-newsgroup-headers
4029               (sort articles (gnus-make-sort-function
4030                               gnus-article-sort-functions)))
4031       (gnus-message 7 "Sorting articles...done"))))
4032
4033 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4034 (defmacro gnus-thread-header (thread)
4035   "Return header of first article in THREAD.
4036 Note that THREAD must never, ever be anything else than a variable -
4037 using some other form will lead to serious barfage."
4038   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4039   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4040   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4041         (vector thread) 2))
4042
4043 (defsubst gnus-article-sort-by-number (h1 h2)
4044   "Sort articles by article number."
4045   (< (mail-header-number h1)
4046      (mail-header-number h2)))
4047
4048 (defun gnus-thread-sort-by-number (h1 h2)
4049   "Sort threads by root article number."
4050   (gnus-article-sort-by-number
4051    (gnus-thread-header h1) (gnus-thread-header h2)))
4052
4053 (defsubst gnus-article-sort-by-lines (h1 h2)
4054   "Sort articles by article Lines header."
4055   (< (mail-header-lines h1)
4056      (mail-header-lines h2)))
4057
4058 (defun gnus-thread-sort-by-lines (h1 h2)
4059   "Sort threads by root article Lines header."
4060   (gnus-article-sort-by-lines
4061    (gnus-thread-header h1) (gnus-thread-header h2)))
4062
4063 (defsubst gnus-article-sort-by-chars (h1 h2)
4064   "Sort articles by octet length."
4065   (< (mail-header-chars h1)
4066      (mail-header-chars h2)))
4067
4068 (defun gnus-thread-sort-by-chars (h1 h2)
4069   "Sort threads by root article octet length."
4070   (gnus-article-sort-by-chars
4071    (gnus-thread-header h1) (gnus-thread-header h2)))
4072
4073 (defsubst gnus-article-sort-by-author (h1 h2)
4074   "Sort articles by root author."
4075   (string-lessp
4076    (let ((extract (funcall
4077                    gnus-extract-address-components
4078                    (mail-header-from h1))))
4079      (or (car extract) (cadr extract) ""))
4080    (let ((extract (funcall
4081                    gnus-extract-address-components
4082                    (mail-header-from h2))))
4083      (or (car extract) (cadr extract) ""))))
4084
4085 (defun gnus-thread-sort-by-author (h1 h2)
4086   "Sort threads by root author."
4087   (gnus-article-sort-by-author
4088    (gnus-thread-header h1)  (gnus-thread-header h2)))
4089
4090 (defsubst gnus-article-sort-by-subject (h1 h2)
4091   "Sort articles by root subject."
4092   (string-lessp
4093    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4094    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4095
4096 (defun gnus-thread-sort-by-subject (h1 h2)
4097   "Sort threads by root subject."
4098   (gnus-article-sort-by-subject
4099    (gnus-thread-header h1) (gnus-thread-header h2)))
4100
4101 (defsubst gnus-article-sort-by-date (h1 h2)
4102   "Sort articles by root article date."
4103   (time-less-p
4104    (gnus-date-get-time (mail-header-date h1))
4105    (gnus-date-get-time (mail-header-date h2))))
4106
4107 (defun gnus-thread-sort-by-date (h1 h2)
4108   "Sort threads by root article date."
4109   (gnus-article-sort-by-date
4110    (gnus-thread-header h1) (gnus-thread-header h2)))
4111
4112 (defsubst gnus-article-sort-by-score (h1 h2)
4113   "Sort articles by root article score.
4114 Unscored articles will be counted as having a score of zero."
4115   (> (or (cdr (assq (mail-header-number h1)
4116                     gnus-newsgroup-scored))
4117          gnus-summary-default-score 0)
4118      (or (cdr (assq (mail-header-number h2)
4119                     gnus-newsgroup-scored))
4120          gnus-summary-default-score 0)))
4121
4122 (defun gnus-thread-sort-by-score (h1 h2)
4123   "Sort threads by root article score."
4124   (gnus-article-sort-by-score
4125    (gnus-thread-header h1) (gnus-thread-header h2)))
4126
4127 (defun gnus-thread-sort-by-total-score (h1 h2)
4128   "Sort threads by the sum of all scores in the thread.
4129 Unscored articles will be counted as having a score of zero."
4130   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4131
4132 (defun gnus-thread-total-score (thread)
4133   ;; This function find the total score of THREAD.
4134   (cond ((null thread)
4135          0)
4136         ((consp thread)
4137          (if (stringp (car thread))
4138              (apply gnus-thread-score-function 0
4139                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4140            (gnus-thread-total-score-1 thread)))
4141         (t
4142          (gnus-thread-total-score-1 (list thread)))))
4143
4144 (defun gnus-thread-total-score-1 (root)
4145   ;; This function find the total score of the thread below ROOT.
4146   (setq root (car root))
4147   (apply gnus-thread-score-function
4148          (or (append
4149               (mapcar 'gnus-thread-total-score
4150                       (cdr (gnus-id-to-thread (mail-header-id root))))
4151               (when (> (mail-header-number root) 0)
4152                 (list (or (cdr (assq (mail-header-number root)
4153                                      gnus-newsgroup-scored))
4154                           gnus-summary-default-score 0))))
4155              (list gnus-summary-default-score)
4156              '(0))))
4157
4158 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4159 (defvar gnus-tmp-prev-subject nil)
4160 (defvar gnus-tmp-false-parent nil)
4161 (defvar gnus-tmp-root-expunged nil)
4162 (defvar gnus-tmp-dummy-line nil)
4163
4164 (eval-when-compile (defvar gnus-tmp-header))
4165 (defun gnus-extra-header (type &optional header)
4166   "Return the extra header of TYPE."
4167   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4168       ""))
4169
4170 (defvar gnus-tmp-thread-tree-header-string "")
4171
4172 (defvar gnus-sum-thread-tree-root "> "
4173   "With %B spec, used for the root of a thread.
4174 If nil, use subject instead.")
4175 (defvar gnus-sum-thread-tree-single-indent ""
4176   "With %B spec, used for a thread with just one message.
4177 If nil, use subject instead.")
4178 (defvar gnus-sum-thread-tree-vertical "| "
4179   "With %B spec, used for drawing a vertical line.")
4180 (defvar gnus-sum-thread-tree-indent "  "
4181   "With %B spec, used for indenting.")
4182 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4183   "With %B spec, used for a leaf with brothers.")
4184 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4185   "With %B spec, used for a leaf without brothers.")
4186
4187 (defun gnus-summary-prepare-threads (threads)
4188   "Prepare summary buffer from THREADS and indentation LEVEL.
4189 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4190 or a straight list of headers."
4191   (gnus-message 7 "Generating summary...")
4192
4193   (setq gnus-newsgroup-threads threads)
4194   (beginning-of-line)
4195
4196   (let ((gnus-tmp-level 0)
4197         (default-score (or gnus-summary-default-score 0))
4198         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4199         thread number subject stack state gnus-tmp-gathered beg-match
4200         new-roots gnus-tmp-new-adopts thread-end
4201         gnus-tmp-header gnus-tmp-unread
4202         gnus-tmp-replied gnus-tmp-subject-or-nil
4203         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4204         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4205         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4206         tree-stack)
4207
4208     (setq gnus-tmp-prev-subject nil)
4209
4210     (if (vectorp (car threads))
4211         ;; If this is a straight (sic) list of headers, then a
4212         ;; threaded summary display isn't required, so we just create
4213         ;; an unthreaded one.
4214         (gnus-summary-prepare-unthreaded threads)
4215
4216       ;; Do the threaded display.
4217
4218       (while (or threads stack gnus-tmp-new-adopts new-roots)
4219
4220         (if (and (= gnus-tmp-level 0)
4221                  (or (not stack)
4222                      (= (caar stack) 0))
4223                  (not gnus-tmp-false-parent)
4224                  (or gnus-tmp-new-adopts new-roots))
4225             (if gnus-tmp-new-adopts
4226                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4227                       thread (list (car gnus-tmp-new-adopts))
4228                       gnus-tmp-header (caar thread)
4229                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4230               (when new-roots
4231                 (setq thread (list (car new-roots))
4232                       gnus-tmp-header (caar thread)
4233                       new-roots (cdr new-roots))))
4234
4235           (if threads
4236               ;; If there are some threads, we do them before the
4237               ;; threads on the stack.
4238               (setq thread threads
4239                     gnus-tmp-header (caar thread))
4240             ;; There were no current threads, so we pop something off
4241             ;; the stack.
4242             (setq state (car stack)
4243                   gnus-tmp-level (car state)
4244                   tree-stack (cadr state)
4245                   thread (caddr state)
4246                   stack (cdr stack)
4247                   gnus-tmp-header (caar thread))))
4248
4249         (setq gnus-tmp-false-parent nil)
4250         (setq gnus-tmp-root-expunged nil)
4251         (setq thread-end nil)
4252
4253         (if (stringp gnus-tmp-header)
4254             ;; The header is a dummy root.
4255             (cond
4256              ((eq gnus-summary-make-false-root 'adopt)
4257               ;; We let the first article adopt the rest.
4258               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4259                                                (cddar thread)))
4260               (setq gnus-tmp-gathered
4261                     (nconc (mapcar
4262                             (lambda (h) (mail-header-number (car h)))
4263                             (cddar thread))
4264                            gnus-tmp-gathered))
4265               (setq thread (cons (list (caar thread)
4266                                        (cadar thread))
4267                                  (cdr thread)))
4268               (setq gnus-tmp-level -1
4269                     gnus-tmp-false-parent t))
4270              ((eq gnus-summary-make-false-root 'empty)
4271               ;; We print adopted articles with empty subject fields.
4272               (setq gnus-tmp-gathered
4273                     (nconc (mapcar
4274                             (lambda (h) (mail-header-number (car h)))
4275                             (cddar thread))
4276                            gnus-tmp-gathered))
4277               (setq gnus-tmp-level -1))
4278              ((eq gnus-summary-make-false-root 'dummy)
4279               ;; We remember that we probably want to output a dummy
4280               ;; root.
4281               (setq gnus-tmp-dummy-line gnus-tmp-header)
4282               (setq gnus-tmp-prev-subject gnus-tmp-header))
4283              (t
4284               ;; We do not make a root for the gathered
4285               ;; sub-threads at all.
4286               (setq gnus-tmp-level -1)))
4287
4288           (setq number (mail-header-number gnus-tmp-header)
4289                 subject (mail-header-subject gnus-tmp-header))
4290
4291           (cond
4292            ;; If the thread has changed subject, we might want to make
4293            ;; this subthread into a root.
4294            ((and (null gnus-thread-ignore-subject)
4295                  (not (zerop gnus-tmp-level))
4296                  gnus-tmp-prev-subject
4297                  (not (inline
4298                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4299             (setq new-roots (nconc new-roots (list (car thread)))
4300                   thread-end t
4301                   gnus-tmp-header nil))
4302            ;; If the article lies outside the current limit,
4303            ;; then we do not display it.
4304            ((not (memq number gnus-newsgroup-limit))
4305             (setq gnus-tmp-gathered
4306                   (nconc (mapcar
4307                           (lambda (h) (mail-header-number (car h)))
4308                           (cdar thread))
4309                          gnus-tmp-gathered))
4310             (setq gnus-tmp-new-adopts (if (cdar thread)
4311                                           (append gnus-tmp-new-adopts
4312                                                   (cdar thread))
4313                                         gnus-tmp-new-adopts)
4314                   thread-end t
4315                   gnus-tmp-header nil)
4316             (when (zerop gnus-tmp-level)
4317               (setq gnus-tmp-root-expunged t)))
4318            ;; Perhaps this article is to be marked as read?
4319            ((and gnus-summary-mark-below
4320                  (< (or (cdr (assq number gnus-newsgroup-scored))
4321                         default-score)
4322                     gnus-summary-mark-below)
4323                  ;; Don't touch sparse articles.
4324                  (not (gnus-summary-article-sparse-p number))
4325                  (not (gnus-summary-article-ancient-p number)))
4326             (setq gnus-newsgroup-unreads
4327                   (delq number gnus-newsgroup-unreads))
4328             (if gnus-newsgroup-auto-expire
4329                 (push number gnus-newsgroup-expirable)
4330               (push (cons number gnus-low-score-mark)
4331                     gnus-newsgroup-reads))))
4332
4333           (when gnus-tmp-header
4334             ;; We may have an old dummy line to output before this
4335             ;; article.
4336             (when (and gnus-tmp-dummy-line
4337                        (gnus-subject-equal
4338                         gnus-tmp-dummy-line
4339                         (mail-header-subject gnus-tmp-header)))
4340               (gnus-summary-insert-dummy-line
4341                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4342               (setq gnus-tmp-dummy-line nil))
4343
4344             ;; Compute the mark.
4345             (setq gnus-tmp-unread (gnus-article-mark number))
4346
4347             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4348                                   gnus-tmp-header gnus-tmp-level)
4349                   gnus-newsgroup-data)
4350
4351             ;; Actually insert the line.
4352             (setq
4353              gnus-tmp-subject-or-nil
4354              (cond
4355               ((and gnus-thread-ignore-subject
4356                     gnus-tmp-prev-subject
4357                     (not (inline (gnus-subject-equal
4358                                   gnus-tmp-prev-subject subject))))
4359                subject)
4360               ((zerop gnus-tmp-level)
4361                (if (and (eq gnus-summary-make-false-root 'empty)
4362                         (memq number gnus-tmp-gathered)
4363                         gnus-tmp-prev-subject
4364                         (inline (gnus-subject-equal
4365                                  gnus-tmp-prev-subject subject)))
4366                    gnus-summary-same-subject
4367                  subject))
4368               (t gnus-summary-same-subject)))
4369             (if (and (eq gnus-summary-make-false-root 'adopt)
4370                      (= gnus-tmp-level 1)
4371                      (memq number gnus-tmp-gathered))
4372                 (setq gnus-tmp-opening-bracket ?\<
4373                       gnus-tmp-closing-bracket ?\>)
4374               (setq gnus-tmp-opening-bracket ?\[
4375                     gnus-tmp-closing-bracket ?\]))
4376             (setq
4377              gnus-tmp-indentation
4378              (aref gnus-thread-indent-array gnus-tmp-level)
4379              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4380              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4381                                 gnus-summary-default-score 0)
4382              gnus-tmp-score-char
4383              (if (or (null gnus-summary-default-score)
4384                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4385                          gnus-summary-zcore-fuzz))
4386                  ?                      ;Whitespace
4387                (if (< gnus-tmp-score gnus-summary-default-score)
4388                    gnus-score-below-mark gnus-score-over-mark))
4389              gnus-tmp-replied
4390              (cond ((memq number gnus-newsgroup-processable)
4391                     gnus-process-mark)
4392                    ((memq number gnus-newsgroup-cached)
4393                     gnus-cached-mark)
4394                    ((memq number gnus-newsgroup-replied)
4395                     gnus-replied-mark)
4396                    ((memq number gnus-newsgroup-forwarded)
4397                     gnus-forwarded-mark)
4398                    ((memq number gnus-newsgroup-saved)
4399                     gnus-saved-mark)
4400                    ((memq number gnus-newsgroup-recent)
4401                     gnus-recent-mark)
4402                    ((memq number gnus-newsgroup-unseen)
4403                     gnus-unseen-mark)
4404                    (t gnus-no-mark))
4405              gnus-tmp-from (mail-header-from gnus-tmp-header)
4406              gnus-tmp-name
4407              (cond
4408               ((string-match "<[^>]+> *$" gnus-tmp-from)
4409                (setq beg-match (match-beginning 0))
4410                (or (and (string-match "^\".+\"" gnus-tmp-from)
4411                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4412                    (substring gnus-tmp-from 0 beg-match)))
4413               ((string-match "(.+)" gnus-tmp-from)
4414                (substring gnus-tmp-from
4415                           (1+ (match-beginning 0)) (1- (match-end 0))))
4416               (t gnus-tmp-from))
4417              gnus-tmp-thread-tree-header-string
4418              (cond
4419               ((not gnus-show-threads) "")
4420               ((zerop gnus-tmp-level)
4421                (if (cdar thread)
4422                    (or gnus-sum-thread-tree-root subject)
4423                  (or gnus-sum-thread-tree-single-indent subject)))
4424               (t
4425                (concat (apply 'concat
4426                               (mapcar (lambda (item)
4427                                         (if (= item 1)
4428                                             gnus-sum-thread-tree-vertical
4429                                           gnus-sum-thread-tree-indent))
4430                                       (cdr (reverse tree-stack))))
4431                        (if (nth 1 thread)
4432                            gnus-sum-thread-tree-leaf-with-other
4433                          gnus-sum-thread-tree-single-leaf)))))
4434             (when (string= gnus-tmp-name "")
4435               (setq gnus-tmp-name gnus-tmp-from))
4436             (unless (numberp gnus-tmp-lines)
4437               (setq gnus-tmp-lines -1))
4438             (if (= gnus-tmp-lines -1)
4439                 (setq gnus-tmp-lines "?")
4440               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4441             (gnus-put-text-property
4442              (point)
4443              (progn (eval gnus-summary-line-format-spec) (point))
4444              'gnus-number number)
4445             (when gnus-visual-p
4446               (forward-line -1)
4447               (gnus-run-hooks 'gnus-summary-update-hook)
4448               (forward-line 1))
4449
4450             (setq gnus-tmp-prev-subject subject)))
4451
4452         (when (nth 1 thread)
4453           (push (list (max 0 gnus-tmp-level)
4454                       (copy-list tree-stack)
4455                       (nthcdr 1 thread))
4456                 stack))
4457         (push (if (nth 1 thread) 1 0) tree-stack)
4458         (incf gnus-tmp-level)
4459         (setq threads (if thread-end nil (cdar thread)))
4460         (unless threads
4461           (setq gnus-tmp-level 0)))))
4462   (gnus-message 7 "Generating summary...done"))
4463
4464 (defun gnus-summary-prepare-unthreaded (headers)
4465   "Generate an unthreaded summary buffer based on HEADERS."
4466   (let (header number mark)
4467
4468     (beginning-of-line)
4469
4470     (while headers
4471       ;; We may have to root out some bad articles...
4472       (when (memq (setq number (mail-header-number
4473                                 (setq header (pop headers))))
4474                   gnus-newsgroup-limit)
4475         ;; Mark article as read when it has a low score.
4476         (when (and gnus-summary-mark-below
4477                    (< (or (cdr (assq number gnus-newsgroup-scored))
4478                           gnus-summary-default-score 0)
4479                       gnus-summary-mark-below)
4480                    (not (gnus-summary-article-ancient-p number)))
4481           (setq gnus-newsgroup-unreads
4482                 (delq number gnus-newsgroup-unreads))
4483           (if gnus-newsgroup-auto-expire
4484               (push number gnus-newsgroup-expirable)
4485             (push (cons number gnus-low-score-mark)
4486                   gnus-newsgroup-reads)))
4487
4488         (setq mark (gnus-article-mark number))
4489         (push (gnus-data-make number mark (1+ (point)) header 0)
4490               gnus-newsgroup-data)
4491         (gnus-summary-insert-line
4492          header 0 number
4493          mark (memq number gnus-newsgroup-replied)
4494          (memq number gnus-newsgroup-expirable)
4495          (mail-header-subject header) nil
4496          (cdr (assq number gnus-newsgroup-scored))
4497          (memq number gnus-newsgroup-processable))))))
4498
4499 (defun gnus-summary-remove-list-identifiers ()
4500   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4501   (let ((regexp (if (consp gnus-list-identifiers)
4502                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4503                   gnus-list-identifiers))
4504         changed subject)
4505     (when regexp
4506       (dolist (header gnus-newsgroup-headers)
4507         (setq subject (mail-header-subject header)
4508               changed nil)
4509         (while (string-match
4510                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4511                 subject)
4512           (setq subject
4513                 (concat (substring subject 0 (match-beginning 2))
4514                         (substring subject (match-end 0)))
4515                 changed t))
4516         (when (and changed
4517                    (string-match
4518                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4519           (setq subject
4520                 (concat (substring subject 0 (match-beginning 1))
4521                         (substring subject (match-end 1)))))
4522         (when changed
4523           (mail-header-set-subject header subject))))))
4524
4525 (defun gnus-fetch-headers (articles)
4526   "Fetch headers of ARTICLES."
4527   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4528     (gnus-message 5 "Fetching headers for %s..." name)
4529     (prog1
4530         (if (eq 'nov
4531                 (setq gnus-headers-retrieved-by
4532                       (gnus-retrieve-headers
4533                        articles gnus-newsgroup-name
4534                        ;; We might want to fetch old headers, but
4535                        ;; not if there is only 1 article.
4536                        (and (or (and
4537                                  (not (eq gnus-fetch-old-headers 'some))
4538                                  (not (numberp gnus-fetch-old-headers)))
4539                                 (> (length articles) 1))
4540                             gnus-fetch-old-headers))))
4541             (gnus-get-newsgroup-headers-xover
4542              articles nil nil gnus-newsgroup-name t)
4543           (gnus-get-newsgroup-headers))
4544       (gnus-message 5 "Fetching headers for %s...done" name))))
4545
4546 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4547   "Select newsgroup GROUP.
4548 If READ-ALL is non-nil, all articles in the group are selected.
4549 If SELECT-ARTICLES, only select those articles from GROUP."
4550   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4551          ;;!!! Dirty hack; should be removed.
4552          (gnus-summary-ignore-duplicates
4553           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4554               t
4555             gnus-summary-ignore-duplicates))
4556          (info (nth 2 entry))
4557          articles fetched-articles cached)
4558
4559     (unless (gnus-check-server
4560              (set (make-local-variable 'gnus-current-select-method)
4561                   (gnus-find-method-for-group group)))
4562       (error "Couldn't open server"))
4563
4564     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4565         (gnus-activate-group group)     ; Or we can activate it...
4566         (progn                          ; Or we bug out.
4567           (when (equal major-mode 'gnus-summary-mode)
4568             (kill-buffer (current-buffer)))
4569           (error "Couldn't activate group %s: %s"
4570                  group (gnus-status-message group))))
4571
4572     (unless (gnus-request-group group t)
4573       (when (equal major-mode 'gnus-summary-mode)
4574         (kill-buffer (current-buffer)))
4575       (error "Couldn't request group %s: %s"
4576              group (gnus-status-message group)))
4577
4578     (setq gnus-newsgroup-name group
4579           gnus-newsgroup-unselected nil
4580           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4581
4582     (let ((display (gnus-group-find-parameter group 'display)))
4583       (setq gnus-newsgroup-display
4584             (cond
4585              ((not (zerop (or (car-safe read-all) 0)))
4586               ;; The user entered the group with C-u SPC/RET, let's show
4587               ;; all articles.
4588               'gnus-not-ignore)
4589              ((eq display 'all)
4590               'gnus-not-ignore)
4591              ((arrayp display)
4592               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4593              ((numberp display)
4594               ;; The following is probably the "correct" solution, but
4595               ;; it makes Gnus fetch all headers and then limit the
4596               ;; articles (which is slow), so instead we hack the
4597               ;; select-articles parameter instead. -- Simon Josefsson
4598               ;; <jas@kth.se>
4599               ;;
4600               ;; (gnus-byte-compile
4601               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4602               ;;                         display)))))
4603               (setq select-articles
4604                     (gnus-uncompress-range
4605                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4606                              (if (> tmp 0)
4607                                  tmp
4608                                1))
4609                            (cdr (gnus-active group)))))
4610               nil)
4611              (t
4612               nil))))
4613
4614     (gnus-summary-setup-default-charset)
4615
4616     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4617     (when (gnus-virtual-group-p group)
4618       (setq cached gnus-newsgroup-cached))
4619
4620     (setq gnus-newsgroup-unreads
4621           (gnus-set-difference
4622            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4623            gnus-newsgroup-dormant))
4624
4625     (setq gnus-newsgroup-processable nil)
4626
4627     (gnus-update-read-articles group gnus-newsgroup-unreads)
4628
4629     ;; Adjust and set lists of article marks.
4630     (when info
4631       (gnus-adjust-marked-articles info))
4632
4633     (if (setq articles select-articles)
4634         (setq gnus-newsgroup-unselected
4635               (gnus-sorted-intersection
4636                gnus-newsgroup-unreads
4637                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4638       (setq articles (gnus-articles-to-read group read-all)))
4639
4640     (cond
4641      ((null articles)
4642       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4643       'quit)
4644      ((eq articles 0) nil)
4645      (t
4646       ;; Init the dependencies hash table.
4647       (setq gnus-newsgroup-dependencies
4648             (gnus-make-hashtable (length articles)))
4649       (gnus-set-global-variables)
4650       ;; Retrieve the headers and read them in.
4651       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4652
4653       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4654       (when cached
4655         (setq gnus-newsgroup-cached cached))
4656
4657       ;; Suppress duplicates?
4658       (when gnus-suppress-duplicates
4659         (gnus-dup-suppress-articles))
4660
4661       ;; Set the initial limit.
4662       (setq gnus-newsgroup-limit (copy-sequence articles))
4663       ;; Remove canceled articles from the list of unread articles.
4664       (setq fetched-articles
4665             (mapcar (lambda (headers) (mail-header-number headers))
4666                     gnus-newsgroup-headers))
4667       (setq gnus-newsgroup-articles fetched-articles)
4668       (setq gnus-newsgroup-unreads
4669             (gnus-set-sorted-intersection
4670              gnus-newsgroup-unreads fetched-articles))
4671
4672       ;; The `seen' marks are treated specially.
4673       (if (not gnus-newsgroup-seen)
4674           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4675         (dolist (article gnus-newsgroup-articles)
4676           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4677             (push article gnus-newsgroup-unseen)))
4678         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4679
4680       ;; Removed marked articles that do not exist.
4681       (gnus-update-missing-marks
4682        (gnus-sorted-complement fetched-articles articles))
4683       ;; We might want to build some more threads first.
4684       (when (and gnus-fetch-old-headers
4685                  (eq gnus-headers-retrieved-by 'nov))
4686         (if (eq gnus-fetch-old-headers 'invisible)
4687             (gnus-build-all-threads)
4688           (gnus-build-old-threads)))
4689       ;; Let the Gnus agent mark articles as read.
4690       (when gnus-agent
4691         (gnus-agent-get-undownloaded-list))
4692       ;; Remove list identifiers from subject
4693       (when gnus-list-identifiers
4694         (gnus-summary-remove-list-identifiers))
4695       ;; Check whether auto-expire is to be done in this group.
4696       (setq gnus-newsgroup-auto-expire
4697             (gnus-group-auto-expirable-p group))
4698       ;; Set up the article buffer now, if necessary.
4699       (unless gnus-single-article-buffer
4700         (gnus-article-setup-buffer))
4701       ;; First and last article in this newsgroup.
4702       (when gnus-newsgroup-headers
4703         (setq gnus-newsgroup-begin
4704               (mail-header-number (car gnus-newsgroup-headers))
4705               gnus-newsgroup-end
4706               (mail-header-number
4707                (gnus-last-element gnus-newsgroup-headers))))
4708       ;; GROUP is successfully selected.
4709       (or gnus-newsgroup-headers t)))))
4710
4711 (defun gnus-summary-display-make-predicate (display)
4712   (require 'gnus-agent)
4713   (when (= (length display) 1)
4714     (setq display (car display)))
4715   (unless gnus-summary-display-cache
4716     (dolist (elem (append (list (cons 'read 'read)
4717                                 (cons 'unseen 'unseen))
4718                           gnus-article-mark-lists))
4719       (push (cons (cdr elem)
4720                   (gnus-byte-compile
4721                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4722             gnus-summary-display-cache)))
4723   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4724     (gnus-get-predicate display)))
4725
4726 ;; Uses the dynamically bound `number' variable.
4727 (defvar number)
4728 (defun gnus-article-marked-p (type &optional article)
4729   (let ((article (or article number)))
4730     (cond
4731      ((eq type 'tick)
4732       (memq article gnus-newsgroup-marked))
4733      ((eq type 'unsend)
4734       (memq article gnus-newsgroup-unsendable))
4735      ((eq type 'undownload)
4736       (memq article gnus-newsgroup-undownloaded))
4737      ((eq type 'download)
4738       (memq article gnus-newsgroup-downloadable))
4739      ((eq type 'unread)
4740       (memq article gnus-newsgroup-unreads))
4741      ((eq type 'read)
4742       (memq article gnus-newsgroup-reads))
4743      ((eq type 'dormant)
4744       (memq article gnus-newsgroup-dormant) )
4745      ((eq type 'expire)
4746       (memq article gnus-newsgroup-expirable))
4747      ((eq type 'reply)
4748       (memq article gnus-newsgroup-replied))
4749      ((eq type 'killed)
4750       (memq article gnus-newsgroup-killed))
4751      ((eq type 'bookmark)
4752       (assq article gnus-newsgroup-bookmarks))
4753      ((eq type 'score)
4754       (assq article gnus-newsgroup-scored))
4755      ((eq type 'save)
4756       (memq article gnus-newsgroup-saved))
4757      ((eq type 'cache)
4758       (memq article gnus-newsgroup-cached))
4759      ((eq type 'forward)
4760       (memq article gnus-newsgroup-forwarded))
4761      ((eq type 'seen)
4762       (not (memq article gnus-newsgroup-unseen)))
4763      ((eq type 'recent)
4764       (memq article gnus-newsgroup-recent))
4765      (t t))))
4766
4767 (defun gnus-articles-to-read (group &optional read-all)
4768   "Find out what articles the user wants to read."
4769   (let* ((articles
4770           ;; Select all articles if `read-all' is non-nil, or if there
4771           ;; are no unread articles.
4772           (if (or read-all
4773                   (and (zerop (length gnus-newsgroup-marked))
4774                        (zerop (length gnus-newsgroup-unreads)))
4775                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4776               ;; We want to select the headers for all the articles in
4777               ;; the group, so we select either all the active
4778               ;; articles in the group, or (if that's nil), the
4779               ;; articles in the cache.
4780               (or
4781                (gnus-uncompress-range (gnus-active group))
4782                (gnus-cache-articles-in-group group))
4783             ;; Select only the "normal" subset of articles.
4784             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4785                           (copy-sequence gnus-newsgroup-unreads))
4786                   '<)))
4787          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4788          (scored (length scored-list))
4789          (number (length articles))
4790          (marked (+ (length gnus-newsgroup-marked)
4791                     (length gnus-newsgroup-dormant)))
4792          (select
4793           (cond
4794            ((numberp read-all)
4795             read-all)
4796            (t
4797             (condition-case ()
4798                 (cond
4799                  ((and (or (<= scored marked) (= scored number))
4800                        (numberp gnus-large-newsgroup)
4801                        (> number gnus-large-newsgroup))
4802                   (let ((input
4803                          (read-string
4804                           (format
4805                            "How many articles from %s (default %d): "
4806                            (gnus-limit-string
4807                             (gnus-group-decoded-name gnus-newsgroup-name)
4808                             35)
4809                            number))))
4810                     (if (string-match "^[ \t]*$" input) number input)))
4811                  ((and (> scored marked) (< scored number)
4812                        (> (- scored number) 20))
4813                   (let ((input
4814                          (read-string
4815                           (format "%s %s (%d scored, %d total): "
4816                                   "How many articles from"
4817                                   (gnus-group-decoded-name group)
4818                                   scored number))))
4819                     (if (string-match "^[ \t]*$" input)
4820                         number input)))
4821                  (t number))
4822               (quit
4823                (message "Quit getting the articles to read")
4824                nil))))))
4825     (setq select (if (stringp select) (string-to-number select) select))
4826     (if (or (null select) (zerop select))
4827         select
4828       (if (and (not (zerop scored)) (<= (abs select) scored))
4829           (progn
4830             (setq articles (sort scored-list '<))
4831             (setq number (length articles)))
4832         (setq articles (copy-sequence articles)))
4833
4834       (when (< (abs select) number)
4835         (if (< select 0)
4836             ;; Select the N oldest articles.
4837             (setcdr (nthcdr (1- (abs select)) articles) nil)
4838           ;; Select the N most recent articles.
4839           (setq articles (nthcdr (- number select) articles))))
4840       (setq gnus-newsgroup-unselected
4841             (gnus-sorted-intersection
4842              gnus-newsgroup-unreads
4843              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4844       (when gnus-alter-articles-to-read-function
4845         (setq gnus-newsgroup-unreads
4846               (sort
4847                (funcall gnus-alter-articles-to-read-function
4848                         gnus-newsgroup-name gnus-newsgroup-unreads)
4849                '<)))
4850       articles)))
4851
4852 (defun gnus-killed-articles (killed articles)
4853   (let (out)
4854     (while articles
4855       (when (inline (gnus-member-of-range (car articles) killed))
4856         (push (car articles) out))
4857       (setq articles (cdr articles)))
4858     out))
4859
4860 (defun gnus-uncompress-marks (marks)
4861   "Uncompress the mark ranges in MARKS."
4862   (let ((uncompressed '(score bookmark))
4863         out)
4864     (while marks
4865       (if (memq (caar marks) uncompressed)
4866           (push (car marks) out)
4867         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4868       (setq marks (cdr marks)))
4869     out))
4870
4871 (defun gnus-article-mark-to-type (mark)
4872   "Return the type of MARK."
4873   (or (cadr (assq mark gnus-article-special-mark-lists))
4874       'list))
4875
4876 (defun gnus-article-unpropagatable-p (mark)
4877   "Return whether MARK should be propagated to backend."
4878   (memq mark gnus-article-unpropagated-mark-lists))
4879
4880 (defun gnus-adjust-marked-articles (info)
4881   "Set all article lists and remove all marks that are no longer valid."
4882   (let* ((marked-lists (gnus-info-marks info))
4883          (active (gnus-active (gnus-info-group info)))
4884          (min (car active))
4885          (max (cdr active))
4886          (types gnus-article-mark-lists)
4887          marks var articles article mark mark-type)
4888
4889     (dolist (marks marked-lists)
4890       (setq mark (car marks)
4891             mark-type (gnus-article-mark-to-type mark)
4892             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4893
4894       ;; We set the variable according to the type of the marks list,
4895       ;; and then adjust the marks to a subset of the active articles.
4896       (cond
4897        ;; Adjust "simple" lists.
4898        ((eq mark-type 'list)
4899         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4900         (when (memq mark '(tick dormant expire reply save))
4901           (while articles
4902             (when (or (< (setq article (pop articles)) min) (> article max))
4903               (set var (delq article (symbol-value var)))))))
4904        ;; Adjust assocs.
4905        ((eq mark-type 'tuple)
4906         (set var (setq articles (cdr marks)))
4907         (when (not (listp (cdr (symbol-value var))))
4908           (set var (list (symbol-value var))))
4909         (when (not (listp (cdr articles)))
4910           (setq articles (list articles)))
4911         (while articles
4912           (when (or (not (consp (setq article (pop articles))))
4913                     (< (car article) min)
4914                     (> (car article) max))
4915             (set var (delq article (symbol-value var))))))
4916        ;; Adjust ranges (sloppily).
4917        ((eq mark-type 'range)
4918         (cond
4919          ((eq mark 'seen)
4920           (setq articles (cdr marks))
4921           (while (and articles
4922                       (or (and (consp (car articles))
4923                                (> min (cdar articles)))
4924                           (and (numberp (car articles))
4925                                (> min (car articles)))))
4926             (pop articles))
4927           (set var articles))))))))
4928
4929 (defun gnus-update-missing-marks (missing)
4930   "Go through the list of MISSING articles and remove them from the mark lists."
4931   (when missing
4932     (let (var m)
4933       ;; Go through all types.
4934       (dolist (elem gnus-article-mark-lists)
4935         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4936           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4937           (when (symbol-value var)
4938             ;; This list has articles.  So we delete all missing
4939             ;; articles from it.
4940             (setq m missing)
4941             (while m
4942               (set var (delq (pop m) (symbol-value var))))))))))
4943
4944 (defun gnus-update-marks ()
4945   "Enter the various lists of marked articles into the newsgroup info list."
4946   (let ((types gnus-article-mark-lists)
4947         (info (gnus-get-info gnus-newsgroup-name))
4948         type list newmarked symbol delta-marks)
4949     (when info
4950       ;; Add all marks lists to the list of marks lists.
4951       (while (setq type (pop types))
4952         (setq list (symbol-value
4953                     (setq symbol
4954                           (intern (format "gnus-newsgroup-%s" (car type))))))
4955
4956         (when list
4957           ;; Get rid of the entries of the articles that have the
4958           ;; default score.
4959           (when (and (eq (cdr type) 'score)
4960                      gnus-save-score
4961                      list)
4962             (let* ((arts list)
4963                    (prev (cons nil list))
4964                    (all prev))
4965               (while arts
4966                 (if (or (not (consp (car arts)))
4967                         (= (cdar arts) gnus-summary-default-score))
4968                     (setcdr prev (cdr arts))
4969                   (setq prev arts))
4970                 (setq arts (cdr arts)))
4971               (setq list (cdr all)))))
4972
4973         (when (eq (cdr type) 'seen)
4974           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
4975
4976         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4977           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4978
4979         (when (and (gnus-check-backend-function
4980                     'request-set-mark gnus-newsgroup-name)
4981                    (not (gnus-article-unpropagatable-p (cdr type))))
4982           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4983                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4984                  (add (gnus-remove-from-range
4985                        (gnus-copy-sequence list) old)))
4986             (when add
4987               (push (list add 'add (list (cdr type))) delta-marks))
4988             (when del
4989               (push (list del 'del (list (cdr type))) delta-marks))))
4990
4991         (when list
4992           (push (cons (cdr type) list) newmarked)))
4993
4994       (when delta-marks
4995         (unless (gnus-check-group gnus-newsgroup-name)
4996           (error "Can't open server for %s" gnus-newsgroup-name))
4997         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4998
4999       ;; Enter these new marks into the info of the group.
5000       (if (nthcdr 3 info)
5001           (setcar (nthcdr 3 info) newmarked)
5002         ;; Add the marks lists to the end of the info.
5003         (when newmarked
5004           (setcdr (nthcdr 2 info) (list newmarked))))
5005
5006       ;; Cut off the end of the info if there's nothing else there.
5007       (let ((i 5))
5008         (while (and (> i 2)
5009                     (not (nth i info)))
5010           (when (nthcdr (decf i) info)
5011             (setcdr (nthcdr i info) nil)))))))
5012
5013 (defun gnus-set-mode-line (where)
5014   "Set the mode line of the article or summary buffers.
5015 If WHERE is `summary', the summary mode line format will be used."
5016   ;; Is this mode line one we keep updated?
5017   (when (and (memq where gnus-updated-mode-lines)
5018              (symbol-value
5019               (intern (format "gnus-%s-mode-line-format-spec" where))))
5020     (let (mode-string)
5021       (save-excursion
5022         ;; We evaluate this in the summary buffer since these
5023         ;; variables are buffer-local to that buffer.
5024         (set-buffer gnus-summary-buffer)
5025        ;; We bind all these variables that are used in the `eval' form
5026         ;; below.
5027         (let* ((mformat (symbol-value
5028                          (intern
5029                           (format "gnus-%s-mode-line-format-spec" where))))
5030                (gnus-tmp-group-name (gnus-group-decoded-name
5031                                      gnus-newsgroup-name))
5032                (gnus-tmp-article-number (or gnus-current-article 0))
5033                (gnus-tmp-unread gnus-newsgroup-unreads)
5034                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5035                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5036                (gnus-tmp-unread-and-unselected
5037                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5038                             (zerop gnus-tmp-unselected))
5039                        "")
5040                       ((zerop gnus-tmp-unselected)
5041                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5042                       (t (format "{%d(+%d) more}"
5043                                  gnus-tmp-unread-and-unticked
5044                                  gnus-tmp-unselected))))
5045                (gnus-tmp-subject
5046                 (if (and gnus-current-headers
5047                          (vectorp gnus-current-headers))
5048                     (gnus-mode-string-quote
5049                      (mail-header-subject gnus-current-headers))
5050                   ""))
5051                bufname-length max-len
5052                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5053           (setq mode-string (eval mformat))
5054           (setq bufname-length (if (string-match "%b" mode-string)
5055                                    (- (length
5056                                        (buffer-name
5057                                         (if (eq where 'summary)
5058                                             nil
5059                                           (get-buffer gnus-article-buffer))))
5060                                       2)
5061                                  0))
5062           (setq max-len (max 4 (if gnus-mode-non-string-length
5063                                    (- (window-width)
5064                                       gnus-mode-non-string-length
5065                                       bufname-length)
5066                                  (length mode-string))))
5067           ;; We might have to chop a bit of the string off...
5068           (when (> (length mode-string) max-len)
5069             (setq mode-string
5070                   (concat (truncate-string-to-width mode-string (- max-len 3))
5071                           "...")))
5072           ;; Pad the mode string a bit.
5073           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5074       ;; Update the mode line.
5075       (setq mode-line-buffer-identification
5076             (gnus-mode-line-buffer-identification (list mode-string)))
5077       (set-buffer-modified-p t))))
5078
5079 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5080   "Go through the HEADERS list and add all Xrefs to a hash table.
5081 The resulting hash table is returned, or nil if no Xrefs were found."
5082   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5083          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5084          (xref-hashtb (gnus-make-hashtable))
5085          start group entry number xrefs header)
5086     (while headers
5087       (setq header (pop headers))
5088       (when (and (setq xrefs (mail-header-xref header))
5089                  (not (memq (setq number (mail-header-number header))
5090                             unreads)))
5091         (setq start 0)
5092         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5093           (setq start (match-end 0))
5094           (setq group (if prefix
5095                           (concat prefix (substring xrefs (match-beginning 1)
5096                                                     (match-end 1)))
5097                         (substring xrefs (match-beginning 1) (match-end 1))))
5098           (setq number
5099                 (string-to-int (substring xrefs (match-beginning 2)
5100                                           (match-end 2))))
5101           (if (setq entry (gnus-gethash group xref-hashtb))
5102               (setcdr entry (cons number (cdr entry)))
5103             (gnus-sethash group (cons number nil) xref-hashtb)))))
5104     (and start xref-hashtb)))
5105
5106 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5107   "Look through all the headers and mark the Xrefs as read."
5108   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5109         name entry info xref-hashtb idlist method nth4)
5110     (save-excursion
5111       (set-buffer gnus-group-buffer)
5112       (when (setq xref-hashtb
5113                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5114         (mapatoms
5115          (lambda (group)
5116            (unless (string= from-newsgroup (setq name (symbol-name group)))
5117              (setq idlist (symbol-value group))
5118              ;; Dead groups are not updated.
5119              (and (prog1
5120                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5121                             info (nth 2 entry))
5122                     (when (stringp (setq nth4 (gnus-info-method info)))
5123                       (setq nth4 (gnus-server-to-method nth4))))
5124                   ;; Only do the xrefs if the group has the same
5125                   ;; select method as the group we have just read.
5126                   (or (gnus-methods-equal-p
5127                        nth4 (gnus-find-method-for-group from-newsgroup))
5128                       virtual
5129                       (equal nth4 (setq method (gnus-find-method-for-group
5130                                                 from-newsgroup)))
5131                       (and (equal (car nth4) (car method))
5132                            (equal (nth 1 nth4) (nth 1 method))))
5133                   gnus-use-cross-reference
5134                   (or (not (eq gnus-use-cross-reference t))
5135                       virtual
5136                       ;; Only do cross-references on subscribed
5137                       ;; groups, if that is what is wanted.
5138                       (<= (gnus-info-level info) gnus-level-subscribed))
5139                   (gnus-group-make-articles-read name idlist))))
5140          xref-hashtb)))))
5141
5142 (defun gnus-compute-read-articles (group articles)
5143   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5144          (info (nth 2 entry))
5145          (active (gnus-active group))
5146          ninfo)
5147     (when entry
5148       ;; First peel off all invalid article numbers.
5149       (when active
5150         (let ((ids articles)
5151               id first)
5152           (while (setq id (pop ids))
5153             (when (and first (> id (cdr active)))
5154               ;; We'll end up in this situation in one particular
5155               ;; obscure situation.  If you re-scan a group and get
5156               ;; a new article that is cross-posted to a different
5157               ;; group that has not been re-scanned, you might get
5158               ;; crossposted article that has a higher number than
5159               ;; Gnus believes possible.  So we re-activate this
5160               ;; group as well.  This might mean doing the
5161               ;; crossposting thingy will *increase* the number
5162               ;; of articles in some groups.  Tsk, tsk.
5163               (setq active (or (gnus-activate-group group) active)))
5164             (when (or (> id (cdr active))
5165                       (< id (car active)))
5166               (setq articles (delq id articles))))))
5167       ;; If the read list is nil, we init it.
5168       (if (and active
5169                (null (gnus-info-read info))
5170                (> (car active) 1))
5171           (setq ninfo (cons 1 (1- (car active))))
5172         (setq ninfo (gnus-info-read info)))
5173       ;; Then we add the read articles to the range.
5174       (gnus-add-to-range
5175        ninfo (setq articles (sort articles '<))))))
5176
5177 (defun gnus-group-make-articles-read (group articles)
5178   "Update the info of GROUP to say that ARTICLES are read."
5179   (let* ((num 0)
5180          (entry (gnus-gethash group gnus-newsrc-hashtb))
5181          (info (nth 2 entry))
5182          (active (gnus-active group))
5183          range)
5184     (when entry
5185       (setq range (gnus-compute-read-articles group articles))
5186       (save-excursion
5187         (set-buffer gnus-group-buffer)
5188         (gnus-undo-register
5189           `(progn
5190              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5191              (gnus-info-set-read ',info ',(gnus-info-read info))
5192              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5193              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5194              (gnus-group-update-group ,group t))))
5195       ;; Add the read articles to the range.
5196       (gnus-info-set-read info range)
5197       (gnus-request-set-mark group (list (list range 'add '(read))))
5198       ;; Then we have to re-compute how many unread
5199       ;; articles there are in this group.
5200       (when active
5201         (cond
5202          ((not range)
5203           (setq num (- (1+ (cdr active)) (car active))))
5204          ((not (listp (cdr range)))
5205           (setq num (- (cdr active) (- (1+ (cdr range))
5206                                        (car range)))))
5207          (t
5208           (while range
5209             (if (numberp (car range))
5210                 (setq num (1+ num))
5211               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5212             (setq range (cdr range)))
5213           (setq num (- (cdr active) num))))
5214         ;; Update the number of unread articles.
5215         (setcar entry num)
5216         ;; Update the group buffer.
5217         (gnus-group-update-group group t)))))
5218
5219 (defvar gnus-newsgroup-none-id 0)
5220
5221 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5222   (let ((cur nntp-server-buffer)
5223         (dependencies
5224          (or dependencies
5225              (save-excursion (set-buffer gnus-summary-buffer)
5226                              gnus-newsgroup-dependencies)))
5227         headers id end ref
5228         (mail-parse-charset gnus-newsgroup-charset)
5229         (mail-parse-ignored-charsets
5230          (save-excursion (condition-case nil
5231                              (set-buffer gnus-summary-buffer)
5232                            (error))
5233                          gnus-newsgroup-ignored-charsets)))
5234     (save-excursion
5235       (set-buffer nntp-server-buffer)
5236       ;; Translate all TAB characters into SPACE characters.
5237       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5238       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5239       (gnus-run-hooks 'gnus-parse-headers-hook)
5240       (let ((case-fold-search t)
5241             in-reply-to header p lines chars)
5242         (goto-char (point-min))
5243         ;; Search to the beginning of the next header.  Error messages
5244         ;; do not begin with 2 or 3.
5245         (while (re-search-forward "^[23][0-9]+ " nil t)
5246           (setq id nil
5247                 ref nil)
5248           ;; This implementation of this function, with nine
5249           ;; search-forwards instead of the one re-search-forward and
5250           ;; a case (which basically was the old function) is actually
5251           ;; about twice as fast, even though it looks messier.  You
5252           ;; can't have everything, I guess.  Speed and elegance
5253           ;; doesn't always go hand in hand.
5254           (setq
5255            header
5256            (vector
5257             ;; Number.
5258             (prog1
5259                 (read cur)
5260               (end-of-line)
5261               (setq p (point))
5262               (narrow-to-region (point)
5263                                 (or (and (search-forward "\n.\n" nil t)
5264                                          (- (point) 2))
5265                                     (point))))
5266             ;; Subject.
5267             (progn
5268               (goto-char p)
5269               (if (search-forward "\nsubject:" nil t)
5270                   (funcall gnus-decode-encoded-word-function
5271                            (nnheader-header-value))
5272                 "(none)"))
5273             ;; From.
5274             (progn
5275               (goto-char p)
5276               (if (search-forward "\nfrom:" nil t)
5277                   (funcall gnus-decode-encoded-word-function
5278                            (nnheader-header-value))
5279                 "(nobody)"))
5280             ;; Date.
5281             (progn
5282               (goto-char p)
5283               (if (search-forward "\ndate:" nil t)
5284                   (nnheader-header-value) ""))
5285             ;; Message-ID.
5286             (progn
5287               (goto-char p)
5288               (setq id (if (re-search-forward
5289                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5290                            ;; We do it this way to make sure the Message-ID
5291                            ;; is (somewhat) syntactically valid.
5292                            (buffer-substring (match-beginning 1)
5293                                              (match-end 1))
5294                          ;; If there was no message-id, we just fake one
5295                          ;; to make subsequent routines simpler.
5296                          (nnheader-generate-fake-message-id))))
5297             ;; References.
5298             (progn
5299               (goto-char p)
5300               (if (search-forward "\nreferences:" nil t)
5301                   (progn
5302                     (setq end (point))
5303                     (prog1
5304                         (nnheader-header-value)
5305                       (setq ref
5306                             (buffer-substring
5307                              (progn
5308                                (end-of-line)
5309                                (search-backward ">" end t)
5310                                (1+ (point)))
5311                              (progn
5312                                (search-backward "<" end t)
5313                                (point))))))
5314                 ;; Get the references from the in-reply-to header if there
5315                 ;; were no references and the in-reply-to header looks
5316                 ;; promising.
5317                 (if (and (search-forward "\nin-reply-to:" nil t)
5318                          (setq in-reply-to (nnheader-header-value))
5319                          (string-match "<[^>]+>" in-reply-to))
5320                     (let (ref2)
5321                       (setq ref (substring in-reply-to (match-beginning 0)
5322                                            (match-end 0)))
5323                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5324                         (setq ref2 (substring in-reply-to (match-beginning 0)
5325                                               (match-end 0)))
5326                         (when (> (length ref2) (length ref))
5327                           (setq ref ref2)))
5328                       ref)
5329                   (setq ref nil))))
5330             ;; Chars.
5331             (progn
5332               (goto-char p)
5333               (if (search-forward "\nchars: " nil t)
5334                   (if (numberp (setq chars (ignore-errors (read cur))))
5335                       chars -1)
5336                 -1))
5337             ;; Lines.
5338             (progn
5339               (goto-char p)
5340               (if (search-forward "\nlines: " nil t)
5341                   (if (numberp (setq lines (ignore-errors (read cur))))
5342                       lines -1)
5343                 -1))
5344             ;; Xref.
5345             (progn
5346               (goto-char p)
5347               (and (search-forward "\nxref:" nil t)
5348                    (nnheader-header-value)))
5349             ;; Extra.
5350             (when gnus-extra-headers
5351               (let ((extra gnus-extra-headers)
5352                     out)
5353                 (while extra
5354                   (goto-char p)
5355                   (when (search-forward
5356                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5357                     (push (cons (car extra) (nnheader-header-value))
5358                           out))
5359                   (pop extra))
5360                 out))))
5361           (when (equal id ref)
5362             (setq ref nil))
5363
5364           (when gnus-alter-header-function
5365             (funcall gnus-alter-header-function header)
5366             (setq id (mail-header-id header)
5367                   ref (gnus-parent-id (mail-header-references header))))
5368
5369           (when (setq header
5370                       (gnus-dependencies-add-header
5371                        header dependencies force-new))
5372             (push header headers))
5373           (goto-char (point-max))
5374           (widen))
5375         (nreverse headers)))))
5376
5377 ;; Goes through the xover lines and returns a list of vectors
5378 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5379                                                   force-new dependencies
5380                                                   group also-fetch-heads)
5381   "Parse the news overview data in the server buffer.
5382 Return a list of headers that match SEQUENCE (see
5383 `nntp-retrieve-headers')."
5384   ;; Get the Xref when the users reads the articles since most/some
5385   ;; NNTP servers do not include Xrefs when using XOVER.
5386   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5387   (let ((mail-parse-charset gnus-newsgroup-charset)
5388         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5389         (cur nntp-server-buffer)
5390         (dependencies (or dependencies gnus-newsgroup-dependencies))
5391         (allp (cond
5392                ((eq gnus-read-all-available-headers t)
5393                 t)
5394                ((stringp gnus-read-all-available-headers)
5395                 (string-match gnus-read-all-available-headers group))
5396                (t
5397                 nil)))
5398         number headers header)
5399     (save-excursion
5400       (set-buffer nntp-server-buffer)
5401       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5402       ;; Allow the user to mangle the headers before parsing them.
5403       (gnus-run-hooks 'gnus-parse-headers-hook)
5404       (goto-char (point-min))
5405       (while (not (eobp))
5406         (condition-case ()
5407             (while (and (or sequence allp)
5408                         (not (eobp)))
5409               (setq number (read cur))
5410               (when (not allp)
5411                 (while (and sequence
5412                             (< (car sequence) number))
5413                   (setq sequence (cdr sequence))))
5414               (when (and (or allp
5415                              (and sequence
5416                                   (eq number (car sequence))))
5417                          (progn
5418                            (setq sequence (cdr sequence))
5419                            (setq header (inline
5420                                           (gnus-nov-parse-line
5421                                            number dependencies force-new)))))
5422                 (push header headers))
5423               (forward-line 1))
5424           (error
5425            (gnus-error 4 "Strange nov line (%d)"
5426                        (count-lines (point-min) (point)))))
5427         (forward-line 1))
5428       ;; A common bug in inn is that if you have posted an article and
5429       ;; then retrieves the active file, it will answer correctly --
5430       ;; the new article is included.  However, a NOV entry for the
5431       ;; article may not have been generated yet, so this may fail.
5432       ;; We work around this problem by retrieving the last few
5433       ;; headers using HEAD.
5434       (if (or (not also-fetch-heads)
5435               (not sequence))
5436           ;; We (probably) got all the headers.
5437           (nreverse headers)
5438         (let ((gnus-nov-is-evil t))
5439           (nconc
5440            (nreverse headers)
5441            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5442              (gnus-get-newsgroup-headers))))))))
5443
5444 (defun gnus-article-get-xrefs ()
5445   "Fill in the Xref value in `gnus-current-headers', if necessary.
5446 This is meant to be called in `gnus-article-internal-prepare-hook'."
5447   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5448                                  gnus-current-headers)))
5449     (or (not gnus-use-cross-reference)
5450         (not headers)
5451         (and (mail-header-xref headers)
5452              (not (string= (mail-header-xref headers) "")))
5453         (let ((case-fold-search t)
5454               xref)
5455           (save-restriction
5456             (nnheader-narrow-to-headers)
5457             (goto-char (point-min))
5458             (when (or (and (not (eobp))
5459                            (eq (downcase (char-after)) ?x)
5460                            (looking-at "Xref:"))
5461                       (search-forward "\nXref:" nil t))
5462               (goto-char (1+ (match-end 0)))
5463               (setq xref (buffer-substring (point)
5464                                            (progn (end-of-line) (point))))
5465               (mail-header-set-xref headers xref)))))))
5466
5467 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5468   "Find article ID and insert the summary line for that article.
5469 OLD-HEADER can either be a header or a line number to insert
5470 the subject line on."
5471   (let* ((line (and (numberp old-header) old-header))
5472          (old-header (and (vectorp old-header) old-header))
5473          (header (cond ((and old-header use-old-header)
5474                         old-header)
5475                        ((and (numberp id)
5476                              (gnus-number-to-header id))
5477                         (gnus-number-to-header id))
5478                        (t
5479                         (gnus-read-header id))))
5480          (number (and (numberp id) id))
5481          d)
5482     (when header
5483       ;; Rebuild the thread that this article is part of and go to the
5484       ;; article we have fetched.
5485       (when (and (not gnus-show-threads)
5486                  old-header)
5487         (when (and number
5488                    (setq d (gnus-data-find (mail-header-number old-header))))
5489           (goto-char (gnus-data-pos d))
5490           (gnus-data-remove
5491            number
5492            (- (gnus-point-at-bol)
5493               (prog1
5494                   (1+ (gnus-point-at-eol))
5495                 (gnus-delete-line))))))
5496       (when old-header
5497         (mail-header-set-number header (mail-header-number old-header)))
5498       (setq gnus-newsgroup-sparse
5499             (delq (setq number (mail-header-number header))
5500                   gnus-newsgroup-sparse))
5501       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5502       (push number gnus-newsgroup-limit)
5503       (gnus-rebuild-thread (mail-header-id header) line)
5504       (gnus-summary-goto-subject number nil t))
5505     (when (and (numberp number)
5506                (> number 0))
5507       ;; We have to update the boundaries even if we can't fetch the
5508       ;; article if ID is a number -- so that the next `P' or `N'
5509       ;; command will fetch the previous (or next) article even
5510       ;; if the one we tried to fetch this time has been canceled.
5511       (when (> number gnus-newsgroup-end)
5512         (setq gnus-newsgroup-end number))
5513       (when (< number gnus-newsgroup-begin)
5514         (setq gnus-newsgroup-begin number))
5515       (setq gnus-newsgroup-unselected
5516             (delq number gnus-newsgroup-unselected)))
5517     ;; Report back a success?
5518     (and header (mail-header-number header))))
5519
5520 ;;; Process/prefix in the summary buffer
5521
5522 (defun gnus-summary-work-articles (n)
5523   "Return a list of articles to be worked upon.
5524 The prefix argument, the list of process marked articles, and the
5525 current article will be taken into consideration."
5526   (save-excursion
5527     (set-buffer gnus-summary-buffer)
5528     (cond
5529      (n
5530       ;; A numerical prefix has been given.
5531       (setq n (prefix-numeric-value n))
5532       (let ((backward (< n 0))
5533             (n (abs (prefix-numeric-value n)))
5534             articles article)
5535         (save-excursion
5536           (while
5537               (and (> n 0)
5538                    (push (setq article (gnus-summary-article-number))
5539                          articles)
5540                    (if backward
5541                        (gnus-summary-find-prev nil article)
5542                      (gnus-summary-find-next nil article)))
5543             (decf n)))
5544         (nreverse articles)))
5545      ((and (gnus-region-active-p) (mark))
5546       (message "region active")
5547       ;; Work on the region between point and mark.
5548       (let ((max (max (point) (mark)))
5549             articles article)
5550         (save-excursion
5551           (goto-char (min (min (point) (mark))))
5552           (while
5553               (and
5554                (push (setq article (gnus-summary-article-number)) articles)
5555                (gnus-summary-find-next nil article)
5556                (< (point) max)))
5557           (nreverse articles))))
5558      (gnus-newsgroup-processable
5559       ;; There are process-marked articles present.
5560       ;; Save current state.
5561       (gnus-summary-save-process-mark)
5562       ;; Return the list.
5563       (reverse gnus-newsgroup-processable))
5564      (t
5565       ;; Just return the current article.
5566       (list (gnus-summary-article-number))))))
5567
5568 (defmacro gnus-summary-iterate (arg &rest forms)
5569   "Iterate over the process/prefixed articles and do FORMS.
5570 ARG is the interactive prefix given to the command.  FORMS will be
5571 executed with point over the summary line of the articles."
5572   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5573     `(let ((,articles (gnus-summary-work-articles ,arg)))
5574        (while ,articles
5575          (gnus-summary-goto-subject (car ,articles))
5576          ,@forms
5577          (pop ,articles)))))
5578
5579 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5580 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5581
5582 (defun gnus-summary-save-process-mark ()
5583   "Push the current set of process marked articles on the stack."
5584   (interactive)
5585   (push (copy-sequence gnus-newsgroup-processable)
5586         gnus-newsgroup-process-stack))
5587
5588 (defun gnus-summary-kill-process-mark ()
5589   "Push the current set of process marked articles on the stack and unmark."
5590   (interactive)
5591   (gnus-summary-save-process-mark)
5592   (gnus-summary-unmark-all-processable))
5593
5594 (defun gnus-summary-yank-process-mark ()
5595   "Pop the last process mark state off the stack and restore it."
5596   (interactive)
5597   (unless gnus-newsgroup-process-stack
5598     (error "Empty mark stack"))
5599   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5600
5601 (defun gnus-summary-process-mark-set (set)
5602   "Make SET into the current process marked articles."
5603   (gnus-summary-unmark-all-processable)
5604   (while set
5605     (gnus-summary-set-process-mark (pop set))))
5606
5607 ;;; Searching and stuff
5608
5609 (defun gnus-summary-search-group (&optional backward use-level)
5610   "Search for next unread newsgroup.
5611 If optional argument BACKWARD is non-nil, search backward instead."
5612   (save-excursion
5613     (set-buffer gnus-group-buffer)
5614     (when (gnus-group-search-forward
5615            backward nil (if use-level (gnus-group-group-level) nil))
5616       (gnus-group-group-name))))
5617
5618 (defun gnus-summary-best-group (&optional exclude-group)
5619   "Find the name of the best unread group.
5620 If EXCLUDE-GROUP, do not go to this group."
5621   (save-excursion
5622     (set-buffer gnus-group-buffer)
5623     (save-excursion
5624       (gnus-group-best-unread-group exclude-group))))
5625
5626 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5627   (if backward (gnus-summary-find-prev)
5628     (let* ((dummy (gnus-summary-article-intangible-p))
5629            (article (or article (gnus-summary-article-number)))
5630            (arts (gnus-data-find-list article))
5631            result)
5632       (when (and (not dummy)
5633                  (or (not gnus-summary-check-current)
5634                      (not unread)
5635                      (not (gnus-data-unread-p (car arts)))))
5636         (setq arts (cdr arts)))
5637       (when (setq result
5638                   (if unread
5639                       (progn
5640                         (while arts
5641                           (when (or (and undownloaded
5642                                          (eq gnus-undownloaded-mark
5643                                              (gnus-data-mark (car arts))))
5644                                     (gnus-data-unread-p (car arts)))
5645                             (setq result (car arts)
5646                                   arts nil))
5647                           (setq arts (cdr arts)))
5648                         result)
5649                     (car arts)))
5650         (goto-char (gnus-data-pos result))
5651         (gnus-data-number result)))))
5652
5653 (defun gnus-summary-find-prev (&optional unread article)
5654   (let* ((eobp (eobp))
5655          (article (or article (gnus-summary-article-number)))
5656          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5657          result)
5658     (when (and (not eobp)
5659                (or (not gnus-summary-check-current)
5660                    (not unread)
5661                    (not (gnus-data-unread-p (car arts)))))
5662       (setq arts (cdr arts)))
5663     (when (setq result
5664                 (if unread
5665                     (progn
5666                       (while arts
5667                         (when (gnus-data-unread-p (car arts))
5668                           (setq result (car arts)
5669                                 arts nil))
5670                         (setq arts (cdr arts)))
5671                       result)
5672                   (car arts)))
5673       (goto-char (gnus-data-pos result))
5674       (gnus-data-number result))))
5675
5676 (defun gnus-summary-find-subject (subject &optional unread backward article)
5677   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5678          (article (or article (gnus-summary-article-number)))
5679          (articles (gnus-data-list backward))
5680          (arts (gnus-data-find-list article articles))
5681          result)
5682     (when (or (not gnus-summary-check-current)
5683               (not unread)
5684               (not (gnus-data-unread-p (car arts))))
5685       (setq arts (cdr arts)))
5686     (while arts
5687       (and (or (not unread)
5688                (gnus-data-unread-p (car arts)))
5689            (vectorp (gnus-data-header (car arts)))
5690            (gnus-subject-equal
5691             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5692            (setq result (car arts)
5693                  arts nil))
5694       (setq arts (cdr arts)))
5695     (and result
5696          (goto-char (gnus-data-pos result))
5697          (gnus-data-number result))))
5698
5699 (defun gnus-summary-search-forward (&optional unread subject backward)
5700   "Search forward for an article.
5701 If UNREAD, look for unread articles.  If SUBJECT, look for
5702 articles with that subject.  If BACKWARD, search backward instead."
5703   (cond (subject (gnus-summary-find-subject subject unread backward))
5704         (backward (gnus-summary-find-prev unread))
5705         (t (gnus-summary-find-next unread))))
5706
5707 (defun gnus-recenter (&optional n)
5708   "Center point in window and redisplay frame.
5709 Also do horizontal recentering."
5710   (interactive "P")
5711   (when (and gnus-auto-center-summary
5712              (not (eq gnus-auto-center-summary 'vertical)))
5713     (gnus-horizontal-recenter))
5714   (recenter n))
5715
5716 (defun gnus-summary-recenter ()
5717   "Center point in the summary window.
5718 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5719 displayed, no centering will be performed."
5720   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5721 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5722   (interactive)
5723   (let* ((top (cond ((< (window-height) 4) 0)
5724                     ((< (window-height) 7) 1)
5725                     (t (if (numberp gnus-auto-center-summary)
5726                            gnus-auto-center-summary
5727                          2))))
5728          (height (1- (window-height)))
5729          (bottom (save-excursion (goto-char (point-max))
5730                                  (forward-line (- height))
5731                                  (point)))
5732          (window (get-buffer-window (current-buffer))))
5733     ;; The user has to want it.
5734     (when gnus-auto-center-summary
5735       (when (get-buffer-window gnus-article-buffer)
5736         ;; Only do recentering when the article buffer is displayed,
5737       ;; Set the window start to either `bottom', which is the biggest
5738         ;; possible valid number, or the second line from the top,
5739         ;; whichever is the least.
5740         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5741           (if (> bottom top-pos)
5742               ;; Keep the second line from the top visible
5743               (set-window-start window top-pos t)
5744             ;; Try to keep the bottom line visible; if it's partially
5745             ;; obscured, either scroll one more line to make it fully
5746             ;; visible, or revert to using TOP-POS.
5747             (save-excursion
5748               (goto-char (point-max))
5749               (forward-line -1)
5750               (let ((last-line-start (point)))
5751                 (goto-char bottom)
5752                 (set-window-start window (point) t)
5753                 (when (not (pos-visible-in-window-p last-line-start window))
5754                   (forward-line 1)
5755                   (set-window-start window (min (point) top-pos) t)))))))
5756       ;; Do horizontal recentering while we're at it.
5757       (when (and (get-buffer-window (current-buffer) t)
5758                  (not (eq gnus-auto-center-summary 'vertical)))
5759         (let ((selected (selected-window)))
5760           (select-window (get-buffer-window (current-buffer) t))
5761           (gnus-summary-position-point)
5762           (gnus-horizontal-recenter)
5763           (select-window selected))))))
5764
5765 (defun gnus-summary-jump-to-group (newsgroup)
5766   "Move point to NEWSGROUP in group mode buffer."
5767   ;; Keep update point of group mode buffer if visible.
5768   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5769       (save-window-excursion
5770         ;; Take care of tree window mode.
5771         (when (get-buffer-window gnus-group-buffer)
5772           (pop-to-buffer gnus-group-buffer))
5773         (gnus-group-jump-to-group newsgroup))
5774     (save-excursion
5775       ;; Take care of tree window mode.
5776       (if (get-buffer-window gnus-group-buffer)
5777           (pop-to-buffer gnus-group-buffer)
5778         (set-buffer gnus-group-buffer))
5779       (gnus-group-jump-to-group newsgroup))))
5780
5781 ;; This function returns a list of article numbers based on the
5782 ;; difference between the ranges of read articles in this group and
5783 ;; the range of active articles.
5784 (defun gnus-list-of-unread-articles (group)
5785   (let* ((read (gnus-info-read (gnus-get-info group)))
5786          (active (or (gnus-active group) (gnus-activate-group group)))
5787          (last (cdr active))
5788          first nlast unread)
5789     ;; If none are read, then all are unread.
5790     (if (not read)
5791         (setq first (car active))
5792       ;; If the range of read articles is a single range, then the
5793       ;; first unread article is the article after the last read
5794       ;; article.  Sounds logical, doesn't it?
5795       (if (and (not (listp (cdr read)))
5796                (or (< (car read) (car active))
5797                    (progn (setq read (list read))
5798                           nil)))
5799           (setq first (max (car active) (1+ (cdr read))))
5800         ;; `read' is a list of ranges.
5801         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5802                                   (caar read)))
5803                   1)
5804           (setq first (car active)))
5805         (while read
5806           (when first
5807             (while (< first nlast)
5808               (push first unread)
5809               (setq first (1+ first))))
5810           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5811           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5812           (setq read (cdr read)))))
5813     ;; And add the last unread articles.
5814     (while (<= first last)
5815       (push first unread)
5816       (setq first (1+ first)))
5817     ;; Return the list of unread articles.
5818     (delq 0 (nreverse unread))))
5819
5820 (defun gnus-list-of-read-articles (group)
5821   "Return a list of unread, unticked and non-dormant articles."
5822   (let* ((info (gnus-get-info group))
5823          (marked (gnus-info-marks info))
5824          (active (gnus-active group)))
5825     (and info active
5826          (gnus-set-difference
5827           (gnus-sorted-complement
5828            (gnus-uncompress-range active)
5829            (gnus-list-of-unread-articles group))
5830           (append
5831            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5832            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5833
5834 ;; Various summary commands
5835
5836 (defun gnus-summary-select-article-buffer ()
5837   "Reconfigure windows to show article buffer."
5838   (interactive)
5839   (if (not (gnus-buffer-live-p gnus-article-buffer))
5840       (error "There is no article buffer for this summary buffer")
5841     (gnus-configure-windows 'article)
5842     (select-window (get-buffer-window gnus-article-buffer))))
5843
5844 (defun gnus-summary-universal-argument (arg)
5845   "Perform any operation on all articles that are process/prefixed."
5846   (interactive "P")
5847   (let ((articles (gnus-summary-work-articles arg))
5848         func article)
5849     (if (eq
5850          (setq
5851           func
5852           (key-binding
5853            (read-key-sequence
5854             (substitute-command-keys
5855              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5856          'undefined)
5857         (gnus-error 1 "Undefined key")
5858       (save-excursion
5859         (while articles
5860           (gnus-summary-goto-subject (setq article (pop articles)))
5861           (let (gnus-newsgroup-processable)
5862             (command-execute func))
5863           (gnus-summary-remove-process-mark article)))))
5864   (gnus-summary-position-point))
5865
5866 (defun gnus-summary-toggle-truncation (&optional arg)
5867   "Toggle truncation of summary lines.
5868 With arg, turn line truncation on iff arg is positive."
5869   (interactive "P")
5870   (setq truncate-lines
5871         (if (null arg) (not truncate-lines)
5872           (> (prefix-numeric-value arg) 0)))
5873   (redraw-display))
5874
5875 (defun gnus-summary-reselect-current-group (&optional all rescan)
5876   "Exit and then reselect the current newsgroup.
5877 The prefix argument ALL means to select all articles."
5878   (interactive "P")
5879   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5880     (error "Ephemeral groups can't be reselected"))
5881   (let ((current-subject (gnus-summary-article-number))
5882         (group gnus-newsgroup-name))
5883     (setq gnus-newsgroup-begin nil)
5884     (gnus-summary-exit)
5885     ;; We have to adjust the point of group mode buffer because
5886     ;; point was moved to the next unread newsgroup by exiting.
5887     (gnus-summary-jump-to-group group)
5888     (when rescan
5889       (save-excursion
5890         (gnus-group-get-new-news-this-group 1)))
5891     (gnus-group-read-group all t)
5892     (gnus-summary-goto-subject current-subject nil t)))
5893
5894 (defun gnus-summary-rescan-group (&optional all)
5895   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5896   (interactive "P")
5897   (gnus-summary-reselect-current-group all t))
5898
5899 (defun gnus-summary-update-info (&optional non-destructive)
5900   (save-excursion
5901     (let ((group gnus-newsgroup-name))
5902       (when group
5903         (when gnus-newsgroup-kill-headers
5904           (setq gnus-newsgroup-killed
5905                 (gnus-compress-sequence
5906                  (nconc
5907                   (gnus-set-sorted-intersection
5908                    (gnus-uncompress-range gnus-newsgroup-killed)
5909                    (setq gnus-newsgroup-unselected
5910                          (sort gnus-newsgroup-unselected '<)))
5911                   (setq gnus-newsgroup-unreads
5912                         (sort gnus-newsgroup-unreads '<)))
5913                  t)))
5914         (unless (listp (cdr gnus-newsgroup-killed))
5915           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5916         (let ((headers gnus-newsgroup-headers))
5917           ;; Set the new ranges of read articles.
5918           (save-excursion
5919             (set-buffer gnus-group-buffer)
5920             (gnus-undo-force-boundary))
5921           (gnus-update-read-articles
5922            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5923           ;; Set the current article marks.
5924           (let ((gnus-newsgroup-scored
5925                  (if (and (not gnus-save-score)
5926                           (not non-destructive))
5927                      nil
5928                    gnus-newsgroup-scored)))
5929             (save-excursion
5930               (gnus-update-marks)))
5931           ;; Do the cross-ref thing.
5932           (when gnus-use-cross-reference
5933             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5934           ;; Do not switch windows but change the buffer to work.
5935           (set-buffer gnus-group-buffer)
5936           (unless (gnus-ephemeral-group-p group)
5937             (gnus-group-update-group group)))))))
5938
5939 (defun gnus-summary-save-newsrc (&optional force)
5940   "Save the current number of read/marked articles in the dribble buffer.
5941 The dribble buffer will then be saved.
5942 If FORCE (the prefix), also save the .newsrc file(s)."
5943   (interactive "P")
5944   (gnus-summary-update-info t)
5945   (if force
5946       (gnus-save-newsrc-file)
5947     (gnus-dribble-save)))
5948
5949 (defun gnus-summary-exit (&optional temporary)
5950   "Exit reading current newsgroup, and then return to group selection mode.
5951 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5952   (interactive)
5953   (gnus-set-global-variables)
5954   (when (gnus-buffer-live-p gnus-article-buffer)
5955     (save-excursion
5956       (set-buffer gnus-article-buffer)
5957       (mm-destroy-parts gnus-article-mime-handles)
5958       ;; Set it to nil for safety reason.
5959       (setq gnus-article-mime-handle-alist nil)
5960       (setq gnus-article-mime-handles nil)))
5961   (gnus-kill-save-kill-buffer)
5962   (gnus-async-halt-prefetch)
5963   (let* ((group gnus-newsgroup-name)
5964          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5965          (mode major-mode)
5966          (group-point nil)
5967          (buf (current-buffer)))
5968     (unless quit-config
5969       ;; Do adaptive scoring, and possibly save score files.
5970       (when gnus-newsgroup-adaptive
5971         (gnus-score-adaptive))
5972       (when gnus-use-scoring
5973         (gnus-score-save)))
5974     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5975     ;; If we have several article buffers, we kill them at exit.
5976     (unless gnus-single-article-buffer
5977       (gnus-kill-buffer gnus-original-article-buffer)
5978       (setq gnus-article-current nil))
5979     (when gnus-use-cache
5980       (gnus-cache-possibly-remove-articles)
5981       (gnus-cache-save-buffers))
5982     (gnus-async-prefetch-remove-group group)
5983     (when gnus-suppress-duplicates
5984       (gnus-dup-enter-articles))
5985     (when gnus-use-trees
5986       (gnus-tree-close group))
5987     (when gnus-use-cache
5988       (gnus-cache-write-active))
5989     ;; Remove entries for this group.
5990     (nnmail-purge-split-history (gnus-group-real-name group))
5991     ;; Make all changes in this group permanent.
5992     (unless quit-config
5993       (gnus-run-hooks 'gnus-exit-group-hook)
5994       (gnus-summary-update-info))
5995     (gnus-close-group group)
5996     ;; Make sure where we were, and go to next newsgroup.
5997     (set-buffer gnus-group-buffer)
5998     (unless quit-config
5999       (gnus-group-jump-to-group group))
6000     (gnus-run-hooks 'gnus-summary-exit-hook)
6001     (unless (or quit-config
6002                 ;; If this group has disappeared from the summary
6003                 ;; buffer, don't skip forwards.
6004                 (not (string= group (gnus-group-group-name))))
6005       (gnus-group-next-unread-group 1))
6006     (setq group-point (point))
6007     (if temporary
6008         nil                             ;Nothing to do.
6009       ;; If we have several article buffers, we kill them at exit.
6010       (unless gnus-single-article-buffer
6011         (gnus-kill-buffer gnus-article-buffer)
6012         (gnus-kill-buffer gnus-original-article-buffer)
6013         (setq gnus-article-current nil))
6014       (set-buffer buf)
6015       (if (not gnus-kill-summary-on-exit)
6016           (progn
6017             (gnus-deaden-summary)
6018             (setq mode nil))
6019        ;; We set all buffer-local variables to nil.  It is unclear why
6020         ;; this is needed, but if we don't, buffer-local variables are
6021         ;; not garbage-collected, it seems.  This would the lead to en
6022         ;; ever-growing Emacs.
6023         (gnus-summary-clear-local-variables)
6024         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6025           (gnus-summary-clear-local-variables))
6026         (when (get-buffer gnus-article-buffer)
6027           (bury-buffer gnus-article-buffer))
6028         ;; We clear the global counterparts of the buffer-local
6029         ;; variables as well, just to be on the safe side.
6030         (set-buffer gnus-group-buffer)
6031         (gnus-summary-clear-local-variables)
6032         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6033           (gnus-summary-clear-local-variables)))
6034       (setq gnus-current-select-method gnus-select-method)
6035       (pop-to-buffer gnus-group-buffer)
6036       (if (not quit-config)
6037           (progn
6038             (goto-char group-point)
6039             (gnus-configure-windows 'group 'force))
6040         (gnus-handle-ephemeral-exit quit-config))
6041       ;; Return to group mode buffer.
6042       (when (eq mode 'gnus-summary-mode)
6043         (gnus-kill-buffer buf))
6044       ;; Clear the current group name.
6045       (unless quit-config
6046         (setq gnus-newsgroup-name nil)))))
6047
6048 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6049 (defun gnus-summary-exit-no-update (&optional no-questions)
6050   "Quit reading current newsgroup without updating read article info."
6051   (interactive)
6052   (let* ((group gnus-newsgroup-name)
6053          (quit-config (gnus-group-quit-config group)))
6054     (when (or no-questions
6055               gnus-expert-user
6056               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6057       (gnus-async-halt-prefetch)
6058       (mapcar 'funcall
6059               (delq 'gnus-summary-expire-articles
6060                     (copy-sequence gnus-summary-prepare-exit-hook)))
6061       (when (gnus-buffer-live-p gnus-article-buffer)
6062         (save-excursion
6063           (set-buffer gnus-article-buffer)
6064           (mm-destroy-parts gnus-article-mime-handles)
6065           ;; Set it to nil for safety reason.
6066           (setq gnus-article-mime-handle-alist nil)
6067           (setq gnus-article-mime-handles nil)))
6068       ;; If we have several article buffers, we kill them at exit.
6069       (unless gnus-single-article-buffer
6070         (gnus-kill-buffer gnus-article-buffer)
6071         (gnus-kill-buffer gnus-original-article-buffer)
6072         (setq gnus-article-current nil))
6073       (if (not gnus-kill-summary-on-exit)
6074           (gnus-deaden-summary)
6075         (gnus-close-group group)
6076         (gnus-summary-clear-local-variables)
6077         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6078           (gnus-summary-clear-local-variables))
6079         (set-buffer gnus-group-buffer)
6080         (gnus-summary-clear-local-variables)
6081         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6082           (gnus-summary-clear-local-variables))
6083         (when (get-buffer gnus-summary-buffer)
6084           (kill-buffer gnus-summary-buffer)))
6085       (unless gnus-single-article-buffer
6086         (setq gnus-article-current nil))
6087       (when gnus-use-trees
6088         (gnus-tree-close group))
6089       (gnus-async-prefetch-remove-group group)
6090       (when (get-buffer gnus-article-buffer)
6091         (bury-buffer gnus-article-buffer))
6092       ;; Return to the group buffer.
6093       (gnus-configure-windows 'group 'force)
6094       ;; Clear the current group name.
6095       (setq gnus-newsgroup-name nil)
6096       (when (equal (gnus-group-group-name) group)
6097         (gnus-group-next-unread-group 1))
6098       (when quit-config
6099         (gnus-handle-ephemeral-exit quit-config)))))
6100
6101 (defun gnus-handle-ephemeral-exit (quit-config)
6102   "Handle movement when leaving an ephemeral group.
6103 The state which existed when entering the ephemeral is reset."
6104   (if (not (buffer-name (car quit-config)))
6105       (gnus-configure-windows 'group 'force)
6106     (set-buffer (car quit-config))
6107     (cond ((eq major-mode 'gnus-summary-mode)
6108            (gnus-set-global-variables))
6109           ((eq major-mode 'gnus-article-mode)
6110            (save-excursion
6111              ;; The `gnus-summary-buffer' variable may point
6112              ;; to the old summary buffer when using a single
6113              ;; article buffer.
6114              (unless (gnus-buffer-live-p gnus-summary-buffer)
6115                (set-buffer gnus-group-buffer))
6116              (set-buffer gnus-summary-buffer)
6117              (gnus-set-global-variables))))
6118     (if (or (eq (cdr quit-config) 'article)
6119             (eq (cdr quit-config) 'pick))
6120         (progn
6121           ;; The current article may be from the ephemeral group
6122           ;; thus it is best that we reload this article
6123           (gnus-summary-show-article)
6124           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6125               (gnus-configure-windows 'pick 'force)
6126             (gnus-configure-windows (cdr quit-config) 'force)))
6127       (gnus-configure-windows (cdr quit-config) 'force))
6128     (when (eq major-mode 'gnus-summary-mode)
6129       (gnus-summary-next-subject 1 nil t)
6130       (gnus-summary-recenter)
6131       (gnus-summary-position-point))))
6132
6133 ;;; Dead summaries.
6134
6135 (defvar gnus-dead-summary-mode-map nil)
6136
6137 (unless gnus-dead-summary-mode-map
6138   (setq gnus-dead-summary-mode-map (make-keymap))
6139   (suppress-keymap gnus-dead-summary-mode-map)
6140   (substitute-key-definition
6141    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6142   (let ((keys '("\C-d" "\r" "\177" [delete])))
6143     (while keys
6144       (define-key gnus-dead-summary-mode-map
6145         (pop keys) 'gnus-summary-wake-up-the-dead))))
6146
6147 (defvar gnus-dead-summary-mode nil
6148   "Minor mode for Gnus summary buffers.")
6149
6150 (defun gnus-dead-summary-mode (&optional arg)
6151   "Minor mode for Gnus summary buffers."
6152   (interactive "P")
6153   (when (eq major-mode 'gnus-summary-mode)
6154     (make-local-variable 'gnus-dead-summary-mode)
6155     (setq gnus-dead-summary-mode
6156           (if (null arg) (not gnus-dead-summary-mode)
6157             (> (prefix-numeric-value arg) 0)))
6158     (when gnus-dead-summary-mode
6159       (gnus-add-minor-mode
6160        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6161
6162 (defun gnus-deaden-summary ()
6163   "Make the current summary buffer into a dead summary buffer."
6164   ;; Kill any previous dead summary buffer.
6165   (when (and gnus-dead-summary
6166              (buffer-name gnus-dead-summary))
6167     (save-excursion
6168       (set-buffer gnus-dead-summary)
6169       (when gnus-dead-summary-mode
6170         (kill-buffer (current-buffer)))))
6171   ;; Make this the current dead summary.
6172   (setq gnus-dead-summary (current-buffer))
6173   (gnus-dead-summary-mode 1)
6174   (let ((name (buffer-name)))
6175     (when (string-match "Summary" name)
6176       (rename-buffer
6177        (concat (substring name 0 (match-beginning 0)) "Dead "
6178                (substring name (match-beginning 0)))
6179        t)
6180       (bury-buffer))))
6181
6182 (defun gnus-kill-or-deaden-summary (buffer)
6183   "Kill or deaden the summary BUFFER."
6184   (save-excursion
6185     (when (and (buffer-name buffer)
6186                (not gnus-single-article-buffer))
6187       (save-excursion
6188         (set-buffer buffer)
6189         (gnus-kill-buffer gnus-article-buffer)
6190         (gnus-kill-buffer gnus-original-article-buffer)))
6191     (cond (gnus-kill-summary-on-exit
6192            (when (and gnus-use-trees
6193                       (gnus-buffer-exists-p buffer))
6194              (save-excursion
6195                (set-buffer buffer)
6196                (gnus-tree-close gnus-newsgroup-name)))
6197            (gnus-kill-buffer buffer))
6198           ((gnus-buffer-exists-p buffer)
6199            (save-excursion
6200              (set-buffer buffer)
6201              (gnus-deaden-summary))))))
6202
6203 (defun gnus-summary-wake-up-the-dead (&rest args)
6204   "Wake up the dead summary buffer."
6205   (interactive)
6206   (gnus-dead-summary-mode -1)
6207   (let ((name (buffer-name)))
6208     (when (string-match "Dead " name)
6209       (rename-buffer
6210        (concat (substring name 0 (match-beginning 0))
6211                (substring name (match-end 0)))
6212        t)))
6213   (gnus-message 3 "This dead summary is now alive again"))
6214
6215 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6216 (defun gnus-summary-fetch-faq (&optional faq-dir)
6217   "Fetch the FAQ for the current group.
6218 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6219 in."
6220   (interactive
6221    (list
6222     (when current-prefix-arg
6223       (completing-read
6224        "Faq dir: " (and (listp gnus-group-faq-directory)
6225                         (mapcar (lambda (file) (list file))
6226                                 gnus-group-faq-directory))))))
6227   (let (gnus-faq-buffer)
6228     (when (setq gnus-faq-buffer
6229                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6230       (gnus-configure-windows 'summary-faq))))
6231
6232 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6233 (defun gnus-summary-describe-group (&optional force)
6234   "Describe the current newsgroup."
6235   (interactive "P")
6236   (gnus-group-describe-group force gnus-newsgroup-name))
6237
6238 (defun gnus-summary-describe-briefly ()
6239   "Describe summary mode commands briefly."
6240   (interactive)
6241   (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")))
6242
6243 ;; Walking around group mode buffer from summary mode.
6244
6245 (defun gnus-summary-next-group (&optional no-article target-group backward)
6246   "Exit current newsgroup and then select next unread newsgroup.
6247 If prefix argument NO-ARTICLE is non-nil, no article is selected
6248 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6249 previous group instead."
6250   (interactive "P")
6251   ;; Stop pre-fetching.
6252   (gnus-async-halt-prefetch)
6253   (let ((current-group gnus-newsgroup-name)
6254         (current-buffer (current-buffer))
6255         entered)
6256    ;; First we semi-exit this group to update Xrefs and all variables.
6257     ;; We can't do a real exit, because the window conf must remain
6258     ;; the same in case the user is prompted for info, and we don't
6259     ;; want the window conf to change before that...
6260     (gnus-summary-exit t)
6261     (while (not entered)
6262       ;; Then we find what group we are supposed to enter.
6263       (set-buffer gnus-group-buffer)
6264       (gnus-group-jump-to-group current-group)
6265       (setq target-group
6266             (or target-group
6267                 (if (eq gnus-keep-same-level 'best)
6268                     (gnus-summary-best-group gnus-newsgroup-name)
6269                   (gnus-summary-search-group backward gnus-keep-same-level))))
6270       (if (not target-group)
6271           ;; There are no further groups, so we return to the group
6272           ;; buffer.
6273           (progn
6274             (gnus-message 5 "Returning to the group buffer")
6275             (setq entered t)
6276             (when (gnus-buffer-live-p current-buffer)
6277               (set-buffer current-buffer)
6278               (gnus-summary-exit))
6279             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6280         ;; We try to enter the target group.
6281         (gnus-group-jump-to-group target-group)
6282         (let ((unreads (gnus-group-group-unread)))
6283           (if (and (or (eq t unreads)
6284                        (and unreads (not (zerop unreads))))
6285                    (gnus-summary-read-group
6286                     target-group nil no-article
6287                     (and (buffer-name current-buffer) current-buffer)
6288                     nil backward))
6289               (setq entered t)
6290             (setq current-group target-group
6291                   target-group nil)))))))
6292
6293 (defun gnus-summary-prev-group (&optional no-article)
6294   "Exit current newsgroup and then select previous unread newsgroup.
6295 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6296   (interactive "P")
6297   (gnus-summary-next-group no-article nil t))
6298
6299 ;; Walking around summary lines.
6300
6301 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6302   "Go to the first unread subject.
6303 If UNREAD is non-nil, go to the first unread article.
6304 Returns the article selected or nil if there are no unread articles."
6305   (interactive "P")
6306   (prog1
6307       (cond
6308        ;; Empty summary.
6309        ((null gnus-newsgroup-data)
6310         (gnus-message 3 "No articles in the group")
6311         nil)
6312        ;; Pick the first article.
6313        ((not unread)
6314         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6315         (gnus-data-number (car gnus-newsgroup-data)))
6316        ;; No unread articles.
6317        ((null gnus-newsgroup-unreads)
6318         (gnus-message 3 "No more unread articles")
6319         nil)
6320        ;; Find the first unread article.
6321        (t
6322         (let ((data gnus-newsgroup-data))
6323           (while (and data
6324                       (and (not (and undownloaded
6325                                      (eq gnus-undownloaded-mark
6326                                          (gnus-data-mark (car data)))))
6327                            (not (and unseen
6328                                      (memq (car data) gnus-newsgroup-unseen)))
6329                            (not (gnus-data-unread-p (car data)))))
6330             (setq data (cdr data)))
6331           (when data
6332             (goto-char (gnus-data-pos (car data)))
6333             (gnus-data-number (car data))))))
6334     (gnus-summary-position-point)))
6335
6336 (defun gnus-summary-next-subject (n &optional unread dont-display)
6337   "Go to next N'th summary line.
6338 If N is negative, go to the previous N'th subject line.
6339 If UNREAD is non-nil, only unread articles are selected.
6340 The difference between N and the actual number of steps taken is
6341 returned."
6342   (interactive "p")
6343   (let ((backward (< n 0))
6344         (n (abs n)))
6345     (while (and (> n 0)
6346                 (if backward
6347                     (gnus-summary-find-prev unread)
6348                   (gnus-summary-find-next unread)))
6349       (unless (zerop (setq n (1- n)))
6350         (gnus-summary-show-thread)))
6351     (when (/= 0 n)
6352       (gnus-message 7 "No more%s articles"
6353                     (if unread " unread" "")))
6354     (unless dont-display
6355       (gnus-summary-recenter)
6356       (gnus-summary-position-point))
6357     n))
6358
6359 (defun gnus-summary-next-unread-subject (n)
6360   "Go to next N'th unread summary line."
6361   (interactive "p")
6362   (gnus-summary-next-subject n t))
6363
6364 (defun gnus-summary-prev-subject (n &optional unread)
6365   "Go to previous N'th summary line.
6366 If optional argument UNREAD is non-nil, only unread article is selected."
6367   (interactive "p")
6368   (gnus-summary-next-subject (- n) unread))
6369
6370 (defun gnus-summary-prev-unread-subject (n)
6371   "Go to previous N'th unread summary line."
6372   (interactive "p")
6373   (gnus-summary-next-subject (- n) t))
6374
6375 (defun gnus-summary-goto-subject (article &optional force silent)
6376   "Go the subject line of ARTICLE.
6377 If FORCE, also allow jumping to articles not currently shown."
6378   (interactive "nArticle number: ")
6379   (let ((b (point))
6380         (data (gnus-data-find article)))
6381     ;; We read in the article if we have to.
6382     (and (not data)
6383          force
6384          (gnus-summary-insert-subject
6385           article
6386           (if (or (numberp force) (vectorp force)) force)
6387           t)
6388          (setq data (gnus-data-find article)))
6389     (goto-char b)
6390     (if (not data)
6391         (progn
6392           (unless silent
6393             (gnus-message 3 "Can't find article %d" article))
6394           nil)
6395       (let ((pt (gnus-data-pos data)))
6396         (goto-char pt)
6397         (gnus-summary-set-article-display-arrow pt))
6398       (gnus-summary-position-point)
6399       article)))
6400
6401 ;; Walking around summary lines with displaying articles.
6402
6403 (defun gnus-summary-expand-window (&optional arg)
6404   "Make the summary buffer take up the entire Emacs frame.
6405 Given a prefix, will force an `article' buffer configuration."
6406   (interactive "P")
6407   (if arg
6408       (gnus-configure-windows 'article 'force)
6409     (gnus-configure-windows 'summary 'force)))
6410
6411 (defun gnus-summary-display-article (article &optional all-header)
6412   "Display ARTICLE in article buffer."
6413   (when (gnus-buffer-live-p gnus-article-buffer)
6414     (with-current-buffer gnus-article-buffer
6415       (mm-enable-multibyte-mule4)))
6416   (gnus-set-global-variables)
6417   (when (gnus-buffer-live-p gnus-article-buffer)
6418     (with-current-buffer gnus-article-buffer
6419       (setq gnus-article-charset gnus-newsgroup-charset)
6420       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6421       (mm-enable-multibyte-mule4)))
6422   (if (null article)
6423       nil
6424     (prog1
6425         (if gnus-summary-display-article-function
6426             (funcall gnus-summary-display-article-function article all-header)
6427           (gnus-article-prepare article all-header))
6428       (gnus-run-hooks 'gnus-select-article-hook)
6429       (when (and gnus-current-article
6430                  (not (zerop gnus-current-article)))
6431         (gnus-summary-goto-subject gnus-current-article))
6432       (gnus-summary-recenter)
6433       (when (and gnus-use-trees gnus-show-threads)
6434         (gnus-possibly-generate-tree article)
6435         (gnus-highlight-selected-tree article))
6436       ;; Successfully display article.
6437       (gnus-article-set-window-start
6438        (cdr (assq article gnus-newsgroup-bookmarks))))))
6439
6440 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6441   "Select the current article.
6442 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6443 non-nil, the article will be re-fetched even if it already present in
6444 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6445 be displayed."
6446   ;; Make sure we are in the summary buffer to work around bbdb bug.
6447   (unless (eq major-mode 'gnus-summary-mode)
6448     (set-buffer gnus-summary-buffer))
6449   (let ((article (or article (gnus-summary-article-number)))
6450         (all-headers (not (not all-headers))) ;Must be t or nil.
6451         gnus-summary-display-article-function)
6452     (and (not pseudo)
6453          (gnus-summary-article-pseudo-p article)
6454          (error "This is a pseudo-article"))
6455     (save-excursion
6456       (set-buffer gnus-summary-buffer)
6457       (if (or (and gnus-single-article-buffer
6458                    (or (null gnus-current-article)
6459                        (null gnus-article-current)
6460                        (null (get-buffer gnus-article-buffer))
6461                        (not (eq article (cdr gnus-article-current)))
6462                        (not (equal (car gnus-article-current)
6463                                    gnus-newsgroup-name))))
6464               (and (not gnus-single-article-buffer)
6465                    (or (null gnus-current-article)
6466                        (not (eq gnus-current-article article))))
6467               force)
6468        ;; The requested article is different from the current article.
6469           (progn
6470             (gnus-summary-display-article article all-headers)
6471             (when (gnus-buffer-live-p gnus-article-buffer)
6472               (with-current-buffer gnus-article-buffer
6473                 (if (not gnus-article-decoded-p) ;; a local variable
6474                     (mm-disable-multibyte-mule4))))
6475             (when (or all-headers gnus-show-all-headers)
6476               (gnus-article-show-all-headers))
6477             (gnus-article-set-window-start
6478              (cdr (assq article gnus-newsgroup-bookmarks)))
6479             article)
6480         (when (or all-headers gnus-show-all-headers)
6481           (gnus-article-show-all-headers))
6482         'old))))
6483
6484 (defun gnus-summary-force-verify-and-decrypt ()
6485   (interactive)
6486   (let ((mm-verify-option 'known)
6487         (mm-decrypt-option 'known))
6488     (gnus-summary-select-article nil 'force)))
6489
6490 (defun gnus-summary-set-current-mark (&optional current-mark)
6491   "Obsolete function."
6492   nil)
6493
6494 (defun gnus-summary-next-article (&optional unread subject backward push)
6495   "Select the next article.
6496 If UNREAD, only unread articles are selected.
6497 If SUBJECT, only articles with SUBJECT are selected.
6498 If BACKWARD, the previous article is selected instead of the next."
6499   (interactive "P")
6500   (cond
6501    ;; Is there such an article?
6502    ((and (gnus-summary-search-forward unread subject backward)
6503          (or (gnus-summary-display-article (gnus-summary-article-number))
6504              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6505     (gnus-summary-position-point))
6506    ;; If not, we try the first unread, if that is wanted.
6507    ((and subject
6508          gnus-auto-select-same
6509          (gnus-summary-first-unread-article))
6510     (gnus-summary-position-point)
6511     (gnus-message 6 "Wrapped"))
6512    ;; Try to get next/previous article not displayed in this group.
6513    ((and gnus-auto-extend-newsgroup
6514          (not unread) (not subject))
6515     (gnus-summary-goto-article
6516      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6517      nil (count-lines (point-min) (point))))
6518    ;; Go to next/previous group.
6519    (t
6520     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6521       (gnus-summary-jump-to-group gnus-newsgroup-name))
6522     (let ((cmd last-command-char)
6523           (point
6524            (save-excursion
6525              (set-buffer gnus-group-buffer)
6526              (point)))
6527           (group
6528            (if (eq gnus-keep-same-level 'best)
6529                (gnus-summary-best-group gnus-newsgroup-name)
6530              (gnus-summary-search-group backward gnus-keep-same-level))))
6531       ;; For some reason, the group window gets selected.  We change
6532       ;; it back.
6533       (select-window (get-buffer-window (current-buffer)))
6534       ;; Select next unread newsgroup automagically.
6535       (cond
6536        ((or (not gnus-auto-select-next)
6537             (not cmd))
6538         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6539        ((or (eq gnus-auto-select-next 'quietly)
6540             (and (eq gnus-auto-select-next 'slightly-quietly)
6541                  push)
6542             (and (eq gnus-auto-select-next 'almost-quietly)
6543                  (gnus-summary-last-article-p)))
6544         ;; Select quietly.
6545         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6546             (gnus-summary-exit)
6547           (gnus-message 7 "No more%s articles (%s)..."
6548                         (if unread " unread" "")
6549                         (if group (concat "selecting " group)
6550                           "exiting"))
6551           (gnus-summary-next-group nil group backward)))
6552        (t
6553         (when (gnus-key-press-event-p last-input-event)
6554           (gnus-summary-walk-group-buffer
6555            gnus-newsgroup-name cmd unread backward point))))))))
6556
6557 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6558   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6559                       (?\C-p (gnus-group-prev-unread-group 1))))
6560         (cursor-in-echo-area t)
6561         keve key group ended)
6562     (save-excursion
6563       (set-buffer gnus-group-buffer)
6564       (goto-char start)
6565       (setq group
6566             (if (eq gnus-keep-same-level 'best)
6567                 (gnus-summary-best-group gnus-newsgroup-name)
6568               (gnus-summary-search-group backward gnus-keep-same-level))))
6569     (while (not ended)
6570       (gnus-message
6571        5 "No more%s articles%s" (if unread " unread" "")
6572        (if (and group
6573                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6574            (format " (Type %s for %s [%s])"
6575                    (single-key-description cmd) group
6576                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6577          (format " (Type %s to exit %s)"
6578                  (single-key-description cmd)
6579                  gnus-newsgroup-name)))
6580       ;; Confirm auto selection.
6581       (setq key (car (setq keve (gnus-read-event-char))))
6582       (setq ended t)
6583       (cond
6584        ((assq key keystrokes)
6585         (let ((obuf (current-buffer)))
6586           (switch-to-buffer gnus-group-buffer)
6587           (when group
6588             (gnus-group-jump-to-group group))
6589           (eval (cadr (assq key keystrokes)))
6590           (setq group (gnus-group-group-name))
6591           (switch-to-buffer obuf))
6592         (setq ended nil))
6593        ((equal key cmd)
6594         (if (or (not group)
6595                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6596             (gnus-summary-exit)
6597           (gnus-summary-next-group nil group backward)))
6598        (t
6599         (push (cdr keve) unread-command-events))))))
6600
6601 (defun gnus-summary-next-unread-article ()
6602   "Select unread article after current one."
6603   (interactive)
6604   (gnus-summary-next-article
6605    (or (not (eq gnus-summary-goto-unread 'never))
6606        (gnus-summary-last-article-p (gnus-summary-article-number)))
6607    (and gnus-auto-select-same
6608         (gnus-summary-article-subject))))
6609
6610 (defun gnus-summary-prev-article (&optional unread subject)
6611   "Select the article after the current one.
6612 If UNREAD is non-nil, only unread articles are selected."
6613   (interactive "P")
6614   (gnus-summary-next-article unread subject t))
6615
6616 (defun gnus-summary-prev-unread-article ()
6617   "Select unread article before current one."
6618   (interactive)
6619   (gnus-summary-prev-article
6620    (or (not (eq gnus-summary-goto-unread 'never))
6621        (gnus-summary-first-article-p (gnus-summary-article-number)))
6622    (and gnus-auto-select-same
6623         (gnus-summary-article-subject))))
6624
6625 (defun gnus-summary-next-page (&optional lines circular)
6626   "Show next page of the selected article.
6627 If at the end of the current article, select the next article.
6628 LINES says how many lines should be scrolled up.
6629
6630 If CIRCULAR is non-nil, go to the start of the article instead of
6631 selecting the next article when reaching the end of the current
6632 article."
6633   (interactive "P")
6634   (setq gnus-summary-buffer (current-buffer))
6635   (gnus-set-global-variables)
6636   (let ((article (gnus-summary-article-number))
6637         (article-window (get-buffer-window gnus-article-buffer t))
6638         endp)
6639     ;; If the buffer is empty, we have no article.
6640     (unless article
6641       (error "No article to select"))
6642     (gnus-configure-windows 'article)
6643     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6644         (if (and (eq gnus-summary-goto-unread 'never)
6645                  (not (gnus-summary-last-article-p article)))
6646             (gnus-summary-next-article)
6647           (gnus-summary-next-unread-article))
6648       (if (or (null gnus-current-article)
6649               (null gnus-article-current)
6650               (/= article (cdr gnus-article-current))
6651               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6652           ;; Selected subject is different from current article's.
6653           (gnus-summary-display-article article)
6654         (when article-window
6655           (gnus-eval-in-buffer-window gnus-article-buffer
6656             (setq endp (gnus-article-next-page lines)))
6657           (when endp
6658             (cond (circular
6659                    (gnus-summary-beginning-of-article))
6660                   (lines
6661                    (gnus-message 3 "End of message"))
6662                   ((null lines)
6663                    (if (and (eq gnus-summary-goto-unread 'never)
6664                             (not (gnus-summary-last-article-p article)))
6665                        (gnus-summary-next-article)
6666                      (gnus-summary-next-unread-article))))))))
6667     (gnus-summary-recenter)
6668     (gnus-summary-position-point)))
6669
6670 (defun gnus-summary-prev-page (&optional lines move)
6671   "Show previous page of selected article.
6672 Argument LINES specifies lines to be scrolled down.
6673 If MOVE, move to the previous unread article if point is at
6674 the beginning of the buffer."
6675   (interactive "P")
6676   (let ((article (gnus-summary-article-number))
6677         (article-window (get-buffer-window gnus-article-buffer t))
6678         endp)
6679     (gnus-configure-windows 'article)
6680     (if (or (null gnus-current-article)
6681             (null gnus-article-current)
6682             (/= article (cdr gnus-article-current))
6683             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6684         ;; Selected subject is different from current article's.
6685         (gnus-summary-display-article article)
6686       (gnus-summary-recenter)
6687       (when article-window
6688         (gnus-eval-in-buffer-window gnus-article-buffer
6689           (setq endp (gnus-article-prev-page lines)))
6690         (when (and move endp)
6691           (cond (lines
6692                  (gnus-message 3 "Beginning of message"))
6693                 ((null lines)
6694                  (if (and (eq gnus-summary-goto-unread 'never)
6695                           (not (gnus-summary-first-article-p article)))
6696                      (gnus-summary-prev-article)
6697                    (gnus-summary-prev-unread-article))))))))
6698   (gnus-summary-position-point))
6699
6700 (defun gnus-summary-prev-page-or-article (&optional lines)
6701   "Show previous page of selected article.
6702 Argument LINES specifies lines to be scrolled down.
6703 If at the beginning of the article, go to the next article."
6704   (interactive "P")
6705   (gnus-summary-prev-page lines t))
6706
6707 (defun gnus-summary-scroll-up (lines)
6708   "Scroll up (or down) one line current article.
6709 Argument LINES specifies lines to be scrolled up (or down if negative)."
6710   (interactive "p")
6711   (gnus-configure-windows 'article)
6712   (gnus-summary-show-thread)
6713   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6714     (gnus-eval-in-buffer-window gnus-article-buffer
6715       (cond ((> lines 0)
6716              (when (gnus-article-next-page lines)
6717                (gnus-message 3 "End of message")))
6718             ((< lines 0)
6719              (gnus-article-prev-page (- lines))))))
6720   (gnus-summary-recenter)
6721   (gnus-summary-position-point))
6722
6723 (defun gnus-summary-scroll-down (lines)
6724   "Scroll down (or up) one line current article.
6725 Argument LINES specifies lines to be scrolled down (or up if negative)."
6726   (interactive "p")
6727   (gnus-summary-scroll-up (- lines)))
6728
6729 (defun gnus-summary-next-same-subject ()
6730   "Select next article which has the same subject as current one."
6731   (interactive)
6732   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6733
6734 (defun gnus-summary-prev-same-subject ()
6735   "Select previous article which has the same subject as current one."
6736   (interactive)
6737   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6738
6739 (defun gnus-summary-next-unread-same-subject ()
6740   "Select next unread article which has the same subject as current one."
6741   (interactive)
6742   (gnus-summary-next-article t (gnus-summary-article-subject)))
6743
6744 (defun gnus-summary-prev-unread-same-subject ()
6745   "Select previous unread article which has the same subject as current one."
6746   (interactive)
6747   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6748
6749 (defun gnus-summary-first-unread-article ()
6750   "Select the first unread article.
6751 Return nil if there are no unread articles."
6752   (interactive)
6753   (prog1
6754       (when (gnus-summary-first-subject t)
6755         (gnus-summary-show-thread)
6756         (gnus-summary-first-subject t)
6757         (gnus-summary-display-article (gnus-summary-article-number)))
6758     (gnus-summary-position-point)))
6759
6760 (defun gnus-summary-first-unread-subject ()
6761   "Place the point on the subject line of the first unread article.
6762 Return nil if there are no unread articles."
6763   (interactive)
6764   (prog1
6765       (when (gnus-summary-first-subject t)
6766         (gnus-summary-show-thread)
6767         (gnus-summary-first-subject t))
6768     (gnus-summary-position-point)))
6769
6770 (defun gnus-summary-first-unseen-subject ()
6771   "Place the point on the subject line of the first unseen article.
6772 Return nil if there are no unseen articles."
6773   (interactive)
6774   (prog1
6775       (when (gnus-summary-first-subject t t t)
6776         (gnus-summary-show-thread)
6777         (gnus-summary-first-subject t t t))
6778     (gnus-summary-position-point)))
6779
6780 (defun gnus-summary-first-article ()
6781   "Select the first article.
6782 Return nil if there are no articles."
6783   (interactive)
6784   (prog1
6785       (when (gnus-summary-first-subject)
6786         (gnus-summary-show-thread)
6787         (gnus-summary-first-subject)
6788         (gnus-summary-display-article (gnus-summary-article-number)))
6789     (gnus-summary-position-point)))
6790
6791 (defun gnus-summary-best-unread-article ()
6792   "Select the unread article with the highest score."
6793   (interactive)
6794   (let ((article (gnus-summary-best-unread-subject)))
6795     (if article
6796         (gnus-summary-goto-article article)
6797       (error "No unread articles"))))
6798
6799 (defun gnus-summary-best-unread-subject ()
6800   "Select the unread subject with the highest score."
6801   (interactive)
6802   (let ((best -1000000)
6803         (data gnus-newsgroup-data)
6804         article score)
6805     (while data
6806       (and (gnus-data-unread-p (car data))
6807            (> (setq score
6808                     (gnus-summary-article-score (gnus-data-number (car data))))
6809               best)
6810            (setq best score
6811                  article (gnus-data-number (car data))))
6812       (setq data (cdr data)))
6813     (gnus-summary-position-point)
6814     article))
6815
6816 (defun gnus-summary-last-subject ()
6817   "Go to the last displayed subject line in the group."
6818   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6819     (when article
6820       (gnus-summary-goto-subject article))))
6821
6822 (defun gnus-summary-goto-article (article &optional all-headers force)
6823   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6824 If ALL-HEADERS is non-nil, no header lines are hidden.
6825 If FORCE, go to the article even if it isn't displayed.  If FORCE
6826 is a number, it is the line the article is to be displayed on."
6827   (interactive
6828    (list
6829     (completing-read
6830      "Article number or Message-ID: "
6831      (mapcar (lambda (number) (list (int-to-string number)))
6832              gnus-newsgroup-limit))
6833     current-prefix-arg
6834     t))
6835   (prog1
6836       (if (and (stringp article)
6837                (string-match "@" article))
6838           (gnus-summary-refer-article article)
6839         (when (stringp article)
6840           (setq article (string-to-number article)))
6841         (if (gnus-summary-goto-subject article force)
6842             (gnus-summary-display-article article all-headers)
6843           (gnus-message 4 "Couldn't go to article %s" article) nil))
6844     (gnus-summary-position-point)))
6845
6846 (defun gnus-summary-goto-last-article ()
6847   "Go to the previously read article."
6848   (interactive)
6849   (prog1
6850       (when gnus-last-article
6851         (gnus-summary-goto-article gnus-last-article nil t))
6852     (gnus-summary-position-point)))
6853
6854 (defun gnus-summary-pop-article (number)
6855   "Pop one article off the history and go to the previous.
6856 NUMBER articles will be popped off."
6857   (interactive "p")
6858   (let (to)
6859     (setq gnus-newsgroup-history
6860           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6861     (if to
6862         (gnus-summary-goto-article (car to) nil t)
6863       (error "Article history empty")))
6864   (gnus-summary-position-point))
6865
6866 ;; Summary commands and functions for limiting the summary buffer.
6867
6868 (defun gnus-summary-limit-to-articles (n)
6869   "Limit the summary buffer to the next N articles.
6870 If not given a prefix, use the process marked articles instead."
6871   (interactive "P")
6872   (prog1
6873       (let ((articles (gnus-summary-work-articles n)))
6874         (setq gnus-newsgroup-processable nil)
6875         (gnus-summary-limit articles))
6876     (gnus-summary-position-point)))
6877
6878 (defun gnus-summary-pop-limit (&optional total)
6879   "Restore the previous limit.
6880 If given a prefix, remove all limits."
6881   (interactive "P")
6882   (when total
6883     (setq gnus-newsgroup-limits
6884           (list (mapcar (lambda (h) (mail-header-number h))
6885                         gnus-newsgroup-headers))))
6886   (unless gnus-newsgroup-limits
6887     (error "No limit to pop"))
6888   (prog1
6889       (gnus-summary-limit nil 'pop)
6890     (gnus-summary-position-point)))
6891
6892 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6893   "Limit the summary buffer to articles that have subjects that match a regexp.
6894 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6895   (interactive
6896    (list (read-string (if current-prefix-arg
6897                           "Exclude subject (regexp): "
6898                         "Limit to subject (regexp): "))
6899          nil current-prefix-arg))
6900   (unless header
6901     (setq header "subject"))
6902   (when (not (equal "" subject))
6903     (prog1
6904         (let ((articles (gnus-summary-find-matching
6905                          (or header "subject") subject 'all nil nil
6906                          not-matching)))
6907           (unless articles
6908             (error "Found no matches for \"%s\"" subject))
6909           (gnus-summary-limit articles))
6910       (gnus-summary-position-point))))
6911
6912 (defun gnus-summary-limit-to-author (from &optional not-matching)
6913   "Limit the summary buffer to articles that have authors that match a regexp.
6914 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6915   (interactive
6916    (list (read-string (if current-prefix-arg
6917                           "Exclude author (regexp): "
6918                         "Limit to author (regexp): "))
6919          current-prefix-arg))
6920   (gnus-summary-limit-to-subject from "from" not-matching))
6921
6922 (defun gnus-summary-limit-to-age (age &optional younger-p)
6923   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6924 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6925 articles that are younger than AGE days."
6926   (interactive
6927    (let ((younger current-prefix-arg)
6928          (days-got nil)
6929          days)
6930      (while (not days-got)
6931        (setq days (if younger
6932                       (read-string "Limit to articles within (in days): ")
6933                     (read-string "Limit to articles older than (in days): ")))
6934        (when (> (length days) 0)
6935          (setq days (read days)))
6936        (if (numberp days)
6937            (progn 
6938              (setq days-got t)
6939              (if (< days 0)
6940                  (progn 
6941                    (setq younger (not younger))
6942                    (setq days (* days -1)))))
6943          (message "Please enter a number.")
6944          (sleep-for 1)))
6945      (list days younger)))
6946   (prog1
6947       (let ((data gnus-newsgroup-data)
6948             (cutoff (days-to-time age))
6949             articles d date is-younger)
6950         (while (setq d (pop data))
6951           (when (and (vectorp (gnus-data-header d))
6952                      (setq date (mail-header-date (gnus-data-header d))))
6953             (setq is-younger (time-less-p
6954                               (time-since (condition-case ()
6955                                               (date-to-time date)
6956                                             (error '(0 0))))
6957                               cutoff))
6958             (when (if younger-p
6959                       is-younger
6960                     (not is-younger))
6961               (push (gnus-data-number d) articles))))
6962         (gnus-summary-limit (nreverse articles)))
6963     (gnus-summary-position-point)))
6964
6965 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
6966   "Limit the summary buffer to articles that match an 'extra' header."
6967   (interactive
6968    (let ((header
6969           (intern
6970            (gnus-completing-read
6971             (symbol-name (car gnus-extra-headers))
6972             (if current-prefix-arg
6973                 "Exclude extra header:"
6974               "Limit extra header:")
6975             (mapcar (lambda (x)
6976                       (cons (symbol-name x) x))
6977                     gnus-extra-headers)
6978             nil
6979             t))))
6980      (list header
6981            (read-string (format "%s header %s (regexp): "
6982                                 (if current-prefix-arg "Exclude" "Limit to")
6983                                 header))
6984            current-prefix-arg)))
6985   (when (not (equal "" regexp))
6986     (prog1
6987         (let ((articles (gnus-summary-find-matching
6988                          (cons 'extra header) regexp 'all nil nil
6989                          not-matching)))
6990           (unless articles
6991             (error "Found no matches for \"%s\"" regexp))
6992           (gnus-summary-limit articles))
6993       (gnus-summary-position-point))))
6994
6995 (defun gnus-summary-limit-to-display-predicate ()
6996   "Limit the summary buffer to the predicated in the `display' group parameter."
6997   (interactive)
6998   (unless gnus-newsgroup-display
6999     (error "There is no `display' group parameter"))
7000   (let (articles)
7001     (dolist (number gnus-newsgroup-articles)
7002       (when (funcall gnus-newsgroup-display)
7003         (push number articles)))
7004     (gnus-summary-limit articles))
7005   (gnus-summary-position-point))
7006
7007 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7008 (make-obsolete
7009  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7010
7011 (defun gnus-summary-limit-to-unread (&optional all)
7012   "Limit the summary buffer to articles that are not marked as read.
7013 If ALL is non-nil, limit strictly to unread articles."
7014   (interactive "P")
7015   (if all
7016       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7017     (gnus-summary-limit-to-marks
7018      ;; Concat all the marks that say that an article is read and have
7019      ;; those removed.
7020      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7021            gnus-killed-mark gnus-kill-file-mark
7022            gnus-low-score-mark gnus-expirable-mark
7023            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7024            gnus-duplicate-mark gnus-souped-mark)
7025      'reverse)))
7026
7027 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7028 (make-obsolete 'gnus-summary-delete-marked-with
7029                'gnus-summary-limit-exlude-marks)
7030
7031 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7032   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7033 If REVERSE, limit the summary buffer to articles that are marked
7034 with MARKS.  MARKS can either be a string of marks or a list of marks.
7035 Returns how many articles were removed."
7036   (interactive "sMarks: ")
7037   (gnus-summary-limit-to-marks marks t))
7038
7039 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7040   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7041 If REVERSE (the prefix), limit the summary buffer to articles that are
7042 not marked with MARKS.  MARKS can either be a string of marks or a
7043 list of marks.
7044 Returns how many articles were removed."
7045   (interactive "sMarks: \nP")
7046   (prog1
7047       (let ((data gnus-newsgroup-data)
7048             (marks (if (listp marks) marks
7049                      (append marks nil))) ; Transform to list.
7050             articles)
7051         (while data
7052           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7053                   (memq (gnus-data-mark (car data)) marks))
7054             (push (gnus-data-number (car data)) articles))
7055           (setq data (cdr data)))
7056         (gnus-summary-limit articles))
7057     (gnus-summary-position-point)))
7058
7059 (defun gnus-summary-limit-to-score (score)
7060   "Limit to articles with score at or above SCORE."
7061   (interactive "NLimit to articles with score of at least: ")
7062   (let ((data gnus-newsgroup-data)
7063         articles)
7064     (while data
7065       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7066                 score)
7067         (push (gnus-data-number (car data)) articles))
7068       (setq data (cdr data)))
7069     (prog1
7070         (gnus-summary-limit articles)
7071       (gnus-summary-position-point))))
7072
7073 (defun gnus-summary-limit-include-thread (id)
7074   "Display all the hidden articles that is in the thread with ID in it.
7075 When called interactively, ID is the Message-ID of the current
7076 article."
7077   (interactive (list (mail-header-id (gnus-summary-article-header))))
7078   (let ((articles (gnus-articles-in-thread
7079                    (gnus-id-to-thread (gnus-root-id id)))))
7080     (prog1
7081         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7082       (gnus-summary-limit-include-matching-articles
7083        "subject"
7084        (regexp-quote (gnus-simplify-subject-re
7085                       (mail-header-subject (gnus-id-to-header id)))))
7086       (gnus-summary-position-point))))
7087
7088 (defun gnus-summary-limit-include-matching-articles (header regexp)
7089   "Display all the hidden articles that have HEADERs that match REGEXP."
7090   (interactive (list (read-string "Match on header: ")
7091                      (read-string "Regexp: ")))
7092   (let ((articles (gnus-find-matching-articles header regexp)))
7093     (prog1
7094         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7095       (gnus-summary-position-point))))
7096
7097 (defun gnus-summary-limit-include-dormant ()
7098   "Display all the hidden articles that are marked as dormant.
7099 Note that this command only works on a subset of the articles currently
7100 fetched for this group."
7101   (interactive)
7102   (unless gnus-newsgroup-dormant
7103     (error "There are no dormant articles in this group"))
7104   (prog1
7105       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7106     (gnus-summary-position-point)))
7107
7108 (defun gnus-summary-limit-exclude-dormant ()
7109   "Hide all dormant articles."
7110   (interactive)
7111   (prog1
7112       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7113     (gnus-summary-position-point)))
7114
7115 (defun gnus-summary-limit-exclude-childless-dormant ()
7116   "Hide all dormant articles that have no children."
7117   (interactive)
7118   (let ((data (gnus-data-list t))
7119         articles d children)
7120     ;; Find all articles that are either not dormant or have
7121     ;; children.
7122     (while (setq d (pop data))
7123       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7124                 (and (setq children
7125                            (gnus-article-children (gnus-data-number d)))
7126                      (let (found)
7127                        (while children
7128                          (when (memq (car children) articles)
7129                            (setq children nil
7130                                  found t))
7131                          (pop children))
7132                        found)))
7133         (push (gnus-data-number d) articles)))
7134     ;; Do the limiting.
7135     (prog1
7136         (gnus-summary-limit articles)
7137       (gnus-summary-position-point))))
7138
7139 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7140   "Mark all unread excluded articles as read.
7141 If ALL, mark even excluded ticked and dormants as read."
7142   (interactive "P")
7143   (let ((articles (gnus-sorted-complement
7144                    (sort
7145                     (mapcar (lambda (h) (mail-header-number h))
7146                             gnus-newsgroup-headers)
7147                     '<)
7148                    (sort gnus-newsgroup-limit '<)))
7149         article)
7150     (setq gnus-newsgroup-unreads
7151           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7152     (if all
7153         (setq gnus-newsgroup-dormant nil
7154               gnus-newsgroup-marked nil
7155               gnus-newsgroup-reads
7156               (nconc
7157                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7158                gnus-newsgroup-reads))
7159       (while (setq article (pop articles))
7160         (unless (or (memq article gnus-newsgroup-dormant)
7161                     (memq article gnus-newsgroup-marked))
7162           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7163
7164 (defun gnus-summary-limit (articles &optional pop)
7165   (if pop
7166       ;; We pop the previous limit off the stack and use that.
7167       (setq articles (car gnus-newsgroup-limits)
7168             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7169     ;; We use the new limit, so we push the old limit on the stack.
7170     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7171   ;; Set the limit.
7172   (setq gnus-newsgroup-limit articles)
7173   (let ((total (length gnus-newsgroup-data))
7174         (data (gnus-data-find-list (gnus-summary-article-number)))
7175         (gnus-summary-mark-below nil)   ; Inhibit this.
7176         found)
7177     ;; This will do all the work of generating the new summary buffer
7178     ;; according to the new limit.
7179     (gnus-summary-prepare)
7180     ;; Hide any threads, possibly.
7181     (and gnus-show-threads
7182          gnus-thread-hide-subtree
7183          (gnus-summary-hide-all-threads))
7184     ;; Try to return to the article you were at, or one in the
7185     ;; neighborhood.
7186     (when data
7187       ;; We try to find some article after the current one.
7188       (while data
7189         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7190           (setq data nil
7191                 found t))
7192         (setq data (cdr data))))
7193     (unless found
7194       ;; If there is no data, that means that we were after the last
7195       ;; article.  The same goes when we can't find any articles
7196       ;; after the current one.
7197       (goto-char (point-max))
7198       (gnus-summary-find-prev))
7199     (gnus-set-mode-line 'summary)
7200     ;; We return how many articles were removed from the summary
7201     ;; buffer as a result of the new limit.
7202     (- total (length gnus-newsgroup-data))))
7203
7204 (defsubst gnus-invisible-cut-children (threads)
7205   (let ((num 0))
7206     (while threads
7207       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7208         (incf num))
7209       (pop threads))
7210     (< num 2)))
7211
7212 (defsubst gnus-cut-thread (thread)
7213   "Go forwards in the thread until we find an article that we want to display."
7214   (when (or (eq gnus-fetch-old-headers 'some)
7215             (eq gnus-fetch-old-headers 'invisible)
7216             (numberp gnus-fetch-old-headers)
7217             (eq gnus-build-sparse-threads 'some)
7218             (eq gnus-build-sparse-threads 'more))
7219     ;; Deal with old-fetched headers and sparse threads.
7220     (while (and
7221             thread
7222             (or
7223              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7224              (gnus-summary-article-ancient-p
7225               (mail-header-number (car thread))))
7226             (if (or (<= (length (cdr thread)) 1)
7227                     (eq gnus-fetch-old-headers 'invisible))
7228                 (setq gnus-newsgroup-limit
7229                       (delq (mail-header-number (car thread))
7230                             gnus-newsgroup-limit)
7231                       thread (cadr thread))
7232               (when (gnus-invisible-cut-children (cdr thread))
7233                 (let ((th (cdr thread)))
7234                   (while th
7235                     (if (memq (mail-header-number (caar th))
7236                               gnus-newsgroup-limit)
7237                         (setq thread (car th)
7238                               th nil)
7239                       (setq th (cdr th))))))))))
7240   thread)
7241
7242 (defun gnus-cut-threads (threads)
7243   "Cut off all uninteresting articles from the beginning of threads."
7244   (when (or (eq gnus-fetch-old-headers 'some)
7245             (eq gnus-fetch-old-headers 'invisible)
7246             (numberp gnus-fetch-old-headers)
7247             (eq gnus-build-sparse-threads 'some)
7248             (eq gnus-build-sparse-threads 'more))
7249     (let ((th threads))
7250       (while th
7251         (setcar th (gnus-cut-thread (car th)))
7252         (setq th (cdr th)))))
7253   ;; Remove nixed out threads.
7254   (delq nil threads))
7255
7256 (defun gnus-summary-initial-limit (&optional show-if-empty)
7257   "Figure out what the initial limit is supposed to be on group entry.
7258 This entails weeding out unwanted dormants, low-scored articles,
7259 fetch-old-headers verbiage, and so on."
7260   ;; Most groups have nothing to remove.
7261   (if (or gnus-inhibit-limiting
7262           (and (null gnus-newsgroup-dormant)
7263                (eq gnus-newsgroup-display 'gnus-not-ignore)
7264                (not (eq gnus-fetch-old-headers 'some))
7265                (not (numberp gnus-fetch-old-headers))
7266                (not (eq gnus-fetch-old-headers 'invisible))
7267                (null gnus-summary-expunge-below)
7268                (not (eq gnus-build-sparse-threads 'some))
7269                (not (eq gnus-build-sparse-threads 'more))
7270                (null gnus-thread-expunge-below)
7271                (not gnus-use-nocem)))
7272       ()                                ; Do nothing.
7273     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7274     (setq gnus-newsgroup-limit nil)
7275     (mapatoms
7276      (lambda (node)
7277        (unless (car (symbol-value node))
7278          ;; These threads have no parents -- they are roots.
7279          (let ((nodes (cdr (symbol-value node)))
7280                thread)
7281            (while nodes
7282              (if (and gnus-thread-expunge-below
7283                       (< (gnus-thread-total-score (car nodes))
7284                          gnus-thread-expunge-below))
7285                  (gnus-expunge-thread (pop nodes))
7286                (setq thread (pop nodes))
7287                (gnus-summary-limit-children thread))))))
7288      gnus-newsgroup-dependencies)
7289     ;; If this limitation resulted in an empty group, we might
7290     ;; pop the previous limit and use it instead.
7291     (when (and (not gnus-newsgroup-limit)
7292                show-if-empty)
7293       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7294     gnus-newsgroup-limit))
7295
7296 (defun gnus-summary-limit-children (thread)
7297   "Return 1 if this subthread is visible and 0 if it is not."
7298   ;; First we get the number of visible children to this thread.  This
7299   ;; is done by recursing down the thread using this function, so this
7300   ;; will really go down to a leaf article first, before slowly
7301   ;; working its way up towards the root.
7302   (when thread
7303     (let ((children
7304            (if (cdr thread)
7305                (apply '+ (mapcar 'gnus-summary-limit-children
7306                                  (cdr thread)))
7307              0))
7308           (number (mail-header-number (car thread)))
7309           score)
7310       (if (and
7311            (not (memq number gnus-newsgroup-marked))
7312            (or
7313             ;; If this article is dormant and has absolutely no visible
7314             ;; children, then this article isn't visible.
7315             (and (memq number gnus-newsgroup-dormant)
7316                  (zerop children))
7317             ;; If this is "fetch-old-headered" and there is no
7318             ;; visible children, then we don't want this article.
7319             (and (or (eq gnus-fetch-old-headers 'some)
7320                      (numberp gnus-fetch-old-headers))
7321                  (gnus-summary-article-ancient-p number)
7322                  (zerop children))
7323             ;; If this is "fetch-old-headered" and `invisible', then
7324             ;; we don't want this article.
7325             (and (eq gnus-fetch-old-headers 'invisible)
7326                  (gnus-summary-article-ancient-p number))
7327             ;; If this is a sparsely inserted article with no children,
7328             ;; we don't want it.
7329             (and (eq gnus-build-sparse-threads 'some)
7330                  (gnus-summary-article-sparse-p number)
7331                  (zerop children))
7332             ;; If we use expunging, and this article is really
7333             ;; low-scored, then we don't want this article.
7334             (when (and gnus-summary-expunge-below
7335                        (< (setq score
7336                                 (or (cdr (assq number gnus-newsgroup-scored))
7337                                     gnus-summary-default-score))
7338                           gnus-summary-expunge-below))
7339               ;; We increase the expunge-tally here, but that has
7340               ;; nothing to do with the limits, really.
7341               (incf gnus-newsgroup-expunged-tally)
7342               ;; We also mark as read here, if that's wanted.
7343               (when (and gnus-summary-mark-below
7344                          (< score gnus-summary-mark-below))
7345                 (setq gnus-newsgroup-unreads
7346                       (delq number gnus-newsgroup-unreads))
7347                 (if gnus-newsgroup-auto-expire
7348                     (push number gnus-newsgroup-expirable)
7349                   (push (cons number gnus-low-score-mark)
7350                         gnus-newsgroup-reads)))
7351               t)
7352             ;; Do the `display' group parameter.
7353             (and gnus-newsgroup-display
7354                  (not (funcall gnus-newsgroup-display)))
7355             ;; Check NoCeM things.
7356             (if (and gnus-use-nocem
7357                      (gnus-nocem-unwanted-article-p
7358                       (mail-header-id (car thread))))
7359                 (progn
7360                   (setq gnus-newsgroup-unreads
7361                         (delq number gnus-newsgroup-unreads))
7362                   t))))
7363           ;; Nope, invisible article.
7364           0
7365         ;; Ok, this article is to be visible, so we add it to the limit
7366         ;; and return 1.
7367         (push number gnus-newsgroup-limit)
7368         1))))
7369
7370 (defun gnus-expunge-thread (thread)
7371   "Mark all articles in THREAD as read."
7372   (let* ((number (mail-header-number (car thread))))
7373     (incf gnus-newsgroup-expunged-tally)
7374     ;; We also mark as read here, if that's wanted.
7375     (setq gnus-newsgroup-unreads
7376           (delq number gnus-newsgroup-unreads))
7377     (if gnus-newsgroup-auto-expire
7378         (push number gnus-newsgroup-expirable)
7379       (push (cons number gnus-low-score-mark)
7380             gnus-newsgroup-reads)))
7381   ;; Go recursively through all subthreads.
7382   (mapcar 'gnus-expunge-thread (cdr thread)))
7383
7384 ;; Summary article oriented commands
7385
7386 (defun gnus-summary-refer-parent-article (n)
7387   "Refer parent article N times.
7388 If N is negative, go to ancestor -N instead.
7389 The difference between N and the number of articles fetched is returned."
7390   (interactive "p")
7391   (let ((skip 1)
7392         error header ref)
7393     (when (not (natnump n))
7394       (setq skip (abs n)
7395             n 1))
7396     (while (and (> n 0)
7397                 (not error))
7398       (setq header (gnus-summary-article-header))
7399       (if (and (eq (mail-header-number header)
7400                    (cdr gnus-article-current))
7401                (equal gnus-newsgroup-name
7402                       (car gnus-article-current)))
7403           ;; If we try to find the parent of the currently
7404           ;; displayed article, then we take a look at the actual
7405           ;; References header, since this is slightly more
7406           ;; reliable than the References field we got from the
7407           ;; server.
7408           (save-excursion
7409             (set-buffer gnus-original-article-buffer)
7410             (nnheader-narrow-to-headers)
7411             (unless (setq ref (message-fetch-field "references"))
7412               (setq ref (message-fetch-field "in-reply-to")))
7413             (widen))
7414         (setq ref
7415               ;; It's not the current article, so we take a bet on
7416               ;; the value we got from the server.
7417               (mail-header-references header)))
7418       (if (and ref
7419                (not (equal ref "")))
7420           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7421             (gnus-message 1 "Couldn't find parent"))
7422         (gnus-message 1 "No references in article %d"
7423                       (gnus-summary-article-number))
7424         (setq error t))
7425       (decf n))
7426     (gnus-summary-position-point)
7427     n))
7428
7429 (defun gnus-summary-refer-references ()
7430   "Fetch all articles mentioned in the References header.
7431 Return the number of articles fetched."
7432   (interactive)
7433   (let ((ref (mail-header-references (gnus-summary-article-header)))
7434         (current (gnus-summary-article-number))
7435         (n 0))
7436     (if (or (not ref)
7437             (equal ref ""))
7438         (error "No References in the current article")
7439       ;; For each Message-ID in the References header...
7440       (while (string-match "<[^>]*>" ref)
7441         (incf n)
7442         ;; ... fetch that article.
7443         (gnus-summary-refer-article
7444          (prog1 (match-string 0 ref)
7445            (setq ref (substring ref (match-end 0))))))
7446       (gnus-summary-goto-subject current)
7447       (gnus-summary-position-point)
7448       n)))
7449
7450 (defun gnus-summary-refer-thread (&optional limit)
7451   "Fetch all articles in the current thread.
7452 If LIMIT (the numerical prefix), fetch that many old headers instead
7453 of what's specified by the `gnus-refer-thread-limit' variable."
7454   (interactive "P")
7455   (let ((id (mail-header-id (gnus-summary-article-header)))
7456         (limit (if limit (prefix-numeric-value limit)
7457                  gnus-refer-thread-limit)))
7458     ;; We want to fetch LIMIT *old* headers, but we also have to
7459     ;; re-fetch all the headers in the current buffer, because many of
7460     ;; them may be undisplayed.  So we adjust LIMIT.
7461     (when (numberp limit)
7462       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7463     (unless (eq gnus-fetch-old-headers 'invisible)
7464       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7465       ;; Retrieve the headers and read them in.
7466       (if (eq (gnus-retrieve-headers
7467                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7468               'nov)
7469           (gnus-build-all-threads)
7470         (error "Can't fetch thread from backends that don't support NOV"))
7471       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7472     (gnus-summary-limit-include-thread id)))
7473
7474 (defun gnus-summary-refer-article (message-id)
7475   "Fetch an article specified by MESSAGE-ID."
7476   (interactive "sMessage-ID: ")
7477   (when (and (stringp message-id)
7478              (not (zerop (length message-id))))
7479     ;; Construct the correct Message-ID if necessary.
7480     ;; Suggested by tale@pawl.rpi.edu.
7481     (unless (string-match "^<" message-id)
7482       (setq message-id (concat "<" message-id)))
7483     (unless (string-match ">$" message-id)
7484       (setq message-id (concat message-id ">")))
7485     (let* ((header (gnus-id-to-header message-id))
7486            (sparse (and header
7487                         (gnus-summary-article-sparse-p
7488                          (mail-header-number header))
7489                         (memq (mail-header-number header)
7490                               gnus-newsgroup-limit)))
7491            number)
7492       (cond
7493        ;; If the article is present in the buffer we just go to it.
7494        ((and header
7495              (or (not (gnus-summary-article-sparse-p
7496                        (mail-header-number header)))
7497                  sparse))
7498         (prog1
7499             (gnus-summary-goto-article
7500              (mail-header-number header) nil t)
7501           (when sparse
7502             (gnus-summary-update-article (mail-header-number header)))))
7503        (t
7504         ;; We fetch the article.
7505         (catch 'found
7506           (dolist (gnus-override-method (gnus-refer-article-methods))
7507             (gnus-check-server gnus-override-method)
7508             ;; Fetch the header, and display the article.
7509             (when (setq number (gnus-summary-insert-subject message-id))
7510               (gnus-summary-select-article nil nil nil number)
7511               (throw 'found t)))
7512           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7513
7514 (defun gnus-refer-article-methods ()
7515   "Return a list of referrable methods."
7516   (cond
7517    ;; No method, so we default to current and native.
7518    ((null gnus-refer-article-method)
7519     (list gnus-current-select-method gnus-select-method))
7520    ;; Current.
7521    ((eq 'current gnus-refer-article-method)
7522     (list gnus-current-select-method))
7523    ;; List of select methods.
7524    ((not (and (symbolp (car gnus-refer-article-method))
7525               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7526     (let (out)
7527       (dolist (method gnus-refer-article-method)
7528         (push (if (eq 'current method)
7529                   gnus-current-select-method
7530                 method)
7531               out))
7532       (nreverse out)))
7533    ;; One single select method.
7534    (t
7535     (list gnus-refer-article-method))))
7536
7537 (defun gnus-summary-edit-parameters ()
7538   "Edit the group parameters of the current group."
7539   (interactive)
7540   (gnus-group-edit-group gnus-newsgroup-name 'params))
7541
7542 (defun gnus-summary-customize-parameters ()
7543   "Customize the group parameters of the current group."
7544   (interactive)
7545   (gnus-group-customize gnus-newsgroup-name))
7546
7547 (defun gnus-summary-enter-digest-group (&optional force)
7548   "Enter an nndoc group based on the current article.
7549 If FORCE, force a digest interpretation.  If not, try
7550 to guess what the document format is."
7551   (interactive "P")
7552   (let ((conf gnus-current-window-configuration))
7553     (save-excursion
7554       (gnus-summary-select-article))
7555     (setq gnus-current-window-configuration conf)
7556     (let* ((name (format "%s-%d"
7557                          (gnus-group-prefixed-name
7558                           gnus-newsgroup-name (list 'nndoc ""))
7559                          (save-excursion
7560                            (set-buffer gnus-summary-buffer)
7561                            gnus-current-article)))
7562            (ogroup gnus-newsgroup-name)
7563            (params (append (gnus-info-params (gnus-get-info ogroup))
7564                            (list (cons 'to-group ogroup))
7565                            (list (cons 'save-article-group ogroup))))
7566            (case-fold-search t)
7567            (buf (current-buffer))
7568            dig to-address)
7569       (save-excursion
7570         (set-buffer gnus-original-article-buffer)
7571         ;; Have the digest group inherit the main mail address of
7572         ;; the parent article.
7573         (when (setq to-address (or (message-fetch-field "reply-to")
7574                                    (message-fetch-field "from")))
7575           (setq params (append
7576                         (list (cons 'to-address
7577                                     (funcall gnus-decode-encoded-word-function
7578                                              to-address))))))
7579         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7580         (insert-buffer-substring gnus-original-article-buffer)
7581         ;; Remove lines that may lead nndoc to misinterpret the
7582         ;; document type.
7583         (narrow-to-region
7584          (goto-char (point-min))
7585          (or (search-forward "\n\n" nil t) (point)))
7586         (goto-char (point-min))
7587         (delete-matching-lines "^Path:\\|^From ")
7588         (widen))
7589       (unwind-protect
7590           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7591                     (gnus-newsgroup-ephemeral-ignored-charsets
7592                      gnus-newsgroup-ignored-charsets))
7593                 (gnus-group-read-ephemeral-group
7594                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7595                               (nndoc-article-type
7596                                ,(if force 'mbox 'guess))) t))
7597             ;; Make all postings to this group go to the parent group.
7598               (nconc (gnus-info-params (gnus-get-info name))
7599                      params)
7600             ;; Couldn't select this doc group.
7601             (switch-to-buffer buf)
7602             (gnus-set-global-variables)
7603             (gnus-configure-windows 'summary)
7604             (gnus-message 3 "Article couldn't be entered?"))
7605         (kill-buffer dig)))))
7606
7607 (defun gnus-summary-read-document (n)
7608   "Open a new group based on the current article(s).
7609 This will allow you to read digests and other similar
7610 documents as newsgroups.
7611 Obeys the standard process/prefix convention."
7612   (interactive "P")
7613   (let* ((articles (gnus-summary-work-articles n))
7614          (ogroup gnus-newsgroup-name)
7615          (params (append (gnus-info-params (gnus-get-info ogroup))
7616                          (list (cons 'to-group ogroup))))
7617          article group egroup groups vgroup)
7618     (while (setq article (pop articles))
7619       (setq group (format "%s-%d" gnus-newsgroup-name article))
7620       (gnus-summary-remove-process-mark article)
7621       (when (gnus-summary-display-article article)
7622         (save-excursion
7623           (with-temp-buffer
7624             (insert-buffer-substring gnus-original-article-buffer)
7625             ;; Remove some headers that may lead nndoc to make
7626             ;; the wrong guess.
7627             (message-narrow-to-head)
7628             (goto-char (point-min))
7629             (delete-matching-lines "^\\(Path\\):\\|^From ")
7630             (widen)
7631             (if (setq egroup
7632                       (gnus-group-read-ephemeral-group
7633                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7634                                      (nndoc-article-type guess))
7635                        t nil t))
7636                 (progn
7637             ;; Make all postings to this group go to the parent group.
7638                   (nconc (gnus-info-params (gnus-get-info egroup))
7639                          params)
7640                   (push egroup groups))
7641               ;; Couldn't select this doc group.
7642               (gnus-error 3 "Article couldn't be entered"))))))
7643     ;; Now we have selected all the documents.
7644     (cond
7645      ((not groups)
7646       (error "None of the articles could be interpreted as documents"))
7647      ((gnus-group-read-ephemeral-group
7648        (setq vgroup (format
7649                      "nnvirtual:%s-%s" gnus-newsgroup-name
7650                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7651        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7652        t
7653        (cons (current-buffer) 'summary)))
7654      (t
7655       (error "Couldn't select virtual nndoc group")))))
7656
7657 (defun gnus-summary-isearch-article (&optional regexp-p)
7658   "Do incremental search forward on the current article.
7659 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7660   (interactive "P")
7661   (gnus-summary-select-article)
7662   (gnus-configure-windows 'article)
7663   (gnus-eval-in-buffer-window gnus-article-buffer
7664     (save-restriction
7665       (widen)
7666       (isearch-forward regexp-p))))
7667
7668 (defun gnus-summary-search-article-forward (regexp &optional backward)
7669   "Search for an article containing REGEXP forward.
7670 If BACKWARD, search backward instead."
7671   (interactive
7672    (list (read-string
7673           (format "Search article %s (regexp%s): "
7674                   (if current-prefix-arg "backward" "forward")
7675                   (if gnus-last-search-regexp
7676                       (concat ", default " gnus-last-search-regexp)
7677                     "")))
7678          current-prefix-arg))
7679   (if (string-equal regexp "")
7680       (setq regexp (or gnus-last-search-regexp ""))
7681     (setq gnus-last-search-regexp regexp)
7682     (setq gnus-article-before-search gnus-current-article))
7683   ;; Intentionally set gnus-last-article.
7684   (setq gnus-last-article gnus-article-before-search)
7685   (let ((gnus-last-article gnus-last-article))
7686     (if (gnus-summary-search-article regexp backward)
7687         (gnus-summary-show-thread)
7688       (error "Search failed: \"%s\"" regexp))))
7689
7690 (defun gnus-summary-search-article-backward (regexp)
7691   "Search for an article containing REGEXP backward."
7692   (interactive
7693    (list (read-string
7694           (format "Search article backward (regexp%s): "
7695                   (if gnus-last-search-regexp
7696                       (concat ", default " gnus-last-search-regexp)
7697                     "")))))
7698   (gnus-summary-search-article-forward regexp 'backward))
7699
7700 (defun gnus-summary-search-article (regexp &optional backward)
7701   "Search for an article containing REGEXP.
7702 Optional argument BACKWARD means do search for backward.
7703 `gnus-select-article-hook' is not called during the search."
7704   ;; We have to require this here to make sure that the following
7705   ;; dynamic binding isn't shadowed by autoloading.
7706   (require 'gnus-async)
7707   (require 'gnus-art)
7708   (let ((gnus-select-article-hook nil)  ;Disable hook.
7709         (gnus-article-prepare-hook nil)
7710         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7711         (gnus-use-article-prefetch nil)
7712         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7713         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7714         (sum (current-buffer))
7715         (gnus-display-mime-function nil)
7716         (found nil)
7717         point)
7718     (gnus-save-hidden-threads
7719       (gnus-summary-select-article)
7720       (set-buffer gnus-article-buffer)
7721       (goto-char (window-point (get-buffer-window (current-buffer))))
7722       (when backward
7723         (forward-line -1))
7724       (while (not found)
7725         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7726         (if (if backward
7727                 (re-search-backward regexp nil t)
7728               (re-search-forward regexp nil t))
7729             ;; We found the regexp.
7730             (progn
7731               (setq found 'found)
7732               (beginning-of-line)
7733               (set-window-start
7734                (get-buffer-window (current-buffer))
7735                (point))
7736               (forward-line 1)
7737               (set-window-point
7738                (get-buffer-window (current-buffer))
7739                (point))
7740               (set-buffer sum)
7741               (setq point (point)))
7742           ;; We didn't find it, so we go to the next article.
7743           (set-buffer sum)
7744           (setq found 'not)
7745           (while (eq found 'not)
7746             (if (not (if backward (gnus-summary-find-prev)
7747                        (gnus-summary-find-next)))
7748                 ;; No more articles.
7749                 (setq found t)
7750               ;; Select the next article and adjust point.
7751               (unless (gnus-summary-article-sparse-p
7752                        (gnus-summary-article-number))
7753                 (setq found nil)
7754                 (gnus-summary-select-article)
7755                 (set-buffer gnus-article-buffer)
7756                 (widen)
7757                 (goto-char (if backward (point-max) (point-min))))))))
7758       (gnus-message 7 ""))
7759     ;; Return whether we found the regexp.
7760     (when (eq found 'found)
7761       (goto-char point)
7762       (gnus-summary-show-thread)
7763       (gnus-summary-goto-subject gnus-current-article)
7764       (gnus-summary-position-point)
7765       t)))
7766
7767 (defun gnus-find-matching-articles (header regexp)
7768   "Return a list of all articles that match REGEXP on HEADER.
7769 This search includes all articles in the current group that Gnus has
7770 fetched headers for, whether they are displayed or not."
7771   (let ((articles nil)
7772         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7773         (case-fold-search t))
7774     (dolist (header gnus-newsgroup-headers)
7775       (when (string-match regexp (funcall func header))
7776         (push (mail-header-number header) articles)))
7777     (nreverse articles)))
7778
7779 (defun gnus-summary-find-matching (header regexp &optional backward unread
7780                                           not-case-fold not-matching)
7781   "Return a list of all articles that match REGEXP on HEADER.
7782 The search stars on the current article and goes forwards unless
7783 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7784 If UNREAD is non-nil, only unread articles will
7785 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7786 in the comparisons. If NOT-MATCHING, return a list of all articles that
7787 not match REGEXP on HEADER."
7788   (let ((case-fold-search (not not-case-fold))
7789         articles d func)
7790     (if (consp header)
7791         (if (eq (car header) 'extra)
7792             (setq func
7793                   `(lambda (h)
7794                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7795                          "")))
7796           (error "%s is an invalid header" header))
7797       (unless (fboundp (intern (concat "mail-header-" header)))
7798         (error "%s is not a valid header" header))
7799       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7800     (dolist (d (if (eq backward 'all)
7801                    gnus-newsgroup-data
7802                  (gnus-data-find-list
7803                   (gnus-summary-article-number)
7804                   (gnus-data-list backward))))
7805       (when (and (or (not unread)       ; We want all articles...
7806                      (gnus-data-unread-p d)) ; Or just unreads.
7807                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7808                  (if not-matching
7809                      (not (string-match
7810                            regexp
7811                            (funcall func (gnus-data-header d))))
7812                    (string-match regexp
7813                                  (funcall func (gnus-data-header d)))))
7814         (push (gnus-data-number d) articles))) ; Success!
7815     (nreverse articles)))
7816
7817 (defun gnus-summary-execute-command (header regexp command &optional backward)
7818   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7819 If HEADER is an empty string (or nil), the match is done on the entire
7820 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7821   (interactive
7822    (list (let ((completion-ignore-case t))
7823            (completing-read
7824             "Header name: "
7825             (mapcar (lambda (header) (list (format "%s" header)))
7826                     (append
7827                      '("Number" "Subject" "From" "Lines" "Date"
7828                        "Message-ID" "Xref" "References" "Body")
7829                      gnus-extra-headers))
7830             nil 'require-match))
7831          (read-string "Regexp: ")
7832          (read-key-sequence "Command: ")
7833          current-prefix-arg))
7834   (when (equal header "Body")
7835     (setq header ""))
7836   ;; Hidden thread subtrees must be searched as well.
7837   (gnus-summary-show-all-threads)
7838   ;; We don't want to change current point nor window configuration.
7839   (save-excursion
7840     (save-window-excursion
7841       (gnus-message 6 "Executing %s..." (key-description command))
7842 ;; We'd like to execute COMMAND interactively so as to give arguments.
7843       (gnus-execute header regexp
7844                     `(call-interactively ',(key-binding command))
7845                     backward)
7846       (gnus-message 6 "Executing %s...done" (key-description command)))))
7847
7848 (defun gnus-summary-beginning-of-article ()
7849   "Scroll the article back to the beginning."
7850   (interactive)
7851   (gnus-summary-select-article)
7852   (gnus-configure-windows 'article)
7853   (gnus-eval-in-buffer-window gnus-article-buffer
7854     (widen)
7855     (goto-char (point-min))
7856     (when gnus-page-broken
7857       (gnus-narrow-to-page))))
7858
7859 (defun gnus-summary-end-of-article ()
7860   "Scroll to the end of the article."
7861   (interactive)
7862   (gnus-summary-select-article)
7863   (gnus-configure-windows 'article)
7864   (gnus-eval-in-buffer-window gnus-article-buffer
7865     (widen)
7866     (goto-char (point-max))
7867     (recenter -3)
7868     (when gnus-page-broken
7869       (gnus-narrow-to-page))))
7870
7871 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7872   "Truncate to LEN and quote all \"(\"'s in STRING."
7873   (gnus-replace-in-string (if (and len (> (length string) len))
7874                               (substring string 0 len)
7875                             string)
7876                           "[()]" "\\\\\\&"))
7877
7878 (defun gnus-summary-print-article (&optional filename n)
7879   "Generate and print a PostScript image of the N next (mail) articles.
7880
7881 If N is negative, print the N previous articles.  If N is nil and articles
7882 have been marked with the process mark, print these instead.
7883
7884 If the optional first argument FILENAME is nil, send the image to the
7885 printer.  If FILENAME is a string, save the PostScript image in a file with
7886 that name.  If FILENAME is a number, prompt the user for the name of the file
7887 to save in."
7888   (interactive (list (ps-print-preprint current-prefix-arg)))
7889   (dolist (article (gnus-summary-work-articles n))
7890     (gnus-summary-select-article nil nil 'pseudo article)
7891     (gnus-eval-in-buffer-window gnus-article-buffer
7892       (let ((buffer (generate-new-buffer " *print*")))
7893         (unwind-protect
7894             (progn
7895               (copy-to-buffer buffer (point-min) (point-max))
7896               (set-buffer buffer)
7897               (gnus-article-delete-invisible-text)
7898               (when (gnus-visual-p 'article-highlight 'highlight)
7899                 ;; Copy-to-buffer doesn't copy overlay.  So redo
7900                 ;; highlight.
7901                 (let ((gnus-article-buffer buffer))
7902                   (gnus-article-highlight-citation t)
7903                   (gnus-article-highlight-signature)))
7904               (let ((ps-left-header
7905                      (list
7906                       (concat "("
7907                               (gnus-summary-print-truncate-and-quote
7908                                (mail-header-subject gnus-current-headers)
7909                                66) ")")
7910                       (concat "("
7911                               (gnus-summary-print-truncate-and-quote
7912                                (mail-header-from gnus-current-headers)
7913                                45) ")")))
7914                     (ps-right-header
7915                      (list
7916                       "/pagenumberstring load"
7917                       (concat "("
7918                               (mail-header-date gnus-current-headers) ")"))))
7919                 (gnus-run-hooks 'gnus-ps-print-hook)
7920                 (save-excursion
7921                   (if window-system
7922                       (ps-spool-buffer-with-faces)
7923                     (ps-spool-buffer)))))
7924           (kill-buffer buffer))))
7925     (gnus-summary-remove-process-mark article))
7926   (ps-despool filename))
7927
7928 (defun gnus-summary-show-article (&optional arg)
7929   "Force redisplaying of the current article.
7930 If ARG (the prefix) is a number, show the article with the charset
7931 defined in `gnus-summary-show-article-charset-alist', or the charset
7932 input.
7933 If ARG (the prefix) is non-nil and not a number, show the raw article
7934 without any article massaging functions being run.  Normally, the key strokes 
7935 are `C-u g'."
7936   (interactive "P")
7937   (cond
7938    ((numberp arg)
7939     (gnus-summary-show-article t)
7940     (let ((gnus-newsgroup-charset
7941            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7942                (mm-read-coding-system
7943                 "View as charset: "
7944                 (save-excursion
7945                   (set-buffer gnus-article-buffer)
7946                   (let ((coding-systems
7947                          (detect-coding-region (point) (point-max))))
7948                     (or (car-safe coding-systems)
7949                         coding-systems))))))
7950           (gnus-newsgroup-ignored-charsets 'gnus-all))
7951       (gnus-summary-select-article nil 'force)
7952       (let ((deps gnus-newsgroup-dependencies)
7953             head header lines)
7954         (save-excursion
7955           (set-buffer gnus-original-article-buffer)
7956           (save-restriction
7957             (message-narrow-to-head)
7958             (setq head (buffer-string))
7959             (goto-char (point-min))
7960             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
7961               (goto-char (point-max))
7962               (widen)
7963               (setq lines (1- (count-lines (point) (point-max))))))
7964           (with-temp-buffer
7965             (insert (format "211 %d Article retrieved.\n"
7966                             (cdr gnus-article-current)))
7967             (insert head)
7968             (if lines (insert (format "Lines: %d\n" lines)))
7969             (insert ".\n")
7970             (let ((nntp-server-buffer (current-buffer)))
7971               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7972         (gnus-data-set-header
7973          (gnus-data-find (cdr gnus-article-current))
7974          header)
7975         (gnus-summary-update-article-line
7976          (cdr gnus-article-current) header)
7977         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
7978           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
7979    ((not arg)
7980     ;; Select the article the normal way.
7981     (gnus-summary-select-article nil 'force))
7982    (t
7983     ;; We have to require this here to make sure that the following
7984     ;; dynamic binding isn't shadowed by autoloading.
7985     (require 'gnus-async)
7986     (require 'gnus-art)
7987     ;; Bind the article treatment functions to nil.
7988     (let ((gnus-have-all-headers t)
7989           gnus-article-prepare-hook
7990           gnus-article-decode-hook
7991           gnus-display-mime-function
7992           gnus-break-pages)
7993       ;; Destroy any MIME parts.
7994       (when (gnus-buffer-live-p gnus-article-buffer)
7995         (save-excursion
7996           (set-buffer gnus-article-buffer)
7997           (mm-destroy-parts gnus-article-mime-handles)
7998           ;; Set it to nil for safety reason.
7999           (setq gnus-article-mime-handle-alist nil)
8000           (setq gnus-article-mime-handles nil)))
8001       (gnus-summary-select-article nil 'force))))
8002   (gnus-summary-goto-subject gnus-current-article)
8003   (gnus-summary-position-point))
8004
8005 (defun gnus-summary-show-raw-article ()
8006   "Show the raw article without any article massaging functions being run."
8007   (interactive)
8008   (gnus-summary-show-article t))
8009
8010 (defun gnus-summary-verbose-headers (&optional arg)
8011   "Toggle permanent full header display.
8012 If ARG is a positive number, turn header display on.
8013 If ARG is a negative number, turn header display off."
8014   (interactive "P")
8015   (setq gnus-show-all-headers
8016         (cond ((or (not (numberp arg))
8017                    (zerop arg))
8018                (not gnus-show-all-headers))
8019               ((natnump arg)
8020                t)))
8021   (gnus-summary-show-article))
8022
8023 (defun gnus-summary-toggle-header (&optional arg)
8024   "Show the headers if they are hidden, or hide them if they are shown.
8025 If ARG is a positive number, show the entire header.
8026 If ARG is a negative number, hide the unwanted header lines."
8027   (interactive "P")
8028   (save-excursion
8029     (set-buffer gnus-article-buffer)
8030     (save-restriction
8031       (let* ((buffer-read-only nil)
8032              (inhibit-point-motion-hooks t)
8033              hidden e)
8034         (setq hidden
8035               (if (numberp arg)
8036                   (>= arg 0)
8037                 (save-restriction
8038                   (article-narrow-to-head)
8039                   (gnus-article-hidden-text-p 'headers))))
8040         (goto-char (point-min))
8041         (when (search-forward "\n\n" nil t)
8042           (delete-region (point-min) (1- (point))))
8043         (goto-char (point-min))
8044         (save-excursion
8045           (set-buffer gnus-original-article-buffer)
8046           (goto-char (point-min))
8047           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8048         (insert-buffer-substring gnus-original-article-buffer 1 e)
8049         (save-restriction
8050           (narrow-to-region (point-min) (point))
8051           (article-decode-encoded-words)
8052           (if  hidden
8053               (let ((gnus-treat-hide-headers nil)
8054                     (gnus-treat-hide-boring-headers nil))
8055                 (setq gnus-article-wash-types
8056                       (delq 'headers gnus-article-wash-types))
8057                 (gnus-treat-article 'head))
8058             (gnus-treat-article 'head)))
8059         (gnus-set-mode-line 'article)))))
8060
8061 (defun gnus-summary-show-all-headers ()
8062   "Make all header lines visible."
8063   (interactive)
8064   (gnus-summary-toggle-header 1))
8065
8066 (defun gnus-summary-caesar-message (&optional arg)
8067   "Caesar rotate the current article by 13.
8068 The numerical prefix specifies how many places to rotate each letter
8069 forward."
8070   (interactive "P")
8071   (gnus-summary-select-article)
8072   (let ((mail-header-separator ""))
8073     (gnus-eval-in-buffer-window gnus-article-buffer
8074       (save-restriction
8075         (widen)
8076         (let ((start (window-start))
8077               buffer-read-only)
8078           (message-caesar-buffer-body arg)
8079           (set-window-start (get-buffer-window (current-buffer)) start))))))
8080
8081 (defun gnus-summary-stop-page-breaking ()
8082   "Stop page breaking in the current article."
8083   (interactive)
8084   (gnus-summary-select-article)
8085   (gnus-eval-in-buffer-window gnus-article-buffer
8086     (widen)
8087     (when (gnus-visual-p 'page-marker)
8088       (let ((buffer-read-only nil))
8089         (gnus-remove-text-with-property 'gnus-prev)
8090         (gnus-remove-text-with-property 'gnus-next))
8091       (setq gnus-page-broken nil))))
8092
8093 (defun gnus-summary-move-article (&optional n to-newsgroup
8094                                             select-method action)
8095   "Move the current article to a different newsgroup.
8096 If N is a positive number, move the N next articles.
8097 If N is a negative number, move the N previous articles.
8098 If N is nil and any articles have been marked with the process mark,
8099 move those articles instead.
8100 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8101 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8102 re-spool using this method.
8103
8104 For this function to work, both the current newsgroup and the
8105 newsgroup that you want to move to have to support the `request-move'
8106 and `request-accept' functions.
8107
8108 ACTION can be either `move' (the default), `crosspost' or `copy'."
8109   (interactive "P")
8110   (unless action
8111     (setq action 'move))
8112   ;; Check whether the source group supports the required functions.
8113   (cond ((and (eq action 'move)
8114               (not (gnus-check-backend-function
8115                     'request-move-article gnus-newsgroup-name)))
8116          (error "The current group does not support article moving"))
8117         ((and (eq action 'crosspost)
8118               (not (gnus-check-backend-function
8119                     'request-replace-article gnus-newsgroup-name)))
8120          (error "The current group does not support article editing")))
8121   (let ((articles (gnus-summary-work-articles n))
8122         (prefix (if (gnus-check-backend-function
8123                      'request-move-article gnus-newsgroup-name)
8124                     (gnus-group-real-prefix gnus-newsgroup-name)
8125                   ""))
8126         (names '((move "Move" "Moving")
8127                  (copy "Copy" "Copying")
8128                  (crosspost "Crosspost" "Crossposting")))
8129         (copy-buf (save-excursion
8130                     (nnheader-set-temp-buffer " *copy article*")))
8131         art-group to-method new-xref article to-groups)
8132     (unless (assq action names)
8133       (error "Unknown action %s" action))
8134     ;; Read the newsgroup name.
8135     (when (and (not to-newsgroup)
8136                (not select-method))
8137       (setq to-newsgroup
8138             (gnus-read-move-group-name
8139              (cadr (assq action names))
8140              (symbol-value (intern (format "gnus-current-%s-group" action)))
8141              articles prefix))
8142       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8143     (setq to-method (or select-method
8144                         (gnus-server-to-method
8145                          (gnus-group-method to-newsgroup))))
8146     ;; Check the method we are to move this article to...
8147     (unless (gnus-check-backend-function
8148              'request-accept-article (car to-method))
8149       (error "%s does not support article copying" (car to-method)))
8150     (unless (gnus-check-server to-method)
8151       (error "Can't open server %s" (car to-method)))
8152     (gnus-message 6 "%s to %s: %s..."
8153                   (caddr (assq action names))
8154                   (or (car select-method) to-newsgroup) articles)
8155     (while articles
8156       (setq article (pop articles))
8157       (setq
8158        art-group
8159        (cond
8160         ;; Move the article.
8161         ((eq action 'move)
8162          ;; Remove this article from future suppression.
8163          (gnus-dup-unsuppress-article article)
8164          (gnus-request-move-article
8165           article                       ; Article to move
8166           gnus-newsgroup-name           ; From newsgroup
8167           (nth 1 (gnus-find-method-for-group
8168                   gnus-newsgroup-name)) ; Server
8169           (list 'gnus-request-accept-article
8170                 to-newsgroup (list 'quote select-method)
8171                 (not articles) t)       ; Accept form
8172           (not articles)))              ; Only save nov last time
8173         ;; Copy the article.
8174         ((eq action 'copy)
8175          (save-excursion
8176            (set-buffer copy-buf)
8177            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8178              (gnus-request-accept-article
8179               to-newsgroup select-method (not articles) t))))
8180         ;; Crosspost the article.
8181         ((eq action 'crosspost)
8182          (let ((xref (message-tokenize-header
8183                       (mail-header-xref (gnus-summary-article-header article))
8184                       " ")))
8185            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8186                                   ":" (number-to-string article)))
8187            (unless xref
8188              (setq xref (list (system-name))))
8189            (setq new-xref
8190                  (concat
8191                   (mapconcat 'identity
8192                              (delete "Xref:" (delete new-xref xref))
8193                              " ")
8194                   " " new-xref))
8195            (save-excursion
8196              (set-buffer copy-buf)
8197              ;; First put the article in the destination group.
8198              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8199              (when (consp (setq art-group
8200                                 (gnus-request-accept-article
8201                                  to-newsgroup select-method (not articles))))
8202                (setq new-xref (concat new-xref " " (car art-group)
8203                                       ":"
8204                                       (number-to-string (cdr art-group))))
8205                ;; Now we have the new Xrefs header, so we insert
8206                ;; it and replace the new article.
8207                (nnheader-replace-header "Xref" new-xref)
8208                (gnus-request-replace-article
8209                 (cdr art-group) to-newsgroup (current-buffer))
8210                art-group))))))
8211       (cond
8212        ((not art-group)
8213         (gnus-message 1 "Couldn't %s article %s: %s"
8214                       (cadr (assq action names)) article
8215                       (nnheader-get-report (car to-method))))
8216        ((eq art-group 'junk)
8217         (when (eq action 'move)
8218           (gnus-summary-mark-article article gnus-canceled-mark)
8219           (gnus-message 4 "Deleted article %s" article)))
8220        (t
8221         (let* ((pto-group (gnus-group-prefixed-name
8222                            (car art-group) to-method))
8223                (entry
8224                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8225                (info (nth 2 entry))
8226                (to-group (gnus-info-group info))
8227                to-marks)
8228           ;; Update the group that has been moved to.
8229           (when (and info
8230                      (memq action '(move copy)))
8231             (unless (member to-group to-groups)
8232               (push to-group to-groups))
8233
8234             (unless (memq article gnus-newsgroup-unreads)
8235               (push 'read to-marks)
8236               (gnus-info-set-read
8237                info (gnus-add-to-range (gnus-info-read info)
8238                                        (list (cdr art-group)))))
8239
8240             ;; See whether the article is to be put in the cache.
8241             (let ((marks gnus-article-mark-lists)
8242                   (to-article (cdr art-group)))
8243
8244               ;; Enter the article into the cache in the new group,
8245               ;; if that is required.
8246               (when gnus-use-cache
8247                 (gnus-cache-possibly-enter-article
8248                  to-group to-article
8249                  (memq article gnus-newsgroup-marked)
8250                  (memq article gnus-newsgroup-dormant)
8251                  (memq article gnus-newsgroup-unreads)))
8252
8253               (when gnus-preserve-marks
8254                 ;; Copy any marks over to the new group.
8255                 (when (and (equal to-group gnus-newsgroup-name)
8256                            (not (memq article gnus-newsgroup-unreads)))
8257                   ;; Mark this article as read in this group.
8258                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8259                   (setcdr (gnus-active to-group) to-article)
8260                   (setcdr gnus-newsgroup-active to-article))
8261
8262                 (while marks
8263                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8264                     (when (memq article (symbol-value
8265                                          (intern (format "gnus-newsgroup-%s"
8266                                                          (caar marks)))))
8267                       (push (cdar marks) to-marks)
8268                       ;; If the other group is the same as this group,
8269                       ;; then we have to add the mark to the list.
8270                       (when (equal to-group gnus-newsgroup-name)
8271                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8272                              (cons to-article
8273                                    (symbol-value
8274                                     (intern (format "gnus-newsgroup-%s"
8275                                                     (caar marks)))))))
8276                       ;; Copy the marks to other group.
8277                       (gnus-add-marked-articles
8278                        to-group (cdar marks) (list to-article) info)))
8279                   (setq marks (cdr marks)))
8280
8281                 (gnus-request-set-mark to-group (list (list (list to-article)
8282                                                             'add
8283                                                             to-marks))))
8284
8285               (gnus-dribble-enter
8286                (concat "(gnus-group-set-info '"
8287                        (gnus-prin1-to-string (gnus-get-info to-group))
8288                        ")"))))
8289
8290           ;; Update the Xref header in this article to point to
8291           ;; the new crossposted article we have just created.
8292           (when (eq action 'crosspost)
8293             (save-excursion
8294               (set-buffer copy-buf)
8295               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8296               (nnheader-replace-header "Xref" new-xref)
8297               (gnus-request-replace-article
8298                article gnus-newsgroup-name (current-buffer)))))
8299
8300         ;;;!!!Why is this necessary?
8301         (set-buffer gnus-summary-buffer)
8302
8303         (gnus-summary-goto-subject article)
8304         (when (eq action 'move)
8305           (gnus-summary-mark-article article gnus-canceled-mark))))
8306       (gnus-summary-remove-process-mark article))
8307     ;; Re-activate all groups that have been moved to.
8308     (save-excursion
8309       (set-buffer gnus-group-buffer)
8310       (let ((gnus-group-marked to-groups))
8311         (gnus-group-get-new-news-this-group nil t)))
8312
8313     (gnus-kill-buffer copy-buf)
8314     (gnus-summary-position-point)
8315     (gnus-set-mode-line 'summary)))
8316
8317 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8318   "Move the current article to a different newsgroup.
8319 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8320 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8321 re-spool using this method."
8322   (interactive "P")
8323   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8324
8325 (defun gnus-summary-crosspost-article (&optional n)
8326   "Crosspost the current article to some other group."
8327   (interactive "P")
8328   (gnus-summary-move-article n nil nil 'crosspost))
8329
8330 (defcustom gnus-summary-respool-default-method nil
8331   "Default method type for respooling an article.
8332 If nil, use to the current newsgroup method."
8333   :type 'symbol
8334   :group 'gnus-summary-mail)
8335
8336 (defun gnus-summary-respool-article (&optional n method)
8337   "Respool the current article.
8338 The article will be squeezed through the mail spooling process again,
8339 which means that it will be put in some mail newsgroup or other
8340 depending on `nnmail-split-methods'.
8341 If N is a positive number, respool the N next articles.
8342 If N is a negative number, respool the N previous articles.
8343 If N is nil and any articles have been marked with the process mark,
8344 respool those articles instead.
8345
8346 Respooling can be done both from mail groups and \"real\" newsgroups.
8347 In the former case, the articles in question will be moved from the
8348 current group into whatever groups they are destined to.  In the
8349 latter case, they will be copied into the relevant groups."
8350   (interactive
8351    (list current-prefix-arg
8352          (let* ((methods (gnus-methods-using 'respool))
8353                 (methname
8354                  (symbol-name (or gnus-summary-respool-default-method
8355                                   (car (gnus-find-method-for-group
8356                                         gnus-newsgroup-name)))))
8357                 (method
8358                  (gnus-completing-read
8359                   methname "What backend do you want to use when respooling?"
8360                   methods nil t nil 'gnus-mail-method-history))
8361                 ms)
8362            (cond
8363             ((zerop (length (setq ms (gnus-servers-using-backend
8364                                       (intern method)))))
8365              (list (intern method) ""))
8366             ((= 1 (length ms))
8367              (car ms))
8368             (t
8369              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8370                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8371                            ms-alist))))))))
8372   (unless method
8373     (error "No method given for respooling"))
8374   (if (assoc (symbol-name
8375               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8376              (gnus-methods-using 'respool))
8377       (gnus-summary-move-article n nil method)
8378     (gnus-summary-copy-article n nil method)))
8379
8380 (defun gnus-summary-import-article (file &optional edit)
8381   "Import an arbitrary file into a mail newsgroup."
8382   (interactive "fImport file: \nP")
8383   (let ((group gnus-newsgroup-name)
8384         (now (current-time))
8385         atts lines group-art)
8386     (unless (gnus-check-backend-function 'request-accept-article group)
8387       (error "%s does not support article importing" group))
8388     (or (file-readable-p file)
8389         (not (file-regular-p file))
8390         (error "Can't read %s" file))
8391     (save-excursion
8392       (set-buffer (gnus-get-buffer-create " *import file*"))
8393       (erase-buffer)
8394       (nnheader-insert-file-contents file)
8395       (goto-char (point-min))
8396       (if (nnheader-article-p)
8397           (save-restriction
8398             (goto-char (point-min))
8399             (search-forward "\n\n" nil t)
8400             (narrow-to-region (point-min) (1- (point)))
8401             (goto-char (point-min))
8402             (unless (re-search-forward "^date:" nil t)
8403               (goto-char (point-max))
8404               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8405        ;; This doesn't look like an article, so we fudge some headers.
8406         (setq atts (file-attributes file)
8407               lines (count-lines (point-min) (point-max)))
8408         (insert "From: " (read-string "From: ") "\n"
8409                 "Subject: " (read-string "Subject: ") "\n"
8410                 "Date: " (message-make-date (nth 5 atts)) "\n"
8411                 "Message-ID: " (message-make-message-id) "\n"
8412                 "Lines: " (int-to-string lines) "\n"
8413                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8414       (setq group-art (gnus-request-accept-article group nil t))
8415       (kill-buffer (current-buffer)))
8416     (setq gnus-newsgroup-active (gnus-activate-group group))
8417     (forward-line 1)
8418     (gnus-summary-goto-article (cdr group-art) nil t)
8419     (when edit
8420       (gnus-summary-edit-article))))
8421
8422 (defun gnus-summary-create-article ()
8423   "Create an article in a mail newsgroup."
8424   (interactive)
8425   (let ((group gnus-newsgroup-name)
8426         (now (current-time))
8427         group-art)
8428     (unless (gnus-check-backend-function 'request-accept-article group)
8429       (error "%s does not support article importing" group))
8430     (save-excursion
8431       (set-buffer (gnus-get-buffer-create " *import file*"))
8432       (erase-buffer)
8433       (goto-char (point-min))
8434       ;; This doesn't look like an article, so we fudge some headers.
8435       (insert "From: " (read-string "From: ") "\n"
8436               "Subject: " (read-string "Subject: ") "\n"
8437               "Date: " (message-make-date now) "\n"
8438               "Message-ID: " (message-make-message-id) "\n")
8439       (setq group-art (gnus-request-accept-article group nil t))
8440       (kill-buffer (current-buffer)))
8441     (setq gnus-newsgroup-active (gnus-activate-group group))
8442     (forward-line 1)
8443     (gnus-summary-goto-article (cdr group-art) nil t)
8444     (gnus-summary-edit-article)))
8445
8446 (defun gnus-summary-article-posted-p ()
8447   "Say whether the current (mail) article is available from news as well.
8448 This will be the case if the article has both been mailed and posted."
8449   (interactive)
8450   (let ((id (mail-header-references (gnus-summary-article-header)))
8451         (gnus-override-method (car (gnus-refer-article-methods))))
8452     (if (gnus-request-head id "")
8453         (gnus-message 2 "The current message was found on %s"
8454                       gnus-override-method)
8455       (gnus-message 2 "The current message couldn't be found on %s"
8456                     gnus-override-method)
8457       nil)))
8458
8459 (defun gnus-summary-expire-articles (&optional now)
8460   "Expire all articles that are marked as expirable in the current group."
8461   (interactive)
8462   (when (gnus-check-backend-function
8463          'request-expire-articles gnus-newsgroup-name)
8464     ;; This backend supports expiry.
8465     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8466            (expirable (if total
8467                           (progn
8468                             ;; We need to update the info for
8469                             ;; this group for `gnus-list-of-read-articles'
8470                             ;; to give us the right answer.
8471                             (gnus-run-hooks 'gnus-exit-group-hook)
8472                             (gnus-summary-update-info)
8473                             (gnus-list-of-read-articles gnus-newsgroup-name))
8474                         (setq gnus-newsgroup-expirable
8475                               (sort gnus-newsgroup-expirable '<))))
8476            (expiry-wait (if now 'immediate
8477                           (gnus-group-find-parameter
8478                            gnus-newsgroup-name 'expiry-wait)))
8479            (nnmail-expiry-target
8480             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8481                 nnmail-expiry-target))
8482            es)
8483       (when expirable
8484         ;; There are expirable articles in this group, so we run them
8485         ;; through the expiry process.
8486         (gnus-message 6 "Expiring articles...")
8487         (unless (gnus-check-group gnus-newsgroup-name)
8488           (error "Can't open server for %s" gnus-newsgroup-name))
8489         ;; The list of articles that weren't expired is returned.
8490         (save-excursion
8491           (if expiry-wait
8492               (let ((nnmail-expiry-wait-function nil)
8493                     (nnmail-expiry-wait expiry-wait))
8494                 (setq es (gnus-request-expire-articles
8495                           expirable gnus-newsgroup-name)))
8496             (setq es (gnus-request-expire-articles
8497                       expirable gnus-newsgroup-name)))
8498           (unless total
8499             (setq gnus-newsgroup-expirable es))
8500           ;; We go through the old list of expirable, and mark all
8501           ;; really expired articles as nonexistent.
8502           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8503             (let ((gnus-use-cache nil))
8504               (while expirable
8505                 (unless (memq (car expirable) es)
8506                   (when (gnus-data-find (car expirable))
8507                     (gnus-summary-mark-article
8508                      (car expirable) gnus-canceled-mark)))
8509                 (setq expirable (cdr expirable))))))
8510         (gnus-message 6 "Expiring articles...done")))))
8511
8512 (defun gnus-summary-expire-articles-now ()
8513   "Expunge all expirable articles in the current group.
8514 This means that *all* articles that are marked as expirable will be
8515 deleted forever, right now."
8516   (interactive)
8517   (or gnus-expert-user
8518       (gnus-yes-or-no-p
8519        "Are you really, really, really sure you want to delete all these messages? ")
8520       (error "Phew!"))
8521   (gnus-summary-expire-articles t))
8522
8523 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8524 (defun gnus-summary-delete-article (&optional n)
8525   "Delete the N next (mail) articles.
8526 This command actually deletes articles.  This is not a marking
8527 command.  The article will disappear forever from your life, never to
8528 return.
8529 If N is negative, delete backwards.
8530 If N is nil and articles have been marked with the process mark,
8531 delete these instead."
8532   (interactive "P")
8533   (unless (gnus-check-backend-function 'request-expire-articles
8534                                        gnus-newsgroup-name)
8535     (error "The current newsgroup does not support article deletion"))
8536   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8537     (error "Couldn't open server"))
8538   ;; Compute the list of articles to delete.
8539   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8540         not-deleted)
8541     (if (and gnus-novice-user
8542              (not (gnus-yes-or-no-p
8543                    (format "Do you really want to delete %s forever? "
8544                            (if (> (length articles) 1)
8545                                (format "these %s articles" (length articles))
8546                              "this article")))))
8547         ()
8548       ;; Delete the articles.
8549       (setq not-deleted (gnus-request-expire-articles
8550                          articles gnus-newsgroup-name 'force))
8551       (while articles
8552         (gnus-summary-remove-process-mark (car articles))
8553         ;; The backend might not have been able to delete the article
8554         ;; after all.
8555         (unless (memq (car articles) not-deleted)
8556           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8557         (setq articles (cdr articles)))
8558       (when not-deleted
8559         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8560     (gnus-summary-position-point)
8561     (gnus-set-mode-line 'summary)
8562     not-deleted))
8563
8564 (defun gnus-summary-edit-article (&optional arg)
8565   "Edit the current article.
8566 This will have permanent effect only in mail groups.
8567 If ARG is nil, edit the decoded articles.
8568 If ARG is 1, edit the raw articles.
8569 If ARG is 2, edit the raw articles even in read-only groups.
8570 If ARG is 3, edit the articles with the current handles.
8571 Otherwise, allow editing of articles even in read-only
8572 groups."
8573   (interactive "P")
8574   (let (force raw current-handles)
8575     (cond
8576      ((null arg))
8577      ((eq arg 1) (setq raw t))
8578      ((eq arg 2) (setq raw t
8579                        force t))
8580      ((eq arg 3) (setq current-handles
8581                        (and (gnus-buffer-live-p gnus-article-buffer)
8582                             (with-current-buffer gnus-article-buffer
8583                               (prog1
8584                                   gnus-article-mime-handles
8585                                 (setq gnus-article-mime-handles nil))))))
8586      (t (setq force t)))
8587     (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8588         (error "Can't edit the raw article in group nndraft:drafts"))
8589     (save-excursion
8590       (set-buffer gnus-summary-buffer)
8591       (let ((mail-parse-charset gnus-newsgroup-charset)
8592             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8593         (gnus-set-global-variables)
8594         (when (and (not force)
8595                    (gnus-group-read-only-p))
8596           (error "The current newsgroup does not support article editing"))
8597         (gnus-summary-show-article t)
8598         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8599           (with-current-buffer gnus-article-buffer
8600             (mm-enable-multibyte-mule4)))
8601         (if (equal gnus-newsgroup-name "nndraft:drafts")
8602             (setq raw t))
8603         (gnus-article-edit-article
8604          (if raw 'ignore
8605            `(lambda ()
8606               (let ((mbl mml-buffer-list))
8607                 (setq mml-buffer-list nil)
8608                 (mime-to-mml ,'current-handles)
8609                 (let ((mbl1 mml-buffer-list))
8610                   (setq mml-buffer-list mbl)
8611                   (set (make-local-variable 'mml-buffer-list) mbl1))
8612                 (make-local-hook 'kill-buffer-hook)
8613                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8614          `(lambda (no-highlight)
8615             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8616                   (message-options message-options)
8617                   (message-options-set-recipient)
8618                   (mail-parse-ignored-charsets
8619                    ',gnus-newsgroup-ignored-charsets))
8620               ,(if (not raw) '(progn
8621                                 (mml-to-mime)
8622                                 (mml-destroy-buffers)
8623                                 (remove-hook 'kill-buffer-hook
8624                                              'mml-destroy-buffers t)
8625                                 (kill-local-variable 'mml-buffer-list)))
8626               (gnus-summary-edit-article-done
8627                ,(or (mail-header-references gnus-current-headers) "")
8628                ,(gnus-group-read-only-p)
8629                ,gnus-summary-buffer no-highlight))))))))
8630
8631 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8632
8633 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8634                                                  no-highlight)
8635   "Make edits to the current article permanent."
8636   (interactive)
8637   (save-excursion
8638    ;; The buffer restriction contains the entire article if it exists.
8639     (when (article-goto-body)
8640       (let ((lines (count-lines (point) (point-max)))
8641             (length (- (point-max) (point)))
8642             (case-fold-search t)
8643             (body (copy-marker (point))))
8644         (goto-char (point-min))
8645         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8646           (delete-region (match-beginning 1) (match-end 1))
8647           (insert (number-to-string length)))
8648         (goto-char (point-min))
8649         (when (re-search-forward
8650                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8651           (delete-region (match-beginning 1) (match-end 1))
8652           (insert (number-to-string length)))
8653         (goto-char (point-min))
8654         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8655           (delete-region (match-beginning 1) (match-end 1))
8656           (insert (number-to-string lines))))))
8657   ;; Replace the article.
8658   (let ((buf (current-buffer)))
8659     (with-temp-buffer
8660       (insert-buffer-substring buf)
8661
8662       (if (and (not read-only)
8663                (not (gnus-request-replace-article
8664                      (cdr gnus-article-current) (car gnus-article-current)
8665                      (current-buffer) t)))
8666           (error "Couldn't replace article")
8667         ;; Update the summary buffer.
8668         (if (and references
8669                  (equal (message-tokenize-header references " ")
8670                         (message-tokenize-header
8671                          (or (message-fetch-field "references") "") " ")))
8672             ;; We only have to update this line.
8673             (save-excursion
8674               (save-restriction
8675                 (message-narrow-to-head)
8676                 (let ((head (buffer-string))
8677                       header)
8678                   (with-temp-buffer
8679                     (insert (format "211 %d Article retrieved.\n"
8680                                     (cdr gnus-article-current)))
8681                     (insert head)
8682                     (insert ".\n")
8683                     (let ((nntp-server-buffer (current-buffer)))
8684                       (setq header (car (gnus-get-newsgroup-headers
8685                                          (save-excursion
8686                                            (set-buffer gnus-summary-buffer)
8687                                            gnus-newsgroup-dependencies)
8688                                          t))))
8689                     (save-excursion
8690                       (set-buffer gnus-summary-buffer)
8691                       (gnus-data-set-header
8692                        (gnus-data-find (cdr gnus-article-current))
8693                        header)
8694                       (gnus-summary-update-article-line
8695                        (cdr gnus-article-current) header)
8696                       (if (gnus-summary-goto-subject
8697                            (cdr gnus-article-current) nil t)
8698                           (gnus-summary-update-secondary-mark
8699                            (cdr gnus-article-current))))))))
8700           ;; Update threads.
8701           (set-buffer (or buffer gnus-summary-buffer))
8702           (gnus-summary-update-article (cdr gnus-article-current))
8703           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8704               (gnus-summary-update-secondary-mark
8705                (cdr gnus-article-current))))
8706         ;; Prettify the article buffer again.
8707         (unless no-highlight
8708           (save-excursion
8709             (set-buffer gnus-article-buffer)
8710             ;;;!!! Fix this -- article should be rehighlighted.
8711             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8712             (set-buffer gnus-original-article-buffer)
8713             (gnus-request-article
8714              (cdr gnus-article-current)
8715              (car gnus-article-current) (current-buffer))))
8716         ;; Prettify the summary buffer line.
8717         (when (gnus-visual-p 'summary-highlight 'highlight)
8718           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8719
8720 (defun gnus-summary-edit-wash (key)
8721   "Perform editing command KEY in the article buffer."
8722   (interactive
8723    (list
8724     (progn
8725       (message "%s" (concat (this-command-keys) "- "))
8726       (read-char))))
8727   (message "")
8728   (gnus-summary-edit-article)
8729   (execute-kbd-macro (concat (this-command-keys) key))
8730   (gnus-article-edit-done))
8731
8732
8733 (defun gnus-summary-toggle-smiley (&optional arg)
8734   "Toggle the display of smilies as small graphical icons."
8735   (interactive "P")
8736   (save-excursion
8737     (set-buffer gnus-article-buffer)
8738     (gnus-smiley-display arg)
8739     ))
8740
8741 ;;; Respooling
8742
8743 (defun gnus-summary-respool-query (&optional silent trace)
8744   "Query where the respool algorithm would put this article."
8745   (interactive)
8746   (let (gnus-mark-article-hook)
8747     (gnus-summary-select-article)
8748     (save-excursion
8749       (set-buffer gnus-original-article-buffer)
8750       (save-restriction
8751         (message-narrow-to-head)
8752         (let ((groups (nnmail-article-group 'identity trace)))
8753           (unless silent
8754             (if groups
8755                 (message "This message would go to %s"
8756                          (mapconcat 'car groups ", "))
8757               (message "This message would go to no groups"))
8758             groups))))))
8759
8760 (defun gnus-summary-respool-trace ()
8761   "Trace where the respool algorithm would put this article.
8762 Display a buffer showing all fancy splitting patterns which matched."
8763   (interactive)
8764   (gnus-summary-respool-query nil t))
8765
8766 ;; Summary marking commands.
8767
8768 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8769   "Mark articles which has the same subject as read, and then select the next.
8770 If UNMARK is positive, remove any kind of mark.
8771 If UNMARK is negative, tick articles."
8772   (interactive "P")
8773   (when unmark
8774     (setq unmark (prefix-numeric-value unmark)))
8775   (let ((count
8776          (gnus-summary-mark-same-subject
8777           (gnus-summary-article-subject) unmark)))
8778     ;; Select next unread article.  If auto-select-same mode, should
8779     ;; select the first unread article.
8780     (gnus-summary-next-article t (and gnus-auto-select-same
8781                                       (gnus-summary-article-subject)))
8782     (gnus-message 7 "%d article%s marked as %s"
8783                   count (if (= count 1) " is" "s are")
8784                   (if unmark "unread" "read"))))
8785
8786 (defun gnus-summary-kill-same-subject (&optional unmark)
8787   "Mark articles which has the same subject as read.
8788 If UNMARK is positive, remove any kind of mark.
8789 If UNMARK is negative, tick articles."
8790   (interactive "P")
8791   (when unmark
8792     (setq unmark (prefix-numeric-value unmark)))
8793   (let ((count
8794          (gnus-summary-mark-same-subject
8795           (gnus-summary-article-subject) unmark)))
8796     ;; If marked as read, go to next unread subject.
8797     (when (null unmark)
8798       ;; Go to next unread subject.
8799       (gnus-summary-next-subject 1 t))
8800     (gnus-message 7 "%d articles are marked as %s"
8801                   count (if unmark "unread" "read"))))
8802
8803 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8804   "Mark articles with same SUBJECT as read, and return marked number.
8805 If optional argument UNMARK is positive, remove any kinds of marks.
8806 If optional argument UNMARK is negative, mark articles as unread instead."
8807   (let ((count 1))
8808     (save-excursion
8809       (cond
8810        ((null unmark)                   ; Mark as read.
8811         (while (and
8812                 (progn
8813                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8814                   (gnus-summary-show-thread) t)
8815                 (gnus-summary-find-subject subject))
8816           (setq count (1+ count))))
8817        ((> unmark 0)                    ; Tick.
8818         (while (and
8819                 (progn
8820                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8821                   (gnus-summary-show-thread) t)
8822                 (gnus-summary-find-subject subject))
8823           (setq count (1+ count))))
8824        (t                               ; Mark as unread.
8825         (while (and
8826                 (progn
8827                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8828                   (gnus-summary-show-thread) t)
8829                 (gnus-summary-find-subject subject))
8830           (setq count (1+ count)))))
8831       (gnus-set-mode-line 'summary)
8832       ;; Return the number of marked articles.
8833       count)))
8834
8835 (defun gnus-summary-mark-as-processable (n &optional unmark)
8836   "Set the process mark on the next N articles.
8837 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8838 the process mark instead.  The difference between N and the actual
8839 number of articles marked is returned."
8840   (interactive "P")
8841   (if (and (null n) (gnus-region-active-p))
8842       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8843     (setq n (prefix-numeric-value n))
8844     (let ((backward (< n 0))
8845           (n (abs n)))
8846       (while (and
8847               (> n 0)
8848               (if unmark
8849                   (gnus-summary-remove-process-mark
8850                    (gnus-summary-article-number))
8851                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8852               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8853         (setq n (1- n)))
8854       (when (/= 0 n)
8855         (gnus-message 7 "No more articles"))
8856       (gnus-summary-recenter)
8857       (gnus-summary-position-point)
8858       n)))
8859
8860 (defun gnus-summary-unmark-as-processable (n)
8861   "Remove the process mark from the next N articles.
8862 If N is negative, unmark backward instead.  The difference between N and
8863 the actual number of articles unmarked is returned."
8864   (interactive "P")
8865   (gnus-summary-mark-as-processable n t))
8866
8867 (defun gnus-summary-unmark-all-processable ()
8868   "Remove the process mark from all articles."
8869   (interactive)
8870   (save-excursion
8871     (while gnus-newsgroup-processable
8872       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8873   (gnus-summary-position-point))
8874
8875 (defun gnus-summary-add-mark (article type)
8876   "Mark ARTICLE with a mark of TYPE."
8877   (let ((vtype (car (assq type gnus-article-mark-lists)))
8878         var)
8879     (if (not vtype)
8880         (error "No such mark type: %s" type)
8881       (setq var (intern (format "gnus-newsgroup-%s" type)))
8882       (set var (cons article (symbol-value var)))
8883       (if (memq type '(processable cached replied forwarded recent saved))
8884           (gnus-summary-update-secondary-mark article)
8885         ;;; !!! This is bogus.  We should find out what primary
8886         ;;; !!! mark we want to set.
8887         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8888
8889 (defun gnus-summary-mark-as-expirable (n)
8890   "Mark N articles forward as expirable.
8891 If N is negative, mark backward instead.  The difference between N and
8892 the actual number of articles marked is returned."
8893   (interactive "p")
8894   (gnus-summary-mark-forward n gnus-expirable-mark))
8895
8896 (defun gnus-summary-mark-article-as-replied (article)
8897   "Mark ARTICLE as replied to and update the summary line.
8898 ARTICLE can also be a list of articles."
8899   (interactive (list (gnus-summary-article-number)))
8900   (let ((articles (if (listp article) article (list article))))
8901     (dolist (article articles)
8902       (push article gnus-newsgroup-replied)
8903       (let ((buffer-read-only nil))
8904         (when (gnus-summary-goto-subject article nil t)
8905           (gnus-summary-update-secondary-mark article))))))
8906
8907 (defun gnus-summary-mark-article-as-forwarded (article)
8908   "Mark ARTICLE as forwarded and update the summary line.
8909 ARTICLE can also be a list of articles."
8910   (let ((articles (if (listp article) article (list article))))
8911     (dolist (article articles)
8912       (push article gnus-newsgroup-forwarded)
8913       (let ((buffer-read-only nil))
8914         (when (gnus-summary-goto-subject article nil t)
8915           (gnus-summary-update-secondary-mark article))))))
8916
8917 (defun gnus-summary-set-bookmark (article)
8918   "Set a bookmark in current article."
8919   (interactive (list (gnus-summary-article-number)))
8920   (when (or (not (get-buffer gnus-article-buffer))
8921             (not gnus-current-article)
8922             (not gnus-article-current)
8923             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8924     (error "No current article selected"))
8925   ;; Remove old bookmark, if one exists.
8926   (let ((old (assq article gnus-newsgroup-bookmarks)))
8927     (when old
8928       (setq gnus-newsgroup-bookmarks
8929             (delq old gnus-newsgroup-bookmarks))))
8930   ;; Set the new bookmark, which is on the form
8931   ;; (article-number . line-number-in-body).
8932   (push
8933    (cons article
8934          (save-excursion
8935            (set-buffer gnus-article-buffer)
8936            (count-lines
8937             (min (point)
8938                  (save-excursion
8939                    (goto-char (point-min))
8940                    (search-forward "\n\n" nil t)
8941                    (point)))
8942             (point))))
8943    gnus-newsgroup-bookmarks)
8944   (gnus-message 6 "A bookmark has been added to the current article."))
8945
8946 (defun gnus-summary-remove-bookmark (article)
8947   "Remove the bookmark from the current article."
8948   (interactive (list (gnus-summary-article-number)))
8949   ;; Remove old bookmark, if one exists.
8950   (let ((old (assq article gnus-newsgroup-bookmarks)))
8951     (if old
8952         (progn
8953           (setq gnus-newsgroup-bookmarks
8954                 (delq old gnus-newsgroup-bookmarks))
8955           (gnus-message 6 "Removed bookmark."))
8956       (gnus-message 6 "No bookmark in current article."))))
8957
8958 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8959 (defun gnus-summary-mark-as-dormant (n)
8960   "Mark N articles forward as dormant.
8961 If N is negative, mark backward instead.  The difference between N and
8962 the actual number of articles marked is returned."
8963   (interactive "p")
8964   (gnus-summary-mark-forward n gnus-dormant-mark))
8965
8966 (defun gnus-summary-set-process-mark (article)
8967   "Set the process mark on ARTICLE and update the summary line."
8968   (setq gnus-newsgroup-processable
8969         (cons article
8970               (delq article gnus-newsgroup-processable)))
8971   (when (gnus-summary-goto-subject article)
8972     (gnus-summary-show-thread)
8973     (gnus-summary-goto-subject article)
8974     (gnus-summary-update-secondary-mark article)))
8975
8976 (defun gnus-summary-remove-process-mark (article)
8977   "Remove the process mark from ARTICLE and update the summary line."
8978   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8979   (when (gnus-summary-goto-subject article)
8980     (gnus-summary-show-thread)
8981     (gnus-summary-goto-subject article)
8982     (gnus-summary-update-secondary-mark article)))
8983
8984 (defun gnus-summary-set-saved-mark (article)
8985   "Set the process mark on ARTICLE and update the summary line."
8986   (push article gnus-newsgroup-saved)
8987   (when (gnus-summary-goto-subject article)
8988     (gnus-summary-update-secondary-mark article)))
8989
8990 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8991   "Mark N articles as read forwards.
8992 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8993 The difference between N and the actual number of articles marked is
8994 returned.
8995 Iff NO-EXPIRE, auto-expiry will be inhibited."
8996   (interactive "p")
8997   (gnus-summary-show-thread)
8998   (let ((backward (< n 0))
8999         (gnus-summary-goto-unread
9000          (and gnus-summary-goto-unread
9001               (not (eq gnus-summary-goto-unread 'never))
9002               (not (memq mark (list gnus-unread-mark
9003                                     gnus-ticked-mark gnus-dormant-mark)))))
9004         (n (abs n))
9005         (mark (or mark gnus-del-mark)))
9006     (while (and (> n 0)
9007                 (gnus-summary-mark-article nil mark no-expire)
9008                 (zerop (gnus-summary-next-subject
9009                         (if backward -1 1)
9010                         (and gnus-summary-goto-unread
9011                              (not (eq gnus-summary-goto-unread 'never)))
9012                         t)))
9013       (setq n (1- n)))
9014     (when (/= 0 n)
9015       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9016     (gnus-summary-recenter)
9017     (gnus-summary-position-point)
9018     (gnus-set-mode-line 'summary)
9019     n))
9020
9021 (defun gnus-summary-mark-article-as-read (mark)
9022   "Mark the current article quickly as read with MARK."
9023   (let ((article (gnus-summary-article-number)))
9024     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9025     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9026     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9027     (push (cons article mark) gnus-newsgroup-reads)
9028     ;; Possibly remove from cache, if that is used.
9029     (when gnus-use-cache
9030       (gnus-cache-enter-remove-article article))
9031     ;; Allow the backend to change the mark.
9032     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9033     ;; Check for auto-expiry.
9034     (when (and gnus-newsgroup-auto-expire
9035                (memq mark gnus-auto-expirable-marks))
9036       (setq mark gnus-expirable-mark)
9037       ;; Let the backend know about the mark change.
9038       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9039       (push article gnus-newsgroup-expirable))
9040     ;; Set the mark in the buffer.
9041     (gnus-summary-update-mark mark 'unread)
9042     t))
9043
9044 (defun gnus-summary-mark-article-as-unread (mark)
9045   "Mark the current article quickly as unread with MARK."
9046   (let* ((article (gnus-summary-article-number))
9047          (old-mark (gnus-summary-article-mark article)))
9048     ;; Allow the backend to change the mark.
9049     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9050     (if (eq mark old-mark)
9051         t
9052       (if (<= article 0)
9053           (progn
9054             (gnus-error 1 "Can't mark negative article numbers")
9055             nil)
9056         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9057         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9058         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9059         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9060         (cond ((= mark gnus-ticked-mark)
9061                (push article gnus-newsgroup-marked))
9062               ((= mark gnus-dormant-mark)
9063                (push article gnus-newsgroup-dormant))
9064               (t
9065                (push article gnus-newsgroup-unreads)))
9066         (gnus-pull article gnus-newsgroup-reads)
9067
9068         ;; See whether the article is to be put in the cache.
9069         (and gnus-use-cache
9070              (vectorp (gnus-summary-article-header article))
9071              (save-excursion
9072                (gnus-cache-possibly-enter-article
9073                 gnus-newsgroup-name article
9074                 (= mark gnus-ticked-mark)
9075                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9076
9077         ;; Fix the mark.
9078         (gnus-summary-update-mark mark 'unread)
9079         t))))
9080
9081 (defun gnus-summary-mark-article (&optional article mark no-expire)
9082   "Mark ARTICLE with MARK.  MARK can be any character.
9083 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9084 `??' (dormant) and `?E' (expirable).
9085 If MARK is nil, then the default character `?r' is used.
9086 If ARTICLE is nil, then the article on the current line will be
9087 marked.
9088 Iff NO-EXPIRE, auto-expiry will be inhibited."
9089   ;; The mark might be a string.
9090   (when (stringp mark)
9091     (setq mark (aref mark 0)))
9092   ;; If no mark is given, then we check auto-expiring.
9093   (when (null mark)
9094     (setq mark gnus-del-mark))
9095   (when (and (not no-expire)
9096              gnus-newsgroup-auto-expire
9097              (memq mark gnus-auto-expirable-marks))
9098     (setq mark gnus-expirable-mark))
9099   (let ((article (or article (gnus-summary-article-number)))
9100         (old-mark (gnus-summary-article-mark article)))
9101     ;; Allow the backend to change the mark.
9102     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9103     (if (eq mark old-mark)
9104         t
9105       (unless article
9106         (error "No article on current line"))
9107       (if (not (if (or (= mark gnus-unread-mark)
9108                        (= mark gnus-ticked-mark)
9109                        (= mark gnus-dormant-mark))
9110                    (gnus-mark-article-as-unread article mark)
9111                  (gnus-mark-article-as-read article mark)))
9112           t
9113         ;; See whether the article is to be put in the cache.
9114         (and gnus-use-cache
9115              (not (= mark gnus-canceled-mark))
9116              (vectorp (gnus-summary-article-header article))
9117              (save-excursion
9118                (gnus-cache-possibly-enter-article
9119                 gnus-newsgroup-name article
9120                 (= mark gnus-ticked-mark)
9121                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9122
9123         (when (gnus-summary-goto-subject article nil t)
9124           (let ((buffer-read-only nil))
9125             (gnus-summary-show-thread)
9126             ;; Fix the mark.
9127             (gnus-summary-update-mark mark 'unread)
9128             t))))))
9129
9130 (defun gnus-summary-update-secondary-mark (article)
9131   "Update the secondary (read, process, cache) mark."
9132   (gnus-summary-update-mark
9133    (cond ((memq article gnus-newsgroup-processable)
9134           gnus-process-mark)
9135          ((memq article gnus-newsgroup-cached)
9136           gnus-cached-mark)
9137          ((memq article gnus-newsgroup-replied)
9138           gnus-replied-mark)
9139          ((memq article gnus-newsgroup-forwarded)
9140           gnus-forwarded-mark)
9141          ((memq article gnus-newsgroup-saved)
9142           gnus-saved-mark)
9143          ((memq article gnus-newsgroup-recent)
9144           gnus-recent-mark)
9145          ((memq article gnus-newsgroup-unseen)
9146           gnus-unseen-mark)
9147          (t gnus-no-mark))
9148    'replied)
9149   (when (gnus-visual-p 'summary-highlight 'highlight)
9150     (gnus-run-hooks 'gnus-summary-update-hook))
9151   t)
9152
9153 (defun gnus-summary-update-mark (mark type)
9154   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9155         (buffer-read-only nil))
9156     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9157     (when forward
9158       (when (looking-at "\r")
9159         (incf forward))
9160       (when (<= (+ forward (point)) (point-max))
9161         ;; Go to the right position on the line.
9162         (goto-char (+ forward (point)))
9163         ;; Replace the old mark with the new mark.
9164         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9165         ;; Optionally update the marks by some user rule.
9166         (when (eq type 'unread)
9167           (gnus-data-set-mark
9168            (gnus-data-find (gnus-summary-article-number)) mark)
9169           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9170
9171 (defun gnus-mark-article-as-read (article &optional mark)
9172   "Enter ARTICLE in the pertinent lists and remove it from others."
9173   ;; Make the article expirable.
9174   (let ((mark (or mark gnus-del-mark)))
9175     (if (= mark gnus-expirable-mark)
9176         (push article gnus-newsgroup-expirable)
9177       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9178     ;; Remove from unread and marked lists.
9179     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9180     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9181     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9182     (push (cons article mark) gnus-newsgroup-reads)
9183     ;; Possibly remove from cache, if that is used.
9184     (when gnus-use-cache
9185       (gnus-cache-enter-remove-article article))
9186     t))
9187
9188 (defun gnus-mark-article-as-unread (article &optional mark)
9189   "Enter ARTICLE in the pertinent lists and remove it from others."
9190   (let ((mark (or mark gnus-ticked-mark)))
9191     (if (<= article 0)
9192         (progn
9193           (gnus-error 1 "Can't mark negative article numbers")
9194           nil)
9195       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9196             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9197             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9198             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9199
9200       ;; Unsuppress duplicates?
9201       (when gnus-suppress-duplicates
9202         (gnus-dup-unsuppress-article article))
9203
9204       (cond ((= mark gnus-ticked-mark)
9205              (push article gnus-newsgroup-marked))
9206             ((= mark gnus-dormant-mark)
9207              (push article gnus-newsgroup-dormant))
9208             (t
9209              (push article gnus-newsgroup-unreads)))
9210       (gnus-pull article gnus-newsgroup-reads)
9211       t)))
9212
9213 (defalias 'gnus-summary-mark-as-unread-forward
9214   'gnus-summary-tick-article-forward)
9215 (make-obsolete 'gnus-summary-mark-as-unread-forward
9216                'gnus-summary-tick-article-forward)
9217 (defun gnus-summary-tick-article-forward (n)
9218   "Tick N articles forwards.
9219 If N is negative, tick backwards instead.
9220 The difference between N and the number of articles ticked is returned."
9221   (interactive "p")
9222   (gnus-summary-mark-forward n gnus-ticked-mark))
9223
9224 (defalias 'gnus-summary-mark-as-unread-backward
9225   'gnus-summary-tick-article-backward)
9226 (make-obsolete 'gnus-summary-mark-as-unread-backward
9227                'gnus-summary-tick-article-backward)
9228 (defun gnus-summary-tick-article-backward (n)
9229   "Tick N articles backwards.
9230 The difference between N and the number of articles ticked is returned."
9231   (interactive "p")
9232   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9233
9234 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9235 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9236 (defun gnus-summary-tick-article (&optional article clear-mark)
9237   "Mark current article as unread.
9238 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9239 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9240   (interactive)
9241   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9242                                        gnus-ticked-mark)))
9243
9244 (defun gnus-summary-mark-as-read-forward (n)
9245   "Mark N articles as read forwards.
9246 If N is negative, mark backwards instead.
9247 The difference between N and the actual number of articles marked is
9248 returned."
9249   (interactive "p")
9250   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9251
9252 (defun gnus-summary-mark-as-read-backward (n)
9253   "Mark the N articles as read backwards.
9254 The difference between N and the actual number of articles marked is
9255 returned."
9256   (interactive "p")
9257   (gnus-summary-mark-forward
9258    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9259
9260 (defun gnus-summary-mark-as-read (&optional article mark)
9261   "Mark current article as read.
9262 ARTICLE specifies the article to be marked as read.
9263 MARK specifies a string to be inserted at the beginning of the line."
9264   (gnus-summary-mark-article article mark))
9265
9266 (defun gnus-summary-clear-mark-forward (n)
9267   "Clear marks from N articles forward.
9268 If N is negative, clear backward instead.
9269 The difference between N and the number of marks cleared is returned."
9270   (interactive "p")
9271   (gnus-summary-mark-forward n gnus-unread-mark))
9272
9273 (defun gnus-summary-clear-mark-backward (n)
9274   "Clear marks from N articles backward.
9275 The difference between N and the number of marks cleared is returned."
9276   (interactive "p")
9277   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9278
9279 (defun gnus-summary-mark-unread-as-read ()
9280   "Intended to be used by `gnus-summary-mark-article-hook'."
9281   (when (memq gnus-current-article gnus-newsgroup-unreads)
9282     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9283
9284 (defun gnus-summary-mark-read-and-unread-as-read ()
9285   "Intended to be used by `gnus-summary-mark-article-hook'."
9286   (let ((mark (gnus-summary-article-mark)))
9287     (when (or (gnus-unread-mark-p mark)
9288               (gnus-read-mark-p mark))
9289       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9290
9291 (defun gnus-summary-mark-unread-as-ticked ()
9292   "Intended to be used by `gnus-summary-mark-article-hook'."
9293   (when (memq gnus-current-article gnus-newsgroup-unreads)
9294     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9295
9296 (defun gnus-summary-mark-region-as-read (point mark all)
9297   "Mark all unread articles between point and mark as read.
9298 If given a prefix, mark all articles between point and mark as read,
9299 even ticked and dormant ones."
9300   (interactive "r\nP")
9301   (save-excursion
9302     (let (article)
9303       (goto-char point)
9304       (beginning-of-line)
9305       (while (and
9306               (< (point) mark)
9307               (progn
9308                 (when (or all
9309                           (memq (setq article (gnus-summary-article-number))
9310                                 gnus-newsgroup-unreads))
9311                   (gnus-summary-mark-article article gnus-del-mark))
9312                 t)
9313               (gnus-summary-find-next))))))
9314
9315 (defun gnus-summary-mark-below (score mark)
9316   "Mark articles with score less than SCORE with MARK."
9317   (interactive "P\ncMark: ")
9318   (setq score (if score
9319                   (prefix-numeric-value score)
9320                 (or gnus-summary-default-score 0)))
9321   (save-excursion
9322     (set-buffer gnus-summary-buffer)
9323     (goto-char (point-min))
9324     (while
9325         (progn
9326           (and (< (gnus-summary-article-score) score)
9327                (gnus-summary-mark-article nil mark))
9328           (gnus-summary-find-next)))))
9329
9330 (defun gnus-summary-kill-below (&optional score)
9331   "Mark articles with score below SCORE as read."
9332   (interactive "P")
9333   (gnus-summary-mark-below score gnus-killed-mark))
9334
9335 (defun gnus-summary-clear-above (&optional score)
9336   "Clear all marks from articles with score above SCORE."
9337   (interactive "P")
9338   (gnus-summary-mark-above score gnus-unread-mark))
9339
9340 (defun gnus-summary-tick-above (&optional score)
9341   "Tick all articles with score above SCORE."
9342   (interactive "P")
9343   (gnus-summary-mark-above score gnus-ticked-mark))
9344
9345 (defun gnus-summary-mark-above (score mark)
9346   "Mark articles with score over SCORE with MARK."
9347   (interactive "P\ncMark: ")
9348   (setq score (if score
9349                   (prefix-numeric-value score)
9350                 (or gnus-summary-default-score 0)))
9351   (save-excursion
9352     (set-buffer gnus-summary-buffer)
9353     (goto-char (point-min))
9354     (while (and (progn
9355                   (when (> (gnus-summary-article-score) score)
9356                     (gnus-summary-mark-article nil mark))
9357                   t)
9358                 (gnus-summary-find-next)))))
9359
9360 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9361 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9362 (defun gnus-summary-limit-include-expunged (&optional no-error)
9363   "Display all the hidden articles that were expunged for low scores."
9364   (interactive)
9365   (let ((buffer-read-only nil))
9366     (let ((scored gnus-newsgroup-scored)
9367           headers h)
9368       (while scored
9369         (unless (gnus-summary-article-header (caar scored))
9370           (and (setq h (gnus-number-to-header (caar scored)))
9371                (< (cdar scored) gnus-summary-expunge-below)
9372                (push h headers)))
9373         (setq scored (cdr scored)))
9374       (if (not headers)
9375           (when (not no-error)
9376             (error "No expunged articles hidden"))
9377         (goto-char (point-min))
9378         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9379         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9380         (mapcar (lambda (x) (push (mail-header-number x)
9381                                   gnus-newsgroup-limit))
9382                 headers)
9383         (gnus-summary-prepare-unthreaded (nreverse headers))
9384         (goto-char (point-min))
9385         (gnus-summary-position-point)
9386         t))))
9387
9388 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9389   "Mark all unread articles in this newsgroup as read.
9390 If prefix argument ALL is non-nil, ticked and dormant articles will
9391 also be marked as read.
9392 If QUIETLY is non-nil, no questions will be asked.
9393 If TO-HERE is non-nil, it should be a point in the buffer.  All
9394 articles before (after, if REVERSE is set) this point will be marked as read.
9395 Note that this function will only catch up the unread article
9396 in the current summary buffer limitation.
9397 The number of articles marked as read is returned."
9398   (interactive "P")
9399   (prog1
9400       (save-excursion
9401         (when (or quietly
9402                   (not gnus-interactive-catchup) ;Without confirmation?
9403                   gnus-expert-user
9404                   (gnus-y-or-n-p
9405                    (if all
9406                        "Mark absolutely all articles as read? "
9407                      "Mark all unread articles as read? ")))
9408           (if (and not-mark
9409                    (not gnus-newsgroup-adaptive)
9410                    (not gnus-newsgroup-auto-expire)
9411                    (not gnus-suppress-duplicates)
9412                    (or (not gnus-use-cache)
9413                        (eq gnus-use-cache 'passive)))
9414               (progn
9415                 (when all
9416                   (setq gnus-newsgroup-marked nil
9417                         gnus-newsgroup-dormant nil))
9418                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9419             ;; We actually mark all articles as canceled, which we
9420             ;; have to do when using auto-expiry or adaptive scoring.
9421             (gnus-summary-show-all-threads)
9422             (if (and to-here reverse)
9423                 (progn
9424                   (goto-char to-here)
9425                   (while (and
9426                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9427                           (gnus-summary-find-next (not all) nil nil t))))
9428               (when (gnus-summary-first-subject (not all) t)
9429                 (while (and
9430                         (if to-here (< (point) to-here) t)
9431                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9432                         (gnus-summary-find-next (not all) nil nil t)))))
9433             (gnus-set-mode-line 'summary))
9434           t))
9435     (gnus-summary-position-point)))
9436
9437 (defun gnus-summary-catchup-to-here (&optional all)
9438   "Mark all unticked articles before the current one as read.
9439 If ALL is non-nil, also mark ticked and dormant articles as read."
9440   (interactive "P")
9441   (save-excursion
9442     (gnus-save-hidden-threads
9443       (let ((beg (point)))
9444         ;; We check that there are unread articles.
9445         (when (or all (gnus-summary-find-prev))
9446           (gnus-summary-catchup all t beg)))))
9447   (gnus-summary-position-point))
9448
9449 (defun gnus-summary-catchup-from-here (&optional all)
9450   "Mark all unticked articles after the current one as read.
9451 If ALL is non-nil, also mark ticked and dormant articles as read."
9452   (interactive "P")
9453   (save-excursion
9454     (gnus-save-hidden-threads
9455       (let ((beg (point)))
9456         ;; We check that there are unread articles.
9457         (when (or all (gnus-summary-find-next))
9458           (gnus-summary-catchup all t beg nil t)))))
9459
9460   (gnus-summary-position-point))
9461 (defun gnus-summary-catchup-all (&optional quietly)
9462   "Mark all articles in this newsgroup as read."
9463   (interactive "P")
9464   (gnus-summary-catchup t quietly))
9465
9466 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9467   "Mark all unread articles in this group as read, then exit.
9468 If prefix argument ALL is non-nil, all articles are marked as read.
9469 If QUIETLY is non-nil, no questions will be asked."
9470   (interactive "P")
9471   (when (gnus-summary-catchup all quietly nil 'fast)
9472     ;; Select next newsgroup or exit.
9473     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9474              (eq gnus-auto-select-next 'quietly))
9475         (gnus-summary-next-group nil)
9476       (gnus-summary-exit))))
9477
9478 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9479   "Mark all articles in this newsgroup as read, and then exit."
9480   (interactive "P")
9481   (gnus-summary-catchup-and-exit t quietly))
9482
9483 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9484   "Mark all articles in this group as read and select the next group.
9485 If given a prefix, mark all articles, unread as well as ticked, as
9486 read."
9487   (interactive "P")
9488   (save-excursion
9489     (gnus-summary-catchup all))
9490   (gnus-summary-next-group))
9491
9492 ;;;
9493 ;;; with article
9494 ;;;
9495
9496 (defmacro gnus-with-article (article &rest forms)
9497   "Select ARTICLE and perform FORMS in the original article buffer.
9498 Then replace the article with the result."
9499   `(progn
9500      ;; We don't want the article to be marked as read.
9501      (let (gnus-mark-article-hook)
9502        (gnus-summary-select-article t t nil ,article))
9503      (set-buffer gnus-original-article-buffer)
9504      ,@forms
9505      (if (not (gnus-check-backend-function
9506                'request-replace-article (car gnus-article-current)))
9507          (gnus-message 5 "Read-only group; not replacing")
9508        (unless (gnus-request-replace-article
9509                 ,article (car gnus-article-current)
9510                 (current-buffer) t)
9511          (error "Couldn't replace article")))
9512      ;; The cache and backlog have to be flushed somewhat.
9513      (when gnus-keep-backlog
9514        (gnus-backlog-remove-article
9515         (car gnus-article-current) (cdr gnus-article-current)))
9516      (when gnus-use-cache
9517        (gnus-cache-update-article
9518         (car gnus-article-current) (cdr gnus-article-current)))))
9519
9520 (put 'gnus-with-article 'lisp-indent-function 1)
9521 (put 'gnus-with-article 'edebug-form-spec '(form body))
9522
9523 ;; Thread-based commands.
9524
9525 (defun gnus-summary-articles-in-thread (&optional article)
9526   "Return a list of all articles in the current thread.
9527 If ARTICLE is non-nil, return all articles in the thread that starts
9528 with that article."
9529   (let* ((article (or article (gnus-summary-article-number)))
9530          (data (gnus-data-find-list article))
9531          (top-level (gnus-data-level (car data)))
9532          (top-subject
9533           (cond ((null gnus-thread-operation-ignore-subject)
9534                  (gnus-simplify-subject-re
9535                   (mail-header-subject (gnus-data-header (car data)))))
9536                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9537                  (gnus-simplify-subject-fuzzy
9538                   (mail-header-subject (gnus-data-header (car data)))))
9539                 (t nil)))
9540          (end-point (save-excursion
9541                       (if (gnus-summary-go-to-next-thread)
9542                           (point) (point-max))))
9543          articles)
9544     (while (and data
9545                 (< (gnus-data-pos (car data)) end-point))
9546       (when (or (not top-subject)
9547                 (string= top-subject
9548                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9549                              (gnus-simplify-subject-fuzzy
9550                               (mail-header-subject
9551                                (gnus-data-header (car data))))
9552                            (gnus-simplify-subject-re
9553                             (mail-header-subject
9554                              (gnus-data-header (car data)))))))
9555         (push (gnus-data-number (car data)) articles))
9556       (unless (and (setq data (cdr data))
9557                    (> (gnus-data-level (car data)) top-level))
9558         (setq data nil)))
9559     ;; Return the list of articles.
9560     (nreverse articles)))
9561
9562 (defun gnus-summary-rethread-current ()
9563   "Rethread the thread the current article is part of."
9564   (interactive)
9565   (let* ((gnus-show-threads t)
9566          (article (gnus-summary-article-number))
9567          (id (mail-header-id (gnus-summary-article-header)))
9568          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9569     (unless id
9570       (error "No article on the current line"))
9571     (gnus-rebuild-thread id)
9572     (gnus-summary-goto-subject article)))
9573
9574 (defun gnus-summary-reparent-thread ()
9575   "Make the current article child of the marked (or previous) article.
9576
9577 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9578 is non-nil or the Subject: of both articles are the same."
9579   (interactive)
9580   (unless (not (gnus-group-read-only-p))
9581     (error "The current newsgroup does not support article editing"))
9582   (unless (<= (length gnus-newsgroup-processable) 1)
9583     (error "No more than one article may be marked"))
9584   (save-window-excursion
9585     (let ((gnus-article-buffer " *reparent*")
9586           (current-article (gnus-summary-article-number))
9587           ;; First grab the marked article, otherwise one line up.
9588           (parent-article (if (not (null gnus-newsgroup-processable))
9589                               (car gnus-newsgroup-processable)
9590                             (save-excursion
9591                               (if (eq (forward-line -1) 0)
9592                                   (gnus-summary-article-number)
9593                                 (error "Beginning of summary buffer"))))))
9594       (unless (not (eq current-article parent-article))
9595         (error "An article may not be self-referential"))
9596       (let ((message-id (mail-header-id
9597                          (gnus-summary-article-header parent-article))))
9598         (unless (and message-id (not (equal message-id "")))
9599           (error "No message-id in desired parent"))
9600         (gnus-with-article current-article
9601           (save-restriction
9602             (goto-char (point-min))
9603             (message-narrow-to-head)
9604             (if (re-search-forward "^References: " nil t)
9605                 (progn
9606                   (re-search-forward "^[^ \t]" nil t)
9607                   (forward-line -1)
9608                   (end-of-line)
9609                   (insert " " message-id))
9610               (insert "References: " message-id "\n"))))
9611         (set-buffer gnus-summary-buffer)
9612         (gnus-summary-unmark-all-processable)
9613         (gnus-summary-update-article current-article)
9614         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9615             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9616         (gnus-summary-rethread-current)
9617         (gnus-message 3 "Article %d is now the child of article %d"
9618                       current-article parent-article)))))
9619
9620 (defun gnus-summary-toggle-threads (&optional arg)
9621   "Toggle showing conversation threads.
9622 If ARG is positive number, turn showing conversation threads on."
9623   (interactive "P")
9624   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9625     (setq gnus-show-threads
9626           (if (null arg) (not gnus-show-threads)
9627             (> (prefix-numeric-value arg) 0)))
9628     (gnus-summary-prepare)
9629     (gnus-summary-goto-subject current)
9630     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9631     (gnus-summary-position-point)))
9632
9633 (defun gnus-summary-show-all-threads ()
9634   "Show all threads."
9635   (interactive)
9636   (save-excursion
9637     (let ((buffer-read-only nil))
9638       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9639   (gnus-summary-position-point))
9640
9641 (defun gnus-summary-show-thread ()
9642   "Show thread subtrees.
9643 Returns nil if no thread was there to be shown."
9644   (interactive)
9645   (let ((buffer-read-only nil)
9646         (orig (point))
9647         ;; first goto end then to beg, to have point at beg after let
9648         (end (progn (end-of-line) (point)))
9649         (beg (progn (beginning-of-line) (point))))
9650     (prog1
9651         ;; Any hidden lines here?
9652         (search-forward "\r" end t)
9653       (subst-char-in-region beg end ?\^M ?\n t)
9654       (goto-char orig)
9655       (gnus-summary-position-point))))
9656
9657 (defun gnus-summary-hide-all-threads ()
9658   "Hide all thread subtrees."
9659   (interactive)
9660   (save-excursion
9661     (goto-char (point-min))
9662     (gnus-summary-hide-thread)
9663     (while (zerop (gnus-summary-next-thread 1 t))
9664       (gnus-summary-hide-thread)))
9665   (gnus-summary-position-point))
9666
9667 (defun gnus-summary-hide-thread ()
9668   "Hide thread subtrees.
9669 Returns nil if no threads were there to be hidden."
9670   (interactive)
9671   (let ((buffer-read-only nil)
9672         (start (point))
9673         (article (gnus-summary-article-number)))
9674     (goto-char start)
9675     ;; Go forward until either the buffer ends or the subthread
9676     ;; ends.
9677     (when (and (not (eobp))
9678                (or (zerop (gnus-summary-next-thread 1 t))
9679                    (goto-char (point-max))))
9680       (prog1
9681           (if (and (> (point) start)
9682                    (search-backward "\n" start t))
9683               (progn
9684                 (subst-char-in-region start (point) ?\n ?\^M)
9685                 (gnus-summary-goto-subject article))
9686             (goto-char start)
9687             nil)))))
9688
9689 (defun gnus-summary-go-to-next-thread (&optional previous)
9690   "Go to the same level (or less) next thread.
9691 If PREVIOUS is non-nil, go to previous thread instead.
9692 Return the article number moved to, or nil if moving was impossible."
9693   (let ((level (gnus-summary-thread-level))
9694         (way (if previous -1 1))
9695         (beg (point)))
9696     (forward-line way)
9697     (while (and (not (eobp))
9698                 (< level (gnus-summary-thread-level)))
9699       (forward-line way))
9700     (if (eobp)
9701         (progn
9702           (goto-char beg)
9703           nil)
9704       (setq beg (point))
9705       (prog1
9706           (gnus-summary-article-number)
9707         (goto-char beg)))))
9708
9709 (defun gnus-summary-next-thread (n &optional silent)
9710   "Go to the same level next N'th thread.
9711 If N is negative, search backward instead.
9712 Returns the difference between N and the number of skips actually
9713 done.
9714
9715 If SILENT, don't output messages."
9716   (interactive "p")
9717   (let ((backward (< n 0))
9718         (n (abs n)))
9719     (while (and (> n 0)
9720                 (gnus-summary-go-to-next-thread backward))
9721       (decf n))
9722     (unless silent
9723       (gnus-summary-position-point))
9724     (when (and (not silent) (/= 0 n))
9725       (gnus-message 7 "No more threads"))
9726     n))
9727
9728 (defun gnus-summary-prev-thread (n)
9729   "Go to the same level previous N'th thread.
9730 Returns the difference between N and the number of skips actually
9731 done."
9732   (interactive "p")
9733   (gnus-summary-next-thread (- n)))
9734
9735 (defun gnus-summary-go-down-thread ()
9736   "Go down one level in the current thread."
9737   (let ((children (gnus-summary-article-children)))
9738     (when children
9739       (gnus-summary-goto-subject (car children)))))
9740
9741 (defun gnus-summary-go-up-thread ()
9742   "Go up one level in the current thread."
9743   (let ((parent (gnus-summary-article-parent)))
9744     (when parent
9745       (gnus-summary-goto-subject parent))))
9746
9747 (defun gnus-summary-down-thread (n)
9748   "Go down thread N steps.
9749 If N is negative, go up instead.
9750 Returns the difference between N and how many steps down that were
9751 taken."
9752   (interactive "p")
9753   (let ((up (< n 0))
9754         (n (abs n)))
9755     (while (and (> n 0)
9756                 (if up (gnus-summary-go-up-thread)
9757                   (gnus-summary-go-down-thread)))
9758       (setq n (1- n)))
9759     (gnus-summary-position-point)
9760     (when (/= 0 n)
9761       (gnus-message 7 "Can't go further"))
9762     n))
9763
9764 (defun gnus-summary-up-thread (n)
9765   "Go up thread N steps.
9766 If N is negative, go down instead.
9767 Returns the difference between N and how many steps down that were
9768 taken."
9769   (interactive "p")
9770   (gnus-summary-down-thread (- n)))
9771
9772 (defun gnus-summary-top-thread ()
9773   "Go to the top of the thread."
9774   (interactive)
9775   (while (gnus-summary-go-up-thread))
9776   (gnus-summary-article-number))
9777
9778 (defun gnus-summary-kill-thread (&optional unmark)
9779   "Mark articles under current thread as read.
9780 If the prefix argument is positive, remove any kinds of marks.
9781 If the prefix argument is negative, tick articles instead."
9782   (interactive "P")
9783   (when unmark
9784     (setq unmark (prefix-numeric-value unmark)))
9785   (let ((articles (gnus-summary-articles-in-thread)))
9786     (save-excursion
9787       ;; Expand the thread.
9788       (gnus-summary-show-thread)
9789       ;; Mark all the articles.
9790       (while articles
9791         (gnus-summary-goto-subject (car articles))
9792         (cond ((null unmark)
9793                (gnus-summary-mark-article-as-read gnus-killed-mark))
9794               ((> unmark 0)
9795                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9796               (t
9797                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9798         (setq articles (cdr articles))))
9799     ;; Hide killed subtrees.
9800     (and (null unmark)
9801          gnus-thread-hide-killed
9802          (gnus-summary-hide-thread))
9803     ;; If marked as read, go to next unread subject.
9804     (when (null unmark)
9805       ;; Go to next unread subject.
9806       (gnus-summary-next-subject 1 t)))
9807   (gnus-set-mode-line 'summary))
9808
9809 ;; Summary sorting commands
9810
9811 (defun gnus-summary-sort-by-number (&optional reverse)
9812   "Sort the summary buffer by article number.
9813 Argument REVERSE means reverse order."
9814   (interactive "P")
9815   (gnus-summary-sort 'number reverse))
9816
9817 (defun gnus-summary-sort-by-author (&optional reverse)
9818   "Sort the summary buffer by author name alphabetically.
9819 If `case-fold-search' is non-nil, case of letters is ignored.
9820 Argument REVERSE means reverse order."
9821   (interactive "P")
9822   (gnus-summary-sort 'author reverse))
9823
9824 (defun gnus-summary-sort-by-subject (&optional reverse)
9825   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9826 If `case-fold-search' is non-nil, case of letters is ignored.
9827 Argument REVERSE means reverse order."
9828   (interactive "P")
9829   (gnus-summary-sort 'subject reverse))
9830
9831 (defun gnus-summary-sort-by-date (&optional reverse)
9832   "Sort the summary buffer by date.
9833 Argument REVERSE means reverse order."
9834   (interactive "P")
9835   (gnus-summary-sort 'date reverse))
9836
9837 (defun gnus-summary-sort-by-score (&optional reverse)
9838   "Sort the summary buffer by score.
9839 Argument REVERSE means reverse order."
9840   (interactive "P")
9841   (gnus-summary-sort 'score reverse))
9842
9843 (defun gnus-summary-sort-by-lines (&optional reverse)
9844   "Sort the summary buffer by the number of lines.
9845 Argument REVERSE means reverse order."
9846   (interactive "P")
9847   (gnus-summary-sort 'lines reverse))
9848
9849 (defun gnus-summary-sort-by-chars (&optional reverse)
9850   "Sort the summary buffer by article length.
9851 Argument REVERSE means reverse order."
9852   (interactive "P")
9853   (gnus-summary-sort 'chars reverse))
9854
9855 (defun gnus-summary-sort-by-original (&optional reverse)
9856   "Sort the summary buffer using the default sorting method.
9857 Argument REVERSE means reverse order."
9858   (interactive "P")
9859   (let* ((buffer-read-only)
9860          (gnus-summary-prepare-hook nil))
9861     ;; We do the sorting by regenerating the threads.
9862     (gnus-summary-prepare)
9863     ;; Hide subthreads if needed.
9864     (when (and gnus-show-threads gnus-thread-hide-subtree)
9865       (gnus-summary-hide-all-threads))))
9866
9867 (defun gnus-summary-sort (predicate reverse)
9868   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9869   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9870          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9871          (gnus-thread-sort-functions
9872           (if (not reverse)
9873               thread
9874             `(lambda (t1 t2)
9875                (,thread t2 t1))))
9876          (gnus-sort-gathered-threads-function
9877           gnus-thread-sort-functions)
9878          (gnus-article-sort-functions
9879           (if (not reverse)
9880               article
9881             `(lambda (t1 t2)
9882                (,article t2 t1))))
9883          (buffer-read-only)
9884          (gnus-summary-prepare-hook nil))
9885     ;; We do the sorting by regenerating the threads.
9886     (gnus-summary-prepare)
9887     ;; Hide subthreads if needed.
9888     (when (and gnus-show-threads gnus-thread-hide-subtree)
9889       (gnus-summary-hide-all-threads))))
9890
9891 ;; Summary saving commands.
9892
9893 (defun gnus-summary-save-article (&optional n not-saved)
9894   "Save the current article using the default saver function.
9895 If N is a positive number, save the N next articles.
9896 If N is a negative number, save the N previous articles.
9897 If N is nil and any articles have been marked with the process mark,
9898 save those articles instead.
9899 The variable `gnus-default-article-saver' specifies the saver function."
9900   (interactive "P")
9901   (let* ((articles (gnus-summary-work-articles n))
9902          (save-buffer (save-excursion
9903                         (nnheader-set-temp-buffer " *Gnus Save*")))
9904          (num (length articles))
9905          header file)
9906     (dolist (article articles)
9907       (setq header (gnus-summary-article-header article))
9908       (if (not (vectorp header))
9909           ;; This is a pseudo-article.
9910           (if (assq 'name header)
9911               (gnus-copy-file (cdr (assq 'name header)))
9912             (gnus-message 1 "Article %d is unsaveable" article))
9913         ;; This is a real article.
9914         (save-window-excursion
9915           (let ((gnus-display-mime-function nil)
9916                 (gnus-article-prepare-hook nil))
9917             (gnus-summary-select-article t nil nil article)))
9918         (save-excursion
9919           (set-buffer save-buffer)
9920           (erase-buffer)
9921           (insert-buffer-substring gnus-original-article-buffer))
9922         (setq file (gnus-article-save save-buffer file num))
9923         (gnus-summary-remove-process-mark article)
9924         (unless not-saved
9925           (gnus-summary-set-saved-mark article))))
9926     (gnus-kill-buffer save-buffer)
9927     (gnus-summary-position-point)
9928     (gnus-set-mode-line 'summary)
9929     n))
9930
9931 (defun gnus-summary-pipe-output (&optional arg)
9932   "Pipe the current article to a subprocess.
9933 If N is a positive number, pipe the N next articles.
9934 If N is a negative number, pipe the N previous articles.
9935 If N is nil and any articles have been marked with the process mark,
9936 pipe those articles instead."
9937   (interactive "P")
9938   (require 'gnus-art)
9939   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9940     (gnus-summary-save-article arg t))
9941   (let ((buffer (get-buffer "*Shell Command Output*")))
9942     (if (and buffer
9943              (with-current-buffer buffer (> (point-max) (point-min))))
9944         (gnus-configure-windows 'pipe))))
9945
9946 (defun gnus-summary-save-article-mail (&optional arg)
9947   "Append the current article to an mail file.
9948 If N is a positive number, save the N next articles.
9949 If N is a negative number, save the N previous articles.
9950 If N is nil and any articles have been marked with the process mark,
9951 save those articles instead."
9952   (interactive "P")
9953   (require 'gnus-art)
9954   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9955     (gnus-summary-save-article arg)))
9956
9957 (defun gnus-summary-save-article-rmail (&optional arg)
9958   "Append the current article to an rmail file.
9959 If N is a positive number, save the N next articles.
9960 If N is a negative number, save the N previous articles.
9961 If N is nil and any articles have been marked with the process mark,
9962 save those articles instead."
9963   (interactive "P")
9964   (require 'gnus-art)
9965   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9966     (gnus-summary-save-article arg)))
9967
9968 (defun gnus-summary-save-article-file (&optional arg)
9969   "Append the current article to a file.
9970 If N is a positive number, save the N next articles.
9971 If N is a negative number, save the N previous articles.
9972 If N is nil and any articles have been marked with the process mark,
9973 save those articles instead."
9974   (interactive "P")
9975   (require 'gnus-art)
9976   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9977     (gnus-summary-save-article arg)))
9978
9979 (defun gnus-summary-write-article-file (&optional arg)
9980   "Write the current article to a file, deleting the previous file.
9981 If N is a positive number, save the N next articles.
9982 If N is a negative number, save the N previous articles.
9983 If N is nil and any articles have been marked with the process mark,
9984 save those articles instead."
9985   (interactive "P")
9986   (require 'gnus-art)
9987   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9988     (gnus-summary-save-article arg)))
9989
9990 (defun gnus-summary-save-article-body-file (&optional arg)
9991   "Append the current article body to a file.
9992 If N is a positive number, save the N next articles.
9993 If N is a negative number, save the N previous articles.
9994 If N is nil and any articles have been marked with the process mark,
9995 save those articles instead."
9996   (interactive "P")
9997   (require 'gnus-art)
9998   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9999     (gnus-summary-save-article arg)))
10000
10001 (defun gnus-summary-muttprint (&optional arg)
10002   "Print the current article using Muttprint.
10003 If N is a positive number, save the N next articles.
10004 If N is a negative number, save the N previous articles.
10005 If N is nil and any articles have been marked with the process mark,
10006 save those articles instead."
10007   (interactive "P")
10008   (require 'gnus-art)
10009   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10010     (gnus-summary-save-article arg t)))
10011
10012 (defun gnus-summary-pipe-message (program)
10013   "Pipe the current article through PROGRAM."
10014   (interactive "sProgram: ")
10015   (gnus-summary-select-article)
10016   (let ((mail-header-separator ""))
10017     (gnus-eval-in-buffer-window gnus-article-buffer
10018       (save-restriction
10019         (widen)
10020         (let ((start (window-start))
10021               buffer-read-only)
10022           (message-pipe-buffer-body program)
10023           (set-window-start (get-buffer-window (current-buffer)) start))))))
10024
10025 (defun gnus-get-split-value (methods)
10026   "Return a value based on the split METHODS."
10027   (let (split-name method result match)
10028     (when methods
10029       (save-excursion
10030         (set-buffer gnus-original-article-buffer)
10031         (save-restriction
10032           (nnheader-narrow-to-headers)
10033           (while (and methods (not split-name))
10034             (goto-char (point-min))
10035             (setq method (pop methods))
10036             (setq match (car method))
10037             (when (cond
10038                    ((stringp match)
10039                     ;; Regular expression.
10040                     (ignore-errors
10041                       (re-search-forward match nil t)))
10042                    ((gnus-functionp match)
10043                     ;; Function.
10044                     (save-restriction
10045                       (widen)
10046                       (setq result (funcall match gnus-newsgroup-name))))
10047                    ((consp match)
10048                     ;; Form.
10049                     (save-restriction
10050                       (widen)
10051                       (setq result (eval match)))))
10052               (setq split-name (cdr method))
10053               (cond ((stringp result)
10054                      (push (expand-file-name
10055                             result gnus-article-save-directory)
10056                            split-name))
10057                     ((consp result)
10058                      (setq split-name (append result split-name)))))))))
10059     (nreverse split-name)))
10060
10061 (defun gnus-valid-move-group-p (group)
10062   (and (boundp group)
10063        (symbol-name group)
10064        (symbol-value group)
10065        (gnus-get-function (gnus-find-method-for-group
10066                            (symbol-name group)) 'request-accept-article t)))
10067
10068 (defun gnus-read-move-group-name (prompt default articles prefix)
10069   "Read a group name."
10070   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10071          (minibuffer-confirm-incomplete nil) ; XEmacs
10072          (prom
10073           (format "%s %s to:"
10074                   prompt
10075                   (if (> (length articles) 1)
10076                       (format "these %d articles" (length articles))
10077                     "this article")))
10078          (to-newsgroup
10079           (cond
10080            ((null split-name)
10081             (gnus-completing-read default prom
10082                                   gnus-active-hashtb
10083                                   'gnus-valid-move-group-p
10084                                   nil prefix
10085                                   'gnus-group-history))
10086            ((= 1 (length split-name))
10087             (gnus-completing-read (car split-name) prom
10088                                   gnus-active-hashtb
10089                                   'gnus-valid-move-group-p
10090                                   nil nil
10091                                   'gnus-group-history))
10092            (t
10093             (gnus-completing-read nil prom
10094                                   (mapcar (lambda (el) (list el))
10095                                           (nreverse split-name))
10096                                   nil nil nil
10097                                   'gnus-group-history))))
10098          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10099     (when to-newsgroup
10100       (if (or (string= to-newsgroup "")
10101               (string= to-newsgroup prefix))
10102           (setq to-newsgroup default))
10103       (unless to-newsgroup
10104         (error "No group name entered"))
10105       (or (gnus-active to-newsgroup)
10106           (gnus-activate-group to-newsgroup nil nil to-method)
10107           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10108                                      to-newsgroup))
10109               (or (and (gnus-request-create-group to-newsgroup to-method)
10110                        (gnus-activate-group
10111                         to-newsgroup nil nil to-method)
10112                        (gnus-subscribe-group to-newsgroup))
10113                   (error "Couldn't create group %s" to-newsgroup)))
10114           (error "No such group: %s" to-newsgroup)))
10115     to-newsgroup))
10116
10117 (defun gnus-summary-save-parts (type dir n &optional reverse)
10118   "Save parts matching TYPE to DIR.
10119 If REVERSE, save parts that do not match TYPE."
10120   (interactive
10121    (list (read-string "Save parts of type: "
10122                       (or (car gnus-summary-save-parts-type-history)
10123                           gnus-summary-save-parts-default-mime)
10124                       'gnus-summary-save-parts-type-history)
10125          (setq gnus-summary-save-parts-last-directory
10126                (read-file-name "Save to directory: "
10127                                gnus-summary-save-parts-last-directory
10128                                nil t))
10129          current-prefix-arg))
10130   (gnus-summary-iterate n
10131     (let ((gnus-display-mime-function nil)
10132           (gnus-inhibit-treatment t))
10133       (gnus-summary-select-article))
10134     (save-excursion
10135       (set-buffer gnus-article-buffer)
10136       (let ((handles (or gnus-article-mime-handles
10137                          (mm-dissect-buffer) (mm-uu-dissect))))
10138         (when handles
10139           (gnus-summary-save-parts-1 type dir handles reverse)
10140           (unless gnus-article-mime-handles ;; Don't destroy this case.
10141             (mm-destroy-parts handles)))))))
10142
10143 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10144   (if (stringp (car handle))
10145       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10146               (cdr handle))
10147     (when (if reverse
10148               (not (string-match type (mm-handle-media-type handle)))
10149             (string-match type (mm-handle-media-type handle)))
10150       (let ((file (expand-file-name
10151                    (file-name-nondirectory
10152                     (or
10153                      (mail-content-type-get
10154                       (mm-handle-disposition handle) 'filename)
10155                      (concat gnus-newsgroup-name
10156                              "." (number-to-string
10157                                   (cdr gnus-article-current)))))
10158                    dir)))
10159         (unless (file-exists-p file)
10160           (mm-save-part-to-file handle file))))))
10161
10162 ;; Summary extract commands
10163
10164 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10165   (let ((buffer-read-only nil)
10166         (article (gnus-summary-article-number))
10167         after-article b e)
10168     (unless (gnus-summary-goto-subject article)
10169       (error "No such article: %d" article))
10170     (gnus-summary-position-point)
10171     ;; If all commands are to be bunched up on one line, we collect
10172     ;; them here.
10173     (unless gnus-view-pseudos-separately
10174       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10175             files action)
10176         (while ps
10177           (setq action (cdr (assq 'action (car ps))))
10178           (setq files (list (cdr (assq 'name (car ps)))))
10179           (while (and ps (cdr ps)
10180                       (string= (or action "1")
10181                                (or (cdr (assq 'action (cadr ps))) "2")))
10182             (push (cdr (assq 'name (cadr ps))) files)
10183             (setcdr ps (cddr ps)))
10184           (when files
10185             (when (not (string-match "%s" action))
10186               (push " " files))
10187             (push " " files)
10188             (when (assq 'execute (car ps))
10189               (setcdr (assq 'execute (car ps))
10190                       (funcall (if (string-match "%s" action)
10191                                    'format 'concat)
10192                                action
10193                                (mapconcat
10194                                 (lambda (f)
10195                                   (if (equal f " ")
10196                                       f
10197                                     (mm-quote-arg f)))
10198                                 files " ")))))
10199           (setq ps (cdr ps)))))
10200     (if (and gnus-view-pseudos (not not-view))
10201         (while pslist
10202           (when (assq 'execute (car pslist))
10203             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10204                                   (eq gnus-view-pseudos 'not-confirm)))
10205           (setq pslist (cdr pslist)))
10206       (save-excursion
10207         (while pslist
10208           (setq after-article (or (cdr (assq 'article (car pslist)))
10209                                   (gnus-summary-article-number)))
10210           (gnus-summary-goto-subject after-article)
10211           (forward-line 1)
10212           (setq b (point))
10213           (insert "    " (file-name-nondirectory
10214                           (cdr (assq 'name (car pslist))))
10215                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10216           (setq e (point))
10217           (forward-line -1)             ; back to `b'
10218           (gnus-add-text-properties
10219            b (1- e) (list 'gnus-number gnus-reffed-article-number
10220                           gnus-mouse-face-prop gnus-mouse-face))
10221           (gnus-data-enter
10222            after-article gnus-reffed-article-number
10223            gnus-unread-mark b (car pslist) 0 (- e b))
10224           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10225           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10226           (setq pslist (cdr pslist)))))))
10227
10228 (defun gnus-pseudos< (p1 p2)
10229   (let ((c1 (cdr (assq 'action p1)))
10230         (c2 (cdr (assq 'action p2))))
10231     (and c1 c2 (string< c1 c2))))
10232
10233 (defun gnus-request-pseudo-article (props)
10234   (cond ((assq 'execute props)
10235          (gnus-execute-command (cdr (assq 'execute props)))))
10236   (let ((gnus-current-article (gnus-summary-article-number)))
10237     (gnus-run-hooks 'gnus-mark-article-hook)))
10238
10239 (defun gnus-execute-command (command &optional automatic)
10240   (save-excursion
10241     (gnus-article-setup-buffer)
10242     (set-buffer gnus-article-buffer)
10243     (setq buffer-read-only nil)
10244     (let ((command (if automatic command
10245                      (read-string "Command: " (cons command 0)))))
10246       (erase-buffer)
10247       (insert "$ " command "\n\n")
10248       (if gnus-view-pseudo-asynchronously
10249           (start-process "gnus-execute" (current-buffer) shell-file-name
10250                          shell-command-switch command)
10251         (call-process shell-file-name nil t nil
10252                       shell-command-switch command)))))
10253
10254 ;; Summary kill commands.
10255
10256 (defun gnus-summary-edit-global-kill (article)
10257   "Edit the \"global\" kill file."
10258   (interactive (list (gnus-summary-article-number)))
10259   (gnus-group-edit-global-kill article))
10260
10261 (defun gnus-summary-edit-local-kill ()
10262   "Edit a local kill file applied to the current newsgroup."
10263   (interactive)
10264   (setq gnus-current-headers (gnus-summary-article-header))
10265   (gnus-group-edit-local-kill
10266    (gnus-summary-article-number) gnus-newsgroup-name))
10267
10268 ;;; Header reading.
10269
10270 (defun gnus-read-header (id &optional header)
10271   "Read the headers of article ID and enter them into the Gnus system."
10272   (let ((group gnus-newsgroup-name)
10273         (gnus-override-method
10274          (or
10275           gnus-override-method
10276           (and (gnus-news-group-p gnus-newsgroup-name)
10277                (car (gnus-refer-article-methods)))))
10278         where)
10279     ;; First we check to see whether the header in question is already
10280     ;; fetched.
10281     (if (stringp id)
10282         ;; This is a Message-ID.
10283         (setq header (or header (gnus-id-to-header id)))
10284       ;; This is an article number.
10285       (setq header (or header (gnus-summary-article-header id))))
10286     (if (and header
10287              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10288         ;; We have found the header.
10289         header
10290       ;; If this is a sparse article, we have to nix out its
10291       ;; previous entry in the thread hashtb.
10292       (when (and header
10293                  (gnus-summary-article-sparse-p (mail-header-number header)))
10294         (let* ((parent (gnus-parent-id (mail-header-references header)))
10295                (thread (and parent (gnus-id-to-thread parent))))
10296           (when thread
10297             (delq (assq header thread) thread))))
10298       ;; We have to really fetch the header to this article.
10299       (save-excursion
10300         (set-buffer nntp-server-buffer)
10301         (when (setq where (gnus-request-head id group))
10302           (nnheader-fold-continuation-lines)
10303           (goto-char (point-max))
10304           (insert ".\n")
10305           (goto-char (point-min))
10306           (insert "211 ")
10307           (princ (cond
10308                   ((numberp id) id)
10309                   ((cdr where) (cdr where))
10310                   (header (mail-header-number header))
10311                   (t gnus-reffed-article-number))
10312                  (current-buffer))
10313           (insert " Article retrieved.\n"))
10314         (if (or (not where)
10315                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10316             ()                          ; Malformed head.
10317           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10318             (when (and (stringp id)
10319                        (not (string= (gnus-group-real-name group)
10320                                      (car where))))
10321               ;; If we fetched by Message-ID and the article came
10322               ;; from a different group, we fudge some bogus article
10323               ;; numbers for this article.
10324               (mail-header-set-number header gnus-reffed-article-number))
10325             (save-excursion
10326               (set-buffer gnus-summary-buffer)
10327               (decf gnus-reffed-article-number)
10328               (gnus-remove-header (mail-header-number header))
10329               (push header gnus-newsgroup-headers)
10330               (setq gnus-current-headers header)
10331               (push (mail-header-number header) gnus-newsgroup-limit)))
10332           header)))))
10333
10334 (defun gnus-remove-header (number)
10335   "Remove header NUMBER from `gnus-newsgroup-headers'."
10336   (if (and gnus-newsgroup-headers
10337            (= number (mail-header-number (car gnus-newsgroup-headers))))
10338       (pop gnus-newsgroup-headers)
10339     (let ((headers gnus-newsgroup-headers))
10340       (while (and (cdr headers)
10341                   (not (= number (mail-header-number (cadr headers)))))
10342         (pop headers))
10343       (when (cdr headers)
10344         (setcdr headers (cddr headers))))))
10345
10346 ;;;
10347 ;;; summary highlights
10348 ;;;
10349
10350 (defun gnus-highlight-selected-summary ()
10351   "Highlight selected article in summary buffer."
10352   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10353   (when gnus-summary-selected-face
10354     (save-excursion
10355       (let* ((beg (progn (beginning-of-line) (point)))
10356              (end (progn (end-of-line) (point)))
10357              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10358              (from (if (get-text-property beg gnus-mouse-face-prop)
10359                        beg
10360                      (or (next-single-property-change
10361                           beg gnus-mouse-face-prop nil end)
10362                          beg)))
10363              (to
10364               (if (= from end)
10365                   (- from 2)
10366                 (or (next-single-property-change
10367                      from gnus-mouse-face-prop nil end)
10368                     end))))
10369         ;; If no mouse-face prop on line we will have to = from = end,
10370         ;; so we highlight the entire line instead.
10371         (when (= (+ to 2) from)
10372           (setq from beg)
10373           (setq to end))
10374         (if gnus-newsgroup-selected-overlay
10375             ;; Move old overlay.
10376             (gnus-move-overlay
10377              gnus-newsgroup-selected-overlay from to (current-buffer))
10378           ;; Create new overlay.
10379           (gnus-overlay-put
10380            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10381            'face gnus-summary-selected-face))))))
10382
10383 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10384 (defun gnus-summary-highlight-line ()
10385   "Highlight current line according to `gnus-summary-highlight'."
10386   (let* ((list gnus-summary-highlight)
10387          (p (point))
10388          (end (progn (end-of-line) (point)))
10389          ;; now find out where the line starts and leave point there.
10390          (beg (progn (beginning-of-line) (point)))
10391          (article (gnus-summary-article-number))
10392          (score (or (cdr (assq (or article gnus-current-article)
10393                                gnus-newsgroup-scored))
10394                     gnus-summary-default-score 0))
10395          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10396          (inhibit-read-only t))
10397     ;; Eval the cars of the lists until we find a match.
10398     (let ((default gnus-summary-default-score)
10399           (default-high gnus-summary-default-high-score)
10400           (default-low gnus-summary-default-low-score))
10401       (while (and list
10402                   (not (eval (caar list))))
10403         (setq list (cdr list))))
10404     (let ((face (cdar list)))
10405       (unless (eq face (get-text-property beg 'face))
10406         (gnus-put-text-property-excluding-characters-with-faces
10407          beg end 'face
10408          (setq face (if (boundp face) (symbol-value face) face)))
10409         (when gnus-summary-highlight-line-function
10410           (funcall gnus-summary-highlight-line-function article face))))
10411     (goto-char p)))
10412
10413 (defun gnus-update-read-articles (group unread &optional compute)
10414   "Update the list of read articles in GROUP."
10415   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10416          (entry (gnus-gethash group gnus-newsrc-hashtb))
10417          (info (nth 2 entry))
10418          (prev 1)
10419          (unread (sort (copy-sequence unread) '<))
10420          read)
10421     (if (or (not info) (not active))
10422         ;; There is no info on this group if it was, in fact,
10423         ;; killed.  Gnus stores no information on killed groups, so
10424         ;; there's nothing to be done.
10425         ;; One could store the information somewhere temporarily,
10426         ;; perhaps...  Hmmm...
10427         ()
10428       ;; Remove any negative articles numbers.
10429       (while (and unread (< (car unread) 0))
10430         (setq unread (cdr unread)))
10431       ;; Remove any expired article numbers
10432       (while (and unread (< (car unread) (car active)))
10433         (setq unread (cdr unread)))
10434       ;; Compute the ranges of read articles by looking at the list of
10435       ;; unread articles.
10436       (while unread
10437         (when (/= (car unread) prev)
10438           (push (if (= prev (1- (car unread))) prev
10439                   (cons prev (1- (car unread))))
10440                 read))
10441         (setq prev (1+ (car unread)))
10442         (setq unread (cdr unread)))
10443       (when (<= prev (cdr active))
10444         (push (cons prev (cdr active)) read))
10445       (setq read (if (> (length read) 1) (nreverse read) read))
10446       (if compute
10447           read
10448         (save-excursion
10449           (let (setmarkundo)
10450             ;; Propagate the read marks to the backend.
10451             (when (gnus-check-backend-function 'request-set-mark group)
10452               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10453                     (add (gnus-remove-from-range read (gnus-info-read info))))
10454                 (when (or add del)
10455                   (unless (gnus-check-group group)
10456                     (error "Can't open server for %s" group))
10457                   (gnus-request-set-mark
10458                    group (delq nil (list (if add (list add 'add '(read)))
10459                                          (if del (list del 'del '(read))))))
10460                   (setq setmarkundo
10461                         `(gnus-request-set-mark
10462                           ,group
10463                           ',(delq nil (list
10464                                        (if del (list del 'add '(read)))
10465                                        (if add (list add 'del '(read))))))))))
10466             (set-buffer gnus-group-buffer)
10467             (gnus-undo-register
10468               `(progn
10469                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10470                  (gnus-info-set-read ',info ',(gnus-info-read info))
10471                  (gnus-get-unread-articles-in-group ',info
10472                                                     (gnus-active ,group))
10473                  (gnus-group-update-group ,group t)
10474                  ,setmarkundo))))
10475         ;; Enter this list into the group info.
10476         (gnus-info-set-read info read)
10477         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10478         (gnus-get-unread-articles-in-group info (gnus-active group))
10479         t))))
10480
10481 (defun gnus-offer-save-summaries ()
10482   "Offer to save all active summary buffers."
10483   (let (buffers)
10484     ;; Go through all buffers and find all summaries.
10485     (dolist (buffer (buffer-list))
10486       (when (and (setq buffer (buffer-name buffer))
10487                  (string-match "Summary" buffer)
10488                  (save-excursion
10489                    (set-buffer buffer)
10490                    ;; We check that this is, indeed, a summary buffer.
10491                    (and (eq major-mode 'gnus-summary-mode)
10492                         ;; Also make sure this isn't bogus.
10493                         gnus-newsgroup-prepared
10494                         ;; Also make sure that this isn't a
10495                         ;; dead summary buffer.
10496                         (not gnus-dead-summary-mode))))
10497         (push buffer buffers)))
10498     ;; Go through all these summary buffers and offer to save them.
10499     (when buffers
10500       (save-excursion
10501         (map-y-or-n-p
10502          "Update summary buffer %s? "
10503          (lambda (buf)
10504            (switch-to-buffer buf)
10505            (gnus-summary-exit))
10506          buffers)))))
10507
10508 (defun gnus-summary-setup-default-charset ()
10509   "Setup newsgroup default charset."
10510   (if (equal gnus-newsgroup-name "nndraft:drafts")
10511       (setq gnus-newsgroup-charset nil)
10512     (let* ((ignored-charsets
10513             (or gnus-newsgroup-ephemeral-ignored-charsets
10514                 (append
10515                  (and gnus-newsgroup-name
10516                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10517                  gnus-newsgroup-ignored-charsets))))
10518       (setq gnus-newsgroup-charset
10519             (or gnus-newsgroup-ephemeral-charset
10520                 (and gnus-newsgroup-name
10521                      (gnus-parameter-charset gnus-newsgroup-name))
10522                 gnus-default-charset))
10523       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10524            ignored-charsets))))
10525
10526 ;;;
10527 ;;; Mime Commands
10528 ;;;
10529
10530 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10531   "Display the current article buffer fully MIME-buttonized.
10532 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10533 treated as multipart/mixed."
10534   (interactive "P")
10535   (require 'gnus-art)
10536   (let ((gnus-unbuttonized-mime-types nil)
10537         (gnus-mime-display-multipart-as-mixed show-all-parts))
10538     (gnus-summary-show-article)))
10539
10540 (defun gnus-summary-repair-multipart (article)
10541   "Add a Content-Type header to a multipart article without one."
10542   (interactive (list (gnus-summary-article-number)))
10543   (gnus-with-article article
10544     (message-narrow-to-head)
10545     (message-remove-header "Mime-Version")
10546     (goto-char (point-max))
10547     (insert "Mime-Version: 1.0\n")
10548     (widen)
10549     (when (search-forward "\n--" nil t)
10550       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10551         (message-narrow-to-head)
10552         (message-remove-header "Content-Type")
10553         (goto-char (point-max))
10554         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10555                         separator))
10556         (widen))))
10557   (let (gnus-mark-article-hook)
10558     (gnus-summary-select-article t t nil article)))
10559
10560 (defun gnus-summary-toggle-display-buttonized ()
10561   "Toggle the buttonizing of the article buffer."
10562   (interactive)
10563   (require 'gnus-art)
10564   (if (setq gnus-inhibit-mime-unbuttonizing
10565             (not gnus-inhibit-mime-unbuttonizing))
10566       (let ((gnus-unbuttonized-mime-types nil))
10567         (gnus-summary-show-article))
10568     (gnus-summary-show-article)))
10569
10570 ;;;
10571 ;;; Generic summary marking commands
10572 ;;;
10573
10574 (defvar gnus-summary-marking-alist
10575   '((read gnus-del-mark "d")
10576     (unread gnus-unread-mark "u")
10577     (ticked gnus-ticked-mark "!")
10578     (dormant gnus-dormant-mark "?")
10579     (expirable gnus-expirable-mark "e"))
10580   "An alist of names/marks/keystrokes.")
10581
10582 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10583 (defvar gnus-summary-mark-map)
10584
10585 (defun gnus-summary-make-all-marking-commands ()
10586   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10587   (dolist (elem gnus-summary-marking-alist)
10588     (apply 'gnus-summary-make-marking-command elem)))
10589
10590 (defun gnus-summary-make-marking-command (name mark keystroke)
10591   (let ((map (make-sparse-keymap)))
10592     (define-key gnus-summary-generic-mark-map keystroke map)
10593     (dolist (lway `((next "next" next nil "n")
10594                     (next-unread "next unread" next t "N")
10595                     (prev "previous" prev nil "p")
10596                     (prev-unread "previous unread" prev t "P")
10597                     (nomove "" nil nil ,keystroke)))
10598       (let ((func (gnus-summary-make-marking-command-1
10599                    mark (car lway) lway name)))
10600         (setq func (eval func))
10601         (define-key map (nth 4 lway) func)))))
10602
10603 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10604   `(defun ,(intern
10605             (format "gnus-summary-put-mark-as-%s%s"
10606                     name (if (eq way 'nomove)
10607                              ""
10608                            (concat "-" (symbol-name way)))))
10609      (n)
10610      ,(format
10611        "Mark the current article as %s%s.
10612 If N, the prefix, then repeat N times.
10613 If N is negative, move in reverse order.
10614 The difference between N and the actual number of articles marked is
10615 returned."
10616        name (cadr lway))
10617      (interactive "p")
10618      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10619
10620 (defun gnus-summary-generic-mark (n mark move unread)
10621   "Mark N articles with MARK."
10622   (unless (eq major-mode 'gnus-summary-mode)
10623     (error "This command can only be used in the summary buffer"))
10624   (gnus-summary-show-thread)
10625   (let ((nummove
10626          (cond
10627           ((eq move 'next) 1)
10628           ((eq move 'prev) -1)
10629           (t 0))))
10630     (if (zerop nummove)
10631         (setq n 1)
10632       (when (< n 0)
10633         (setq n (abs n)
10634               nummove (* -1 nummove))))
10635     (while (and (> n 0)
10636                 (gnus-summary-mark-article nil mark)
10637                 (zerop (gnus-summary-next-subject nummove unread t)))
10638       (setq n (1- n)))
10639     (when (/= 0 n)
10640       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10641     (gnus-summary-recenter)
10642     (gnus-summary-position-point)
10643     (gnus-set-mode-line 'summary)
10644     n))
10645
10646 (defun gnus-summary-insert-articles (articles)
10647   (when (setq articles
10648               (gnus-set-difference articles
10649                                    (mapcar (lambda (h) (mail-header-number h))
10650                                            gnus-newsgroup-headers)))
10651     (setq gnus-newsgroup-headers
10652           (merge 'list
10653                  gnus-newsgroup-headers
10654                  (gnus-fetch-headers articles)
10655                  'gnus-article-sort-by-number))
10656     ;; Suppress duplicates?
10657     (when gnus-suppress-duplicates
10658       (gnus-dup-suppress-articles))
10659
10660     ;; We might want to build some more threads first.
10661     (when (and gnus-fetch-old-headers
10662                (eq gnus-headers-retrieved-by 'nov))
10663       (if (eq gnus-fetch-old-headers 'invisible)
10664           (gnus-build-all-threads)
10665         (gnus-build-old-threads)))
10666     ;; Let the Gnus agent mark articles as read.
10667     (when gnus-agent
10668       (gnus-agent-get-undownloaded-list))
10669     ;; Remove list identifiers from subject
10670     (when gnus-list-identifiers
10671       (gnus-summary-remove-list-identifiers))
10672     ;; First and last article in this newsgroup.
10673     (when gnus-newsgroup-headers
10674       (setq gnus-newsgroup-begin
10675             (mail-header-number (car gnus-newsgroup-headers))
10676             gnus-newsgroup-end
10677             (mail-header-number
10678              (gnus-last-element gnus-newsgroup-headers))))
10679     (when gnus-use-scoring
10680       (gnus-possibly-score-headers))))
10681
10682 (defun gnus-summary-insert-old-articles (&optional all)
10683   "Insert all old articles in this group.
10684 If ALL is non-nil, already read articles become readable.
10685 If ALL is a number, fetch this number of articles."
10686   (interactive "P")
10687   (prog1
10688       (let ((old (mapcar 'car gnus-newsgroup-data))
10689             (i (car gnus-newsgroup-active))
10690             older len)
10691         (while (<= i (cdr gnus-newsgroup-active))
10692           (or (memq i old) (push i older))
10693           (incf i))
10694         (setq len (length older))
10695         (cond
10696          ((null older) nil)
10697          ((numberp all)
10698           (if (< all len)
10699               (setq older (subseq older 0 all))))
10700          (all nil)
10701          (t
10702           (if (and (numberp gnus-large-newsgroup)
10703                    (> len gnus-large-newsgroup))
10704               (let ((input
10705                      (read-string
10706                       (format
10707                        "How many articles from %s (default %d): "
10708                        (gnus-limit-string
10709                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10710                        len))))
10711                 (unless (string-match "^[ \t]*$" input)
10712                   (setq all (string-to-number input))
10713                   (if (< all len)
10714                       (setq older (subseq older 0 all))))))))
10715         (if (not older)
10716             (message "No old news.")
10717           (gnus-summary-insert-articles older)
10718           (gnus-summary-limit (gnus-union older old))))
10719     (gnus-summary-position-point)))
10720
10721 (defun gnus-summary-insert-new-articles ()
10722   "Insert all new articles in this group."
10723   (interactive)
10724   (prog1
10725       (let ((old (mapcar 'car gnus-newsgroup-data))
10726             (old-active gnus-newsgroup-active)
10727             (nnmail-fetched-sources (list t))
10728             i new)
10729         (setq gnus-newsgroup-active
10730               (gnus-activate-group gnus-newsgroup-name 'scan))
10731         (setq i (1+ (cdr old-active)))
10732         (while (<= i (cdr gnus-newsgroup-active))
10733           (push i new)
10734           (incf i))
10735         (if (not new)
10736             (message "No gnus is bad news.")
10737           (setq new (nreverse new))
10738           (gnus-summary-insert-articles new)
10739           (setq gnus-newsgroup-unreads
10740                 (append gnus-newsgroup-unreads new))
10741           (gnus-summary-limit (gnus-union old new))))
10742     (gnus-summary-position-point)))
10743
10744 (gnus-summary-make-all-marking-commands)
10745
10746 (gnus-ems-redefine)
10747
10748 (provide 'gnus-sum)
10749
10750 (run-hooks 'gnus-sum-load-hook)
10751
10752 ;;; gnus-sum.el ends here