7960b8d84dbb07b74a90e03153e3bfdb5bf255a6
[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 (require 'nnoo)
40
41 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
42 (autoload 'gnus-cache-write-active "gnus-cache")
43 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
44 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
45 (autoload 'mm-uu-dissect "mm-uu")
46
47 (defcustom gnus-kill-summary-on-exit t
48   "*If non-nil, kill the summary buffer when you exit from it.
49 If nil, the summary will become a \"*Dead Summary*\" buffer, and
50 it will be killed sometime later."
51   :group 'gnus-summary-exit
52   :type 'boolean)
53
54 (defcustom gnus-fetch-old-headers nil
55   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
56 If an unread article in the group refers to an older, already read (or
57 just marked as read) article, the old article will not normally be
58 displayed in the Summary buffer.  If this variable is non-nil, Gnus
59 will attempt to grab the headers to the old articles, and thereby
60 build complete threads.  If it has the value `some', only enough
61 headers to connect otherwise loose threads will be displayed.  This
62 variable can also be a number.  In that case, no more than that number
63 of old headers will be fetched.  If it has the value `invisible', all
64 old headers will be fetched, but none will be displayed.
65
66 The server has to support NOV for any of this to work."
67   :group 'gnus-thread
68   :type '(choice (const :tag "off" nil)
69                  (const some)
70                  number
71                  (sexp :menu-tag "other" t)))
72
73 (defcustom gnus-refer-thread-limit 200
74   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
75 If t, fetch all the available old headers."
76   :group 'gnus-thread
77   :type '(choice number
78                  (sexp :menu-tag "other" t)))
79
80 (defcustom gnus-summary-make-false-root 'adopt
81   "*nil means that Gnus won't gather loose threads.
82 If the root of a thread has expired or been read in a previous
83 session, the information necessary to build a complete thread has been
84 lost.  Instead of having many small sub-threads from this original thread
85 scattered all over the summary buffer, Gnus can gather them.
86
87 If non-nil, Gnus will try to gather all loose sub-threads from an
88 original thread into one large thread.
89
90 If this variable is non-nil, it should be one of `none', `adopt',
91 `dummy' or `empty'.
92
93 If this variable is `none', Gnus will not make a false root, but just
94 present the sub-threads after another.
95 If this variable is `dummy', Gnus will create a dummy root that will
96 have all the sub-threads as children.
97 If this variable is `adopt', Gnus will make one of the \"children\"
98 the parent and mark all the step-children as such.
99 If this variable is `empty', the \"children\" are printed with empty
100 subject fields.  (Or rather, they will be printed with a string
101 given by the `gnus-summary-same-subject' variable.)"
102   :group 'gnus-thread
103   :type '(choice (const :tag "off" nil)
104                  (const none)
105                  (const dummy)
106                  (const adopt)
107                  (const empty)))
108
109 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
110   "*A regexp to match subjects to be excluded from loose thread gathering.
111 As loose thread gathering is done on subjects only, that means that
112 there can be many false gatherings performed.  By rooting out certain
113 common subjects, gathering might become saner."
114   :group 'gnus-thread
115   :type 'regexp)
116
117 (defcustom gnus-summary-gather-subject-limit nil
118   "*Maximum length of subject comparisons when gathering loose threads.
119 Use nil to compare full subjects.  Setting this variable to a low
120 number will help gather threads that have been corrupted by
121 newsreaders chopping off subject lines, but it might also mean that
122 unrelated articles that have subject that happen to begin with the
123 same few characters will be incorrectly gathered.
124
125 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
126 comparing subjects."
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const fuzzy)
130                  (sexp :menu-tag "on" t)))
131
132 (defcustom gnus-simplify-subject-functions nil
133   "List of functions taking a string argument that simplify subjects.
134 The functions are applied recursively.
135
136 Useful functions to put in this list include: `gnus-simplify-subject-re',
137 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
138   :group 'gnus-thread
139   :type '(repeat function))
140
141 (defcustom gnus-simplify-ignored-prefixes nil
142   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
143   :group 'gnus-thread
144   :type '(choice (const :tag "off" nil)
145                  regexp))
146
147 (defcustom gnus-build-sparse-threads nil
148   "*If non-nil, fill in the gaps in threads.
149 If `some', only fill in the gaps that are needed to tie loose threads
150 together.  If `more', fill in all leaf nodes that Gnus can find.  If
151 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
152   :group 'gnus-thread
153   :type '(choice (const :tag "off" nil)
154                  (const some)
155                  (const more)
156                  (sexp :menu-tag "all" t)))
157
158 (defcustom gnus-summary-thread-gathering-function
159   'gnus-gather-threads-by-subject
160   "*Function used for gathering loose threads.
161 There are two pre-defined functions: `gnus-gather-threads-by-subject',
162 which only takes Subjects into consideration; and
163 `gnus-gather-threads-by-references', which compared the References
164 headers of the articles to find matches."
165   :group 'gnus-thread
166   :type '(radio (function-item gnus-gather-threads-by-subject)
167                 (function-item gnus-gather-threads-by-references)
168                 (function :tag "other")))
169
170 (defcustom gnus-summary-same-subject ""
171   "*String indicating that the current article has the same subject as the previous.
172 This variable will only be used if the value of
173 `gnus-summary-make-false-root' is `empty'."
174   :group 'gnus-summary-format
175   :type 'string)
176
177 (defcustom gnus-summary-goto-unread t
178   "*If t, many commands will go to the next unread article.
179 This applies to marking commands as well as other commands that
180 \"naturally\" select the next article, like, for instance, `SPC' at
181 the end of an article.
182
183 If nil, the marking commands do NOT go to the next unread article
184 (they go to the next article instead).  If `never', commands that
185 usually go to the next unread article, will go to the next article,
186 whether it is read or not."
187   :group 'gnus-summary-marks
188   :link '(custom-manual "(gnus)Setting Marks")
189   :type '(choice (const :tag "off" nil)
190                  (const never)
191                  (sexp :menu-tag "on" t)))
192
193 (defcustom gnus-summary-default-score 0
194   "*Default article score level.
195 All scores generated by the score files will be added to this score.
196 If this variable is nil, scoring will be disabled."
197   :group 'gnus-score-default
198   :type '(choice (const :tag "disable")
199                  integer))
200
201 (defcustom gnus-summary-default-high-score 0
202   "*Default threshold for a high scored article.
203 An article will be highlighted as high scored if its score is greater
204 than this score."
205   :group 'gnus-score-default
206   :type 'integer)
207
208 (defcustom gnus-summary-default-low-score 0
209   "*Default threshold for a low scored article.
210 An article will be highlighted as low scored if its score is smaller
211 than this score."
212   :group 'gnus-score-default
213   :type 'integer)
214
215 (defcustom gnus-summary-zcore-fuzz 0
216   "*Fuzziness factor for the zcore in the summary buffer.
217 Articles with scores closer than this to `gnus-summary-default-score'
218 will not be marked."
219   :group 'gnus-summary-format
220   :type 'integer)
221
222 (defcustom gnus-simplify-subject-fuzzy-regexp nil
223   "*Strings to be removed when doing fuzzy matches.
224 This can either be a regular expression or list of regular expressions
225 that will be removed from subject strings if fuzzy subject
226 simplification is selected."
227   :group 'gnus-thread
228   :type '(repeat regexp))
229
230 (defcustom gnus-show-threads t
231   "*If non-nil, display threads in summary mode."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-hide-subtree nil
236   "*If non-nil, hide all threads initially.
237 If threads are hidden, you have to run the command
238 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
239 to expose hidden threads."
240   :group 'gnus-thread
241   :type 'boolean)
242
243 (defcustom gnus-thread-hide-killed t
244   "*If non-nil, hide killed threads automatically."
245   :group 'gnus-thread
246   :type 'boolean)
247
248 (defcustom gnus-thread-ignore-subject t
249   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
250 If nil, articles that have different subjects from their parents will
251 start separate threads."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-operation-ignore-subject t
256   "*If non-nil, subjects will be ignored when doing thread commands.
257 This affects commands like `gnus-summary-kill-thread' and
258 `gnus-summary-lower-thread'.
259
260 If this variable is nil, articles in the same thread with different
261 subjects will not be included in the operation in question.  If this
262 variable is `fuzzy', only articles that have subjects that are fuzzily
263 equal will be included."
264   :group 'gnus-thread
265   :type '(choice (const :tag "off" nil)
266                  (const fuzzy)
267                  (sexp :tag "on" t)))
268
269 (defcustom gnus-thread-indent-level 4
270   "*Number that says how much each sub-thread should be indented."
271   :group 'gnus-thread
272   :type 'integer)
273
274 (defcustom gnus-auto-extend-newsgroup t
275   "*If non-nil, extend newsgroup forward and backward when requested."
276   :group 'gnus-summary-choose
277   :type 'boolean)
278
279 (defcustom gnus-auto-select-first t
280   "*If non-nil, select the article under point.
281 Which article this is is controlled by the `gnus-auto-select-subject'
282 variable.
283
284 If you want to prevent automatic selection of articles in some
285 newsgroups, set the variable to nil in `gnus-select-group-hook'."
286   :group 'gnus-group-select
287   :type '(choice (const :tag "none" nil)
288                  (sexp :menu-tag "first" t)))
289
290 (defcustom gnus-auto-select-subject 'unread
291   "*Says what subject to place under point when entering a group.
292
293 This variable can either be the symbols `first' (place point on the
294 first subject), `unread' (place point on the subject line of the first
295 unread article), `best' (place point on the subject line of the
296 higest-scored article), `unseen' (place point on the subject line of
297 the first unseen article), or a function to be called to place point on
298 some subject line.."
299   :group 'gnus-group-select
300   :type '(choice (const best)
301                  (const unread)
302                  (const first)
303                  (const unseen)))
304
305 (defcustom gnus-auto-select-next t
306   "*If non-nil, offer to go to the next group from the end of the previous.
307 If the value is t and the next newsgroup is empty, Gnus will exit
308 summary mode and go back to group mode.  If the value is neither nil
309 nor t, Gnus will select the following unread newsgroup.  In
310 particular, if the value is the symbol `quietly', the next unread
311 newsgroup will be selected without any confirmation, and if it is
312 `almost-quietly', the next group will be selected without any
313 confirmation if you are located on the last article in the group.
314 Finally, if this variable is `slightly-quietly', the `Z n' command
315 will go to the next group without confirmation."
316   :group 'gnus-summary-maneuvering
317   :type '(choice (const :tag "off" nil)
318                  (const quietly)
319                  (const almost-quietly)
320                  (const slightly-quietly)
321                  (sexp :menu-tag "on" t)))
322
323 (defcustom gnus-auto-select-same nil
324   "*If non-nil, select the next article with the same subject.
325 If there are no more articles with the same subject, go to
326 the first unread article."
327   :group 'gnus-summary-maneuvering
328   :type 'boolean)
329
330 (defcustom gnus-summary-check-current nil
331   "*If non-nil, consider the current article when moving.
332 The \"unread\" movement commands will stay on the same line if the
333 current article is unread."
334   :group 'gnus-summary-maneuvering
335   :type 'boolean)
336
337 (defcustom gnus-auto-center-summary t
338   "*If non-nil, always center the current summary buffer.
339 In particular, if `vertical' do only vertical recentering.  If non-nil
340 and non-`vertical', do both horizontal and vertical recentering."
341   :group 'gnus-summary-maneuvering
342   :type '(choice (const :tag "none" nil)
343                  (const vertical)
344                  (integer :tag "height")
345                  (sexp :menu-tag "both" t)))
346
347 (defcustom gnus-show-all-headers nil
348   "*If non-nil, don't hide any headers."
349   :group 'gnus-article-hiding
350   :group 'gnus-article-headers
351   :type 'boolean)
352
353 (defcustom gnus-summary-ignore-duplicates nil
354   "*If non-nil, ignore articles with identical Message-ID headers."
355   :group 'gnus-summary
356   :type 'boolean)
357
358 (defcustom gnus-single-article-buffer t
359   "*If non-nil, display all articles in the same buffer.
360 If nil, each group will get its own article buffer."
361   :group 'gnus-article-various
362   :type 'boolean)
363
364 (defcustom gnus-break-pages t
365   "*If non-nil, do page breaking on articles.
366 The page delimiter is specified by the `gnus-page-delimiter'
367 variable."
368   :group 'gnus-article-various
369   :type 'boolean)
370
371 (defcustom gnus-move-split-methods nil
372   "*Variable used to suggest where articles are to be moved to.
373 It uses the same syntax as the `gnus-split-methods' variable.
374 However, whereas `gnus-split-methods' specifies file names as targets,
375 this variable specifies group names."
376   :group 'gnus-summary-mail
377   :type '(repeat (choice (list :value (fun) function)
378                          (cons :value ("" "") regexp (repeat string))
379                          (sexp :value nil))))
380
381 (defcustom gnus-unread-mark ?           ;Whitespace
382   "*Mark used for unread articles."
383   :group 'gnus-summary-marks
384   :type 'character)
385
386 (defcustom gnus-ticked-mark ?!
387   "*Mark used for ticked articles."
388   :group 'gnus-summary-marks
389   :type 'character)
390
391 (defcustom gnus-dormant-mark ??
392   "*Mark used for dormant articles."
393   :group 'gnus-summary-marks
394   :type 'character)
395
396 (defcustom gnus-del-mark ?r
397   "*Mark used for del'd articles."
398   :group 'gnus-summary-marks
399   :type 'character)
400
401 (defcustom gnus-read-mark ?R
402   "*Mark used for read articles."
403   :group 'gnus-summary-marks
404   :type 'character)
405
406 (defcustom gnus-expirable-mark ?E
407   "*Mark used for expirable articles."
408   :group 'gnus-summary-marks
409   :type 'character)
410
411 (defcustom gnus-killed-mark ?K
412   "*Mark used for killed articles."
413   :group 'gnus-summary-marks
414   :type 'character)
415
416 (defcustom gnus-souped-mark ?F
417   "*Mark used for souped articles."
418   :group 'gnus-summary-marks
419   :type 'character)
420
421 (defcustom gnus-kill-file-mark ?X
422   "*Mark used for articles killed by kill files."
423   :group 'gnus-summary-marks
424   :type 'character)
425
426 (defcustom gnus-low-score-mark ?Y
427   "*Mark used for articles with a low score."
428   :group 'gnus-summary-marks
429   :type 'character)
430
431 (defcustom gnus-catchup-mark ?C
432   "*Mark used for articles that are caught up."
433   :group 'gnus-summary-marks
434   :type 'character)
435
436 (defcustom gnus-replied-mark ?A
437   "*Mark used for articles that have been replied to."
438   :group 'gnus-summary-marks
439   :type 'character)
440
441 (defcustom gnus-forwarded-mark ?F
442   "*Mark used for articles that have been forwarded."
443   :group 'gnus-summary-marks
444   :type 'character)
445
446 (defcustom gnus-recent-mark ?N
447   "*Mark used for articles that are recent."
448   :group 'gnus-summary-marks
449   :type 'character)
450
451 (defcustom gnus-cached-mark ?*
452   "*Mark used for articles that are in the cache."
453   :group 'gnus-summary-marks
454   :type 'character)
455
456 (defcustom gnus-saved-mark ?S
457   "*Mark used for articles that have been saved."
458   :group 'gnus-summary-marks
459   :type 'character)
460
461 (defcustom gnus-unseen-mark ?.
462   "*Mark used for articles that haven't been seen."
463   :group 'gnus-summary-marks
464   :type 'character)
465
466 (defcustom gnus-no-mark ?               ;Whitespace
467   "*Mark used for articles that have no other secondary mark."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ancient-mark ?O
472   "*Mark used for ancient articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-sparse-mark ?Q
477   "*Mark used for sparsely reffed articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-canceled-mark ?G
482   "*Mark used for canceled articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-duplicate-mark ?M
487   "*Mark used for duplicate articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-undownloaded-mark ?@
492   "*Mark used for articles that weren't downloaded."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-downloadable-mark ?%
497   "*Mark used for articles that are to be downloaded."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-unsendable-mark ?=
502   "*Mark used for articles that won't be sent."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-score-over-mark ?+
507   "*Score mark used for articles with high scores."
508   :group 'gnus-summary-marks
509   :type 'character)
510
511 (defcustom gnus-score-below-mark ?-
512   "*Score mark used for articles with low scores."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-empty-thread-mark ?     ;Whitespace
517   "*There is no thread under the article."
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-not-empty-thread-mark ?=
522   "*There is a thread under the article."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-view-pseudo-asynchronously nil
527   "*If non-nil, Gnus will view pseudo-articles asynchronously."
528   :group 'gnus-extract-view
529   :type 'boolean)
530
531 (defcustom gnus-auto-expirable-marks
532   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
533         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
534         gnus-souped-mark gnus-duplicate-mark)
535   "*The list of marks converted into expiration if a group is auto-expirable."
536   :version "21.1"
537   :group 'gnus-summary
538   :type '(repeat character))
539
540 (defcustom gnus-inhibit-user-auto-expire t
541   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
542   :version "21.1"
543   :group 'gnus-summary
544   :type 'boolean)
545
546 (defcustom gnus-view-pseudos nil
547   "*If `automatic', pseudo-articles will be viewed automatically.
548 If `not-confirm', pseudos will be viewed automatically, and the user
549 will not be asked to confirm the command."
550   :group 'gnus-extract-view
551   :type '(choice (const :tag "off" nil)
552                  (const automatic)
553                  (const not-confirm)))
554
555 (defcustom gnus-view-pseudos-separately t
556   "*If non-nil, one pseudo-article will be created for each file to be viewed.
557 If nil, all files that use the same viewing command will be given as a
558 list of parameters to that command."
559   :group 'gnus-extract-view
560   :type 'boolean)
561
562 (defcustom gnus-insert-pseudo-articles t
563   "*If non-nil, insert pseudo-articles when decoding articles."
564   :group 'gnus-extract-view
565   :type 'boolean)
566
567 (defcustom gnus-summary-dummy-line-format
568   "  %(:                          :%) %S\n"
569   "*The format specification for the dummy roots in the summary buffer.
570 It works along the same lines as a normal formatting string,
571 with some simple extensions.
572
573 %S  The subject"
574   :group 'gnus-threading
575   :type 'string)
576
577 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
578   "*The format specification for the summary mode line.
579 It works along the same lines as a normal formatting string,
580 with some simple extensions:
581
582 %G  Group name
583 %p  Unprefixed group name
584 %A  Current article number
585 %z  Current article score
586 %V  Gnus version
587 %U  Number of unread articles in the group
588 %e  Number of unselected articles in the group
589 %Z  A string with unread/unselected article counts
590 %g  Shortish group name
591 %S  Subject of the current article
592 %u  User-defined spec
593 %s  Current score file name
594 %d  Number of dormant articles
595 %r  Number of articles that have been marked as read in this session
596 %E  Number of articles expunged by the score files"
597   :group 'gnus-summary-format
598   :type 'string)
599
600 (defcustom gnus-list-identifiers nil
601   "Regexp that matches list identifiers to be removed from subject.
602 This can also be a list of regexps."
603   :version "21.1"
604   :group 'gnus-summary-format
605   :group 'gnus-article-hiding
606   :type '(choice (const :tag "none" nil)
607                  (regexp :value ".*")
608                  (repeat :value (".*") regexp)))
609
610 (defcustom gnus-summary-mark-below 0
611   "*Mark all articles with a score below this variable as read.
612 This variable is local to each summary buffer and usually set by the
613 score file."
614   :group 'gnus-score-default
615   :type 'integer)
616
617 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
618   "*List of functions used for sorting articles in the summary buffer.
619
620 Each function takes two articles and returns non-nil if the first
621 article should be sorted before the other.  If you use more than one
622 function, the primary sort function should be the last.  You should
623 probably always include `gnus-article-sort-by-number' in the list of
624 sorting functions -- preferably first.  Also note that sorting by date
625 is often much slower than sorting by number, and the sorting order is
626 very similar.  (Sorting by date means sorting by the time the message
627 was sent, sorting by number means sorting by arrival time.)
628
629 Ready-made functions include `gnus-article-sort-by-number',
630 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
631 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
632
633 When threading is turned on, the variable `gnus-thread-sort-functions'
634 controls how articles are sorted."
635   :group 'gnus-summary-sort
636   :type '(repeat (choice (function-item gnus-article-sort-by-number)
637                          (function-item gnus-article-sort-by-author)
638                          (function-item gnus-article-sort-by-subject)
639                          (function-item gnus-article-sort-by-date)
640                          (function-item gnus-article-sort-by-score)
641                          (function :tag "other"))))
642
643 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
644   "*List of functions used for sorting threads in the summary buffer.
645 By default, threads are sorted by article number.
646
647 Each function takes two threads and returns non-nil if the first
648 thread should be sorted before the other.  If you use more than one
649 function, the primary sort function should be the last.  You should
650 probably always include `gnus-thread-sort-by-number' in the list of
651 sorting functions -- preferably first.  Also note that sorting by date
652 is often much slower than sorting by number, and the sorting order is
653 very similar.  (Sorting by date means sorting by the time the message
654 was sent, sorting by number means sorting by arrival time.)
655
656 Ready-made functions include `gnus-thread-sort-by-number',
657 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
658 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
659 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
660
661 When threading is turned off, the variable
662 `gnus-article-sort-functions' controls how articles are sorted."
663   :group 'gnus-summary-sort
664   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
665                          (function-item gnus-thread-sort-by-author)
666                          (function-item gnus-thread-sort-by-subject)
667                          (function-item gnus-thread-sort-by-date)
668                          (function-item gnus-thread-sort-by-score)
669                          (function-item gnus-thread-sort-by-total-score)
670                          (function :tag "other"))))
671
672 (defcustom gnus-thread-score-function '+
673   "*Function used for calculating the total score of a thread.
674
675 The function is called with the scores of the article and each
676 subthread and should then return the score of the thread.
677
678 Some functions you can use are `+', `max', or `min'."
679   :group 'gnus-summary-sort
680   :type 'function)
681
682 (defcustom gnus-summary-expunge-below nil
683   "All articles that have a score less than this variable will be expunged.
684 This variable is local to the summary buffers."
685   :group 'gnus-score-default
686   :type '(choice (const :tag "off" nil)
687                  integer))
688
689 (defcustom gnus-thread-expunge-below nil
690   "All threads that have a total score less than this variable will be expunged.
691 See `gnus-thread-score-function' for en explanation of what a
692 \"thread score\" is.
693
694 This variable is local to the summary buffers."
695   :group 'gnus-threading
696   :group 'gnus-score-default
697   :type '(choice (const :tag "off" nil)
698                  integer))
699
700 (defcustom gnus-summary-mode-hook nil
701   "*A hook for Gnus summary mode.
702 This hook is run before any variables are set in the summary buffer."
703   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
704   :group 'gnus-summary-various
705   :type 'hook)
706
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (when (featurep 'xemacs)
709   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
710   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
711   (add-hook 'gnus-summary-mode-hook
712             'gnus-xmas-switch-horizontal-scrollbar-off))
713
714 (defcustom gnus-summary-menu-hook nil
715   "*Hook run after the creation of the summary mode menu."
716   :group 'gnus-summary-visual
717   :type 'hook)
718
719 (defcustom gnus-summary-exit-hook nil
720   "*A hook called on exit from the summary buffer.
721 It will be called with point in the group buffer."
722   :group 'gnus-summary-exit
723   :type 'hook)
724
725 (defcustom gnus-summary-prepare-hook nil
726   "*A hook called after the summary buffer has been generated.
727 If you want to modify the summary buffer, you can use this hook."
728   :group 'gnus-summary-various
729   :type 'hook)
730
731 (defcustom gnus-summary-prepared-hook nil
732   "*A hook called as the last thing after the summary buffer has been generated."
733   :group 'gnus-summary-various
734   :type 'hook)
735
736 (defcustom gnus-summary-generate-hook nil
737   "*A hook run just before generating the summary buffer.
738 This hook is commonly used to customize threading variables and the
739 like."
740   :group 'gnus-summary-various
741   :type 'hook)
742
743 (defcustom gnus-select-group-hook nil
744   "*A hook called when a newsgroup is selected.
745
746 If you'd like to simplify subjects like the
747 `gnus-summary-next-same-subject' command does, you can use the
748 following hook:
749
750  (setq gnus-select-group-hook
751       (list
752         (lambda ()
753           (mapcar (lambda (header)
754                      (mail-header-set-subject
755                       header
756                       (gnus-simplify-subject
757                        (mail-header-subject header) 're-only)))
758                   gnus-newsgroup-headers))))"
759   :group 'gnus-group-select
760   :type 'hook)
761
762 (defcustom gnus-select-article-hook nil
763   "*A hook called when an article is selected."
764   :group 'gnus-summary-choose
765   :type 'hook)
766
767 (defcustom gnus-visual-mark-article-hook
768   (list 'gnus-highlight-selected-summary)
769   "*Hook run after selecting an article in the summary buffer.
770 It is meant to be used for highlighting the article in some way.  It
771 is not run if `gnus-visual' is nil."
772   :group 'gnus-summary-visual
773   :type 'hook)
774
775 (defcustom gnus-parse-headers-hook nil
776   "*A hook called before parsing the headers."
777   :group 'gnus-various
778   :type 'hook)
779
780 (defcustom gnus-exit-group-hook nil
781   "*A hook called when exiting summary mode.
782 This hook is not called from the non-updating exit commands like `Q'."
783   :group 'gnus-various
784   :type 'hook)
785
786 (defcustom gnus-summary-update-hook
787   (list 'gnus-summary-highlight-line)
788   "*A hook called when a summary line is changed.
789 The hook will not be called if `gnus-visual' is nil.
790
791 The default function `gnus-summary-highlight-line' will
792 highlight the line according to the `gnus-summary-highlight'
793 variable."
794   :group 'gnus-summary-visual
795   :type 'hook)
796
797 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
798   "*A hook called when an article is selected for the first time.
799 The hook is intended to mark an article as read (or unread)
800 automatically when it is selected."
801   :group 'gnus-summary-choose
802   :type 'hook)
803
804 (defcustom gnus-group-no-more-groups-hook nil
805   "*A hook run when returning to group mode having no more (unread) groups."
806   :group 'gnus-group-select
807   :type 'hook)
808
809 (defcustom gnus-ps-print-hook nil
810   "*A hook run before ps-printing something from Gnus."
811   :group 'gnus-summary
812   :type 'hook)
813
814 (defcustom gnus-summary-display-arrow
815   (and (fboundp 'display-graphic-p)
816        (display-graphic-p))
817   "*If non-nil, display an arrow highlighting the current article."
818   :version "21.1"
819   :group 'gnus-summary
820   :type 'boolean)
821
822 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
823   "Face used for highlighting the current article in the summary buffer."
824   :group 'gnus-summary-visual
825   :type 'face)
826
827 (defcustom gnus-summary-highlight
828   '(((= mark gnus-canceled-mark)
829      . gnus-summary-cancelled-face)
830     ((and (> score default-high)
831           (or (= mark gnus-dormant-mark)
832               (= mark gnus-ticked-mark)))
833      . gnus-summary-high-ticked-face)
834     ((and (< score default-low)
835           (or (= mark gnus-dormant-mark)
836               (= mark gnus-ticked-mark)))
837      . gnus-summary-low-ticked-face)
838     ((or (= mark gnus-dormant-mark)
839          (= mark gnus-ticked-mark))
840      . gnus-summary-normal-ticked-face)
841     ((and (> score default-high) (= mark gnus-ancient-mark))
842      . gnus-summary-high-ancient-face)
843     ((and (< score default-low) (= mark gnus-ancient-mark))
844      . gnus-summary-low-ancient-face)
845     ((= mark gnus-ancient-mark)
846      . gnus-summary-normal-ancient-face)
847     ((and (> score default-high) (= mark gnus-unread-mark))
848      . gnus-summary-high-unread-face)
849     ((and (< score default-low) (= mark gnus-unread-mark))
850      . gnus-summary-low-unread-face)
851     ((= mark gnus-unread-mark)
852      . gnus-summary-normal-unread-face)
853     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
854                                                   gnus-undownloaded-mark)))
855      . gnus-summary-high-unread-face)
856     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
857                                                  gnus-undownloaded-mark)))
858      . gnus-summary-low-unread-face)
859     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
860           (memq article gnus-newsgroup-unreads))
861      . gnus-summary-normal-unread-face)
862     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
863      . gnus-summary-normal-read-face)
864     ((> score default-high)
865      . gnus-summary-high-read-face)
866     ((< score default-low)
867      . gnus-summary-low-read-face)
868     (t
869      . gnus-summary-normal-read-face))
870   "*Controls the highlighting of summary buffer lines.
871
872 A list of (FORM . FACE) pairs.  When deciding how a a particular
873 summary line should be displayed, each form is evaluated.  The content
874 of the face field after the first true form is used.  You can change
875 how those summary lines are displayed, by editing the face field.
876
877 You can use the following variables in the FORM field.
878
879 score:        The article's score
880 default:      The default article score.
881 default-high: The default score for high scored articles.
882 default-low:  The default score for low scored articles.
883 below:        The score below which articles are automatically marked as read.
884 mark:         The articles mark."
885   :group 'gnus-summary-visual
886   :type '(repeat (cons (sexp :tag "Form" nil)
887                        face)))
888
889 (defcustom gnus-alter-header-function nil
890   "Function called to allow alteration of article header structures.
891 The function is called with one parameter, the article header vector,
892 which it may alter in any way.")
893
894 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
895   "Variable that says which function should be used to decode a string with encoded words.")
896
897 (defcustom gnus-extra-headers nil
898   "*Extra headers to parse."
899   :version "21.1"
900   :group 'gnus-summary
901   :type '(repeat symbol))
902
903 (defcustom gnus-ignored-from-addresses
904   (and user-mail-address (regexp-quote user-mail-address))
905   "*Regexp of From headers that may be suppressed in favor of To headers."
906   :version "21.1"
907   :group 'gnus-summary
908   :type 'regexp)
909
910 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
911   "List of charsets that should be ignored.
912 When these charsets are used in the \"charset\" parameter, the
913 default charset will be used instead."
914   :version "21.1"
915   :type '(repeat symbol)
916   :group 'gnus-charset)
917
918 (gnus-define-group-parameter
919  ignored-charsets
920  :type list
921  :function-document
922  "Return the ignored charsets of GROUP."
923  :variable gnus-group-ignored-charsets-alist
924  :variable-default
925  '(("alt\\.chinese\\.text" iso-8859-1))
926  :variable-document
927  "Alist of regexps (to match group names) and charsets that should be ignored.
928 When these charsets are used in the \"charset\" parameter, the
929 default charset will be used instead."
930  :variable-group gnus-charset
931  :variable-type '(repeat (cons (regexp :tag "Group")
932                                (repeat symbol)))
933  :parameter-type '(choice :tag "Ignored charsets"
934                           :value nil
935                           (repeat (symbol)))
936  :parameter-document       "\
937 List of charsets that should be ignored.
938
939 When these charsets are used in the \"charset\" parameter, the
940 default charset will be used instead.")
941
942 (defcustom gnus-group-highlight-words-alist nil
943   "Alist of group regexps and highlight regexps.
944 This variable uses the same syntax as `gnus-emphasis-alist'."
945   :version "21.1"
946   :type '(repeat (cons (regexp :tag "Group")
947                        (repeat (list (regexp :tag "Highlight regexp")
948                                      (number :tag "Group for entire word" 0)
949                                      (number :tag "Group for displayed part" 0)
950                                      (symbol :tag "Face"
951                                              gnus-emphasis-highlight-words)))))
952   :group 'gnus-summary-visual)
953
954 (defcustom gnus-summary-show-article-charset-alist
955   nil
956   "Alist of number and charset.
957 The article will be shown with the charset corresponding to the
958 numbered argument.
959 For example: ((1 . cn-gb-2312) (2 . big5))."
960   :version "21.1"
961   :type '(repeat (cons (number :tag "Argument" 1)
962                        (symbol :tag "Charset")))
963   :group 'gnus-charset)
964
965 (defcustom gnus-preserve-marks t
966   "Whether marks are preserved when moving, copying and respooling messages."
967   :version "21.1"
968   :type 'boolean
969   :group 'gnus-summary-marks)
970
971 (defcustom gnus-alter-articles-to-read-function nil
972   "Function to be called to alter the list of articles to be selected."
973   :type '(choice (const nil) function)
974   :group 'gnus-summary)
975
976 (defcustom gnus-orphan-score nil
977   "*All orphans get this score added.  Set in the score file."
978   :group 'gnus-score-default
979   :type '(choice (const nil)
980                  integer))
981
982 (defcustom gnus-summary-save-parts-default-mime "image/.*"
983   "*A regexp to match MIME parts when saving multiple parts of a message
984 with gnus-summary-save-parts (X m). This regexp will be used by default
985 when prompting the user for which type of files to save."
986   :group 'gnus-summary
987   :type 'regexp)
988
989
990 (defcustom gnus-summary-save-parts-default-mime "image/.*"
991   "*A regexp to match MIME parts when saving multiple parts of a message
992 with gnus-summary-save-parts (X m). This regexp will be used by default
993 when prompting the user for which type of files to save."
994   :group 'gnus-summary
995   :type 'regexp)
996
997 (defcustom gnus-read-all-available-headers nil
998   "Whether Gnus should parse all headers made available to it.
999 This is mostly relevant for slow backends where the user may
1000 wish to widen the summary buffer to include all headers
1001 that were fetched.  Say, for nnultimate groups."
1002   :group 'gnus-summary
1003   :type '(choice boolean regexp))
1004
1005 (defcustom gnus-summary-muttprint-program "muttprint"
1006   "Command (and optional arguments) used to run Muttprint."
1007   :group 'gnus-summary
1008   :type 'string)
1009
1010 ;;; Internal variables
1011
1012 (defvar gnus-summary-display-cache nil)
1013 (defvar gnus-article-mime-handles nil)
1014 (defvar gnus-article-decoded-p nil)
1015 (defvar gnus-article-charset nil)
1016 (defvar gnus-article-ignored-charsets nil)
1017 (defvar gnus-scores-exclude-files nil)
1018 (defvar gnus-page-broken nil)
1019 (defvar gnus-inhibit-mime-unbuttonizing nil)
1020
1021 (defvar gnus-original-article nil)
1022 (defvar gnus-article-internal-prepare-hook nil)
1023 (defvar gnus-newsgroup-process-stack nil)
1024
1025 (defvar gnus-thread-indent-array nil)
1026 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1027 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1028   "Function called to sort the articles within a thread after it has been gathered together.")
1029
1030 (defvar gnus-summary-save-parts-type-history nil)
1031 (defvar gnus-summary-save-parts-last-directory nil)
1032
1033 (defvar gnus-summary-save-parts-type-history nil)
1034 (defvar gnus-summary-save-parts-last-directory nil)
1035
1036 ;; Avoid highlighting in kill files.
1037 (defvar gnus-summary-inhibit-highlight nil)
1038 (defvar gnus-newsgroup-selected-overlay nil)
1039 (defvar gnus-inhibit-limiting nil)
1040 (defvar gnus-newsgroup-adaptive-score-file nil)
1041 (defvar gnus-current-score-file nil)
1042 (defvar gnus-current-move-group nil)
1043 (defvar gnus-current-copy-group nil)
1044 (defvar gnus-current-crosspost-group nil)
1045 (defvar gnus-newsgroup-display nil)
1046
1047 (defvar gnus-newsgroup-dependencies nil)
1048 (defvar gnus-newsgroup-adaptive nil)
1049 (defvar gnus-summary-display-article-function nil)
1050 (defvar gnus-summary-highlight-line-function nil
1051   "Function called after highlighting a summary line.")
1052
1053 (defvar gnus-summary-line-format-alist
1054   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1055     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1056     (?s gnus-tmp-subject-or-nil ?s)
1057     (?n gnus-tmp-name ?s)
1058     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1059         ?s)
1060     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1061             gnus-tmp-from) ?s)
1062     (?F gnus-tmp-from ?s)
1063     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1064     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1065     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1066     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1067     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1068     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1069     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1070     (?L gnus-tmp-lines ?s)
1071     (?I gnus-tmp-indentation ?s)
1072     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1073     (?R gnus-tmp-replied ?c)
1074     (?\[ gnus-tmp-opening-bracket ?c)
1075     (?\] gnus-tmp-closing-bracket ?c)
1076     (?\> (make-string gnus-tmp-level ? ) ?s)
1077     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1078     (?i gnus-tmp-score ?d)
1079     (?z gnus-tmp-score-char ?c)
1080     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1081     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1082     (?U gnus-tmp-unread ?c)
1083     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1084         ?s)
1085     (?t (gnus-summary-number-of-articles-in-thread
1086          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1087         ?d)
1088     (?e (gnus-summary-number-of-articles-in-thread
1089          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1090         ?c)
1091     (?u gnus-tmp-user-defined ?s)
1092     (?P (gnus-pick-line-number) ?d)
1093     (?B gnus-tmp-thread-tree-header-string ?s)
1094     (user-date (gnus-user-date
1095                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1096   "An alist of format specifications that can appear in summary lines.
1097 These are paired with what variables they correspond with, along with
1098 the type of the variable (string, integer, character, etc).")
1099
1100 (defvar gnus-summary-dummy-line-format-alist
1101   `((?S gnus-tmp-subject ?s)
1102     (?N gnus-tmp-number ?d)
1103     (?u gnus-tmp-user-defined ?s)))
1104
1105 (defvar gnus-summary-mode-line-format-alist
1106   `((?G gnus-tmp-group-name ?s)
1107     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1108     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1109     (?A gnus-tmp-article-number ?d)
1110     (?Z gnus-tmp-unread-and-unselected ?s)
1111     (?V gnus-version ?s)
1112     (?U gnus-tmp-unread-and-unticked ?d)
1113     (?S gnus-tmp-subject ?s)
1114     (?e gnus-tmp-unselected ?d)
1115     (?u gnus-tmp-user-defined ?s)
1116     (?d (length gnus-newsgroup-dormant) ?d)
1117     (?t (length gnus-newsgroup-marked) ?d)
1118     (?r (length gnus-newsgroup-reads) ?d)
1119     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1120     (?E gnus-newsgroup-expunged-tally ?d)
1121     (?s (gnus-current-score-file-nondirectory) ?s)))
1122
1123 (defvar gnus-last-search-regexp nil
1124   "Default regexp for article search command.")
1125
1126 (defvar gnus-last-shell-command nil
1127   "Default shell command on article.")
1128
1129 (defvar gnus-newsgroup-begin nil)
1130 (defvar gnus-newsgroup-end nil)
1131 (defvar gnus-newsgroup-last-rmail nil)
1132 (defvar gnus-newsgroup-last-mail nil)
1133 (defvar gnus-newsgroup-last-folder nil)
1134 (defvar gnus-newsgroup-last-file nil)
1135 (defvar gnus-newsgroup-auto-expire nil)
1136 (defvar gnus-newsgroup-active nil)
1137
1138 (defvar gnus-newsgroup-data nil)
1139 (defvar gnus-newsgroup-data-reverse nil)
1140 (defvar gnus-newsgroup-limit nil)
1141 (defvar gnus-newsgroup-limits nil)
1142
1143 (defvar gnus-newsgroup-unreads nil
1144   "List of unread articles in the current newsgroup.")
1145
1146 (defvar gnus-newsgroup-unselected nil
1147   "List of unselected unread articles in the current newsgroup.")
1148
1149 (defvar gnus-newsgroup-reads nil
1150   "Alist of read articles and article marks in the current newsgroup.")
1151
1152 (defvar gnus-newsgroup-expunged-tally nil)
1153
1154 (defvar gnus-newsgroup-marked nil
1155   "List of ticked articles in the current newsgroup (a subset of unread art).")
1156
1157 (defvar gnus-newsgroup-killed nil
1158   "List of ranges of articles that have been through the scoring process.")
1159
1160 (defvar gnus-newsgroup-cached nil
1161   "List of articles that come from the article cache.")
1162
1163 (defvar gnus-newsgroup-saved nil
1164   "List of articles that have been saved.")
1165
1166 (defvar gnus-newsgroup-kill-headers nil)
1167
1168 (defvar gnus-newsgroup-replied nil
1169   "List of articles that have been replied to in the current newsgroup.")
1170
1171 (defvar gnus-newsgroup-forwarded nil
1172   "List of articles that have been forwarded in the current newsgroup.")
1173
1174 (defvar gnus-newsgroup-recent nil
1175   "List of articles that have are recent in the current newsgroup.")
1176
1177 (defvar gnus-newsgroup-expirable nil
1178   "List of articles in the current newsgroup that can be expired.")
1179
1180 (defvar gnus-newsgroup-processable nil
1181   "List of articles in the current newsgroup that can be processed.")
1182
1183 (defvar gnus-newsgroup-downloadable nil
1184   "List of articles in the current newsgroup that can be processed.")
1185
1186 (defvar gnus-newsgroup-undownloaded nil
1187   "List of articles in the current newsgroup that haven't been downloaded..")
1188
1189 (defvar gnus-newsgroup-unsendable nil
1190   "List of articles in the current newsgroup that won't be sent.")
1191
1192 (defvar gnus-newsgroup-bookmarks nil
1193   "List of articles in the current newsgroup that have bookmarks.")
1194
1195 (defvar gnus-newsgroup-dormant nil
1196   "List of dormant articles in the current newsgroup.")
1197
1198 (defvar gnus-newsgroup-unseen nil
1199   "List of unseen articles in the current newsgroup.")
1200
1201 (defvar gnus-newsgroup-seen nil
1202   "Range of seen articles in the current newsgroup.")
1203
1204 (defvar gnus-newsgroup-articles nil
1205   "List of articles in the current newsgroup.")
1206
1207 (defvar gnus-newsgroup-scored nil
1208   "List of scored articles in the current newsgroup.")
1209
1210 (defvar gnus-newsgroup-headers nil
1211   "List of article headers in the current newsgroup.")
1212
1213 (defvar gnus-newsgroup-threads nil)
1214
1215 (defvar gnus-newsgroup-prepared nil
1216   "Whether the current group has been prepared properly.")
1217
1218 (defvar gnus-newsgroup-ancient nil
1219   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1220
1221 (defvar gnus-newsgroup-sparse nil)
1222
1223 (defvar gnus-current-article nil)
1224 (defvar gnus-article-current nil)
1225 (defvar gnus-current-headers nil)
1226 (defvar gnus-have-all-headers nil)
1227 (defvar gnus-last-article nil)
1228 (defvar gnus-newsgroup-history nil)
1229 (defvar gnus-newsgroup-charset nil)
1230 (defvar gnus-newsgroup-ephemeral-charset nil)
1231 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1232
1233 (defvar gnus-article-before-search nil)
1234
1235 (defconst gnus-summary-local-variables
1236   '(gnus-newsgroup-name
1237     gnus-newsgroup-begin gnus-newsgroup-end
1238     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1239     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1240     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1241     gnus-newsgroup-unselected gnus-newsgroup-marked
1242     gnus-newsgroup-reads gnus-newsgroup-saved
1243     gnus-newsgroup-replied gnus-newsgroup-forwarded
1244     gnus-newsgroup-recent
1245     gnus-newsgroup-expirable
1246     gnus-newsgroup-processable gnus-newsgroup-killed
1247     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1248     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1249     gnus-newsgroup-seen gnus-newsgroup-articles
1250     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1251     gnus-newsgroup-headers gnus-newsgroup-threads
1252     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1253     gnus-current-article gnus-current-headers gnus-have-all-headers
1254     gnus-last-article gnus-article-internal-prepare-hook
1255     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1256     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1257     gnus-thread-expunge-below
1258     gnus-score-alist gnus-current-score-file
1259     (gnus-summary-expunge-below . global)
1260     (gnus-summary-mark-below . global)
1261     (gnus-orphan-score . global)
1262     gnus-newsgroup-active gnus-scores-exclude-files
1263     gnus-newsgroup-history gnus-newsgroup-ancient
1264     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1265     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1266     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1267     (gnus-newsgroup-expunged-tally . 0)
1268     gnus-cache-removable-articles gnus-newsgroup-cached
1269     gnus-newsgroup-data gnus-newsgroup-data-reverse
1270     gnus-newsgroup-limit gnus-newsgroup-limits
1271     gnus-newsgroup-charset gnus-newsgroup-display)
1272   "Variables that are buffer-local to the summary buffers.")
1273
1274 (defvar gnus-newsgroup-variables nil
1275   "A list of variables that have separate values in different newsgroups.
1276 A list of newsgroup (summary buffer) local variables, or cons of
1277 variables and their default values (when the default values are not
1278 nil), that should be made global while the summary buffer is active.
1279 These variables can be used to set variables in the group parameters
1280 while still allowing them to affect operations done in other
1281 buffers. For example:
1282
1283 \(setq gnus-newsgroup-variables
1284      '(message-use-followup-to
1285        (gnus-visible-headers .
1286          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1287 ")
1288
1289 ;; Byte-compiler warning.
1290 (eval-when-compile (defvar gnus-article-mode-map))
1291
1292 ;; MIME stuff.
1293
1294 (defvar gnus-decode-encoded-word-methods
1295   '(mail-decode-encoded-word-string)
1296   "List of methods used to decode encoded words.
1297
1298 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1299 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1300 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1301 whose names match REGEXP.
1302
1303 For example:
1304 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1305  mail-decode-encoded-word-string
1306  (\"chinese\" . rfc1843-decode-string))")
1307
1308 (defvar gnus-decode-encoded-word-methods-cache nil)
1309
1310 (defun gnus-multi-decode-encoded-word-string (string)
1311   "Apply the functions from `gnus-encoded-word-methods' that match."
1312   (unless (and gnus-decode-encoded-word-methods-cache
1313                (eq gnus-newsgroup-name
1314                    (car gnus-decode-encoded-word-methods-cache)))
1315     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1316     (mapcar (lambda (x)
1317               (if (symbolp x)
1318                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1319                 (if (and gnus-newsgroup-name
1320                          (string-match (car x) gnus-newsgroup-name))
1321                     (nconc gnus-decode-encoded-word-methods-cache
1322                            (list (cdr x))))))
1323             gnus-decode-encoded-word-methods))
1324   (let ((xlist gnus-decode-encoded-word-methods-cache))
1325     (pop xlist)
1326     (while xlist
1327       (setq string (funcall (pop xlist) string))))
1328   string)
1329
1330 ;; Subject simplification.
1331
1332 (defun gnus-simplify-whitespace (str)
1333   "Remove excessive whitespace from STR."
1334   (let ((mystr str))
1335     ;; Multiple spaces.
1336     (while (string-match "[ \t][ \t]+" mystr)
1337       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1338                           " "
1339                           (substring mystr (match-end 0)))))
1340     ;; Leading spaces.
1341     (when (string-match "^[ \t]+" mystr)
1342       (setq mystr (substring mystr (match-end 0))))
1343     ;; Trailing spaces.
1344     (when (string-match "[ \t]+$" mystr)
1345       (setq mystr (substring mystr 0 (match-beginning 0))))
1346     mystr))
1347
1348 (defsubst gnus-simplify-subject-re (subject)
1349   "Remove \"Re:\" from subject lines."
1350   (if (string-match message-subject-re-regexp subject)
1351       (substring subject (match-end 0))
1352     subject))
1353
1354 (defun gnus-simplify-subject (subject &optional re-only)
1355   "Remove `Re:' and words in parentheses.
1356 If RE-ONLY is non-nil, strip leading `Re:'s only."
1357   (let ((case-fold-search t))           ;Ignore case.
1358     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1359     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1360       (setq subject (substring subject (match-end 0))))
1361     ;; Remove uninteresting prefixes.
1362     (when (and (not re-only)
1363                gnus-simplify-ignored-prefixes
1364                (string-match gnus-simplify-ignored-prefixes subject))
1365       (setq subject (substring subject (match-end 0))))
1366     ;; Remove words in parentheses from end.
1367     (unless re-only
1368       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1369         (setq subject (substring subject 0 (match-beginning 0)))))
1370     ;; Return subject string.
1371     subject))
1372
1373 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1374 ;; all whitespace.
1375 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1376   (goto-char (point-min))
1377   (while (re-search-forward regexp nil t)
1378     (replace-match (or newtext ""))))
1379
1380 (defun gnus-simplify-buffer-fuzzy ()
1381   "Simplify string in the buffer fuzzily.
1382 The string in the accessible portion of the current buffer is simplified.
1383 It is assumed to be a single-line subject.
1384 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1385 matter is removed.  Additional things can be deleted by setting
1386 `gnus-simplify-subject-fuzzy-regexp'."
1387   (let ((case-fold-search t)
1388         (modified-tick))
1389     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1390
1391     (while (not (eq modified-tick (buffer-modified-tick)))
1392       (setq modified-tick (buffer-modified-tick))
1393       (cond
1394        ((listp gnus-simplify-subject-fuzzy-regexp)
1395         (mapcar 'gnus-simplify-buffer-fuzzy-step
1396                 gnus-simplify-subject-fuzzy-regexp))
1397        (gnus-simplify-subject-fuzzy-regexp
1398         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1399       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1400       (gnus-simplify-buffer-fuzzy-step
1401        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1402       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1403
1404     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1405     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1406     (gnus-simplify-buffer-fuzzy-step " $")
1407     (gnus-simplify-buffer-fuzzy-step "^ +")))
1408
1409 (defun gnus-simplify-subject-fuzzy (subject)
1410   "Simplify a subject string fuzzily.
1411 See `gnus-simplify-buffer-fuzzy' for details."
1412   (save-excursion
1413     (gnus-set-work-buffer)
1414     (let ((case-fold-search t))
1415       ;; Remove uninteresting prefixes.
1416       (when (and gnus-simplify-ignored-prefixes
1417                  (string-match gnus-simplify-ignored-prefixes subject))
1418         (setq subject (substring subject (match-end 0))))
1419       (insert subject)
1420       (inline (gnus-simplify-buffer-fuzzy))
1421       (buffer-string))))
1422
1423 (defsubst gnus-simplify-subject-fully (subject)
1424   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1425   (cond
1426    (gnus-simplify-subject-functions
1427     (gnus-map-function gnus-simplify-subject-functions subject))
1428    ((null gnus-summary-gather-subject-limit)
1429     (gnus-simplify-subject-re subject))
1430    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1431     (gnus-simplify-subject-fuzzy subject))
1432    ((numberp gnus-summary-gather-subject-limit)
1433     (gnus-limit-string (gnus-simplify-subject-re subject)
1434                        gnus-summary-gather-subject-limit))
1435    (t
1436     subject)))
1437
1438 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1439   "Check whether two subjects are equal.
1440 If optional argument simple-first is t, first argument is already
1441 simplified."
1442   (cond
1443    ((null simple-first)
1444     (equal (gnus-simplify-subject-fully s1)
1445            (gnus-simplify-subject-fully s2)))
1446    (t
1447     (equal s1
1448            (gnus-simplify-subject-fully s2)))))
1449
1450 (defun gnus-summary-bubble-group ()
1451   "Increase the score of the current group.
1452 This is a handy function to add to `gnus-summary-exit-hook' to
1453 increase the score of each group you read."
1454   (gnus-group-add-score gnus-newsgroup-name))
1455
1456 \f
1457 ;;;
1458 ;;; Gnus summary mode
1459 ;;;
1460
1461 (put 'gnus-summary-mode 'mode-class 'special)
1462
1463 (defvar gnus-article-commands-menu)
1464
1465 (when t
1466   ;; Non-orthogonal keys
1467
1468   (gnus-define-keys gnus-summary-mode-map
1469     " " gnus-summary-next-page
1470     "\177" gnus-summary-prev-page
1471     [delete] gnus-summary-prev-page
1472     [backspace] gnus-summary-prev-page
1473     "\r" gnus-summary-scroll-up
1474     "\M-\r" gnus-summary-scroll-down
1475     "n" gnus-summary-next-unread-article
1476     "p" gnus-summary-prev-unread-article
1477     "N" gnus-summary-next-article
1478     "P" gnus-summary-prev-article
1479     "\M-\C-n" gnus-summary-next-same-subject
1480     "\M-\C-p" gnus-summary-prev-same-subject
1481     "\M-n" gnus-summary-next-unread-subject
1482     "\M-p" gnus-summary-prev-unread-subject
1483     "." gnus-summary-first-unread-article
1484     "," gnus-summary-best-unread-article
1485     "\M-s" gnus-summary-search-article-forward
1486     "\M-r" gnus-summary-search-article-backward
1487     "<" gnus-summary-beginning-of-article
1488     ">" gnus-summary-end-of-article
1489     "j" gnus-summary-goto-article
1490     "^" gnus-summary-refer-parent-article
1491     "\M-^" gnus-summary-refer-article
1492     "u" gnus-summary-tick-article-forward
1493     "!" gnus-summary-tick-article-forward
1494     "U" gnus-summary-tick-article-backward
1495     "d" gnus-summary-mark-as-read-forward
1496     "D" gnus-summary-mark-as-read-backward
1497     "E" gnus-summary-mark-as-expirable
1498     "\M-u" gnus-summary-clear-mark-forward
1499     "\M-U" gnus-summary-clear-mark-backward
1500     "k" gnus-summary-kill-same-subject-and-select
1501     "\C-k" gnus-summary-kill-same-subject
1502     "\M-\C-k" gnus-summary-kill-thread
1503     "\M-\C-l" gnus-summary-lower-thread
1504     "e" gnus-summary-edit-article
1505     "#" gnus-summary-mark-as-processable
1506     "\M-#" gnus-summary-unmark-as-processable
1507     "\M-\C-t" gnus-summary-toggle-threads
1508     "\M-\C-s" gnus-summary-show-thread
1509     "\M-\C-h" gnus-summary-hide-thread
1510     "\M-\C-f" gnus-summary-next-thread
1511     "\M-\C-b" gnus-summary-prev-thread
1512     [(meta down)] gnus-summary-next-thread
1513     [(meta up)] gnus-summary-prev-thread
1514     "\M-\C-u" gnus-summary-up-thread
1515     "\M-\C-d" gnus-summary-down-thread
1516     "&" gnus-summary-execute-command
1517     "c" gnus-summary-catchup-and-exit
1518     "\C-w" gnus-summary-mark-region-as-read
1519     "\C-t" gnus-summary-toggle-truncation
1520     "?" gnus-summary-mark-as-dormant
1521     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1522     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1523     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1524     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1525     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1526     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1527     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1528     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1529     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1530     "=" gnus-summary-expand-window
1531     "\C-x\C-s" gnus-summary-reselect-current-group
1532     "\M-g" gnus-summary-rescan-group
1533     "w" gnus-summary-stop-page-breaking
1534     "\C-c\C-r" gnus-summary-caesar-message
1535     "f" gnus-summary-followup
1536     "F" gnus-summary-followup-with-original
1537     "C" gnus-summary-cancel-article
1538     "r" gnus-summary-reply
1539     "R" gnus-summary-reply-with-original
1540     "\C-c\C-f" gnus-summary-mail-forward
1541     "o" gnus-summary-save-article
1542     "\C-o" gnus-summary-save-article-mail
1543     "|" gnus-summary-pipe-output
1544     "\M-k" gnus-summary-edit-local-kill
1545     "\M-K" gnus-summary-edit-global-kill
1546     ;; "V" gnus-version
1547     "\C-c\C-d" gnus-summary-describe-group
1548     "q" gnus-summary-exit
1549     "Q" gnus-summary-exit-no-update
1550     "\C-c\C-i" gnus-info-find-node
1551     gnus-mouse-2 gnus-mouse-pick-article
1552     "m" gnus-summary-mail-other-window
1553     "a" gnus-summary-post-news
1554     "i" gnus-summary-news-other-window
1555     "x" gnus-summary-limit-to-unread
1556     "s" gnus-summary-isearch-article
1557     "t" gnus-summary-toggle-header
1558     "g" gnus-summary-show-article
1559     "l" gnus-summary-goto-last-article
1560     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1561     "\C-d" gnus-summary-enter-digest-group
1562     "\M-\C-d" gnus-summary-read-document
1563     "\M-\C-e" gnus-summary-edit-parameters
1564     "\M-\C-a" gnus-summary-customize-parameters
1565     "\C-c\C-b" gnus-bug
1566     "*" gnus-cache-enter-article
1567     "\M-*" gnus-cache-remove-article
1568     "\M-&" gnus-summary-universal-argument
1569     "\C-l" gnus-recenter
1570     "I" gnus-summary-increase-score
1571     "L" gnus-summary-lower-score
1572     "\M-i" gnus-symbolic-argument
1573     "h" gnus-summary-select-article-buffer
1574
1575     "b" gnus-article-view-part
1576     "\M-t" gnus-summary-toggle-display-buttonized
1577
1578     "V" gnus-summary-score-map
1579     "X" gnus-uu-extract-map
1580     "S" gnus-summary-send-map)
1581
1582   ;; Sort of orthogonal keymap
1583   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1584     "t" gnus-summary-tick-article-forward
1585     "!" gnus-summary-tick-article-forward
1586     "d" gnus-summary-mark-as-read-forward
1587     "r" gnus-summary-mark-as-read-forward
1588     "c" gnus-summary-clear-mark-forward
1589     " " gnus-summary-clear-mark-forward
1590     "e" gnus-summary-mark-as-expirable
1591     "x" gnus-summary-mark-as-expirable
1592     "?" gnus-summary-mark-as-dormant
1593     "b" gnus-summary-set-bookmark
1594     "B" gnus-summary-remove-bookmark
1595     "#" gnus-summary-mark-as-processable
1596     "\M-#" gnus-summary-unmark-as-processable
1597     "S" gnus-summary-limit-include-expunged
1598     "C" gnus-summary-catchup
1599     "H" gnus-summary-catchup-to-here
1600     "h" gnus-summary-catchup-from-here
1601     "\C-c" gnus-summary-catchup-all
1602     "k" gnus-summary-kill-same-subject-and-select
1603     "K" gnus-summary-kill-same-subject
1604     "P" gnus-uu-mark-map)
1605
1606   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1607     "c" gnus-summary-clear-above
1608     "u" gnus-summary-tick-above
1609     "m" gnus-summary-mark-above
1610     "k" gnus-summary-kill-below)
1611
1612   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1613     "/" gnus-summary-limit-to-subject
1614     "n" gnus-summary-limit-to-articles
1615     "w" gnus-summary-pop-limit
1616     "s" gnus-summary-limit-to-subject
1617     "a" gnus-summary-limit-to-author
1618     "u" gnus-summary-limit-to-unread
1619     "m" gnus-summary-limit-to-marks
1620     "M" gnus-summary-limit-exclude-marks
1621     "v" gnus-summary-limit-to-score
1622     "*" gnus-summary-limit-include-cached
1623     "D" gnus-summary-limit-include-dormant
1624     "T" gnus-summary-limit-include-thread
1625     "d" gnus-summary-limit-exclude-dormant
1626     "t" gnus-summary-limit-to-age
1627     "x" gnus-summary-limit-to-extra
1628     "p" gnus-summary-limit-to-display-predicate
1629     "E" gnus-summary-limit-include-expunged
1630     "c" gnus-summary-limit-exclude-childless-dormant
1631     "C" gnus-summary-limit-mark-excluded-as-read
1632     "o" gnus-summary-insert-old-articles
1633     "N" gnus-summary-insert-new-articles)
1634
1635   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1636     "n" gnus-summary-next-unread-article
1637     "p" gnus-summary-prev-unread-article
1638     "N" gnus-summary-next-article
1639     "P" gnus-summary-prev-article
1640     "\C-n" gnus-summary-next-same-subject
1641     "\C-p" gnus-summary-prev-same-subject
1642     "\M-n" gnus-summary-next-unread-subject
1643     "\M-p" gnus-summary-prev-unread-subject
1644     "f" gnus-summary-first-unread-article
1645     "b" gnus-summary-best-unread-article
1646     "j" gnus-summary-goto-article
1647     "g" gnus-summary-goto-subject
1648     "l" gnus-summary-goto-last-article
1649     "o" gnus-summary-pop-article)
1650
1651   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1652     "k" gnus-summary-kill-thread
1653     "l" gnus-summary-lower-thread
1654     "i" gnus-summary-raise-thread
1655     "T" gnus-summary-toggle-threads
1656     "t" gnus-summary-rethread-current
1657     "^" gnus-summary-reparent-thread
1658     "s" gnus-summary-show-thread
1659     "S" gnus-summary-show-all-threads
1660     "h" gnus-summary-hide-thread
1661     "H" gnus-summary-hide-all-threads
1662     "n" gnus-summary-next-thread
1663     "p" gnus-summary-prev-thread
1664     "u" gnus-summary-up-thread
1665     "o" gnus-summary-top-thread
1666     "d" gnus-summary-down-thread
1667     "#" gnus-uu-mark-thread
1668     "\M-#" gnus-uu-unmark-thread)
1669
1670   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1671     "g" gnus-summary-prepare
1672     "c" gnus-summary-insert-cached-articles)
1673
1674   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1675     "c" gnus-summary-catchup-and-exit
1676     "C" gnus-summary-catchup-all-and-exit
1677     "E" gnus-summary-exit-no-update
1678     "Q" gnus-summary-exit
1679     "Z" gnus-summary-exit
1680     "n" gnus-summary-catchup-and-goto-next-group
1681     "R" gnus-summary-reselect-current-group
1682     "G" gnus-summary-rescan-group
1683     "N" gnus-summary-next-group
1684     "s" gnus-summary-save-newsrc
1685     "P" gnus-summary-prev-group)
1686
1687   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1688     " " gnus-summary-next-page
1689     "n" gnus-summary-next-page
1690     "\177" gnus-summary-prev-page
1691     [delete] gnus-summary-prev-page
1692     "p" gnus-summary-prev-page
1693     "\r" gnus-summary-scroll-up
1694     "\M-\r" gnus-summary-scroll-down
1695     "<" gnus-summary-beginning-of-article
1696     ">" gnus-summary-end-of-article
1697     "b" gnus-summary-beginning-of-article
1698     "e" gnus-summary-end-of-article
1699     "^" gnus-summary-refer-parent-article
1700     "r" gnus-summary-refer-parent-article
1701     "D" gnus-summary-enter-digest-group
1702     "R" gnus-summary-refer-references
1703     "T" gnus-summary-refer-thread
1704     "g" gnus-summary-show-article
1705     "s" gnus-summary-isearch-article
1706     "P" gnus-summary-print-article
1707     "M" gnus-mailing-list-insinuate
1708     "t" gnus-article-babel)
1709
1710   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1711     "b" gnus-article-add-buttons
1712     "B" gnus-article-add-buttons-to-head
1713     "o" gnus-article-treat-overstrike
1714     "e" gnus-article-emphasize
1715     "w" gnus-article-fill-cited-article
1716     "Q" gnus-article-fill-long-lines
1717     "C" gnus-article-capitalize-sentences
1718     "c" gnus-article-remove-cr
1719     "q" gnus-article-de-quoted-unreadable
1720     "6" gnus-article-de-base64-unreadable
1721     "Z" gnus-article-decode-HZ
1722     "h" gnus-article-wash-html
1723     "s" gnus-summary-force-verify-and-decrypt
1724     "f" gnus-article-display-x-face
1725     "l" gnus-summary-stop-page-breaking
1726     "r" gnus-summary-caesar-message
1727     "t" gnus-summary-toggle-header
1728     "g" gnus-summary-toggle-smiley
1729     "u" gnus-article-treat-unfold-headers
1730     "n" gnus-article-treat-fold-newsgroups
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-display-map "D" gnus-summary-wash-map)
1756     "x" gnus-article-display-x-face
1757     "s" gnus-summary-toggle-smiley
1758     "f" gnus-treat-from-picon
1759     "m" gnus-treat-mail-picon
1760     "n" gnus-treat-newsgroups-picon)
1761
1762   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1763     "w" gnus-article-decode-mime-words
1764     "c" gnus-article-decode-charset
1765     "v" gnus-mime-view-all-parts
1766     "b" gnus-article-view-part)
1767
1768   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1769     "z" gnus-article-date-ut
1770     "u" gnus-article-date-ut
1771     "l" gnus-article-date-local
1772     "p" gnus-article-date-english
1773     "e" gnus-article-date-lapsed
1774     "o" gnus-article-date-original
1775     "i" gnus-article-date-iso8601
1776     "s" gnus-article-date-user)
1777
1778   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1779     "t" gnus-article-remove-trailing-blank-lines
1780     "l" gnus-article-strip-leading-blank-lines
1781     "m" gnus-article-strip-multiple-blank-lines
1782     "a" gnus-article-strip-blank-lines
1783     "A" gnus-article-strip-all-blank-lines
1784     "s" gnus-article-strip-leading-space
1785     "e" gnus-article-strip-trailing-space
1786     "w" gnus-article-remove-leading-whitespace)
1787
1788   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1789     "v" gnus-version
1790     "f" gnus-summary-fetch-faq
1791     "d" gnus-summary-describe-group
1792     "h" gnus-summary-describe-briefly
1793     "i" gnus-info-find-node)
1794
1795   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1796     "e" gnus-summary-expire-articles
1797     "\M-\C-e" gnus-summary-expire-articles-now
1798     "\177" gnus-summary-delete-article
1799     [delete] gnus-summary-delete-article
1800     [backspace] gnus-summary-delete-article
1801     "m" gnus-summary-move-article
1802     "r" gnus-summary-respool-article
1803     "w" gnus-summary-edit-article
1804     "c" gnus-summary-copy-article
1805     "B" gnus-summary-crosspost-article
1806     "q" gnus-summary-respool-query
1807     "t" gnus-summary-respool-trace
1808     "i" gnus-summary-import-article
1809     "I" gnus-summary-create-article
1810     "p" gnus-summary-article-posted-p)
1811
1812   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1813     "o" gnus-summary-save-article
1814     "m" gnus-summary-save-article-mail
1815     "F" gnus-summary-write-article-file
1816     "r" gnus-summary-save-article-rmail
1817     "f" gnus-summary-save-article-file
1818     "b" gnus-summary-save-article-body-file
1819     "h" gnus-summary-save-article-folder
1820     "v" gnus-summary-save-article-vm
1821     "p" gnus-summary-pipe-output
1822     "P" gnus-summary-muttprint
1823     "s" gnus-soup-add-article)
1824
1825   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1826     "b" gnus-summary-display-buttonized
1827     "m" gnus-summary-repair-multipart
1828     "v" gnus-article-view-part
1829     "o" gnus-article-save-part
1830     "c" gnus-article-copy-part
1831     "C" gnus-article-view-part-as-charset
1832     "e" gnus-article-externalize-part
1833     "E" gnus-article-encrypt-body
1834     "i" gnus-article-inline-part
1835     "|" gnus-article-pipe-part))
1836
1837 (defvar gnus-article-post-menu nil)
1838
1839 (defun gnus-summary-make-menu-bar ()
1840   (gnus-turn-off-edit-menu 'summary)
1841
1842   (unless (boundp 'gnus-summary-misc-menu)
1843
1844     (easy-menu-define
1845       gnus-summary-kill-menu gnus-summary-mode-map ""
1846       (cons
1847        "Score"
1848        (nconc
1849         (list
1850          ["Customize" gnus-score-customize t])
1851         (gnus-make-score-map 'increase)
1852         (gnus-make-score-map 'lower)
1853         '(("Mark"
1854            ["Kill below" gnus-summary-kill-below t]
1855            ["Mark above" gnus-summary-mark-above t]
1856            ["Tick above" gnus-summary-tick-above t]
1857            ["Clear above" gnus-summary-clear-above t])
1858           ["Current score" gnus-summary-current-score t]
1859           ["Set score" gnus-summary-set-score t]
1860           ["Switch current score file..." gnus-score-change-score-file t]
1861           ["Set mark below..." gnus-score-set-mark-below t]
1862           ["Set expunge below..." gnus-score-set-expunge-below t]
1863           ["Edit current score file" gnus-score-edit-current-scores t]
1864           ["Edit score file" gnus-score-edit-file t]
1865           ["Trace score" gnus-score-find-trace t]
1866           ["Find words" gnus-score-find-favourite-words t]
1867           ["Rescore buffer" gnus-summary-rescore t]
1868           ["Increase score..." gnus-summary-increase-score t]
1869           ["Lower score..." gnus-summary-lower-score t]))))
1870
1871     ;; Define both the Article menu in the summary buffer and the
1872     ;; equivalent Commands menu in the article buffer here for
1873     ;; consistency.
1874     (let ((innards
1875            `(("Hide"
1876               ["All" gnus-article-hide t]
1877               ["Headers" gnus-article-hide-headers t]
1878               ["Signature" gnus-article-hide-signature t]
1879               ["Citation" gnus-article-hide-citation t]
1880               ["List identifiers" gnus-article-hide-list-identifiers t]
1881               ["PGP" gnus-article-hide-pgp t]
1882               ["Banner" gnus-article-strip-banner t]
1883               ["Boring headers" gnus-article-hide-boring-headers t])
1884              ("Highlight"
1885               ["All" gnus-article-highlight t]
1886               ["Headers" gnus-article-highlight-headers t]
1887               ["Signature" gnus-article-highlight-signature t]
1888               ["Citation" gnus-article-highlight-citation t])
1889              ("MIME"
1890               ["Words" gnus-article-decode-mime-words t]
1891               ["Charset" gnus-article-decode-charset t]
1892               ["QP" gnus-article-de-quoted-unreadable t]
1893               ["Base64" gnus-article-de-base64-unreadable t]
1894               ["View all" gnus-mime-view-all-parts t]
1895               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1896               ["Encrypt body" gnus-article-encrypt-body t])
1897              ("Date"
1898               ["Local" gnus-article-date-local t]
1899               ["ISO8601" gnus-article-date-iso8601 t]
1900               ["UT" gnus-article-date-ut t]
1901               ["Original" gnus-article-date-original t]
1902               ["Lapsed" gnus-article-date-lapsed t]
1903               ["User-defined" gnus-article-date-user t])
1904              ("Display"
1905               ["Toggle smiley" gnus-summary-toggle-smiley t]
1906               ["Show X-Face" gnus-article-display-x-face t]
1907               ["Show picons in From" gnus-treat-from-picon t]
1908               ["Show picons in mail headers" gnus-treat-mail-picon t]
1909               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1910              ("Washing"
1911               ("Remove Blanks"
1912                ["Leading" gnus-article-strip-leading-blank-lines t]
1913                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1914                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1915                ["All of the above" gnus-article-strip-blank-lines t]
1916                ["All" gnus-article-strip-all-blank-lines t]
1917                ["Leading space" gnus-article-strip-leading-space t]
1918                ["Trailing space" gnus-article-strip-trailing-space t]
1919                ["Leading space in headers"
1920                 gnus-article-remove-leading-whitespace t])
1921               ["Overstrike" gnus-article-treat-overstrike t]
1922               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1923               ["Emphasis" gnus-article-emphasize t]
1924               ["Word wrap" gnus-article-fill-cited-article t]
1925               ["Fill long lines" gnus-article-fill-long-lines t]
1926               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1927               ["CR" gnus-article-remove-cr t]
1928               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1929               ["Base64" gnus-article-de-base64-unreadable t]
1930               ["Rot 13" gnus-summary-caesar-message
1931                ,@(if (featurep 'xemacs) '(t)
1932                    '(:help "\"Caesar rotate\" article by 13"))]
1933               ["Unix pipe" gnus-summary-pipe-message t]
1934               ["Add buttons" gnus-article-add-buttons t]
1935               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1936               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1937               ["Verbose header" gnus-summary-verbose-headers t]
1938               ["Toggle header" gnus-summary-toggle-header t]
1939               ["Unfold headers" gnus-article-treat-unfold-headers t]
1940               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1941               ["Html" gnus-article-wash-html t]
1942               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1943               ["HZ" gnus-article-decode-HZ t])
1944              ("Output"
1945               ["Save in default format" gnus-summary-save-article
1946                ,@(if (featurep 'xemacs) '(t)
1947                    '(:help "Save article using default method"))]
1948               ["Save in file" gnus-summary-save-article-file
1949                ,@(if (featurep 'xemacs) '(t)
1950                    '(:help "Save article in file"))]
1951               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1952               ["Save in MH folder" gnus-summary-save-article-folder t]
1953               ["Save in VM folder" gnus-summary-save-article-vm t]
1954               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1955               ["Save body in file" gnus-summary-save-article-body-file t]
1956               ["Pipe through a filter" gnus-summary-pipe-output t]
1957               ["Add to SOUP packet" gnus-soup-add-article t]
1958               ["Print with Muttprint" gnus-summary-muttprint t]
1959               ["Print" gnus-summary-print-article t])
1960              ("Backend"
1961               ["Respool article..." gnus-summary-respool-article t]
1962               ["Move article..." gnus-summary-move-article
1963                (gnus-check-backend-function
1964                 'request-move-article gnus-newsgroup-name)]
1965               ["Copy article..." gnus-summary-copy-article t]
1966               ["Crosspost article..." gnus-summary-crosspost-article
1967                (gnus-check-backend-function
1968                 'request-replace-article gnus-newsgroup-name)]
1969               ["Import file..." gnus-summary-import-article t]
1970               ["Create article..." gnus-summary-create-article t]
1971               ["Check if posted" gnus-summary-article-posted-p t]
1972               ["Edit article" gnus-summary-edit-article
1973                (not (gnus-group-read-only-p))]
1974               ["Delete article" gnus-summary-delete-article
1975                (gnus-check-backend-function
1976                 'request-expire-articles gnus-newsgroup-name)]
1977               ["Query respool" gnus-summary-respool-query t]
1978               ["Trace respool" gnus-summary-respool-trace t]
1979               ["Delete expirable articles" gnus-summary-expire-articles-now
1980                (gnus-check-backend-function
1981                 'request-expire-articles gnus-newsgroup-name)])
1982              ("Extract"
1983               ["Uudecode" gnus-uu-decode-uu
1984                ,@(if (featurep 'xemacs) '(t)
1985                    '(:help "Decode uuencoded article(s)"))]
1986               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1987               ["Unshar" gnus-uu-decode-unshar t]
1988               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1989               ["Save" gnus-uu-decode-save t]
1990               ["Binhex" gnus-uu-decode-binhex t]
1991               ["Postscript" gnus-uu-decode-postscript t])
1992              ("Cache"
1993               ["Enter article" gnus-cache-enter-article t]
1994               ["Remove article" gnus-cache-remove-article t])
1995              ["Translate" gnus-article-babel t]
1996              ["Select article buffer" gnus-summary-select-article-buffer t]
1997              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1998              ["Isearch article..." gnus-summary-isearch-article t]
1999              ["Beginning of the article" gnus-summary-beginning-of-article t]
2000              ["End of the article" gnus-summary-end-of-article t]
2001              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2002              ["Fetch referenced articles" gnus-summary-refer-references t]
2003              ["Fetch current thread" gnus-summary-refer-thread t]
2004              ["Fetch article with id..." gnus-summary-refer-article t]
2005              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2006              ["Redisplay" gnus-summary-show-article t]
2007              ["Raw article" gnus-summary-show-raw-article t])))
2008       (easy-menu-define
2009         gnus-summary-article-menu gnus-summary-mode-map ""
2010         (cons "Article" innards))
2011
2012       (if (not (keymapp gnus-summary-article-menu))
2013           (easy-menu-define
2014             gnus-article-commands-menu gnus-article-mode-map ""
2015             (cons "Commands" innards))
2016         ;; in Emacs, don't share menu.
2017         (setq gnus-article-commands-menu
2018               (copy-keymap gnus-summary-article-menu))
2019         (define-key gnus-article-mode-map [menu-bar commands]
2020           (cons "Commands" gnus-article-commands-menu))))
2021
2022     (easy-menu-define
2023       gnus-summary-thread-menu gnus-summary-mode-map ""
2024       '("Threads"
2025         ["Toggle threading" gnus-summary-toggle-threads t]
2026         ["Hide threads" gnus-summary-hide-all-threads t]
2027         ["Show threads" gnus-summary-show-all-threads t]
2028         ["Hide thread" gnus-summary-hide-thread t]
2029         ["Show thread" gnus-summary-show-thread t]
2030         ["Go to next thread" gnus-summary-next-thread t]
2031         ["Go to previous thread" gnus-summary-prev-thread t]
2032         ["Go down thread" gnus-summary-down-thread t]
2033         ["Go up thread" gnus-summary-up-thread t]
2034         ["Top of thread" gnus-summary-top-thread t]
2035         ["Mark thread as read" gnus-summary-kill-thread t]
2036         ["Lower thread score" gnus-summary-lower-thread t]
2037         ["Raise thread score" gnus-summary-raise-thread t]
2038         ["Rethread current" gnus-summary-rethread-current t]))
2039
2040     (easy-menu-define
2041       gnus-summary-post-menu gnus-summary-mode-map ""
2042       `("Post"
2043         ["Send a message (mail or news)" gnus-summary-post-news
2044          ,@(if (featurep 'xemacs) '(t)
2045              '(:help "Post an article"))]
2046         ["Followup" gnus-summary-followup
2047          ,@(if (featurep 'xemacs) '(t)
2048              '(:help "Post followup to this article"))]
2049         ["Followup and yank" gnus-summary-followup-with-original
2050          ,@(if (featurep 'xemacs) '(t)
2051              '(:help "Post followup to this article, quoting its contents"))]
2052         ["Supersede article" gnus-summary-supersede-article t]
2053         ["Cancel article" gnus-summary-cancel-article
2054          ,@(if (featurep 'xemacs) '(t)
2055              '(:help "Cancel an article you posted"))]
2056         ["Reply" gnus-summary-reply t]
2057         ["Reply and yank" gnus-summary-reply-with-original t]
2058         ["Wide reply" gnus-summary-wide-reply t]
2059         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2060          ,@(if (featurep 'xemacs) '(t)
2061              '(:help "Mail a reply, quoting this article"))]
2062         ["Mail forward" gnus-summary-mail-forward t]
2063         ["Post forward" gnus-summary-post-forward t]
2064         ["Digest and mail" gnus-uu-digest-mail-forward t]
2065         ["Digest and post" gnus-uu-digest-post-forward t]
2066         ["Resend message" gnus-summary-resend-message t]
2067         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2068         ["Send a mail" gnus-summary-mail-other-window t]
2069         ["Create a local message" gnus-summary-news-other-window t]
2070         ["Uuencode and post" gnus-uu-post-news
2071          ,@(if (featurep 'xemacs) '(t)
2072              '(:help "Post a uuencoded article"))]
2073         ["Followup via news" gnus-summary-followup-to-mail t]
2074         ["Followup via news and yank"
2075          gnus-summary-followup-to-mail-with-original t]
2076         ;;("Draft"
2077         ;;["Send" gnus-summary-send-draft t]
2078         ;;["Send bounced" gnus-resend-bounced-mail t])
2079         ))
2080
2081     (cond
2082      ((not (keymapp gnus-summary-post-menu))
2083       (setq gnus-article-post-menu gnus-summary-post-menu))
2084      ((not gnus-article-post-menu)
2085       ;; Don't share post menu.
2086       (setq gnus-article-post-menu
2087             (copy-keymap gnus-summary-post-menu))))
2088     (define-key gnus-article-mode-map [menu-bar post]
2089       (cons "Post" gnus-article-post-menu))
2090
2091     (easy-menu-define
2092       gnus-summary-misc-menu gnus-summary-mode-map ""
2093       `("Gnus"
2094         ("Mark Read"
2095          ["Mark as read" gnus-summary-mark-as-read-forward t]
2096          ["Mark same subject and select"
2097           gnus-summary-kill-same-subject-and-select t]
2098          ["Mark same subject" gnus-summary-kill-same-subject t]
2099          ["Catchup" gnus-summary-catchup
2100           ,@(if (featurep 'xemacs) '(t)
2101               '(:help "Mark unread articles in this group as read"))]
2102          ["Catchup all" gnus-summary-catchup-all t]
2103          ["Catchup to here" gnus-summary-catchup-to-here t]
2104          ["Catchup from here" gnus-summary-catchup-from-here t]
2105          ["Catchup region" gnus-summary-mark-region-as-read t]
2106          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2107         ("Mark Various"
2108          ["Tick" gnus-summary-tick-article-forward t]
2109          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2110          ["Remove marks" gnus-summary-clear-mark-forward t]
2111          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2112          ["Set bookmark" gnus-summary-set-bookmark t]
2113          ["Remove bookmark" gnus-summary-remove-bookmark t])
2114         ("Limit to"
2115          ["Marks..." gnus-summary-limit-to-marks t]
2116          ["Subject..." gnus-summary-limit-to-subject t]
2117          ["Author..." gnus-summary-limit-to-author t]
2118          ["Age..." gnus-summary-limit-to-age t]
2119          ["Extra..." gnus-summary-limit-to-extra t]
2120          ["Score" gnus-summary-limit-to-score t]
2121          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2122          ["Unread" gnus-summary-limit-to-unread t]
2123          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2124          ["Articles" gnus-summary-limit-to-articles t]
2125          ["Pop limit" gnus-summary-pop-limit t]
2126          ["Show dormant" gnus-summary-limit-include-dormant t]
2127          ["Hide childless dormant"
2128           gnus-summary-limit-exclude-childless-dormant t]
2129          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2130          ["Hide marked" gnus-summary-limit-exclude-marks t]
2131          ["Show expunged" gnus-summary-limit-include-expunged t])
2132         ("Process Mark"
2133          ["Set mark" gnus-summary-mark-as-processable t]
2134          ["Remove mark" gnus-summary-unmark-as-processable t]
2135          ["Remove all marks" gnus-summary-unmark-all-processable t]
2136          ["Mark above" gnus-uu-mark-over t]
2137          ["Mark series" gnus-uu-mark-series t]
2138          ["Mark region" gnus-uu-mark-region t]
2139          ["Unmark region" gnus-uu-unmark-region t]
2140          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2141          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2142          ["Mark all" gnus-uu-mark-all t]
2143          ["Mark buffer" gnus-uu-mark-buffer t]
2144          ["Mark sparse" gnus-uu-mark-sparse t]
2145          ["Mark thread" gnus-uu-mark-thread t]
2146          ["Unmark thread" gnus-uu-unmark-thread t]
2147          ("Process Mark Sets"
2148           ["Kill" gnus-summary-kill-process-mark t]
2149           ["Yank" gnus-summary-yank-process-mark
2150            gnus-newsgroup-process-stack]
2151           ["Save" gnus-summary-save-process-mark t]))
2152         ("Scroll article"
2153          ["Page forward" gnus-summary-next-page
2154           ,@(if (featurep 'xemacs) '(t)
2155               '(:help "Show next page of article"))]
2156          ["Page backward" gnus-summary-prev-page
2157           ,@(if (featurep 'xemacs) '(t)
2158               '(:help "Show previous page of article"))]
2159          ["Line forward" gnus-summary-scroll-up t])
2160         ("Move"
2161          ["Next unread article" gnus-summary-next-unread-article t]
2162          ["Previous unread article" gnus-summary-prev-unread-article t]
2163          ["Next article" gnus-summary-next-article t]
2164          ["Previous article" gnus-summary-prev-article t]
2165          ["Next unread subject" gnus-summary-next-unread-subject t]
2166          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2167          ["Next article same subject" gnus-summary-next-same-subject t]
2168          ["Previous article same subject" gnus-summary-prev-same-subject t]
2169          ["First unread article" gnus-summary-first-unread-article t]
2170          ["Best unread article" gnus-summary-best-unread-article t]
2171          ["Go to subject number..." gnus-summary-goto-subject t]
2172          ["Go to article number..." gnus-summary-goto-article t]
2173          ["Go to the last article" gnus-summary-goto-last-article t]
2174          ["Pop article off history" gnus-summary-pop-article t])
2175         ("Sort"
2176          ["Sort by number" gnus-summary-sort-by-number t]
2177          ["Sort by author" gnus-summary-sort-by-author t]
2178          ["Sort by subject" gnus-summary-sort-by-subject t]
2179          ["Sort by date" gnus-summary-sort-by-date t]
2180          ["Sort by score" gnus-summary-sort-by-score t]
2181          ["Sort by lines" gnus-summary-sort-by-lines t]
2182          ["Sort by characters" gnus-summary-sort-by-chars t]
2183          ["Original sort" gnus-summary-sort-by-original t])
2184         ("Help"
2185          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2186          ["Describe group" gnus-summary-describe-group t]
2187          ["Read manual" gnus-info-find-node t])
2188         ("Modes"
2189          ["Pick and read" gnus-pick-mode t]
2190          ["Binary" gnus-binary-mode t])
2191         ("Regeneration"
2192          ["Regenerate" gnus-summary-prepare t]
2193          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2194          ["Toggle threading" gnus-summary-toggle-threads t])
2195         ["See old articles" gnus-summary-insert-old-articles t]
2196         ["See new articles" gnus-summary-insert-new-articles t]
2197         ["Filter articles..." gnus-summary-execute-command t]
2198         ["Run command on subjects..." gnus-summary-universal-argument t]
2199         ["Search articles forward..." gnus-summary-search-article-forward t]
2200         ["Search articles backward..." gnus-summary-search-article-backward t]
2201         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2202         ["Expand window" gnus-summary-expand-window t]
2203         ["Expire expirable articles" gnus-summary-expire-articles
2204          (gnus-check-backend-function
2205           'request-expire-articles gnus-newsgroup-name)]
2206         ["Edit local kill file" gnus-summary-edit-local-kill t]
2207         ["Edit main kill file" gnus-summary-edit-global-kill t]
2208         ["Edit group parameters" gnus-summary-edit-parameters t]
2209         ["Customize group parameters" gnus-summary-customize-parameters t]
2210         ["Send a bug report" gnus-bug t]
2211         ("Exit"
2212          ["Catchup and exit" gnus-summary-catchup-and-exit
2213           ,@(if (featurep 'xemacs) '(t)
2214               '(:help "Mark unread articles in this group as read, then exit"))]
2215          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2216          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2217          ["Exit group" gnus-summary-exit
2218           ,@(if (featurep 'xemacs) '(t)
2219               '(:help "Exit current group, return to group selection mode"))]
2220          ["Exit group without updating" gnus-summary-exit-no-update t]
2221          ["Exit and goto next group" gnus-summary-next-group t]
2222          ["Exit and goto prev group" gnus-summary-prev-group t]
2223          ["Reselect group" gnus-summary-reselect-current-group t]
2224          ["Rescan group" gnus-summary-rescan-group t]
2225          ["Update dribble" gnus-summary-save-newsrc t])))
2226
2227     (gnus-run-hooks 'gnus-summary-menu-hook)))
2228
2229 (defvar gnus-summary-tool-bar-map nil)
2230
2231 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2232 (defun gnus-summary-make-tool-bar ()
2233   (if (and (fboundp 'tool-bar-add-item-from-menu)
2234            (default-value 'tool-bar-mode)
2235            (not gnus-summary-tool-bar-map))
2236       (setq gnus-summary-tool-bar-map
2237             (let ((tool-bar-map (make-sparse-keymap))
2238                   (load-path (mm-image-load-path)))
2239               (tool-bar-add-item-from-menu
2240                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2241               (tool-bar-add-item-from-menu
2242                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2243               (tool-bar-add-item-from-menu
2244                'gnus-summary-post-news "post" gnus-summary-mode-map)
2245               (tool-bar-add-item-from-menu
2246                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2247               (tool-bar-add-item-from-menu
2248                'gnus-summary-followup "followup" gnus-summary-mode-map)
2249               (tool-bar-add-item-from-menu
2250                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2251               (tool-bar-add-item-from-menu
2252                'gnus-summary-reply "reply" gnus-summary-mode-map)
2253               (tool-bar-add-item-from-menu
2254                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2255               (tool-bar-add-item-from-menu
2256                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2257               (tool-bar-add-item-from-menu
2258                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2259               (tool-bar-add-item-from-menu
2260                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2261               (tool-bar-add-item-from-menu
2262                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2263               (tool-bar-add-item-from-menu
2264                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2265               (tool-bar-add-item-from-menu
2266                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2267               (tool-bar-add-item-from-menu
2268                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2269               tool-bar-map)))
2270   (if gnus-summary-tool-bar-map
2271       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2272
2273 (defun gnus-score-set-default (var value)
2274   "A version of set that updates the GNU Emacs menu-bar."
2275   (set var value)
2276   ;; It is the message that forces the active status to be updated.
2277   (message ""))
2278
2279 (defun gnus-make-score-map (type)
2280   "Make a summary score map of type TYPE."
2281   (if t
2282       nil
2283     (let ((headers '(("author" "from" string)
2284                      ("subject" "subject" string)
2285                      ("article body" "body" string)
2286                      ("article head" "head" string)
2287                      ("xref" "xref" string)
2288                      ("extra header" "extra" string)
2289                      ("lines" "lines" number)
2290                      ("followups to author" "followup" string)))
2291           (types '((number ("less than" <)
2292                            ("greater than" >)
2293                            ("equal" =))
2294                    (string ("substring" s)
2295                            ("exact string" e)
2296                            ("fuzzy string" f)
2297                            ("regexp" r))))
2298           (perms '(("temporary" (current-time-string))
2299                    ("permanent" nil)
2300                    ("immediate" now)))
2301           header)
2302       (list
2303        (apply
2304         'nconc
2305         (list
2306          (if (eq type 'lower)
2307              "Lower score"
2308            "Increase score"))
2309         (let (outh)
2310           (while headers
2311             (setq header (car headers))
2312             (setq outh
2313                   (cons
2314                    (apply
2315                     'nconc
2316                     (list (car header))
2317                     (let ((ts (cdr (assoc (nth 2 header) types)))
2318                           outt)
2319                       (while ts
2320                         (setq outt
2321                               (cons
2322                                (apply
2323                                 'nconc
2324                                 (list (caar ts))
2325                                 (let ((ps perms)
2326                                       outp)
2327                                   (while ps
2328                                     (setq outp
2329                                           (cons
2330                                            (vector
2331                                             (caar ps)
2332                                             (list
2333                                              'gnus-summary-score-entry
2334                                              (nth 1 header)
2335                                              (if (or (string= (nth 1 header)
2336                                                               "head")
2337                                                      (string= (nth 1 header)
2338                                                               "body"))
2339                                                  ""
2340                                                (list 'gnus-summary-header
2341                                                      (nth 1 header)))
2342                                              (list 'quote (nth 1 (car ts)))
2343                                              (list 'gnus-score-delta-default
2344                                                    nil)
2345                                              (nth 1 (car ps))
2346                                              t)
2347                                             t)
2348                                            outp))
2349                                     (setq ps (cdr ps)))
2350                                   (list (nreverse outp))))
2351                                outt))
2352                         (setq ts (cdr ts)))
2353                       (list (nreverse outt))))
2354                    outh))
2355             (setq headers (cdr headers)))
2356           (list (nreverse outh))))))))
2357
2358 \f
2359
2360 (defun gnus-summary-mode (&optional group)
2361   "Major mode for reading articles.
2362
2363 All normal editing commands are switched off.
2364 \\<gnus-summary-mode-map>
2365 Each line in this buffer represents one article.  To read an
2366 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2367 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2368 respectively.
2369
2370 You can also post articles and send mail from this buffer.  To
2371 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2372 of an article, type `\\[gnus-summary-reply]'.
2373
2374 There are approx. one gazillion commands you can execute in this
2375 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2376
2377 The following commands are available:
2378
2379 \\{gnus-summary-mode-map}"
2380   (interactive)
2381   (kill-all-local-variables)
2382   (when (gnus-visual-p 'summary-menu 'menu)
2383     (gnus-summary-make-menu-bar)
2384     (gnus-summary-make-tool-bar))
2385   (gnus-summary-make-local-variables)
2386   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2387     (gnus-summary-make-local-variables))
2388   (gnus-make-thread-indent-array)
2389   (gnus-simplify-mode-line)
2390   (setq major-mode 'gnus-summary-mode)
2391   (setq mode-name "Summary")
2392   (make-local-variable 'minor-mode-alist)
2393   (use-local-map gnus-summary-mode-map)
2394   (buffer-disable-undo)
2395   (setq buffer-read-only t)             ;Disable modification
2396   (setq truncate-lines t)
2397   (setq selective-display t)
2398   (setq selective-display-ellipses t)   ;Display `...'
2399   (gnus-summary-set-display-table)
2400   (gnus-set-default-directory)
2401   (setq gnus-newsgroup-name group)
2402   (make-local-variable 'gnus-summary-line-format)
2403   (make-local-variable 'gnus-summary-line-format-spec)
2404   (make-local-variable 'gnus-summary-dummy-line-format)
2405   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2406   (make-local-variable 'gnus-summary-mark-positions)
2407   (make-local-hook 'pre-command-hook)
2408   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2409   (gnus-run-hooks 'gnus-summary-mode-hook)
2410   (turn-on-gnus-mailing-list-mode)
2411   (mm-enable-multibyte-mule4)
2412   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2413   (gnus-update-summary-mark-positions))
2414
2415 (defun gnus-summary-make-local-variables ()
2416   "Make all the local summary buffer variables."
2417   (let (global)
2418     (dolist (local gnus-summary-local-variables)
2419       (if (consp local)
2420           (progn
2421             (if (eq (cdr local) 'global)
2422                 ;; Copy the global value of the variable.
2423                 (setq global (symbol-value (car local)))
2424               ;; Use the value from the list.
2425               (setq global (eval (cdr local))))
2426             (set (make-local-variable (car local)) global))
2427         ;; Simple nil-valued local variable.
2428         (set (make-local-variable local) nil)))))
2429
2430 (defun gnus-summary-clear-local-variables ()
2431   (let ((locals gnus-summary-local-variables))
2432     (while locals
2433       (if (consp (car locals))
2434           (and (vectorp (caar locals))
2435                (set (caar locals) nil))
2436         (and (vectorp (car locals))
2437              (set (car locals) nil)))
2438       (setq locals (cdr locals)))))
2439
2440 ;; Summary data functions.
2441
2442 (defmacro gnus-data-number (data)
2443   `(car ,data))
2444
2445 (defmacro gnus-data-set-number (data number)
2446   `(setcar ,data ,number))
2447
2448 (defmacro gnus-data-mark (data)
2449   `(nth 1 ,data))
2450
2451 (defmacro gnus-data-set-mark (data mark)
2452   `(setcar (nthcdr 1 ,data) ,mark))
2453
2454 (defmacro gnus-data-pos (data)
2455   `(nth 2 ,data))
2456
2457 (defmacro gnus-data-set-pos (data pos)
2458   `(setcar (nthcdr 2 ,data) ,pos))
2459
2460 (defmacro gnus-data-header (data)
2461   `(nth 3 ,data))
2462
2463 (defmacro gnus-data-set-header (data header)
2464   `(setf (nth 3 ,data) ,header))
2465
2466 (defmacro gnus-data-level (data)
2467   `(nth 4 ,data))
2468
2469 (defmacro gnus-data-unread-p (data)
2470   `(= (nth 1 ,data) gnus-unread-mark))
2471
2472 (defmacro gnus-data-read-p (data)
2473   `(/= (nth 1 ,data) gnus-unread-mark))
2474
2475 (defmacro gnus-data-pseudo-p (data)
2476   `(consp (nth 3 ,data)))
2477
2478 (defmacro gnus-data-find (number)
2479   `(assq ,number gnus-newsgroup-data))
2480
2481 (defmacro gnus-data-find-list (number &optional data)
2482   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2483      (memq (assq ,number bdata)
2484            bdata)))
2485
2486 (defmacro gnus-data-make (number mark pos header level)
2487   `(list ,number ,mark ,pos ,header ,level))
2488
2489 (defun gnus-data-enter (after-article number mark pos header level offset)
2490   (let ((data (gnus-data-find-list after-article)))
2491     (unless data
2492       (error "No such article: %d" after-article))
2493     (setcdr data (cons (gnus-data-make number mark pos header level)
2494                        (cdr data)))
2495     (setq gnus-newsgroup-data-reverse nil)
2496     (gnus-data-update-list (cddr data) offset)))
2497
2498 (defun gnus-data-enter-list (after-article list &optional offset)
2499   (when list
2500     (let ((data (and after-article (gnus-data-find-list after-article)))
2501           (ilist list))
2502       (if (not (or data
2503                    after-article))
2504           (let ((odata gnus-newsgroup-data))
2505             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2506             (when offset
2507               (gnus-data-update-list odata offset)))
2508       ;; Find the last element in the list to be spliced into the main
2509         ;; list.
2510         (while (cdr list)
2511           (setq list (cdr list)))
2512         (if (not data)
2513             (progn
2514               (setcdr list gnus-newsgroup-data)
2515               (setq gnus-newsgroup-data ilist)
2516               (when offset
2517                 (gnus-data-update-list (cdr list) offset)))
2518           (setcdr list (cdr data))
2519           (setcdr data ilist)
2520           (when offset
2521             (gnus-data-update-list (cdr list) offset))))
2522       (setq gnus-newsgroup-data-reverse nil))))
2523
2524 (defun gnus-data-remove (article &optional offset)
2525   (let ((data gnus-newsgroup-data))
2526     (if (= (gnus-data-number (car data)) article)
2527         (progn
2528           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2529                 gnus-newsgroup-data-reverse nil)
2530           (when offset
2531             (gnus-data-update-list gnus-newsgroup-data offset)))
2532       (while (cdr data)
2533         (when (= (gnus-data-number (cadr data)) article)
2534           (setcdr data (cddr data))
2535           (when offset
2536             (gnus-data-update-list (cdr data) offset))
2537           (setq data nil
2538                 gnus-newsgroup-data-reverse nil))
2539         (setq data (cdr data))))))
2540
2541 (defmacro gnus-data-list (backward)
2542   `(if ,backward
2543        (or gnus-newsgroup-data-reverse
2544            (setq gnus-newsgroup-data-reverse
2545                  (reverse gnus-newsgroup-data)))
2546      gnus-newsgroup-data))
2547
2548 (defun gnus-data-update-list (data offset)
2549   "Add OFFSET to the POS of all data entries in DATA."
2550   (setq gnus-newsgroup-data-reverse nil)
2551   (while data
2552     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2553     (setq data (cdr data))))
2554
2555 (defun gnus-summary-article-pseudo-p (article)
2556   "Say whether this article is a pseudo article or not."
2557   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2558
2559 (defmacro gnus-summary-article-sparse-p (article)
2560   "Say whether this article is a sparse article or not."
2561   `(memq ,article gnus-newsgroup-sparse))
2562
2563 (defmacro gnus-summary-article-ancient-p (article)
2564   "Say whether this article is a sparse article or not."
2565   `(memq ,article gnus-newsgroup-ancient))
2566
2567 (defun gnus-article-parent-p (number)
2568   "Say whether this article is a parent or not."
2569   (let ((data (gnus-data-find-list number)))
2570     (and (cdr data)              ; There has to be an article after...
2571          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2572             (gnus-data-level (nth 1 data))))))
2573
2574 (defun gnus-article-children (number)
2575   "Return a list of all children to NUMBER."
2576   (let* ((data (gnus-data-find-list number))
2577          (level (gnus-data-level (car data)))
2578          children)
2579     (setq data (cdr data))
2580     (while (and data
2581                 (= (gnus-data-level (car data)) (1+ level)))
2582       (push (gnus-data-number (car data)) children)
2583       (setq data (cdr data)))
2584     children))
2585
2586 (defmacro gnus-summary-skip-intangible ()
2587   "If the current article is intangible, then jump to a different article."
2588   '(let ((to (get-text-property (point) 'gnus-intangible)))
2589      (and to (gnus-summary-goto-subject to))))
2590
2591 (defmacro gnus-summary-article-intangible-p ()
2592   "Say whether this article is intangible or not."
2593   '(get-text-property (point) 'gnus-intangible))
2594
2595 (defun gnus-article-read-p (article)
2596   "Say whether ARTICLE is read or not."
2597   (not (or (memq article gnus-newsgroup-marked)
2598            (memq article gnus-newsgroup-unreads)
2599            (memq article gnus-newsgroup-unselected)
2600            (memq article gnus-newsgroup-dormant))))
2601
2602 ;; Some summary mode macros.
2603
2604 (defmacro gnus-summary-article-number ()
2605   "The article number of the article on the current line.
2606 If there isn's an article number here, then we return the current
2607 article number."
2608   '(progn
2609      (gnus-summary-skip-intangible)
2610      (or (get-text-property (point) 'gnus-number)
2611          (gnus-summary-last-subject))))
2612
2613 (defmacro gnus-summary-article-header (&optional number)
2614   "Return the header of article NUMBER."
2615   `(gnus-data-header (gnus-data-find
2616                       ,(or number '(gnus-summary-article-number)))))
2617
2618 (defmacro gnus-summary-thread-level (&optional number)
2619   "Return the level of thread that starts with article NUMBER."
2620   `(if (and (eq gnus-summary-make-false-root 'dummy)
2621             (get-text-property (point) 'gnus-intangible))
2622        0
2623      (gnus-data-level (gnus-data-find
2624                        ,(or number '(gnus-summary-article-number))))))
2625
2626 (defmacro gnus-summary-article-mark (&optional number)
2627   "Return the mark of article NUMBER."
2628   `(gnus-data-mark (gnus-data-find
2629                     ,(or number '(gnus-summary-article-number)))))
2630
2631 (defmacro gnus-summary-article-pos (&optional number)
2632   "Return the position of the line of article NUMBER."
2633   `(gnus-data-pos (gnus-data-find
2634                    ,(or number '(gnus-summary-article-number)))))
2635
2636 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2637 (defmacro gnus-summary-article-subject (&optional number)
2638   "Return current subject string or nil if nothing."
2639   `(let ((headers
2640           ,(if number
2641                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2642              '(gnus-data-header (assq (gnus-summary-article-number)
2643                                       gnus-newsgroup-data)))))
2644      (and headers
2645           (vectorp headers)
2646           (mail-header-subject headers))))
2647
2648 (defmacro gnus-summary-article-score (&optional number)
2649   "Return current article score."
2650   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2651                   gnus-newsgroup-scored))
2652        gnus-summary-default-score 0))
2653
2654 (defun gnus-summary-article-children (&optional number)
2655   "Return a list of article numbers that are children of article NUMBER."
2656   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2657          (level (gnus-data-level (car data)))
2658          l children)
2659     (while (and (setq data (cdr data))
2660                 (> (setq l (gnus-data-level (car data))) level))
2661       (and (= (1+ level) l)
2662            (push (gnus-data-number (car data))
2663                  children)))
2664     (nreverse children)))
2665
2666 (defun gnus-summary-article-parent (&optional number)
2667   "Return the article number of the parent of article NUMBER."
2668   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2669                                     (gnus-data-list t)))
2670          (level (gnus-data-level (car data))))
2671     (if (zerop level)
2672         ()                              ; This is a root.
2673       ;; We search until we find an article with a level less than
2674       ;; this one.  That function has to be the parent.
2675       (while (and (setq data (cdr data))
2676                   (not (< (gnus-data-level (car data)) level))))
2677       (and data (gnus-data-number (car data))))))
2678
2679 (defun gnus-unread-mark-p (mark)
2680   "Say whether MARK is the unread mark."
2681   (= mark gnus-unread-mark))
2682
2683 (defun gnus-read-mark-p (mark)
2684   "Say whether MARK is one of the marks that mark as read.
2685 This is all marks except unread, ticked, dormant, and expirable."
2686   (not (or (= mark gnus-unread-mark)
2687            (= mark gnus-ticked-mark)
2688            (= mark gnus-dormant-mark)
2689            (= mark gnus-expirable-mark))))
2690
2691 (defmacro gnus-article-mark (number)
2692   "Return the MARK of article NUMBER.
2693 This macro should only be used when computing the mark the \"first\"
2694 time; i.e., when generating the summary lines.  After that,
2695 `gnus-summary-article-mark' should be used to examine the
2696 marks of articles."
2697   `(cond
2698     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2699     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2700     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2701     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2702     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2703     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2704     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2705     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2706            gnus-ancient-mark))))
2707
2708 ;; Saving hidden threads.
2709
2710 (defmacro gnus-save-hidden-threads (&rest forms)
2711   "Save hidden threads, eval FORMS, and restore the hidden threads."
2712   (let ((config (make-symbol "config")))
2713     `(let ((,config (gnus-hidden-threads-configuration)))
2714        (unwind-protect
2715            (save-excursion
2716              ,@forms)
2717          (gnus-restore-hidden-threads-configuration ,config)))))
2718 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2719 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2720
2721 (defun gnus-data-compute-positions ()
2722   "Compute the positions of all articles."
2723   (setq gnus-newsgroup-data-reverse nil)
2724   (let ((data gnus-newsgroup-data))
2725     (save-excursion
2726       (gnus-save-hidden-threads
2727         (gnus-summary-show-all-threads)
2728         (goto-char (point-min))
2729         (while data
2730           (while (get-text-property (point) 'gnus-intangible)
2731             (forward-line 1))
2732           (gnus-data-set-pos (car data) (+ (point) 3))
2733           (setq data (cdr data))
2734           (forward-line 1))))))
2735
2736 (defun gnus-hidden-threads-configuration ()
2737   "Return the current hidden threads configuration."
2738   (save-excursion
2739     (let (config)
2740       (goto-char (point-min))
2741       (while (search-forward "\r" nil t)
2742         (push (1- (point)) config))
2743       config)))
2744
2745 (defun gnus-restore-hidden-threads-configuration (config)
2746   "Restore hidden threads configuration from CONFIG."
2747   (save-excursion
2748     (let (point buffer-read-only)
2749       (while (setq point (pop config))
2750         (when (and (< point (point-max))
2751                    (goto-char point)
2752                    (eq (char-after) ?\n))
2753           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2754
2755 ;; Various summary mode internalish functions.
2756
2757 (defun gnus-mouse-pick-article (e)
2758   (interactive "e")
2759   (mouse-set-point e)
2760   (gnus-summary-next-page nil t))
2761
2762 (defun gnus-summary-set-display-table ()
2763   "Change the display table.
2764 Odd characters have a tendency to mess
2765 up nicely formatted displays - we make all possible glyphs
2766 display only a single character."
2767
2768   ;; We start from the standard display table, if any.
2769   (let ((table (or (copy-sequence standard-display-table)
2770                    (make-display-table)))
2771         (i 32))
2772     ;; Nix out all the control chars...
2773     (while (>= (setq i (1- i)) 0)
2774       (aset table i [??]))
2775    ;; ... but not newline and cr, of course.  (cr is necessary for the
2776     ;; selective display).
2777     (aset table ?\n nil)
2778     (aset table ?\r nil)
2779     ;; We keep TAB as well.
2780     (aset table ?\t nil)
2781     ;; We nix out any glyphs over 126 that are not set already.
2782     (let ((i 256))
2783       (while (>= (setq i (1- i)) 127)
2784         ;; Only modify if the entry is nil.
2785         (unless (aref table i)
2786           (aset table i [??]))))
2787     (setq buffer-display-table table)))
2788
2789 (defun gnus-summary-set-article-display-arrow (pos)
2790   "Update the overlay arrow to point to line at position POS."
2791   (when (and gnus-summary-display-arrow
2792              (boundp 'overlay-arrow-position)
2793              (boundp 'overlay-arrow-string))
2794     (save-excursion
2795       (goto-char pos)
2796       (beginning-of-line)
2797       (unless overlay-arrow-position
2798         (setq overlay-arrow-position (make-marker)))
2799       (setq overlay-arrow-string "=>"
2800             overlay-arrow-position (set-marker overlay-arrow-position
2801                                                (point)
2802                                                (current-buffer))))))
2803
2804 (defun gnus-summary-buffer-name (group)
2805   "Return the summary buffer name of GROUP."
2806   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2807
2808 (defun gnus-summary-setup-buffer (group)
2809   "Initialize summary buffer."
2810   (let ((buffer (gnus-summary-buffer-name group)))
2811     (if (get-buffer buffer)
2812         (progn
2813           (set-buffer buffer)
2814           (setq gnus-summary-buffer (current-buffer))
2815           (not gnus-newsgroup-prepared))
2816       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2817       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2818       (gnus-summary-mode group)
2819       (when gnus-carpal
2820         (gnus-carpal-setup-buffer 'summary))
2821       (unless gnus-single-article-buffer
2822         (make-local-variable 'gnus-article-buffer)
2823         (make-local-variable 'gnus-article-current)
2824         (make-local-variable 'gnus-original-article-buffer))
2825       (setq gnus-newsgroup-name group)
2826       ;; Set any local variables in the group parameters.
2827       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2828       t)))
2829
2830 (defun gnus-set-global-variables ()
2831   "Set the global equivalents of the buffer-local variables.
2832 They are set to the latest values they had.  These reflect the summary
2833 buffer that was in action when the last article was fetched."
2834   (when (eq major-mode 'gnus-summary-mode)
2835     (setq gnus-summary-buffer (current-buffer))
2836     (let ((name gnus-newsgroup-name)
2837           (marked gnus-newsgroup-marked)
2838           (unread gnus-newsgroup-unreads)
2839           (headers gnus-current-headers)
2840           (data gnus-newsgroup-data)
2841           (summary gnus-summary-buffer)
2842           (article-buffer gnus-article-buffer)
2843           (original gnus-original-article-buffer)
2844           (gac gnus-article-current)
2845           (reffed gnus-reffed-article-number)
2846           (score-file gnus-current-score-file)
2847           (default-charset gnus-newsgroup-charset)
2848           vlist)
2849       (let ((locals gnus-newsgroup-variables))
2850         (while locals
2851           (if (consp (car locals))
2852               (push (eval (caar locals)) vlist)
2853             (push (eval (car locals)) vlist))
2854           (setq locals (cdr locals)))
2855         (setq vlist (nreverse vlist)))
2856       (save-excursion
2857         (set-buffer gnus-group-buffer)
2858         (setq gnus-newsgroup-name name
2859               gnus-newsgroup-marked marked
2860               gnus-newsgroup-unreads unread
2861               gnus-current-headers headers
2862               gnus-newsgroup-data data
2863               gnus-article-current gac
2864               gnus-summary-buffer summary
2865               gnus-article-buffer article-buffer
2866               gnus-original-article-buffer original
2867               gnus-reffed-article-number reffed
2868               gnus-current-score-file score-file
2869               gnus-newsgroup-charset default-charset)
2870         (let ((locals gnus-newsgroup-variables))
2871           (while locals
2872             (if (consp (car locals))
2873                 (set (caar locals) (pop vlist))
2874               (set (car locals) (pop vlist)))
2875             (setq locals (cdr locals))))
2876         ;; The article buffer also has local variables.
2877         (when (gnus-buffer-live-p gnus-article-buffer)
2878           (set-buffer gnus-article-buffer)
2879           (setq gnus-summary-buffer summary))))))
2880
2881 (defun gnus-summary-article-unread-p (article)
2882   "Say whether ARTICLE is unread or not."
2883   (memq article gnus-newsgroup-unreads))
2884
2885 (defun gnus-summary-first-article-p (&optional article)
2886   "Return whether ARTICLE is the first article in the buffer."
2887   (if (not (setq article (or article (gnus-summary-article-number))))
2888       nil
2889     (eq article (caar gnus-newsgroup-data))))
2890
2891 (defun gnus-summary-last-article-p (&optional article)
2892   "Return whether ARTICLE is the last article in the buffer."
2893   (if (not (setq article (or article (gnus-summary-article-number))))
2894       ;; All non-existent numbers are the last article.  :-)
2895       t
2896     (not (cdr (gnus-data-find-list article)))))
2897
2898 (defun gnus-make-thread-indent-array ()
2899   (let ((n 200))
2900     (unless (and gnus-thread-indent-array
2901                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2902       (setq gnus-thread-indent-array (make-vector 201 "")
2903             gnus-thread-indent-array-level gnus-thread-indent-level)
2904       (while (>= n 0)
2905         (aset gnus-thread-indent-array n
2906               (make-string (* n gnus-thread-indent-level) ? ))
2907         (setq n (1- n))))))
2908
2909 (defun gnus-update-summary-mark-positions ()
2910   "Compute where the summary marks are to go."
2911   (save-excursion
2912     (when (gnus-buffer-exists-p gnus-summary-buffer)
2913       (set-buffer gnus-summary-buffer))
2914     (let ((gnus-replied-mark 129)
2915           (gnus-score-below-mark 130)
2916           (gnus-score-over-mark 130)
2917           (gnus-download-mark 131)
2918           (spec gnus-summary-line-format-spec)
2919           gnus-visual pos)
2920       (save-excursion
2921         (gnus-set-work-buffer)
2922         (let ((gnus-summary-line-format-spec spec)
2923               (gnus-newsgroup-downloadable '((0 . t))))
2924           (gnus-summary-insert-line
2925            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2926            0 nil 128 t nil "" nil 1)
2927           (goto-char (point-min))
2928           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2929                                              (- (point) 2)))))
2930           (goto-char (point-min))
2931           (push (cons 'replied (and (search-forward "\201" nil t)
2932                                     (- (point) 2)))
2933                 pos)
2934           (goto-char (point-min))
2935           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2936                 pos)
2937           (goto-char (point-min))
2938           (push (cons 'download
2939                       (and (search-forward "\203" nil t) (- (point) 2)))
2940                 pos)))
2941       (setq gnus-summary-mark-positions pos))))
2942
2943 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2944   "Insert a dummy root in the summary buffer."
2945   (beginning-of-line)
2946   (gnus-add-text-properties
2947    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2948    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2949
2950 (defun gnus-summary-extract-address-component (from)
2951   (or (car (funcall gnus-extract-address-components from))
2952       from))
2953
2954 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2955   (let ((mail-parse-charset gnus-newsgroup-charset)
2956         ; Is it really necessary to do this next part for each summary line?
2957         ; Luckily, doesn't seem to slow things down much.
2958         (mail-parse-ignored-charsets
2959          (save-excursion (set-buffer gnus-summary-buffer)
2960                          gnus-newsgroup-ignored-charsets)))
2961     (or
2962      (and gnus-ignored-from-addresses
2963           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2964           (let ((extra-headers (mail-header-extra header))
2965                 to
2966                 newsgroups)
2967             (cond
2968              ((setq to (cdr (assq 'To extra-headers)))
2969               (concat "-> "
2970                       (gnus-summary-extract-address-component
2971                        (funcall gnus-decode-encoded-word-function to))))
2972              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2973               (concat "=> " newsgroups)))))
2974      (gnus-summary-extract-address-component gnus-tmp-from))))
2975
2976 (defun gnus-summary-insert-line (gnus-tmp-header
2977                                  gnus-tmp-level gnus-tmp-current
2978                                  gnus-tmp-unread gnus-tmp-replied
2979                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2980                                  &optional gnus-tmp-dummy gnus-tmp-score
2981                                  gnus-tmp-process)
2982   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2983          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2984          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2985          (gnus-tmp-score-char
2986           (if (or (null gnus-summary-default-score)
2987                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2988                       gnus-summary-zcore-fuzz))
2989               ?                         ;Whitespace
2990             (if (< gnus-tmp-score gnus-summary-default-score)
2991                 gnus-score-below-mark gnus-score-over-mark)))
2992          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2993          (gnus-tmp-replied
2994           (cond (gnus-tmp-process gnus-process-mark)
2995                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2996                  gnus-cached-mark)
2997                 (gnus-tmp-replied gnus-replied-mark)
2998                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
2999                  gnus-forwarded-mark)
3000                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3001                  gnus-saved-mark)
3002                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3003                  gnus-recent-mark)
3004                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3005                  gnus-unseen-mark)
3006                 (t gnus-no-mark)))
3007          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3008          (gnus-tmp-name
3009           (cond
3010            ((string-match "<[^>]+> *$" gnus-tmp-from)
3011             (let ((beg (match-beginning 0)))
3012               (or (and (string-match "^\".+\"" gnus-tmp-from)
3013                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3014                   (substring gnus-tmp-from 0 beg))))
3015            ((string-match "(.+)" gnus-tmp-from)
3016             (substring gnus-tmp-from
3017                        (1+ (match-beginning 0)) (1- (match-end 0))))
3018            (t gnus-tmp-from)))
3019          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3020          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3021          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3022          (buffer-read-only nil))
3023     (when (string= gnus-tmp-name "")
3024       (setq gnus-tmp-name gnus-tmp-from))
3025     (unless (numberp gnus-tmp-lines)
3026       (setq gnus-tmp-lines -1))
3027     (if (= gnus-tmp-lines -1)
3028         (setq gnus-tmp-lines "?")
3029       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3030     (gnus-put-text-property
3031      (point)
3032      (progn (eval gnus-summary-line-format-spec) (point))
3033      'gnus-number gnus-tmp-number)
3034     (when (gnus-visual-p 'summary-highlight 'highlight)
3035       (forward-line -1)
3036       (gnus-run-hooks 'gnus-summary-update-hook)
3037       (forward-line 1))))
3038
3039 (defun gnus-summary-update-line (&optional dont-update)
3040   "Update summary line after change."
3041   (when (and gnus-summary-default-score
3042              (not gnus-summary-inhibit-highlight))
3043     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3044            (article (gnus-summary-article-number))
3045            (score (gnus-summary-article-score article)))
3046       (unless dont-update
3047         (if (and gnus-summary-mark-below
3048                  (< (gnus-summary-article-score)
3049                     gnus-summary-mark-below))
3050             ;; This article has a low score, so we mark it as read.
3051             (when (memq article gnus-newsgroup-unreads)
3052               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3053           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3054             ;; This article was previously marked as read on account
3055             ;; of a low score, but now it has risen, so we mark it as
3056             ;; unread.
3057             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3058         (gnus-summary-update-mark
3059          (if (or (null gnus-summary-default-score)
3060                  (<= (abs (- score gnus-summary-default-score))
3061                      gnus-summary-zcore-fuzz))
3062              ?                          ;Whitespace
3063            (if (< score gnus-summary-default-score)
3064                gnus-score-below-mark gnus-score-over-mark))
3065          'score))
3066       ;; Do visual highlighting.
3067       (when (gnus-visual-p 'summary-highlight 'highlight)
3068         (gnus-run-hooks 'gnus-summary-update-hook)))))
3069
3070 (defvar gnus-tmp-new-adopts nil)
3071
3072 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3073   "Return the number of articles in THREAD.
3074 This may be 0 in some cases -- if none of the articles in
3075 the thread are to be displayed."
3076   (let* ((number
3077          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3078           (cond
3079            ((not (listp thread))
3080             1)
3081            ((and (consp thread) (cdr thread))
3082             (apply
3083              '+ 1 (mapcar
3084                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3085            ((null thread)
3086             1)
3087            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3088             1)
3089            (t 0))))
3090     (when (and level (zerop level) gnus-tmp-new-adopts)
3091       (incf number
3092             (apply '+ (mapcar
3093                        'gnus-summary-number-of-articles-in-thread
3094                        gnus-tmp-new-adopts))))
3095     (if char
3096         (if (> number 1) gnus-not-empty-thread-mark
3097           gnus-empty-thread-mark)
3098       number)))
3099
3100 (defun gnus-summary-set-local-parameters (group)
3101   "Go through the local params of GROUP and set all variable specs in that list."
3102   (let ((params (gnus-group-find-parameter group))
3103         (vars '(quit-config))           ; Ignore quit-config.
3104         elem)
3105     (while params
3106       (setq elem (car params)
3107             params (cdr params))
3108       (and (consp elem)                 ; Has to be a cons.
3109            (consp (cdr elem))           ; The cdr has to be a list.
3110            (symbolp (car elem))         ; Has to be a symbol in there.
3111            (not (memq (car elem) vars))
3112            (ignore-errors               ; So we set it.
3113              (push (car elem) vars)
3114              (make-local-variable (car elem))
3115              (set (car elem) (eval (nth 1 elem))))))))
3116
3117 (defun gnus-summary-read-group (group &optional show-all no-article
3118                                       kill-buffer no-display backward
3119                                       select-articles)
3120   "Start reading news in newsgroup GROUP.
3121 If SHOW-ALL is non-nil, already read articles are also listed.
3122 If NO-ARTICLE is non-nil, no article is selected initially.
3123 If NO-DISPLAY, don't generate a summary buffer."
3124   (let (result)
3125     (while (and group
3126                 (null (setq result
3127                             (let ((gnus-auto-select-next nil))
3128                               (or (gnus-summary-read-group-1
3129                                    group show-all no-article
3130                                    kill-buffer no-display
3131                                    select-articles)
3132                                   (setq show-all nil
3133                                         select-articles nil)))))
3134                 (eq gnus-auto-select-next 'quietly))
3135       (set-buffer gnus-group-buffer)
3136       ;; The entry function called above goes to the next
3137       ;; group automatically, so we go two groups back
3138       ;; if we are searching for the previous group.
3139       (when backward
3140         (gnus-group-prev-unread-group 2))
3141       (if (not (equal group (gnus-group-group-name)))
3142           (setq group (gnus-group-group-name))
3143         (setq group nil)))
3144     result))
3145
3146 (defun gnus-summary-read-group-1 (group show-all no-article
3147                                         kill-buffer no-display
3148                                         &optional select-articles)
3149   ;; Killed foreign groups can't be entered.
3150   ;;  (when (and (not (gnus-group-native-p group))
3151   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3152   ;;    (error "Dead non-native groups can't be entered"))
3153   (gnus-message 5 "Retrieving newsgroup: %s..."
3154                 (gnus-group-decoded-name group))
3155   (let* ((new-group (gnus-summary-setup-buffer group))
3156          (quit-config (gnus-group-quit-config group))
3157          (did-select (and new-group (gnus-select-newsgroup
3158                                      group show-all select-articles))))
3159     (cond
3160      ;; This summary buffer exists already, so we just select it.
3161      ((not new-group)
3162       (gnus-set-global-variables)
3163       (when kill-buffer
3164         (gnus-kill-or-deaden-summary kill-buffer))
3165       (gnus-configure-windows 'summary 'force)
3166       (gnus-set-mode-line 'summary)
3167       (gnus-summary-position-point)
3168       (message "")
3169       t)
3170      ;; We couldn't select this group.
3171      ((null did-select)
3172       (when (and (eq major-mode 'gnus-summary-mode)
3173                  (not (equal (current-buffer) kill-buffer)))
3174         (kill-buffer (current-buffer))
3175         (if (not quit-config)
3176             (progn
3177               ;; Update the info -- marks might need to be removed,
3178               ;; for instance.
3179               (gnus-summary-update-info)
3180               (set-buffer gnus-group-buffer)
3181               (gnus-group-jump-to-group group)
3182               (gnus-group-next-unread-group 1))
3183           (gnus-handle-ephemeral-exit quit-config)))
3184       (let ((grpinfo (gnus-get-info group)))
3185         (if (null (gnus-info-read grpinfo))
3186             (gnus-message 3 "Group %s contains no messages"
3187                           (gnus-group-decoded-name group))
3188           (gnus-message 3 "Can't select group")))
3189       nil)
3190      ;; The user did a `C-g' while prompting for number of articles,
3191      ;; so we exit this group.
3192      ((eq did-select 'quit)
3193       (and (eq major-mode 'gnus-summary-mode)
3194            (not (equal (current-buffer) kill-buffer))
3195            (kill-buffer (current-buffer)))
3196       (when kill-buffer
3197         (gnus-kill-or-deaden-summary kill-buffer))
3198       (if (not quit-config)
3199           (progn
3200             (set-buffer gnus-group-buffer)
3201             (gnus-group-jump-to-group group)
3202             (gnus-group-next-unread-group 1)
3203             (gnus-configure-windows 'group 'force))
3204         (gnus-handle-ephemeral-exit quit-config))
3205       ;; Finally signal the quit.
3206       (signal 'quit nil))
3207      ;; The group was successfully selected.
3208      (t
3209       (gnus-set-global-variables)
3210       ;; Save the active value in effect when the group was entered.
3211       (setq gnus-newsgroup-active
3212             (gnus-copy-sequence
3213              (gnus-active gnus-newsgroup-name)))
3214       ;; You can change the summary buffer in some way with this hook.
3215       (gnus-run-hooks 'gnus-select-group-hook)
3216       (gnus-update-format-specifications
3217        nil 'summary 'summary-mode 'summary-dummy)
3218       (gnus-update-summary-mark-positions)
3219       ;; Do score processing.
3220       (when gnus-use-scoring
3221         (gnus-possibly-score-headers))
3222       ;; Check whether to fill in the gaps in the threads.
3223       (when gnus-build-sparse-threads
3224         (gnus-build-sparse-threads))
3225       ;; Find the initial limit.
3226       (if gnus-show-threads
3227           (if show-all
3228               (let ((gnus-newsgroup-dormant nil))
3229                 (gnus-summary-initial-limit show-all))
3230             (gnus-summary-initial-limit show-all))
3231         ;; When untreaded, all articles are always shown.
3232         (setq gnus-newsgroup-limit
3233               (mapcar
3234                (lambda (header) (mail-header-number header))
3235                gnus-newsgroup-headers)))
3236       ;; Generate the summary buffer.
3237       (unless no-display
3238         (gnus-summary-prepare))
3239       (when gnus-use-trees
3240         (gnus-tree-open group)
3241         (setq gnus-summary-highlight-line-function
3242               'gnus-tree-highlight-article))
3243       ;; If the summary buffer is empty, but there are some low-scored
3244       ;; articles or some excluded dormants, we include these in the
3245       ;; buffer.
3246       (when (and (zerop (buffer-size))
3247                  (not no-display))
3248         (cond (gnus-newsgroup-dormant
3249                (gnus-summary-limit-include-dormant))
3250               ((and gnus-newsgroup-scored show-all)
3251                (gnus-summary-limit-include-expunged t))))
3252       ;; Function `gnus-apply-kill-file' must be called in this hook.
3253       (gnus-run-hooks 'gnus-apply-kill-hook)
3254       (if (and (zerop (buffer-size))
3255                (not no-display))
3256           (progn
3257             ;; This newsgroup is empty.
3258             (gnus-summary-catchup-and-exit nil t)
3259             (gnus-message 6 "No unread news")
3260             (when kill-buffer
3261               (gnus-kill-or-deaden-summary kill-buffer))
3262             ;; Return nil from this function.
3263             nil)
3264         ;; Hide conversation thread subtrees.  We cannot do this in
3265         ;; gnus-summary-prepare-hook since kill processing may not
3266         ;; work with hidden articles.
3267         (and gnus-show-threads
3268              gnus-thread-hide-subtree
3269              (gnus-summary-hide-all-threads))
3270         (when kill-buffer
3271           (gnus-kill-or-deaden-summary kill-buffer))
3272         (gnus-summary-auto-select-subject)
3273         ;; Show first unread article if requested.
3274         (if (and (not no-article)
3275                  (not no-display)
3276                  gnus-newsgroup-unreads
3277                  gnus-auto-select-first)
3278             (progn
3279               (gnus-configure-windows 'summary)
3280               (gnus-summary-goto-article (gnus-summary-article-number)))
3281           ;; Don't select any articles.
3282           (gnus-summary-position-point)
3283           (gnus-configure-windows 'summary 'force)
3284           (gnus-set-mode-line 'summary))
3285         (when (get-buffer-window gnus-group-buffer t)
3286           ;; Gotta use windows, because recenter does weird stuff if
3287           ;; the current buffer ain't the displayed window.
3288           (let ((owin (selected-window)))
3289             (select-window (get-buffer-window gnus-group-buffer t))
3290             (when (gnus-group-goto-group group)
3291               (recenter))
3292             (select-window owin)))
3293         ;; Mark this buffer as "prepared".
3294         (setq gnus-newsgroup-prepared t)
3295         (gnus-run-hooks 'gnus-summary-prepared-hook)
3296         t)))))
3297
3298 (defun gnus-summary-auto-select-subject ()
3299   "Select the subject line on initial group entry."
3300   (goto-char (point-min))
3301   (cond
3302    ((eq gnus-auto-select-subject 'best)
3303     (gnus-summary-best-unread-subject))
3304    ((eq gnus-auto-select-subject 'unread)
3305     (gnus-summary-first-unread-subject))
3306    ((eq gnus-auto-select-subject 'unseen)
3307     (gnus-summary-first-unseen-subject))
3308    ((eq gnus-auto-select-subject 'first)
3309     ;; Do nothing.
3310     )
3311    ((gnus-functionp gnus-auto-select-subject)
3312     (funcall gnus-auto-select-subject))))
3313
3314 (defun gnus-summary-prepare ()
3315   "Generate the summary buffer."
3316   (interactive)
3317   (let ((buffer-read-only nil))
3318     (erase-buffer)
3319     (setq gnus-newsgroup-data nil
3320           gnus-newsgroup-data-reverse nil)
3321     (gnus-run-hooks 'gnus-summary-generate-hook)
3322     ;; Generate the buffer, either with threads or without.
3323     (when gnus-newsgroup-headers
3324       (gnus-summary-prepare-threads
3325        (if gnus-show-threads
3326            (gnus-sort-gathered-threads
3327             (funcall gnus-summary-thread-gathering-function
3328                      (gnus-sort-threads
3329                       (gnus-cut-threads (gnus-make-threads)))))
3330          ;; Unthreaded display.
3331          (gnus-sort-articles gnus-newsgroup-headers))))
3332     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3333     ;; Call hooks for modifying summary buffer.
3334     (goto-char (point-min))
3335     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3336
3337 (defsubst gnus-general-simplify-subject (subject)
3338   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3339   (setq subject
3340         (cond
3341          ;; Truncate the subject.
3342          (gnus-simplify-subject-functions
3343           (gnus-map-function gnus-simplify-subject-functions subject))
3344          ((numberp gnus-summary-gather-subject-limit)
3345           (setq subject (gnus-simplify-subject-re subject))
3346           (if (> (length subject) gnus-summary-gather-subject-limit)
3347               (substring subject 0 gnus-summary-gather-subject-limit)
3348             subject))
3349          ;; Fuzzily simplify it.
3350          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3351           (gnus-simplify-subject-fuzzy subject))
3352          ;; Just remove the leading "Re:".
3353          (t
3354           (gnus-simplify-subject-re subject))))
3355
3356   (if (and gnus-summary-gather-exclude-subject
3357            (string-match gnus-summary-gather-exclude-subject subject))
3358       nil                         ; This article shouldn't be gathered
3359     subject))
3360
3361 (defun gnus-summary-simplify-subject-query ()
3362   "Query where the respool algorithm would put this article."
3363   (interactive)
3364   (gnus-summary-select-article)
3365   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3366
3367 (defun gnus-gather-threads-by-subject (threads)
3368   "Gather threads by looking at Subject headers."
3369   (if (not gnus-summary-make-false-root)
3370       threads
3371     (let ((hashtb (gnus-make-hashtable 1024))
3372           (prev threads)
3373           (result threads)
3374           subject hthread whole-subject)
3375       (while threads
3376         (setq subject (gnus-general-simplify-subject
3377                        (setq whole-subject (mail-header-subject
3378                                             (caar threads)))))
3379         (when subject
3380           (if (setq hthread (gnus-gethash subject hashtb))
3381               (progn
3382                 ;; We enter a dummy root into the thread, if we
3383                 ;; haven't done that already.
3384                 (unless (stringp (caar hthread))
3385                   (setcar hthread (list whole-subject (car hthread))))
3386                 ;; We add this new gathered thread to this gathered
3387                 ;; thread.
3388                 (setcdr (car hthread)
3389                         (nconc (cdar hthread) (list (car threads))))
3390                 ;; Remove it from the list of threads.
3391                 (setcdr prev (cdr threads))
3392                 (setq threads prev))
3393             ;; Enter this thread into the hash table.
3394             (gnus-sethash subject threads hashtb)))
3395         (setq prev threads)
3396         (setq threads (cdr threads)))
3397       result)))
3398
3399 (defun gnus-gather-threads-by-references (threads)
3400   "Gather threads by looking at References headers."
3401   (let ((idhashtb (gnus-make-hashtable 1024))
3402         (thhashtb (gnus-make-hashtable 1024))
3403         (prev threads)
3404         (result threads)
3405         ids references id gthread gid entered ref)
3406     (while threads
3407       (when (setq references (mail-header-references (caar threads)))
3408         (setq id (mail-header-id (caar threads))
3409               ids (gnus-split-references references)
3410               entered nil)
3411         (while (setq ref (pop ids))
3412           (setq ids (delete ref ids))
3413           (if (not (setq gid (gnus-gethash ref idhashtb)))
3414               (progn
3415                 (gnus-sethash ref id idhashtb)
3416                 (gnus-sethash id threads thhashtb))
3417             (setq gthread (gnus-gethash gid thhashtb))
3418             (unless entered
3419               ;; We enter a dummy root into the thread, if we
3420               ;; haven't done that already.
3421               (unless (stringp (caar gthread))
3422                 (setcar gthread (list (mail-header-subject (caar gthread))
3423                                       (car gthread))))
3424               ;; We add this new gathered thread to this gathered
3425               ;; thread.
3426               (setcdr (car gthread)
3427                       (nconc (cdar gthread) (list (car threads)))))
3428             ;; Add it into the thread hash table.
3429             (gnus-sethash id gthread thhashtb)
3430             (setq entered t)
3431             ;; Remove it from the list of threads.
3432             (setcdr prev (cdr threads))
3433             (setq threads prev))))
3434       (setq prev threads)
3435       (setq threads (cdr threads)))
3436     result))
3437
3438 (defun gnus-sort-gathered-threads (threads)
3439   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3440   (let ((result threads))
3441     (while threads
3442       (when (stringp (caar threads))
3443         (setcdr (car threads)
3444                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3445       (setq threads (cdr threads)))
3446     result))
3447
3448 (defun gnus-thread-loop-p (root thread)
3449   "Say whether ROOT is in THREAD."
3450   (let ((stack (list thread))
3451         (infloop 0)
3452         th)
3453     (while (setq thread (pop stack))
3454       (setq th (cdr thread))
3455       (while (and th
3456                   (not (eq (caar th) root)))
3457         (pop th))
3458       (if th
3459           ;; We have found a loop.
3460           (let (ref-dep)
3461             (setcdr thread (delq (car th) (cdr thread)))
3462             (if (boundp (setq ref-dep (intern "none"
3463                                               gnus-newsgroup-dependencies)))
3464                 (setcdr (symbol-value ref-dep)
3465                         (nconc (cdr (symbol-value ref-dep))
3466                                (list (car th))))
3467               (set ref-dep (list nil (car th))))
3468             (setq infloop 1
3469                   stack nil))
3470         ;; Push all the subthreads onto the stack.
3471         (push (cdr thread) stack)))
3472     infloop))
3473
3474 (defun gnus-make-threads ()
3475   "Go through the dependency hashtb and find the roots.  Return all threads."
3476   (let (threads)
3477     (while (catch 'infloop
3478              (mapatoms
3479               (lambda (refs)
3480                 ;; Deal with self-referencing References loops.
3481                 (when (and (car (symbol-value refs))
3482                            (not (zerop
3483                                  (apply
3484                                   '+
3485                                   (mapcar
3486                                    (lambda (thread)
3487                                      (gnus-thread-loop-p
3488                                       (car (symbol-value refs)) thread))
3489                                    (cdr (symbol-value refs)))))))
3490                   (setq threads nil)
3491                   (throw 'infloop t))
3492                 (unless (car (symbol-value refs))
3493              ;; These threads do not refer back to any other articles,
3494                   ;; so they're roots.
3495                   (setq threads (append (cdr (symbol-value refs)) threads))))
3496               gnus-newsgroup-dependencies)))
3497     threads))
3498
3499 ;; Build the thread tree.
3500 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3501   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3502
3503 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3504 if it was already present.
3505
3506 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3507 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3508 Message-IDs will be renamed be renamed to a unique Message-ID before
3509 being entered.
3510
3511 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3512   (let* ((id (mail-header-id header))
3513          (id-dep (and id (intern id dependencies)))
3514          ref ref-dep ref-header)
3515     ;; Enter this `header' in the `dependencies' table.
3516     (cond
3517      ((not id-dep)
3518       (setq header nil))
3519      ;; The first two cases do the normal part: enter a new `header'
3520      ;; in the `dependencies' table.
3521      ((not (boundp id-dep))
3522       (set id-dep (list header)))
3523      ((null (car (symbol-value id-dep)))
3524       (setcar (symbol-value id-dep) header))
3525
3526      ;; From here the `header' was already present in the
3527      ;; `dependencies' table.
3528      (force-new
3529       ;; Overrides an existing entry;
3530       ;; just set the header part of the entry.
3531       (setcar (symbol-value id-dep) header))
3532
3533      ;; Renames the existing `header' to a unique Message-ID.
3534      ((not gnus-summary-ignore-duplicates)
3535       ;; An article with this Message-ID has already been seen.
3536       ;; We rename the Message-ID.
3537       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3538            (list header))
3539       (mail-header-set-id header id))
3540
3541      ;; The last case ignores an existing entry, except it adds any
3542      ;; additional Xrefs (in case the two articles came from different
3543      ;; servers.
3544      ;; Also sets `header' to `nil' meaning that the `dependencies'
3545      ;; table was *not* modified.
3546      (t
3547       (mail-header-set-xref
3548        (car (symbol-value id-dep))
3549        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3550                    "")
3551                (or (mail-header-xref header) "")))
3552       (setq header nil)))
3553
3554     (when header
3555       ;; First check if that we are not creating a References loop.
3556       (setq ref (gnus-parent-id (mail-header-references header)))
3557       (while (and ref
3558                   (setq ref-dep (intern-soft ref dependencies))
3559                   (boundp ref-dep)
3560                   (setq ref-header (car (symbol-value ref-dep))))
3561         (if (string= id ref)
3562             ;; Yuk!  This is a reference loop.  Make the article be a
3563             ;; root article.
3564             (progn
3565               (mail-header-set-references (car (symbol-value id-dep)) "none")
3566               (setq ref nil))
3567           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3568       (setq ref (gnus-parent-id (mail-header-references header)))
3569       (setq ref-dep (intern (or ref "none") dependencies))
3570       (if (boundp ref-dep)
3571           (setcdr (symbol-value ref-dep)
3572                   (nconc (cdr (symbol-value ref-dep))
3573                          (list (symbol-value id-dep))))
3574         (set ref-dep (list nil (symbol-value id-dep)))))
3575     header))
3576
3577 (defun gnus-build-sparse-threads ()
3578   (let ((headers gnus-newsgroup-headers)
3579         (mail-parse-charset gnus-newsgroup-charset)
3580         (gnus-summary-ignore-duplicates t)
3581         header references generation relations
3582         subject child end new-child date)
3583     ;; First we create an alist of generations/relations, where
3584     ;; generations is how much we trust the relation, and the relation
3585     ;; is parent/child.
3586     (gnus-message 7 "Making sparse threads...")
3587     (save-excursion
3588       (nnheader-set-temp-buffer " *gnus sparse threads*")
3589       (while (setq header (pop headers))
3590         (when (and (setq references (mail-header-references header))
3591                    (not (string= references "")))
3592           (insert references)
3593           (setq child (mail-header-id header)
3594                 subject (mail-header-subject header)
3595                 date (mail-header-date header)
3596                 generation 0)
3597           (while (search-backward ">" nil t)
3598             (setq end (1+ (point)))
3599             (when (search-backward "<" nil t)
3600               (setq new-child (buffer-substring (point) end))
3601               (push (list (incf generation)
3602                           child (setq child new-child)
3603                           subject date)
3604                     relations)))
3605           (when child
3606             (push (list (1+ generation) child nil subject) relations))
3607           (erase-buffer)))
3608       (kill-buffer (current-buffer)))
3609     ;; Sort over trustworthiness.
3610     (mapcar
3611      (lambda (relation)
3612        (when (gnus-dependencies-add-header
3613               (make-full-mail-header
3614                gnus-reffed-article-number
3615                (nth 3 relation) "" (or (nth 4 relation) "")
3616                (nth 1 relation)
3617                (or (nth 2 relation) "") 0 0 "")
3618               gnus-newsgroup-dependencies nil)
3619          (push gnus-reffed-article-number gnus-newsgroup-limit)
3620          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3621          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3622                gnus-newsgroup-reads)
3623          (decf gnus-reffed-article-number)))
3624      (sort relations 'car-less-than-car))
3625     (gnus-message 7 "Making sparse threads...done")))
3626
3627 (defun gnus-build-old-threads ()
3628   ;; Look at all the articles that refer back to old articles, and
3629   ;; fetch the headers for the articles that aren't there.  This will
3630   ;; build complete threads - if the roots haven't been expired by the
3631   ;; server, that is.
3632   (let ((mail-parse-charset gnus-newsgroup-charset)
3633         id heads)
3634     (mapatoms
3635      (lambda (refs)
3636        (when (not (car (symbol-value refs)))
3637          (setq heads (cdr (symbol-value refs)))
3638          (while heads
3639            (if (memq (mail-header-number (caar heads))
3640                      gnus-newsgroup-dormant)
3641                (setq heads (cdr heads))
3642              (setq id (symbol-name refs))
3643              (while (and (setq id (gnus-build-get-header id))
3644                          (not (car (gnus-id-to-thread id)))))
3645              (setq heads nil)))))
3646      gnus-newsgroup-dependencies)))
3647
3648 ;; This function has to be called with point after the article number
3649 ;; on the beginning of the line.
3650 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3651   (let ((eol (gnus-point-at-eol))
3652         (buffer (current-buffer))
3653         header)
3654
3655     ;; overview: [num subject from date id refs chars lines misc]
3656     (unwind-protect
3657         (progn
3658           (narrow-to-region (point) eol)
3659           (unless (eobp)
3660             (forward-char))
3661
3662           (setq header
3663                 (make-full-mail-header
3664                  number                 ; number
3665                  (funcall gnus-decode-encoded-word-function
3666                           (nnheader-nov-field)) ; subject
3667                  (funcall gnus-decode-encoded-word-function
3668                           (nnheader-nov-field)) ; from
3669                  (nnheader-nov-field)   ; date
3670                  (nnheader-nov-read-message-id) ; id
3671                  (nnheader-nov-field)   ; refs
3672                  (nnheader-nov-read-integer) ; chars
3673                  (nnheader-nov-read-integer) ; lines
3674                  (unless (eobp)
3675                    (if (looking-at "Xref: ")
3676                        (goto-char (match-end 0)))
3677                    (nnheader-nov-field)) ; Xref
3678                  (nnheader-nov-parse-extra)))) ; extra
3679
3680       (widen))
3681
3682     (when gnus-alter-header-function
3683       (funcall gnus-alter-header-function header))
3684     (gnus-dependencies-add-header header dependencies force-new)))
3685
3686 (defun gnus-build-get-header (id)
3687   "Look through the buffer of NOV lines and find the header to ID.
3688 Enter this line into the dependencies hash table, and return
3689 the id of the parent article (if any)."
3690   (let ((deps gnus-newsgroup-dependencies)
3691         found header)
3692     (prog1
3693         (save-excursion
3694           (set-buffer nntp-server-buffer)
3695           (let ((case-fold-search nil))
3696             (goto-char (point-min))
3697             (while (and (not found)
3698                         (search-forward id nil t))
3699               (beginning-of-line)
3700               (setq found (looking-at
3701                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3702                                    (regexp-quote id))))
3703               (or found (beginning-of-line 2)))
3704             (when found
3705               (beginning-of-line)
3706               (and
3707                (setq header (gnus-nov-parse-line
3708                              (read (current-buffer)) deps))
3709                (gnus-parent-id (mail-header-references header))))))
3710       (when header
3711         (let ((number (mail-header-number header)))
3712           (push number gnus-newsgroup-limit)
3713           (push header gnus-newsgroup-headers)
3714           (if (memq number gnus-newsgroup-unselected)
3715               (progn
3716                 (push number gnus-newsgroup-unreads)
3717                 (setq gnus-newsgroup-unselected
3718                       (delq number gnus-newsgroup-unselected)))
3719             (push number gnus-newsgroup-ancient)))))))
3720
3721 (defun gnus-build-all-threads ()
3722   "Read all the headers."
3723   (let ((gnus-summary-ignore-duplicates t)
3724         (mail-parse-charset gnus-newsgroup-charset)
3725         (dependencies gnus-newsgroup-dependencies)
3726         header article)
3727     (save-excursion
3728       (set-buffer nntp-server-buffer)
3729       (let ((case-fold-search nil))
3730         (goto-char (point-min))
3731         (while (not (eobp))
3732           (ignore-errors
3733             (setq article (read (current-buffer))
3734                   header (gnus-nov-parse-line article dependencies)))
3735           (when header
3736             (save-excursion
3737               (set-buffer gnus-summary-buffer)
3738               (push header gnus-newsgroup-headers)
3739               (if (memq (setq article (mail-header-number header))
3740                         gnus-newsgroup-unselected)
3741                   (progn
3742                     (push article gnus-newsgroup-unreads)
3743                     (setq gnus-newsgroup-unselected
3744                           (delq article gnus-newsgroup-unselected)))
3745                 (push article gnus-newsgroup-ancient)))
3746             (forward-line 1)))))))
3747
3748 (defun gnus-summary-update-article-line (article header)
3749   "Update the line for ARTICLE using HEADERS."
3750   (let* ((id (mail-header-id header))
3751          (thread (gnus-id-to-thread id)))
3752     (unless thread
3753       (error "Article in no thread"))
3754     ;; Update the thread.
3755     (setcar thread header)
3756     (gnus-summary-goto-subject article)
3757     (let* ((datal (gnus-data-find-list article))
3758            (data (car datal))
3759            (length (when (cdr datal)
3760                      (- (gnus-data-pos data)
3761                         (gnus-data-pos (cadr datal)))))
3762            (buffer-read-only nil)
3763            (level (gnus-summary-thread-level)))
3764       (gnus-delete-line)
3765       (gnus-summary-insert-line
3766        header level nil (gnus-article-mark article)
3767        (memq article gnus-newsgroup-replied)
3768        (memq article gnus-newsgroup-expirable)
3769        ;; Only insert the Subject string when it's different
3770        ;; from the previous Subject string.
3771        (if (and
3772             gnus-show-threads
3773             (gnus-subject-equal
3774              (condition-case ()
3775                  (mail-header-subject
3776                   (gnus-data-header
3777                    (cadr
3778                     (gnus-data-find-list
3779                      article
3780                      (gnus-data-list t)))))
3781                ;; Error on the side of excessive subjects.
3782                (error ""))
3783              (mail-header-subject header)))
3784            ""
3785          (mail-header-subject header))
3786        nil (cdr (assq article gnus-newsgroup-scored))
3787        (memq article gnus-newsgroup-processable))
3788       (when length
3789         (gnus-data-update-list
3790          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3791
3792 (defun gnus-summary-update-article (article &optional iheader)
3793   "Update ARTICLE in the summary buffer."
3794   (set-buffer gnus-summary-buffer)
3795   (let* ((header (gnus-summary-article-header article))
3796          (id (mail-header-id header))
3797          (data (gnus-data-find article))
3798          (thread (gnus-id-to-thread id))
3799          (references (mail-header-references header))
3800          (parent
3801           (gnus-id-to-thread
3802            (or (gnus-parent-id
3803                 (when (and references
3804                            (not (equal "" references)))
3805                   references))
3806                "none")))
3807          (buffer-read-only nil)
3808          (old (car thread)))
3809     (when thread
3810       (unless iheader
3811         (setcar thread nil)
3812         (when parent
3813           (delq thread parent)))
3814       (if (gnus-summary-insert-subject id header)
3815        ;; Set the (possibly) new article number in the data structure.
3816           (gnus-data-set-number data (gnus-id-to-article id))
3817         (setcar thread old)
3818         nil))))
3819
3820 (defun gnus-rebuild-thread (id &optional line)
3821   "Rebuild the thread containing ID.
3822 If LINE, insert the rebuilt thread starting on line LINE."
3823   (let ((buffer-read-only nil)
3824         old-pos current thread data)
3825     (if (not gnus-show-threads)
3826         (setq thread (list (car (gnus-id-to-thread id))))
3827       ;; Get the thread this article is part of.
3828       (setq thread (gnus-remove-thread id)))
3829     (setq old-pos (gnus-point-at-bol))
3830     (setq current (save-excursion
3831                     (and (re-search-backward "[\r\n]" nil t)
3832                          (gnus-summary-article-number))))
3833     ;; If this is a gathered thread, we have to go some re-gathering.
3834     (when (stringp (car thread))
3835       (let ((subject (car thread))
3836             roots thr)
3837         (setq thread (cdr thread))
3838         (while thread
3839           (unless (memq (setq thr (gnus-id-to-thread
3840                                    (gnus-root-id
3841                                     (mail-header-id (caar thread)))))
3842                         roots)
3843             (push thr roots))
3844           (setq thread (cdr thread)))
3845         ;; We now have all (unique) roots.
3846         (if (= (length roots) 1)
3847             ;; All the loose roots are now one solid root.
3848             (setq thread (car roots))
3849           (setq thread (cons subject (gnus-sort-threads roots))))))
3850     (let (threads)
3851       ;; We then insert this thread into the summary buffer.
3852       (when line
3853         (goto-char (point-min))
3854         (forward-line (1- line)))
3855       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3856         (if gnus-show-threads
3857             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3858           (gnus-summary-prepare-unthreaded thread))
3859         (setq data (nreverse gnus-newsgroup-data))
3860         (setq threads gnus-newsgroup-threads))
3861       ;; We splice the new data into the data structure.
3862       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3863       ;;!!! then we want to insert at the beginning of the buffer.
3864       ;;!!! That happens to be true with Gnus now, but that may
3865       ;;!!! change in the future.  Perhaps.
3866       (gnus-data-enter-list
3867        (if line nil current) data (- (point) old-pos))
3868       (setq gnus-newsgroup-threads
3869             (nconc threads gnus-newsgroup-threads))
3870       (gnus-data-compute-positions))))
3871
3872 (defun gnus-number-to-header (number)
3873   "Return the header for article NUMBER."
3874   (let ((headers gnus-newsgroup-headers))
3875     (while (and headers
3876                 (not (= number (mail-header-number (car headers)))))
3877       (pop headers))
3878     (when headers
3879       (car headers))))
3880
3881 (defun gnus-parent-headers (in-headers &optional generation)
3882   "Return the headers of the GENERATIONeth parent of HEADERS."
3883   (unless generation
3884     (setq generation 1))
3885   (let ((parent t)
3886         (headers in-headers)
3887         references)
3888     (while (and parent
3889                 (not (zerop generation))
3890                 (setq references (mail-header-references headers)))
3891       (setq headers (if (and references
3892                              (setq parent (gnus-parent-id references)))
3893                         (car (gnus-id-to-thread parent))
3894                       nil))
3895       (decf generation))
3896     (and (not (eq headers in-headers))
3897          headers)))
3898
3899 (defun gnus-id-to-thread (id)
3900   "Return the (sub-)thread where ID appears."
3901   (gnus-gethash id gnus-newsgroup-dependencies))
3902
3903 (defun gnus-id-to-article (id)
3904   "Return the article number of ID."
3905   (let ((thread (gnus-id-to-thread id)))
3906     (when (and thread
3907                (car thread))
3908       (mail-header-number (car thread)))))
3909
3910 (defun gnus-id-to-header (id)
3911   "Return the article headers of ID."
3912   (car (gnus-id-to-thread id)))
3913
3914 (defun gnus-article-displayed-root-p (article)
3915   "Say whether ARTICLE is a root(ish) article."
3916   (let ((level (gnus-summary-thread-level article))
3917         (refs (mail-header-references  (gnus-summary-article-header article)))
3918         particle)
3919     (cond
3920      ((null level) nil)
3921      ((zerop level) t)
3922      ((null refs) t)
3923      ((null (gnus-parent-id refs)) t)
3924      ((and (= 1 level)
3925            (null (setq particle (gnus-id-to-article
3926                                  (gnus-parent-id refs))))
3927            (null (gnus-summary-thread-level particle)))))))
3928
3929 (defun gnus-root-id (id)
3930   "Return the id of the root of the thread where ID appears."
3931   (let (last-id prev)
3932     (while (and id (setq prev (car (gnus-id-to-thread id))))
3933       (setq last-id id
3934             id (gnus-parent-id (mail-header-references prev))))
3935     last-id))
3936
3937 (defun gnus-articles-in-thread (thread)
3938   "Return the list of articles in THREAD."
3939   (cons (mail-header-number (car thread))
3940         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3941
3942 (defun gnus-remove-thread (id &optional dont-remove)
3943   "Remove the thread that has ID in it."
3944   (let (headers thread last-id)
3945     ;; First go up in this thread until we find the root.
3946     (setq last-id (gnus-root-id id)
3947           headers (message-flatten-list (gnus-id-to-thread last-id)))
3948     ;; We have now found the real root of this thread.  It might have
3949     ;; been gathered into some loose thread, so we have to search
3950     ;; through the threads to find the thread we wanted.
3951     (let ((threads gnus-newsgroup-threads)
3952           sub)
3953       (while threads
3954         (setq sub (car threads))
3955         (if (stringp (car sub))
3956             ;; This is a gathered thread, so we look at the roots
3957             ;; below it to find whether this article is in this
3958             ;; gathered root.
3959             (progn
3960               (setq sub (cdr sub))
3961               (while sub
3962                 (when (member (caar sub) headers)
3963                   (setq thread (car threads)
3964                         threads nil
3965                         sub nil))
3966                 (setq sub (cdr sub))))
3967           ;; It's an ordinary thread, so we check it.
3968           (when (eq (car sub) (car headers))
3969             (setq thread sub
3970                   threads nil)))
3971         (setq threads (cdr threads)))
3972       ;; If this article is in no thread, then it's a root.
3973       (if thread
3974           (unless dont-remove
3975             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3976         (setq thread (gnus-id-to-thread last-id)))
3977       (when thread
3978         (prog1
3979             thread                      ; We return this thread.
3980           (unless dont-remove
3981             (if (stringp (car thread))
3982                 (progn
3983                   ;; If we use dummy roots, then we have to remove the
3984                   ;; dummy root as well.
3985                   (when (eq gnus-summary-make-false-root 'dummy)
3986                     ;; We go to the dummy root by going to
3987                     ;; the first sub-"thread", and then one line up.
3988                     (gnus-summary-goto-article
3989                      (mail-header-number (caadr thread)))
3990                     (forward-line -1)
3991                     (gnus-delete-line)
3992                     (gnus-data-compute-positions))
3993                   (setq thread (cdr thread))
3994                   (while thread
3995                     (gnus-remove-thread-1 (car thread))
3996                     (setq thread (cdr thread))))
3997               (gnus-remove-thread-1 thread))))))))
3998
3999 (defun gnus-remove-thread-1 (thread)
4000   "Remove the thread THREAD recursively."
4001   (let ((number (mail-header-number (pop thread)))
4002         d)
4003     (setq thread (reverse thread))
4004     (while thread
4005       (gnus-remove-thread-1 (pop thread)))
4006     (when (setq d (gnus-data-find number))
4007       (goto-char (gnus-data-pos d))
4008       (gnus-summary-show-thread)
4009       (gnus-data-remove
4010        number
4011        (- (gnus-point-at-bol)
4012           (prog1
4013               (1+ (gnus-point-at-eol))
4014             (gnus-delete-line)))))))
4015
4016 (defun gnus-sort-threads-1 (threads func)
4017   (sort (mapcar (lambda (thread)
4018                   (cons (car thread)
4019                         (and (cdr thread)
4020                              (gnus-sort-threads-1 (cdr thread) func))))
4021                 threads) func))
4022
4023 (defun gnus-sort-threads (threads)
4024   "Sort THREADS."
4025   (if (not gnus-thread-sort-functions)
4026       threads
4027     (gnus-message 8 "Sorting threads...")
4028     (prog1
4029         (gnus-sort-threads-1
4030          threads
4031          (gnus-make-sort-function gnus-thread-sort-functions))
4032       (gnus-message 8 "Sorting threads...done"))))
4033
4034 (defun gnus-sort-articles (articles)
4035   "Sort ARTICLES."
4036   (when gnus-article-sort-functions
4037     (gnus-message 7 "Sorting articles...")
4038     (prog1
4039         (setq gnus-newsgroup-headers
4040               (sort articles (gnus-make-sort-function
4041                               gnus-article-sort-functions)))
4042       (gnus-message 7 "Sorting articles...done"))))
4043
4044 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4045 (defmacro gnus-thread-header (thread)
4046   "Return header of first article in THREAD.
4047 Note that THREAD must never, ever be anything else than a variable -
4048 using some other form will lead to serious barfage."
4049   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4050   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4051   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4052         (vector thread) 2))
4053
4054 (defsubst gnus-article-sort-by-number (h1 h2)
4055   "Sort articles by article number."
4056   (< (mail-header-number h1)
4057      (mail-header-number h2)))
4058
4059 (defun gnus-thread-sort-by-number (h1 h2)
4060   "Sort threads by root article number."
4061   (gnus-article-sort-by-number
4062    (gnus-thread-header h1) (gnus-thread-header h2)))
4063
4064 (defsubst gnus-article-sort-by-lines (h1 h2)
4065   "Sort articles by article Lines header."
4066   (< (mail-header-lines h1)
4067      (mail-header-lines h2)))
4068
4069 (defun gnus-thread-sort-by-lines (h1 h2)
4070   "Sort threads by root article Lines header."
4071   (gnus-article-sort-by-lines
4072    (gnus-thread-header h1) (gnus-thread-header h2)))
4073
4074 (defsubst gnus-article-sort-by-chars (h1 h2)
4075   "Sort articles by octet length."
4076   (< (mail-header-chars h1)
4077      (mail-header-chars h2)))
4078
4079 (defun gnus-thread-sort-by-chars (h1 h2)
4080   "Sort threads by root article octet length."
4081   (gnus-article-sort-by-chars
4082    (gnus-thread-header h1) (gnus-thread-header h2)))
4083
4084 (defsubst gnus-article-sort-by-author (h1 h2)
4085   "Sort articles by root author."
4086   (string-lessp
4087    (let ((extract (funcall
4088                    gnus-extract-address-components
4089                    (mail-header-from h1))))
4090      (or (car extract) (cadr extract) ""))
4091    (let ((extract (funcall
4092                    gnus-extract-address-components
4093                    (mail-header-from h2))))
4094      (or (car extract) (cadr extract) ""))))
4095
4096 (defun gnus-thread-sort-by-author (h1 h2)
4097   "Sort threads by root author."
4098   (gnus-article-sort-by-author
4099    (gnus-thread-header h1)  (gnus-thread-header h2)))
4100
4101 (defsubst gnus-article-sort-by-subject (h1 h2)
4102   "Sort articles by root subject."
4103   (string-lessp
4104    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4105    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4106
4107 (defun gnus-thread-sort-by-subject (h1 h2)
4108   "Sort threads by root subject."
4109   (gnus-article-sort-by-subject
4110    (gnus-thread-header h1) (gnus-thread-header h2)))
4111
4112 (defsubst gnus-article-sort-by-date (h1 h2)
4113   "Sort articles by root article date."
4114   (time-less-p
4115    (gnus-date-get-time (mail-header-date h1))
4116    (gnus-date-get-time (mail-header-date h2))))
4117
4118 (defun gnus-thread-sort-by-date (h1 h2)
4119   "Sort threads by root article date."
4120   (gnus-article-sort-by-date
4121    (gnus-thread-header h1) (gnus-thread-header h2)))
4122
4123 (defsubst gnus-article-sort-by-score (h1 h2)
4124   "Sort articles by root article score.
4125 Unscored articles will be counted as having a score of zero."
4126   (> (or (cdr (assq (mail-header-number h1)
4127                     gnus-newsgroup-scored))
4128          gnus-summary-default-score 0)
4129      (or (cdr (assq (mail-header-number h2)
4130                     gnus-newsgroup-scored))
4131          gnus-summary-default-score 0)))
4132
4133 (defun gnus-thread-sort-by-score (h1 h2)
4134   "Sort threads by root article score."
4135   (gnus-article-sort-by-score
4136    (gnus-thread-header h1) (gnus-thread-header h2)))
4137
4138 (defun gnus-thread-sort-by-total-score (h1 h2)
4139   "Sort threads by the sum of all scores in the thread.
4140 Unscored articles will be counted as having a score of zero."
4141   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4142
4143 (defun gnus-thread-total-score (thread)
4144   ;; This function find the total score of THREAD.
4145   (cond ((null thread)
4146          0)
4147         ((consp thread)
4148          (if (stringp (car thread))
4149              (apply gnus-thread-score-function 0
4150                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4151            (gnus-thread-total-score-1 thread)))
4152         (t
4153          (gnus-thread-total-score-1 (list thread)))))
4154
4155 (defun gnus-thread-total-score-1 (root)
4156   ;; This function find the total score of the thread below ROOT.
4157   (setq root (car root))
4158   (apply gnus-thread-score-function
4159          (or (append
4160               (mapcar 'gnus-thread-total-score
4161                       (cdr (gnus-id-to-thread (mail-header-id root))))
4162               (when (> (mail-header-number root) 0)
4163                 (list (or (cdr (assq (mail-header-number root)
4164                                      gnus-newsgroup-scored))
4165                           gnus-summary-default-score 0))))
4166              (list gnus-summary-default-score)
4167              '(0))))
4168
4169 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4170 (defvar gnus-tmp-prev-subject nil)
4171 (defvar gnus-tmp-false-parent nil)
4172 (defvar gnus-tmp-root-expunged nil)
4173 (defvar gnus-tmp-dummy-line nil)
4174
4175 (eval-when-compile (defvar gnus-tmp-header))
4176 (defun gnus-extra-header (type &optional header)
4177   "Return the extra header of TYPE."
4178   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4179       ""))
4180
4181 (defvar gnus-tmp-thread-tree-header-string "")
4182
4183 (defvar gnus-sum-thread-tree-root "> "
4184   "With %B spec, used for the root of a thread.
4185 If nil, use subject instead.")
4186 (defvar gnus-sum-thread-tree-single-indent ""
4187   "With %B spec, used for a thread with just one message.
4188 If nil, use subject instead.")
4189 (defvar gnus-sum-thread-tree-vertical "| "
4190   "With %B spec, used for drawing a vertical line.")
4191 (defvar gnus-sum-thread-tree-indent "  "
4192   "With %B spec, used for indenting.")
4193 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4194   "With %B spec, used for a leaf with brothers.")
4195 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4196   "With %B spec, used for a leaf without brothers.")
4197
4198 (defun gnus-summary-prepare-threads (threads)
4199   "Prepare summary buffer from THREADS and indentation LEVEL.
4200 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4201 or a straight list of headers."
4202   (gnus-message 7 "Generating summary...")
4203
4204   (setq gnus-newsgroup-threads threads)
4205   (beginning-of-line)
4206
4207   (let ((gnus-tmp-level 0)
4208         (default-score (or gnus-summary-default-score 0))
4209         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4210         thread number subject stack state gnus-tmp-gathered beg-match
4211         new-roots gnus-tmp-new-adopts thread-end
4212         gnus-tmp-header gnus-tmp-unread
4213         gnus-tmp-replied gnus-tmp-subject-or-nil
4214         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4215         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4216         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4217         tree-stack)
4218
4219     (setq gnus-tmp-prev-subject nil)
4220
4221     (if (vectorp (car threads))
4222         ;; If this is a straight (sic) list of headers, then a
4223         ;; threaded summary display isn't required, so we just create
4224         ;; an unthreaded one.
4225         (gnus-summary-prepare-unthreaded threads)
4226
4227       ;; Do the threaded display.
4228
4229       (while (or threads stack gnus-tmp-new-adopts new-roots)
4230
4231         (if (and (= gnus-tmp-level 0)
4232                  (or (not stack)
4233                      (= (caar stack) 0))
4234                  (not gnus-tmp-false-parent)
4235                  (or gnus-tmp-new-adopts new-roots))
4236             (if gnus-tmp-new-adopts
4237                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4238                       thread (list (car gnus-tmp-new-adopts))
4239                       gnus-tmp-header (caar thread)
4240                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4241               (when new-roots
4242                 (setq thread (list (car new-roots))
4243                       gnus-tmp-header (caar thread)
4244                       new-roots (cdr new-roots))))
4245
4246           (if threads
4247               ;; If there are some threads, we do them before the
4248               ;; threads on the stack.
4249               (setq thread threads
4250                     gnus-tmp-header (caar thread))
4251             ;; There were no current threads, so we pop something off
4252             ;; the stack.
4253             (setq state (car stack)
4254                   gnus-tmp-level (car state)
4255                   tree-stack (cadr state)
4256                   thread (caddr state)
4257                   stack (cdr stack)
4258                   gnus-tmp-header (caar thread))))
4259
4260         (setq gnus-tmp-false-parent nil)
4261         (setq gnus-tmp-root-expunged nil)
4262         (setq thread-end nil)
4263
4264         (if (stringp gnus-tmp-header)
4265             ;; The header is a dummy root.
4266             (cond
4267              ((eq gnus-summary-make-false-root 'adopt)
4268               ;; We let the first article adopt the rest.
4269               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4270                                                (cddar thread)))
4271               (setq gnus-tmp-gathered
4272                     (nconc (mapcar
4273                             (lambda (h) (mail-header-number (car h)))
4274                             (cddar thread))
4275                            gnus-tmp-gathered))
4276               (setq thread (cons (list (caar thread)
4277                                        (cadar thread))
4278                                  (cdr thread)))
4279               (setq gnus-tmp-level -1
4280                     gnus-tmp-false-parent t))
4281              ((eq gnus-summary-make-false-root 'empty)
4282               ;; We print adopted articles with empty subject fields.
4283               (setq gnus-tmp-gathered
4284                     (nconc (mapcar
4285                             (lambda (h) (mail-header-number (car h)))
4286                             (cddar thread))
4287                            gnus-tmp-gathered))
4288               (setq gnus-tmp-level -1))
4289              ((eq gnus-summary-make-false-root 'dummy)
4290               ;; We remember that we probably want to output a dummy
4291               ;; root.
4292               (setq gnus-tmp-dummy-line gnus-tmp-header)
4293               (setq gnus-tmp-prev-subject gnus-tmp-header))
4294              (t
4295               ;; We do not make a root for the gathered
4296               ;; sub-threads at all.
4297               (setq gnus-tmp-level -1)))
4298
4299           (setq number (mail-header-number gnus-tmp-header)
4300                 subject (mail-header-subject gnus-tmp-header))
4301
4302           (cond
4303            ;; If the thread has changed subject, we might want to make
4304            ;; this subthread into a root.
4305            ((and (null gnus-thread-ignore-subject)
4306                  (not (zerop gnus-tmp-level))
4307                  gnus-tmp-prev-subject
4308                  (not (inline
4309                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4310             (setq new-roots (nconc new-roots (list (car thread)))
4311                   thread-end t
4312                   gnus-tmp-header nil))
4313            ;; If the article lies outside the current limit,
4314            ;; then we do not display it.
4315            ((not (memq number gnus-newsgroup-limit))
4316             (setq gnus-tmp-gathered
4317                   (nconc (mapcar
4318                           (lambda (h) (mail-header-number (car h)))
4319                           (cdar thread))
4320                          gnus-tmp-gathered))
4321             (setq gnus-tmp-new-adopts (if (cdar thread)
4322                                           (append gnus-tmp-new-adopts
4323                                                   (cdar thread))
4324                                         gnus-tmp-new-adopts)
4325                   thread-end t
4326                   gnus-tmp-header nil)
4327             (when (zerop gnus-tmp-level)
4328               (setq gnus-tmp-root-expunged t)))
4329            ;; Perhaps this article is to be marked as read?
4330            ((and gnus-summary-mark-below
4331                  (< (or (cdr (assq number gnus-newsgroup-scored))
4332                         default-score)
4333                     gnus-summary-mark-below)
4334                  ;; Don't touch sparse articles.
4335                  (not (gnus-summary-article-sparse-p number))
4336                  (not (gnus-summary-article-ancient-p number)))
4337             (setq gnus-newsgroup-unreads
4338                   (delq number gnus-newsgroup-unreads))
4339             (if gnus-newsgroup-auto-expire
4340                 (push number gnus-newsgroup-expirable)
4341               (push (cons number gnus-low-score-mark)
4342                     gnus-newsgroup-reads))))
4343
4344           (when gnus-tmp-header
4345             ;; We may have an old dummy line to output before this
4346             ;; article.
4347             (when (and gnus-tmp-dummy-line
4348                        (gnus-subject-equal
4349                         gnus-tmp-dummy-line
4350                         (mail-header-subject gnus-tmp-header)))
4351               (gnus-summary-insert-dummy-line
4352                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4353               (setq gnus-tmp-dummy-line nil))
4354
4355             ;; Compute the mark.
4356             (setq gnus-tmp-unread (gnus-article-mark number))
4357
4358             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4359                                   gnus-tmp-header gnus-tmp-level)
4360                   gnus-newsgroup-data)
4361
4362             ;; Actually insert the line.
4363             (setq
4364              gnus-tmp-subject-or-nil
4365              (cond
4366               ((and gnus-thread-ignore-subject
4367                     gnus-tmp-prev-subject
4368                     (not (inline (gnus-subject-equal
4369                                   gnus-tmp-prev-subject subject))))
4370                subject)
4371               ((zerop gnus-tmp-level)
4372                (if (and (eq gnus-summary-make-false-root 'empty)
4373                         (memq number gnus-tmp-gathered)
4374                         gnus-tmp-prev-subject
4375                         (inline (gnus-subject-equal
4376                                  gnus-tmp-prev-subject subject)))
4377                    gnus-summary-same-subject
4378                  subject))
4379               (t gnus-summary-same-subject)))
4380             (if (and (eq gnus-summary-make-false-root 'adopt)
4381                      (= gnus-tmp-level 1)
4382                      (memq number gnus-tmp-gathered))
4383                 (setq gnus-tmp-opening-bracket ?\<
4384                       gnus-tmp-closing-bracket ?\>)
4385               (setq gnus-tmp-opening-bracket ?\[
4386                     gnus-tmp-closing-bracket ?\]))
4387             (setq
4388              gnus-tmp-indentation
4389              (aref gnus-thread-indent-array gnus-tmp-level)
4390              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4391              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4392                                 gnus-summary-default-score 0)
4393              gnus-tmp-score-char
4394              (if (or (null gnus-summary-default-score)
4395                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4396                          gnus-summary-zcore-fuzz))
4397                  ?                      ;Whitespace
4398                (if (< gnus-tmp-score gnus-summary-default-score)
4399                    gnus-score-below-mark gnus-score-over-mark))
4400              gnus-tmp-replied
4401              (cond ((memq number gnus-newsgroup-processable)
4402                     gnus-process-mark)
4403                    ((memq number gnus-newsgroup-cached)
4404                     gnus-cached-mark)
4405                    ((memq number gnus-newsgroup-replied)
4406                     gnus-replied-mark)
4407                    ((memq number gnus-newsgroup-forwarded)
4408                     gnus-forwarded-mark)
4409                    ((memq number gnus-newsgroup-saved)
4410                     gnus-saved-mark)
4411                    ((memq number gnus-newsgroup-recent)
4412                     gnus-recent-mark)
4413                    ((memq number gnus-newsgroup-unseen)
4414                     gnus-unseen-mark)
4415                    (t gnus-no-mark))
4416              gnus-tmp-from (mail-header-from gnus-tmp-header)
4417              gnus-tmp-name
4418              (cond
4419               ((string-match "<[^>]+> *$" gnus-tmp-from)
4420                (setq beg-match (match-beginning 0))
4421                (or (and (string-match "^\".+\"" gnus-tmp-from)
4422                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4423                    (substring gnus-tmp-from 0 beg-match)))
4424               ((string-match "(.+)" gnus-tmp-from)
4425                (substring gnus-tmp-from
4426                           (1+ (match-beginning 0)) (1- (match-end 0))))
4427               (t gnus-tmp-from))
4428              gnus-tmp-thread-tree-header-string
4429              (cond
4430               ((not gnus-show-threads) "")
4431               ((zerop gnus-tmp-level)
4432                (if (cdar thread)
4433                    (or gnus-sum-thread-tree-root subject)
4434                  (or gnus-sum-thread-tree-single-indent subject)))
4435               (t
4436                (concat (apply 'concat
4437                               (mapcar (lambda (item)
4438                                         (if (= item 1)
4439                                             gnus-sum-thread-tree-vertical
4440                                           gnus-sum-thread-tree-indent))
4441                                       (cdr (reverse tree-stack))))
4442                        (if (nth 1 thread)
4443                            gnus-sum-thread-tree-leaf-with-other
4444                          gnus-sum-thread-tree-single-leaf)))))
4445             (when (string= gnus-tmp-name "")
4446               (setq gnus-tmp-name gnus-tmp-from))
4447             (unless (numberp gnus-tmp-lines)
4448               (setq gnus-tmp-lines -1))
4449             (if (= gnus-tmp-lines -1)
4450                 (setq gnus-tmp-lines "?")
4451               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4452             (gnus-put-text-property
4453              (point)
4454              (progn (eval gnus-summary-line-format-spec) (point))
4455              'gnus-number number)
4456             (when gnus-visual-p
4457               (forward-line -1)
4458               (gnus-run-hooks 'gnus-summary-update-hook)
4459               (forward-line 1))
4460
4461             (setq gnus-tmp-prev-subject subject)))
4462
4463         (when (nth 1 thread)
4464           (push (list (max 0 gnus-tmp-level)
4465                       (copy-list tree-stack)
4466                       (nthcdr 1 thread))
4467                 stack))
4468         (push (if (nth 1 thread) 1 0) tree-stack)
4469         (incf gnus-tmp-level)
4470         (setq threads (if thread-end nil (cdar thread)))
4471         (unless threads
4472           (setq gnus-tmp-level 0)))))
4473   (gnus-message 7 "Generating summary...done"))
4474
4475 (defun gnus-summary-prepare-unthreaded (headers)
4476   "Generate an unthreaded summary buffer based on HEADERS."
4477   (let (header number mark)
4478
4479     (beginning-of-line)
4480
4481     (while headers
4482       ;; We may have to root out some bad articles...
4483       (when (memq (setq number (mail-header-number
4484                                 (setq header (pop headers))))
4485                   gnus-newsgroup-limit)
4486         ;; Mark article as read when it has a low score.
4487         (when (and gnus-summary-mark-below
4488                    (< (or (cdr (assq number gnus-newsgroup-scored))
4489                           gnus-summary-default-score 0)
4490                       gnus-summary-mark-below)
4491                    (not (gnus-summary-article-ancient-p number)))
4492           (setq gnus-newsgroup-unreads
4493                 (delq number gnus-newsgroup-unreads))
4494           (if gnus-newsgroup-auto-expire
4495               (push number gnus-newsgroup-expirable)
4496             (push (cons number gnus-low-score-mark)
4497                   gnus-newsgroup-reads)))
4498
4499         (setq mark (gnus-article-mark number))
4500         (push (gnus-data-make number mark (1+ (point)) header 0)
4501               gnus-newsgroup-data)
4502         (gnus-summary-insert-line
4503          header 0 number
4504          mark (memq number gnus-newsgroup-replied)
4505          (memq number gnus-newsgroup-expirable)
4506          (mail-header-subject header) nil
4507          (cdr (assq number gnus-newsgroup-scored))
4508          (memq number gnus-newsgroup-processable))))))
4509
4510 (defun gnus-summary-remove-list-identifiers ()
4511   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4512   (let ((regexp (if (consp gnus-list-identifiers)
4513                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4514                   gnus-list-identifiers))
4515         changed subject)
4516     (when regexp
4517       (dolist (header gnus-newsgroup-headers)
4518         (setq subject (mail-header-subject header)
4519               changed nil)
4520         (while (string-match
4521                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4522                 subject)
4523           (setq subject
4524                 (concat (substring subject 0 (match-beginning 2))
4525                         (substring subject (match-end 0)))
4526                 changed t))
4527         (when (and changed
4528                    (string-match
4529                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4530           (setq subject
4531                 (concat (substring subject 0 (match-beginning 1))
4532                         (substring subject (match-end 1)))))
4533         (when changed
4534           (mail-header-set-subject header subject))))))
4535
4536 (defun gnus-fetch-headers (articles)
4537   "Fetch headers of ARTICLES."
4538   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4539     (gnus-message 5 "Fetching headers for %s..." name)
4540     (prog1
4541         (if (eq 'nov
4542                 (setq gnus-headers-retrieved-by
4543                       (gnus-retrieve-headers
4544                        articles gnus-newsgroup-name
4545                        ;; We might want to fetch old headers, but
4546                        ;; not if there is only 1 article.
4547                        (and (or (and
4548                                  (not (eq gnus-fetch-old-headers 'some))
4549                                  (not (numberp gnus-fetch-old-headers)))
4550                                 (> (length articles) 1))
4551                             gnus-fetch-old-headers))))
4552             (gnus-get-newsgroup-headers-xover
4553              articles nil nil gnus-newsgroup-name t)
4554           (gnus-get-newsgroup-headers))
4555       (gnus-message 5 "Fetching headers for %s...done" name))))
4556
4557 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4558   "Select newsgroup GROUP.
4559 If READ-ALL is non-nil, all articles in the group are selected.
4560 If SELECT-ARTICLES, only select those articles from GROUP."
4561   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4562          ;;!!! Dirty hack; should be removed.
4563          (gnus-summary-ignore-duplicates
4564           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4565               t
4566             gnus-summary-ignore-duplicates))
4567          (info (nth 2 entry))
4568          articles fetched-articles cached)
4569
4570     (unless (gnus-check-server
4571              (set (make-local-variable 'gnus-current-select-method)
4572                   (gnus-find-method-for-group group)))
4573       (error "Couldn't open server"))
4574
4575     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4576         (gnus-activate-group group)     ; Or we can activate it...
4577         (progn                          ; Or we bug out.
4578           (when (equal major-mode 'gnus-summary-mode)
4579             (kill-buffer (current-buffer)))
4580           (error "Couldn't activate group %s: %s"
4581                  group (gnus-status-message group))))
4582
4583     (unless (gnus-request-group group t)
4584       (when (equal major-mode 'gnus-summary-mode)
4585         (kill-buffer (current-buffer)))
4586       (error "Couldn't request group %s: %s"
4587              group (gnus-status-message group)))
4588
4589     (setq gnus-newsgroup-name group
4590           gnus-newsgroup-unselected nil
4591           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4592
4593     (let ((display (gnus-group-find-parameter group 'display)))
4594       (setq gnus-newsgroup-display
4595             (cond
4596              ((not (zerop (or (car-safe read-all) 0)))
4597               ;; The user entered the group with C-u SPC/RET, let's show
4598               ;; all articles.
4599               'gnus-not-ignore)
4600              ((eq display 'all)
4601               'gnus-not-ignore)
4602              ((arrayp display)
4603               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4604              ((numberp display)
4605               ;; The following is probably the "correct" solution, but
4606               ;; it makes Gnus fetch all headers and then limit the
4607               ;; articles (which is slow), so instead we hack the
4608               ;; select-articles parameter instead. -- Simon Josefsson
4609               ;; <jas@kth.se>
4610               ;;
4611               ;; (gnus-byte-compile
4612               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4613               ;;                         display)))))
4614               (setq select-articles
4615                     (gnus-uncompress-range
4616                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4617                              (if (> tmp 0)
4618                                  tmp
4619                                1))
4620                            (cdr (gnus-active group)))))
4621               nil)
4622              (t
4623               nil))))
4624
4625     (gnus-summary-setup-default-charset)
4626
4627     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4628     (when (gnus-virtual-group-p group)
4629       (setq cached gnus-newsgroup-cached))
4630
4631     (setq gnus-newsgroup-unreads
4632           (gnus-set-difference
4633            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4634            gnus-newsgroup-dormant))
4635
4636     (setq gnus-newsgroup-processable nil)
4637
4638     (gnus-update-read-articles group gnus-newsgroup-unreads)
4639
4640     ;; Adjust and set lists of article marks.
4641     (when info
4642       (gnus-adjust-marked-articles info))
4643
4644     (if (setq articles select-articles)
4645         (setq gnus-newsgroup-unselected
4646               (gnus-sorted-intersection
4647                gnus-newsgroup-unreads
4648                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4649       (setq articles (gnus-articles-to-read group read-all)))
4650
4651     (cond
4652      ((null articles)
4653       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4654       'quit)
4655      ((eq articles 0) nil)
4656      (t
4657       ;; Init the dependencies hash table.
4658       (setq gnus-newsgroup-dependencies
4659             (gnus-make-hashtable (length articles)))
4660       (gnus-set-global-variables)
4661       ;; Retrieve the headers and read them in.
4662       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4663
4664       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4665       (when cached
4666         (setq gnus-newsgroup-cached cached))
4667
4668       ;; Suppress duplicates?
4669       (when gnus-suppress-duplicates
4670         (gnus-dup-suppress-articles))
4671
4672       ;; Set the initial limit.
4673       (setq gnus-newsgroup-limit (copy-sequence articles))
4674       ;; Remove canceled articles from the list of unread articles.
4675       (setq fetched-articles
4676             (mapcar (lambda (headers) (mail-header-number headers))
4677                     gnus-newsgroup-headers))
4678       (setq gnus-newsgroup-articles fetched-articles)
4679       (setq gnus-newsgroup-unreads
4680             (gnus-set-sorted-intersection
4681              gnus-newsgroup-unreads fetched-articles))
4682
4683       ;; The `seen' marks are treated specially.
4684       (if (not gnus-newsgroup-seen)
4685           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4686         (dolist (article gnus-newsgroup-articles)
4687           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4688             (push article gnus-newsgroup-unseen)))
4689         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4690
4691       ;; Removed marked articles that do not exist.
4692       (gnus-update-missing-marks
4693        (gnus-sorted-complement fetched-articles articles))
4694       ;; We might want to build some more threads first.
4695       (when (and gnus-fetch-old-headers
4696                  (eq gnus-headers-retrieved-by 'nov))
4697         (if (eq gnus-fetch-old-headers 'invisible)
4698             (gnus-build-all-threads)
4699           (gnus-build-old-threads)))
4700       ;; Let the Gnus agent mark articles as read.
4701       (when gnus-agent
4702         (gnus-agent-get-undownloaded-list))
4703       ;; Remove list identifiers from subject
4704       (when gnus-list-identifiers
4705         (gnus-summary-remove-list-identifiers))
4706       ;; Check whether auto-expire is to be done in this group.
4707       (setq gnus-newsgroup-auto-expire
4708             (gnus-group-auto-expirable-p group))
4709       ;; Set up the article buffer now, if necessary.
4710       (unless gnus-single-article-buffer
4711         (gnus-article-setup-buffer))
4712       ;; First and last article in this newsgroup.
4713       (when gnus-newsgroup-headers
4714         (setq gnus-newsgroup-begin
4715               (mail-header-number (car gnus-newsgroup-headers))
4716               gnus-newsgroup-end
4717               (mail-header-number
4718                (gnus-last-element gnus-newsgroup-headers))))
4719       ;; GROUP is successfully selected.
4720       (or gnus-newsgroup-headers t)))))
4721
4722 (defun gnus-summary-display-make-predicate (display)
4723   (require 'gnus-agent)
4724   (when (= (length display) 1)
4725     (setq display (car display)))
4726   (unless gnus-summary-display-cache
4727     (dolist (elem (append (list (cons 'read 'read)
4728                                 (cons 'unseen 'unseen))
4729                           gnus-article-mark-lists))
4730       (push (cons (cdr elem)
4731                   (gnus-byte-compile
4732                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4733             gnus-summary-display-cache)))
4734   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4735     (gnus-get-predicate display)))
4736
4737 ;; Uses the dynamically bound `number' variable.
4738 (defvar number)
4739 (defun gnus-article-marked-p (type &optional article)
4740   (let ((article (or article number)))
4741     (cond
4742      ((eq type 'tick)
4743       (memq article gnus-newsgroup-marked))
4744      ((eq type 'unsend)
4745       (memq article gnus-newsgroup-unsendable))
4746      ((eq type 'undownload)
4747       (memq article gnus-newsgroup-undownloaded))
4748      ((eq type 'download)
4749       (memq article gnus-newsgroup-downloadable))
4750      ((eq type 'unread)
4751       (memq article gnus-newsgroup-unreads))
4752      ((eq type 'read)
4753       (memq article gnus-newsgroup-reads))
4754      ((eq type 'dormant)
4755       (memq article gnus-newsgroup-dormant) )
4756      ((eq type 'expire)
4757       (memq article gnus-newsgroup-expirable))
4758      ((eq type 'reply)
4759       (memq article gnus-newsgroup-replied))
4760      ((eq type 'killed)
4761       (memq article gnus-newsgroup-killed))
4762      ((eq type 'bookmark)
4763       (assq article gnus-newsgroup-bookmarks))
4764      ((eq type 'score)
4765       (assq article gnus-newsgroup-scored))
4766      ((eq type 'save)
4767       (memq article gnus-newsgroup-saved))
4768      ((eq type 'cache)
4769       (memq article gnus-newsgroup-cached))
4770      ((eq type 'forward)
4771       (memq article gnus-newsgroup-forwarded))
4772      ((eq type 'seen)
4773       (not (memq article gnus-newsgroup-unseen)))
4774      ((eq type 'recent)
4775       (memq article gnus-newsgroup-recent))
4776      (t t))))
4777
4778 (defun gnus-articles-to-read (group &optional read-all)
4779   "Find out what articles the user wants to read."
4780   (let* ((articles
4781           ;; Select all articles if `read-all' is non-nil, or if there
4782           ;; are no unread articles.
4783           (if (or read-all
4784                   (and (zerop (length gnus-newsgroup-marked))
4785                        (zerop (length gnus-newsgroup-unreads)))
4786                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4787               ;; We want to select the headers for all the articles in
4788               ;; the group, so we select either all the active
4789               ;; articles in the group, or (if that's nil), the
4790               ;; articles in the cache.
4791               (or
4792                (gnus-uncompress-range (gnus-active group))
4793                (gnus-cache-articles-in-group group))
4794             ;; Select only the "normal" subset of articles.
4795             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4796                           (copy-sequence gnus-newsgroup-unreads))
4797                   '<)))
4798          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4799          (scored (length scored-list))
4800          (number (length articles))
4801          (marked (+ (length gnus-newsgroup-marked)
4802                     (length gnus-newsgroup-dormant)))
4803          (select
4804           (cond
4805            ((numberp read-all)
4806             read-all)
4807            (t
4808             (condition-case ()
4809                 (cond
4810                  ((and (or (<= scored marked) (= scored number))
4811                        (numberp gnus-large-newsgroup)
4812                        (> number gnus-large-newsgroup))
4813                   (let ((input
4814                          (read-string
4815                           (format
4816                            "How many articles from %s (default %d): "
4817                            (gnus-limit-string
4818                             (gnus-group-decoded-name gnus-newsgroup-name)
4819                             35)
4820                            number))))
4821                     (if (string-match "^[ \t]*$" input) number input)))
4822                  ((and (> scored marked) (< scored number)
4823                        (> (- scored number) 20))
4824                   (let ((input
4825                          (read-string
4826                           (format "%s %s (%d scored, %d total): "
4827                                   "How many articles from"
4828                                   (gnus-group-decoded-name group)
4829                                   scored number))))
4830                     (if (string-match "^[ \t]*$" input)
4831                         number input)))
4832                  (t number))
4833               (quit
4834                (message "Quit getting the articles to read")
4835                nil))))))
4836     (setq select (if (stringp select) (string-to-number select) select))
4837     (if (or (null select) (zerop select))
4838         select
4839       (if (and (not (zerop scored)) (<= (abs select) scored))
4840           (progn
4841             (setq articles (sort scored-list '<))
4842             (setq number (length articles)))
4843         (setq articles (copy-sequence articles)))
4844
4845       (when (< (abs select) number)
4846         (if (< select 0)
4847             ;; Select the N oldest articles.
4848             (setcdr (nthcdr (1- (abs select)) articles) nil)
4849           ;; Select the N most recent articles.
4850           (setq articles (nthcdr (- number select) articles))))
4851       (setq gnus-newsgroup-unselected
4852             (gnus-sorted-intersection
4853              gnus-newsgroup-unreads
4854              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4855       (when gnus-alter-articles-to-read-function
4856         (setq gnus-newsgroup-unreads
4857               (sort
4858                (funcall gnus-alter-articles-to-read-function
4859                         gnus-newsgroup-name gnus-newsgroup-unreads)
4860                '<)))
4861       articles)))
4862
4863 (defun gnus-killed-articles (killed articles)
4864   (let (out)
4865     (while articles
4866       (when (inline (gnus-member-of-range (car articles) killed))
4867         (push (car articles) out))
4868       (setq articles (cdr articles)))
4869     out))
4870
4871 (defun gnus-uncompress-marks (marks)
4872   "Uncompress the mark ranges in MARKS."
4873   (let ((uncompressed '(score bookmark))
4874         out)
4875     (while marks
4876       (if (memq (caar marks) uncompressed)
4877           (push (car marks) out)
4878         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4879       (setq marks (cdr marks)))
4880     out))
4881
4882 (defun gnus-article-mark-to-type (mark)
4883   "Return the type of MARK."
4884   (or (cadr (assq mark gnus-article-special-mark-lists))
4885       'list))
4886
4887 (defun gnus-article-unpropagatable-p (mark)
4888   "Return whether MARK should be propagated to backend."
4889   (memq mark gnus-article-unpropagated-mark-lists))
4890
4891 (defun gnus-adjust-marked-articles (info)
4892   "Set all article lists and remove all marks that are no longer valid."
4893   (let* ((marked-lists (gnus-info-marks info))
4894          (active (gnus-active (gnus-info-group info)))
4895          (min (car active))
4896          (max (cdr active))
4897          (types gnus-article-mark-lists)
4898          marks var articles article mark mark-type)
4899
4900     (dolist (marks marked-lists)
4901       (setq mark (car marks)
4902             mark-type (gnus-article-mark-to-type mark)
4903             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4904
4905       ;; We set the variable according to the type of the marks list,
4906       ;; and then adjust the marks to a subset of the active articles.
4907       (cond
4908        ;; Adjust "simple" lists.
4909        ((eq mark-type 'list)
4910         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4911         (when (memq mark '(tick dormant expire reply save))
4912           (while articles
4913             (when (or (< (setq article (pop articles)) min) (> article max))
4914               (set var (delq article (symbol-value var)))))))
4915        ;; Adjust assocs.
4916        ((eq mark-type 'tuple)
4917         (set var (setq articles (cdr marks)))
4918         (when (not (listp (cdr (symbol-value var))))
4919           (set var (list (symbol-value var))))
4920         (when (not (listp (cdr articles)))
4921           (setq articles (list articles)))
4922         (while articles
4923           (when (or (not (consp (setq article (pop articles))))
4924                     (< (car article) min)
4925                     (> (car article) max))
4926             (set var (delq article (symbol-value var))))))
4927        ;; Adjust ranges (sloppily).
4928        ((eq mark-type 'range)
4929         (cond
4930          ((eq mark 'seen)
4931           (setq articles (cdr marks))
4932           (while (and articles
4933                       (or (and (consp (car articles))
4934                                (> min (cdar articles)))
4935                           (and (numberp (car articles))
4936                                (> min (car articles)))))
4937             (pop articles))
4938           (set var articles))))))))
4939
4940 (defun gnus-update-missing-marks (missing)
4941   "Go through the list of MISSING articles and remove them from the mark lists."
4942   (when missing
4943     (let (var m)
4944       ;; Go through all types.
4945       (dolist (elem gnus-article-mark-lists)
4946         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4947           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4948           (when (symbol-value var)
4949             ;; This list has articles.  So we delete all missing
4950             ;; articles from it.
4951             (setq m missing)
4952             (while m
4953               (set var (delq (pop m) (symbol-value var))))))))))
4954
4955 (defun gnus-update-marks ()
4956   "Enter the various lists of marked articles into the newsgroup info list."
4957   (let ((types gnus-article-mark-lists)
4958         (info (gnus-get-info gnus-newsgroup-name))
4959         type list newmarked symbol delta-marks)
4960     (when info
4961       ;; Add all marks lists to the list of marks lists.
4962       (while (setq type (pop types))
4963         (setq list (symbol-value
4964                     (setq symbol
4965                           (intern (format "gnus-newsgroup-%s" (car type))))))
4966
4967         (when list
4968           ;; Get rid of the entries of the articles that have the
4969           ;; default score.
4970           (when (and (eq (cdr type) 'score)
4971                      gnus-save-score
4972                      list)
4973             (let* ((arts list)
4974                    (prev (cons nil list))
4975                    (all prev))
4976               (while arts
4977                 (if (or (not (consp (car arts)))
4978                         (= (cdar arts) gnus-summary-default-score))
4979                     (setcdr prev (cdr arts))
4980                   (setq prev arts))
4981                 (setq arts (cdr arts)))
4982               (setq list (cdr all)))))
4983
4984         (when (eq (cdr type) 'seen)
4985           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
4986
4987         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4988           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4989
4990         (when (and (gnus-check-backend-function
4991                     'request-set-mark gnus-newsgroup-name)
4992                    (not (gnus-article-unpropagatable-p (cdr type))))
4993           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4994                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4995                  (add (gnus-remove-from-range
4996                        (gnus-copy-sequence list) old)))
4997             (when add
4998               (push (list add 'add (list (cdr type))) delta-marks))
4999             (when del
5000               (push (list del 'del (list (cdr type))) delta-marks))))
5001
5002         (when list
5003           (push (cons (cdr type) list) newmarked)))
5004
5005       (when delta-marks
5006         (unless (gnus-check-group gnus-newsgroup-name)
5007           (error "Can't open server for %s" gnus-newsgroup-name))
5008         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5009
5010       ;; Enter these new marks into the info of the group.
5011       (if (nthcdr 3 info)
5012           (setcar (nthcdr 3 info) newmarked)
5013         ;; Add the marks lists to the end of the info.
5014         (when newmarked
5015           (setcdr (nthcdr 2 info) (list newmarked))))
5016
5017       ;; Cut off the end of the info if there's nothing else there.
5018       (let ((i 5))
5019         (while (and (> i 2)
5020                     (not (nth i info)))
5021           (when (nthcdr (decf i) info)
5022             (setcdr (nthcdr i info) nil)))))))
5023
5024 (defun gnus-set-mode-line (where)
5025   "Set the mode line of the article or summary buffers.
5026 If WHERE is `summary', the summary mode line format will be used."
5027   ;; Is this mode line one we keep updated?
5028   (when (and (memq where gnus-updated-mode-lines)
5029              (symbol-value
5030               (intern (format "gnus-%s-mode-line-format-spec" where))))
5031     (let (mode-string)
5032       (save-excursion
5033         ;; We evaluate this in the summary buffer since these
5034         ;; variables are buffer-local to that buffer.
5035         (set-buffer gnus-summary-buffer)
5036        ;; We bind all these variables that are used in the `eval' form
5037         ;; below.
5038         (let* ((mformat (symbol-value
5039                          (intern
5040                           (format "gnus-%s-mode-line-format-spec" where))))
5041                (gnus-tmp-group-name (gnus-group-decoded-name
5042                                      gnus-newsgroup-name))
5043                (gnus-tmp-article-number (or gnus-current-article 0))
5044                (gnus-tmp-unread gnus-newsgroup-unreads)
5045                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5046                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5047                (gnus-tmp-unread-and-unselected
5048                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5049                             (zerop gnus-tmp-unselected))
5050                        "")
5051                       ((zerop gnus-tmp-unselected)
5052                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5053                       (t (format "{%d(+%d) more}"
5054                                  gnus-tmp-unread-and-unticked
5055                                  gnus-tmp-unselected))))
5056                (gnus-tmp-subject
5057                 (if (and gnus-current-headers
5058                          (vectorp gnus-current-headers))
5059                     (gnus-mode-string-quote
5060                      (mail-header-subject gnus-current-headers))
5061                   ""))
5062                bufname-length max-len
5063                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5064           (setq mode-string (eval mformat))
5065           (setq bufname-length (if (string-match "%b" mode-string)
5066                                    (- (length
5067                                        (buffer-name
5068                                         (if (eq where 'summary)
5069                                             nil
5070                                           (get-buffer gnus-article-buffer))))
5071                                       2)
5072                                  0))
5073           (setq max-len (max 4 (if gnus-mode-non-string-length
5074                                    (- (window-width)
5075                                       gnus-mode-non-string-length
5076                                       bufname-length)
5077                                  (length mode-string))))
5078           ;; We might have to chop a bit of the string off...
5079           (when (> (length mode-string) max-len)
5080             (setq mode-string
5081                   (concat (truncate-string-to-width mode-string (- max-len 3))
5082                           "...")))
5083           ;; Pad the mode string a bit.
5084           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5085       ;; Update the mode line.
5086       (setq mode-line-buffer-identification
5087             (gnus-mode-line-buffer-identification (list mode-string)))
5088       (set-buffer-modified-p t))))
5089
5090 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5091   "Go through the HEADERS list and add all Xrefs to a hash table.
5092 The resulting hash table is returned, or nil if no Xrefs were found."
5093   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5094          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5095          (xref-hashtb (gnus-make-hashtable))
5096          start group entry number xrefs header)
5097     (while headers
5098       (setq header (pop headers))
5099       (when (and (setq xrefs (mail-header-xref header))
5100                  (not (memq (setq number (mail-header-number header))
5101                             unreads)))
5102         (setq start 0)
5103         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5104           (setq start (match-end 0))
5105           (setq group (if prefix
5106                           (concat prefix (substring xrefs (match-beginning 1)
5107                                                     (match-end 1)))
5108                         (substring xrefs (match-beginning 1) (match-end 1))))
5109           (setq number
5110                 (string-to-int (substring xrefs (match-beginning 2)
5111                                           (match-end 2))))
5112           (if (setq entry (gnus-gethash group xref-hashtb))
5113               (setcdr entry (cons number (cdr entry)))
5114             (gnus-sethash group (cons number nil) xref-hashtb)))))
5115     (and start xref-hashtb)))
5116
5117 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5118   "Look through all the headers and mark the Xrefs as read."
5119   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5120         name entry info xref-hashtb idlist method nth4)
5121     (save-excursion
5122       (set-buffer gnus-group-buffer)
5123       (when (setq xref-hashtb
5124                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5125         (mapatoms
5126          (lambda (group)
5127            (unless (string= from-newsgroup (setq name (symbol-name group)))
5128              (setq idlist (symbol-value group))
5129              ;; Dead groups are not updated.
5130              (and (prog1
5131                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5132                             info (nth 2 entry))
5133                     (when (stringp (setq nth4 (gnus-info-method info)))
5134                       (setq nth4 (gnus-server-to-method nth4))))
5135                   ;; Only do the xrefs if the group has the same
5136                   ;; select method as the group we have just read.
5137                   (or (gnus-methods-equal-p
5138                        nth4 (gnus-find-method-for-group from-newsgroup))
5139                       virtual
5140                       (equal nth4 (setq method (gnus-find-method-for-group
5141                                                 from-newsgroup)))
5142                       (and (equal (car nth4) (car method))
5143                            (equal (nth 1 nth4) (nth 1 method))))
5144                   gnus-use-cross-reference
5145                   (or (not (eq gnus-use-cross-reference t))
5146                       virtual
5147                       ;; Only do cross-references on subscribed
5148                       ;; groups, if that is what is wanted.
5149                       (<= (gnus-info-level info) gnus-level-subscribed))
5150                   (gnus-group-make-articles-read name idlist))))
5151          xref-hashtb)))))
5152
5153 (defun gnus-compute-read-articles (group articles)
5154   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5155          (info (nth 2 entry))
5156          (active (gnus-active group))
5157          ninfo)
5158     (when entry
5159       ;; First peel off all invalid article numbers.
5160       (when active
5161         (let ((ids articles)
5162               id first)
5163           (while (setq id (pop ids))
5164             (when (and first (> id (cdr active)))
5165               ;; We'll end up in this situation in one particular
5166               ;; obscure situation.  If you re-scan a group and get
5167               ;; a new article that is cross-posted to a different
5168               ;; group that has not been re-scanned, you might get
5169               ;; crossposted article that has a higher number than
5170               ;; Gnus believes possible.  So we re-activate this
5171               ;; group as well.  This might mean doing the
5172               ;; crossposting thingy will *increase* the number
5173               ;; of articles in some groups.  Tsk, tsk.
5174               (setq active (or (gnus-activate-group group) active)))
5175             (when (or (> id (cdr active))
5176                       (< id (car active)))
5177               (setq articles (delq id articles))))))
5178       ;; If the read list is nil, we init it.
5179       (if (and active
5180                (null (gnus-info-read info))
5181                (> (car active) 1))
5182           (setq ninfo (cons 1 (1- (car active))))
5183         (setq ninfo (gnus-info-read info)))
5184       ;; Then we add the read articles to the range.
5185       (gnus-add-to-range
5186        ninfo (setq articles (sort articles '<))))))
5187
5188 (defun gnus-group-make-articles-read (group articles)
5189   "Update the info of GROUP to say that ARTICLES are read."
5190   (let* ((num 0)
5191          (entry (gnus-gethash group gnus-newsrc-hashtb))
5192          (info (nth 2 entry))
5193          (active (gnus-active group))
5194          range)
5195     (when entry
5196       (setq range (gnus-compute-read-articles group articles))
5197       (save-excursion
5198         (set-buffer gnus-group-buffer)
5199         (gnus-undo-register
5200           `(progn
5201              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5202              (gnus-info-set-read ',info ',(gnus-info-read info))
5203              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5204              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5205              (gnus-group-update-group ,group t))))
5206       ;; Add the read articles to the range.
5207       (gnus-info-set-read info range)
5208       (gnus-request-set-mark group (list (list range 'add '(read))))
5209       ;; Then we have to re-compute how many unread
5210       ;; articles there are in this group.
5211       (when active
5212         (cond
5213          ((not range)
5214           (setq num (- (1+ (cdr active)) (car active))))
5215          ((not (listp (cdr range)))
5216           (setq num (- (cdr active) (- (1+ (cdr range))
5217                                        (car range)))))
5218          (t
5219           (while range
5220             (if (numberp (car range))
5221                 (setq num (1+ num))
5222               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5223             (setq range (cdr range)))
5224           (setq num (- (cdr active) num))))
5225         ;; Update the number of unread articles.
5226         (setcar entry num)
5227         ;; Update the group buffer.
5228         (gnus-group-update-group group t)))))
5229
5230 (defvar gnus-newsgroup-none-id 0)
5231
5232 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5233   (let ((cur nntp-server-buffer)
5234         (dependencies
5235          (or dependencies
5236              (save-excursion (set-buffer gnus-summary-buffer)
5237                              gnus-newsgroup-dependencies)))
5238         headers id end ref
5239         (mail-parse-charset gnus-newsgroup-charset)
5240         (mail-parse-ignored-charsets
5241          (save-excursion (condition-case nil
5242                              (set-buffer gnus-summary-buffer)
5243                            (error))
5244                          gnus-newsgroup-ignored-charsets)))
5245     (save-excursion
5246       (set-buffer nntp-server-buffer)
5247       ;; Translate all TAB characters into SPACE characters.
5248       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5249       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5250       (gnus-run-hooks 'gnus-parse-headers-hook)
5251       (let ((case-fold-search t)
5252             in-reply-to header p lines chars)
5253         (goto-char (point-min))
5254         ;; Search to the beginning of the next header.  Error messages
5255         ;; do not begin with 2 or 3.
5256         (while (re-search-forward "^[23][0-9]+ " nil t)
5257           (setq id nil
5258                 ref nil)
5259           ;; This implementation of this function, with nine
5260           ;; search-forwards instead of the one re-search-forward and
5261           ;; a case (which basically was the old function) is actually
5262           ;; about twice as fast, even though it looks messier.  You
5263           ;; can't have everything, I guess.  Speed and elegance
5264           ;; doesn't always go hand in hand.
5265           (setq
5266            header
5267            (vector
5268             ;; Number.
5269             (prog1
5270                 (read cur)
5271               (end-of-line)
5272               (setq p (point))
5273               (narrow-to-region (point)
5274                                 (or (and (search-forward "\n.\n" nil t)
5275                                          (- (point) 2))
5276                                     (point))))
5277             ;; Subject.
5278             (progn
5279               (goto-char p)
5280               (if (search-forward "\nsubject:" nil t)
5281                   (funcall gnus-decode-encoded-word-function
5282                            (nnheader-header-value))
5283                 "(none)"))
5284             ;; From.
5285             (progn
5286               (goto-char p)
5287               (if (search-forward "\nfrom:" nil t)
5288                   (funcall gnus-decode-encoded-word-function
5289                            (nnheader-header-value))
5290                 "(nobody)"))
5291             ;; Date.
5292             (progn
5293               (goto-char p)
5294               (if (search-forward "\ndate:" nil t)
5295                   (nnheader-header-value) ""))
5296             ;; Message-ID.
5297             (progn
5298               (goto-char p)
5299               (setq id (if (re-search-forward
5300                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5301                            ;; We do it this way to make sure the Message-ID
5302                            ;; is (somewhat) syntactically valid.
5303                            (buffer-substring (match-beginning 1)
5304                                              (match-end 1))
5305                          ;; If there was no message-id, we just fake one
5306                          ;; to make subsequent routines simpler.
5307                          (nnheader-generate-fake-message-id))))
5308             ;; References.
5309             (progn
5310               (goto-char p)
5311               (if (search-forward "\nreferences:" nil t)
5312                   (progn
5313                     (setq end (point))
5314                     (prog1
5315                         (nnheader-header-value)
5316                       (setq ref
5317                             (buffer-substring
5318                              (progn
5319                                (end-of-line)
5320                                (search-backward ">" end t)
5321                                (1+ (point)))
5322                              (progn
5323                                (search-backward "<" end t)
5324                                (point))))))
5325                 ;; Get the references from the in-reply-to header if there
5326                 ;; were no references and the in-reply-to header looks
5327                 ;; promising.
5328                 (if (and (search-forward "\nin-reply-to:" nil t)
5329                          (setq in-reply-to (nnheader-header-value))
5330                          (string-match "<[^>]+>" in-reply-to))
5331                     (let (ref2)
5332                       (setq ref (substring in-reply-to (match-beginning 0)
5333                                            (match-end 0)))
5334                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5335                         (setq ref2 (substring in-reply-to (match-beginning 0)
5336                                               (match-end 0)))
5337                         (when (> (length ref2) (length ref))
5338                           (setq ref ref2)))
5339                       ref)
5340                   (setq ref nil))))
5341             ;; Chars.
5342             (progn
5343               (goto-char p)
5344               (if (search-forward "\nchars: " nil t)
5345                   (if (numberp (setq chars (ignore-errors (read cur))))
5346                       chars -1)
5347                 -1))
5348             ;; Lines.
5349             (progn
5350               (goto-char p)
5351               (if (search-forward "\nlines: " nil t)
5352                   (if (numberp (setq lines (ignore-errors (read cur))))
5353                       lines -1)
5354                 -1))
5355             ;; Xref.
5356             (progn
5357               (goto-char p)
5358               (and (search-forward "\nxref:" nil t)
5359                    (nnheader-header-value)))
5360             ;; Extra.
5361             (when gnus-extra-headers
5362               (let ((extra gnus-extra-headers)
5363                     out)
5364                 (while extra
5365                   (goto-char p)
5366                   (when (search-forward
5367                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5368                     (push (cons (car extra) (nnheader-header-value))
5369                           out))
5370                   (pop extra))
5371                 out))))
5372           (when (equal id ref)
5373             (setq ref nil))
5374
5375           (when gnus-alter-header-function
5376             (funcall gnus-alter-header-function header)
5377             (setq id (mail-header-id header)
5378                   ref (gnus-parent-id (mail-header-references header))))
5379
5380           (when (setq header
5381                       (gnus-dependencies-add-header
5382                        header dependencies force-new))
5383             (push header headers))
5384           (goto-char (point-max))
5385           (widen))
5386         (nreverse headers)))))
5387
5388 ;; Goes through the xover lines and returns a list of vectors
5389 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5390                                                   force-new dependencies
5391                                                   group also-fetch-heads)
5392   "Parse the news overview data in the server buffer.
5393 Return a list of headers that match SEQUENCE (see
5394 `nntp-retrieve-headers')."
5395   ;; Get the Xref when the users reads the articles since most/some
5396   ;; NNTP servers do not include Xrefs when using XOVER.
5397   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5398   (let ((mail-parse-charset gnus-newsgroup-charset)
5399         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5400         (cur nntp-server-buffer)
5401         (dependencies (or dependencies gnus-newsgroup-dependencies))
5402         (allp (cond
5403                ((eq gnus-read-all-available-headers t)
5404                 t)
5405                ((stringp gnus-read-all-available-headers)
5406                 (string-match gnus-read-all-available-headers group))
5407                (t
5408                 nil)))
5409         number headers header)
5410     (save-excursion
5411       (set-buffer nntp-server-buffer)
5412       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5413       ;; Allow the user to mangle the headers before parsing them.
5414       (gnus-run-hooks 'gnus-parse-headers-hook)
5415       (goto-char (point-min))
5416       (while (not (eobp))
5417         (condition-case ()
5418             (while (and (or sequence allp)
5419                         (not (eobp)))
5420               (setq number (read cur))
5421               (when (not allp)
5422                 (while (and sequence
5423                             (< (car sequence) number))
5424                   (setq sequence (cdr sequence))))
5425               (when (and (or allp
5426                              (and sequence
5427                                   (eq number (car sequence))))
5428                          (progn
5429                            (setq sequence (cdr sequence))
5430                            (setq header (inline
5431                                           (gnus-nov-parse-line
5432                                            number dependencies force-new)))))
5433                 (push header headers))
5434               (forward-line 1))
5435           (error
5436            (gnus-error 4 "Strange nov line (%d)"
5437                        (count-lines (point-min) (point)))))
5438         (forward-line 1))
5439       ;; A common bug in inn is that if you have posted an article and
5440       ;; then retrieves the active file, it will answer correctly --
5441       ;; the new article is included.  However, a NOV entry for the
5442       ;; article may not have been generated yet, so this may fail.
5443       ;; We work around this problem by retrieving the last few
5444       ;; headers using HEAD.
5445       (if (or (not also-fetch-heads)
5446               (not sequence))
5447           ;; We (probably) got all the headers.
5448           (nreverse headers)
5449         (let ((gnus-nov-is-evil t))
5450           (nconc
5451            (nreverse headers)
5452            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5453              (gnus-get-newsgroup-headers))))))))
5454
5455 (defun gnus-article-get-xrefs ()
5456   "Fill in the Xref value in `gnus-current-headers', if necessary.
5457 This is meant to be called in `gnus-article-internal-prepare-hook'."
5458   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5459                                  gnus-current-headers)))
5460     (or (not gnus-use-cross-reference)
5461         (not headers)
5462         (and (mail-header-xref headers)
5463              (not (string= (mail-header-xref headers) "")))
5464         (let ((case-fold-search t)
5465               xref)
5466           (save-restriction
5467             (nnheader-narrow-to-headers)
5468             (goto-char (point-min))
5469             (when (or (and (not (eobp))
5470                            (eq (downcase (char-after)) ?x)
5471                            (looking-at "Xref:"))
5472                       (search-forward "\nXref:" nil t))
5473               (goto-char (1+ (match-end 0)))
5474               (setq xref (buffer-substring (point)
5475                                            (progn (end-of-line) (point))))
5476               (mail-header-set-xref headers xref)))))))
5477
5478 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5479   "Find article ID and insert the summary line for that article.
5480 OLD-HEADER can either be a header or a line number to insert
5481 the subject line on."
5482   (let* ((line (and (numberp old-header) old-header))
5483          (old-header (and (vectorp old-header) old-header))
5484          (header (cond ((and old-header use-old-header)
5485                         old-header)
5486                        ((and (numberp id)
5487                              (gnus-number-to-header id))
5488                         (gnus-number-to-header id))
5489                        (t
5490                         (gnus-read-header id))))
5491          (number (and (numberp id) id))
5492          d)
5493     (when header
5494       ;; Rebuild the thread that this article is part of and go to the
5495       ;; article we have fetched.
5496       (when (and (not gnus-show-threads)
5497                  old-header)
5498         (when (and number
5499                    (setq d (gnus-data-find (mail-header-number old-header))))
5500           (goto-char (gnus-data-pos d))
5501           (gnus-data-remove
5502            number
5503            (- (gnus-point-at-bol)
5504               (prog1
5505                   (1+ (gnus-point-at-eol))
5506                 (gnus-delete-line))))))
5507       (when old-header
5508         (mail-header-set-number header (mail-header-number old-header)))
5509       (setq gnus-newsgroup-sparse
5510             (delq (setq number (mail-header-number header))
5511                   gnus-newsgroup-sparse))
5512       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5513       (push number gnus-newsgroup-limit)
5514       (gnus-rebuild-thread (mail-header-id header) line)
5515       (gnus-summary-goto-subject number nil t))
5516     (when (and (numberp number)
5517                (> number 0))
5518       ;; We have to update the boundaries even if we can't fetch the
5519       ;; article if ID is a number -- so that the next `P' or `N'
5520       ;; command will fetch the previous (or next) article even
5521       ;; if the one we tried to fetch this time has been canceled.
5522       (when (> number gnus-newsgroup-end)
5523         (setq gnus-newsgroup-end number))
5524       (when (< number gnus-newsgroup-begin)
5525         (setq gnus-newsgroup-begin number))
5526       (setq gnus-newsgroup-unselected
5527             (delq number gnus-newsgroup-unselected)))
5528     ;; Report back a success?
5529     (and header (mail-header-number header))))
5530
5531 ;;; Process/prefix in the summary buffer
5532
5533 (defun gnus-summary-work-articles (n)
5534   "Return a list of articles to be worked upon.
5535 The prefix argument, the list of process marked articles, and the
5536 current article will be taken into consideration."
5537   (save-excursion
5538     (set-buffer gnus-summary-buffer)
5539     (cond
5540      (n
5541       ;; A numerical prefix has been given.
5542       (setq n (prefix-numeric-value n))
5543       (let ((backward (< n 0))
5544             (n (abs (prefix-numeric-value n)))
5545             articles article)
5546         (save-excursion
5547           (while
5548               (and (> n 0)
5549                    (push (setq article (gnus-summary-article-number))
5550                          articles)
5551                    (if backward
5552                        (gnus-summary-find-prev nil article)
5553                      (gnus-summary-find-next nil article)))
5554             (decf n)))
5555         (nreverse articles)))
5556      ((and (gnus-region-active-p) (mark))
5557       (message "region active")
5558       ;; Work on the region between point and mark.
5559       (let ((max (max (point) (mark)))
5560             articles article)
5561         (save-excursion
5562           (goto-char (min (min (point) (mark))))
5563           (while
5564               (and
5565                (push (setq article (gnus-summary-article-number)) articles)
5566                (gnus-summary-find-next nil article)
5567                (< (point) max)))
5568           (nreverse articles))))
5569      (gnus-newsgroup-processable
5570       ;; There are process-marked articles present.
5571       ;; Save current state.
5572       (gnus-summary-save-process-mark)
5573       ;; Return the list.
5574       (reverse gnus-newsgroup-processable))
5575      (t
5576       ;; Just return the current article.
5577       (list (gnus-summary-article-number))))))
5578
5579 (defmacro gnus-summary-iterate (arg &rest forms)
5580   "Iterate over the process/prefixed articles and do FORMS.
5581 ARG is the interactive prefix given to the command.  FORMS will be
5582 executed with point over the summary line of the articles."
5583   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5584     `(let ((,articles (gnus-summary-work-articles ,arg)))
5585        (while ,articles
5586          (gnus-summary-goto-subject (car ,articles))
5587          ,@forms
5588          (pop ,articles)))))
5589
5590 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5591 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5592
5593 (defun gnus-summary-save-process-mark ()
5594   "Push the current set of process marked articles on the stack."
5595   (interactive)
5596   (push (copy-sequence gnus-newsgroup-processable)
5597         gnus-newsgroup-process-stack))
5598
5599 (defun gnus-summary-kill-process-mark ()
5600   "Push the current set of process marked articles on the stack and unmark."
5601   (interactive)
5602   (gnus-summary-save-process-mark)
5603   (gnus-summary-unmark-all-processable))
5604
5605 (defun gnus-summary-yank-process-mark ()
5606   "Pop the last process mark state off the stack and restore it."
5607   (interactive)
5608   (unless gnus-newsgroup-process-stack
5609     (error "Empty mark stack"))
5610   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5611
5612 (defun gnus-summary-process-mark-set (set)
5613   "Make SET into the current process marked articles."
5614   (gnus-summary-unmark-all-processable)
5615   (while set
5616     (gnus-summary-set-process-mark (pop set))))
5617
5618 ;;; Searching and stuff
5619
5620 (defun gnus-summary-search-group (&optional backward use-level)
5621   "Search for next unread newsgroup.
5622 If optional argument BACKWARD is non-nil, search backward instead."
5623   (save-excursion
5624     (set-buffer gnus-group-buffer)
5625     (when (gnus-group-search-forward
5626            backward nil (if use-level (gnus-group-group-level) nil))
5627       (gnus-group-group-name))))
5628
5629 (defun gnus-summary-best-group (&optional exclude-group)
5630   "Find the name of the best unread group.
5631 If EXCLUDE-GROUP, do not go to this group."
5632   (save-excursion
5633     (set-buffer gnus-group-buffer)
5634     (save-excursion
5635       (gnus-group-best-unread-group exclude-group))))
5636
5637 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5638   (if backward (gnus-summary-find-prev)
5639     (let* ((dummy (gnus-summary-article-intangible-p))
5640            (article (or article (gnus-summary-article-number)))
5641            (arts (gnus-data-find-list article))
5642            result)
5643       (when (and (not dummy)
5644                  (or (not gnus-summary-check-current)
5645                      (not unread)
5646                      (not (gnus-data-unread-p (car arts)))))
5647         (setq arts (cdr arts)))
5648       (when (setq result
5649                   (if unread
5650                       (progn
5651                         (while arts
5652                           (when (or (and undownloaded
5653                                          (eq gnus-undownloaded-mark
5654                                              (gnus-data-mark (car arts))))
5655                                     (gnus-data-unread-p (car arts)))
5656                             (setq result (car arts)
5657                                   arts nil))
5658                           (setq arts (cdr arts)))
5659                         result)
5660                     (car arts)))
5661         (goto-char (gnus-data-pos result))
5662         (gnus-data-number result)))))
5663
5664 (defun gnus-summary-find-prev (&optional unread article)
5665   (let* ((eobp (eobp))
5666          (article (or article (gnus-summary-article-number)))
5667          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5668          result)
5669     (when (and (not eobp)
5670                (or (not gnus-summary-check-current)
5671                    (not unread)
5672                    (not (gnus-data-unread-p (car arts)))))
5673       (setq arts (cdr arts)))
5674     (when (setq result
5675                 (if unread
5676                     (progn
5677                       (while arts
5678                         (when (gnus-data-unread-p (car arts))
5679                           (setq result (car arts)
5680                                 arts nil))
5681                         (setq arts (cdr arts)))
5682                       result)
5683                   (car arts)))
5684       (goto-char (gnus-data-pos result))
5685       (gnus-data-number result))))
5686
5687 (defun gnus-summary-find-subject (subject &optional unread backward article)
5688   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5689          (article (or article (gnus-summary-article-number)))
5690          (articles (gnus-data-list backward))
5691          (arts (gnus-data-find-list article articles))
5692          result)
5693     (when (or (not gnus-summary-check-current)
5694               (not unread)
5695               (not (gnus-data-unread-p (car arts))))
5696       (setq arts (cdr arts)))
5697     (while arts
5698       (and (or (not unread)
5699                (gnus-data-unread-p (car arts)))
5700            (vectorp (gnus-data-header (car arts)))
5701            (gnus-subject-equal
5702             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5703            (setq result (car arts)
5704                  arts nil))
5705       (setq arts (cdr arts)))
5706     (and result
5707          (goto-char (gnus-data-pos result))
5708          (gnus-data-number result))))
5709
5710 (defun gnus-summary-search-forward (&optional unread subject backward)
5711   "Search forward for an article.
5712 If UNREAD, look for unread articles.  If SUBJECT, look for
5713 articles with that subject.  If BACKWARD, search backward instead."
5714   (cond (subject (gnus-summary-find-subject subject unread backward))
5715         (backward (gnus-summary-find-prev unread))
5716         (t (gnus-summary-find-next unread))))
5717
5718 (defun gnus-recenter (&optional n)
5719   "Center point in window and redisplay frame.
5720 Also do horizontal recentering."
5721   (interactive "P")
5722   (when (and gnus-auto-center-summary
5723              (not (eq gnus-auto-center-summary 'vertical)))
5724     (gnus-horizontal-recenter))
5725   (recenter n))
5726
5727 (defun gnus-summary-recenter ()
5728   "Center point in the summary window.
5729 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5730 displayed, no centering will be performed."
5731   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5732 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5733   (interactive)
5734   (let* ((top (cond ((< (window-height) 4) 0)
5735                     ((< (window-height) 7) 1)
5736                     (t (if (numberp gnus-auto-center-summary)
5737                            gnus-auto-center-summary
5738                          2))))
5739          (height (1- (window-height)))
5740          (bottom (save-excursion (goto-char (point-max))
5741                                  (forward-line (- height))
5742                                  (point)))
5743          (window (get-buffer-window (current-buffer))))
5744     ;; The user has to want it.
5745     (when gnus-auto-center-summary
5746       (when (get-buffer-window gnus-article-buffer)
5747         ;; Only do recentering when the article buffer is displayed,
5748       ;; Set the window start to either `bottom', which is the biggest
5749         ;; possible valid number, or the second line from the top,
5750         ;; whichever is the least.
5751         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5752           (if (> bottom top-pos)
5753               ;; Keep the second line from the top visible
5754               (set-window-start window top-pos t)
5755             ;; Try to keep the bottom line visible; if it's partially
5756             ;; obscured, either scroll one more line to make it fully
5757             ;; visible, or revert to using TOP-POS.
5758             (save-excursion
5759               (goto-char (point-max))
5760               (forward-line -1)
5761               (let ((last-line-start (point)))
5762                 (goto-char bottom)
5763                 (set-window-start window (point) t)
5764                 (when (not (pos-visible-in-window-p last-line-start window))
5765                   (forward-line 1)
5766                   (set-window-start window (min (point) top-pos) t)))))))
5767       ;; Do horizontal recentering while we're at it.
5768       (when (and (get-buffer-window (current-buffer) t)
5769                  (not (eq gnus-auto-center-summary 'vertical)))
5770         (let ((selected (selected-window)))
5771           (select-window (get-buffer-window (current-buffer) t))
5772           (gnus-summary-position-point)
5773           (gnus-horizontal-recenter)
5774           (select-window selected))))))
5775
5776 (defun gnus-summary-jump-to-group (newsgroup)
5777   "Move point to NEWSGROUP in group mode buffer."
5778   ;; Keep update point of group mode buffer if visible.
5779   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5780       (save-window-excursion
5781         ;; Take care of tree window mode.
5782         (when (get-buffer-window gnus-group-buffer)
5783           (pop-to-buffer gnus-group-buffer))
5784         (gnus-group-jump-to-group newsgroup))
5785     (save-excursion
5786       ;; Take care of tree window mode.
5787       (if (get-buffer-window gnus-group-buffer)
5788           (pop-to-buffer gnus-group-buffer)
5789         (set-buffer gnus-group-buffer))
5790       (gnus-group-jump-to-group newsgroup))))
5791
5792 ;; This function returns a list of article numbers based on the
5793 ;; difference between the ranges of read articles in this group and
5794 ;; the range of active articles.
5795 (defun gnus-list-of-unread-articles (group)
5796   (let* ((read (gnus-info-read (gnus-get-info group)))
5797          (active (or (gnus-active group) (gnus-activate-group group)))
5798          (last (cdr active))
5799          first nlast unread)
5800     ;; If none are read, then all are unread.
5801     (if (not read)
5802         (setq first (car active))
5803       ;; If the range of read articles is a single range, then the
5804       ;; first unread article is the article after the last read
5805       ;; article.  Sounds logical, doesn't it?
5806       (if (and (not (listp (cdr read)))
5807                (or (< (car read) (car active))
5808                    (progn (setq read (list read))
5809                           nil)))
5810           (setq first (max (car active) (1+ (cdr read))))
5811         ;; `read' is a list of ranges.
5812         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5813                                   (caar read)))
5814                   1)
5815           (setq first (car active)))
5816         (while read
5817           (when first
5818             (while (< first nlast)
5819               (push first unread)
5820               (setq first (1+ first))))
5821           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5822           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5823           (setq read (cdr read)))))
5824     ;; And add the last unread articles.
5825     (while (<= first last)
5826       (push first unread)
5827       (setq first (1+ first)))
5828     ;; Return the list of unread articles.
5829     (delq 0 (nreverse unread))))
5830
5831 (defun gnus-list-of-read-articles (group)
5832   "Return a list of unread, unticked and non-dormant articles."
5833   (let* ((info (gnus-get-info group))
5834          (marked (gnus-info-marks info))
5835          (active (gnus-active group)))
5836     (and info active
5837          (gnus-set-difference
5838           (gnus-sorted-complement
5839            (gnus-uncompress-range active)
5840            (gnus-list-of-unread-articles group))
5841           (append
5842            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5843            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5844
5845 ;; Various summary commands
5846
5847 (defun gnus-summary-select-article-buffer ()
5848   "Reconfigure windows to show article buffer."
5849   (interactive)
5850   (if (not (gnus-buffer-live-p gnus-article-buffer))
5851       (error "There is no article buffer for this summary buffer")
5852     (gnus-configure-windows 'article)
5853     (select-window (get-buffer-window gnus-article-buffer))))
5854
5855 (defun gnus-summary-universal-argument (arg)
5856   "Perform any operation on all articles that are process/prefixed."
5857   (interactive "P")
5858   (let ((articles (gnus-summary-work-articles arg))
5859         func article)
5860     (if (eq
5861          (setq
5862           func
5863           (key-binding
5864            (read-key-sequence
5865             (substitute-command-keys
5866              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5867          'undefined)
5868         (gnus-error 1 "Undefined key")
5869       (save-excursion
5870         (while articles
5871           (gnus-summary-goto-subject (setq article (pop articles)))
5872           (let (gnus-newsgroup-processable)
5873             (command-execute func))
5874           (gnus-summary-remove-process-mark article)))))
5875   (gnus-summary-position-point))
5876
5877 (defun gnus-summary-toggle-truncation (&optional arg)
5878   "Toggle truncation of summary lines.
5879 With arg, turn line truncation on iff arg is positive."
5880   (interactive "P")
5881   (setq truncate-lines
5882         (if (null arg) (not truncate-lines)
5883           (> (prefix-numeric-value arg) 0)))
5884   (redraw-display))
5885
5886 (defun gnus-summary-reselect-current-group (&optional all rescan)
5887   "Exit and then reselect the current newsgroup.
5888 The prefix argument ALL means to select all articles."
5889   (interactive "P")
5890   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5891     (error "Ephemeral groups can't be reselected"))
5892   (let ((current-subject (gnus-summary-article-number))
5893         (group gnus-newsgroup-name))
5894     (setq gnus-newsgroup-begin nil)
5895     (gnus-summary-exit)
5896     ;; We have to adjust the point of group mode buffer because
5897     ;; point was moved to the next unread newsgroup by exiting.
5898     (gnus-summary-jump-to-group group)
5899     (when rescan
5900       (save-excursion
5901         (gnus-group-get-new-news-this-group 1)))
5902     (gnus-group-read-group all t)
5903     (gnus-summary-goto-subject current-subject nil t)))
5904
5905 (defun gnus-summary-rescan-group (&optional all)
5906   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5907   (interactive "P")
5908   (gnus-summary-reselect-current-group all t))
5909
5910 (defun gnus-summary-update-info (&optional non-destructive)
5911   (save-excursion
5912     (let ((group gnus-newsgroup-name))
5913       (when group
5914         (when gnus-newsgroup-kill-headers
5915           (setq gnus-newsgroup-killed
5916                 (gnus-compress-sequence
5917                  (nconc
5918                   (gnus-set-sorted-intersection
5919                    (gnus-uncompress-range gnus-newsgroup-killed)
5920                    (setq gnus-newsgroup-unselected
5921                          (sort gnus-newsgroup-unselected '<)))
5922                   (setq gnus-newsgroup-unreads
5923                         (sort gnus-newsgroup-unreads '<)))
5924                  t)))
5925         (unless (listp (cdr gnus-newsgroup-killed))
5926           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5927         (let ((headers gnus-newsgroup-headers))
5928           ;; Set the new ranges of read articles.
5929           (save-excursion
5930             (set-buffer gnus-group-buffer)
5931             (gnus-undo-force-boundary))
5932           (gnus-update-read-articles
5933            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5934           ;; Set the current article marks.
5935           (let ((gnus-newsgroup-scored
5936                  (if (and (not gnus-save-score)
5937                           (not non-destructive))
5938                      nil
5939                    gnus-newsgroup-scored)))
5940             (save-excursion
5941               (gnus-update-marks)))
5942           ;; Do the cross-ref thing.
5943           (when gnus-use-cross-reference
5944             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5945           ;; Do not switch windows but change the buffer to work.
5946           (set-buffer gnus-group-buffer)
5947           (unless (gnus-ephemeral-group-p group)
5948             (gnus-group-update-group group)))))))
5949
5950 (defun gnus-summary-save-newsrc (&optional force)
5951   "Save the current number of read/marked articles in the dribble buffer.
5952 The dribble buffer will then be saved.
5953 If FORCE (the prefix), also save the .newsrc file(s)."
5954   (interactive "P")
5955   (gnus-summary-update-info t)
5956   (if force
5957       (gnus-save-newsrc-file)
5958     (gnus-dribble-save)))
5959
5960 (defun gnus-summary-exit (&optional temporary)
5961   "Exit reading current newsgroup, and then return to group selection mode.
5962 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5963   (interactive)
5964   (gnus-set-global-variables)
5965   (when (gnus-buffer-live-p gnus-article-buffer)
5966     (save-excursion
5967       (set-buffer gnus-article-buffer)
5968       (mm-destroy-parts gnus-article-mime-handles)
5969       ;; Set it to nil for safety reason.
5970       (setq gnus-article-mime-handle-alist nil)
5971       (setq gnus-article-mime-handles nil)))
5972   (gnus-kill-save-kill-buffer)
5973   (gnus-async-halt-prefetch)
5974   (let* ((group gnus-newsgroup-name)
5975          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5976          (mode major-mode)
5977          (group-point nil)
5978          (buf (current-buffer)))
5979     (unless quit-config
5980       ;; Do adaptive scoring, and possibly save score files.
5981       (when gnus-newsgroup-adaptive
5982         (gnus-score-adaptive))
5983       (when gnus-use-scoring
5984         (gnus-score-save)))
5985     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5986     ;; If we have several article buffers, we kill them at exit.
5987     (unless gnus-single-article-buffer
5988       (gnus-kill-buffer gnus-original-article-buffer)
5989       (setq gnus-article-current nil))
5990     (when gnus-use-cache
5991       (gnus-cache-possibly-remove-articles)
5992       (gnus-cache-save-buffers))
5993     (gnus-async-prefetch-remove-group group)
5994     (when gnus-suppress-duplicates
5995       (gnus-dup-enter-articles))
5996     (when gnus-use-trees
5997       (gnus-tree-close group))
5998     (when gnus-use-cache
5999       (gnus-cache-write-active))
6000     ;; Remove entries for this group.
6001     (nnmail-purge-split-history (gnus-group-real-name group))
6002     ;; Make all changes in this group permanent.
6003     (unless quit-config
6004       (gnus-run-hooks 'gnus-exit-group-hook)
6005       (gnus-summary-update-info))
6006     (gnus-close-group group)
6007     ;; Make sure where we were, and go to next newsgroup.
6008     (set-buffer gnus-group-buffer)
6009     (unless quit-config
6010       (gnus-group-jump-to-group group))
6011     (gnus-run-hooks 'gnus-summary-exit-hook)
6012     (unless (or quit-config
6013                 ;; If this group has disappeared from the summary
6014                 ;; buffer, don't skip forwards.
6015                 (not (string= group (gnus-group-group-name))))
6016       (gnus-group-next-unread-group 1))
6017     (setq group-point (point))
6018     (if temporary
6019         nil                             ;Nothing to do.
6020       ;; If we have several article buffers, we kill them at exit.
6021       (unless gnus-single-article-buffer
6022         (gnus-kill-buffer gnus-article-buffer)
6023         (gnus-kill-buffer gnus-original-article-buffer)
6024         (setq gnus-article-current nil))
6025       (set-buffer buf)
6026       (if (not gnus-kill-summary-on-exit)
6027           (progn
6028             (gnus-deaden-summary)
6029             (setq mode nil))
6030        ;; We set all buffer-local variables to nil.  It is unclear why
6031         ;; this is needed, but if we don't, buffer-local variables are
6032         ;; not garbage-collected, it seems.  This would the lead to en
6033         ;; ever-growing Emacs.
6034         (gnus-summary-clear-local-variables)
6035         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6036           (gnus-summary-clear-local-variables))
6037         (when (get-buffer gnus-article-buffer)
6038           (bury-buffer gnus-article-buffer))
6039         ;; We clear the global counterparts of the buffer-local
6040         ;; variables as well, just to be on the safe side.
6041         (set-buffer gnus-group-buffer)
6042         (gnus-summary-clear-local-variables)
6043         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6044           (gnus-summary-clear-local-variables)))
6045       (setq gnus-current-select-method gnus-select-method)
6046       (pop-to-buffer gnus-group-buffer)
6047       (if (not quit-config)
6048           (progn
6049             (goto-char group-point)
6050             (gnus-configure-windows 'group 'force))
6051         (gnus-handle-ephemeral-exit quit-config))
6052       ;; Return to group mode buffer.
6053       (when (eq mode 'gnus-summary-mode)
6054         (gnus-kill-buffer buf))
6055       ;; Clear the current group name.
6056       (unless quit-config
6057         (setq gnus-newsgroup-name nil)))))
6058
6059 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6060 (defun gnus-summary-exit-no-update (&optional no-questions)
6061   "Quit reading current newsgroup without updating read article info."
6062   (interactive)
6063   (let* ((group gnus-newsgroup-name)
6064          (quit-config (gnus-group-quit-config group)))
6065     (when (or no-questions
6066               gnus-expert-user
6067               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6068       (gnus-async-halt-prefetch)
6069       (mapcar 'funcall
6070               (delq 'gnus-summary-expire-articles
6071                     (copy-sequence gnus-summary-prepare-exit-hook)))
6072       (when (gnus-buffer-live-p gnus-article-buffer)
6073         (save-excursion
6074           (set-buffer gnus-article-buffer)
6075           (mm-destroy-parts gnus-article-mime-handles)
6076           ;; Set it to nil for safety reason.
6077           (setq gnus-article-mime-handle-alist nil)
6078           (setq gnus-article-mime-handles nil)))
6079       ;; If we have several article buffers, we kill them at exit.
6080       (unless gnus-single-article-buffer
6081         (gnus-kill-buffer gnus-article-buffer)
6082         (gnus-kill-buffer gnus-original-article-buffer)
6083         (setq gnus-article-current nil))
6084       (if (not gnus-kill-summary-on-exit)
6085           (gnus-deaden-summary)
6086         (gnus-close-group group)
6087         (gnus-summary-clear-local-variables)
6088         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6089           (gnus-summary-clear-local-variables))
6090         (set-buffer gnus-group-buffer)
6091         (gnus-summary-clear-local-variables)
6092         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6093           (gnus-summary-clear-local-variables))
6094         (when (get-buffer gnus-summary-buffer)
6095           (kill-buffer gnus-summary-buffer)))
6096       (unless gnus-single-article-buffer
6097         (setq gnus-article-current nil))
6098       (when gnus-use-trees
6099         (gnus-tree-close group))
6100       (gnus-async-prefetch-remove-group group)
6101       (when (get-buffer gnus-article-buffer)
6102         (bury-buffer gnus-article-buffer))
6103       ;; Return to the group buffer.
6104       (gnus-configure-windows 'group 'force)
6105       ;; Clear the current group name.
6106       (setq gnus-newsgroup-name nil)
6107       (when (equal (gnus-group-group-name) group)
6108         (gnus-group-next-unread-group 1))
6109       (when quit-config
6110         (gnus-handle-ephemeral-exit quit-config)))))
6111
6112 (defun gnus-handle-ephemeral-exit (quit-config)
6113   "Handle movement when leaving an ephemeral group.
6114 The state which existed when entering the ephemeral is reset."
6115   (if (not (buffer-name (car quit-config)))
6116       (gnus-configure-windows 'group 'force)
6117     (set-buffer (car quit-config))
6118     (cond ((eq major-mode 'gnus-summary-mode)
6119            (gnus-set-global-variables))
6120           ((eq major-mode 'gnus-article-mode)
6121            (save-excursion
6122              ;; The `gnus-summary-buffer' variable may point
6123              ;; to the old summary buffer when using a single
6124              ;; article buffer.
6125              (unless (gnus-buffer-live-p gnus-summary-buffer)
6126                (set-buffer gnus-group-buffer))
6127              (set-buffer gnus-summary-buffer)
6128              (gnus-set-global-variables))))
6129     (if (or (eq (cdr quit-config) 'article)
6130             (eq (cdr quit-config) 'pick))
6131         (progn
6132           ;; The current article may be from the ephemeral group
6133           ;; thus it is best that we reload this article
6134           (gnus-summary-show-article)
6135           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6136               (gnus-configure-windows 'pick 'force)
6137             (gnus-configure-windows (cdr quit-config) 'force)))
6138       (gnus-configure-windows (cdr quit-config) 'force))
6139     (when (eq major-mode 'gnus-summary-mode)
6140       (gnus-summary-next-subject 1 nil t)
6141       (gnus-summary-recenter)
6142       (gnus-summary-position-point))))
6143
6144 ;;; Dead summaries.
6145
6146 (defvar gnus-dead-summary-mode-map nil)
6147
6148 (unless gnus-dead-summary-mode-map
6149   (setq gnus-dead-summary-mode-map (make-keymap))
6150   (suppress-keymap gnus-dead-summary-mode-map)
6151   (substitute-key-definition
6152    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6153   (let ((keys '("\C-d" "\r" "\177" [delete])))
6154     (while keys
6155       (define-key gnus-dead-summary-mode-map
6156         (pop keys) 'gnus-summary-wake-up-the-dead))))
6157
6158 (defvar gnus-dead-summary-mode nil
6159   "Minor mode for Gnus summary buffers.")
6160
6161 (defun gnus-dead-summary-mode (&optional arg)
6162   "Minor mode for Gnus summary buffers."
6163   (interactive "P")
6164   (when (eq major-mode 'gnus-summary-mode)
6165     (make-local-variable 'gnus-dead-summary-mode)
6166     (setq gnus-dead-summary-mode
6167           (if (null arg) (not gnus-dead-summary-mode)
6168             (> (prefix-numeric-value arg) 0)))
6169     (when gnus-dead-summary-mode
6170       (gnus-add-minor-mode
6171        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6172
6173 (defun gnus-deaden-summary ()
6174   "Make the current summary buffer into a dead summary buffer."
6175   ;; Kill any previous dead summary buffer.
6176   (when (and gnus-dead-summary
6177              (buffer-name gnus-dead-summary))
6178     (save-excursion
6179       (set-buffer gnus-dead-summary)
6180       (when gnus-dead-summary-mode
6181         (kill-buffer (current-buffer)))))
6182   ;; Make this the current dead summary.
6183   (setq gnus-dead-summary (current-buffer))
6184   (gnus-dead-summary-mode 1)
6185   (let ((name (buffer-name)))
6186     (when (string-match "Summary" name)
6187       (rename-buffer
6188        (concat (substring name 0 (match-beginning 0)) "Dead "
6189                (substring name (match-beginning 0)))
6190        t)
6191       (bury-buffer))))
6192
6193 (defun gnus-kill-or-deaden-summary (buffer)
6194   "Kill or deaden the summary BUFFER."
6195   (save-excursion
6196     (when (and (buffer-name buffer)
6197                (not gnus-single-article-buffer))
6198       (save-excursion
6199         (set-buffer buffer)
6200         (gnus-kill-buffer gnus-article-buffer)
6201         (gnus-kill-buffer gnus-original-article-buffer)))
6202     (cond (gnus-kill-summary-on-exit
6203            (when (and gnus-use-trees
6204                       (gnus-buffer-exists-p buffer))
6205              (save-excursion
6206                (set-buffer buffer)
6207                (gnus-tree-close gnus-newsgroup-name)))
6208            (gnus-kill-buffer buffer))
6209           ((gnus-buffer-exists-p buffer)
6210            (save-excursion
6211              (set-buffer buffer)
6212              (gnus-deaden-summary))))))
6213
6214 (defun gnus-summary-wake-up-the-dead (&rest args)
6215   "Wake up the dead summary buffer."
6216   (interactive)
6217   (gnus-dead-summary-mode -1)
6218   (let ((name (buffer-name)))
6219     (when (string-match "Dead " name)
6220       (rename-buffer
6221        (concat (substring name 0 (match-beginning 0))
6222                (substring name (match-end 0)))
6223        t)))
6224   (gnus-message 3 "This dead summary is now alive again"))
6225
6226 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6227 (defun gnus-summary-fetch-faq (&optional faq-dir)
6228   "Fetch the FAQ for the current group.
6229 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6230 in."
6231   (interactive
6232    (list
6233     (when current-prefix-arg
6234       (completing-read
6235        "Faq dir: " (and (listp gnus-group-faq-directory)
6236                         (mapcar (lambda (file) (list file))
6237                                 gnus-group-faq-directory))))))
6238   (let (gnus-faq-buffer)
6239     (when (setq gnus-faq-buffer
6240                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6241       (gnus-configure-windows 'summary-faq))))
6242
6243 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6244 (defun gnus-summary-describe-group (&optional force)
6245   "Describe the current newsgroup."
6246   (interactive "P")
6247   (gnus-group-describe-group force gnus-newsgroup-name))
6248
6249 (defun gnus-summary-describe-briefly ()
6250   "Describe summary mode commands briefly."
6251   (interactive)
6252   (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")))
6253
6254 ;; Walking around group mode buffer from summary mode.
6255
6256 (defun gnus-summary-next-group (&optional no-article target-group backward)
6257   "Exit current newsgroup and then select next unread newsgroup.
6258 If prefix argument NO-ARTICLE is non-nil, no article is selected
6259 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6260 previous group instead."
6261   (interactive "P")
6262   ;; Stop pre-fetching.
6263   (gnus-async-halt-prefetch)
6264   (let ((current-group gnus-newsgroup-name)
6265         (current-buffer (current-buffer))
6266         entered)
6267    ;; First we semi-exit this group to update Xrefs and all variables.
6268     ;; We can't do a real exit, because the window conf must remain
6269     ;; the same in case the user is prompted for info, and we don't
6270     ;; want the window conf to change before that...
6271     (gnus-summary-exit t)
6272     (while (not entered)
6273       ;; Then we find what group we are supposed to enter.
6274       (set-buffer gnus-group-buffer)
6275       (gnus-group-jump-to-group current-group)
6276       (setq target-group
6277             (or target-group
6278                 (if (eq gnus-keep-same-level 'best)
6279                     (gnus-summary-best-group gnus-newsgroup-name)
6280                   (gnus-summary-search-group backward gnus-keep-same-level))))
6281       (if (not target-group)
6282           ;; There are no further groups, so we return to the group
6283           ;; buffer.
6284           (progn
6285             (gnus-message 5 "Returning to the group buffer")
6286             (setq entered t)
6287             (when (gnus-buffer-live-p current-buffer)
6288               (set-buffer current-buffer)
6289               (gnus-summary-exit))
6290             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6291         ;; We try to enter the target group.
6292         (gnus-group-jump-to-group target-group)
6293         (let ((unreads (gnus-group-group-unread)))
6294           (if (and (or (eq t unreads)
6295                        (and unreads (not (zerop unreads))))
6296                    (gnus-summary-read-group
6297                     target-group nil no-article
6298                     (and (buffer-name current-buffer) current-buffer)
6299                     nil backward))
6300               (setq entered t)
6301             (setq current-group target-group
6302                   target-group nil)))))))
6303
6304 (defun gnus-summary-prev-group (&optional no-article)
6305   "Exit current newsgroup and then select previous unread newsgroup.
6306 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6307   (interactive "P")
6308   (gnus-summary-next-group no-article nil t))
6309
6310 ;; Walking around summary lines.
6311
6312 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6313   "Go to the first unread subject.
6314 If UNREAD is non-nil, go to the first unread article.
6315 Returns the article selected or nil if there are no unread articles."
6316   (interactive "P")
6317   (prog1
6318       (cond
6319        ;; Empty summary.
6320        ((null gnus-newsgroup-data)
6321         (gnus-message 3 "No articles in the group")
6322         nil)
6323        ;; Pick the first article.
6324        ((not unread)
6325         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6326         (gnus-data-number (car gnus-newsgroup-data)))
6327        ;; No unread articles.
6328        ((null gnus-newsgroup-unreads)
6329         (gnus-message 3 "No more unread articles")
6330         nil)
6331        ;; Find the first unread article.
6332        (t
6333         (let ((data gnus-newsgroup-data))
6334           (while (and data
6335                       (and (not (and undownloaded
6336                                      (eq gnus-undownloaded-mark
6337                                          (gnus-data-mark (car data)))))
6338                            (not (and unseen
6339                                      (memq (car data) gnus-newsgroup-unseen)))
6340                            (not (gnus-data-unread-p (car data)))))
6341             (setq data (cdr data)))
6342           (when data
6343             (goto-char (gnus-data-pos (car data)))
6344             (gnus-data-number (car data))))))
6345     (gnus-summary-position-point)))
6346
6347 (defun gnus-summary-next-subject (n &optional unread dont-display)
6348   "Go to next N'th summary line.
6349 If N is negative, go to the previous N'th subject line.
6350 If UNREAD is non-nil, only unread articles are selected.
6351 The difference between N and the actual number of steps taken is
6352 returned."
6353   (interactive "p")
6354   (let ((backward (< n 0))
6355         (n (abs n)))
6356     (while (and (> n 0)
6357                 (if backward
6358                     (gnus-summary-find-prev unread)
6359                   (gnus-summary-find-next unread)))
6360       (unless (zerop (setq n (1- n)))
6361         (gnus-summary-show-thread)))
6362     (when (/= 0 n)
6363       (gnus-message 7 "No more%s articles"
6364                     (if unread " unread" "")))
6365     (unless dont-display
6366       (gnus-summary-recenter)
6367       (gnus-summary-position-point))
6368     n))
6369
6370 (defun gnus-summary-next-unread-subject (n)
6371   "Go to next N'th unread summary line."
6372   (interactive "p")
6373   (gnus-summary-next-subject n t))
6374
6375 (defun gnus-summary-prev-subject (n &optional unread)
6376   "Go to previous N'th summary line.
6377 If optional argument UNREAD is non-nil, only unread article is selected."
6378   (interactive "p")
6379   (gnus-summary-next-subject (- n) unread))
6380
6381 (defun gnus-summary-prev-unread-subject (n)
6382   "Go to previous N'th unread summary line."
6383   (interactive "p")
6384   (gnus-summary-next-subject (- n) t))
6385
6386 (defun gnus-summary-goto-subject (article &optional force silent)
6387   "Go the subject line of ARTICLE.
6388 If FORCE, also allow jumping to articles not currently shown."
6389   (interactive "nArticle number: ")
6390   (let ((b (point))
6391         (data (gnus-data-find article)))
6392     ;; We read in the article if we have to.
6393     (and (not data)
6394          force
6395          (gnus-summary-insert-subject
6396           article
6397           (if (or (numberp force) (vectorp force)) force)
6398           t)
6399          (setq data (gnus-data-find article)))
6400     (goto-char b)
6401     (if (not data)
6402         (progn
6403           (unless silent
6404             (gnus-message 3 "Can't find article %d" article))
6405           nil)
6406       (let ((pt (gnus-data-pos data)))
6407         (goto-char pt)
6408         (gnus-summary-set-article-display-arrow pt))
6409       (gnus-summary-position-point)
6410       article)))
6411
6412 ;; Walking around summary lines with displaying articles.
6413
6414 (defun gnus-summary-expand-window (&optional arg)
6415   "Make the summary buffer take up the entire Emacs frame.
6416 Given a prefix, will force an `article' buffer configuration."
6417   (interactive "P")
6418   (if arg
6419       (gnus-configure-windows 'article 'force)
6420     (gnus-configure-windows 'summary 'force)))
6421
6422 (defun gnus-summary-display-article (article &optional all-header)
6423   "Display ARTICLE in article buffer."
6424   (when (gnus-buffer-live-p gnus-article-buffer)
6425     (with-current-buffer gnus-article-buffer
6426       (mm-enable-multibyte-mule4)))
6427   (gnus-set-global-variables)
6428   (when (gnus-buffer-live-p gnus-article-buffer)
6429     (with-current-buffer gnus-article-buffer
6430       (setq gnus-article-charset gnus-newsgroup-charset)
6431       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6432       (mm-enable-multibyte-mule4)))
6433   (if (null article)
6434       nil
6435     (prog1
6436         (if gnus-summary-display-article-function
6437             (funcall gnus-summary-display-article-function article all-header)
6438           (gnus-article-prepare article all-header))
6439       (gnus-run-hooks 'gnus-select-article-hook)
6440       (when (and gnus-current-article
6441                  (not (zerop gnus-current-article)))
6442         (gnus-summary-goto-subject gnus-current-article))
6443       (gnus-summary-recenter)
6444       (when (and gnus-use-trees gnus-show-threads)
6445         (gnus-possibly-generate-tree article)
6446         (gnus-highlight-selected-tree article))
6447       ;; Successfully display article.
6448       (gnus-article-set-window-start
6449        (cdr (assq article gnus-newsgroup-bookmarks))))))
6450
6451 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6452   "Select the current article.
6453 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6454 non-nil, the article will be re-fetched even if it already present in
6455 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6456 be displayed."
6457   ;; Make sure we are in the summary buffer to work around bbdb bug.
6458   (unless (eq major-mode 'gnus-summary-mode)
6459     (set-buffer gnus-summary-buffer))
6460   (let ((article (or article (gnus-summary-article-number)))
6461         (all-headers (not (not all-headers))) ;Must be t or nil.
6462         gnus-summary-display-article-function)
6463     (and (not pseudo)
6464          (gnus-summary-article-pseudo-p article)
6465          (error "This is a pseudo-article"))
6466     (save-excursion
6467       (set-buffer gnus-summary-buffer)
6468       (if (or (and gnus-single-article-buffer
6469                    (or (null gnus-current-article)
6470                        (null gnus-article-current)
6471                        (null (get-buffer gnus-article-buffer))
6472                        (not (eq article (cdr gnus-article-current)))
6473                        (not (equal (car gnus-article-current)
6474                                    gnus-newsgroup-name))))
6475               (and (not gnus-single-article-buffer)
6476                    (or (null gnus-current-article)
6477                        (not (eq gnus-current-article article))))
6478               force)
6479        ;; The requested article is different from the current article.
6480           (progn
6481             (gnus-summary-display-article article all-headers)
6482             (when (gnus-buffer-live-p gnus-article-buffer)
6483               (with-current-buffer gnus-article-buffer
6484                 (if (not gnus-article-decoded-p) ;; a local variable
6485                     (mm-disable-multibyte-mule4))))
6486             (when (or all-headers gnus-show-all-headers)
6487               (gnus-article-show-all-headers))
6488             (gnus-article-set-window-start
6489              (cdr (assq article gnus-newsgroup-bookmarks)))
6490             article)
6491         (when (or all-headers gnus-show-all-headers)
6492           (gnus-article-show-all-headers))
6493         'old))))
6494
6495 (defun gnus-summary-force-verify-and-decrypt ()
6496   (interactive)
6497   (let ((mm-verify-option 'known)
6498         (mm-decrypt-option 'known))
6499     (gnus-summary-select-article nil 'force)))
6500
6501 (defun gnus-summary-set-current-mark (&optional current-mark)
6502   "Obsolete function."
6503   nil)
6504
6505 (defun gnus-summary-next-article (&optional unread subject backward push)
6506   "Select the next article.
6507 If UNREAD, only unread articles are selected.
6508 If SUBJECT, only articles with SUBJECT are selected.
6509 If BACKWARD, the previous article is selected instead of the next."
6510   (interactive "P")
6511   (cond
6512    ;; Is there such an article?
6513    ((and (gnus-summary-search-forward unread subject backward)
6514          (or (gnus-summary-display-article (gnus-summary-article-number))
6515              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6516     (gnus-summary-position-point))
6517    ;; If not, we try the first unread, if that is wanted.
6518    ((and subject
6519          gnus-auto-select-same
6520          (gnus-summary-first-unread-article))
6521     (gnus-summary-position-point)
6522     (gnus-message 6 "Wrapped"))
6523    ;; Try to get next/previous article not displayed in this group.
6524    ((and gnus-auto-extend-newsgroup
6525          (not unread) (not subject))
6526     (gnus-summary-goto-article
6527      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6528      nil (count-lines (point-min) (point))))
6529    ;; Go to next/previous group.
6530    (t
6531     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6532       (gnus-summary-jump-to-group gnus-newsgroup-name))
6533     (let ((cmd last-command-char)
6534           (point
6535            (save-excursion
6536              (set-buffer gnus-group-buffer)
6537              (point)))
6538           (group
6539            (if (eq gnus-keep-same-level 'best)
6540                (gnus-summary-best-group gnus-newsgroup-name)
6541              (gnus-summary-search-group backward gnus-keep-same-level))))
6542       ;; For some reason, the group window gets selected.  We change
6543       ;; it back.
6544       (select-window (get-buffer-window (current-buffer)))
6545       ;; Select next unread newsgroup automagically.
6546       (cond
6547        ((or (not gnus-auto-select-next)
6548             (not cmd))
6549         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6550        ((or (eq gnus-auto-select-next 'quietly)
6551             (and (eq gnus-auto-select-next 'slightly-quietly)
6552                  push)
6553             (and (eq gnus-auto-select-next 'almost-quietly)
6554                  (gnus-summary-last-article-p)))
6555         ;; Select quietly.
6556         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6557             (gnus-summary-exit)
6558           (gnus-message 7 "No more%s articles (%s)..."
6559                         (if unread " unread" "")
6560                         (if group (concat "selecting " group)
6561                           "exiting"))
6562           (gnus-summary-next-group nil group backward)))
6563        (t
6564         (when (gnus-key-press-event-p last-input-event)
6565           (gnus-summary-walk-group-buffer
6566            gnus-newsgroup-name cmd unread backward point))))))))
6567
6568 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6569   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6570                       (?\C-p (gnus-group-prev-unread-group 1))))
6571         (cursor-in-echo-area t)
6572         keve key group ended)
6573     (save-excursion
6574       (set-buffer gnus-group-buffer)
6575       (goto-char start)
6576       (setq group
6577             (if (eq gnus-keep-same-level 'best)
6578                 (gnus-summary-best-group gnus-newsgroup-name)
6579               (gnus-summary-search-group backward gnus-keep-same-level))))
6580     (while (not ended)
6581       (gnus-message
6582        5 "No more%s articles%s" (if unread " unread" "")
6583        (if (and group
6584                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6585            (format " (Type %s for %s [%s])"
6586                    (single-key-description cmd) group
6587                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6588          (format " (Type %s to exit %s)"
6589                  (single-key-description cmd)
6590                  gnus-newsgroup-name)))
6591       ;; Confirm auto selection.
6592       (setq key (car (setq keve (gnus-read-event-char))))
6593       (setq ended t)
6594       (cond
6595        ((assq key keystrokes)
6596         (let ((obuf (current-buffer)))
6597           (switch-to-buffer gnus-group-buffer)
6598           (when group
6599             (gnus-group-jump-to-group group))
6600           (eval (cadr (assq key keystrokes)))
6601           (setq group (gnus-group-group-name))
6602           (switch-to-buffer obuf))
6603         (setq ended nil))
6604        ((equal key cmd)
6605         (if (or (not group)
6606                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6607             (gnus-summary-exit)
6608           (gnus-summary-next-group nil group backward)))
6609        (t
6610         (push (cdr keve) unread-command-events))))))
6611
6612 (defun gnus-summary-next-unread-article ()
6613   "Select unread article after current one."
6614   (interactive)
6615   (gnus-summary-next-article
6616    (or (not (eq gnus-summary-goto-unread 'never))
6617        (gnus-summary-last-article-p (gnus-summary-article-number)))
6618    (and gnus-auto-select-same
6619         (gnus-summary-article-subject))))
6620
6621 (defun gnus-summary-prev-article (&optional unread subject)
6622   "Select the article after the current one.
6623 If UNREAD is non-nil, only unread articles are selected."
6624   (interactive "P")
6625   (gnus-summary-next-article unread subject t))
6626
6627 (defun gnus-summary-prev-unread-article ()
6628   "Select unread article before current one."
6629   (interactive)
6630   (gnus-summary-prev-article
6631    (or (not (eq gnus-summary-goto-unread 'never))
6632        (gnus-summary-first-article-p (gnus-summary-article-number)))
6633    (and gnus-auto-select-same
6634         (gnus-summary-article-subject))))
6635
6636 (defun gnus-summary-next-page (&optional lines circular)
6637   "Show next page of the selected article.
6638 If at the end of the current article, select the next article.
6639 LINES says how many lines should be scrolled up.
6640
6641 If CIRCULAR is non-nil, go to the start of the article instead of
6642 selecting the next article when reaching the end of the current
6643 article."
6644   (interactive "P")
6645   (setq gnus-summary-buffer (current-buffer))
6646   (gnus-set-global-variables)
6647   (let ((article (gnus-summary-article-number))
6648         (article-window (get-buffer-window gnus-article-buffer t))
6649         endp)
6650     ;; If the buffer is empty, we have no article.
6651     (unless article
6652       (error "No article to select"))
6653     (gnus-configure-windows 'article)
6654     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6655         (if (and (eq gnus-summary-goto-unread 'never)
6656                  (not (gnus-summary-last-article-p article)))
6657             (gnus-summary-next-article)
6658           (gnus-summary-next-unread-article))
6659       (if (or (null gnus-current-article)
6660               (null gnus-article-current)
6661               (/= article (cdr gnus-article-current))
6662               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6663           ;; Selected subject is different from current article's.
6664           (gnus-summary-display-article article)
6665         (when article-window
6666           (gnus-eval-in-buffer-window gnus-article-buffer
6667             (setq endp (gnus-article-next-page lines)))
6668           (when endp
6669             (cond (circular
6670                    (gnus-summary-beginning-of-article))
6671                   (lines
6672                    (gnus-message 3 "End of message"))
6673                   ((null lines)
6674                    (if (and (eq gnus-summary-goto-unread 'never)
6675                             (not (gnus-summary-last-article-p article)))
6676                        (gnus-summary-next-article)
6677                      (gnus-summary-next-unread-article))))))))
6678     (gnus-summary-recenter)
6679     (gnus-summary-position-point)))
6680
6681 (defun gnus-summary-prev-page (&optional lines move)
6682   "Show previous page of selected article.
6683 Argument LINES specifies lines to be scrolled down.
6684 If MOVE, move to the previous unread article if point is at
6685 the beginning of the buffer."
6686   (interactive "P")
6687   (let ((article (gnus-summary-article-number))
6688         (article-window (get-buffer-window gnus-article-buffer t))
6689         endp)
6690     (gnus-configure-windows 'article)
6691     (if (or (null gnus-current-article)
6692             (null gnus-article-current)
6693             (/= article (cdr gnus-article-current))
6694             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6695         ;; Selected subject is different from current article's.
6696         (gnus-summary-display-article article)
6697       (gnus-summary-recenter)
6698       (when article-window
6699         (gnus-eval-in-buffer-window gnus-article-buffer
6700           (setq endp (gnus-article-prev-page lines)))
6701         (when (and move endp)
6702           (cond (lines
6703                  (gnus-message 3 "Beginning of message"))
6704                 ((null lines)
6705                  (if (and (eq gnus-summary-goto-unread 'never)
6706                           (not (gnus-summary-first-article-p article)))
6707                      (gnus-summary-prev-article)
6708                    (gnus-summary-prev-unread-article))))))))
6709   (gnus-summary-position-point))
6710
6711 (defun gnus-summary-prev-page-or-article (&optional lines)
6712   "Show previous page of selected article.
6713 Argument LINES specifies lines to be scrolled down.
6714 If at the beginning of the article, go to the next article."
6715   (interactive "P")
6716   (gnus-summary-prev-page lines t))
6717
6718 (defun gnus-summary-scroll-up (lines)
6719   "Scroll up (or down) one line current article.
6720 Argument LINES specifies lines to be scrolled up (or down if negative)."
6721   (interactive "p")
6722   (gnus-configure-windows 'article)
6723   (gnus-summary-show-thread)
6724   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6725     (gnus-eval-in-buffer-window gnus-article-buffer
6726       (cond ((> lines 0)
6727              (when (gnus-article-next-page lines)
6728                (gnus-message 3 "End of message")))
6729             ((< lines 0)
6730              (gnus-article-prev-page (- lines))))))
6731   (gnus-summary-recenter)
6732   (gnus-summary-position-point))
6733
6734 (defun gnus-summary-scroll-down (lines)
6735   "Scroll down (or up) one line current article.
6736 Argument LINES specifies lines to be scrolled down (or up if negative)."
6737   (interactive "p")
6738   (gnus-summary-scroll-up (- lines)))
6739
6740 (defun gnus-summary-next-same-subject ()
6741   "Select next article which has the same subject as current one."
6742   (interactive)
6743   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6744
6745 (defun gnus-summary-prev-same-subject ()
6746   "Select previous article which has the same subject as current one."
6747   (interactive)
6748   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6749
6750 (defun gnus-summary-next-unread-same-subject ()
6751   "Select next unread article which has the same subject as current one."
6752   (interactive)
6753   (gnus-summary-next-article t (gnus-summary-article-subject)))
6754
6755 (defun gnus-summary-prev-unread-same-subject ()
6756   "Select previous unread article which has the same subject as current one."
6757   (interactive)
6758   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6759
6760 (defun gnus-summary-first-unread-article ()
6761   "Select 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-display-article (gnus-summary-article-number)))
6769     (gnus-summary-position-point)))
6770
6771 (defun gnus-summary-first-unread-subject ()
6772   "Place the point on the subject line of the first unread article.
6773 Return nil if there are no unread articles."
6774   (interactive)
6775   (prog1
6776       (when (gnus-summary-first-subject t)
6777         (gnus-summary-show-thread)
6778         (gnus-summary-first-subject t))
6779     (gnus-summary-position-point)))
6780
6781 (defun gnus-summary-first-unseen-subject ()
6782   "Place the point on the subject line of the first unseen article.
6783 Return nil if there are no unseen articles."
6784   (interactive)
6785   (prog1
6786       (when (gnus-summary-first-subject t t t)
6787         (gnus-summary-show-thread)
6788         (gnus-summary-first-subject t t t))
6789     (gnus-summary-position-point)))
6790
6791 (defun gnus-summary-first-article ()
6792   "Select the first article.
6793 Return nil if there are no articles."
6794   (interactive)
6795   (prog1
6796       (when (gnus-summary-first-subject)
6797         (gnus-summary-show-thread)
6798         (gnus-summary-first-subject)
6799         (gnus-summary-display-article (gnus-summary-article-number)))
6800     (gnus-summary-position-point)))
6801
6802 (defun gnus-summary-best-unread-article (&optional arg)
6803   "Select the unread article with the highest score.
6804 If given a prefix argument, select the next unread article that has a
6805 score higher than the default score."
6806   (interactive "P")
6807   (let ((article (if arg
6808                      (gnus-summary-better-unread-subject)
6809                    (gnus-summary-best-unread-subject))))
6810     (if article
6811         (gnus-summary-goto-article article)
6812       (error "No unread articles"))))
6813
6814 (defun gnus-summary-best-unread-subject ()
6815   "Select the unread subject with the highest score."
6816   (interactive)
6817   (let ((best -1000000)
6818         (data gnus-newsgroup-data)
6819         article score)
6820     (while data
6821       (and (gnus-data-unread-p (car data))
6822            (> (setq score
6823                     (gnus-summary-article-score (gnus-data-number (car data))))
6824               best)
6825            (setq best score
6826                  article (gnus-data-number (car data))))
6827       (setq data (cdr data)))
6828     (when article
6829       (gnus-summary-goto-subject article))
6830     (gnus-summary-position-point)
6831     article))
6832
6833 (defun gnus-summary-better-unread-subject ()
6834   "Select the first unread subject that has a score over the default score."
6835   (interactive)
6836   (let ((data gnus-newsgroup-data)
6837         article score)
6838     (while (and (setq article (gnus-data-number (car data)))
6839                 (or (gnus-data-read-p (car data))
6840                     (not (> (gnus-summary-article-score article)
6841                             gnus-summary-default-score))))
6842       (setq data (cdr data)))
6843     (when article
6844       (gnus-summary-goto-subject article))
6845     (gnus-summary-position-point)
6846     article))
6847
6848 (defun gnus-summary-last-subject ()
6849   "Go to the last displayed subject line in the group."
6850   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6851     (when article
6852       (gnus-summary-goto-subject article))))
6853
6854 (defun gnus-summary-goto-article (article &optional all-headers force)
6855   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6856 If ALL-HEADERS is non-nil, no header lines are hidden.
6857 If FORCE, go to the article even if it isn't displayed.  If FORCE
6858 is a number, it is the line the article is to be displayed on."
6859   (interactive
6860    (list
6861     (completing-read
6862      "Article number or Message-ID: "
6863      (mapcar (lambda (number) (list (int-to-string number)))
6864              gnus-newsgroup-limit))
6865     current-prefix-arg
6866     t))
6867   (prog1
6868       (if (and (stringp article)
6869                (string-match "@" article))
6870           (gnus-summary-refer-article article)
6871         (when (stringp article)
6872           (setq article (string-to-number article)))
6873         (if (gnus-summary-goto-subject article force)
6874             (gnus-summary-display-article article all-headers)
6875           (gnus-message 4 "Couldn't go to article %s" article) nil))
6876     (gnus-summary-position-point)))
6877
6878 (defun gnus-summary-goto-last-article ()
6879   "Go to the previously read article."
6880   (interactive)
6881   (prog1
6882       (when gnus-last-article
6883         (gnus-summary-goto-article gnus-last-article nil t))
6884     (gnus-summary-position-point)))
6885
6886 (defun gnus-summary-pop-article (number)
6887   "Pop one article off the history and go to the previous.
6888 NUMBER articles will be popped off."
6889   (interactive "p")
6890   (let (to)
6891     (setq gnus-newsgroup-history
6892           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6893     (if to
6894         (gnus-summary-goto-article (car to) nil t)
6895       (error "Article history empty")))
6896   (gnus-summary-position-point))
6897
6898 ;; Summary commands and functions for limiting the summary buffer.
6899
6900 (defun gnus-summary-limit-to-articles (n)
6901   "Limit the summary buffer to the next N articles.
6902 If not given a prefix, use the process marked articles instead."
6903   (interactive "P")
6904   (prog1
6905       (let ((articles (gnus-summary-work-articles n)))
6906         (setq gnus-newsgroup-processable nil)
6907         (gnus-summary-limit articles))
6908     (gnus-summary-position-point)))
6909
6910 (defun gnus-summary-pop-limit (&optional total)
6911   "Restore the previous limit.
6912 If given a prefix, remove all limits."
6913   (interactive "P")
6914   (when total
6915     (setq gnus-newsgroup-limits
6916           (list (mapcar (lambda (h) (mail-header-number h))
6917                         gnus-newsgroup-headers))))
6918   (unless gnus-newsgroup-limits
6919     (error "No limit to pop"))
6920   (prog1
6921       (gnus-summary-limit nil 'pop)
6922     (gnus-summary-position-point)))
6923
6924 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6925   "Limit the summary buffer to articles that have subjects that match a regexp.
6926 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6927   (interactive
6928    (list (read-string (if current-prefix-arg
6929                           "Exclude subject (regexp): "
6930                         "Limit to subject (regexp): "))
6931          nil current-prefix-arg))
6932   (unless header
6933     (setq header "subject"))
6934   (when (not (equal "" subject))
6935     (prog1
6936         (let ((articles (gnus-summary-find-matching
6937                          (or header "subject") subject 'all nil nil
6938                          not-matching)))
6939           (unless articles
6940             (error "Found no matches for \"%s\"" subject))
6941           (gnus-summary-limit articles))
6942       (gnus-summary-position-point))))
6943
6944 (defun gnus-summary-limit-to-author (from &optional not-matching)
6945   "Limit the summary buffer to articles that have authors that match a regexp.
6946 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6947   (interactive
6948    (list (read-string (if current-prefix-arg
6949                           "Exclude author (regexp): "
6950                         "Limit to author (regexp): "))
6951          current-prefix-arg))
6952   (gnus-summary-limit-to-subject from "from" not-matching))
6953
6954 (defun gnus-summary-limit-to-age (age &optional younger-p)
6955   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6956 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6957 articles that are younger than AGE days."
6958   (interactive
6959    (let ((younger current-prefix-arg)
6960          (days-got nil)
6961          days)
6962      (while (not days-got)
6963        (setq days (if younger
6964                       (read-string "Limit to articles within (in days): ")
6965                     (read-string "Limit to articles older than (in days): ")))
6966        (when (> (length days) 0)
6967          (setq days (read days)))
6968        (if (numberp days)
6969            (progn 
6970              (setq days-got t)
6971              (if (< days 0)
6972                  (progn 
6973                    (setq younger (not younger))
6974                    (setq days (* days -1)))))
6975          (message "Please enter a number.")
6976          (sleep-for 1)))
6977      (list days younger)))
6978   (prog1
6979       (let ((data gnus-newsgroup-data)
6980             (cutoff (days-to-time age))
6981             articles d date is-younger)
6982         (while (setq d (pop data))
6983           (when (and (vectorp (gnus-data-header d))
6984                      (setq date (mail-header-date (gnus-data-header d))))
6985             (setq is-younger (time-less-p
6986                               (time-since (condition-case ()
6987                                               (date-to-time date)
6988                                             (error '(0 0))))
6989                               cutoff))
6990             (when (if younger-p
6991                       is-younger
6992                     (not is-younger))
6993               (push (gnus-data-number d) articles))))
6994         (gnus-summary-limit (nreverse articles)))
6995     (gnus-summary-position-point)))
6996
6997 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
6998   "Limit the summary buffer to articles that match an 'extra' header."
6999   (interactive
7000    (let ((header
7001           (intern
7002            (gnus-completing-read
7003             (symbol-name (car gnus-extra-headers))
7004             (if current-prefix-arg
7005                 "Exclude extra header:"
7006               "Limit extra header:")
7007             (mapcar (lambda (x)
7008                       (cons (symbol-name x) x))
7009                     gnus-extra-headers)
7010             nil
7011             t))))
7012      (list header
7013            (read-string (format "%s header %s (regexp): "
7014                                 (if current-prefix-arg "Exclude" "Limit to")
7015                                 header))
7016            current-prefix-arg)))
7017   (when (not (equal "" regexp))
7018     (prog1
7019         (let ((articles (gnus-summary-find-matching
7020                          (cons 'extra header) regexp 'all nil nil
7021                          not-matching)))
7022           (unless articles
7023             (error "Found no matches for \"%s\"" regexp))
7024           (gnus-summary-limit articles))
7025       (gnus-summary-position-point))))
7026
7027 (defun gnus-summary-limit-to-display-predicate ()
7028   "Limit the summary buffer to the predicated in the `display' group parameter."
7029   (interactive)
7030   (unless gnus-newsgroup-display
7031     (error "There is no `display' group parameter"))
7032   (let (articles)
7033     (dolist (number gnus-newsgroup-articles)
7034       (when (funcall gnus-newsgroup-display)
7035         (push number articles)))
7036     (gnus-summary-limit articles))
7037   (gnus-summary-position-point))
7038
7039 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7040 (make-obsolete
7041  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7042
7043 (defun gnus-summary-limit-to-unread (&optional all)
7044   "Limit the summary buffer to articles that are not marked as read.
7045 If ALL is non-nil, limit strictly to unread articles."
7046   (interactive "P")
7047   (if all
7048       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7049     (gnus-summary-limit-to-marks
7050      ;; Concat all the marks that say that an article is read and have
7051      ;; those removed.
7052      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7053            gnus-killed-mark gnus-kill-file-mark
7054            gnus-low-score-mark gnus-expirable-mark
7055            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7056            gnus-duplicate-mark gnus-souped-mark)
7057      'reverse)))
7058
7059 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7060 (make-obsolete 'gnus-summary-delete-marked-with
7061                'gnus-summary-limit-exlude-marks)
7062
7063 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7064   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7065 If REVERSE, limit the summary buffer to articles that are marked
7066 with MARKS.  MARKS can either be a string of marks or a list of marks.
7067 Returns how many articles were removed."
7068   (interactive "sMarks: ")
7069   (gnus-summary-limit-to-marks marks t))
7070
7071 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7072   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7073 If REVERSE (the prefix), limit the summary buffer to articles that are
7074 not marked with MARKS.  MARKS can either be a string of marks or a
7075 list of marks.
7076 Returns how many articles were removed."
7077   (interactive "sMarks: \nP")
7078   (prog1
7079       (let ((data gnus-newsgroup-data)
7080             (marks (if (listp marks) marks
7081                      (append marks nil))) ; Transform to list.
7082             articles)
7083         (while data
7084           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7085                   (memq (gnus-data-mark (car data)) marks))
7086             (push (gnus-data-number (car data)) articles))
7087           (setq data (cdr data)))
7088         (gnus-summary-limit articles))
7089     (gnus-summary-position-point)))
7090
7091 (defun gnus-summary-limit-to-score (score)
7092   "Limit to articles with score at or above SCORE."
7093   (interactive "NLimit to articles with score of at least: ")
7094   (let ((data gnus-newsgroup-data)
7095         articles)
7096     (while data
7097       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7098                 score)
7099         (push (gnus-data-number (car data)) articles))
7100       (setq data (cdr data)))
7101     (prog1
7102         (gnus-summary-limit articles)
7103       (gnus-summary-position-point))))
7104
7105 (defun gnus-summary-limit-include-thread (id)
7106   "Display all the hidden articles that is in the thread with ID in it.
7107 When called interactively, ID is the Message-ID of the current
7108 article."
7109   (interactive (list (mail-header-id (gnus-summary-article-header))))
7110   (let ((articles (gnus-articles-in-thread
7111                    (gnus-id-to-thread (gnus-root-id id)))))
7112     (prog1
7113         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7114       (gnus-summary-limit-include-matching-articles
7115        "subject"
7116        (regexp-quote (gnus-simplify-subject-re
7117                       (mail-header-subject (gnus-id-to-header id)))))
7118       (gnus-summary-position-point))))
7119
7120 (defun gnus-summary-limit-include-matching-articles (header regexp)
7121   "Display all the hidden articles that have HEADERs that match REGEXP."
7122   (interactive (list (read-string "Match on header: ")
7123                      (read-string "Regexp: ")))
7124   (let ((articles (gnus-find-matching-articles header regexp)))
7125     (prog1
7126         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7127       (gnus-summary-position-point))))
7128
7129 (defun gnus-summary-limit-include-dormant ()
7130   "Display all the hidden articles that are marked as dormant.
7131 Note that this command only works on a subset of the articles currently
7132 fetched for this group."
7133   (interactive)
7134   (unless gnus-newsgroup-dormant
7135     (error "There are no dormant articles in this group"))
7136   (prog1
7137       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7138     (gnus-summary-position-point)))
7139
7140 (defun gnus-summary-limit-exclude-dormant ()
7141   "Hide all dormant articles."
7142   (interactive)
7143   (prog1
7144       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7145     (gnus-summary-position-point)))
7146
7147 (defun gnus-summary-limit-exclude-childless-dormant ()
7148   "Hide all dormant articles that have no children."
7149   (interactive)
7150   (let ((data (gnus-data-list t))
7151         articles d children)
7152     ;; Find all articles that are either not dormant or have
7153     ;; children.
7154     (while (setq d (pop data))
7155       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7156                 (and (setq children
7157                            (gnus-article-children (gnus-data-number d)))
7158                      (let (found)
7159                        (while children
7160                          (when (memq (car children) articles)
7161                            (setq children nil
7162                                  found t))
7163                          (pop children))
7164                        found)))
7165         (push (gnus-data-number d) articles)))
7166     ;; Do the limiting.
7167     (prog1
7168         (gnus-summary-limit articles)
7169       (gnus-summary-position-point))))
7170
7171 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7172   "Mark all unread excluded articles as read.
7173 If ALL, mark even excluded ticked and dormants as read."
7174   (interactive "P")
7175   (let ((articles (gnus-sorted-complement
7176                    (sort
7177                     (mapcar (lambda (h) (mail-header-number h))
7178                             gnus-newsgroup-headers)
7179                     '<)
7180                    (sort gnus-newsgroup-limit '<)))
7181         article)
7182     (setq gnus-newsgroup-unreads
7183           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7184     (if all
7185         (setq gnus-newsgroup-dormant nil
7186               gnus-newsgroup-marked nil
7187               gnus-newsgroup-reads
7188               (nconc
7189                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7190                gnus-newsgroup-reads))
7191       (while (setq article (pop articles))
7192         (unless (or (memq article gnus-newsgroup-dormant)
7193                     (memq article gnus-newsgroup-marked))
7194           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7195
7196 (defun gnus-summary-limit (articles &optional pop)
7197   (if pop
7198       ;; We pop the previous limit off the stack and use that.
7199       (setq articles (car gnus-newsgroup-limits)
7200             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7201     ;; We use the new limit, so we push the old limit on the stack.
7202     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7203   ;; Set the limit.
7204   (setq gnus-newsgroup-limit articles)
7205   (let ((total (length gnus-newsgroup-data))
7206         (data (gnus-data-find-list (gnus-summary-article-number)))
7207         (gnus-summary-mark-below nil)   ; Inhibit this.
7208         found)
7209     ;; This will do all the work of generating the new summary buffer
7210     ;; according to the new limit.
7211     (gnus-summary-prepare)
7212     ;; Hide any threads, possibly.
7213     (and gnus-show-threads
7214          gnus-thread-hide-subtree
7215          (gnus-summary-hide-all-threads))
7216     ;; Try to return to the article you were at, or one in the
7217     ;; neighborhood.
7218     (when data
7219       ;; We try to find some article after the current one.
7220       (while data
7221         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7222           (setq data nil
7223                 found t))
7224         (setq data (cdr data))))
7225     (unless found
7226       ;; If there is no data, that means that we were after the last
7227       ;; article.  The same goes when we can't find any articles
7228       ;; after the current one.
7229       (goto-char (point-max))
7230       (gnus-summary-find-prev))
7231     (gnus-set-mode-line 'summary)
7232     ;; We return how many articles were removed from the summary
7233     ;; buffer as a result of the new limit.
7234     (- total (length gnus-newsgroup-data))))
7235
7236 (defsubst gnus-invisible-cut-children (threads)
7237   (let ((num 0))
7238     (while threads
7239       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7240         (incf num))
7241       (pop threads))
7242     (< num 2)))
7243
7244 (defsubst gnus-cut-thread (thread)
7245   "Go forwards in the thread until we find an article that we want to display."
7246   (when (or (eq gnus-fetch-old-headers 'some)
7247             (eq gnus-fetch-old-headers 'invisible)
7248             (numberp gnus-fetch-old-headers)
7249             (eq gnus-build-sparse-threads 'some)
7250             (eq gnus-build-sparse-threads 'more))
7251     ;; Deal with old-fetched headers and sparse threads.
7252     (while (and
7253             thread
7254             (or
7255              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7256              (gnus-summary-article-ancient-p
7257               (mail-header-number (car thread))))
7258             (if (or (<= (length (cdr thread)) 1)
7259                     (eq gnus-fetch-old-headers 'invisible))
7260                 (setq gnus-newsgroup-limit
7261                       (delq (mail-header-number (car thread))
7262                             gnus-newsgroup-limit)
7263                       thread (cadr thread))
7264               (when (gnus-invisible-cut-children (cdr thread))
7265                 (let ((th (cdr thread)))
7266                   (while th
7267                     (if (memq (mail-header-number (caar th))
7268                               gnus-newsgroup-limit)
7269                         (setq thread (car th)
7270                               th nil)
7271                       (setq th (cdr th))))))))))
7272   thread)
7273
7274 (defun gnus-cut-threads (threads)
7275   "Cut off all uninteresting articles from the beginning of threads."
7276   (when (or (eq gnus-fetch-old-headers 'some)
7277             (eq gnus-fetch-old-headers 'invisible)
7278             (numberp gnus-fetch-old-headers)
7279             (eq gnus-build-sparse-threads 'some)
7280             (eq gnus-build-sparse-threads 'more))
7281     (let ((th threads))
7282       (while th
7283         (setcar th (gnus-cut-thread (car th)))
7284         (setq th (cdr th)))))
7285   ;; Remove nixed out threads.
7286   (delq nil threads))
7287
7288 (defun gnus-summary-initial-limit (&optional show-if-empty)
7289   "Figure out what the initial limit is supposed to be on group entry.
7290 This entails weeding out unwanted dormants, low-scored articles,
7291 fetch-old-headers verbiage, and so on."
7292   ;; Most groups have nothing to remove.
7293   (if (or gnus-inhibit-limiting
7294           (and (null gnus-newsgroup-dormant)
7295                (eq gnus-newsgroup-display 'gnus-not-ignore)
7296                (not (eq gnus-fetch-old-headers 'some))
7297                (not (numberp gnus-fetch-old-headers))
7298                (not (eq gnus-fetch-old-headers 'invisible))
7299                (null gnus-summary-expunge-below)
7300                (not (eq gnus-build-sparse-threads 'some))
7301                (not (eq gnus-build-sparse-threads 'more))
7302                (null gnus-thread-expunge-below)
7303                (not gnus-use-nocem)))
7304       ()                                ; Do nothing.
7305     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7306     (setq gnus-newsgroup-limit nil)
7307     (mapatoms
7308      (lambda (node)
7309        (unless (car (symbol-value node))
7310          ;; These threads have no parents -- they are roots.
7311          (let ((nodes (cdr (symbol-value node)))
7312                thread)
7313            (while nodes
7314              (if (and gnus-thread-expunge-below
7315                       (< (gnus-thread-total-score (car nodes))
7316                          gnus-thread-expunge-below))
7317                  (gnus-expunge-thread (pop nodes))
7318                (setq thread (pop nodes))
7319                (gnus-summary-limit-children thread))))))
7320      gnus-newsgroup-dependencies)
7321     ;; If this limitation resulted in an empty group, we might
7322     ;; pop the previous limit and use it instead.
7323     (when (and (not gnus-newsgroup-limit)
7324                show-if-empty)
7325       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7326     gnus-newsgroup-limit))
7327
7328 (defun gnus-summary-limit-children (thread)
7329   "Return 1 if this subthread is visible and 0 if it is not."
7330   ;; First we get the number of visible children to this thread.  This
7331   ;; is done by recursing down the thread using this function, so this
7332   ;; will really go down to a leaf article first, before slowly
7333   ;; working its way up towards the root.
7334   (when thread
7335     (let ((children
7336            (if (cdr thread)
7337                (apply '+ (mapcar 'gnus-summary-limit-children
7338                                  (cdr thread)))
7339              0))
7340           (number (mail-header-number (car thread)))
7341           score)
7342       (if (and
7343            (not (memq number gnus-newsgroup-marked))
7344            (or
7345             ;; If this article is dormant and has absolutely no visible
7346             ;; children, then this article isn't visible.
7347             (and (memq number gnus-newsgroup-dormant)
7348                  (zerop children))
7349             ;; If this is "fetch-old-headered" and there is no
7350             ;; visible children, then we don't want this article.
7351             (and (or (eq gnus-fetch-old-headers 'some)
7352                      (numberp gnus-fetch-old-headers))
7353                  (gnus-summary-article-ancient-p number)
7354                  (zerop children))
7355             ;; If this is "fetch-old-headered" and `invisible', then
7356             ;; we don't want this article.
7357             (and (eq gnus-fetch-old-headers 'invisible)
7358                  (gnus-summary-article-ancient-p number))
7359             ;; If this is a sparsely inserted article with no children,
7360             ;; we don't want it.
7361             (and (eq gnus-build-sparse-threads 'some)
7362                  (gnus-summary-article-sparse-p number)
7363                  (zerop children))
7364             ;; If we use expunging, and this article is really
7365             ;; low-scored, then we don't want this article.
7366             (when (and gnus-summary-expunge-below
7367                        (< (setq score
7368                                 (or (cdr (assq number gnus-newsgroup-scored))
7369                                     gnus-summary-default-score))
7370                           gnus-summary-expunge-below))
7371               ;; We increase the expunge-tally here, but that has
7372               ;; nothing to do with the limits, really.
7373               (incf gnus-newsgroup-expunged-tally)
7374               ;; We also mark as read here, if that's wanted.
7375               (when (and gnus-summary-mark-below
7376                          (< score gnus-summary-mark-below))
7377                 (setq gnus-newsgroup-unreads
7378                       (delq number gnus-newsgroup-unreads))
7379                 (if gnus-newsgroup-auto-expire
7380                     (push number gnus-newsgroup-expirable)
7381                   (push (cons number gnus-low-score-mark)
7382                         gnus-newsgroup-reads)))
7383               t)
7384             ;; Do the `display' group parameter.
7385             (and gnus-newsgroup-display
7386                  (not (funcall gnus-newsgroup-display)))
7387             ;; Check NoCeM things.
7388             (if (and gnus-use-nocem
7389                      (gnus-nocem-unwanted-article-p
7390                       (mail-header-id (car thread))))
7391                 (progn
7392                   (setq gnus-newsgroup-unreads
7393                         (delq number gnus-newsgroup-unreads))
7394                   t))))
7395           ;; Nope, invisible article.
7396           0
7397         ;; Ok, this article is to be visible, so we add it to the limit
7398         ;; and return 1.
7399         (push number gnus-newsgroup-limit)
7400         1))))
7401
7402 (defun gnus-expunge-thread (thread)
7403   "Mark all articles in THREAD as read."
7404   (let* ((number (mail-header-number (car thread))))
7405     (incf gnus-newsgroup-expunged-tally)
7406     ;; We also mark as read here, if that's wanted.
7407     (setq gnus-newsgroup-unreads
7408           (delq number gnus-newsgroup-unreads))
7409     (if gnus-newsgroup-auto-expire
7410         (push number gnus-newsgroup-expirable)
7411       (push (cons number gnus-low-score-mark)
7412             gnus-newsgroup-reads)))
7413   ;; Go recursively through all subthreads.
7414   (mapcar 'gnus-expunge-thread (cdr thread)))
7415
7416 ;; Summary article oriented commands
7417
7418 (defun gnus-summary-refer-parent-article (n)
7419   "Refer parent article N times.
7420 If N is negative, go to ancestor -N instead.
7421 The difference between N and the number of articles fetched is returned."
7422   (interactive "p")
7423   (let ((skip 1)
7424         error header ref)
7425     (when (not (natnump n))
7426       (setq skip (abs n)
7427             n 1))
7428     (while (and (> n 0)
7429                 (not error))
7430       (setq header (gnus-summary-article-header))
7431       (if (and (eq (mail-header-number header)
7432                    (cdr gnus-article-current))
7433                (equal gnus-newsgroup-name
7434                       (car gnus-article-current)))
7435           ;; If we try to find the parent of the currently
7436           ;; displayed article, then we take a look at the actual
7437           ;; References header, since this is slightly more
7438           ;; reliable than the References field we got from the
7439           ;; server.
7440           (save-excursion
7441             (set-buffer gnus-original-article-buffer)
7442             (nnheader-narrow-to-headers)
7443             (unless (setq ref (message-fetch-field "references"))
7444               (setq ref (message-fetch-field "in-reply-to")))
7445             (widen))
7446         (setq ref
7447               ;; It's not the current article, so we take a bet on
7448               ;; the value we got from the server.
7449               (mail-header-references header)))
7450       (if (and ref
7451                (not (equal ref "")))
7452           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7453             (gnus-message 1 "Couldn't find parent"))
7454         (gnus-message 1 "No references in article %d"
7455                       (gnus-summary-article-number))
7456         (setq error t))
7457       (decf n))
7458     (gnus-summary-position-point)
7459     n))
7460
7461 (defun gnus-summary-refer-references ()
7462   "Fetch all articles mentioned in the References header.
7463 Return the number of articles fetched."
7464   (interactive)
7465   (let ((ref (mail-header-references (gnus-summary-article-header)))
7466         (current (gnus-summary-article-number))
7467         (n 0))
7468     (if (or (not ref)
7469             (equal ref ""))
7470         (error "No References in the current article")
7471       ;; For each Message-ID in the References header...
7472       (while (string-match "<[^>]*>" ref)
7473         (incf n)
7474         ;; ... fetch that article.
7475         (gnus-summary-refer-article
7476          (prog1 (match-string 0 ref)
7477            (setq ref (substring ref (match-end 0))))))
7478       (gnus-summary-goto-subject current)
7479       (gnus-summary-position-point)
7480       n)))
7481
7482 (defun gnus-summary-refer-thread (&optional limit)
7483   "Fetch all articles in the current thread.
7484 If LIMIT (the numerical prefix), fetch that many old headers instead
7485 of what's specified by the `gnus-refer-thread-limit' variable."
7486   (interactive "P")
7487   (let ((id (mail-header-id (gnus-summary-article-header)))
7488         (limit (if limit (prefix-numeric-value limit)
7489                  gnus-refer-thread-limit)))
7490     ;; We want to fetch LIMIT *old* headers, but we also have to
7491     ;; re-fetch all the headers in the current buffer, because many of
7492     ;; them may be undisplayed.  So we adjust LIMIT.
7493     (when (numberp limit)
7494       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7495     (unless (eq gnus-fetch-old-headers 'invisible)
7496       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7497       ;; Retrieve the headers and read them in.
7498       (if (eq (gnus-retrieve-headers
7499                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7500               'nov)
7501           (gnus-build-all-threads)
7502         (error "Can't fetch thread from backends that don't support NOV"))
7503       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7504     (gnus-summary-limit-include-thread id)))
7505
7506 (defun gnus-summary-refer-article (message-id)
7507   "Fetch an article specified by MESSAGE-ID."
7508   (interactive "sMessage-ID: ")
7509   (when (and (stringp message-id)
7510              (not (zerop (length message-id))))
7511     ;; Construct the correct Message-ID if necessary.
7512     ;; Suggested by tale@pawl.rpi.edu.
7513     (unless (string-match "^<" message-id)
7514       (setq message-id (concat "<" message-id)))
7515     (unless (string-match ">$" message-id)
7516       (setq message-id (concat message-id ">")))
7517     (let* ((header (gnus-id-to-header message-id))
7518            (sparse (and header
7519                         (gnus-summary-article-sparse-p
7520                          (mail-header-number header))
7521                         (memq (mail-header-number header)
7522                               gnus-newsgroup-limit)))
7523            number)
7524       (cond
7525        ;; If the article is present in the buffer we just go to it.
7526        ((and header
7527              (or (not (gnus-summary-article-sparse-p
7528                        (mail-header-number header)))
7529                  sparse))
7530         (prog1
7531             (gnus-summary-goto-article
7532              (mail-header-number header) nil t)
7533           (when sparse
7534             (gnus-summary-update-article (mail-header-number header)))))
7535        (t
7536         ;; We fetch the article.
7537         (catch 'found
7538           (dolist (gnus-override-method (gnus-refer-article-methods))
7539             (gnus-check-server gnus-override-method)
7540             ;; Fetch the header, and display the article.
7541             (when (setq number (gnus-summary-insert-subject message-id))
7542               (gnus-summary-select-article nil nil nil number)
7543               (throw 'found t)))
7544           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7545
7546 (defun gnus-refer-article-methods ()
7547   "Return a list of referrable methods."
7548   (cond
7549    ;; No method, so we default to current and native.
7550    ((null gnus-refer-article-method)
7551     (list gnus-current-select-method gnus-select-method))
7552    ;; Current.
7553    ((eq 'current gnus-refer-article-method)
7554     (list gnus-current-select-method))
7555    ;; List of select methods.
7556    ((not (and (symbolp (car gnus-refer-article-method))
7557               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7558     (let (out)
7559       (dolist (method gnus-refer-article-method)
7560         (push (if (eq 'current method)
7561                   gnus-current-select-method
7562                 method)
7563               out))
7564       (nreverse out)))
7565    ;; One single select method.
7566    (t
7567     (list gnus-refer-article-method))))
7568
7569 (defun gnus-summary-edit-parameters ()
7570   "Edit the group parameters of the current group."
7571   (interactive)
7572   (gnus-group-edit-group gnus-newsgroup-name 'params))
7573
7574 (defun gnus-summary-customize-parameters ()
7575   "Customize the group parameters of the current group."
7576   (interactive)
7577   (gnus-group-customize gnus-newsgroup-name))
7578
7579 (defun gnus-summary-enter-digest-group (&optional force)
7580   "Enter an nndoc group based on the current article.
7581 If FORCE, force a digest interpretation.  If not, try
7582 to guess what the document format is."
7583   (interactive "P")
7584   (let ((conf gnus-current-window-configuration))
7585     (save-excursion
7586       (gnus-summary-select-article))
7587     (setq gnus-current-window-configuration conf)
7588     (let* ((name (format "%s-%d"
7589                          (gnus-group-prefixed-name
7590                           gnus-newsgroup-name (list 'nndoc ""))
7591                          (save-excursion
7592                            (set-buffer gnus-summary-buffer)
7593                            gnus-current-article)))
7594            (ogroup gnus-newsgroup-name)
7595            (params (append (gnus-info-params (gnus-get-info ogroup))
7596                            (list (cons 'to-group ogroup))
7597                            (list (cons 'save-article-group ogroup))))
7598            (case-fold-search t)
7599            (buf (current-buffer))
7600            dig to-address)
7601       (save-excursion
7602         (set-buffer gnus-original-article-buffer)
7603         ;; Have the digest group inherit the main mail address of
7604         ;; the parent article.
7605         (when (setq to-address (or (message-fetch-field "reply-to")
7606                                    (message-fetch-field "from")))
7607           (setq params (append
7608                         (list (cons 'to-address
7609                                     (funcall gnus-decode-encoded-word-function
7610                                              to-address))))))
7611         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7612         (insert-buffer-substring gnus-original-article-buffer)
7613         ;; Remove lines that may lead nndoc to misinterpret the
7614         ;; document type.
7615         (narrow-to-region
7616          (goto-char (point-min))
7617          (or (search-forward "\n\n" nil t) (point)))
7618         (goto-char (point-min))
7619         (delete-matching-lines "^Path:\\|^From ")
7620         (widen))
7621       (unwind-protect
7622           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7623                     (gnus-newsgroup-ephemeral-ignored-charsets
7624                      gnus-newsgroup-ignored-charsets))
7625                 (gnus-group-read-ephemeral-group
7626                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7627                               (nndoc-article-type
7628                                ,(if force 'mbox 'guess))) t))
7629             ;; Make all postings to this group go to the parent group.
7630               (nconc (gnus-info-params (gnus-get-info name))
7631                      params)
7632             ;; Couldn't select this doc group.
7633             (switch-to-buffer buf)
7634             (gnus-set-global-variables)
7635             (gnus-configure-windows 'summary)
7636             (gnus-message 3 "Article couldn't be entered?"))
7637         (kill-buffer dig)))))
7638
7639 (defun gnus-summary-read-document (n)
7640   "Open a new group based on the current article(s).
7641 This will allow you to read digests and other similar
7642 documents as newsgroups.
7643 Obeys the standard process/prefix convention."
7644   (interactive "P")
7645   (let* ((articles (gnus-summary-work-articles n))
7646          (ogroup gnus-newsgroup-name)
7647          (params (append (gnus-info-params (gnus-get-info ogroup))
7648                          (list (cons 'to-group ogroup))))
7649          article group egroup groups vgroup)
7650     (while (setq article (pop articles))
7651       (setq group (format "%s-%d" gnus-newsgroup-name article))
7652       (gnus-summary-remove-process-mark article)
7653       (when (gnus-summary-display-article article)
7654         (save-excursion
7655           (with-temp-buffer
7656             (insert-buffer-substring gnus-original-article-buffer)
7657             ;; Remove some headers that may lead nndoc to make
7658             ;; the wrong guess.
7659             (message-narrow-to-head)
7660             (goto-char (point-min))
7661             (delete-matching-lines "^\\(Path\\):\\|^From ")
7662             (widen)
7663             (if (setq egroup
7664                       (gnus-group-read-ephemeral-group
7665                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7666                                      (nndoc-article-type guess))
7667                        t nil t))
7668                 (progn
7669             ;; Make all postings to this group go to the parent group.
7670                   (nconc (gnus-info-params (gnus-get-info egroup))
7671                          params)
7672                   (push egroup groups))
7673               ;; Couldn't select this doc group.
7674               (gnus-error 3 "Article couldn't be entered"))))))
7675     ;; Now we have selected all the documents.
7676     (cond
7677      ((not groups)
7678       (error "None of the articles could be interpreted as documents"))
7679      ((gnus-group-read-ephemeral-group
7680        (setq vgroup (format
7681                      "nnvirtual:%s-%s" gnus-newsgroup-name
7682                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7683        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7684        t
7685        (cons (current-buffer) 'summary)))
7686      (t
7687       (error "Couldn't select virtual nndoc group")))))
7688
7689 (defun gnus-summary-isearch-article (&optional regexp-p)
7690   "Do incremental search forward on the current article.
7691 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7692   (interactive "P")
7693   (gnus-summary-select-article)
7694   (gnus-configure-windows 'article)
7695   (gnus-eval-in-buffer-window gnus-article-buffer
7696     (save-restriction
7697       (widen)
7698       (isearch-forward regexp-p))))
7699
7700 (defun gnus-summary-search-article-forward (regexp &optional backward)
7701   "Search for an article containing REGEXP forward.
7702 If BACKWARD, search backward instead."
7703   (interactive
7704    (list (read-string
7705           (format "Search article %s (regexp%s): "
7706                   (if current-prefix-arg "backward" "forward")
7707                   (if gnus-last-search-regexp
7708                       (concat ", default " gnus-last-search-regexp)
7709                     "")))
7710          current-prefix-arg))
7711   (if (string-equal regexp "")
7712       (setq regexp (or gnus-last-search-regexp ""))
7713     (setq gnus-last-search-regexp regexp)
7714     (setq gnus-article-before-search gnus-current-article))
7715   ;; Intentionally set gnus-last-article.
7716   (setq gnus-last-article gnus-article-before-search)
7717   (let ((gnus-last-article gnus-last-article))
7718     (if (gnus-summary-search-article regexp backward)
7719         (gnus-summary-show-thread)
7720       (error "Search failed: \"%s\"" regexp))))
7721
7722 (defun gnus-summary-search-article-backward (regexp)
7723   "Search for an article containing REGEXP backward."
7724   (interactive
7725    (list (read-string
7726           (format "Search article backward (regexp%s): "
7727                   (if gnus-last-search-regexp
7728                       (concat ", default " gnus-last-search-regexp)
7729                     "")))))
7730   (gnus-summary-search-article-forward regexp 'backward))
7731
7732 (defun gnus-summary-search-article (regexp &optional backward)
7733   "Search for an article containing REGEXP.
7734 Optional argument BACKWARD means do search for backward.
7735 `gnus-select-article-hook' is not called during the search."
7736   ;; We have to require this here to make sure that the following
7737   ;; dynamic binding isn't shadowed by autoloading.
7738   (require 'gnus-async)
7739   (require 'gnus-art)
7740   (let ((gnus-select-article-hook nil)  ;Disable hook.
7741         (gnus-article-prepare-hook nil)
7742         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7743         (gnus-use-article-prefetch nil)
7744         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7745         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7746         (sum (current-buffer))
7747         (gnus-display-mime-function nil)
7748         (found nil)
7749         point)
7750     (gnus-save-hidden-threads
7751       (gnus-summary-select-article)
7752       (set-buffer gnus-article-buffer)
7753       (goto-char (window-point (get-buffer-window (current-buffer))))
7754       (when backward
7755         (forward-line -1))
7756       (while (not found)
7757         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7758         (if (if backward
7759                 (re-search-backward regexp nil t)
7760               (re-search-forward regexp nil t))
7761             ;; We found the regexp.
7762             (progn
7763               (setq found 'found)
7764               (beginning-of-line)
7765               (set-window-start
7766                (get-buffer-window (current-buffer))
7767                (point))
7768               (forward-line 1)
7769               (set-window-point
7770                (get-buffer-window (current-buffer))
7771                (point))
7772               (set-buffer sum)
7773               (setq point (point)))
7774           ;; We didn't find it, so we go to the next article.
7775           (set-buffer sum)
7776           (setq found 'not)
7777           (while (eq found 'not)
7778             (if (not (if backward (gnus-summary-find-prev)
7779                        (gnus-summary-find-next)))
7780                 ;; No more articles.
7781                 (setq found t)
7782               ;; Select the next article and adjust point.
7783               (unless (gnus-summary-article-sparse-p
7784                        (gnus-summary-article-number))
7785                 (setq found nil)
7786                 (gnus-summary-select-article)
7787                 (set-buffer gnus-article-buffer)
7788                 (widen)
7789                 (goto-char (if backward (point-max) (point-min))))))))
7790       (gnus-message 7 ""))
7791     ;; Return whether we found the regexp.
7792     (when (eq found 'found)
7793       (goto-char point)
7794       (gnus-summary-show-thread)
7795       (gnus-summary-goto-subject gnus-current-article)
7796       (gnus-summary-position-point)
7797       t)))
7798
7799 (defun gnus-find-matching-articles (header regexp)
7800   "Return a list of all articles that match REGEXP on HEADER.
7801 This search includes all articles in the current group that Gnus has
7802 fetched headers for, whether they are displayed or not."
7803   (let ((articles nil)
7804         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7805         (case-fold-search t))
7806     (dolist (header gnus-newsgroup-headers)
7807       (when (string-match regexp (funcall func header))
7808         (push (mail-header-number header) articles)))
7809     (nreverse articles)))
7810
7811 (defun gnus-summary-find-matching (header regexp &optional backward unread
7812                                           not-case-fold not-matching)
7813   "Return a list of all articles that match REGEXP on HEADER.
7814 The search stars on the current article and goes forwards unless
7815 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7816 If UNREAD is non-nil, only unread articles will
7817 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7818 in the comparisons. If NOT-MATCHING, return a list of all articles that
7819 not match REGEXP on HEADER."
7820   (let ((case-fold-search (not not-case-fold))
7821         articles d func)
7822     (if (consp header)
7823         (if (eq (car header) 'extra)
7824             (setq func
7825                   `(lambda (h)
7826                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7827                          "")))
7828           (error "%s is an invalid header" header))
7829       (unless (fboundp (intern (concat "mail-header-" header)))
7830         (error "%s is not a valid header" header))
7831       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7832     (dolist (d (if (eq backward 'all)
7833                    gnus-newsgroup-data
7834                  (gnus-data-find-list
7835                   (gnus-summary-article-number)
7836                   (gnus-data-list backward))))
7837       (when (and (or (not unread)       ; We want all articles...
7838                      (gnus-data-unread-p d)) ; Or just unreads.
7839                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7840                  (if not-matching
7841                      (not (string-match
7842                            regexp
7843                            (funcall func (gnus-data-header d))))
7844                    (string-match regexp
7845                                  (funcall func (gnus-data-header d)))))
7846         (push (gnus-data-number d) articles))) ; Success!
7847     (nreverse articles)))
7848
7849 (defun gnus-summary-execute-command (header regexp command &optional backward)
7850   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7851 If HEADER is an empty string (or nil), the match is done on the entire
7852 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7853   (interactive
7854    (list (let ((completion-ignore-case t))
7855            (completing-read
7856             "Header name: "
7857             (mapcar (lambda (header) (list (format "%s" header)))
7858                     (append
7859                      '("Number" "Subject" "From" "Lines" "Date"
7860                        "Message-ID" "Xref" "References" "Body")
7861                      gnus-extra-headers))
7862             nil 'require-match))
7863          (read-string "Regexp: ")
7864          (read-key-sequence "Command: ")
7865          current-prefix-arg))
7866   (when (equal header "Body")
7867     (setq header ""))
7868   ;; Hidden thread subtrees must be searched as well.
7869   (gnus-summary-show-all-threads)
7870   ;; We don't want to change current point nor window configuration.
7871   (save-excursion
7872     (save-window-excursion
7873       (gnus-message 6 "Executing %s..." (key-description command))
7874 ;; We'd like to execute COMMAND interactively so as to give arguments.
7875       (gnus-execute header regexp
7876                     `(call-interactively ',(key-binding command))
7877                     backward)
7878       (gnus-message 6 "Executing %s...done" (key-description command)))))
7879
7880 (defun gnus-summary-beginning-of-article ()
7881   "Scroll the article back to the beginning."
7882   (interactive)
7883   (gnus-summary-select-article)
7884   (gnus-configure-windows 'article)
7885   (gnus-eval-in-buffer-window gnus-article-buffer
7886     (widen)
7887     (goto-char (point-min))
7888     (when gnus-page-broken
7889       (gnus-narrow-to-page))))
7890
7891 (defun gnus-summary-end-of-article ()
7892   "Scroll to the end of the article."
7893   (interactive)
7894   (gnus-summary-select-article)
7895   (gnus-configure-windows 'article)
7896   (gnus-eval-in-buffer-window gnus-article-buffer
7897     (widen)
7898     (goto-char (point-max))
7899     (recenter -3)
7900     (when gnus-page-broken
7901       (gnus-narrow-to-page))))
7902
7903 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7904   "Truncate to LEN and quote all \"(\"'s in STRING."
7905   (gnus-replace-in-string (if (and len (> (length string) len))
7906                               (substring string 0 len)
7907                             string)
7908                           "[()]" "\\\\\\&"))
7909
7910 (defun gnus-summary-print-article (&optional filename n)
7911   "Generate and print a PostScript image of the N next (mail) articles.
7912
7913 If N is negative, print the N previous articles.  If N is nil and articles
7914 have been marked with the process mark, print these instead.
7915
7916 If the optional first argument FILENAME is nil, send the image to the
7917 printer.  If FILENAME is a string, save the PostScript image in a file with
7918 that name.  If FILENAME is a number, prompt the user for the name of the file
7919 to save in."
7920   (interactive (list (ps-print-preprint current-prefix-arg)))
7921   (dolist (article (gnus-summary-work-articles n))
7922     (gnus-summary-select-article nil nil 'pseudo article)
7923     (gnus-eval-in-buffer-window gnus-article-buffer
7924       (gnus-print-buffer))
7925     (gnus-summary-remove-process-mark article))
7926   (ps-despool filename))
7927
7928 (defun gnus-print-buffer ()
7929   (let ((buffer (generate-new-buffer " *print*")))
7930     (unwind-protect
7931         (progn
7932           (copy-to-buffer buffer (point-min) (point-max))
7933           (set-buffer buffer)
7934           (gnus-article-delete-invisible-text)
7935           (when (gnus-visual-p 'article-highlight 'highlight)
7936             ;; Copy-to-buffer doesn't copy overlay.  So redo
7937             ;; highlight.
7938             (let ((gnus-article-buffer buffer))
7939               (gnus-article-highlight-citation t)
7940               (gnus-article-highlight-signature)))
7941           (let ((ps-left-header
7942                  (list
7943                   (concat "("
7944                           (gnus-summary-print-truncate-and-quote
7945                            (mail-header-subject gnus-current-headers)
7946                            66) ")")
7947                   (concat "("
7948                           (gnus-summary-print-truncate-and-quote
7949                            (mail-header-from gnus-current-headers)
7950                            45) ")")))
7951                 (ps-right-header
7952                  (list
7953                   "/pagenumberstring load"
7954                   (concat "("
7955                           (mail-header-date gnus-current-headers) ")"))))
7956             (gnus-run-hooks 'gnus-ps-print-hook)
7957             (save-excursion
7958               (if window-system
7959                   (ps-spool-buffer-with-faces)
7960                 (ps-spool-buffer)))))
7961       (kill-buffer buffer))))
7962
7963 (defun gnus-summary-show-article (&optional arg)
7964   "Force redisplaying of the current article.
7965 If ARG (the prefix) is a number, show the article with the charset
7966 defined in `gnus-summary-show-article-charset-alist', or the charset
7967 input.
7968 If ARG (the prefix) is non-nil and not a number, show the raw article
7969 without any article massaging functions being run.  Normally, the key strokes 
7970 are `C-u g'."
7971   (interactive "P")
7972   (cond
7973    ((numberp arg)
7974     (gnus-summary-show-article t)
7975     (let ((gnus-newsgroup-charset
7976            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7977                (mm-read-coding-system
7978                 "View as charset: "
7979                 (save-excursion
7980                   (set-buffer gnus-article-buffer)
7981                   (let ((coding-systems
7982                          (detect-coding-region (point) (point-max))))
7983                     (or (car-safe coding-systems)
7984                         coding-systems))))))
7985           (gnus-newsgroup-ignored-charsets 'gnus-all))
7986       (gnus-summary-select-article nil 'force)
7987       (let ((deps gnus-newsgroup-dependencies)
7988             head header lines)
7989         (save-excursion
7990           (set-buffer gnus-original-article-buffer)
7991           (save-restriction
7992             (message-narrow-to-head)
7993             (setq head (buffer-string))
7994             (goto-char (point-min))
7995             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
7996               (goto-char (point-max))
7997               (widen)
7998               (setq lines (1- (count-lines (point) (point-max))))))
7999           (with-temp-buffer
8000             (insert (format "211 %d Article retrieved.\n"
8001                             (cdr gnus-article-current)))
8002             (insert head)
8003             (if lines (insert (format "Lines: %d\n" lines)))
8004             (insert ".\n")
8005             (let ((nntp-server-buffer (current-buffer)))
8006               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8007         (gnus-data-set-header
8008          (gnus-data-find (cdr gnus-article-current))
8009          header)
8010         (gnus-summary-update-article-line
8011          (cdr gnus-article-current) header)
8012         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8013           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8014    ((not arg)
8015     ;; Select the article the normal way.
8016     (gnus-summary-select-article nil 'force))
8017    (t
8018     ;; We have to require this here to make sure that the following
8019     ;; dynamic binding isn't shadowed by autoloading.
8020     (require 'gnus-async)
8021     (require 'gnus-art)
8022     ;; Bind the article treatment functions to nil.
8023     (let ((gnus-have-all-headers t)
8024           gnus-article-prepare-hook
8025           gnus-article-decode-hook
8026           gnus-display-mime-function
8027           gnus-break-pages)
8028       ;; Destroy any MIME parts.
8029       (when (gnus-buffer-live-p gnus-article-buffer)
8030         (save-excursion
8031           (set-buffer gnus-article-buffer)
8032           (mm-destroy-parts gnus-article-mime-handles)
8033           ;; Set it to nil for safety reason.
8034           (setq gnus-article-mime-handle-alist nil)
8035           (setq gnus-article-mime-handles nil)))
8036       (gnus-summary-select-article nil 'force))))
8037   (gnus-summary-goto-subject gnus-current-article)
8038   (gnus-summary-position-point))
8039
8040 (defun gnus-summary-show-raw-article ()
8041   "Show the raw article without any article massaging functions being run."
8042   (interactive)
8043   (gnus-summary-show-article t))
8044
8045 (defun gnus-summary-verbose-headers (&optional arg)
8046   "Toggle permanent full header display.
8047 If ARG is a positive number, turn header display on.
8048 If ARG is a negative number, turn header display off."
8049   (interactive "P")
8050   (setq gnus-show-all-headers
8051         (cond ((or (not (numberp arg))
8052                    (zerop arg))
8053                (not gnus-show-all-headers))
8054               ((natnump arg)
8055                t)))
8056   (gnus-summary-show-article))
8057
8058 (defun gnus-summary-toggle-header (&optional arg)
8059   "Show the headers if they are hidden, or hide them if they are shown.
8060 If ARG is a positive number, show the entire header.
8061 If ARG is a negative number, hide the unwanted header lines."
8062   (interactive "P")
8063   (save-excursion
8064     (set-buffer gnus-article-buffer)
8065     (save-restriction
8066       (let* ((buffer-read-only nil)
8067              (inhibit-point-motion-hooks t)
8068              hidden e)
8069         (setq hidden
8070               (if (numberp arg)
8071                   (>= arg 0)
8072                 (save-restriction
8073                   (article-narrow-to-head)
8074                   (gnus-article-hidden-text-p 'headers))))
8075         (goto-char (point-min))
8076         (when (search-forward "\n\n" nil t)
8077           (delete-region (point-min) (1- (point))))
8078         (goto-char (point-min))
8079         (save-excursion
8080           (set-buffer gnus-original-article-buffer)
8081           (goto-char (point-min))
8082           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8083         (insert-buffer-substring gnus-original-article-buffer 1 e)
8084         (save-restriction
8085           (narrow-to-region (point-min) (point))
8086           (article-decode-encoded-words)
8087           (if  hidden
8088               (let ((gnus-treat-hide-headers nil)
8089                     (gnus-treat-hide-boring-headers nil))
8090                 (gnus-delete-wash-type 'headers)
8091                 (gnus-treat-article 'head))
8092             (gnus-treat-article 'head)))
8093         (gnus-set-mode-line 'article)))))
8094
8095 (defun gnus-summary-show-all-headers ()
8096   "Make all header lines visible."
8097   (interactive)
8098   (gnus-summary-toggle-header 1))
8099
8100 (defun gnus-summary-caesar-message (&optional arg)
8101   "Caesar rotate the current article by 13.
8102 The numerical prefix specifies how many places to rotate each letter
8103 forward."
8104   (interactive "P")
8105   (gnus-summary-select-article)
8106   (let ((mail-header-separator ""))
8107     (gnus-eval-in-buffer-window gnus-article-buffer
8108       (save-restriction
8109         (widen)
8110         (let ((start (window-start))
8111               buffer-read-only)
8112           (message-caesar-buffer-body arg)
8113           (set-window-start (get-buffer-window (current-buffer)) start))))))
8114
8115 (defun gnus-summary-stop-page-breaking ()
8116   "Stop page breaking in the current article."
8117   (interactive)
8118   (gnus-summary-select-article)
8119   (gnus-eval-in-buffer-window gnus-article-buffer
8120     (widen)
8121     (when (gnus-visual-p 'page-marker)
8122       (let ((buffer-read-only nil))
8123         (gnus-remove-text-with-property 'gnus-prev)
8124         (gnus-remove-text-with-property 'gnus-next))
8125       (setq gnus-page-broken nil))))
8126
8127 (defun gnus-summary-move-article (&optional n to-newsgroup
8128                                             select-method action)
8129   "Move the current article to a different newsgroup.
8130 If N is a positive number, move the N next articles.
8131 If N is a negative number, move the N previous articles.
8132 If N is nil and any articles have been marked with the process mark,
8133 move those articles instead.
8134 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8135 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8136 re-spool using this method.
8137
8138 For this function to work, both the current newsgroup and the
8139 newsgroup that you want to move to have to support the `request-move'
8140 and `request-accept' functions.
8141
8142 ACTION can be either `move' (the default), `crosspost' or `copy'."
8143   (interactive "P")
8144   (unless action
8145     (setq action 'move))
8146   ;; Check whether the source group supports the required functions.
8147   (cond ((and (eq action 'move)
8148               (not (gnus-check-backend-function
8149                     'request-move-article gnus-newsgroup-name)))
8150          (error "The current group does not support article moving"))
8151         ((and (eq action 'crosspost)
8152               (not (gnus-check-backend-function
8153                     'request-replace-article gnus-newsgroup-name)))
8154          (error "The current group does not support article editing")))
8155   (let ((articles (gnus-summary-work-articles n))
8156         (prefix (if (gnus-check-backend-function
8157                      'request-move-article gnus-newsgroup-name)
8158                     (gnus-group-real-prefix gnus-newsgroup-name)
8159                   ""))
8160         (names '((move "Move" "Moving")
8161                  (copy "Copy" "Copying")
8162                  (crosspost "Crosspost" "Crossposting")))
8163         (copy-buf (save-excursion
8164                     (nnheader-set-temp-buffer " *copy article*")))
8165         art-group to-method new-xref article to-groups)
8166     (unless (assq action names)
8167       (error "Unknown action %s" action))
8168     ;; We have to select an article to give
8169     ;; `gnus-read-move-group-name' an opportunity to suggest an
8170     ;; appropriate default.
8171     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8172       (gnus-summary-select-article nil nil nil (car articles)))
8173     ;; Read the newsgroup name.
8174     (when (and (not to-newsgroup)
8175                (not select-method))
8176       (setq to-newsgroup
8177             (gnus-read-move-group-name
8178              (cadr (assq action names))
8179              (symbol-value (intern (format "gnus-current-%s-group" action)))
8180              articles prefix))
8181       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8182     (setq to-method (or select-method
8183                         (gnus-server-to-method
8184                          (gnus-group-method to-newsgroup))))
8185     ;; Check the method we are to move this article to...
8186     (unless (gnus-check-backend-function
8187              'request-accept-article (car to-method))
8188       (error "%s does not support article copying" (car to-method)))
8189     (unless (gnus-check-server to-method)
8190       (error "Can't open server %s" (car to-method)))
8191     (gnus-message 6 "%s to %s: %s..."
8192                   (caddr (assq action names))
8193                   (or (car select-method) to-newsgroup) articles)
8194     (while articles
8195       (setq article (pop articles))
8196       (setq
8197        art-group
8198        (cond
8199         ;; Move the article.
8200         ((eq action 'move)
8201          ;; Remove this article from future suppression.
8202          (gnus-dup-unsuppress-article article)
8203          (gnus-request-move-article
8204           article                       ; Article to move
8205           gnus-newsgroup-name           ; From newsgroup
8206           (nth 1 (gnus-find-method-for-group
8207                   gnus-newsgroup-name)) ; Server
8208           (list 'gnus-request-accept-article
8209                 to-newsgroup (list 'quote select-method)
8210                 (not articles) t)       ; Accept form
8211           (not articles)))              ; Only save nov last time
8212         ;; Copy the article.
8213         ((eq action 'copy)
8214          (save-excursion
8215            (set-buffer copy-buf)
8216            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8217              (gnus-request-accept-article
8218               to-newsgroup select-method (not articles) t))))
8219         ;; Crosspost the article.
8220         ((eq action 'crosspost)
8221          (let ((xref (message-tokenize-header
8222                       (mail-header-xref (gnus-summary-article-header article))
8223                       " ")))
8224            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8225                                   ":" (number-to-string article)))
8226            (unless xref
8227              (setq xref (list (system-name))))
8228            (setq new-xref
8229                  (concat
8230                   (mapconcat 'identity
8231                              (delete "Xref:" (delete new-xref xref))
8232                              " ")
8233                   " " new-xref))
8234            (save-excursion
8235              (set-buffer copy-buf)
8236              ;; First put the article in the destination group.
8237              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8238              (when (consp (setq art-group
8239                                 (gnus-request-accept-article
8240                                  to-newsgroup select-method (not articles))))
8241                (setq new-xref (concat new-xref " " (car art-group)
8242                                       ":"
8243                                       (number-to-string (cdr art-group))))
8244                ;; Now we have the new Xrefs header, so we insert
8245                ;; it and replace the new article.
8246                (nnheader-replace-header "Xref" new-xref)
8247                (gnus-request-replace-article
8248                 (cdr art-group) to-newsgroup (current-buffer))
8249                art-group))))))
8250       (cond
8251        ((not art-group)
8252         (gnus-message 1 "Couldn't %s article %s: %s"
8253                       (cadr (assq action names)) article
8254                       (nnheader-get-report (car to-method))))
8255        ((eq art-group 'junk)
8256         (when (eq action 'move)
8257           (gnus-summary-mark-article article gnus-canceled-mark)
8258           (gnus-message 4 "Deleted article %s" article)))
8259        (t
8260         (let* ((pto-group (gnus-group-prefixed-name
8261                            (car art-group) to-method))
8262                (entry
8263                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8264                (info (nth 2 entry))
8265                (to-group (gnus-info-group info))
8266                to-marks)
8267           ;; Update the group that has been moved to.
8268           (when (and info
8269                      (memq action '(move copy)))
8270             (unless (member to-group to-groups)
8271               (push to-group to-groups))
8272
8273             (unless (memq article gnus-newsgroup-unreads)
8274               (push 'read to-marks)
8275               (gnus-info-set-read
8276                info (gnus-add-to-range (gnus-info-read info)
8277                                        (list (cdr art-group)))))
8278
8279             ;; See whether the article is to be put in the cache.
8280             (let ((marks gnus-article-mark-lists)
8281                   (to-article (cdr art-group)))
8282
8283               ;; Enter the article into the cache in the new group,
8284               ;; if that is required.
8285               (when gnus-use-cache
8286                 (gnus-cache-possibly-enter-article
8287                  to-group to-article
8288                  (memq article gnus-newsgroup-marked)
8289                  (memq article gnus-newsgroup-dormant)
8290                  (memq article gnus-newsgroup-unreads)))
8291
8292               (when gnus-preserve-marks
8293                 ;; Copy any marks over to the new group.
8294                 (when (and (equal to-group gnus-newsgroup-name)
8295                            (not (memq article gnus-newsgroup-unreads)))
8296                   ;; Mark this article as read in this group.
8297                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8298                   (setcdr (gnus-active to-group) to-article)
8299                   (setcdr gnus-newsgroup-active to-article))
8300
8301                 (while marks
8302                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8303                     (when (memq article (symbol-value
8304                                          (intern (format "gnus-newsgroup-%s"
8305                                                          (caar marks)))))
8306                       (push (cdar marks) to-marks)
8307                       ;; If the other group is the same as this group,
8308                       ;; then we have to add the mark to the list.
8309                       (when (equal to-group gnus-newsgroup-name)
8310                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8311                              (cons to-article
8312                                    (symbol-value
8313                                     (intern (format "gnus-newsgroup-%s"
8314                                                     (caar marks)))))))
8315                       ;; Copy the marks to other group.
8316                       (gnus-add-marked-articles
8317                        to-group (cdar marks) (list to-article) info)))
8318                   (setq marks (cdr marks)))
8319
8320                 (gnus-request-set-mark to-group (list (list (list to-article)
8321                                                             'add
8322                                                             to-marks))))
8323
8324               (gnus-dribble-enter
8325                (concat "(gnus-group-set-info '"
8326                        (gnus-prin1-to-string (gnus-get-info to-group))
8327                        ")"))))
8328
8329           ;; Update the Xref header in this article to point to
8330           ;; the new crossposted article we have just created.
8331           (when (eq action 'crosspost)
8332             (save-excursion
8333               (set-buffer copy-buf)
8334               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8335               (nnheader-replace-header "Xref" new-xref)
8336               (gnus-request-replace-article
8337                article gnus-newsgroup-name (current-buffer)))))
8338
8339         ;;;!!!Why is this necessary?
8340         (set-buffer gnus-summary-buffer)
8341
8342         (gnus-summary-goto-subject article)
8343         (when (eq action 'move)
8344           (gnus-summary-mark-article article gnus-canceled-mark))))
8345       (gnus-summary-remove-process-mark article))
8346     ;; Re-activate all groups that have been moved to.
8347     (save-excursion
8348       (set-buffer gnus-group-buffer)
8349       (let ((gnus-group-marked to-groups))
8350         (gnus-group-get-new-news-this-group nil t)))
8351
8352     (gnus-kill-buffer copy-buf)
8353     (gnus-summary-position-point)
8354     (gnus-set-mode-line 'summary)))
8355
8356 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8357   "Move the current article to a different newsgroup.
8358 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8359 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8360 re-spool using this method."
8361   (interactive "P")
8362   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8363
8364 (defun gnus-summary-crosspost-article (&optional n)
8365   "Crosspost the current article to some other group."
8366   (interactive "P")
8367   (gnus-summary-move-article n nil nil 'crosspost))
8368
8369 (defcustom gnus-summary-respool-default-method nil
8370   "Default method type for respooling an article.
8371 If nil, use to the current newsgroup method."
8372   :type 'symbol
8373   :group 'gnus-summary-mail)
8374
8375 (defun gnus-summary-respool-article (&optional n method)
8376   "Respool the current article.
8377 The article will be squeezed through the mail spooling process again,
8378 which means that it will be put in some mail newsgroup or other
8379 depending on `nnmail-split-methods'.
8380 If N is a positive number, respool the N next articles.
8381 If N is a negative number, respool the N previous articles.
8382 If N is nil and any articles have been marked with the process mark,
8383 respool those articles instead.
8384
8385 Respooling can be done both from mail groups and \"real\" newsgroups.
8386 In the former case, the articles in question will be moved from the
8387 current group into whatever groups they are destined to.  In the
8388 latter case, they will be copied into the relevant groups."
8389   (interactive
8390    (list current-prefix-arg
8391          (let* ((methods (gnus-methods-using 'respool))
8392                 (methname
8393                  (symbol-name (or gnus-summary-respool-default-method
8394                                   (car (gnus-find-method-for-group
8395                                         gnus-newsgroup-name)))))
8396                 (method
8397                  (gnus-completing-read
8398                   methname "What backend do you want to use when respooling?"
8399                   methods nil t nil 'gnus-mail-method-history))
8400                 ms)
8401            (cond
8402             ((zerop (length (setq ms (gnus-servers-using-backend
8403                                       (intern method)))))
8404              (list (intern method) ""))
8405             ((= 1 (length ms))
8406              (car ms))
8407             (t
8408              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8409                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8410                            ms-alist))))))))
8411   (unless method
8412     (error "No method given for respooling"))
8413   (if (assoc (symbol-name
8414               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8415              (gnus-methods-using 'respool))
8416       (gnus-summary-move-article n nil method)
8417     (gnus-summary-copy-article n nil method)))
8418
8419 (defun gnus-summary-import-article (file &optional edit)
8420   "Import an arbitrary file into a mail newsgroup."
8421   (interactive "fImport file: \nP")
8422   (let ((group gnus-newsgroup-name)
8423         (now (current-time))
8424         atts lines group-art)
8425     (unless (gnus-check-backend-function 'request-accept-article group)
8426       (error "%s does not support article importing" group))
8427     (or (file-readable-p file)
8428         (not (file-regular-p file))
8429         (error "Can't read %s" file))
8430     (save-excursion
8431       (set-buffer (gnus-get-buffer-create " *import file*"))
8432       (erase-buffer)
8433       (nnheader-insert-file-contents file)
8434       (goto-char (point-min))
8435       (if (nnheader-article-p)
8436           (save-restriction
8437             (goto-char (point-min))
8438             (search-forward "\n\n" nil t)
8439             (narrow-to-region (point-min) (1- (point)))
8440             (goto-char (point-min))
8441             (unless (re-search-forward "^date:" nil t)
8442               (goto-char (point-max))
8443               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8444        ;; This doesn't look like an article, so we fudge some headers.
8445         (setq atts (file-attributes file)
8446               lines (count-lines (point-min) (point-max)))
8447         (insert "From: " (read-string "From: ") "\n"
8448                 "Subject: " (read-string "Subject: ") "\n"
8449                 "Date: " (message-make-date (nth 5 atts)) "\n"
8450                 "Message-ID: " (message-make-message-id) "\n"
8451                 "Lines: " (int-to-string lines) "\n"
8452                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8453       (setq group-art (gnus-request-accept-article group nil t))
8454       (kill-buffer (current-buffer)))
8455     (setq gnus-newsgroup-active (gnus-activate-group group))
8456     (forward-line 1)
8457     (gnus-summary-goto-article (cdr group-art) nil t)
8458     (when edit
8459       (gnus-summary-edit-article))))
8460
8461 (defun gnus-summary-create-article ()
8462   "Create an article in a mail newsgroup."
8463   (interactive)
8464   (let ((group gnus-newsgroup-name)
8465         (now (current-time))
8466         group-art)
8467     (unless (gnus-check-backend-function 'request-accept-article group)
8468       (error "%s does not support article importing" group))
8469     (save-excursion
8470       (set-buffer (gnus-get-buffer-create " *import file*"))
8471       (erase-buffer)
8472       (goto-char (point-min))
8473       ;; This doesn't look like an article, so we fudge some headers.
8474       (insert "From: " (read-string "From: ") "\n"
8475               "Subject: " (read-string "Subject: ") "\n"
8476               "Date: " (message-make-date now) "\n"
8477               "Message-ID: " (message-make-message-id) "\n")
8478       (setq group-art (gnus-request-accept-article group nil t))
8479       (kill-buffer (current-buffer)))
8480     (setq gnus-newsgroup-active (gnus-activate-group group))
8481     (forward-line 1)
8482     (gnus-summary-goto-article (cdr group-art) nil t)
8483     (gnus-summary-edit-article)))
8484
8485 (defun gnus-summary-article-posted-p ()
8486   "Say whether the current (mail) article is available from news as well.
8487 This will be the case if the article has both been mailed and posted."
8488   (interactive)
8489   (let ((id (mail-header-references (gnus-summary-article-header)))
8490         (gnus-override-method (car (gnus-refer-article-methods))))
8491     (if (gnus-request-head id "")
8492         (gnus-message 2 "The current message was found on %s"
8493                       gnus-override-method)
8494       (gnus-message 2 "The current message couldn't be found on %s"
8495                     gnus-override-method)
8496       nil)))
8497
8498 (defun gnus-summary-expire-articles (&optional now)
8499   "Expire all articles that are marked as expirable in the current group."
8500   (interactive)
8501   (when (gnus-check-backend-function
8502          'request-expire-articles gnus-newsgroup-name)
8503     ;; This backend supports expiry.
8504     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8505            (expirable (if total
8506                           (progn
8507                             ;; We need to update the info for
8508                             ;; this group for `gnus-list-of-read-articles'
8509                             ;; to give us the right answer.
8510                             (gnus-run-hooks 'gnus-exit-group-hook)
8511                             (gnus-summary-update-info)
8512                             (gnus-list-of-read-articles gnus-newsgroup-name))
8513                         (setq gnus-newsgroup-expirable
8514                               (sort gnus-newsgroup-expirable '<))))
8515            (expiry-wait (if now 'immediate
8516                           (gnus-group-find-parameter
8517                            gnus-newsgroup-name 'expiry-wait)))
8518            (nnmail-expiry-target
8519             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8520                 nnmail-expiry-target))
8521            es)
8522       (when expirable
8523         ;; There are expirable articles in this group, so we run them
8524         ;; through the expiry process.
8525         (gnus-message 6 "Expiring articles...")
8526         (unless (gnus-check-group gnus-newsgroup-name)
8527           (error "Can't open server for %s" gnus-newsgroup-name))
8528         ;; The list of articles that weren't expired is returned.
8529         (save-excursion
8530           (if expiry-wait
8531               (let ((nnmail-expiry-wait-function nil)
8532                     (nnmail-expiry-wait expiry-wait))
8533                 (setq es (gnus-request-expire-articles
8534                           expirable gnus-newsgroup-name)))
8535             (setq es (gnus-request-expire-articles
8536                       expirable gnus-newsgroup-name)))
8537           (unless total
8538             (setq gnus-newsgroup-expirable es))
8539           ;; We go through the old list of expirable, and mark all
8540           ;; really expired articles as nonexistent.
8541           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8542             (let ((gnus-use-cache nil))
8543               (while expirable
8544                 (unless (memq (car expirable) es)
8545                   (when (gnus-data-find (car expirable))
8546                     (gnus-summary-mark-article
8547                      (car expirable) gnus-canceled-mark)))
8548                 (setq expirable (cdr expirable))))))
8549         (gnus-message 6 "Expiring articles...done")))))
8550
8551 (defun gnus-summary-expire-articles-now ()
8552   "Expunge all expirable articles in the current group.
8553 This means that *all* articles that are marked as expirable will be
8554 deleted forever, right now."
8555   (interactive)
8556   (or gnus-expert-user
8557       (gnus-yes-or-no-p
8558        "Are you really, really, really sure you want to delete all these messages? ")
8559       (error "Phew!"))
8560   (gnus-summary-expire-articles t))
8561
8562 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8563 (defun gnus-summary-delete-article (&optional n)
8564   "Delete the N next (mail) articles.
8565 This command actually deletes articles.  This is not a marking
8566 command.  The article will disappear forever from your life, never to
8567 return.
8568 If N is negative, delete backwards.
8569 If N is nil and articles have been marked with the process mark,
8570 delete these instead."
8571   (interactive "P")
8572   (unless (gnus-check-backend-function 'request-expire-articles
8573                                        gnus-newsgroup-name)
8574     (error "The current newsgroup does not support article deletion"))
8575   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8576     (error "Couldn't open server"))
8577   ;; Compute the list of articles to delete.
8578   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8579         not-deleted)
8580     (if (and gnus-novice-user
8581              (not (gnus-yes-or-no-p
8582                    (format "Do you really want to delete %s forever? "
8583                            (if (> (length articles) 1)
8584                                (format "these %s articles" (length articles))
8585                              "this article")))))
8586         ()
8587       ;; Delete the articles.
8588       (setq not-deleted (gnus-request-expire-articles
8589                          articles gnus-newsgroup-name 'force))
8590       (while articles
8591         (gnus-summary-remove-process-mark (car articles))
8592         ;; The backend might not have been able to delete the article
8593         ;; after all.
8594         (unless (memq (car articles) not-deleted)
8595           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8596         (setq articles (cdr articles)))
8597       (when not-deleted
8598         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8599     (gnus-summary-position-point)
8600     (gnus-set-mode-line 'summary)
8601     not-deleted))
8602
8603 (defun gnus-summary-edit-article (&optional arg)
8604   "Edit the current article.
8605 This will have permanent effect only in mail groups.
8606 If ARG is nil, edit the decoded articles.
8607 If ARG is 1, edit the raw articles.
8608 If ARG is 2, edit the raw articles even in read-only groups.
8609 If ARG is 3, edit the articles with the current handles.
8610 Otherwise, allow editing of articles even in read-only
8611 groups."
8612   (interactive "P")
8613   (let (force raw current-handles)
8614     (cond
8615      ((null arg))
8616      ((eq arg 1) (setq raw t))
8617      ((eq arg 2) (setq raw t
8618                        force t))
8619      ((eq arg 3) (setq current-handles
8620                        (and (gnus-buffer-live-p gnus-article-buffer)
8621                             (with-current-buffer gnus-article-buffer
8622                               (prog1
8623                                   gnus-article-mime-handles
8624                                 (setq gnus-article-mime-handles nil))))))
8625      (t (setq force t)))
8626     (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8627         (error "Can't edit the raw article in group nndraft:drafts"))
8628     (save-excursion
8629       (set-buffer gnus-summary-buffer)
8630       (let ((mail-parse-charset gnus-newsgroup-charset)
8631             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8632         (gnus-set-global-variables)
8633         (when (and (not force)
8634                    (gnus-group-read-only-p))
8635           (error "The current newsgroup does not support article editing"))
8636         (gnus-summary-show-article t)
8637         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8638           (with-current-buffer gnus-article-buffer
8639             (mm-enable-multibyte-mule4)))
8640         (if (equal gnus-newsgroup-name "nndraft:drafts")
8641             (setq raw t))
8642         (gnus-article-edit-article
8643          (if raw 'ignore
8644            `(lambda ()
8645               (let ((mbl mml-buffer-list))
8646                 (setq mml-buffer-list nil)
8647                 (mime-to-mml ,'current-handles)
8648                 (let ((mbl1 mml-buffer-list))
8649                   (setq mml-buffer-list mbl)
8650                   (set (make-local-variable 'mml-buffer-list) mbl1))
8651                 (make-local-hook 'kill-buffer-hook)
8652                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8653          `(lambda (no-highlight)
8654             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8655                   (message-options message-options)
8656                   (message-options-set-recipient)
8657                   (mail-parse-ignored-charsets
8658                    ',gnus-newsgroup-ignored-charsets))
8659               ,(if (not raw) '(progn
8660                                 (mml-to-mime)
8661                                 (mml-destroy-buffers)
8662                                 (remove-hook 'kill-buffer-hook
8663                                              'mml-destroy-buffers t)
8664                                 (kill-local-variable 'mml-buffer-list)))
8665               (gnus-summary-edit-article-done
8666                ,(or (mail-header-references gnus-current-headers) "")
8667                ,(gnus-group-read-only-p)
8668                ,gnus-summary-buffer no-highlight))))))))
8669
8670 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8671
8672 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8673                                                  no-highlight)
8674   "Make edits to the current article permanent."
8675   (interactive)
8676   (save-excursion
8677    ;; The buffer restriction contains the entire article if it exists.
8678     (when (article-goto-body)
8679       (let ((lines (count-lines (point) (point-max)))
8680             (length (- (point-max) (point)))
8681             (case-fold-search t)
8682             (body (copy-marker (point))))
8683         (goto-char (point-min))
8684         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8685           (delete-region (match-beginning 1) (match-end 1))
8686           (insert (number-to-string length)))
8687         (goto-char (point-min))
8688         (when (re-search-forward
8689                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8690           (delete-region (match-beginning 1) (match-end 1))
8691           (insert (number-to-string length)))
8692         (goto-char (point-min))
8693         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8694           (delete-region (match-beginning 1) (match-end 1))
8695           (insert (number-to-string lines))))))
8696   ;; Replace the article.
8697   (let ((buf (current-buffer)))
8698     (with-temp-buffer
8699       (insert-buffer-substring buf)
8700
8701       (if (and (not read-only)
8702                (not (gnus-request-replace-article
8703                      (cdr gnus-article-current) (car gnus-article-current)
8704                      (current-buffer) t)))
8705           (error "Couldn't replace article")
8706         ;; Update the summary buffer.
8707         (if (and references
8708                  (equal (message-tokenize-header references " ")
8709                         (message-tokenize-header
8710                          (or (message-fetch-field "references") "") " ")))
8711             ;; We only have to update this line.
8712             (save-excursion
8713               (save-restriction
8714                 (message-narrow-to-head)
8715                 (let ((head (buffer-string))
8716                       header)
8717                   (with-temp-buffer
8718                     (insert (format "211 %d Article retrieved.\n"
8719                                     (cdr gnus-article-current)))
8720                     (insert head)
8721                     (insert ".\n")
8722                     (let ((nntp-server-buffer (current-buffer)))
8723                       (setq header (car (gnus-get-newsgroup-headers
8724                                          (save-excursion
8725                                            (set-buffer gnus-summary-buffer)
8726                                            gnus-newsgroup-dependencies)
8727                                          t))))
8728                     (save-excursion
8729                       (set-buffer gnus-summary-buffer)
8730                       (gnus-data-set-header
8731                        (gnus-data-find (cdr gnus-article-current))
8732                        header)
8733                       (gnus-summary-update-article-line
8734                        (cdr gnus-article-current) header)
8735                       (if (gnus-summary-goto-subject
8736                            (cdr gnus-article-current) nil t)
8737                           (gnus-summary-update-secondary-mark
8738                            (cdr gnus-article-current))))))))
8739           ;; Update threads.
8740           (set-buffer (or buffer gnus-summary-buffer))
8741           (gnus-summary-update-article (cdr gnus-article-current))
8742           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8743               (gnus-summary-update-secondary-mark
8744                (cdr gnus-article-current))))
8745         ;; Prettify the article buffer again.
8746         (unless no-highlight
8747           (save-excursion
8748             (set-buffer gnus-article-buffer)
8749             ;;;!!! Fix this -- article should be rehighlighted.
8750             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8751             (set-buffer gnus-original-article-buffer)
8752             (gnus-request-article
8753              (cdr gnus-article-current)
8754              (car gnus-article-current) (current-buffer))))
8755         ;; Prettify the summary buffer line.
8756         (when (gnus-visual-p 'summary-highlight 'highlight)
8757           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8758
8759 (defun gnus-summary-edit-wash (key)
8760   "Perform editing command KEY in the article buffer."
8761   (interactive
8762    (list
8763     (progn
8764       (message "%s" (concat (this-command-keys) "- "))
8765       (read-char))))
8766   (message "")
8767   (gnus-summary-edit-article)
8768   (execute-kbd-macro (concat (this-command-keys) key))
8769   (gnus-article-edit-done))
8770
8771
8772 (defun gnus-summary-toggle-smiley (&optional arg)
8773   "Toggle the display of smilies as small graphical icons."
8774   (interactive "P")
8775   (save-excursion
8776     (set-buffer gnus-article-buffer)
8777     (gnus-smiley-display arg)))
8778
8779 ;;; Respooling
8780
8781 (defun gnus-summary-respool-query (&optional silent trace)
8782   "Query where the respool algorithm would put this article."
8783   (interactive)
8784   (let (gnus-mark-article-hook)
8785     (gnus-summary-select-article)
8786     (save-excursion
8787       (set-buffer gnus-original-article-buffer)
8788       (save-restriction
8789         (message-narrow-to-head)
8790         (let ((groups (nnmail-article-group 'identity trace)))
8791           (unless silent
8792             (if groups
8793                 (message "This message would go to %s"
8794                          (mapconcat 'car groups ", "))
8795               (message "This message would go to no groups"))
8796             groups))))))
8797
8798 (defun gnus-summary-respool-trace ()
8799   "Trace where the respool algorithm would put this article.
8800 Display a buffer showing all fancy splitting patterns which matched."
8801   (interactive)
8802   (gnus-summary-respool-query nil t))
8803
8804 ;; Summary marking commands.
8805
8806 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8807   "Mark articles which has the same subject as read, and then select the next.
8808 If UNMARK is positive, remove any kind of mark.
8809 If UNMARK is negative, tick articles."
8810   (interactive "P")
8811   (when unmark
8812     (setq unmark (prefix-numeric-value unmark)))
8813   (let ((count
8814          (gnus-summary-mark-same-subject
8815           (gnus-summary-article-subject) unmark)))
8816     ;; Select next unread article.  If auto-select-same mode, should
8817     ;; select the first unread article.
8818     (gnus-summary-next-article t (and gnus-auto-select-same
8819                                       (gnus-summary-article-subject)))
8820     (gnus-message 7 "%d article%s marked as %s"
8821                   count (if (= count 1) " is" "s are")
8822                   (if unmark "unread" "read"))))
8823
8824 (defun gnus-summary-kill-same-subject (&optional unmark)
8825   "Mark articles which has the same subject as read.
8826 If UNMARK is positive, remove any kind of mark.
8827 If UNMARK is negative, tick articles."
8828   (interactive "P")
8829   (when unmark
8830     (setq unmark (prefix-numeric-value unmark)))
8831   (let ((count
8832          (gnus-summary-mark-same-subject
8833           (gnus-summary-article-subject) unmark)))
8834     ;; If marked as read, go to next unread subject.
8835     (when (null unmark)
8836       ;; Go to next unread subject.
8837       (gnus-summary-next-subject 1 t))
8838     (gnus-message 7 "%d articles are marked as %s"
8839                   count (if unmark "unread" "read"))))
8840
8841 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8842   "Mark articles with same SUBJECT as read, and return marked number.
8843 If optional argument UNMARK is positive, remove any kinds of marks.
8844 If optional argument UNMARK is negative, mark articles as unread instead."
8845   (let ((count 1))
8846     (save-excursion
8847       (cond
8848        ((null unmark)                   ; Mark as read.
8849         (while (and
8850                 (progn
8851                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8852                   (gnus-summary-show-thread) t)
8853                 (gnus-summary-find-subject subject))
8854           (setq count (1+ count))))
8855        ((> unmark 0)                    ; Tick.
8856         (while (and
8857                 (progn
8858                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8859                   (gnus-summary-show-thread) t)
8860                 (gnus-summary-find-subject subject))
8861           (setq count (1+ count))))
8862        (t                               ; Mark as unread.
8863         (while (and
8864                 (progn
8865                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8866                   (gnus-summary-show-thread) t)
8867                 (gnus-summary-find-subject subject))
8868           (setq count (1+ count)))))
8869       (gnus-set-mode-line 'summary)
8870       ;; Return the number of marked articles.
8871       count)))
8872
8873 (defun gnus-summary-mark-as-processable (n &optional unmark)
8874   "Set the process mark on the next N articles.
8875 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8876 the process mark instead.  The difference between N and the actual
8877 number of articles marked is returned."
8878   (interactive "P")
8879   (if (and (null n) (gnus-region-active-p))
8880       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8881     (setq n (prefix-numeric-value n))
8882     (let ((backward (< n 0))
8883           (n (abs n)))
8884       (while (and
8885               (> n 0)
8886               (if unmark
8887                   (gnus-summary-remove-process-mark
8888                    (gnus-summary-article-number))
8889                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8890               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8891         (setq n (1- n)))
8892       (when (/= 0 n)
8893         (gnus-message 7 "No more articles"))
8894       (gnus-summary-recenter)
8895       (gnus-summary-position-point)
8896       n)))
8897
8898 (defun gnus-summary-unmark-as-processable (n)
8899   "Remove the process mark from the next N articles.
8900 If N is negative, unmark backward instead.  The difference between N and
8901 the actual number of articles unmarked is returned."
8902   (interactive "P")
8903   (gnus-summary-mark-as-processable n t))
8904
8905 (defun gnus-summary-unmark-all-processable ()
8906   "Remove the process mark from all articles."
8907   (interactive)
8908   (save-excursion
8909     (while gnus-newsgroup-processable
8910       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8911   (gnus-summary-position-point))
8912
8913 (defun gnus-summary-add-mark (article type)
8914   "Mark ARTICLE with a mark of TYPE."
8915   (let ((vtype (car (assq type gnus-article-mark-lists)))
8916         var)
8917     (if (not vtype)
8918         (error "No such mark type: %s" type)
8919       (setq var (intern (format "gnus-newsgroup-%s" type)))
8920       (set var (cons article (symbol-value var)))
8921       (if (memq type '(processable cached replied forwarded recent saved))
8922           (gnus-summary-update-secondary-mark article)
8923         ;;; !!! This is bogus.  We should find out what primary
8924         ;;; !!! mark we want to set.
8925         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8926
8927 (defun gnus-summary-mark-as-expirable (n)
8928   "Mark N articles forward as expirable.
8929 If N is negative, mark backward instead.  The difference between N and
8930 the actual number of articles marked is returned."
8931   (interactive "p")
8932   (gnus-summary-mark-forward n gnus-expirable-mark))
8933
8934 (defun gnus-summary-mark-article-as-replied (article)
8935   "Mark ARTICLE as replied to and update the summary line.
8936 ARTICLE can also be a list of articles."
8937   (interactive (list (gnus-summary-article-number)))
8938   (let ((articles (if (listp article) article (list article))))
8939     (dolist (article articles)
8940       (push article gnus-newsgroup-replied)
8941       (let ((buffer-read-only nil))
8942         (when (gnus-summary-goto-subject article nil t)
8943           (gnus-summary-update-secondary-mark article))))))
8944
8945 (defun gnus-summary-mark-article-as-forwarded (article)
8946   "Mark ARTICLE as forwarded and update the summary line.
8947 ARTICLE can also be a list of articles."
8948   (let ((articles (if (listp article) article (list article))))
8949     (dolist (article articles)
8950       (push article gnus-newsgroup-forwarded)
8951       (let ((buffer-read-only nil))
8952         (when (gnus-summary-goto-subject article nil t)
8953           (gnus-summary-update-secondary-mark article))))))
8954
8955 (defun gnus-summary-set-bookmark (article)
8956   "Set a bookmark in current article."
8957   (interactive (list (gnus-summary-article-number)))
8958   (when (or (not (get-buffer gnus-article-buffer))
8959             (not gnus-current-article)
8960             (not gnus-article-current)
8961             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8962     (error "No current article selected"))
8963   ;; Remove old bookmark, if one exists.
8964   (let ((old (assq article gnus-newsgroup-bookmarks)))
8965     (when old
8966       (setq gnus-newsgroup-bookmarks
8967             (delq old gnus-newsgroup-bookmarks))))
8968   ;; Set the new bookmark, which is on the form
8969   ;; (article-number . line-number-in-body).
8970   (push
8971    (cons article
8972          (save-excursion
8973            (set-buffer gnus-article-buffer)
8974            (count-lines
8975             (min (point)
8976                  (save-excursion
8977                    (goto-char (point-min))
8978                    (search-forward "\n\n" nil t)
8979                    (point)))
8980             (point))))
8981    gnus-newsgroup-bookmarks)
8982   (gnus-message 6 "A bookmark has been added to the current article."))
8983
8984 (defun gnus-summary-remove-bookmark (article)
8985   "Remove the bookmark from the current article."
8986   (interactive (list (gnus-summary-article-number)))
8987   ;; Remove old bookmark, if one exists.
8988   (let ((old (assq article gnus-newsgroup-bookmarks)))
8989     (if old
8990         (progn
8991           (setq gnus-newsgroup-bookmarks
8992                 (delq old gnus-newsgroup-bookmarks))
8993           (gnus-message 6 "Removed bookmark."))
8994       (gnus-message 6 "No bookmark in current article."))))
8995
8996 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8997 (defun gnus-summary-mark-as-dormant (n)
8998   "Mark N articles forward as dormant.
8999 If N is negative, mark backward instead.  The difference between N and
9000 the actual number of articles marked is returned."
9001   (interactive "p")
9002   (gnus-summary-mark-forward n gnus-dormant-mark))
9003
9004 (defun gnus-summary-set-process-mark (article)
9005   "Set the process mark on ARTICLE and update the summary line."
9006   (setq gnus-newsgroup-processable
9007         (cons article
9008               (delq article gnus-newsgroup-processable)))
9009   (when (gnus-summary-goto-subject article)
9010     (gnus-summary-show-thread)
9011     (gnus-summary-goto-subject article)
9012     (gnus-summary-update-secondary-mark article)))
9013
9014 (defun gnus-summary-remove-process-mark (article)
9015   "Remove the process mark from ARTICLE and update the summary line."
9016   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9017   (when (gnus-summary-goto-subject article)
9018     (gnus-summary-show-thread)
9019     (gnus-summary-goto-subject article)
9020     (gnus-summary-update-secondary-mark article)))
9021
9022 (defun gnus-summary-set-saved-mark (article)
9023   "Set the process mark on ARTICLE and update the summary line."
9024   (push article gnus-newsgroup-saved)
9025   (when (gnus-summary-goto-subject article)
9026     (gnus-summary-update-secondary-mark article)))
9027
9028 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9029   "Mark N articles as read forwards.
9030 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9031 The difference between N and the actual number of articles marked is
9032 returned.
9033 Iff NO-EXPIRE, auto-expiry will be inhibited."
9034   (interactive "p")
9035   (gnus-summary-show-thread)
9036   (let ((backward (< n 0))
9037         (gnus-summary-goto-unread
9038          (and gnus-summary-goto-unread
9039               (not (eq gnus-summary-goto-unread 'never))
9040               (not (memq mark (list gnus-unread-mark
9041                                     gnus-ticked-mark gnus-dormant-mark)))))
9042         (n (abs n))
9043         (mark (or mark gnus-del-mark)))
9044     (while (and (> n 0)
9045                 (gnus-summary-mark-article nil mark no-expire)
9046                 (zerop (gnus-summary-next-subject
9047                         (if backward -1 1)
9048                         (and gnus-summary-goto-unread
9049                              (not (eq gnus-summary-goto-unread 'never)))
9050                         t)))
9051       (setq n (1- n)))
9052     (when (/= 0 n)
9053       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9054     (gnus-summary-recenter)
9055     (gnus-summary-position-point)
9056     (gnus-set-mode-line 'summary)
9057     n))
9058
9059 (defun gnus-summary-mark-article-as-read (mark)
9060   "Mark the current article quickly as read with MARK."
9061   (let ((article (gnus-summary-article-number)))
9062     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9063     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9064     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9065     (push (cons article mark) gnus-newsgroup-reads)
9066     ;; Possibly remove from cache, if that is used.
9067     (when gnus-use-cache
9068       (gnus-cache-enter-remove-article article))
9069     ;; Allow the backend to change the mark.
9070     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9071     ;; Check for auto-expiry.
9072     (when (and gnus-newsgroup-auto-expire
9073                (memq mark gnus-auto-expirable-marks))
9074       (setq mark gnus-expirable-mark)
9075       ;; Let the backend know about the mark change.
9076       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9077       (push article gnus-newsgroup-expirable))
9078     ;; Set the mark in the buffer.
9079     (gnus-summary-update-mark mark 'unread)
9080     t))
9081
9082 (defun gnus-summary-mark-article-as-unread (mark)
9083   "Mark the current article quickly as unread with MARK."
9084   (let* ((article (gnus-summary-article-number))
9085          (old-mark (gnus-summary-article-mark article)))
9086     ;; Allow the backend to change the mark.
9087     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9088     (if (eq mark old-mark)
9089         t
9090       (if (<= article 0)
9091           (progn
9092             (gnus-error 1 "Can't mark negative article numbers")
9093             nil)
9094         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9095         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9096         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9097         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9098         (cond ((= mark gnus-ticked-mark)
9099                (push article gnus-newsgroup-marked))
9100               ((= mark gnus-dormant-mark)
9101                (push article gnus-newsgroup-dormant))
9102               (t
9103                (push article gnus-newsgroup-unreads)))
9104         (gnus-pull article gnus-newsgroup-reads)
9105
9106         ;; See whether the article is to be put in the cache.
9107         (and gnus-use-cache
9108              (vectorp (gnus-summary-article-header article))
9109              (save-excursion
9110                (gnus-cache-possibly-enter-article
9111                 gnus-newsgroup-name article
9112                 (= mark gnus-ticked-mark)
9113                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9114
9115         ;; Fix the mark.
9116         (gnus-summary-update-mark mark 'unread)
9117         t))))
9118
9119 (defun gnus-summary-mark-article (&optional article mark no-expire)
9120   "Mark ARTICLE with MARK.  MARK can be any character.
9121 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9122 `??' (dormant) and `?E' (expirable).
9123 If MARK is nil, then the default character `?r' is used.
9124 If ARTICLE is nil, then the article on the current line will be
9125 marked.
9126 Iff NO-EXPIRE, auto-expiry will be inhibited."
9127   ;; The mark might be a string.
9128   (when (stringp mark)
9129     (setq mark (aref mark 0)))
9130   ;; If no mark is given, then we check auto-expiring.
9131   (when (null mark)
9132     (setq mark gnus-del-mark))
9133   (when (and (not no-expire)
9134              gnus-newsgroup-auto-expire
9135              (memq mark gnus-auto-expirable-marks))
9136     (setq mark gnus-expirable-mark))
9137   (let ((article (or article (gnus-summary-article-number)))
9138         (old-mark (gnus-summary-article-mark article)))
9139     ;; Allow the backend to change the mark.
9140     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9141     (if (eq mark old-mark)
9142         t
9143       (unless article
9144         (error "No article on current line"))
9145       (if (not (if (or (= mark gnus-unread-mark)
9146                        (= mark gnus-ticked-mark)
9147                        (= mark gnus-dormant-mark))
9148                    (gnus-mark-article-as-unread article mark)
9149                  (gnus-mark-article-as-read article mark)))
9150           t
9151         ;; See whether the article is to be put in the cache.
9152         (and gnus-use-cache
9153              (not (= mark gnus-canceled-mark))
9154              (vectorp (gnus-summary-article-header article))
9155              (save-excursion
9156                (gnus-cache-possibly-enter-article
9157                 gnus-newsgroup-name article
9158                 (= mark gnus-ticked-mark)
9159                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9160
9161         (when (gnus-summary-goto-subject article nil t)
9162           (let ((buffer-read-only nil))
9163             (gnus-summary-show-thread)
9164             ;; Fix the mark.
9165             (gnus-summary-update-mark mark 'unread)
9166             t))))))
9167
9168 (defun gnus-summary-update-secondary-mark (article)
9169   "Update the secondary (read, process, cache) mark."
9170   (gnus-summary-update-mark
9171    (cond ((memq article gnus-newsgroup-processable)
9172           gnus-process-mark)
9173          ((memq article gnus-newsgroup-cached)
9174           gnus-cached-mark)
9175          ((memq article gnus-newsgroup-replied)
9176           gnus-replied-mark)
9177          ((memq article gnus-newsgroup-forwarded)
9178           gnus-forwarded-mark)
9179          ((memq article gnus-newsgroup-saved)
9180           gnus-saved-mark)
9181          ((memq article gnus-newsgroup-recent)
9182           gnus-recent-mark)
9183          ((memq article gnus-newsgroup-unseen)
9184           gnus-unseen-mark)
9185          (t gnus-no-mark))
9186    'replied)
9187   (when (gnus-visual-p 'summary-highlight 'highlight)
9188     (gnus-run-hooks 'gnus-summary-update-hook))
9189   t)
9190
9191 (defun gnus-summary-update-mark (mark type)
9192   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9193         (buffer-read-only nil))
9194     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9195     (when forward
9196       (when (looking-at "\r")
9197         (incf forward))
9198       (when (<= (+ forward (point)) (point-max))
9199         ;; Go to the right position on the line.
9200         (goto-char (+ forward (point)))
9201         ;; Replace the old mark with the new mark.
9202         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9203         ;; Optionally update the marks by some user rule.
9204         (when (eq type 'unread)
9205           (gnus-data-set-mark
9206            (gnus-data-find (gnus-summary-article-number)) mark)
9207           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9208
9209 (defun gnus-mark-article-as-read (article &optional mark)
9210   "Enter ARTICLE in the pertinent lists and remove it from others."
9211   ;; Make the article expirable.
9212   (let ((mark (or mark gnus-del-mark)))
9213     (if (= mark gnus-expirable-mark)
9214         (push article gnus-newsgroup-expirable)
9215       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9216     ;; Remove from unread and marked lists.
9217     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9218     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9219     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9220     (push (cons article mark) gnus-newsgroup-reads)
9221     ;; Possibly remove from cache, if that is used.
9222     (when gnus-use-cache
9223       (gnus-cache-enter-remove-article article))
9224     t))
9225
9226 (defun gnus-mark-article-as-unread (article &optional mark)
9227   "Enter ARTICLE in the pertinent lists and remove it from others."
9228   (let ((mark (or mark gnus-ticked-mark)))
9229     (if (<= article 0)
9230         (progn
9231           (gnus-error 1 "Can't mark negative article numbers")
9232           nil)
9233       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9234             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9235             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9236             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9237
9238       ;; Unsuppress duplicates?
9239       (when gnus-suppress-duplicates
9240         (gnus-dup-unsuppress-article article))
9241
9242       (cond ((= mark gnus-ticked-mark)
9243              (push article gnus-newsgroup-marked))
9244             ((= mark gnus-dormant-mark)
9245              (push article gnus-newsgroup-dormant))
9246             (t
9247              (push article gnus-newsgroup-unreads)))
9248       (gnus-pull article gnus-newsgroup-reads)
9249       t)))
9250
9251 (defalias 'gnus-summary-mark-as-unread-forward
9252   'gnus-summary-tick-article-forward)
9253 (make-obsolete 'gnus-summary-mark-as-unread-forward
9254                'gnus-summary-tick-article-forward)
9255 (defun gnus-summary-tick-article-forward (n)
9256   "Tick N articles forwards.
9257 If N is negative, tick backwards instead.
9258 The difference between N and the number of articles ticked is returned."
9259   (interactive "p")
9260   (gnus-summary-mark-forward n gnus-ticked-mark))
9261
9262 (defalias 'gnus-summary-mark-as-unread-backward
9263   'gnus-summary-tick-article-backward)
9264 (make-obsolete 'gnus-summary-mark-as-unread-backward
9265                'gnus-summary-tick-article-backward)
9266 (defun gnus-summary-tick-article-backward (n)
9267   "Tick N articles backwards.
9268 The difference between N and the number of articles ticked is returned."
9269   (interactive "p")
9270   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9271
9272 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9273 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9274 (defun gnus-summary-tick-article (&optional article clear-mark)
9275   "Mark current article as unread.
9276 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9277 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9278   (interactive)
9279   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9280                                        gnus-ticked-mark)))
9281
9282 (defun gnus-summary-mark-as-read-forward (n)
9283   "Mark N articles as read forwards.
9284 If N is negative, mark backwards instead.
9285 The difference between N and the actual number of articles marked is
9286 returned."
9287   (interactive "p")
9288   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9289
9290 (defun gnus-summary-mark-as-read-backward (n)
9291   "Mark the N articles as read backwards.
9292 The difference between N and the actual number of articles marked is
9293 returned."
9294   (interactive "p")
9295   (gnus-summary-mark-forward
9296    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9297
9298 (defun gnus-summary-mark-as-read (&optional article mark)
9299   "Mark current article as read.
9300 ARTICLE specifies the article to be marked as read.
9301 MARK specifies a string to be inserted at the beginning of the line."
9302   (gnus-summary-mark-article article mark))
9303
9304 (defun gnus-summary-clear-mark-forward (n)
9305   "Clear marks from N articles forward.
9306 If N is negative, clear backward instead.
9307 The difference between N and the number of marks cleared is returned."
9308   (interactive "p")
9309   (gnus-summary-mark-forward n gnus-unread-mark))
9310
9311 (defun gnus-summary-clear-mark-backward (n)
9312   "Clear marks from N articles backward.
9313 The difference between N and the number of marks cleared is returned."
9314   (interactive "p")
9315   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9316
9317 (defun gnus-summary-mark-unread-as-read ()
9318   "Intended to be used by `gnus-summary-mark-article-hook'."
9319   (when (memq gnus-current-article gnus-newsgroup-unreads)
9320     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9321
9322 (defun gnus-summary-mark-read-and-unread-as-read ()
9323   "Intended to be used by `gnus-summary-mark-article-hook'."
9324   (let ((mark (gnus-summary-article-mark)))
9325     (when (or (gnus-unread-mark-p mark)
9326               (gnus-read-mark-p mark))
9327       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9328
9329 (defun gnus-summary-mark-unread-as-ticked ()
9330   "Intended to be used by `gnus-summary-mark-article-hook'."
9331   (when (memq gnus-current-article gnus-newsgroup-unreads)
9332     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9333
9334 (defun gnus-summary-mark-region-as-read (point mark all)
9335   "Mark all unread articles between point and mark as read.
9336 If given a prefix, mark all articles between point and mark as read,
9337 even ticked and dormant ones."
9338   (interactive "r\nP")
9339   (save-excursion
9340     (let (article)
9341       (goto-char point)
9342       (beginning-of-line)
9343       (while (and
9344               (< (point) mark)
9345               (progn
9346                 (when (or all
9347                           (memq (setq article (gnus-summary-article-number))
9348                                 gnus-newsgroup-unreads))
9349                   (gnus-summary-mark-article article gnus-del-mark))
9350                 t)
9351               (gnus-summary-find-next))))))
9352
9353 (defun gnus-summary-mark-below (score mark)
9354   "Mark articles with score less than SCORE with MARK."
9355   (interactive "P\ncMark: ")
9356   (setq score (if score
9357                   (prefix-numeric-value score)
9358                 (or gnus-summary-default-score 0)))
9359   (save-excursion
9360     (set-buffer gnus-summary-buffer)
9361     (goto-char (point-min))
9362     (while
9363         (progn
9364           (and (< (gnus-summary-article-score) score)
9365                (gnus-summary-mark-article nil mark))
9366           (gnus-summary-find-next)))))
9367
9368 (defun gnus-summary-kill-below (&optional score)
9369   "Mark articles with score below SCORE as read."
9370   (interactive "P")
9371   (gnus-summary-mark-below score gnus-killed-mark))
9372
9373 (defun gnus-summary-clear-above (&optional score)
9374   "Clear all marks from articles with score above SCORE."
9375   (interactive "P")
9376   (gnus-summary-mark-above score gnus-unread-mark))
9377
9378 (defun gnus-summary-tick-above (&optional score)
9379   "Tick all articles with score above SCORE."
9380   (interactive "P")
9381   (gnus-summary-mark-above score gnus-ticked-mark))
9382
9383 (defun gnus-summary-mark-above (score mark)
9384   "Mark articles with score over SCORE with MARK."
9385   (interactive "P\ncMark: ")
9386   (setq score (if score
9387                   (prefix-numeric-value score)
9388                 (or gnus-summary-default-score 0)))
9389   (save-excursion
9390     (set-buffer gnus-summary-buffer)
9391     (goto-char (point-min))
9392     (while (and (progn
9393                   (when (> (gnus-summary-article-score) score)
9394                     (gnus-summary-mark-article nil mark))
9395                   t)
9396                 (gnus-summary-find-next)))))
9397
9398 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9399 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9400 (defun gnus-summary-limit-include-expunged (&optional no-error)
9401   "Display all the hidden articles that were expunged for low scores."
9402   (interactive)
9403   (let ((buffer-read-only nil))
9404     (let ((scored gnus-newsgroup-scored)
9405           headers h)
9406       (while scored
9407         (unless (gnus-summary-article-header (caar scored))
9408           (and (setq h (gnus-number-to-header (caar scored)))
9409                (< (cdar scored) gnus-summary-expunge-below)
9410                (push h headers)))
9411         (setq scored (cdr scored)))
9412       (if (not headers)
9413           (when (not no-error)
9414             (error "No expunged articles hidden"))
9415         (goto-char (point-min))
9416         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9417         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9418         (mapcar (lambda (x) (push (mail-header-number x)
9419                                   gnus-newsgroup-limit))
9420                 headers)
9421         (gnus-summary-prepare-unthreaded (nreverse headers))
9422         (goto-char (point-min))
9423         (gnus-summary-position-point)
9424         t))))
9425
9426 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9427   "Mark all unread articles in this newsgroup as read.
9428 If prefix argument ALL is non-nil, ticked and dormant articles will
9429 also be marked as read.
9430 If QUIETLY is non-nil, no questions will be asked.
9431 If TO-HERE is non-nil, it should be a point in the buffer.  All
9432 articles before (after, if REVERSE is set) this point will be marked as read.
9433 Note that this function will only catch up the unread article
9434 in the current summary buffer limitation.
9435 The number of articles marked as read is returned."
9436   (interactive "P")
9437   (prog1
9438       (save-excursion
9439         (when (or quietly
9440                   (not gnus-interactive-catchup) ;Without confirmation?
9441                   gnus-expert-user
9442                   (gnus-y-or-n-p
9443                    (if all
9444                        "Mark absolutely all articles as read? "
9445                      "Mark all unread articles as read? ")))
9446           (if (and not-mark
9447                    (not gnus-newsgroup-adaptive)
9448                    (not gnus-newsgroup-auto-expire)
9449                    (not gnus-suppress-duplicates)
9450                    (or (not gnus-use-cache)
9451                        (eq gnus-use-cache 'passive)))
9452               (progn
9453                 (when all
9454                   (setq gnus-newsgroup-marked nil
9455                         gnus-newsgroup-dormant nil))
9456                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9457             ;; We actually mark all articles as canceled, which we
9458             ;; have to do when using auto-expiry or adaptive scoring.
9459             (gnus-summary-show-all-threads)
9460             (if (and to-here reverse)
9461                 (progn
9462                   (goto-char to-here)
9463                   (while (and
9464                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9465                           (gnus-summary-find-next (not all) nil nil t))))
9466               (when (gnus-summary-first-subject (not all) t)
9467                 (while (and
9468                         (if to-here (< (point) to-here) t)
9469                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9470                         (gnus-summary-find-next (not all) nil nil t)))))
9471             (gnus-set-mode-line 'summary))
9472           t))
9473     (gnus-summary-position-point)))
9474
9475 (defun gnus-summary-catchup-to-here (&optional all)
9476   "Mark all unticked articles before the current one as read.
9477 If ALL is non-nil, also mark ticked and dormant articles as read."
9478   (interactive "P")
9479   (save-excursion
9480     (gnus-save-hidden-threads
9481       (let ((beg (point)))
9482         ;; We check that there are unread articles.
9483         (when (or all (gnus-summary-find-prev))
9484           (gnus-summary-catchup all t beg)))))
9485   (gnus-summary-position-point))
9486
9487 (defun gnus-summary-catchup-from-here (&optional all)
9488   "Mark all unticked articles after the current one as read.
9489 If ALL is non-nil, also mark ticked and dormant articles as read."
9490   (interactive "P")
9491   (save-excursion
9492     (gnus-save-hidden-threads
9493       (let ((beg (point)))
9494         ;; We check that there are unread articles.
9495         (when (or all (gnus-summary-find-next))
9496           (gnus-summary-catchup all t beg nil t)))))
9497
9498   (gnus-summary-position-point))
9499 (defun gnus-summary-catchup-all (&optional quietly)
9500   "Mark all articles in this newsgroup as read."
9501   (interactive "P")
9502   (gnus-summary-catchup t quietly))
9503
9504 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9505   "Mark all unread articles in this group as read, then exit.
9506 If prefix argument ALL is non-nil, all articles are marked as read.
9507 If QUIETLY is non-nil, no questions will be asked."
9508   (interactive "P")
9509   (when (gnus-summary-catchup all quietly nil 'fast)
9510     ;; Select next newsgroup or exit.
9511     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9512              (eq gnus-auto-select-next 'quietly))
9513         (gnus-summary-next-group nil)
9514       (gnus-summary-exit))))
9515
9516 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9517   "Mark all articles in this newsgroup as read, and then exit."
9518   (interactive "P")
9519   (gnus-summary-catchup-and-exit t quietly))
9520
9521 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9522   "Mark all articles in this group as read and select the next group.
9523 If given a prefix, mark all articles, unread as well as ticked, as
9524 read."
9525   (interactive "P")
9526   (save-excursion
9527     (gnus-summary-catchup all))
9528   (gnus-summary-next-group))
9529
9530 ;;;
9531 ;;; with article
9532 ;;;
9533
9534 (defmacro gnus-with-article (article &rest forms)
9535   "Select ARTICLE and perform FORMS in the original article buffer.
9536 Then replace the article with the result."
9537   `(progn
9538      ;; We don't want the article to be marked as read.
9539      (let (gnus-mark-article-hook)
9540        (gnus-summary-select-article t t nil ,article))
9541      (set-buffer gnus-original-article-buffer)
9542      ,@forms
9543      (if (not (gnus-check-backend-function
9544                'request-replace-article (car gnus-article-current)))
9545          (gnus-message 5 "Read-only group; not replacing")
9546        (unless (gnus-request-replace-article
9547                 ,article (car gnus-article-current)
9548                 (current-buffer) t)
9549          (error "Couldn't replace article")))
9550      ;; The cache and backlog have to be flushed somewhat.
9551      (when gnus-keep-backlog
9552        (gnus-backlog-remove-article
9553         (car gnus-article-current) (cdr gnus-article-current)))
9554      (when gnus-use-cache
9555        (gnus-cache-update-article
9556         (car gnus-article-current) (cdr gnus-article-current)))))
9557
9558 (put 'gnus-with-article 'lisp-indent-function 1)
9559 (put 'gnus-with-article 'edebug-form-spec '(form body))
9560
9561 ;; Thread-based commands.
9562
9563 (defun gnus-summary-articles-in-thread (&optional article)
9564   "Return a list of all articles in the current thread.
9565 If ARTICLE is non-nil, return all articles in the thread that starts
9566 with that article."
9567   (let* ((article (or article (gnus-summary-article-number)))
9568          (data (gnus-data-find-list article))
9569          (top-level (gnus-data-level (car data)))
9570          (top-subject
9571           (cond ((null gnus-thread-operation-ignore-subject)
9572                  (gnus-simplify-subject-re
9573                   (mail-header-subject (gnus-data-header (car data)))))
9574                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9575                  (gnus-simplify-subject-fuzzy
9576                   (mail-header-subject (gnus-data-header (car data)))))
9577                 (t nil)))
9578          (end-point (save-excursion
9579                       (if (gnus-summary-go-to-next-thread)
9580                           (point) (point-max))))
9581          articles)
9582     (while (and data
9583                 (< (gnus-data-pos (car data)) end-point))
9584       (when (or (not top-subject)
9585                 (string= top-subject
9586                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9587                              (gnus-simplify-subject-fuzzy
9588                               (mail-header-subject
9589                                (gnus-data-header (car data))))
9590                            (gnus-simplify-subject-re
9591                             (mail-header-subject
9592                              (gnus-data-header (car data)))))))
9593         (push (gnus-data-number (car data)) articles))
9594       (unless (and (setq data (cdr data))
9595                    (> (gnus-data-level (car data)) top-level))
9596         (setq data nil)))
9597     ;; Return the list of articles.
9598     (nreverse articles)))
9599
9600 (defun gnus-summary-rethread-current ()
9601   "Rethread the thread the current article is part of."
9602   (interactive)
9603   (let* ((gnus-show-threads t)
9604          (article (gnus-summary-article-number))
9605          (id (mail-header-id (gnus-summary-article-header)))
9606          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9607     (unless id
9608       (error "No article on the current line"))
9609     (gnus-rebuild-thread id)
9610     (gnus-summary-goto-subject article)))
9611
9612 (defun gnus-summary-reparent-thread ()
9613   "Make the current article child of the marked (or previous) article.
9614
9615 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9616 is non-nil or the Subject: of both articles are the same."
9617   (interactive)
9618   (unless (not (gnus-group-read-only-p))
9619     (error "The current newsgroup does not support article editing"))
9620   (unless (<= (length gnus-newsgroup-processable) 1)
9621     (error "No more than one article may be marked"))
9622   (save-window-excursion
9623     (let ((gnus-article-buffer " *reparent*")
9624           (current-article (gnus-summary-article-number))
9625           ;; First grab the marked article, otherwise one line up.
9626           (parent-article (if (not (null gnus-newsgroup-processable))
9627                               (car gnus-newsgroup-processable)
9628                             (save-excursion
9629                               (if (eq (forward-line -1) 0)
9630                                   (gnus-summary-article-number)
9631                                 (error "Beginning of summary buffer"))))))
9632       (unless (not (eq current-article parent-article))
9633         (error "An article may not be self-referential"))
9634       (let ((message-id (mail-header-id
9635                          (gnus-summary-article-header parent-article))))
9636         (unless (and message-id (not (equal message-id "")))
9637           (error "No message-id in desired parent"))
9638         (gnus-with-article current-article
9639           (save-restriction
9640             (goto-char (point-min))
9641             (message-narrow-to-head)
9642             (if (re-search-forward "^References: " nil t)
9643                 (progn
9644                   (re-search-forward "^[^ \t]" nil t)
9645                   (forward-line -1)
9646                   (end-of-line)
9647                   (insert " " message-id))
9648               (insert "References: " message-id "\n"))))
9649         (set-buffer gnus-summary-buffer)
9650         (gnus-summary-unmark-all-processable)
9651         (gnus-summary-update-article current-article)
9652         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9653             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9654         (gnus-summary-rethread-current)
9655         (gnus-message 3 "Article %d is now the child of article %d"
9656                       current-article parent-article)))))
9657
9658 (defun gnus-summary-toggle-threads (&optional arg)
9659   "Toggle showing conversation threads.
9660 If ARG is positive number, turn showing conversation threads on."
9661   (interactive "P")
9662   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9663     (setq gnus-show-threads
9664           (if (null arg) (not gnus-show-threads)
9665             (> (prefix-numeric-value arg) 0)))
9666     (gnus-summary-prepare)
9667     (gnus-summary-goto-subject current)
9668     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9669     (gnus-summary-position-point)))
9670
9671 (defun gnus-summary-show-all-threads ()
9672   "Show all threads."
9673   (interactive)
9674   (save-excursion
9675     (let ((buffer-read-only nil))
9676       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9677   (gnus-summary-position-point))
9678
9679 (defun gnus-summary-show-thread ()
9680   "Show thread subtrees.
9681 Returns nil if no thread was there to be shown."
9682   (interactive)
9683   (let ((buffer-read-only nil)
9684         (orig (point))
9685         ;; first goto end then to beg, to have point at beg after let
9686         (end (progn (end-of-line) (point)))
9687         (beg (progn (beginning-of-line) (point))))
9688     (prog1
9689         ;; Any hidden lines here?
9690         (search-forward "\r" end t)
9691       (subst-char-in-region beg end ?\^M ?\n t)
9692       (goto-char orig)
9693       (gnus-summary-position-point))))
9694
9695 (defun gnus-summary-hide-all-threads ()
9696   "Hide all thread subtrees."
9697   (interactive)
9698   (save-excursion
9699     (goto-char (point-min))
9700     (gnus-summary-hide-thread)
9701     (while (zerop (gnus-summary-next-thread 1 t))
9702       (gnus-summary-hide-thread)))
9703   (gnus-summary-position-point))
9704
9705 (defun gnus-summary-hide-thread ()
9706   "Hide thread subtrees.
9707 Returns nil if no threads were there to be hidden."
9708   (interactive)
9709   (let ((buffer-read-only nil)
9710         (start (point))
9711         (article (gnus-summary-article-number)))
9712     (goto-char start)
9713     ;; Go forward until either the buffer ends or the subthread
9714     ;; ends.
9715     (when (and (not (eobp))
9716                (or (zerop (gnus-summary-next-thread 1 t))
9717                    (goto-char (point-max))))
9718       (prog1
9719           (if (and (> (point) start)
9720                    (search-backward "\n" start t))
9721               (progn
9722                 (subst-char-in-region start (point) ?\n ?\^M)
9723                 (gnus-summary-goto-subject article))
9724             (goto-char start)
9725             nil)))))
9726
9727 (defun gnus-summary-go-to-next-thread (&optional previous)
9728   "Go to the same level (or less) next thread.
9729 If PREVIOUS is non-nil, go to previous thread instead.
9730 Return the article number moved to, or nil if moving was impossible."
9731   (let ((level (gnus-summary-thread-level))
9732         (way (if previous -1 1))
9733         (beg (point)))
9734     (forward-line way)
9735     (while (and (not (eobp))
9736                 (< level (gnus-summary-thread-level)))
9737       (forward-line way))
9738     (if (eobp)
9739         (progn
9740           (goto-char beg)
9741           nil)
9742       (setq beg (point))
9743       (prog1
9744           (gnus-summary-article-number)
9745         (goto-char beg)))))
9746
9747 (defun gnus-summary-next-thread (n &optional silent)
9748   "Go to the same level next N'th thread.
9749 If N is negative, search backward instead.
9750 Returns the difference between N and the number of skips actually
9751 done.
9752
9753 If SILENT, don't output messages."
9754   (interactive "p")
9755   (let ((backward (< n 0))
9756         (n (abs n)))
9757     (while (and (> n 0)
9758                 (gnus-summary-go-to-next-thread backward))
9759       (decf n))
9760     (unless silent
9761       (gnus-summary-position-point))
9762     (when (and (not silent) (/= 0 n))
9763       (gnus-message 7 "No more threads"))
9764     n))
9765
9766 (defun gnus-summary-prev-thread (n)
9767   "Go to the same level previous N'th thread.
9768 Returns the difference between N and the number of skips actually
9769 done."
9770   (interactive "p")
9771   (gnus-summary-next-thread (- n)))
9772
9773 (defun gnus-summary-go-down-thread ()
9774   "Go down one level in the current thread."
9775   (let ((children (gnus-summary-article-children)))
9776     (when children
9777       (gnus-summary-goto-subject (car children)))))
9778
9779 (defun gnus-summary-go-up-thread ()
9780   "Go up one level in the current thread."
9781   (let ((parent (gnus-summary-article-parent)))
9782     (when parent
9783       (gnus-summary-goto-subject parent))))
9784
9785 (defun gnus-summary-down-thread (n)
9786   "Go down thread N steps.
9787 If N is negative, go up instead.
9788 Returns the difference between N and how many steps down that were
9789 taken."
9790   (interactive "p")
9791   (let ((up (< n 0))
9792         (n (abs n)))
9793     (while (and (> n 0)
9794                 (if up (gnus-summary-go-up-thread)
9795                   (gnus-summary-go-down-thread)))
9796       (setq n (1- n)))
9797     (gnus-summary-position-point)
9798     (when (/= 0 n)
9799       (gnus-message 7 "Can't go further"))
9800     n))
9801
9802 (defun gnus-summary-up-thread (n)
9803   "Go up thread N steps.
9804 If N is negative, go down instead.
9805 Returns the difference between N and how many steps down that were
9806 taken."
9807   (interactive "p")
9808   (gnus-summary-down-thread (- n)))
9809
9810 (defun gnus-summary-top-thread ()
9811   "Go to the top of the thread."
9812   (interactive)
9813   (while (gnus-summary-go-up-thread))
9814   (gnus-summary-article-number))
9815
9816 (defun gnus-summary-kill-thread (&optional unmark)
9817   "Mark articles under current thread as read.
9818 If the prefix argument is positive, remove any kinds of marks.
9819 If the prefix argument is negative, tick articles instead."
9820   (interactive "P")
9821   (when unmark
9822     (setq unmark (prefix-numeric-value unmark)))
9823   (let ((articles (gnus-summary-articles-in-thread)))
9824     (save-excursion
9825       ;; Expand the thread.
9826       (gnus-summary-show-thread)
9827       ;; Mark all the articles.
9828       (while articles
9829         (gnus-summary-goto-subject (car articles))
9830         (cond ((null unmark)
9831                (gnus-summary-mark-article-as-read gnus-killed-mark))
9832               ((> unmark 0)
9833                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9834               (t
9835                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9836         (setq articles (cdr articles))))
9837     ;; Hide killed subtrees.
9838     (and (null unmark)
9839          gnus-thread-hide-killed
9840          (gnus-summary-hide-thread))
9841     ;; If marked as read, go to next unread subject.
9842     (when (null unmark)
9843       ;; Go to next unread subject.
9844       (gnus-summary-next-subject 1 t)))
9845   (gnus-set-mode-line 'summary))
9846
9847 ;; Summary sorting commands
9848
9849 (defun gnus-summary-sort-by-number (&optional reverse)
9850   "Sort the summary buffer by article number.
9851 Argument REVERSE means reverse order."
9852   (interactive "P")
9853   (gnus-summary-sort 'number reverse))
9854
9855 (defun gnus-summary-sort-by-author (&optional reverse)
9856   "Sort the summary buffer by author name alphabetically.
9857 If `case-fold-search' is non-nil, case of letters is ignored.
9858 Argument REVERSE means reverse order."
9859   (interactive "P")
9860   (gnus-summary-sort 'author reverse))
9861
9862 (defun gnus-summary-sort-by-subject (&optional reverse)
9863   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9864 If `case-fold-search' is non-nil, case of letters is ignored.
9865 Argument REVERSE means reverse order."
9866   (interactive "P")
9867   (gnus-summary-sort 'subject reverse))
9868
9869 (defun gnus-summary-sort-by-date (&optional reverse)
9870   "Sort the summary buffer by date.
9871 Argument REVERSE means reverse order."
9872   (interactive "P")
9873   (gnus-summary-sort 'date reverse))
9874
9875 (defun gnus-summary-sort-by-score (&optional reverse)
9876   "Sort the summary buffer by score.
9877 Argument REVERSE means reverse order."
9878   (interactive "P")
9879   (gnus-summary-sort 'score reverse))
9880
9881 (defun gnus-summary-sort-by-lines (&optional reverse)
9882   "Sort the summary buffer by the number of lines.
9883 Argument REVERSE means reverse order."
9884   (interactive "P")
9885   (gnus-summary-sort 'lines reverse))
9886
9887 (defun gnus-summary-sort-by-chars (&optional reverse)
9888   "Sort the summary buffer by article length.
9889 Argument REVERSE means reverse order."
9890   (interactive "P")
9891   (gnus-summary-sort 'chars reverse))
9892
9893 (defun gnus-summary-sort-by-original (&optional reverse)
9894   "Sort the summary buffer using the default sorting method.
9895 Argument REVERSE means reverse order."
9896   (interactive "P")
9897   (let* ((buffer-read-only)
9898          (gnus-summary-prepare-hook nil))
9899     ;; We do the sorting by regenerating the threads.
9900     (gnus-summary-prepare)
9901     ;; Hide subthreads if needed.
9902     (when (and gnus-show-threads gnus-thread-hide-subtree)
9903       (gnus-summary-hide-all-threads))))
9904
9905 (defun gnus-summary-sort (predicate reverse)
9906   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9907   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9908          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9909          (gnus-thread-sort-functions
9910           (if (not reverse)
9911               thread
9912             `(lambda (t1 t2)
9913                (,thread t2 t1))))
9914          (gnus-sort-gathered-threads-function
9915           gnus-thread-sort-functions)
9916          (gnus-article-sort-functions
9917           (if (not reverse)
9918               article
9919             `(lambda (t1 t2)
9920                (,article t2 t1))))
9921          (buffer-read-only)
9922          (gnus-summary-prepare-hook nil))
9923     ;; We do the sorting by regenerating the threads.
9924     (gnus-summary-prepare)
9925     ;; Hide subthreads if needed.
9926     (when (and gnus-show-threads gnus-thread-hide-subtree)
9927       (gnus-summary-hide-all-threads))))
9928
9929 ;; Summary saving commands.
9930
9931 (defun gnus-summary-save-article (&optional n not-saved)
9932   "Save the current article using the default saver function.
9933 If N is a positive number, save the N next articles.
9934 If N is a negative number, save the N previous articles.
9935 If N is nil and any articles have been marked with the process mark,
9936 save those articles instead.
9937 The variable `gnus-default-article-saver' specifies the saver function."
9938   (interactive "P")
9939   (let* ((articles (gnus-summary-work-articles n))
9940          (save-buffer (save-excursion
9941                         (nnheader-set-temp-buffer " *Gnus Save*")))
9942          (num (length articles))
9943          header file)
9944     (dolist (article articles)
9945       (setq header (gnus-summary-article-header article))
9946       (if (not (vectorp header))
9947           ;; This is a pseudo-article.
9948           (if (assq 'name header)
9949               (gnus-copy-file (cdr (assq 'name header)))
9950             (gnus-message 1 "Article %d is unsaveable" article))
9951         ;; This is a real article.
9952         (save-window-excursion
9953           (let ((gnus-display-mime-function nil)
9954                 (gnus-article-prepare-hook nil))
9955             (gnus-summary-select-article t nil nil article)))
9956         (save-excursion
9957           (set-buffer save-buffer)
9958           (erase-buffer)
9959           (insert-buffer-substring gnus-original-article-buffer))
9960         (setq file (gnus-article-save save-buffer file num))
9961         (gnus-summary-remove-process-mark article)
9962         (unless not-saved
9963           (gnus-summary-set-saved-mark article))))
9964     (gnus-kill-buffer save-buffer)
9965     (gnus-summary-position-point)
9966     (gnus-set-mode-line 'summary)
9967     n))
9968
9969 (defun gnus-summary-pipe-output (&optional arg)
9970   "Pipe the current article to a subprocess.
9971 If N is a positive number, pipe the N next articles.
9972 If N is a negative number, pipe the N previous articles.
9973 If N is nil and any articles have been marked with the process mark,
9974 pipe those articles instead."
9975   (interactive "P")
9976   (require 'gnus-art)
9977   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9978     (gnus-summary-save-article arg t))
9979   (let ((buffer (get-buffer "*Shell Command Output*")))
9980     (if (and buffer
9981              (with-current-buffer buffer (> (point-max) (point-min))))
9982         (gnus-configure-windows 'pipe))))
9983
9984 (defun gnus-summary-save-article-mail (&optional arg)
9985   "Append the current article to an mail file.
9986 If N is a positive number, save the N next articles.
9987 If N is a negative number, save the N previous articles.
9988 If N is nil and any articles have been marked with the process mark,
9989 save those articles instead."
9990   (interactive "P")
9991   (require 'gnus-art)
9992   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9993     (gnus-summary-save-article arg)))
9994
9995 (defun gnus-summary-save-article-rmail (&optional arg)
9996   "Append the current article to an rmail file.
9997 If N is a positive number, save the N next articles.
9998 If N is a negative number, save the N previous articles.
9999 If N is nil and any articles have been marked with the process mark,
10000 save those articles instead."
10001   (interactive "P")
10002   (require 'gnus-art)
10003   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10004     (gnus-summary-save-article arg)))
10005
10006 (defun gnus-summary-save-article-file (&optional arg)
10007   "Append the current article to a file.
10008 If N is a positive number, save the N next articles.
10009 If N is a negative number, save the N previous articles.
10010 If N is nil and any articles have been marked with the process mark,
10011 save those articles instead."
10012   (interactive "P")
10013   (require 'gnus-art)
10014   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10015     (gnus-summary-save-article arg)))
10016
10017 (defun gnus-summary-write-article-file (&optional arg)
10018   "Write the current article to a file, deleting the previous file.
10019 If N is a positive number, save the N next articles.
10020 If N is a negative number, save the N previous articles.
10021 If N is nil and any articles have been marked with the process mark,
10022 save those articles instead."
10023   (interactive "P")
10024   (require 'gnus-art)
10025   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10026     (gnus-summary-save-article arg)))
10027
10028 (defun gnus-summary-save-article-body-file (&optional arg)
10029   "Append the current article body to a file.
10030 If N is a positive number, save the N next articles.
10031 If N is a negative number, save the N previous articles.
10032 If N is nil and any articles have been marked with the process mark,
10033 save those articles instead."
10034   (interactive "P")
10035   (require 'gnus-art)
10036   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10037     (gnus-summary-save-article arg)))
10038
10039 (defun gnus-summary-muttprint (&optional arg)
10040   "Print the current article using Muttprint.
10041 If N is a positive number, save the N next articles.
10042 If N is a negative number, save the N previous articles.
10043 If N is nil and any articles have been marked with the process mark,
10044 save those articles instead."
10045   (interactive "P")
10046   (require 'gnus-art)
10047   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10048     (gnus-summary-save-article arg t)))
10049
10050 (defun gnus-summary-pipe-message (program)
10051   "Pipe the current article through PROGRAM."
10052   (interactive "sProgram: ")
10053   (gnus-summary-select-article)
10054   (let ((mail-header-separator ""))
10055     (gnus-eval-in-buffer-window gnus-article-buffer
10056       (save-restriction
10057         (widen)
10058         (let ((start (window-start))
10059               buffer-read-only)
10060           (message-pipe-buffer-body program)
10061           (set-window-start (get-buffer-window (current-buffer)) start))))))
10062
10063 (defun gnus-get-split-value (methods)
10064   "Return a value based on the split METHODS."
10065   (let (split-name method result match)
10066     (when methods
10067       (save-excursion
10068         (set-buffer gnus-original-article-buffer)
10069         (save-restriction
10070           (nnheader-narrow-to-headers)
10071           (while (and methods (not split-name))
10072             (goto-char (point-min))
10073             (setq method (pop methods))
10074             (setq match (car method))
10075             (when (cond
10076                    ((stringp match)
10077                     ;; Regular expression.
10078                     (ignore-errors
10079                       (re-search-forward match nil t)))
10080                    ((gnus-functionp match)
10081                     ;; Function.
10082                     (save-restriction
10083                       (widen)
10084                       (setq result (funcall match gnus-newsgroup-name))))
10085                    ((consp match)
10086                     ;; Form.
10087                     (save-restriction
10088                       (widen)
10089                       (setq result (eval match)))))
10090               (setq split-name (cdr method))
10091               (cond ((stringp result)
10092                      (push (expand-file-name
10093                             result gnus-article-save-directory)
10094                            split-name))
10095                     ((consp result)
10096                      (setq split-name (append result split-name)))))))))
10097     (nreverse split-name)))
10098
10099 (defun gnus-valid-move-group-p (group)
10100   (and (boundp group)
10101        (symbol-name group)
10102        (symbol-value group)
10103        (gnus-get-function (gnus-find-method-for-group
10104                            (symbol-name group)) 'request-accept-article t)))
10105
10106 (defun gnus-read-move-group-name (prompt default articles prefix)
10107   "Read a group name."
10108   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10109          (minibuffer-confirm-incomplete nil) ; XEmacs
10110          (prom
10111           (format "%s %s to:"
10112                   prompt
10113                   (if (> (length articles) 1)
10114                       (format "these %d articles" (length articles))
10115                     "this article")))
10116          (to-newsgroup
10117           (cond
10118            ((null split-name)
10119             (gnus-completing-read default prom
10120                                   gnus-active-hashtb
10121                                   'gnus-valid-move-group-p
10122                                   nil prefix
10123                                   'gnus-group-history))
10124            ((= 1 (length split-name))
10125             (gnus-completing-read (car split-name) prom
10126                                   gnus-active-hashtb
10127                                   'gnus-valid-move-group-p
10128                                   nil nil
10129                                   'gnus-group-history))
10130            (t
10131             (gnus-completing-read nil prom
10132                                   (mapcar (lambda (el) (list el))
10133                                           (nreverse split-name))
10134                                   nil nil nil
10135                                   'gnus-group-history))))
10136          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10137     (when to-newsgroup
10138       (if (or (string= to-newsgroup "")
10139               (string= to-newsgroup prefix))
10140           (setq to-newsgroup default))
10141       (unless to-newsgroup
10142         (error "No group name entered"))
10143       (or (gnus-active to-newsgroup)
10144           (gnus-activate-group to-newsgroup nil nil to-method)
10145           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10146                                      to-newsgroup))
10147               (or (and (gnus-request-create-group to-newsgroup to-method)
10148                        (gnus-activate-group
10149                         to-newsgroup nil nil to-method)
10150                        (gnus-subscribe-group to-newsgroup))
10151                   (error "Couldn't create group %s" to-newsgroup)))
10152           (error "No such group: %s" to-newsgroup)))
10153     to-newsgroup))
10154
10155 (defun gnus-summary-save-parts (type dir n &optional reverse)
10156   "Save parts matching TYPE to DIR.
10157 If REVERSE, save parts that do not match TYPE."
10158   (interactive
10159    (list (read-string "Save parts of type: "
10160                       (or (car gnus-summary-save-parts-type-history)
10161                           gnus-summary-save-parts-default-mime)
10162                       'gnus-summary-save-parts-type-history)
10163          (setq gnus-summary-save-parts-last-directory
10164                (read-file-name "Save to directory: "
10165                                gnus-summary-save-parts-last-directory
10166                                nil t))
10167          current-prefix-arg))
10168   (gnus-summary-iterate n
10169     (let ((gnus-display-mime-function nil)
10170           (gnus-inhibit-treatment t))
10171       (gnus-summary-select-article))
10172     (save-excursion
10173       (set-buffer gnus-article-buffer)
10174       (let ((handles (or gnus-article-mime-handles
10175                          (mm-dissect-buffer) (mm-uu-dissect))))
10176         (when handles
10177           (gnus-summary-save-parts-1 type dir handles reverse)
10178           (unless gnus-article-mime-handles ;; Don't destroy this case.
10179             (mm-destroy-parts handles)))))))
10180
10181 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10182   (if (stringp (car handle))
10183       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10184               (cdr handle))
10185     (when (if reverse
10186               (not (string-match type (mm-handle-media-type handle)))
10187             (string-match type (mm-handle-media-type handle)))
10188       (let ((file (expand-file-name
10189                    (file-name-nondirectory
10190                     (or
10191                      (mail-content-type-get
10192                       (mm-handle-disposition handle) 'filename)
10193                      (concat gnus-newsgroup-name
10194                              "." (number-to-string
10195                                   (cdr gnus-article-current)))))
10196                    dir)))
10197         (unless (file-exists-p file)
10198           (mm-save-part-to-file handle file))))))
10199
10200 ;; Summary extract commands
10201
10202 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10203   (let ((buffer-read-only nil)
10204         (article (gnus-summary-article-number))
10205         after-article b e)
10206     (unless (gnus-summary-goto-subject article)
10207       (error "No such article: %d" article))
10208     (gnus-summary-position-point)
10209     ;; If all commands are to be bunched up on one line, we collect
10210     ;; them here.
10211     (unless gnus-view-pseudos-separately
10212       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10213             files action)
10214         (while ps
10215           (setq action (cdr (assq 'action (car ps))))
10216           (setq files (list (cdr (assq 'name (car ps)))))
10217           (while (and ps (cdr ps)
10218                       (string= (or action "1")
10219                                (or (cdr (assq 'action (cadr ps))) "2")))
10220             (push (cdr (assq 'name (cadr ps))) files)
10221             (setcdr ps (cddr ps)))
10222           (when files
10223             (when (not (string-match "%s" action))
10224               (push " " files))
10225             (push " " files)
10226             (when (assq 'execute (car ps))
10227               (setcdr (assq 'execute (car ps))
10228                       (funcall (if (string-match "%s" action)
10229                                    'format 'concat)
10230                                action
10231                                (mapconcat
10232                                 (lambda (f)
10233                                   (if (equal f " ")
10234                                       f
10235                                     (mm-quote-arg f)))
10236                                 files " ")))))
10237           (setq ps (cdr ps)))))
10238     (if (and gnus-view-pseudos (not not-view))
10239         (while pslist
10240           (when (assq 'execute (car pslist))
10241             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10242                                   (eq gnus-view-pseudos 'not-confirm)))
10243           (setq pslist (cdr pslist)))
10244       (save-excursion
10245         (while pslist
10246           (setq after-article (or (cdr (assq 'article (car pslist)))
10247                                   (gnus-summary-article-number)))
10248           (gnus-summary-goto-subject after-article)
10249           (forward-line 1)
10250           (setq b (point))
10251           (insert "    " (file-name-nondirectory
10252                           (cdr (assq 'name (car pslist))))
10253                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10254           (setq e (point))
10255           (forward-line -1)             ; back to `b'
10256           (gnus-add-text-properties
10257            b (1- e) (list 'gnus-number gnus-reffed-article-number
10258                           gnus-mouse-face-prop gnus-mouse-face))
10259           (gnus-data-enter
10260            after-article gnus-reffed-article-number
10261            gnus-unread-mark b (car pslist) 0 (- e b))
10262           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10263           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10264           (setq pslist (cdr pslist)))))))
10265
10266 (defun gnus-pseudos< (p1 p2)
10267   (let ((c1 (cdr (assq 'action p1)))
10268         (c2 (cdr (assq 'action p2))))
10269     (and c1 c2 (string< c1 c2))))
10270
10271 (defun gnus-request-pseudo-article (props)
10272   (cond ((assq 'execute props)
10273          (gnus-execute-command (cdr (assq 'execute props)))))
10274   (let ((gnus-current-article (gnus-summary-article-number)))
10275     (gnus-run-hooks 'gnus-mark-article-hook)))
10276
10277 (defun gnus-execute-command (command &optional automatic)
10278   (save-excursion
10279     (gnus-article-setup-buffer)
10280     (set-buffer gnus-article-buffer)
10281     (setq buffer-read-only nil)
10282     (let ((command (if automatic command
10283                      (read-string "Command: " (cons command 0)))))
10284       (erase-buffer)
10285       (insert "$ " command "\n\n")
10286       (if gnus-view-pseudo-asynchronously
10287           (start-process "gnus-execute" (current-buffer) shell-file-name
10288                          shell-command-switch command)
10289         (call-process shell-file-name nil t nil
10290                       shell-command-switch command)))))
10291
10292 ;; Summary kill commands.
10293
10294 (defun gnus-summary-edit-global-kill (article)
10295   "Edit the \"global\" kill file."
10296   (interactive (list (gnus-summary-article-number)))
10297   (gnus-group-edit-global-kill article))
10298
10299 (defun gnus-summary-edit-local-kill ()
10300   "Edit a local kill file applied to the current newsgroup."
10301   (interactive)
10302   (setq gnus-current-headers (gnus-summary-article-header))
10303   (gnus-group-edit-local-kill
10304    (gnus-summary-article-number) gnus-newsgroup-name))
10305
10306 ;;; Header reading.
10307
10308 (defun gnus-read-header (id &optional header)
10309   "Read the headers of article ID and enter them into the Gnus system."
10310   (let ((group gnus-newsgroup-name)
10311         (gnus-override-method
10312          (or
10313           gnus-override-method
10314           (and (gnus-news-group-p gnus-newsgroup-name)
10315                (car (gnus-refer-article-methods)))))
10316         where)
10317     ;; First we check to see whether the header in question is already
10318     ;; fetched.
10319     (if (stringp id)
10320         ;; This is a Message-ID.
10321         (setq header (or header (gnus-id-to-header id)))
10322       ;; This is an article number.
10323       (setq header (or header (gnus-summary-article-header id))))
10324     (if (and header
10325              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10326         ;; We have found the header.
10327         header
10328       ;; If this is a sparse article, we have to nix out its
10329       ;; previous entry in the thread hashtb.
10330       (when (and header
10331                  (gnus-summary-article-sparse-p (mail-header-number header)))
10332         (let* ((parent (gnus-parent-id (mail-header-references header)))
10333                (thread (and parent (gnus-id-to-thread parent))))
10334           (when thread
10335             (delq (assq header thread) thread))))
10336       ;; We have to really fetch the header to this article.
10337       (save-excursion
10338         (set-buffer nntp-server-buffer)
10339         (when (setq where (gnus-request-head id group))
10340           (nnheader-fold-continuation-lines)
10341           (goto-char (point-max))
10342           (insert ".\n")
10343           (goto-char (point-min))
10344           (insert "211 ")
10345           (princ (cond
10346                   ((numberp id) id)
10347                   ((cdr where) (cdr where))
10348                   (header (mail-header-number header))
10349                   (t gnus-reffed-article-number))
10350                  (current-buffer))
10351           (insert " Article retrieved.\n"))
10352         (if (or (not where)
10353                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10354             ()                          ; Malformed head.
10355           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10356             (when (and (stringp id)
10357                        (not (string= (gnus-group-real-name group)
10358                                      (car where))))
10359               ;; If we fetched by Message-ID and the article came
10360               ;; from a different group, we fudge some bogus article
10361               ;; numbers for this article.
10362               (mail-header-set-number header gnus-reffed-article-number))
10363             (save-excursion
10364               (set-buffer gnus-summary-buffer)
10365               (decf gnus-reffed-article-number)
10366               (gnus-remove-header (mail-header-number header))
10367               (push header gnus-newsgroup-headers)
10368               (setq gnus-current-headers header)
10369               (push (mail-header-number header) gnus-newsgroup-limit)))
10370           header)))))
10371
10372 (defun gnus-remove-header (number)
10373   "Remove header NUMBER from `gnus-newsgroup-headers'."
10374   (if (and gnus-newsgroup-headers
10375            (= number (mail-header-number (car gnus-newsgroup-headers))))
10376       (pop gnus-newsgroup-headers)
10377     (let ((headers gnus-newsgroup-headers))
10378       (while (and (cdr headers)
10379                   (not (= number (mail-header-number (cadr headers)))))
10380         (pop headers))
10381       (when (cdr headers)
10382         (setcdr headers (cddr headers))))))
10383
10384 ;;;
10385 ;;; summary highlights
10386 ;;;
10387
10388 (defun gnus-highlight-selected-summary ()
10389   "Highlight selected article in summary buffer."
10390   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10391   (when gnus-summary-selected-face
10392     (save-excursion
10393       (let* ((beg (progn (beginning-of-line) (point)))
10394              (end (progn (end-of-line) (point)))
10395              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10396              (from (if (get-text-property beg gnus-mouse-face-prop)
10397                        beg
10398                      (or (next-single-property-change
10399                           beg gnus-mouse-face-prop nil end)
10400                          beg)))
10401              (to
10402               (if (= from end)
10403                   (- from 2)
10404                 (or (next-single-property-change
10405                      from gnus-mouse-face-prop nil end)
10406                     end))))
10407         ;; If no mouse-face prop on line we will have to = from = end,
10408         ;; so we highlight the entire line instead.
10409         (when (= (+ to 2) from)
10410           (setq from beg)
10411           (setq to end))
10412         (if gnus-newsgroup-selected-overlay
10413             ;; Move old overlay.
10414             (gnus-move-overlay
10415              gnus-newsgroup-selected-overlay from to (current-buffer))
10416           ;; Create new overlay.
10417           (gnus-overlay-put
10418            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10419            'face gnus-summary-selected-face))))))
10420
10421 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10422 (defun gnus-summary-highlight-line ()
10423   "Highlight current line according to `gnus-summary-highlight'."
10424   (let* ((list gnus-summary-highlight)
10425          (p (point))
10426          (end (progn (end-of-line) (point)))
10427          ;; now find out where the line starts and leave point there.
10428          (beg (progn (beginning-of-line) (point)))
10429          (article (gnus-summary-article-number))
10430          (score (or (cdr (assq (or article gnus-current-article)
10431                                gnus-newsgroup-scored))
10432                     gnus-summary-default-score 0))
10433          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10434          (inhibit-read-only t))
10435     ;; Eval the cars of the lists until we find a match.
10436     (let ((default gnus-summary-default-score)
10437           (default-high gnus-summary-default-high-score)
10438           (default-low gnus-summary-default-low-score))
10439       (while (and list
10440                   (not (eval (caar list))))
10441         (setq list (cdr list))))
10442     (let ((face (cdar list)))
10443       (unless (eq face (get-text-property beg 'face))
10444         (gnus-put-text-property-excluding-characters-with-faces
10445          beg end 'face
10446          (setq face (if (boundp face) (symbol-value face) face)))
10447         (when gnus-summary-highlight-line-function
10448           (funcall gnus-summary-highlight-line-function article face))))
10449     (goto-char p)))
10450
10451 (defun gnus-update-read-articles (group unread &optional compute)
10452   "Update the list of read articles in GROUP."
10453   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10454          (entry (gnus-gethash group gnus-newsrc-hashtb))
10455          (info (nth 2 entry))
10456          (prev 1)
10457          (unread (sort (copy-sequence unread) '<))
10458          read)
10459     (if (or (not info) (not active))
10460         ;; There is no info on this group if it was, in fact,
10461         ;; killed.  Gnus stores no information on killed groups, so
10462         ;; there's nothing to be done.
10463         ;; One could store the information somewhere temporarily,
10464         ;; perhaps...  Hmmm...
10465         ()
10466       ;; Remove any negative articles numbers.
10467       (while (and unread (< (car unread) 0))
10468         (setq unread (cdr unread)))
10469       ;; Remove any expired article numbers
10470       (while (and unread (< (car unread) (car active)))
10471         (setq unread (cdr unread)))
10472       ;; Compute the ranges of read articles by looking at the list of
10473       ;; unread articles.
10474       (while unread
10475         (when (/= (car unread) prev)
10476           (push (if (= prev (1- (car unread))) prev
10477                   (cons prev (1- (car unread))))
10478                 read))
10479         (setq prev (1+ (car unread)))
10480         (setq unread (cdr unread)))
10481       (when (<= prev (cdr active))
10482         (push (cons prev (cdr active)) read))
10483       (setq read (if (> (length read) 1) (nreverse read) read))
10484       (if compute
10485           read
10486         (save-excursion
10487           (let (setmarkundo)
10488             ;; Propagate the read marks to the backend.
10489             (when (gnus-check-backend-function 'request-set-mark group)
10490               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10491                     (add (gnus-remove-from-range read (gnus-info-read info))))
10492                 (when (or add del)
10493                   (unless (gnus-check-group group)
10494                     (error "Can't open server for %s" group))
10495                   (gnus-request-set-mark
10496                    group (delq nil (list (if add (list add 'add '(read)))
10497                                          (if del (list del 'del '(read))))))
10498                   (setq setmarkundo
10499                         `(gnus-request-set-mark
10500                           ,group
10501                           ',(delq nil (list
10502                                        (if del (list del 'add '(read)))
10503                                        (if add (list add 'del '(read))))))))))
10504             (set-buffer gnus-group-buffer)
10505             (gnus-undo-register
10506               `(progn
10507                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10508                  (gnus-info-set-read ',info ',(gnus-info-read info))
10509                  (gnus-get-unread-articles-in-group ',info
10510                                                     (gnus-active ,group))
10511                  (gnus-group-update-group ,group t)
10512                  ,setmarkundo))))
10513         ;; Enter this list into the group info.
10514         (gnus-info-set-read info read)
10515         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10516         (gnus-get-unread-articles-in-group info (gnus-active group))
10517         t))))
10518
10519 (defun gnus-offer-save-summaries ()
10520   "Offer to save all active summary buffers."
10521   (let (buffers)
10522     ;; Go through all buffers and find all summaries.
10523     (dolist (buffer (buffer-list))
10524       (when (and (setq buffer (buffer-name buffer))
10525                  (string-match "Summary" buffer)
10526                  (save-excursion
10527                    (set-buffer buffer)
10528                    ;; We check that this is, indeed, a summary buffer.
10529                    (and (eq major-mode 'gnus-summary-mode)
10530                         ;; Also make sure this isn't bogus.
10531                         gnus-newsgroup-prepared
10532                         ;; Also make sure that this isn't a
10533                         ;; dead summary buffer.
10534                         (not gnus-dead-summary-mode))))
10535         (push buffer buffers)))
10536     ;; Go through all these summary buffers and offer to save them.
10537     (when buffers
10538       (save-excursion
10539         (map-y-or-n-p
10540          "Update summary buffer %s? "
10541          (lambda (buf)
10542            (switch-to-buffer buf)
10543            (gnus-summary-exit))
10544          buffers)))))
10545
10546 (defun gnus-summary-setup-default-charset ()
10547   "Setup newsgroup default charset."
10548   (if (equal gnus-newsgroup-name "nndraft:drafts")
10549       (setq gnus-newsgroup-charset nil)
10550     (let* ((ignored-charsets
10551             (or gnus-newsgroup-ephemeral-ignored-charsets
10552                 (append
10553                  (and gnus-newsgroup-name
10554                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10555                  gnus-newsgroup-ignored-charsets))))
10556       (setq gnus-newsgroup-charset
10557             (or gnus-newsgroup-ephemeral-charset
10558                 (and gnus-newsgroup-name
10559                      (gnus-parameter-charset gnus-newsgroup-name))
10560                 gnus-default-charset))
10561       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10562            ignored-charsets))))
10563
10564 ;;;
10565 ;;; Mime Commands
10566 ;;;
10567
10568 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10569   "Display the current article buffer fully MIME-buttonized.
10570 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10571 treated as multipart/mixed."
10572   (interactive "P")
10573   (require 'gnus-art)
10574   (let ((gnus-unbuttonized-mime-types nil)
10575         (gnus-mime-display-multipart-as-mixed show-all-parts))
10576     (gnus-summary-show-article)))
10577
10578 (defun gnus-summary-repair-multipart (article)
10579   "Add a Content-Type header to a multipart article without one."
10580   (interactive (list (gnus-summary-article-number)))
10581   (gnus-with-article article
10582     (message-narrow-to-head)
10583     (message-remove-header "Mime-Version")
10584     (goto-char (point-max))
10585     (insert "Mime-Version: 1.0\n")
10586     (widen)
10587     (when (search-forward "\n--" nil t)
10588       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10589         (message-narrow-to-head)
10590         (message-remove-header "Content-Type")
10591         (goto-char (point-max))
10592         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10593                         separator))
10594         (widen))))
10595   (let (gnus-mark-article-hook)
10596     (gnus-summary-select-article t t nil article)))
10597
10598 (defun gnus-summary-toggle-display-buttonized ()
10599   "Toggle the buttonizing of the article buffer."
10600   (interactive)
10601   (require 'gnus-art)
10602   (if (setq gnus-inhibit-mime-unbuttonizing
10603             (not gnus-inhibit-mime-unbuttonizing))
10604       (let ((gnus-unbuttonized-mime-types nil))
10605         (gnus-summary-show-article))
10606     (gnus-summary-show-article)))
10607
10608 ;;;
10609 ;;; Generic summary marking commands
10610 ;;;
10611
10612 (defvar gnus-summary-marking-alist
10613   '((read gnus-del-mark "d")
10614     (unread gnus-unread-mark "u")
10615     (ticked gnus-ticked-mark "!")
10616     (dormant gnus-dormant-mark "?")
10617     (expirable gnus-expirable-mark "e"))
10618   "An alist of names/marks/keystrokes.")
10619
10620 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10621 (defvar gnus-summary-mark-map)
10622
10623 (defun gnus-summary-make-all-marking-commands ()
10624   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10625   (dolist (elem gnus-summary-marking-alist)
10626     (apply 'gnus-summary-make-marking-command elem)))
10627
10628 (defun gnus-summary-make-marking-command (name mark keystroke)
10629   (let ((map (make-sparse-keymap)))
10630     (define-key gnus-summary-generic-mark-map keystroke map)
10631     (dolist (lway `((next "next" next nil "n")
10632                     (next-unread "next unread" next t "N")
10633                     (prev "previous" prev nil "p")
10634                     (prev-unread "previous unread" prev t "P")
10635                     (nomove "" nil nil ,keystroke)))
10636       (let ((func (gnus-summary-make-marking-command-1
10637                    mark (car lway) lway name)))
10638         (setq func (eval func))
10639         (define-key map (nth 4 lway) func)))))
10640
10641 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10642   `(defun ,(intern
10643             (format "gnus-summary-put-mark-as-%s%s"
10644                     name (if (eq way 'nomove)
10645                              ""
10646                            (concat "-" (symbol-name way)))))
10647      (n)
10648      ,(format
10649        "Mark the current article as %s%s.
10650 If N, the prefix, then repeat N times.
10651 If N is negative, move in reverse order.
10652 The difference between N and the actual number of articles marked is
10653 returned."
10654        name (cadr lway))
10655      (interactive "p")
10656      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10657
10658 (defun gnus-summary-generic-mark (n mark move unread)
10659   "Mark N articles with MARK."
10660   (unless (eq major-mode 'gnus-summary-mode)
10661     (error "This command can only be used in the summary buffer"))
10662   (gnus-summary-show-thread)
10663   (let ((nummove
10664          (cond
10665           ((eq move 'next) 1)
10666           ((eq move 'prev) -1)
10667           (t 0))))
10668     (if (zerop nummove)
10669         (setq n 1)
10670       (when (< n 0)
10671         (setq n (abs n)
10672               nummove (* -1 nummove))))
10673     (while (and (> n 0)
10674                 (gnus-summary-mark-article nil mark)
10675                 (zerop (gnus-summary-next-subject nummove unread t)))
10676       (setq n (1- n)))
10677     (when (/= 0 n)
10678       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10679     (gnus-summary-recenter)
10680     (gnus-summary-position-point)
10681     (gnus-set-mode-line 'summary)
10682     n))
10683
10684 (defun gnus-summary-insert-articles (articles)
10685   (when (setq articles
10686               (gnus-set-difference articles
10687                                    (mapcar (lambda (h) (mail-header-number h))
10688                                            gnus-newsgroup-headers)))
10689     (setq gnus-newsgroup-headers
10690           (merge 'list
10691                  gnus-newsgroup-headers
10692                  (gnus-fetch-headers articles)
10693                  'gnus-article-sort-by-number))
10694     ;; Suppress duplicates?
10695     (when gnus-suppress-duplicates
10696       (gnus-dup-suppress-articles))
10697
10698     ;; We might want to build some more threads first.
10699     (when (and gnus-fetch-old-headers
10700                (eq gnus-headers-retrieved-by 'nov))
10701       (if (eq gnus-fetch-old-headers 'invisible)
10702           (gnus-build-all-threads)
10703         (gnus-build-old-threads)))
10704     ;; Let the Gnus agent mark articles as read.
10705     (when gnus-agent
10706       (gnus-agent-get-undownloaded-list))
10707     ;; Remove list identifiers from subject
10708     (when gnus-list-identifiers
10709       (gnus-summary-remove-list-identifiers))
10710     ;; First and last article in this newsgroup.
10711     (when gnus-newsgroup-headers
10712       (setq gnus-newsgroup-begin
10713             (mail-header-number (car gnus-newsgroup-headers))
10714             gnus-newsgroup-end
10715             (mail-header-number
10716              (gnus-last-element gnus-newsgroup-headers))))
10717     (when gnus-use-scoring
10718       (gnus-possibly-score-headers))))
10719
10720 (defun gnus-summary-insert-old-articles (&optional all)
10721   "Insert all old articles in this group.
10722 If ALL is non-nil, already read articles become readable.
10723 If ALL is a number, fetch this number of articles."
10724   (interactive "P")
10725   (prog1
10726       (let ((old (mapcar 'car gnus-newsgroup-data))
10727             (i (car gnus-newsgroup-active))
10728             older len)
10729         (while (<= i (cdr gnus-newsgroup-active))
10730           (or (memq i old) (push i older))
10731           (incf i))
10732         (setq len (length older))
10733         (cond
10734          ((null older) nil)
10735          ((numberp all)
10736           (if (< all len)
10737               (setq older (subseq older 0 all))))
10738          (all nil)
10739          (t
10740           (if (and (numberp gnus-large-newsgroup)
10741                    (> len gnus-large-newsgroup))
10742               (let ((input
10743                      (read-string
10744                       (format
10745                        "How many articles from %s (default %d): "
10746                        (gnus-limit-string
10747                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10748                        len))))
10749                 (unless (string-match "^[ \t]*$" input)
10750                   (setq all (string-to-number input))
10751                   (if (< all len)
10752                       (setq older (subseq older 0 all))))))))
10753         (if (not older)
10754             (message "No old news.")
10755           (gnus-summary-insert-articles older)
10756           (gnus-summary-limit (gnus-union older old))))
10757     (gnus-summary-position-point)))
10758
10759 (defun gnus-summary-insert-new-articles ()
10760   "Insert all new articles in this group."
10761   (interactive)
10762   (prog1
10763       (let ((old (mapcar 'car gnus-newsgroup-data))
10764             (old-active gnus-newsgroup-active)
10765             (nnmail-fetched-sources (list t))
10766             i new)
10767         (setq gnus-newsgroup-active
10768               (gnus-activate-group gnus-newsgroup-name 'scan))
10769         (setq i (1+ (cdr old-active)))
10770         (while (<= i (cdr gnus-newsgroup-active))
10771           (push i new)
10772           (incf i))
10773         (if (not new)
10774             (message "No gnus is bad news.")
10775           (setq new (nreverse new))
10776           (gnus-summary-insert-articles new)
10777           (setq gnus-newsgroup-unreads
10778                 (append gnus-newsgroup-unreads new))
10779           (gnus-summary-limit (gnus-union old new))))
10780     (gnus-summary-position-point)))
10781
10782 (gnus-summary-make-all-marking-commands)
10783
10784 (gnus-ems-redefine)
10785
10786 (provide 'gnus-sum)
10787
10788 (run-hooks 'gnus-sum-load-hook)
10789
10790 ;;; gnus-sum.el ends here