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