Initial Commit
[packages] / xemacs-packages / gnus / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defun-when-void put-display-table (range value display-table)
59   "Set the value for char RANGE to VALUE in DISPLAY-TABLE.  "
60   (ecase (type-of display-table)
61     (vector
62      (aset display-table range value))
63     (char-table
64      (put-char-table range value display-table))))
65
66 (defun-when-void get-display-table (character display-table)
67   "Find value for CHARACTER in DISPLAY-TABLE.  "
68   (ecase (type-of display-table)
69     (vector
70      (aref display-table character))
71     (char-table
72      (get-char-table character display-table))))
73
74 (defcustom gnus-kill-summary-on-exit t
75   "*If non-nil, kill the summary buffer when you exit from it.
76 If nil, the summary will become a \"*Dead Summary*\" buffer, and
77 it will be killed sometime later."
78   :group 'gnus-summary-exit
79   :type 'boolean)
80
81 (defcustom gnus-fetch-old-headers nil
82   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
83 If an unread article in the group refers to an older, already read (or
84 just marked as read) article, the old article will not normally be
85 displayed in the Summary buffer.  If this variable is t, Gnus
86 will attempt to grab the headers to the old articles, and thereby
87 build complete threads.  If it has the value `some', only enough
88 headers to connect otherwise loose threads will be displayed.  This
89 variable can also be a number.  In that case, no more than that number
90 of old headers will be fetched.  If it has the value `invisible', all
91 old headers will be fetched, but none will be displayed.
92
93 The server has to support NOV for any of this to work."
94   :group 'gnus-thread
95   :type '(choice (const :tag "off" nil)
96                  (const :tag "on" t)
97                  (const some)
98                  (const invisible)
99                  number
100                  (sexp :menu-tag "other" t)))
101
102 (defcustom gnus-refer-thread-limit 200
103   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
104 If t, fetch all the available old headers."
105   :group 'gnus-thread
106   :type '(choice number
107                  (sexp :menu-tag "other" t)))
108
109 (defcustom gnus-summary-make-false-root 'adopt
110   "*nil means that Gnus won't gather loose threads.
111 If the root of a thread has expired or been read in a previous
112 session, the information necessary to build a complete thread has been
113 lost.  Instead of having many small sub-threads from this original thread
114 scattered all over the summary buffer, Gnus can gather them.
115
116 If non-nil, Gnus will try to gather all loose sub-threads from an
117 original thread into one large thread.
118
119 If this variable is non-nil, it should be one of `none', `adopt',
120 `dummy' or `empty'.
121
122 If this variable is `none', Gnus will not make a false root, but just
123 present the sub-threads after another.
124 If this variable is `dummy', Gnus will create a dummy root that will
125 have all the sub-threads as children.
126 If this variable is `adopt', Gnus will make one of the \"children\"
127 the parent and mark all the step-children as such.
128 If this variable is `empty', the \"children\" are printed with empty
129 subject fields.  (Or rather, they will be printed with a string
130 given by the `gnus-summary-same-subject' variable.)"
131   :group 'gnus-thread
132   :type '(choice (const :tag "off" nil)
133                  (const none)
134                  (const dummy)
135                  (const adopt)
136                  (const empty)))
137
138 (defcustom gnus-summary-make-false-root-always nil
139   "Always make a false dummy root."
140   :version "22.1"
141   :group 'gnus-thread
142   :type 'boolean)
143
144 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
145   "*A regexp to match subjects to be excluded from loose thread gathering.
146 As loose thread gathering is done on subjects only, that means that
147 there can be many false gatherings performed.  By rooting out certain
148 common subjects, gathering might become saner."
149   :group 'gnus-thread
150   :type 'regexp)
151
152 (defcustom gnus-summary-gather-subject-limit nil
153   "*Maximum length of subject comparisons when gathering loose threads.
154 Use nil to compare full subjects.  Setting this variable to a low
155 number will help gather threads that have been corrupted by
156 newsreaders chopping off subject lines, but it might also mean that
157 unrelated articles that have subject that happen to begin with the
158 same few characters will be incorrectly gathered.
159
160 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
161 comparing subjects."
162   :group 'gnus-thread
163   :type '(choice (const :tag "off" nil)
164                  (const fuzzy)
165                  (sexp :menu-tag "on" t)))
166
167 (defcustom gnus-simplify-subject-functions nil
168   "List of functions taking a string argument that simplify subjects.
169 The functions are applied recursively.
170
171 Useful functions to put in this list include:
172 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
173 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
174   :group 'gnus-thread
175   :type '(repeat function))
176
177 (defcustom gnus-simplify-ignored-prefixes nil
178   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
179   :group 'gnus-thread
180   :type '(choice (const :tag "off" nil)
181                  regexp))
182
183 (defcustom gnus-build-sparse-threads nil
184   "*If non-nil, fill in the gaps in threads.
185 If `some', only fill in the gaps that are needed to tie loose threads
186 together.  If `more', fill in all leaf nodes that Gnus can find.  If
187 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
188   :group 'gnus-thread
189   :type '(choice (const :tag "off" nil)
190                  (const some)
191                  (const more)
192                  (sexp :menu-tag "all" t)))
193
194 (defcustom gnus-summary-thread-gathering-function
195   'gnus-gather-threads-by-subject
196   "*Function used for gathering loose threads.
197 There are two pre-defined functions: `gnus-gather-threads-by-subject',
198 which only takes Subjects into consideration; and
199 `gnus-gather-threads-by-references', which compared the References
200 headers of the articles to find matches."
201   :group 'gnus-thread
202   :type '(radio (function-item gnus-gather-threads-by-subject)
203                 (function-item gnus-gather-threads-by-references)
204                 (function :tag "other")))
205
206 (defcustom gnus-summary-same-subject ""
207   "*String indicating that the current article has the same subject as the previous.
208 This variable will only be used if the value of
209 `gnus-summary-make-false-root' is `empty'."
210   :group 'gnus-summary-format
211   :type 'string)
212
213 (defcustom gnus-summary-goto-unread t
214   "*If t, many commands will go to the next unread article.
215 This applies to marking commands as well as other commands that
216 \"naturally\" select the next article, like, for instance, `SPC' at
217 the end of an article.
218
219 If nil, the marking commands do NOT go to the next unread article
220 \(they go to the next article instead).  If `never', commands that
221 usually go to the next unread article, will go to the next article,
222 whether it is read or not."
223   :group 'gnus-summary-marks
224   :link '(custom-manual "(gnus)Setting Marks")
225   :type '(choice (const :tag "off" nil)
226                  (const never)
227                  (sexp :menu-tag "on" t)))
228
229 (defcustom gnus-summary-default-score 0
230   "*Default article score level.
231 All scores generated by the score files will be added to this score.
232 If this variable is nil, scoring will be disabled."
233   :group 'gnus-score-default
234   :type '(choice (const :tag "disable")
235                  integer))
236
237 (defcustom gnus-summary-default-high-score 0
238   "*Default threshold for a high scored article.
239 An article will be highlighted as high scored if its score is greater
240 than this score."
241   :version "22.1"
242   :group 'gnus-score-default
243   :type 'integer)
244
245 (defcustom gnus-summary-default-low-score 0
246   "*Default threshold for a low scored article.
247 An article will be highlighted as low scored if its score is smaller
248 than this score."
249   :version "22.1"
250   :group 'gnus-score-default
251   :type 'integer)
252
253 (defcustom gnus-summary-zcore-fuzz 0
254   "*Fuzziness factor for the zcore in the summary buffer.
255 Articles with scores closer than this to `gnus-summary-default-score'
256 will not be marked."
257   :group 'gnus-summary-format
258   :type 'integer)
259
260 (defcustom gnus-simplify-subject-fuzzy-regexp nil
261   "*Strings to be removed when doing fuzzy matches.
262 This can either be a regular expression or list of regular expressions
263 that will be removed from subject strings if fuzzy subject
264 simplification is selected."
265   :group 'gnus-thread
266   :type '(repeat regexp))
267
268 (defcustom gnus-show-threads t
269   "*If non-nil, display threads in summary mode."
270   :group 'gnus-thread
271   :type 'boolean)
272
273 (defcustom gnus-thread-hide-subtree nil
274   "*If non-nil, hide all threads initially.
275 This can be a predicate specifier which says which threads to hide.
276 If threads are hidden, you have to run the command
277 `gnus-summary-show-thread' by hand or select an article."
278   :group 'gnus-thread
279   :type '(radio (sexp :format "Non-nil\n"
280                       :match (lambda (widget value)
281                                (not (or (consp value) (functionp value))))
282                       :value t)
283                 (const nil)
284                 (sexp :tag "Predicate specifier")))
285
286 (defcustom gnus-thread-hide-killed t
287   "*If non-nil, hide killed threads automatically."
288   :group 'gnus-thread
289   :type 'boolean)
290
291 (defcustom gnus-thread-ignore-subject t
292   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
293 If nil, articles that have different subjects from their parents will
294 start separate threads."
295   :group 'gnus-thread
296   :type 'boolean)
297
298 (defcustom gnus-thread-operation-ignore-subject t
299   "*If non-nil, subjects will be ignored when doing thread commands.
300 This affects commands like `gnus-summary-kill-thread' and
301 `gnus-summary-lower-thread'.
302
303 If this variable is nil, articles in the same thread with different
304 subjects will not be included in the operation in question.  If this
305 variable is `fuzzy', only articles that have subjects that are fuzzily
306 equal will be included."
307   :group 'gnus-thread
308   :type '(choice (const :tag "off" nil)
309                  (const fuzzy)
310                  (sexp :tag "on" t)))
311
312 (defcustom gnus-thread-indent-level 4
313   "*Number that says how much each sub-thread should be indented."
314   :group 'gnus-thread
315   :type 'integer)
316
317 (defcustom gnus-auto-extend-newsgroup t
318   "*If non-nil, extend newsgroup forward and backward when requested."
319   :group 'gnus-summary-choose
320   :type 'boolean)
321
322 (defcustom gnus-auto-select-first t
323   "If non-nil, select an article on group entry.
324 An article is selected automatically when entering a group
325 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
326 `gnus-summary-catchup-and-goto-next-group'.
327
328 Which article is selected is controlled by the variable
329 `gnus-auto-select-subject'.
330
331 If you want to prevent automatic selection of articles in some
332 newsgroups, set the variable to nil in `gnus-select-group-hook'."
333   ;; Commands include...
334   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
335   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
336   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
337   :group 'gnus-group-select
338   :type '(choice (const :tag "none" nil)
339                  (sexp :menu-tag "first" t)))
340
341 (defcustom gnus-auto-select-subject 'unread
342   "*Says what subject to place under point when entering a group.
343
344 This variable can either be the symbols `first' (place point on the
345 first subject), `unread' (place point on the subject line of the first
346 unread article), `best' (place point on the subject line of the
347 higest-scored article), `unseen' (place point on the subject line of
348 the first unseen article), `unseen-or-unread' (place point on the subject
349 line of the first unseen article or, if all article have been seen, on the
350 subject line of the first unread article), or a function to be called to
351 place point on some subject line."
352   :version "22.1"
353   :group 'gnus-group-select
354   :type '(choice (const best)
355                  (const unread)
356                  (const first)
357                  (const unseen)
358                  (const unseen-or-unread)))
359
360 (defcustom gnus-auto-select-next t
361   "*If non-nil, offer to go to the next group from the end of the previous.
362 If the value is t and the next newsgroup is empty, Gnus will exit
363 summary mode and go back to group mode.  If the value is neither nil
364 nor t, Gnus will select the following unread newsgroup.  In
365 particular, if the value is the symbol `quietly', the next unread
366 newsgroup will be selected without any confirmation, and if it is
367 `almost-quietly', the next group will be selected without any
368 confirmation if you are located on the last article in the group.
369 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
370 will go to the next group without confirmation."
371   :group 'gnus-summary-maneuvering
372   :type '(choice (const :tag "off" nil)
373                  (const quietly)
374                  (const almost-quietly)
375                  (const slightly-quietly)
376                  (sexp :menu-tag "on" t)))
377
378 (defcustom gnus-auto-select-same nil
379   "*If non-nil, select the next article with the same subject.
380 If there are no more articles with the same subject, go to
381 the first unread article."
382   :group 'gnus-summary-maneuvering
383   :type 'boolean)
384
385 (defcustom gnus-auto-goto-ignores 'unfetched
386   "*Says how to handle unfetched articles when maneuvering.
387
388 This variable can either be the symbols nil (maneuver to any
389 article), `undownloaded' (maneuvering while unplugged ignores articles
390 that have not been fetched), `always-undownloaded' (maneuvering always
391 ignores articles that have not been fetched), `unfetched' (maneuvering
392 ignores articles whose headers have not been fetched).
393
394 NOTE: The list of unfetched articles will always be nil when plugged
395 and, when unplugged, a subset of the undownloaded article list."
396   :version "22.1"
397   :group 'gnus-summary-maneuvering
398   :type '(choice (const :tag "None" nil)
399                  (const :tag "Undownloaded when unplugged" undownloaded)
400                  (const :tag "Undownloaded" always-undownloaded)
401                  (const :tag "Unfetched" unfetched)))
402
403 (defcustom gnus-summary-check-current nil
404   "*If non-nil, consider the current article when moving.
405 The \"unread\" movement commands will stay on the same line if the
406 current article is unread."
407   :group 'gnus-summary-maneuvering
408   :type 'boolean)
409
410 (defcustom gnus-auto-center-summary t
411   "*If non-nil, always center the current summary buffer.
412 In particular, if `vertical' do only vertical recentering.  If non-nil
413 and non-`vertical', do both horizontal and vertical recentering."
414   :group 'gnus-summary-maneuvering
415   :type '(choice (const :tag "none" nil)
416                  (const vertical)
417                  (integer :tag "height")
418                  (sexp :menu-tag "both" t)))
419
420 (defvar gnus-auto-center-group t
421   "*If non-nil, always center the group buffer.")
422
423 (defcustom gnus-show-all-headers nil
424   "*If non-nil, don't hide any headers."
425   :group 'gnus-article-hiding
426   :group 'gnus-article-headers
427   :type 'boolean)
428
429 (defcustom gnus-summary-ignore-duplicates nil
430   "*If non-nil, ignore articles with identical Message-ID headers."
431   :group 'gnus-summary
432   :type 'boolean)
433
434 (defcustom gnus-single-article-buffer t
435   "*If non-nil, display all articles in the same buffer.
436 If nil, each group will get its own article buffer."
437   :group 'gnus-article-various
438   :type 'boolean)
439
440 (defcustom gnus-break-pages t
441   "*If non-nil, do page breaking on articles.
442 The page delimiter is specified by the `gnus-page-delimiter'
443 variable."
444   :group 'gnus-article-various
445   :type 'boolean)
446
447 (defcustom gnus-move-split-methods nil
448   "*Variable used to suggest where articles are to be moved to.
449 It uses the same syntax as the `gnus-split-methods' variable.
450 However, whereas `gnus-split-methods' specifies file names as targets,
451 this variable specifies group names."
452   :group 'gnus-summary-mail
453   :type '(repeat (choice (list :value (fun) function)
454                          (cons :value ("" "") regexp (repeat string))
455                          (sexp :value nil))))
456
457 ;; FIXME: Although the custom type is `character' for the following variables,
458 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
459
460 (defcustom gnus-unread-mark ?           ;Whitespace
461   "*Mark used for unread articles."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-ticked-mark ?!
466   "*Mark used for ticked articles."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-dormant-mark ??
471   "*Mark used for dormant articles."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-del-mark ?r
476   "*Mark used for del'd articles."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-read-mark ?R
481   "*Mark used for read articles."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-expirable-mark ?E
486   "*Mark used for expirable articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-killed-mark ?K
491   "*Mark used for killed articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-spam-mark ?$
496   "*Mark used for spam articles."
497   :version "22.1"
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-souped-mark ?F
502   "*Mark used for souped articles."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-kill-file-mark ?X
507   "*Mark used for articles killed by kill files."
508   :group 'gnus-summary-marks
509   :type 'character)
510
511 (defcustom gnus-low-score-mark ?Y
512   "*Mark used for articles with a low score."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-catchup-mark ?C
517   "*Mark used for articles that are caught up."
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-replied-mark ?A
522   "*Mark used for articles that have been replied to."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-forwarded-mark ?F
527   "*Mark used for articles that have been forwarded."
528   :version "22.1"
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-recent-mark ?N
533   "*Mark used for articles that are recent."
534   :version "22.1"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-cached-mark ?*
539   "*Mark used for articles that are in the cache."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-saved-mark ?S
544   "*Mark used for articles that have been saved."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-unseen-mark ?.
549   "*Mark used for articles that haven't been seen."
550   :version "22.1"
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-no-mark ?               ;Whitespace
555   "*Mark used for articles that have no other secondary mark."
556   :version "22.1"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-ancient-mark ?O
561   "*Mark used for ancient articles."
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-sparse-mark ?Q
566   "*Mark used for sparsely reffed articles."
567   :group 'gnus-summary-marks
568   :type 'character)
569
570 (defcustom gnus-canceled-mark ?G
571   "*Mark used for canceled articles."
572   :group 'gnus-summary-marks
573   :type 'character)
574
575 (defcustom gnus-duplicate-mark ?M
576   "*Mark used for duplicate articles."
577   :group 'gnus-summary-marks
578   :type 'character)
579
580 (defcustom gnus-undownloaded-mark ?-
581   "*Mark used for articles that weren't downloaded."
582   :version "22.1"
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-downloaded-mark ?+
587   "*Mark used for articles that were downloaded."
588   :group 'gnus-summary-marks
589   :type 'character)
590
591 (defcustom gnus-downloadable-mark ?%
592   "*Mark used for articles that are to be downloaded."
593   :group 'gnus-summary-marks
594   :type 'character)
595
596 (defcustom gnus-unsendable-mark ?=
597   "*Mark used for articles that won't be sent."
598   :group 'gnus-summary-marks
599   :type 'character)
600
601 (defcustom gnus-score-over-mark ?+
602   "*Score mark used for articles with high scores."
603   :group 'gnus-summary-marks
604   :type 'character)
605
606 (defcustom gnus-score-below-mark ?-
607   "*Score mark used for articles with low scores."
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-empty-thread-mark ?     ;Whitespace
612   "*There is no thread under the article."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-not-empty-thread-mark ?=
617   "*There is a thread under the article."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-view-pseudo-asynchronously nil
622   "*If non-nil, Gnus will view pseudo-articles asynchronously."
623   :group 'gnus-extract-view
624   :type 'boolean)
625
626 (defcustom gnus-auto-expirable-marks
627   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
628         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
629         gnus-souped-mark gnus-duplicate-mark)
630   "*The list of marks converted into expiration if a group is auto-expirable."
631   :version "21.1"
632   :group 'gnus-summary
633   :type '(repeat character))
634
635 (defcustom gnus-inhibit-user-auto-expire t
636   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
637   :version "21.1"
638   :group 'gnus-summary
639   :type 'boolean)
640
641 (defcustom gnus-view-pseudos nil
642   "*If `automatic', pseudo-articles will be viewed automatically.
643 If `not-confirm', pseudos will be viewed automatically, and the user
644 will not be asked to confirm the command."
645   :group 'gnus-extract-view
646   :type '(choice (const :tag "off" nil)
647                  (const automatic)
648                  (const not-confirm)))
649
650 (defcustom gnus-view-pseudos-separately t
651   "*If non-nil, one pseudo-article will be created for each file to be viewed.
652 If nil, all files that use the same viewing command will be given as a
653 list of parameters to that command."
654   :group 'gnus-extract-view
655   :type 'boolean)
656
657 (defcustom gnus-insert-pseudo-articles t
658   "*If non-nil, insert pseudo-articles when decoding articles."
659   :group 'gnus-extract-view
660   :type 'boolean)
661
662 (defcustom gnus-summary-dummy-line-format
663   "   %(:                             :%) %S\n"
664   "*The format specification for the dummy roots in the summary buffer.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions.
667
668 %S  The subject
669
670 General format specifiers can also be used.
671 See `(gnus)Formatting Variables'."
672   :link '(custom-manual "(gnus)Formatting Variables")
673   :group 'gnus-threading
674   :type 'string)
675
676 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
677   "*The format specification for the summary mode line.
678 It works along the same lines as a normal formatting string,
679 with some simple extensions:
680
681 %G  Group name
682 %p  Unprefixed group name
683 %A  Current article number
684 %z  Current article score
685 %V  Gnus version
686 %U  Number of unread articles in the group
687 %e  Number of unselected articles in the group
688 %Z  A string with unread/unselected article counts
689 %g  Shortish group name
690 %S  Subject of the current article
691 %u  User-defined spec
692 %s  Current score file name
693 %d  Number of dormant articles
694 %r  Number of articles that have been marked as read in this session
695 %E  Number of articles expunged by the score files"
696   :group 'gnus-summary-format
697   :type 'string)
698
699 (defcustom gnus-list-identifiers nil
700   "Regexp that matches list identifiers to be removed from subject.
701 This can also be a list of regexps."
702   :version "21.1"
703   :group 'gnus-summary-format
704   :group 'gnus-article-hiding
705   :type '(choice (const :tag "none" nil)
706                  (regexp :value ".*")
707                  (repeat :value (".*") regexp)))
708
709 (defcustom gnus-summary-mark-below 0
710   "*Mark all articles with a score below this variable as read.
711 This variable is local to each summary buffer and usually set by the
712 score file."
713   :group 'gnus-score-default
714   :type 'integer)
715
716 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
717   "*List of functions used for sorting articles in the summary buffer.
718
719 Each function takes two articles and returns non-nil if the first
720 article should be sorted before the other.  If you use more than one
721 function, the primary sort function should be the last.  You should
722 probably always include `gnus-article-sort-by-number' in the list of
723 sorting functions -- preferably first.  Also note that sorting by date
724 is often much slower than sorting by number, and the sorting order is
725 very similar.  (Sorting by date means sorting by the time the message
726 was sent, sorting by number means sorting by arrival time.)
727
728 Ready-made functions include `gnus-article-sort-by-number',
729 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
730 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
731 and `gnus-article-sort-by-score'.
732
733 When threading is turned on, the variable `gnus-thread-sort-functions'
734 controls how articles are sorted."
735   :group 'gnus-summary-sort
736   :type '(repeat (choice (function-item gnus-article-sort-by-number)
737                          (function-item gnus-article-sort-by-author)
738                          (function-item gnus-article-sort-by-subject)
739                          (function-item gnus-article-sort-by-date)
740                          (function-item gnus-article-sort-by-score)
741                          (function-item gnus-article-sort-by-random)
742                          (function :tag "other"))))
743
744 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
745   "*List of functions used for sorting threads in the summary buffer.
746 By default, threads are sorted by article number.
747
748 Each function takes two threads and returns non-nil if the first
749 thread should be sorted before the other.  If you use more than one
750 function, the primary sort function should be the last.  You should
751 probably always include `gnus-thread-sort-by-number' in the list of
752 sorting functions -- preferably first.  Also note that sorting by date
753 is often much slower than sorting by number, and the sorting order is
754 very similar.  (Sorting by date means sorting by the time the message
755 was sent, sorting by number means sorting by arrival time.)
756
757 Ready-made functions include `gnus-thread-sort-by-number',
758 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
759 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
760 `gnus-thread-sort-by-most-recent-number',
761 `gnus-thread-sort-by-most-recent-date',
762 `gnus-thread-sort-by-random', and
763 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
764
765 When threading is turned off, the variable
766 `gnus-article-sort-functions' controls how articles are sorted."
767   :group 'gnus-summary-sort
768   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
769                          (function-item gnus-thread-sort-by-author)
770                          (function-item gnus-thread-sort-by-subject)
771                          (function-item gnus-thread-sort-by-date)
772                          (function-item gnus-thread-sort-by-score)
773                          (function-item gnus-thread-sort-by-total-score)
774                          (function-item gnus-thread-sort-by-random)
775                          (function :tag "other"))))
776
777 (defcustom gnus-thread-score-function '+
778   "*Function used for calculating the total score of a thread.
779
780 The function is called with the scores of the article and each
781 subthread and should then return the score of the thread.
782
783 Some functions you can use are `+', `max', or `min'."
784   :group 'gnus-summary-sort
785   :type 'function)
786
787 (defcustom gnus-summary-expunge-below nil
788   "All articles that have a score less than this variable will be expunged.
789 This variable is local to the summary buffers."
790   :group 'gnus-score-default
791   :type '(choice (const :tag "off" nil)
792                  integer))
793
794 (defcustom gnus-thread-expunge-below nil
795   "All threads that have a total score less than this variable will be expunged.
796 See `gnus-thread-score-function' for en explanation of what a
797 \"thread score\" is.
798
799 This variable is local to the summary buffers."
800   :group 'gnus-threading
801   :group 'gnus-score-default
802   :type '(choice (const :tag "off" nil)
803                  integer))
804
805 (defcustom gnus-summary-mode-hook nil
806   "*A hook for Gnus summary mode.
807 This hook is run before any variables are set in the summary buffer."
808   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
809   :group 'gnus-summary-various
810   :type 'hook)
811
812 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
813 (when (featurep 'xemacs)
814   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
815   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
816   (add-hook 'gnus-summary-mode-hook
817             'gnus-xmas-switch-horizontal-scrollbar-off))
818
819 (defcustom gnus-summary-menu-hook nil
820   "*Hook run after the creation of the summary mode menu."
821   :group 'gnus-summary-visual
822   :type 'hook)
823
824 (defcustom gnus-summary-exit-hook nil
825   "*A hook called on exit from the summary buffer.
826 It will be called with point in the group buffer."
827   :group 'gnus-summary-exit
828   :type 'hook)
829
830 (defcustom gnus-summary-prepare-hook nil
831   "*A hook called after the summary buffer has been generated.
832 If you want to modify the summary buffer, you can use this hook."
833   :group 'gnus-summary-various
834   :type 'hook)
835
836 (defcustom gnus-summary-prepared-hook nil
837   "*A hook called as the last thing after the summary buffer has been generated."
838   :group 'gnus-summary-various
839   :type 'hook)
840
841 (defcustom gnus-summary-generate-hook nil
842   "*A hook run just before generating the summary buffer.
843 This hook is commonly used to customize threading variables and the
844 like."
845   :group 'gnus-summary-various
846   :type 'hook)
847
848 (defcustom gnus-select-group-hook nil
849   "*A hook called when a newsgroup is selected.
850
851 If you'd like to simplify subjects like the
852 `gnus-summary-next-same-subject' command does, you can use the
853 following hook:
854
855  (add-hook gnus-select-group-hook
856            (lambda ()
857              (mapcar (lambda (header)
858                        (mail-header-set-subject
859                         header
860                         (gnus-simplify-subject
861                          (mail-header-subject header) 're-only)))
862                      gnus-newsgroup-headers)))"
863   :group 'gnus-group-select
864   :type 'hook)
865
866 (defcustom gnus-select-article-hook nil
867   "*A hook called when an article is selected."
868   :group 'gnus-summary-choose
869   :options '(gnus-agent-fetch-selected-article)
870   :type 'hook)
871
872 (defcustom gnus-visual-mark-article-hook
873   (list 'gnus-highlight-selected-summary)
874   "*Hook run after selecting an article in the summary buffer.
875 It is meant to be used for highlighting the article in some way.  It
876 is not run if `gnus-visual' is nil."
877   :group 'gnus-summary-visual
878   :type 'hook)
879
880 (defcustom gnus-parse-headers-hook nil
881   "*A hook called before parsing the headers."
882   :group 'gnus-various
883   :type 'hook)
884
885 (defcustom gnus-exit-group-hook nil
886   "*A hook called when exiting summary mode.
887 This hook is not called from the non-updating exit commands like `Q'."
888   :group 'gnus-various
889   :type 'hook)
890
891 (defcustom gnus-summary-update-hook
892   (list 'gnus-summary-highlight-line)
893   "*A hook called when a summary line is changed.
894 The hook will not be called if `gnus-visual' is nil.
895
896 The default function `gnus-summary-highlight-line' will
897 highlight the line according to the `gnus-summary-highlight'
898 variable."
899   :group 'gnus-summary-visual
900   :type 'hook)
901
902 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
903   "*A hook called when an article is selected for the first time.
904 The hook is intended to mark an article as read (or unread)
905 automatically when it is selected."
906   :group 'gnus-summary-choose
907   :type 'hook)
908
909 (defcustom gnus-group-no-more-groups-hook nil
910   "*A hook run when returning to group mode having no more (unread) groups."
911   :group 'gnus-group-select
912   :type 'hook)
913
914 (defcustom gnus-ps-print-hook nil
915   "*A hook run before ps-printing something from Gnus."
916   :group 'gnus-summary
917   :type 'hook)
918
919 (defcustom gnus-summary-article-move-hook nil
920   "*A hook called after an article is moved, copied, respooled, or crossposted."
921   :version "22.1"
922   :group 'gnus-summary
923   :type 'hook)
924
925 (defcustom gnus-summary-article-delete-hook nil
926   "*A hook called after an article is deleted."
927   :version "22.1"
928   :group 'gnus-summary
929   :type 'hook)
930
931 (defcustom gnus-summary-article-expire-hook nil
932   "*A hook called after an article is expired."
933   :version "22.1"
934   :group 'gnus-summary
935   :type 'hook)
936
937 (defcustom gnus-summary-display-arrow
938   (and (fboundp 'display-graphic-p)
939        (display-graphic-p))
940   "*If non-nil, display an arrow highlighting the current article."
941   :version "22.1"
942   :group 'gnus-summary
943   :type 'boolean)
944
945 (defcustom gnus-summary-selected-face 'gnus-summary-selected
946   "Face used for highlighting the current article in the summary buffer."
947   :group 'gnus-summary-visual
948   :type 'face)
949
950 (defvar gnus-tmp-downloaded nil)
951
952 (defcustom gnus-summary-highlight
953   '(((eq mark gnus-canceled-mark)
954      . gnus-summary-cancelled)
955     ((and uncached (> score default-high))
956      . gnus-summary-high-undownloaded)
957     ((and uncached (< score default-low))
958      . gnus-summary-low-undownloaded)
959     (uncached
960      . gnus-summary-normal-undownloaded)
961     ((and (> score default-high)
962           (or (eq mark gnus-dormant-mark)
963               (eq mark gnus-ticked-mark)))
964      . gnus-summary-high-ticked)
965     ((and (< score default-low)
966           (or (eq mark gnus-dormant-mark)
967               (eq mark gnus-ticked-mark)))
968      . gnus-summary-low-ticked)
969     ((or (eq mark gnus-dormant-mark)
970          (eq mark gnus-ticked-mark))
971      . gnus-summary-normal-ticked)
972     ((and (> score default-high) (eq mark gnus-ancient-mark))
973      . gnus-summary-high-ancient)
974     ((and (< score default-low) (eq mark gnus-ancient-mark))
975      . gnus-summary-low-ancient)
976     ((eq mark gnus-ancient-mark)
977      . gnus-summary-normal-ancient)
978     ((and (> score default-high) (eq mark gnus-unread-mark))
979      . gnus-summary-high-unread)
980     ((and (< score default-low) (eq mark gnus-unread-mark))
981      . gnus-summary-low-unread)
982     ((eq mark gnus-unread-mark)
983      . gnus-summary-normal-unread)
984     ((> score default-high)
985      . gnus-summary-high-read)
986     ((< score default-low)
987      . gnus-summary-low-read)
988     (t
989      . gnus-summary-normal-read))
990   "*Controls the highlighting of summary buffer lines.
991
992 A list of (FORM . FACE) pairs.  When deciding how a particular
993 summary line should be displayed, each form is evaluated.  The content
994 of the face field after the first true form is used.  You can change
995 how those summary lines are displayed, by editing the face field.
996
997 You can use the following variables in the FORM field.
998
999 score:        The article's score.
1000 default:      The default article score.
1001 default-high: The default score for high scored articles.
1002 default-low:  The default score for low scored articles.
1003 below:        The score below which articles are automatically marked as read.
1004 mark:         The article's mark.
1005 uncached:     Non-nil if the article is uncached."
1006   :group 'gnus-summary-visual
1007   :type '(repeat (cons (sexp :tag "Form" nil)
1008                        face)))
1009 (put 'gnus-summary-highlight 'risky-local-variable t)
1010
1011 (defcustom gnus-alter-header-function nil
1012   "Function called to allow alteration of article header structures.
1013 The function is called with one parameter, the article header vector,
1014 which it may alter in any way."
1015   :type '(choice (const :tag "None" nil)
1016                  function)
1017   :group 'gnus-summary)
1018
1019 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1020   "Function used to decode a string with encoded words.")
1021
1022 (defvar gnus-decode-encoded-address-function
1023   'mail-decode-encoded-address-string
1024   "Function used to decode addresses with encoded words.")
1025
1026 (defcustom gnus-extra-headers '(To Newsgroups)
1027   "*Extra headers to parse."
1028   :version "21.1"
1029   :group 'gnus-summary
1030   :type '(repeat symbol))
1031
1032 (defcustom gnus-ignored-from-addresses
1033   (and user-mail-address
1034        (not (string= user-mail-address ""))
1035        (regexp-quote user-mail-address))
1036   "*Regexp of From headers that may be suppressed in favor of To headers."
1037   :version "21.1"
1038   :group 'gnus-summary
1039   :type 'regexp)
1040
1041 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1042   "List of charsets that should be ignored.
1043 When these charsets are used in the \"charset\" parameter, the
1044 default charset will be used instead."
1045   :version "21.1"
1046   :type '(repeat symbol)
1047   :group 'gnus-charset)
1048
1049 (defcustom gnus-newsgroup-maximum-articles nil
1050   "The maximum number of articles a newsgroup.
1051 If this is a number, old articles in a newsgroup exceeding this number
1052 are silently ignored.  If it is nil, no article is ignored.  Note that
1053 setting this variable to a number might prevent you from reading very
1054 old articles."
1055   :group 'gnus-group-select
1056   :version "22.2"
1057   :type '(choice (const :tag "No limit" nil)
1058                  integer))
1059
1060 (gnus-define-group-parameter
1061  ignored-charsets
1062  :type list
1063  :function-document
1064  "Return the ignored charsets of GROUP."
1065  :variable gnus-group-ignored-charsets-alist
1066  :variable-default
1067  '(("alt\\.chinese\\.text" iso-8859-1))
1068  :variable-document
1069  "Alist of regexps (to match group names) and charsets that should be ignored.
1070 When these charsets are used in the \"charset\" parameter, the
1071 default charset will be used instead."
1072  :variable-group gnus-charset
1073  :variable-type '(repeat (cons (regexp :tag "Group")
1074                                (repeat symbol)))
1075  :parameter-type '(choice :tag "Ignored charsets"
1076                           :value nil
1077                           (repeat (symbol)))
1078  :parameter-document       "\
1079 List of charsets that should be ignored.
1080
1081 When these charsets are used in the \"charset\" parameter, the
1082 default charset will be used instead.")
1083
1084 (defcustom gnus-group-highlight-words-alist nil
1085   "Alist of group regexps and highlight regexps.
1086 This variable uses the same syntax as `gnus-emphasis-alist'."
1087   :version "21.1"
1088   :type '(repeat (cons (regexp :tag "Group")
1089                        (repeat (list (regexp :tag "Highlight regexp")
1090                                      (number :tag "Group for entire word" 0)
1091                                      (number :tag "Group for displayed part" 0)
1092                                      (symbol :tag "Face"
1093                                              gnus-emphasis-highlight-words)))))
1094   :group 'gnus-summary-visual)
1095
1096 (defcustom gnus-summary-show-article-charset-alist
1097   nil
1098   "Alist of number and charset.
1099 The article will be shown with the charset corresponding to the
1100 numbered argument.
1101 For example: ((1 . cn-gb-2312) (2 . big5))."
1102   :version "21.1"
1103   :type '(repeat (cons (number :tag "Argument" 1)
1104                        (symbol :tag "Charset")))
1105   :group 'gnus-charset)
1106
1107 (defcustom gnus-preserve-marks t
1108   "Whether marks are preserved when moving, copying and respooling messages."
1109   :version "21.1"
1110   :type 'boolean
1111   :group 'gnus-summary-marks)
1112
1113 (defcustom gnus-alter-articles-to-read-function nil
1114   "Function to be called to alter the list of articles to be selected."
1115   :type '(choice (const nil) function)
1116   :group 'gnus-summary)
1117
1118 (defcustom gnus-orphan-score nil
1119   "*All orphans get this score added.  Set in the score file."
1120   :group 'gnus-score-default
1121   :type '(choice (const nil)
1122                  integer))
1123
1124 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1125   "*A regexp to match MIME parts when saving multiple parts of a
1126 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1127 This regexp will be used by default when prompting the user for which
1128 type of files to save."
1129   :group 'gnus-summary
1130   :type 'regexp)
1131
1132 (defcustom gnus-read-all-available-headers nil
1133   "Whether Gnus should parse all headers made available to it.
1134 This is mostly relevant for slow back ends where the user may
1135 wish to widen the summary buffer to include all headers
1136 that were fetched.  Say, for nnultimate groups."
1137   :version "22.1"
1138   :group 'gnus-summary
1139   :type '(choice boolean regexp))
1140
1141 (defcustom gnus-summary-muttprint-program "muttprint"
1142   "Command (and optional arguments) used to run Muttprint."
1143   :version "22.1"
1144   :group 'gnus-summary
1145   :type 'string)
1146
1147 (defcustom gnus-article-loose-mime nil
1148   "If non-nil, don't require MIME-Version header.
1149 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1150 supply the MIME-Version header or deliberately strip it from the mail.
1151 Set it to non-nil, Gnus will treat some articles as MIME even if
1152 the MIME-Version header is missed."
1153   :version "22.1"
1154   :type 'boolean
1155   :group 'gnus-article-mime)
1156
1157 (defcustom gnus-article-emulate-mime t
1158   "If non-nil, use MIME emulation for uuencode and the like.
1159 This means that Gnus will search message bodies for text that look
1160 like uuencoded bits, yEncoded bits, and so on, and present that using
1161 the normal Gnus MIME machinery."
1162   :version "22.1"
1163   :type 'boolean
1164   :group 'gnus-article-mime)
1165
1166 ;;; Internal variables
1167
1168 (defvar gnus-summary-display-cache nil)
1169 (defvar gnus-article-mime-handles nil)
1170 (defvar gnus-article-decoded-p nil)
1171 (defvar gnus-article-charset nil)
1172 (defvar gnus-article-ignored-charsets nil)
1173 (defvar gnus-scores-exclude-files nil)
1174 (defvar gnus-page-broken nil)
1175
1176 (defvar gnus-original-article nil)
1177 (defvar gnus-article-internal-prepare-hook nil)
1178 (defvar gnus-newsgroup-process-stack nil)
1179
1180 (defvar gnus-thread-indent-array nil)
1181 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1182 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1183   "Function called to sort the articles within a thread after it has been gathered together.")
1184
1185 (defvar gnus-summary-save-parts-type-history nil)
1186 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1187
1188 ;; Avoid highlighting in kill files.
1189 (defvar gnus-summary-inhibit-highlight nil)
1190 (defvar gnus-newsgroup-selected-overlay nil)
1191 (defvar gnus-inhibit-limiting nil)
1192 (defvar gnus-newsgroup-adaptive-score-file nil)
1193 (defvar gnus-current-score-file nil)
1194 (defvar gnus-current-move-group nil)
1195 (defvar gnus-current-copy-group nil)
1196 (defvar gnus-current-crosspost-group nil)
1197 (defvar gnus-newsgroup-display nil)
1198
1199 (defvar gnus-newsgroup-dependencies nil)
1200 (defvar gnus-newsgroup-adaptive nil)
1201 (defvar gnus-summary-display-article-function nil)
1202 (defvar gnus-summary-highlight-line-function nil
1203   "Function called after highlighting a summary line.")
1204
1205 (defvar gnus-summary-line-format-alist
1206   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1207     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1208     (?s gnus-tmp-subject-or-nil ?s)
1209     (?n gnus-tmp-name ?s)
1210     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1211         ?s)
1212     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1213             gnus-tmp-from) ?s)
1214     (?F gnus-tmp-from ?s)
1215     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1216     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1217     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1218     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1219     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1220     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1221     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1222     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1223     (?L gnus-tmp-lines ?s)
1224     (?O gnus-tmp-downloaded ?c)
1225     (?I gnus-tmp-indentation ?s)
1226     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1227     (?R gnus-tmp-replied ?c)
1228     (?\[ gnus-tmp-opening-bracket ?c)
1229     (?\] gnus-tmp-closing-bracket ?c)
1230     (?\> (make-string gnus-tmp-level ? ) ?s)
1231     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1232     (?i gnus-tmp-score ?d)
1233     (?z gnus-tmp-score-char ?c)
1234     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1235     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1236     (?U gnus-tmp-unread ?c)
1237     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1238         ?s)
1239     (?t (gnus-summary-number-of-articles-in-thread
1240          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1241         ?d)
1242     (?e (gnus-summary-number-of-articles-in-thread
1243          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1244         ?c)
1245     (?u gnus-tmp-user-defined ?s)
1246     (?P (gnus-pick-line-number) ?d)
1247     (?B gnus-tmp-thread-tree-header-string ?s)
1248     (user-date (gnus-user-date
1249                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1250   "An alist of format specifications that can appear in summary lines.
1251 These are paired with what variables they correspond with, along with
1252 the type of the variable (string, integer, character, etc).")
1253
1254 (defvar gnus-summary-dummy-line-format-alist
1255   `((?S gnus-tmp-subject ?s)
1256     (?N gnus-tmp-number ?d)
1257     (?u gnus-tmp-user-defined ?s)))
1258
1259 (defvar gnus-summary-mode-line-format-alist
1260   `((?G gnus-tmp-group-name ?s)
1261     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1262     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1263     (?A gnus-tmp-article-number ?d)
1264     (?Z gnus-tmp-unread-and-unselected ?s)
1265     (?V gnus-version ?s)
1266     (?U gnus-tmp-unread-and-unticked ?d)
1267     (?S gnus-tmp-subject ?s)
1268     (?e gnus-tmp-unselected ?d)
1269     (?u gnus-tmp-user-defined ?s)
1270     (?d (length gnus-newsgroup-dormant) ?d)
1271     (?t (length gnus-newsgroup-marked) ?d)
1272     (?h (length gnus-newsgroup-spam-marked) ?d)
1273     (?r (length gnus-newsgroup-reads) ?d)
1274     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1275     (?E gnus-newsgroup-expunged-tally ?d)
1276     (?s (gnus-current-score-file-nondirectory) ?s)))
1277
1278 (defvar gnus-last-search-regexp nil
1279   "Default regexp for article search command.")
1280
1281 (defvar gnus-last-shell-command nil
1282   "Default shell command on article.")
1283
1284 (defvar gnus-newsgroup-agentized nil
1285   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1286 (defvar gnus-newsgroup-begin nil)
1287 (defvar gnus-newsgroup-end nil)
1288 (defvar gnus-newsgroup-last-rmail nil)
1289 (defvar gnus-newsgroup-last-mail nil)
1290 (defvar gnus-newsgroup-last-folder nil)
1291 (defvar gnus-newsgroup-last-file nil)
1292 (defvar gnus-newsgroup-last-directory nil)
1293 (defvar gnus-newsgroup-auto-expire nil)
1294 (defvar gnus-newsgroup-active nil)
1295
1296 (defvar gnus-newsgroup-data nil)
1297 (defvar gnus-newsgroup-data-reverse nil)
1298 (defvar gnus-newsgroup-limit nil)
1299 (defvar gnus-newsgroup-limits nil)
1300 (defvar gnus-summary-use-undownloaded-faces nil)
1301
1302 (defvar gnus-newsgroup-unreads nil
1303   "Sorted list of unread articles in the current newsgroup.")
1304
1305 (defvar gnus-newsgroup-unselected nil
1306   "Sorted list of unselected unread articles in the current newsgroup.")
1307
1308 (defvar gnus-newsgroup-reads nil
1309   "Alist of read articles and article marks in the current newsgroup.")
1310
1311 (defvar gnus-newsgroup-expunged-tally nil)
1312
1313 (defvar gnus-newsgroup-marked nil
1314   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1315
1316 (defvar gnus-newsgroup-spam-marked nil
1317   "List of ranges of articles that have been marked as spam.")
1318
1319 (defvar gnus-newsgroup-killed nil
1320   "List of ranges of articles that have been through the scoring process.")
1321
1322 (defvar gnus-newsgroup-cached nil
1323   "Sorted list of articles that come from the article cache.")
1324
1325 (defvar gnus-newsgroup-saved nil
1326   "List of articles that have been saved.")
1327
1328 (defvar gnus-newsgroup-kill-headers nil)
1329
1330 (defvar gnus-newsgroup-replied nil
1331   "List of articles that have been replied to in the current newsgroup.")
1332
1333 (defvar gnus-newsgroup-forwarded nil
1334   "List of articles that have been forwarded in the current newsgroup.")
1335
1336 (defvar gnus-newsgroup-recent nil
1337   "List of articles that have are recent in the current newsgroup.")
1338
1339 (defvar gnus-newsgroup-expirable nil
1340   "Sorted list of articles in the current newsgroup that can be expired.")
1341
1342 (defvar gnus-newsgroup-processable nil
1343   "List of articles in the current newsgroup that can be processed.")
1344
1345 (defvar gnus-newsgroup-downloadable nil
1346   "Sorted list of articles in the current newsgroup that can be processed.")
1347
1348 (defvar gnus-newsgroup-unfetched nil
1349   "Sorted list of articles in the current newsgroup whose headers have
1350 not been fetched into the agent.
1351
1352 This list will always be a subset of gnus-newsgroup-undownloaded.")
1353
1354 (defvar gnus-newsgroup-undownloaded nil
1355   "List of articles in the current newsgroup that haven't been downloaded.")
1356
1357 (defvar gnus-newsgroup-unsendable nil
1358   "List of articles in the current newsgroup that won't be sent.")
1359
1360 (defvar gnus-newsgroup-bookmarks nil
1361   "List of articles in the current newsgroup that have bookmarks.")
1362
1363 (defvar gnus-newsgroup-dormant nil
1364   "Sorted list of dormant articles in the current newsgroup.")
1365
1366 (defvar gnus-newsgroup-unseen nil
1367   "List of unseen articles in the current newsgroup.")
1368
1369 (defvar gnus-newsgroup-seen nil
1370   "Range of seen articles in the current newsgroup.")
1371
1372 (defvar gnus-newsgroup-articles nil
1373   "List of articles in the current newsgroup.")
1374
1375 (defvar gnus-newsgroup-scored nil
1376   "List of scored articles in the current newsgroup.")
1377
1378 (defvar gnus-newsgroup-headers nil
1379   "List of article headers in the current newsgroup.")
1380
1381 (defvar gnus-newsgroup-threads nil)
1382
1383 (defvar gnus-newsgroup-prepared nil
1384   "Whether the current group has been prepared properly.")
1385
1386 (defvar gnus-newsgroup-ancient nil
1387   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1388
1389 (defvar gnus-newsgroup-sparse nil)
1390
1391 (defvar gnus-current-article nil)
1392 (defvar gnus-article-current nil)
1393 (defvar gnus-current-headers nil)
1394 (defvar gnus-have-all-headers nil)
1395 (defvar gnus-last-article nil)
1396 (defvar gnus-newsgroup-history nil)
1397 (defvar gnus-newsgroup-charset nil)
1398 (defvar gnus-newsgroup-ephemeral-charset nil)
1399 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1400
1401 (defvar gnus-article-before-search nil)
1402
1403 (defvar gnus-summary-local-variables
1404   '(gnus-newsgroup-name
1405     gnus-newsgroup-begin gnus-newsgroup-end
1406     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1407     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1408     gnus-newsgroup-last-directory
1409     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1410     gnus-newsgroup-unselected gnus-newsgroup-marked
1411     gnus-newsgroup-spam-marked
1412     gnus-newsgroup-reads gnus-newsgroup-saved
1413     gnus-newsgroup-replied gnus-newsgroup-forwarded
1414     gnus-newsgroup-recent
1415     gnus-newsgroup-expirable
1416     gnus-newsgroup-processable gnus-newsgroup-killed
1417     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1418     gnus-newsgroup-unfetched
1419     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1420     gnus-newsgroup-seen gnus-newsgroup-articles
1421     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1422     gnus-newsgroup-headers gnus-newsgroup-threads
1423     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1424     gnus-current-article gnus-current-headers gnus-have-all-headers
1425     gnus-last-article gnus-article-internal-prepare-hook
1426     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1427     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1428     gnus-thread-expunge-below
1429     gnus-score-alist gnus-current-score-file
1430     (gnus-summary-expunge-below . global)
1431     (gnus-summary-mark-below . global)
1432     (gnus-orphan-score . global)
1433     gnus-newsgroup-active gnus-scores-exclude-files
1434     gnus-newsgroup-history gnus-newsgroup-ancient
1435     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1436     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1437     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1438     (gnus-newsgroup-expunged-tally . 0)
1439     gnus-cache-removable-articles gnus-newsgroup-cached
1440     gnus-newsgroup-data gnus-newsgroup-data-reverse
1441     gnus-newsgroup-limit gnus-newsgroup-limits
1442     gnus-newsgroup-charset gnus-newsgroup-display
1443     gnus-summary-use-undownloaded-faces)
1444   "Variables that are buffer-local to the summary buffers.")
1445
1446 (defvar gnus-newsgroup-variables nil
1447   "A list of variables that have separate values in different newsgroups.
1448 A list of newsgroup (summary buffer) local variables, or cons of
1449 variables and their default expressions to be evalled (when the default
1450 values are not nil), that should be made global while the summary buffer
1451 is active.
1452
1453 Note: The default expressions will be evaluated (using function `eval')
1454 before assignment to the local variable rather than just assigned to it.
1455 If the default expression is the symbol `global', that symbol will not
1456 be evaluated but the global value of the local variable will be used
1457 instead.
1458
1459 These variables can be used to set variables in the group parameters
1460 while still allowing them to affect operations done in other buffers.
1461 For example:
1462
1463 \(setq gnus-newsgroup-variables
1464      '(message-use-followup-to
1465        (gnus-visible-headers .
1466          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1467 ")
1468
1469 ;; Byte-compiler warning.
1470 (eval-when-compile
1471   ;; Bind features so that require will believe that gnus-sum has
1472   ;; already been loaded (avoids infinite recursion)
1473   (let ((features (cons 'gnus-sum features)))
1474     ;; Several of the declarations in gnus-sum are needed to load the
1475     ;; following files. Right now, these definitions have been
1476     ;; compiled but not defined (evaluated).  We could either do a
1477     ;; eval-and-compile about all of the declarations or evaluate the
1478     ;; source file.
1479     (if (boundp 'gnus-newsgroup-variables)
1480         nil
1481       (load "gnus-sum.el" t t t))
1482     (require 'gnus)
1483     (require 'gnus-agent)
1484     (require 'gnus-art)))
1485
1486 ;; MIME stuff.
1487
1488 (defvar gnus-decode-encoded-word-methods
1489   '(mail-decode-encoded-word-string)
1490   "List of methods used to decode encoded words.
1491
1492 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1493 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1494 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1495 whose names match REGEXP.
1496
1497 For example:
1498 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1499  mail-decode-encoded-word-string
1500  (\"chinese\" . rfc1843-decode-string))")
1501
1502 (defvar gnus-decode-encoded-word-methods-cache nil)
1503
1504 (defun gnus-multi-decode-encoded-word-string (string)
1505   "Apply the functions from `gnus-encoded-word-methods' that match."
1506   (unless (and gnus-decode-encoded-word-methods-cache
1507                (eq gnus-newsgroup-name
1508                    (car gnus-decode-encoded-word-methods-cache)))
1509     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1510     (mapcar (lambda (x)
1511               (if (symbolp x)
1512                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1513                 (if (and gnus-newsgroup-name
1514                          (string-match (car x) gnus-newsgroup-name))
1515                     (nconc gnus-decode-encoded-word-methods-cache
1516                            (list (cdr x))))))
1517             gnus-decode-encoded-word-methods))
1518   (let ((xlist gnus-decode-encoded-word-methods-cache))
1519     (pop xlist)
1520     (while xlist
1521       (setq string (funcall (pop xlist) string))))
1522   string)
1523
1524 ;; Subject simplification.
1525
1526 (defun gnus-simplify-whitespace (str)
1527   "Remove excessive whitespace from STR."
1528   ;; Multiple spaces.
1529   (while (string-match "[ \t][ \t]+" str)
1530     (setq str (concat (substring str 0 (match-beginning 0))
1531                         " "
1532                         (substring str (match-end 0)))))
1533   ;; Leading spaces.
1534   (when (string-match "^[ \t]+" str)
1535     (setq str (substring str (match-end 0))))
1536   ;; Trailing spaces.
1537   (when (string-match "[ \t]+$" str)
1538     (setq str (substring str 0 (match-beginning 0))))
1539   str)
1540
1541 (defun gnus-simplify-all-whitespace (str)
1542   "Remove all whitespace from STR."
1543   (while (string-match "[ \t\n]+" str)
1544     (setq str (replace-match "" nil nil str)))
1545   str)
1546
1547 (defsubst gnus-simplify-subject-re (subject)
1548   "Remove \"Re:\" from subject lines."
1549   (if (string-match message-subject-re-regexp subject)
1550       (substring subject (match-end 0))
1551     subject))
1552
1553 (defun gnus-simplify-subject (subject &optional re-only)
1554   "Remove `Re:' and words in parentheses.
1555 If RE-ONLY is non-nil, strip leading `Re:'s only."
1556   (let ((case-fold-search t))           ;Ignore case.
1557     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1558     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1559       (setq subject (substring subject (match-end 0))))
1560     ;; Remove uninteresting prefixes.
1561     (when (and (not re-only)
1562                gnus-simplify-ignored-prefixes
1563                (string-match gnus-simplify-ignored-prefixes subject))
1564       (setq subject (substring subject (match-end 0))))
1565     ;; Remove words in parentheses from end.
1566     (unless re-only
1567       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1568         (setq subject (substring subject 0 (match-beginning 0)))))
1569     ;; Return subject string.
1570     subject))
1571
1572 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1573 ;; all whitespace.
1574 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1575   (goto-char (point-min))
1576   (while (re-search-forward regexp nil t)
1577     (replace-match (or newtext ""))))
1578
1579 (defun gnus-simplify-buffer-fuzzy ()
1580   "Simplify string in the buffer fuzzily.
1581 The string in the accessible portion of the current buffer is simplified.
1582 It is assumed to be a single-line subject.
1583 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1584 matter is removed.  Additional things can be deleted by setting
1585 `gnus-simplify-subject-fuzzy-regexp'."
1586   (let ((case-fold-search t)
1587         (modified-tick))
1588     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1589
1590     (while (not (eq modified-tick (buffer-modified-tick)))
1591       (setq modified-tick (buffer-modified-tick))
1592       (cond
1593        ((listp gnus-simplify-subject-fuzzy-regexp)
1594         (mapcar 'gnus-simplify-buffer-fuzzy-step
1595                 gnus-simplify-subject-fuzzy-regexp))
1596        (gnus-simplify-subject-fuzzy-regexp
1597         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1598       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1599       (gnus-simplify-buffer-fuzzy-step
1600        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1601       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1602
1603     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1604     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1605     (gnus-simplify-buffer-fuzzy-step " $")
1606     (gnus-simplify-buffer-fuzzy-step "^ +")))
1607
1608 (defun gnus-simplify-subject-fuzzy (subject)
1609   "Simplify a subject string fuzzily.
1610 See `gnus-simplify-buffer-fuzzy' for details."
1611   (save-excursion
1612     (gnus-set-work-buffer)
1613     (let ((case-fold-search t))
1614       ;; Remove uninteresting prefixes.
1615       (when (and gnus-simplify-ignored-prefixes
1616                  (string-match gnus-simplify-ignored-prefixes subject))
1617         (setq subject (substring subject (match-end 0))))
1618       (insert subject)
1619       (inline (gnus-simplify-buffer-fuzzy))
1620       (buffer-string))))
1621
1622 (defsubst gnus-simplify-subject-fully (subject)
1623   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1624   (cond
1625    (gnus-simplify-subject-functions
1626     (gnus-map-function gnus-simplify-subject-functions subject))
1627    ((null gnus-summary-gather-subject-limit)
1628     (gnus-simplify-subject-re subject))
1629    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1630     (gnus-simplify-subject-fuzzy subject))
1631    ((numberp gnus-summary-gather-subject-limit)
1632     (gnus-limit-string (gnus-simplify-subject-re subject)
1633                        gnus-summary-gather-subject-limit))
1634    (t
1635     subject)))
1636
1637 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1638   "Check whether two subjects are equal.
1639 If optional argument SIMPLE-FIRST is t, first argument is already
1640 simplified."
1641   (cond
1642    ((null simple-first)
1643     (equal (gnus-simplify-subject-fully s1)
1644            (gnus-simplify-subject-fully s2)))
1645    (t
1646     (equal s1
1647            (gnus-simplify-subject-fully s2)))))
1648
1649 (defun gnus-summary-bubble-group ()
1650   "Increase the score of the current group.
1651 This is a handy function to add to `gnus-summary-exit-hook' to
1652 increase the score of each group you read."
1653   (gnus-group-add-score gnus-newsgroup-name))
1654
1655 \f
1656 ;;;
1657 ;;; Gnus summary mode
1658 ;;;
1659
1660 (put 'gnus-summary-mode 'mode-class 'special)
1661
1662 (defvar gnus-article-commands-menu)
1663
1664 ;; Non-orthogonal keys
1665
1666 (gnus-define-keys gnus-summary-mode-map
1667   " " gnus-summary-next-page
1668   "\177" gnus-summary-prev-page
1669   [delete] gnus-summary-prev-page
1670   [backspace] gnus-summary-prev-page
1671   "\r" gnus-summary-scroll-up
1672   "\M-\r" gnus-summary-scroll-down
1673   "n" gnus-summary-next-unread-article
1674   "p" gnus-summary-prev-unread-article
1675   "N" gnus-summary-next-article
1676   "P" gnus-summary-prev-article
1677   "\M-\C-n" gnus-summary-next-same-subject
1678   "\M-\C-p" gnus-summary-prev-same-subject
1679   "\M-n" gnus-summary-next-unread-subject
1680   "\M-p" gnus-summary-prev-unread-subject
1681   "." gnus-summary-first-unread-article
1682   "," gnus-summary-best-unread-article
1683   "\M-s" gnus-summary-search-article-forward
1684   "\M-r" gnus-summary-search-article-backward
1685   "<" gnus-summary-beginning-of-article
1686   ">" gnus-summary-end-of-article
1687   "j" gnus-summary-goto-article
1688   "^" gnus-summary-refer-parent-article
1689   "\M-^" gnus-summary-refer-article
1690   "u" gnus-summary-tick-article-forward
1691   "!" gnus-summary-tick-article-forward
1692   "U" gnus-summary-tick-article-backward
1693   "d" gnus-summary-mark-as-read-forward
1694   "D" gnus-summary-mark-as-read-backward
1695   "E" gnus-summary-mark-as-expirable
1696   "\M-u" gnus-summary-clear-mark-forward
1697   "\M-U" gnus-summary-clear-mark-backward
1698   "k" gnus-summary-kill-same-subject-and-select
1699   "\C-k" gnus-summary-kill-same-subject
1700   "\M-\C-k" gnus-summary-kill-thread
1701   "\M-\C-l" gnus-summary-lower-thread
1702   "e" gnus-summary-edit-article
1703   "#" gnus-summary-mark-as-processable
1704   "\M-#" gnus-summary-unmark-as-processable
1705   "\M-\C-t" gnus-summary-toggle-threads
1706   "\M-\C-s" gnus-summary-show-thread
1707   "\M-\C-h" gnus-summary-hide-thread
1708   "\M-\C-f" gnus-summary-next-thread
1709   "\M-\C-b" gnus-summary-prev-thread
1710   [(meta down)] gnus-summary-next-thread
1711   [(meta up)] gnus-summary-prev-thread
1712   "\M-\C-u" gnus-summary-up-thread
1713   "\M-\C-d" gnus-summary-down-thread
1714   "&" gnus-summary-execute-command
1715   "c" gnus-summary-catchup-and-exit
1716   "\C-w" gnus-summary-mark-region-as-read
1717   "\C-t" gnus-summary-toggle-truncation
1718   "?" gnus-summary-mark-as-dormant
1719   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1720   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1721   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1722   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1723   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1724   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1725   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1726   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1727   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1728   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1729   "=" gnus-summary-expand-window
1730   "\C-x\C-s" gnus-summary-reselect-current-group
1731   "\M-g" gnus-summary-rescan-group
1732   "w" gnus-summary-stop-page-breaking
1733   "\C-c\C-r" gnus-summary-caesar-message
1734   "f" gnus-summary-followup
1735   "F" gnus-summary-followup-with-original
1736   "C" gnus-summary-cancel-article
1737   "r" gnus-summary-reply
1738   "R" gnus-summary-reply-with-original
1739   "\C-c\C-f" gnus-summary-mail-forward
1740   "o" gnus-summary-save-article
1741   "\C-o" gnus-summary-save-article-mail
1742   "|" gnus-summary-pipe-output
1743   "\M-k" gnus-summary-edit-local-kill
1744   "\M-K" gnus-summary-edit-global-kill
1745   ;; "V" gnus-version
1746   "\C-c\C-d" gnus-summary-describe-group
1747   "q" gnus-summary-exit
1748   "Q" gnus-summary-exit-no-update
1749   "\C-c\C-i" gnus-info-find-node
1750   gnus-mouse-2 gnus-mouse-pick-article
1751   [follow-link] mouse-face
1752   "m" gnus-summary-mail-other-window
1753   "a" gnus-summary-post-news
1754   "i" gnus-summary-news-other-window
1755   "x" gnus-summary-limit-to-unread
1756   "s" gnus-summary-isearch-article
1757   "t" gnus-summary-toggle-header
1758   "g" gnus-summary-show-article
1759   "l" gnus-summary-goto-last-article
1760   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1761   "\C-d" gnus-summary-enter-digest-group
1762   "\M-\C-d" gnus-summary-read-document
1763   "\M-\C-e" gnus-summary-edit-parameters
1764   "\M-\C-a" gnus-summary-customize-parameters
1765   "\C-c\C-b" gnus-bug
1766   "*" gnus-cache-enter-article
1767   "\M-*" gnus-cache-remove-article
1768   "\M-&" gnus-summary-universal-argument
1769   "\C-l" gnus-recenter
1770   "I" gnus-summary-increase-score
1771   "L" gnus-summary-lower-score
1772   "\M-i" gnus-symbolic-argument
1773   "h" gnus-summary-select-article-buffer
1774
1775   "b" gnus-article-view-part
1776   "\M-t" gnus-summary-toggle-display-buttonized
1777
1778   "V" gnus-summary-score-map
1779   "X" gnus-uu-extract-map
1780   "S" gnus-summary-send-map)
1781
1782 ;; Sort of orthogonal keymap
1783 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1784   "t" gnus-summary-tick-article-forward
1785   "!" gnus-summary-tick-article-forward
1786   "d" gnus-summary-mark-as-read-forward
1787   "r" gnus-summary-mark-as-read-forward
1788   "c" gnus-summary-clear-mark-forward
1789   " " gnus-summary-clear-mark-forward
1790   "e" gnus-summary-mark-as-expirable
1791   "x" gnus-summary-mark-as-expirable
1792   "?" gnus-summary-mark-as-dormant
1793   "b" gnus-summary-set-bookmark
1794   "B" gnus-summary-remove-bookmark
1795   "#" gnus-summary-mark-as-processable
1796   "\M-#" gnus-summary-unmark-as-processable
1797   "S" gnus-summary-limit-include-expunged
1798   "C" gnus-summary-catchup
1799   "H" gnus-summary-catchup-to-here
1800   "h" gnus-summary-catchup-from-here
1801   "\C-c" gnus-summary-catchup-all
1802   "k" gnus-summary-kill-same-subject-and-select
1803   "K" gnus-summary-kill-same-subject
1804   "P" gnus-uu-mark-map)
1805
1806 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1807   "c" gnus-summary-clear-above
1808   "u" gnus-summary-tick-above
1809   "m" gnus-summary-mark-above
1810   "k" gnus-summary-kill-below)
1811
1812 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1813   "/" gnus-summary-limit-to-subject
1814   "n" gnus-summary-limit-to-articles
1815   "w" gnus-summary-pop-limit
1816   "s" gnus-summary-limit-to-subject
1817   "a" gnus-summary-limit-to-author
1818   "u" gnus-summary-limit-to-unread
1819   "m" gnus-summary-limit-to-marks
1820   "M" gnus-summary-limit-exclude-marks
1821   "v" gnus-summary-limit-to-score
1822   "*" gnus-summary-limit-include-cached
1823   "D" gnus-summary-limit-include-dormant
1824   "T" gnus-summary-limit-include-thread
1825   "d" gnus-summary-limit-exclude-dormant
1826   "t" gnus-summary-limit-to-age
1827   "." gnus-summary-limit-to-unseen
1828   "x" gnus-summary-limit-to-extra
1829   "p" gnus-summary-limit-to-display-predicate
1830   "E" gnus-summary-limit-include-expunged
1831   "c" gnus-summary-limit-exclude-childless-dormant
1832   "C" gnus-summary-limit-mark-excluded-as-read
1833   "o" gnus-summary-insert-old-articles
1834   "N" gnus-summary-insert-new-articles)
1835
1836 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1837   "n" gnus-summary-next-unread-article
1838   "p" gnus-summary-prev-unread-article
1839   "N" gnus-summary-next-article
1840   "P" gnus-summary-prev-article
1841   "\C-n" gnus-summary-next-same-subject
1842   "\C-p" gnus-summary-prev-same-subject
1843   "\M-n" gnus-summary-next-unread-subject
1844   "\M-p" gnus-summary-prev-unread-subject
1845   "f" gnus-summary-first-unread-article
1846   "b" gnus-summary-best-unread-article
1847   "j" gnus-summary-goto-article
1848   "g" gnus-summary-goto-subject
1849   "l" gnus-summary-goto-last-article
1850   "o" gnus-summary-pop-article)
1851
1852 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1853   "k" gnus-summary-kill-thread
1854   "l" gnus-summary-lower-thread
1855   "i" gnus-summary-raise-thread
1856   "T" gnus-summary-toggle-threads
1857   "t" gnus-summary-rethread-current
1858   "^" gnus-summary-reparent-thread
1859   "s" gnus-summary-show-thread
1860   "S" gnus-summary-show-all-threads
1861   "h" gnus-summary-hide-thread
1862   "H" gnus-summary-hide-all-threads
1863   "n" gnus-summary-next-thread
1864   "p" gnus-summary-prev-thread
1865   "u" gnus-summary-up-thread
1866   "o" gnus-summary-top-thread
1867   "d" gnus-summary-down-thread
1868   "#" gnus-uu-mark-thread
1869   "\M-#" gnus-uu-unmark-thread)
1870
1871 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1872   "g" gnus-summary-prepare
1873   "c" gnus-summary-insert-cached-articles
1874   "d" gnus-summary-insert-dormant-articles)
1875
1876 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1877   "c" gnus-summary-catchup-and-exit
1878   "C" gnus-summary-catchup-all-and-exit
1879   "E" gnus-summary-exit-no-update
1880   "Q" gnus-summary-exit
1881   "Z" gnus-summary-exit
1882   "n" gnus-summary-catchup-and-goto-next-group
1883   "R" gnus-summary-reselect-current-group
1884   "G" gnus-summary-rescan-group
1885   "N" gnus-summary-next-group
1886   "s" gnus-summary-save-newsrc
1887   "P" gnus-summary-prev-group)
1888
1889 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1890   " " gnus-summary-next-page
1891   "n" gnus-summary-next-page
1892   "\177" gnus-summary-prev-page
1893   [delete] gnus-summary-prev-page
1894   "p" gnus-summary-prev-page
1895   "\r" gnus-summary-scroll-up
1896   "\M-\r" gnus-summary-scroll-down
1897   "<" gnus-summary-beginning-of-article
1898   ">" gnus-summary-end-of-article
1899   "b" gnus-summary-beginning-of-article
1900   "e" gnus-summary-end-of-article
1901   "^" gnus-summary-refer-parent-article
1902   "r" gnus-summary-refer-parent-article
1903   "D" gnus-summary-enter-digest-group
1904   "R" gnus-summary-refer-references
1905   "T" gnus-summary-refer-thread
1906   "g" gnus-summary-show-article
1907   "s" gnus-summary-isearch-article
1908   "P" gnus-summary-print-article
1909   "M" gnus-mailing-list-insinuate
1910   "t" gnus-article-babel)
1911
1912 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1913   "b" gnus-article-add-buttons
1914   "B" gnus-article-add-buttons-to-head
1915   "o" gnus-article-treat-overstrike
1916   "e" gnus-article-emphasize
1917   "w" gnus-article-fill-cited-article
1918   "Q" gnus-article-fill-long-lines
1919   "C" gnus-article-capitalize-sentences
1920   "c" gnus-article-remove-cr
1921   "q" gnus-article-de-quoted-unreadable
1922   "6" gnus-article-de-base64-unreadable
1923   "Z" gnus-article-decode-HZ
1924   "h" gnus-article-wash-html
1925   "u" gnus-article-unsplit-urls
1926   "s" gnus-summary-force-verify-and-decrypt
1927   "f" gnus-article-display-x-face
1928   "l" gnus-summary-stop-page-breaking
1929   "r" gnus-summary-caesar-message
1930   "m" gnus-summary-morse-message
1931   "t" gnus-summary-toggle-header
1932   "g" gnus-treat-smiley
1933   "v" gnus-summary-verbose-headers
1934   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1935   "p" gnus-article-verify-x-pgp-sig
1936   "d" gnus-article-treat-dumbquotes)
1937
1938 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1939   ;; mnemonic: deuglif*Y*
1940   "u" gnus-article-outlook-unwrap-lines
1941   "a" gnus-article-outlook-repair-attribution
1942   "c" gnus-article-outlook-rearrange-citation
1943   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1944
1945 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1946   "a" gnus-article-hide
1947   "h" gnus-article-hide-headers
1948   "b" gnus-article-hide-boring-headers
1949   "s" gnus-article-hide-signature
1950   "c" gnus-article-hide-citation
1951   "C" gnus-article-hide-citation-in-followups
1952   "l" gnus-article-hide-list-identifiers
1953   "B" gnus-article-strip-banner
1954   "P" gnus-article-hide-pem
1955   "\C-c" gnus-article-hide-citation-maybe)
1956
1957 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1958   "a" gnus-article-highlight
1959   "h" gnus-article-highlight-headers
1960   "c" gnus-article-highlight-citation
1961   "s" gnus-article-highlight-signature)
1962
1963 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1964   "f" gnus-article-treat-fold-headers
1965   "u" gnus-article-treat-unfold-headers
1966   "n" gnus-article-treat-fold-newsgroups)
1967
1968 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1969   "x" gnus-article-display-x-face
1970   "d" gnus-article-display-face
1971   "s" gnus-treat-smiley
1972   "D" gnus-article-remove-images
1973   "f" gnus-treat-from-picon
1974   "m" gnus-treat-mail-picon
1975   "n" gnus-treat-newsgroups-picon)
1976
1977 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1978   "w" gnus-article-decode-mime-words
1979   "c" gnus-article-decode-charset
1980   "v" gnus-mime-view-all-parts
1981   "b" gnus-article-view-part)
1982
1983 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1984   "z" gnus-article-date-ut
1985   "u" gnus-article-date-ut
1986   "l" gnus-article-date-local
1987   "p" gnus-article-date-english
1988   "e" gnus-article-date-lapsed
1989   "o" gnus-article-date-original
1990   "i" gnus-article-date-iso8601
1991   "s" gnus-article-date-user)
1992
1993 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1994   "t" gnus-article-remove-trailing-blank-lines
1995   "l" gnus-article-strip-leading-blank-lines
1996   "m" gnus-article-strip-multiple-blank-lines
1997   "a" gnus-article-strip-blank-lines
1998   "A" gnus-article-strip-all-blank-lines
1999   "s" gnus-article-strip-leading-space
2000   "e" gnus-article-strip-trailing-space
2001   "w" gnus-article-remove-leading-whitespace)
2002
2003 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2004   "v" gnus-version
2005   "f" gnus-summary-fetch-faq
2006   "d" gnus-summary-describe-group
2007   "h" gnus-summary-describe-briefly
2008   "i" gnus-info-find-node
2009   "c" gnus-group-fetch-charter
2010   "C" gnus-group-fetch-control)
2011
2012 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2013   "e" gnus-summary-expire-articles
2014   "\M-\C-e" gnus-summary-expire-articles-now
2015   "\177" gnus-summary-delete-article
2016   [delete] gnus-summary-delete-article
2017   [backspace] gnus-summary-delete-article
2018   "m" gnus-summary-move-article
2019   "r" gnus-summary-respool-article
2020   "w" gnus-summary-edit-article
2021   "c" gnus-summary-copy-article
2022   "B" gnus-summary-crosspost-article
2023   "q" gnus-summary-respool-query
2024   "t" gnus-summary-respool-trace
2025   "i" gnus-summary-import-article
2026   "I" gnus-summary-create-article
2027   "p" gnus-summary-article-posted-p)
2028
2029 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2030   "o" gnus-summary-save-article
2031   "m" gnus-summary-save-article-mail
2032   "F" gnus-summary-write-article-file
2033   "r" gnus-summary-save-article-rmail
2034   "f" gnus-summary-save-article-file
2035   "b" gnus-summary-save-article-body-file
2036   "B" gnus-summary-write-article-body-file
2037   "h" gnus-summary-save-article-folder
2038   "v" gnus-summary-save-article-vm
2039   "p" gnus-summary-pipe-output
2040   "P" gnus-summary-muttprint
2041   "s" gnus-soup-add-article)
2042
2043 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2044   "b" gnus-summary-display-buttonized
2045   "m" gnus-summary-repair-multipart
2046   "v" gnus-article-view-part
2047   "o" gnus-article-save-part
2048   "c" gnus-article-copy-part
2049   "C" gnus-article-view-part-as-charset
2050   "e" gnus-article-view-part-externally
2051   "E" gnus-article-encrypt-body
2052   "i" gnus-article-inline-part
2053   "|" gnus-article-pipe-part)
2054
2055 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2056   "p" gnus-summary-mark-as-processable
2057   "u" gnus-summary-unmark-as-processable
2058   "U" gnus-summary-unmark-all-processable
2059   "v" gnus-uu-mark-over
2060   "s" gnus-uu-mark-series
2061   "r" gnus-uu-mark-region
2062   "g" gnus-uu-unmark-region
2063   "R" gnus-uu-mark-by-regexp
2064   "G" gnus-uu-unmark-by-regexp
2065   "t" gnus-uu-mark-thread
2066   "T" gnus-uu-unmark-thread
2067   "a" gnus-uu-mark-all
2068   "b" gnus-uu-mark-buffer
2069   "S" gnus-uu-mark-sparse
2070   "k" gnus-summary-kill-process-mark
2071   "y" gnus-summary-yank-process-mark
2072   "w" gnus-summary-save-process-mark
2073   "i" gnus-uu-invert-processable)
2074
2075 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2076   ;;"x" gnus-uu-extract-any
2077   "m" gnus-summary-save-parts
2078   "u" gnus-uu-decode-uu
2079   "U" gnus-uu-decode-uu-and-save
2080   "s" gnus-uu-decode-unshar
2081   "S" gnus-uu-decode-unshar-and-save
2082   "o" gnus-uu-decode-save
2083   "O" gnus-uu-decode-save
2084   "b" gnus-uu-decode-binhex
2085   "B" gnus-uu-decode-binhex
2086   "p" gnus-uu-decode-postscript
2087   "P" gnus-uu-decode-postscript-and-save)
2088
2089 (gnus-define-keys
2090     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2091   "u" gnus-uu-decode-uu-view
2092   "U" gnus-uu-decode-uu-and-save-view
2093   "s" gnus-uu-decode-unshar-view
2094   "S" gnus-uu-decode-unshar-and-save-view
2095   "o" gnus-uu-decode-save-view
2096   "O" gnus-uu-decode-save-view
2097   "b" gnus-uu-decode-binhex-view
2098   "B" gnus-uu-decode-binhex-view
2099   "p" gnus-uu-decode-postscript-view
2100   "P" gnus-uu-decode-postscript-and-save-view)
2101
2102 (defvar gnus-article-post-menu nil)
2103
2104 (defconst gnus-summary-menu-maxlen 20)
2105
2106 (defun gnus-summary-menu-split (menu)
2107   ;; If we have lots of elements, divide them into groups of 20
2108   ;; and make a pane (or submenu) for each one.
2109   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2110       (let ((menu menu) sublists next
2111             (i 1))
2112         (while menu
2113           ;; Pull off the next gnus-summary-menu-maxlen elements
2114           ;; and make them the next element of sublist.
2115           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2116           (if next
2117               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2118                       nil))
2119           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2120                                              (aref (car (last menu)) 0)) menu)
2121                                sublists))
2122           (setq i (1+ i))
2123           (setq menu next))
2124         (nreverse sublists))
2125     ;; Few elements--put them all in one pane.
2126     menu))
2127
2128 (defun gnus-summary-make-menu-bar ()
2129   (gnus-turn-off-edit-menu 'summary)
2130
2131   (unless (boundp 'gnus-summary-misc-menu)
2132
2133     (easy-menu-define
2134       gnus-summary-kill-menu gnus-summary-mode-map ""
2135       (cons
2136        "Score"
2137        (nconc
2138         (list
2139          ["Customize" gnus-score-customize t])
2140         (gnus-make-score-map 'increase)
2141         (gnus-make-score-map 'lower)
2142         '(("Mark"
2143            ["Kill below" gnus-summary-kill-below t]
2144            ["Mark above" gnus-summary-mark-above t]
2145            ["Tick above" gnus-summary-tick-above t]
2146            ["Clear above" gnus-summary-clear-above t])
2147           ["Current score" gnus-summary-current-score t]
2148           ["Set score" gnus-summary-set-score t]
2149           ["Switch current score file..." gnus-score-change-score-file t]
2150           ["Set mark below..." gnus-score-set-mark-below t]
2151           ["Set expunge below..." gnus-score-set-expunge-below t]
2152           ["Edit current score file" gnus-score-edit-current-scores t]
2153           ["Edit score file..." gnus-score-edit-file t]
2154           ["Trace score" gnus-score-find-trace t]
2155           ["Find words" gnus-score-find-favourite-words t]
2156           ["Rescore buffer" gnus-summary-rescore t]
2157           ["Increase score..." gnus-summary-increase-score t]
2158           ["Lower score..." gnus-summary-lower-score t]))))
2159
2160     ;; Define both the Article menu in the summary buffer and the
2161     ;; equivalent Commands menu in the article buffer here for
2162     ;; consistency.
2163     (let ((innards
2164            `(("Hide"
2165               ["All" gnus-article-hide t]
2166               ["Headers" gnus-article-hide-headers t]
2167               ["Signature" gnus-article-hide-signature t]
2168               ["Citation" gnus-article-hide-citation t]
2169               ["List identifiers" gnus-article-hide-list-identifiers t]
2170               ["Banner" gnus-article-strip-banner t]
2171               ["Boring headers" gnus-article-hide-boring-headers t])
2172              ("Highlight"
2173               ["All" gnus-article-highlight t]
2174               ["Headers" gnus-article-highlight-headers t]
2175               ["Signature" gnus-article-highlight-signature t]
2176               ["Citation" gnus-article-highlight-citation t])
2177              ("MIME"
2178               ["Words" gnus-article-decode-mime-words t]
2179               ["Charset" gnus-article-decode-charset t]
2180               ["QP" gnus-article-de-quoted-unreadable t]
2181               ["Base64" gnus-article-de-base64-unreadable t]
2182               ["View MIME buttons" gnus-summary-display-buttonized t]
2183               ["View all" gnus-mime-view-all-parts t]
2184               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2185               ["Encrypt body" gnus-article-encrypt-body
2186                :active (not (gnus-group-read-only-p))
2187                ,@(if (featurep 'xemacs) nil
2188                    '(:help "Encrypt the message body on disk"))]
2189               ["Extract all parts..." gnus-summary-save-parts t]
2190               ("Multipart"
2191                ["Repair multipart" gnus-summary-repair-multipart t]
2192                ["Pipe part..." gnus-article-pipe-part t]
2193                ["Inline part" gnus-article-inline-part t]
2194                ["Encrypt body" gnus-article-encrypt-body
2195                 :active (not (gnus-group-read-only-p))
2196                ,@(if (featurep 'xemacs) nil
2197                    '(:help "Encrypt the message body on disk"))]
2198                ["View part externally" gnus-article-view-part-externally t]
2199                ["View part with charset..." gnus-article-view-part-as-charset t]
2200                ["Copy part" gnus-article-copy-part t]
2201                ["Save part..." gnus-article-save-part t]
2202                ["View part" gnus-article-view-part t]))
2203              ("Date"
2204               ["Local" gnus-article-date-local t]
2205               ["ISO8601" gnus-article-date-iso8601 t]
2206               ["UT" gnus-article-date-ut t]
2207               ["Original" gnus-article-date-original t]
2208               ["Lapsed" gnus-article-date-lapsed t]
2209               ["User-defined" gnus-article-date-user t])
2210              ("Display"
2211               ["Remove images" gnus-article-remove-images t]
2212               ["Toggle smiley" gnus-treat-smiley t]
2213               ["Show X-Face" gnus-article-display-x-face t]
2214               ["Show picons in From" gnus-treat-from-picon t]
2215               ["Show picons in mail headers" gnus-treat-mail-picon t]
2216               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2217               ("View as different encoding"
2218                ,@(gnus-summary-menu-split
2219                   (mapcar
2220                    (lambda (cs)
2221                      ;; Since easymenu under Emacs doesn't allow
2222                      ;; lambda forms for menu commands, we should
2223                      ;; provide intern'ed function symbols.
2224                      (let ((command (intern (format "\
2225 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2226                        (fset command
2227                              `(lambda ()
2228                                 (interactive)
2229                                 (let ((gnus-summary-show-article-charset-alist
2230                                        '((1 . ,cs))))
2231                                   (gnus-summary-show-article 1))))
2232                        `[,(symbol-name cs) ,command t]))
2233                    (sort (if (fboundp 'coding-system-list)
2234                              (coding-system-list)
2235                            (mapcar 'car mm-mime-mule-charset-alist))
2236                          'string<)))))
2237              ("Washing"
2238               ("Remove Blanks"
2239                ["Leading" gnus-article-strip-leading-blank-lines t]
2240                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2241                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2242                ["All of the above" gnus-article-strip-blank-lines t]
2243                ["All" gnus-article-strip-all-blank-lines t]
2244                ["Leading space" gnus-article-strip-leading-space t]
2245                ["Trailing space" gnus-article-strip-trailing-space t]
2246                ["Leading space in headers"
2247                 gnus-article-remove-leading-whitespace t])
2248               ["Overstrike" gnus-article-treat-overstrike t]
2249               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2250               ["Emphasis" gnus-article-emphasize t]
2251               ["Word wrap" gnus-article-fill-cited-article t]
2252               ["Fill long lines" gnus-article-fill-long-lines t]
2253               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2254               ["Remove CR" gnus-article-remove-cr t]
2255               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2256               ["Base64" gnus-article-de-base64-unreadable t]
2257               ["Rot 13" gnus-summary-caesar-message
2258                ,@(if (featurep 'xemacs) '(t)
2259                    '(:help "\"Caesar rotate\" article by 13"))]
2260               ["Morse decode" gnus-summary-morse-message t]
2261               ["Unix pipe..." gnus-summary-pipe-message t]
2262               ["Add buttons" gnus-article-add-buttons t]
2263               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2264               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2265               ["Verbose header" gnus-summary-verbose-headers t]
2266               ["Toggle header" gnus-summary-toggle-header t]
2267               ["Unfold headers" gnus-article-treat-unfold-headers t]
2268               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2269               ["Html" gnus-article-wash-html t]
2270               ["Unsplit URLs" gnus-article-unsplit-urls t]
2271               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2272               ["Decode HZ" gnus-article-decode-HZ t]
2273               ("(Outlook) Deuglify"
2274                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2275                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2276                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2277                ["Full (Outlook) deuglify"
2278                 gnus-article-outlook-deuglify-article t])
2279               )
2280              ("Output"
2281               ["Save in default format..." gnus-summary-save-article
2282                ,@(if (featurep 'xemacs) '(t)
2283                    '(:help "Save article using default method"))]
2284               ["Save in file..." gnus-summary-save-article-file
2285                ,@(if (featurep 'xemacs) '(t)
2286                    '(:help "Save article in file"))]
2287               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2288               ["Save in MH folder..." gnus-summary-save-article-folder t]
2289               ["Save in VM folder..." gnus-summary-save-article-vm t]
2290               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2291               ["Save body in file..." gnus-summary-save-article-body-file t]
2292               ["Pipe through a filter..." gnus-summary-pipe-output t]
2293               ["Add to SOUP packet" gnus-soup-add-article t]
2294               ["Print with Muttprint..." gnus-summary-muttprint t]
2295               ["Print" gnus-summary-print-article
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Generate and print a PostScript image"))])
2298              ("Copy, move,... (Backend)"
2299               ,@(if (featurep 'xemacs) nil
2300                   '(:help "Copying, moving, expiring articles..."))
2301               ["Respool article..." gnus-summary-respool-article t]
2302               ["Move article..." gnus-summary-move-article
2303                (gnus-check-backend-function
2304                 'request-move-article gnus-newsgroup-name)]
2305               ["Copy article..." gnus-summary-copy-article t]
2306               ["Crosspost article..." gnus-summary-crosspost-article
2307                (gnus-check-backend-function
2308                 'request-replace-article gnus-newsgroup-name)]
2309               ["Import file..." gnus-summary-import-article
2310                (gnus-check-backend-function
2311                 'request-accept-article gnus-newsgroup-name)]
2312               ["Create article..." gnus-summary-create-article
2313                (gnus-check-backend-function
2314                 'request-accept-article gnus-newsgroup-name)]
2315               ["Check if posted" gnus-summary-article-posted-p t]
2316               ["Edit article" gnus-summary-edit-article
2317                (not (gnus-group-read-only-p))]
2318               ["Delete article" gnus-summary-delete-article
2319                (gnus-check-backend-function
2320                 'request-expire-articles gnus-newsgroup-name)]
2321               ["Query respool" gnus-summary-respool-query t]
2322               ["Trace respool" gnus-summary-respool-trace t]
2323               ["Delete expirable articles" gnus-summary-expire-articles-now
2324                (gnus-check-backend-function
2325                 'request-expire-articles gnus-newsgroup-name)])
2326              ("Extract"
2327               ["Uudecode" gnus-uu-decode-uu
2328                ,@(if (featurep 'xemacs) '(t)
2329                    '(:help "Decode uuencoded article(s)"))]
2330               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2331               ["Unshar" gnus-uu-decode-unshar t]
2332               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2333               ["Save" gnus-uu-decode-save t]
2334               ["Binhex" gnus-uu-decode-binhex t]
2335               ["Postscript" gnus-uu-decode-postscript t]
2336               ["All MIME parts" gnus-summary-save-parts t])
2337              ("Cache"
2338               ["Enter article" gnus-cache-enter-article t]
2339               ["Remove article" gnus-cache-remove-article t])
2340              ["Translate" gnus-article-babel t]
2341              ["Select article buffer" gnus-summary-select-article-buffer t]
2342              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2343              ["Isearch article..." gnus-summary-isearch-article t]
2344              ["Beginning of the article" gnus-summary-beginning-of-article t]
2345              ["End of the article" gnus-summary-end-of-article t]
2346              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2347              ["Fetch referenced articles" gnus-summary-refer-references t]
2348              ["Fetch current thread" gnus-summary-refer-thread t]
2349              ["Fetch article with id..." gnus-summary-refer-article t]
2350              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2351              ["Redisplay" gnus-summary-show-article t]
2352              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2353       (easy-menu-define
2354         gnus-summary-article-menu gnus-summary-mode-map ""
2355         (cons "Article" innards))
2356
2357       (if (not (keymapp gnus-summary-article-menu))
2358           (easy-menu-define
2359             gnus-article-commands-menu gnus-article-mode-map ""
2360             (cons "Commands" innards))
2361         ;; in Emacs, don't share menu.
2362         (setq gnus-article-commands-menu
2363               (copy-keymap gnus-summary-article-menu))
2364         (define-key gnus-article-mode-map [menu-bar commands]
2365           (cons "Commands" gnus-article-commands-menu))))
2366
2367     (easy-menu-define
2368       gnus-summary-thread-menu gnus-summary-mode-map ""
2369       '("Threads"
2370         ["Find all messages in thread" gnus-summary-refer-thread t]
2371         ["Toggle threading" gnus-summary-toggle-threads t]
2372         ["Hide threads" gnus-summary-hide-all-threads t]
2373         ["Show threads" gnus-summary-show-all-threads t]
2374         ["Hide thread" gnus-summary-hide-thread t]
2375         ["Show thread" gnus-summary-show-thread t]
2376         ["Go to next thread" gnus-summary-next-thread t]
2377         ["Go to previous thread" gnus-summary-prev-thread t]
2378         ["Go down thread" gnus-summary-down-thread t]
2379         ["Go up thread" gnus-summary-up-thread t]
2380         ["Top of thread" gnus-summary-top-thread t]
2381         ["Mark thread as read" gnus-summary-kill-thread t]
2382         ["Lower thread score" gnus-summary-lower-thread t]
2383         ["Raise thread score" gnus-summary-raise-thread t]
2384         ["Rethread current" gnus-summary-rethread-current t]))
2385
2386     (easy-menu-define
2387       gnus-summary-post-menu gnus-summary-mode-map ""
2388       `("Post"
2389         ["Send a message (mail or news)" gnus-summary-post-news
2390          ,@(if (featurep 'xemacs) '(t)
2391              '(:help "Compose a new message (mail or news)"))]
2392         ["Followup" gnus-summary-followup
2393          ,@(if (featurep 'xemacs) '(t)
2394              '(:help "Post followup to this article"))]
2395         ["Followup and yank" gnus-summary-followup-with-original
2396          ,@(if (featurep 'xemacs) '(t)
2397              '(:help "Post followup to this article, quoting its contents"))]
2398         ["Supersede article" gnus-summary-supersede-article t]
2399         ["Cancel article" gnus-summary-cancel-article
2400          ,@(if (featurep 'xemacs) '(t)
2401              '(:help "Cancel an article you posted"))]
2402         ["Reply" gnus-summary-reply t]
2403         ["Reply and yank" gnus-summary-reply-with-original t]
2404         ["Wide reply" gnus-summary-wide-reply t]
2405         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2406          ,@(if (featurep 'xemacs) '(t)
2407              '(:help "Mail a reply, quoting this article"))]
2408         ["Very wide reply" gnus-summary-very-wide-reply t]
2409         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2410          ,@(if (featurep 'xemacs) '(t)
2411              '(:help "Mail a very wide reply, quoting this article"))]
2412         ["Mail forward" gnus-summary-mail-forward t]
2413         ["Post forward" gnus-summary-post-forward t]
2414         ["Digest and mail" gnus-uu-digest-mail-forward t]
2415         ["Digest and post" gnus-uu-digest-post-forward t]
2416         ["Resend message" gnus-summary-resend-message t]
2417         ["Resend message edit" gnus-summary-resend-message-edit t]
2418         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2419         ["Send a mail" gnus-summary-mail-other-window t]
2420         ["Create a local message" gnus-summary-news-other-window t]
2421         ["Uuencode and post" gnus-uu-post-news
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Post a uuencoded article"))]
2424         ["Followup via news" gnus-summary-followup-to-mail t]
2425         ["Followup via news and yank"
2426          gnus-summary-followup-to-mail-with-original t]
2427         ;;("Draft"
2428         ;;["Send" gnus-summary-send-draft t]
2429         ;;["Send bounced" gnus-resend-bounced-mail t])
2430         ))
2431
2432     (cond
2433      ((not (keymapp gnus-summary-post-menu))
2434       (setq gnus-article-post-menu gnus-summary-post-menu))
2435      ((not gnus-article-post-menu)
2436       ;; Don't share post menu.
2437       (setq gnus-article-post-menu
2438             (copy-keymap gnus-summary-post-menu))))
2439     (define-key gnus-article-mode-map [menu-bar post]
2440       (cons "Post" gnus-article-post-menu))
2441
2442     (easy-menu-define
2443       gnus-summary-misc-menu gnus-summary-mode-map ""
2444       `("Gnus"
2445         ("Mark Read"
2446          ["Mark as read" gnus-summary-mark-as-read-forward t]
2447          ["Mark same subject and select"
2448           gnus-summary-kill-same-subject-and-select t]
2449          ["Mark same subject" gnus-summary-kill-same-subject t]
2450          ["Catchup" gnus-summary-catchup
2451           ,@(if (featurep 'xemacs) '(t)
2452               '(:help "Mark unread articles in this group as read"))]
2453          ["Catchup all" gnus-summary-catchup-all t]
2454          ["Catchup to here" gnus-summary-catchup-to-here t]
2455          ["Catchup from here" gnus-summary-catchup-from-here t]
2456          ["Catchup region" gnus-summary-mark-region-as-read
2457           (gnus-mark-active-p)]
2458          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2459         ("Mark Various"
2460          ["Tick" gnus-summary-tick-article-forward t]
2461          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2462          ["Remove marks" gnus-summary-clear-mark-forward t]
2463          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2464          ["Set bookmark" gnus-summary-set-bookmark t]
2465          ["Remove bookmark" gnus-summary-remove-bookmark t])
2466         ("Limit to"
2467          ["Marks..." gnus-summary-limit-to-marks t]
2468          ["Subject..." gnus-summary-limit-to-subject t]
2469          ["Author..." gnus-summary-limit-to-author t]
2470          ["Age..." gnus-summary-limit-to-age t]
2471          ["Extra..." gnus-summary-limit-to-extra t]
2472          ["Score..." gnus-summary-limit-to-score t]
2473          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2474          ["Unread" gnus-summary-limit-to-unread t]
2475          ["Unseen" gnus-summary-limit-to-unseen t]
2476          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2477          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2478          ["Pop limit" gnus-summary-pop-limit t]
2479          ["Show dormant" gnus-summary-limit-include-dormant t]
2480          ["Hide childless dormant"
2481           gnus-summary-limit-exclude-childless-dormant t]
2482          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2483          ["Hide marked" gnus-summary-limit-exclude-marks t]
2484          ["Show expunged" gnus-summary-limit-include-expunged t])
2485         ("Process Mark"
2486          ["Set mark" gnus-summary-mark-as-processable t]
2487          ["Remove mark" gnus-summary-unmark-as-processable t]
2488          ["Remove all marks" gnus-summary-unmark-all-processable t]
2489          ["Mark above" gnus-uu-mark-over t]
2490          ["Mark series" gnus-uu-mark-series t]
2491          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2492          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2493          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2494          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2495          ["Mark all" gnus-uu-mark-all t]
2496          ["Mark buffer" gnus-uu-mark-buffer t]
2497          ["Mark sparse" gnus-uu-mark-sparse t]
2498          ["Mark thread" gnus-uu-mark-thread t]
2499          ["Unmark thread" gnus-uu-unmark-thread t]
2500          ("Process Mark Sets"
2501           ["Kill" gnus-summary-kill-process-mark t]
2502           ["Yank" gnus-summary-yank-process-mark
2503            gnus-newsgroup-process-stack]
2504           ["Save" gnus-summary-save-process-mark t]
2505           ["Run command on marked..." gnus-summary-universal-argument t]))
2506         ("Scroll article"
2507          ["Page forward" gnus-summary-next-page
2508           ,@(if (featurep 'xemacs) '(t)
2509               '(:help "Show next page of article"))]
2510          ["Page backward" gnus-summary-prev-page
2511           ,@(if (featurep 'xemacs) '(t)
2512               '(:help "Show previous page of article"))]
2513          ["Line forward" gnus-summary-scroll-up t])
2514         ("Move"
2515          ["Next unread article" gnus-summary-next-unread-article t]
2516          ["Previous unread article" gnus-summary-prev-unread-article t]
2517          ["Next article" gnus-summary-next-article t]
2518          ["Previous article" gnus-summary-prev-article t]
2519          ["Next unread subject" gnus-summary-next-unread-subject t]
2520          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2521          ["Next article same subject" gnus-summary-next-same-subject t]
2522          ["Previous article same subject" gnus-summary-prev-same-subject t]
2523          ["First unread article" gnus-summary-first-unread-article t]
2524          ["Best unread article" gnus-summary-best-unread-article t]
2525          ["Go to subject number..." gnus-summary-goto-subject t]
2526          ["Go to article number..." gnus-summary-goto-article t]
2527          ["Go to the last article" gnus-summary-goto-last-article t]
2528          ["Pop article off history" gnus-summary-pop-article t])
2529         ("Sort"
2530          ["Sort by number" gnus-summary-sort-by-number t]
2531          ["Sort by author" gnus-summary-sort-by-author t]
2532          ["Sort by subject" gnus-summary-sort-by-subject t]
2533          ["Sort by date" gnus-summary-sort-by-date t]
2534          ["Sort by score" gnus-summary-sort-by-score t]
2535          ["Sort by lines" gnus-summary-sort-by-lines t]
2536          ["Sort by characters" gnus-summary-sort-by-chars t]
2537          ["Randomize" gnus-summary-sort-by-random t]
2538          ["Original sort" gnus-summary-sort-by-original t])
2539         ("Help"
2540          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2541          ["Describe group" gnus-summary-describe-group t]
2542          ["Fetch charter" gnus-group-fetch-charter
2543           ,@(if (featurep 'xemacs) nil
2544               '(:help "Display the charter of the current group"))]
2545          ["Fetch control message" gnus-group-fetch-control
2546           ,@(if (featurep 'xemacs) nil
2547               '(:help "Display the archived control message for the current group"))]
2548          ["Read manual" gnus-info-find-node t])
2549         ("Modes"
2550          ["Pick and read" gnus-pick-mode t]
2551          ["Binary" gnus-binary-mode t])
2552         ("Regeneration"
2553          ["Regenerate" gnus-summary-prepare t]
2554          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2555          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2556          ["Toggle threading" gnus-summary-toggle-threads t])
2557         ["See old articles" gnus-summary-insert-old-articles t]
2558         ["See new articles" gnus-summary-insert-new-articles t]
2559         ["Filter articles..." gnus-summary-execute-command t]
2560         ["Run command on articles..." gnus-summary-universal-argument t]
2561         ["Search articles forward..." gnus-summary-search-article-forward t]
2562         ["Search articles backward..." gnus-summary-search-article-backward t]
2563         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2564         ["Expand window" gnus-summary-expand-window t]
2565         ["Expire expirable articles" gnus-summary-expire-articles
2566          (gnus-check-backend-function
2567           'request-expire-articles gnus-newsgroup-name)]
2568         ["Edit local kill file" gnus-summary-edit-local-kill t]
2569         ["Edit main kill file" gnus-summary-edit-global-kill t]
2570         ["Edit group parameters" gnus-summary-edit-parameters t]
2571         ["Customize group parameters" gnus-summary-customize-parameters t]
2572         ["Send a bug report" gnus-bug t]
2573         ("Exit"
2574          ["Catchup and exit" gnus-summary-catchup-and-exit
2575           ,@(if (featurep 'xemacs) '(t)
2576               '(:help "Mark unread articles in this group as read, then exit"))]
2577          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2578          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2579          ["Exit group" gnus-summary-exit
2580           ,@(if (featurep 'xemacs) '(t)
2581               '(:help "Exit current group, return to group selection mode"))]
2582          ["Exit group without updating" gnus-summary-exit-no-update t]
2583          ["Exit and goto next group" gnus-summary-next-group t]
2584          ["Exit and goto prev group" gnus-summary-prev-group t]
2585          ["Reselect group" gnus-summary-reselect-current-group t]
2586          ["Rescan group" gnus-summary-rescan-group t]
2587          ["Update dribble" gnus-summary-save-newsrc t])))
2588
2589     (gnus-run-hooks 'gnus-summary-menu-hook)))
2590
2591 (defvar gnus-summary-tool-bar-map nil)
2592
2593 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2594 ;; affect _new_ message buffers.  We might add a function that walks thru all
2595 ;; summary-mode buffers and force the update.
2596 (defun gnus-summary-tool-bar-update (&optional symbol value)
2597   "Update summary mode toolbar.
2598 Setter function for custom variables."
2599   (setq-default gnus-summary-tool-bar-map nil)
2600   (when symbol
2601     ;; When used as ":set" function:
2602     (set-default symbol value))
2603   (when (gnus-buffer-live-p gnus-summary-buffer)
2604     (with-current-buffer gnus-summary-buffer
2605       (gnus-summary-make-tool-bar))))
2606
2607 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2608                                      'gnus-summary-tool-bar-gnome
2609                                    'gnus-summary-tool-bar-retro)
2610   "Specifies the Gnus summary tool bar.
2611
2612 It can be either a list or a symbol refering to a list.  See
2613 `gmm-tool-bar-from-list' for the format of the list.  The
2614 default key map is `gnus-summary-mode-map'.
2615
2616 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2617 `gnus-summary-tool-bar-retro'."
2618   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2619                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2620                  (repeat :tag "User defined list" gmm-tool-bar-item)
2621                  (symbol))
2622   :version "22.1" ;; Gnus 5.10.9
2623   :initialize 'custom-initialize-default
2624   :set 'gnus-summary-tool-bar-update
2625   :group 'gnus-summary)
2626
2627 (defcustom gnus-summary-tool-bar-gnome
2628   '((gnus-summary-post-news "mail/compose" nil)
2629     (gnus-summary-insert-new-articles "mail/inbox" nil
2630                                       :visible (or (not gnus-agent)
2631                                                    gnus-plugged))
2632     (gnus-summary-reply-with-original "mail/reply")
2633     (gnus-summary-reply "mail/reply" nil :visible nil)
2634     (gnus-summary-followup-with-original "mail/reply-all")
2635     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2636     (gnus-summary-mail-forward "mail/forward")
2637     (gnus-summary-save-article "mail/save")
2638     (gnus-summary-search-article-forward "search" nil :visible nil)
2639     (gnus-summary-print-article "print")
2640     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2641     ;; Some new commands that may need more suitable icons:
2642     (gnus-summary-save-newsrc "save" nil :visible nil)
2643     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2644     (gnus-summary-prev-article "left-arrow")
2645     (gnus-summary-next-article "right-arrow")
2646     (gnus-summary-next-page "next-page")
2647     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2648     ;;
2649     ;; Maybe some sort-by-... could be added:
2650     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2651     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2652     (gnus-summary-mark-as-expirable
2653      "delete" nil
2654      :visible (gnus-check-backend-function 'request-expire-articles
2655                                            gnus-newsgroup-name))
2656     (gnus-summary-mark-as-spam
2657      "mail/spam" t
2658      :visible (and (fboundp 'spam-group-ham-contents-p)
2659                    (spam-group-ham-contents-p gnus-newsgroup-name))
2660      :help "Mark as spam")
2661     (gnus-summary-mark-as-read-forward
2662      "mail/not-spam" nil
2663      :visible (and (fboundp 'spam-group-spam-contents-p)
2664                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2665     ;;
2666     (gnus-summary-exit "exit")
2667     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2668     (gnus-info-find-node "help"))
2669   "List of functions for the summary tool bar (GNOME style).
2670
2671 See `gmm-tool-bar-from-list' for the format of the list."
2672   :type '(repeat gmm-tool-bar-item)
2673   :version "22.1" ;; Gnus 5.10.9
2674   :initialize 'custom-initialize-default
2675   :set 'gnus-summary-tool-bar-update
2676   :group 'gnus-summary)
2677
2678 (defcustom gnus-summary-tool-bar-retro
2679   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2680     (gnus-summary-next-unread-article "gnus/next-ur")
2681     (gnus-summary-post-news "gnus/post")
2682     (gnus-summary-followup-with-original "gnus/fuwo")
2683     (gnus-summary-followup "gnus/followup")
2684     (gnus-summary-reply-with-original "gnus/reply-wo")
2685     (gnus-summary-reply "gnus/reply")
2686     (gnus-summary-caesar-message "gnus/rot13")
2687     (gnus-uu-decode-uu "gnus/uu-decode")
2688     (gnus-summary-save-article-file "gnus/save-aif")
2689     (gnus-summary-save-article "gnus/save-art")
2690     (gnus-uu-post-news "gnus/uu-post")
2691     (gnus-summary-catchup "gnus/catchup")
2692     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2693     (gnus-summary-exit "gnus/exit-summ")
2694     ;; Some new command that may need more suitable icons:
2695     (gnus-summary-print-article "gnus/print" nil :visible nil)
2696     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2697     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2698     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2699     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2700     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2701     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2702     ;;
2703     (gnus-info-find-node "gnus/help" nil :visible nil))
2704   "List of functions for the summary tool bar (retro look).
2705
2706 See `gmm-tool-bar-from-list' for the format of the list."
2707   :type '(repeat gmm-tool-bar-item)
2708   :version "22.1" ;; Gnus 5.10.9
2709   :initialize 'custom-initialize-default
2710   :set 'gnus-summary-tool-bar-update
2711   :group 'gnus-summary)
2712
2713 (defcustom gnus-summary-tool-bar-zap-list t
2714   "List of icon items from the global tool bar.
2715 These items are not displayed in the Gnus summary mode tool bar.
2716
2717 See `gmm-tool-bar-from-list' for the format of the list."
2718   :type 'gmm-tool-bar-zap-list
2719   :version "22.1" ;; Gnus 5.10.9
2720   :initialize 'custom-initialize-default
2721   :set 'gnus-summary-tool-bar-update
2722   :group 'gnus-summary)
2723
2724 (defvar image-load-path)
2725
2726 (defun gnus-summary-make-tool-bar (&optional force)
2727   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2728 When FORCE, rebuild the tool bar."
2729   (when (and (not (featurep 'xemacs))
2730              (boundp 'tool-bar-mode)
2731              tool-bar-mode
2732              (or (not gnus-summary-tool-bar-map) force))
2733     (let* ((load-path
2734             (gmm-image-load-path-for-library "gnus"
2735                                              "mail/save.xpm"
2736                                              nil t))
2737            (image-load-path (cons (car load-path)
2738                                   (when (boundp 'image-load-path)
2739                                     image-load-path)))
2740            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2741                                         gnus-summary-tool-bar-zap-list
2742                                         'gnus-summary-mode-map)))
2743       (when map
2744         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2745         ;; uses it's value.
2746         (setq gnus-summary-tool-bar-map map))))
2747   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2748
2749 (defun gnus-score-set-default (var value)
2750   "A version of set that updates the GNU Emacs menu-bar."
2751   (set var value)
2752   ;; It is the message that forces the active status to be updated.
2753   (message ""))
2754
2755 (defun gnus-make-score-map (type)
2756   "Make a summary score map of type TYPE."
2757   (if t
2758       nil
2759     (let ((headers '(("author" "from" string)
2760                      ("subject" "subject" string)
2761                      ("article body" "body" string)
2762                      ("article head" "head" string)
2763                      ("xref" "xref" string)
2764                      ("extra header" "extra" string)
2765                      ("lines" "lines" number)
2766                      ("followups to author" "followup" string)))
2767           (types '((number ("less than" <)
2768                            ("greater than" >)
2769                            ("equal" =))
2770                    (string ("substring" s)
2771                            ("exact string" e)
2772                            ("fuzzy string" f)
2773                            ("regexp" r))))
2774           (perms '(("temporary" (current-time-string))
2775                    ("permanent" nil)
2776                    ("immediate" now)))
2777           header)
2778       (list
2779        (apply
2780         'nconc
2781         (list
2782          (if (eq type 'lower)
2783              "Lower score"
2784            "Increase score"))
2785         (let (outh)
2786           (while headers
2787             (setq header (car headers))
2788             (setq outh
2789                   (cons
2790                    (apply
2791                     'nconc
2792                     (list (car header))
2793                     (let ((ts (cdr (assoc (nth 2 header) types)))
2794                           outt)
2795                       (while ts
2796                         (setq outt
2797                               (cons
2798                                (apply
2799                                 'nconc
2800                                 (list (caar ts))
2801                                 (let ((ps perms)
2802                                       outp)
2803                                   (while ps
2804                                     (setq outp
2805                                           (cons
2806                                            (vector
2807                                             (caar ps)
2808                                             (list
2809                                              'gnus-summary-score-entry
2810                                              (nth 1 header)
2811                                              (if (or (string= (nth 1 header)
2812                                                               "head")
2813                                                      (string= (nth 1 header)
2814                                                               "body"))
2815                                                  ""
2816                                                (list 'gnus-summary-header
2817                                                      (nth 1 header)))
2818                                              (list 'quote (nth 1 (car ts)))
2819                                              (list 'gnus-score-delta-default
2820                                                    nil)
2821                                              (nth 1 (car ps))
2822                                              t)
2823                                             t)
2824                                            outp))
2825                                     (setq ps (cdr ps)))
2826                                   (list (nreverse outp))))
2827                                outt))
2828                         (setq ts (cdr ts)))
2829                       (list (nreverse outt))))
2830                    outh))
2831             (setq headers (cdr headers)))
2832           (list (nreverse outh))))))))
2833
2834 \f
2835
2836 (defun gnus-summary-mode (&optional group)
2837   "Major mode for reading articles.
2838
2839 All normal editing commands are switched off.
2840 \\<gnus-summary-mode-map>
2841 Each line in this buffer represents one article.  To read an
2842 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2843 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2844 respectively.
2845
2846 You can also post articles and send mail from this buffer.  To
2847 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2848 of an article, type `\\[gnus-summary-reply]'.
2849
2850 There are approx. one gazillion commands you can execute in this
2851 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2852
2853 The following commands are available:
2854
2855 \\{gnus-summary-mode-map}"
2856   (interactive)
2857   (kill-all-local-variables)
2858   (when (gnus-visual-p 'summary-menu 'menu)
2859     (gnus-summary-make-menu-bar)
2860     (gnus-summary-make-tool-bar))
2861   (gnus-summary-make-local-variables)
2862   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2863     (gnus-summary-make-local-variables))
2864   (gnus-make-thread-indent-array)
2865   (gnus-simplify-mode-line)
2866   (setq major-mode 'gnus-summary-mode)
2867   (setq mode-name "Summary")
2868   (make-local-variable 'minor-mode-alist)
2869   (use-local-map gnus-summary-mode-map)
2870   (buffer-disable-undo)
2871   (setq buffer-read-only t)             ;Disable modification
2872   (setq truncate-lines t)
2873   (setq selective-display t)
2874   (setq selective-display-ellipses t)   ;Display `...'
2875   (gnus-summary-set-display-table)
2876   (gnus-set-default-directory)
2877   (setq gnus-newsgroup-name group)
2878   (make-local-variable 'gnus-summary-line-format)
2879   (make-local-variable 'gnus-summary-line-format-spec)
2880   (make-local-variable 'gnus-summary-dummy-line-format)
2881   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2882   (make-local-variable 'gnus-summary-mark-positions)
2883   (gnus-make-local-hook 'pre-command-hook)
2884   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2885   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2886   (turn-on-gnus-mailing-list-mode)
2887   (mm-enable-multibyte)
2888   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2889   (gnus-update-summary-mark-positions))
2890
2891 (defun gnus-summary-make-local-variables ()
2892   "Make all the local summary buffer variables."
2893   (let (global)
2894     (dolist (local gnus-summary-local-variables)
2895       (if (consp local)
2896           (progn
2897             (if (eq (cdr local) 'global)
2898                 ;; Copy the global value of the variable.
2899                 (setq global (symbol-value (car local)))
2900               ;; Use the value from the list.
2901               (setq global (eval (cdr local))))
2902             (set (make-local-variable (car local)) global))
2903         ;; Simple nil-valued local variable.
2904         (set (make-local-variable local) nil)))))
2905
2906 (defun gnus-summary-clear-local-variables ()
2907   (let ((locals gnus-summary-local-variables))
2908     (while locals
2909       (if (consp (car locals))
2910           (and (vectorp (caar locals))
2911                (set (caar locals) nil))
2912         (and (vectorp (car locals))
2913              (set (car locals) nil)))
2914       (setq locals (cdr locals)))))
2915
2916 ;; Summary data functions.
2917
2918 (defmacro gnus-data-number (data)
2919   `(car ,data))
2920
2921 (defmacro gnus-data-set-number (data number)
2922   `(setcar ,data ,number))
2923
2924 (defmacro gnus-data-mark (data)
2925   `(nth 1 ,data))
2926
2927 (defmacro gnus-data-set-mark (data mark)
2928   `(setcar (nthcdr 1 ,data) ,mark))
2929
2930 (defmacro gnus-data-pos (data)
2931   `(nth 2 ,data))
2932
2933 (defmacro gnus-data-set-pos (data pos)
2934   `(setcar (nthcdr 2 ,data) ,pos))
2935
2936 (defmacro gnus-data-header (data)
2937   `(nth 3 ,data))
2938
2939 (defmacro gnus-data-set-header (data header)
2940   `(setf (nth 3 ,data) ,header))
2941
2942 (defmacro gnus-data-level (data)
2943   `(nth 4 ,data))
2944
2945 (defmacro gnus-data-unread-p (data)
2946   `(= (nth 1 ,data) gnus-unread-mark))
2947
2948 (defmacro gnus-data-read-p (data)
2949   `(/= (nth 1 ,data) gnus-unread-mark))
2950
2951 (defmacro gnus-data-pseudo-p (data)
2952   `(consp (nth 3 ,data)))
2953
2954 (defmacro gnus-data-find (number)
2955   `(assq ,number gnus-newsgroup-data))
2956
2957 (defmacro gnus-data-find-list (number &optional data)
2958   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2959      (memq (assq ,number bdata)
2960            bdata)))
2961
2962 (defmacro gnus-data-make (number mark pos header level)
2963   `(list ,number ,mark ,pos ,header ,level))
2964
2965 (defun gnus-data-enter (after-article number mark pos header level offset)
2966   (let ((data (gnus-data-find-list after-article)))
2967     (unless data
2968       (error "No such article: %d" after-article))
2969     (setcdr data (cons (gnus-data-make number mark pos header level)
2970                        (cdr data)))
2971     (setq gnus-newsgroup-data-reverse nil)
2972     (gnus-data-update-list (cddr data) offset)))
2973
2974 (defun gnus-data-enter-list (after-article list &optional offset)
2975   (when list
2976     (let ((data (and after-article (gnus-data-find-list after-article)))
2977           (ilist list))
2978       (if (not (or data
2979                    after-article))
2980           (let ((odata gnus-newsgroup-data))
2981             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2982             (when offset
2983               (gnus-data-update-list odata offset)))
2984       ;; Find the last element in the list to be spliced into the main
2985         ;; list.
2986         (while (cdr list)
2987           (setq list (cdr list)))
2988         (if (not data)
2989             (progn
2990               (setcdr list gnus-newsgroup-data)
2991               (setq gnus-newsgroup-data ilist)
2992               (when offset
2993                 (gnus-data-update-list (cdr list) offset)))
2994           (setcdr list (cdr data))
2995           (setcdr data ilist)
2996           (when offset
2997             (gnus-data-update-list (cdr list) offset))))
2998       (setq gnus-newsgroup-data-reverse nil))))
2999
3000 (defun gnus-data-remove (article &optional offset)
3001   (let ((data gnus-newsgroup-data))
3002     (if (= (gnus-data-number (car data)) article)
3003         (progn
3004           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3005                 gnus-newsgroup-data-reverse nil)
3006           (when offset
3007             (gnus-data-update-list gnus-newsgroup-data offset)))
3008       (while (cdr data)
3009         (when (= (gnus-data-number (cadr data)) article)
3010           (setcdr data (cddr data))
3011           (when offset
3012             (gnus-data-update-list (cdr data) offset))
3013           (setq data nil
3014                 gnus-newsgroup-data-reverse nil))
3015         (setq data (cdr data))))))
3016
3017 (defmacro gnus-data-list (backward)
3018   `(if ,backward
3019        (or gnus-newsgroup-data-reverse
3020            (setq gnus-newsgroup-data-reverse
3021                  (reverse gnus-newsgroup-data)))
3022      gnus-newsgroup-data))
3023
3024 (defun gnus-data-update-list (data offset)
3025   "Add OFFSET to the POS of all data entries in DATA."
3026   (setq gnus-newsgroup-data-reverse nil)
3027   (while data
3028     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3029     (setq data (cdr data))))
3030
3031 (defun gnus-summary-article-pseudo-p (article)
3032   "Say whether this article is a pseudo article or not."
3033   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3034
3035 (defmacro gnus-summary-article-sparse-p (article)
3036   "Say whether this article is a sparse article or not."
3037   `(memq ,article gnus-newsgroup-sparse))
3038
3039 (defmacro gnus-summary-article-ancient-p (article)
3040   "Say whether this article is a sparse article or not."
3041   `(memq ,article gnus-newsgroup-ancient))
3042
3043 (defun gnus-article-parent-p (number)
3044   "Say whether this article is a parent or not."
3045   (let ((data (gnus-data-find-list number)))
3046     (and (cdr data)              ; There has to be an article after...
3047          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3048             (gnus-data-level (nth 1 data))))))
3049
3050 (defun gnus-article-children (number)
3051   "Return a list of all children to NUMBER."
3052   (let* ((data (gnus-data-find-list number))
3053          (level (gnus-data-level (car data)))
3054          children)
3055     (setq data (cdr data))
3056     (while (and data
3057                 (= (gnus-data-level (car data)) (1+ level)))
3058       (push (gnus-data-number (car data)) children)
3059       (setq data (cdr data)))
3060     children))
3061
3062 (defmacro gnus-summary-skip-intangible ()
3063   "If the current article is intangible, then jump to a different article."
3064   '(let ((to (get-text-property (point) 'gnus-intangible)))
3065      (and to (gnus-summary-goto-subject to))))
3066
3067 (defmacro gnus-summary-article-intangible-p ()
3068   "Say whether this article is intangible or not."
3069   '(get-text-property (point) 'gnus-intangible))
3070
3071 (defun gnus-article-read-p (article)
3072   "Say whether ARTICLE is read or not."
3073   (not (or (memq article gnus-newsgroup-marked)
3074            (memq article gnus-newsgroup-spam-marked)
3075            (memq article gnus-newsgroup-unreads)
3076            (memq article gnus-newsgroup-unselected)
3077            (memq article gnus-newsgroup-dormant))))
3078
3079 ;; Some summary mode macros.
3080
3081 (defmacro gnus-summary-article-number ()
3082   "The article number of the article on the current line.
3083 If there isn't an article number here, then we return the current
3084 article number."
3085   '(progn
3086      (gnus-summary-skip-intangible)
3087      (or (get-text-property (point) 'gnus-number)
3088          (gnus-summary-last-subject))))
3089
3090 (defmacro gnus-summary-article-header (&optional number)
3091   "Return the header of article NUMBER."
3092   `(gnus-data-header (gnus-data-find
3093                       ,(or number '(gnus-summary-article-number)))))
3094
3095 (defmacro gnus-summary-thread-level (&optional number)
3096   "Return the level of thread that starts with article NUMBER."
3097   `(if (and (eq gnus-summary-make-false-root 'dummy)
3098             (get-text-property (point) 'gnus-intangible))
3099        0
3100      (gnus-data-level (gnus-data-find
3101                        ,(or number '(gnus-summary-article-number))))))
3102
3103 (defmacro gnus-summary-article-mark (&optional number)
3104   "Return the mark of article NUMBER."
3105   `(gnus-data-mark (gnus-data-find
3106                     ,(or number '(gnus-summary-article-number)))))
3107
3108 (defmacro gnus-summary-article-pos (&optional number)
3109   "Return the position of the line of article NUMBER."
3110   `(gnus-data-pos (gnus-data-find
3111                    ,(or number '(gnus-summary-article-number)))))
3112
3113 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3114 (defmacro gnus-summary-article-subject (&optional number)
3115   "Return current subject string or nil if nothing."
3116   `(let ((headers
3117           ,(if number
3118                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3119              '(gnus-data-header (assq (gnus-summary-article-number)
3120                                       gnus-newsgroup-data)))))
3121      (and headers
3122           (vectorp headers)
3123           (mail-header-subject headers))))
3124
3125 (defmacro gnus-summary-article-score (&optional number)
3126   "Return current article score."
3127   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3128                   gnus-newsgroup-scored))
3129        gnus-summary-default-score 0))
3130
3131 (defun gnus-summary-article-children (&optional number)
3132   "Return a list of article numbers that are children of article NUMBER."
3133   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3134          (level (gnus-data-level (car data)))
3135          l children)
3136     (while (and (setq data (cdr data))
3137                 (> (setq l (gnus-data-level (car data))) level))
3138       (and (= (1+ level) l)
3139            (push (gnus-data-number (car data))
3140                  children)))
3141     (nreverse children)))
3142
3143 (defun gnus-summary-article-parent (&optional number)
3144   "Return the article number of the parent of article NUMBER."
3145   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3146                                     (gnus-data-list t)))
3147          (level (gnus-data-level (car data))))
3148     (if (zerop level)
3149         ()                              ; This is a root.
3150       ;; We search until we find an article with a level less than
3151       ;; this one.  That function has to be the parent.
3152       (while (and (setq data (cdr data))
3153                   (not (< (gnus-data-level (car data)) level))))
3154       (and data (gnus-data-number (car data))))))
3155
3156 (defun gnus-unread-mark-p (mark)
3157   "Say whether MARK is the unread mark."
3158   (= mark gnus-unread-mark))
3159
3160 (defun gnus-read-mark-p (mark)
3161   "Say whether MARK is one of the marks that mark as read.
3162 This is all marks except unread, ticked, dormant, and expirable."
3163   (not (or (= mark gnus-unread-mark)
3164            (= mark gnus-ticked-mark)
3165            (= mark gnus-spam-mark)
3166            (= mark gnus-dormant-mark)
3167            (= mark gnus-expirable-mark))))
3168
3169 (defmacro gnus-article-mark (number)
3170   "Return the MARK of article NUMBER.
3171 This macro should only be used when computing the mark the \"first\"
3172 time; i.e., when generating the summary lines.  After that,
3173 `gnus-summary-article-mark' should be used to examine the
3174 marks of articles."
3175   `(cond
3176     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3177     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3178     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3179     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3180     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3181     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3182     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3183     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3184            gnus-ancient-mark))))
3185
3186 ;; Saving hidden threads.
3187
3188 (defmacro gnus-save-hidden-threads (&rest forms)
3189   "Save hidden threads, eval FORMS, and restore the hidden threads."
3190   (let ((config (make-symbol "config")))
3191     `(let ((,config (gnus-hidden-threads-configuration)))
3192        (unwind-protect
3193            (save-excursion
3194              ,@forms)
3195          (gnus-restore-hidden-threads-configuration ,config)))))
3196 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3197 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3198
3199 (defun gnus-data-compute-positions ()
3200   "Compute the positions of all articles."
3201   (setq gnus-newsgroup-data-reverse nil)
3202   (let ((data gnus-newsgroup-data))
3203     (save-excursion
3204       (gnus-save-hidden-threads
3205         (gnus-summary-show-all-threads)
3206         (goto-char (point-min))
3207         (while data
3208           (while (get-text-property (point) 'gnus-intangible)
3209             (forward-line 1))
3210           (gnus-data-set-pos (car data) (+ (point) 3))
3211           (setq data (cdr data))
3212           (forward-line 1))))))
3213
3214 (defun gnus-hidden-threads-configuration ()
3215   "Return the current hidden threads configuration."
3216   (save-excursion
3217     (let (config)
3218       (goto-char (point-min))
3219       (while (search-forward "\r" nil t)
3220         (push (1- (point)) config))
3221       config)))
3222
3223 (defun gnus-restore-hidden-threads-configuration (config)
3224   "Restore hidden threads configuration from CONFIG."
3225   (save-excursion
3226     (let (point buffer-read-only)
3227       (while (setq point (pop config))
3228         (when (and (< point (point-max))
3229                    (goto-char point)
3230                    (eq (char-after) ?\n))
3231           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3232
3233 ;; Various summary mode internalish functions.
3234
3235 (defun gnus-mouse-pick-article (e)
3236   (interactive "e")
3237   (mouse-set-point e)
3238   (gnus-summary-next-page nil t))
3239
3240 (defun gnus-summary-set-display-table ()
3241   "Change the display table.
3242 Odd characters have a tendency to mess
3243 up nicely formatted displays - we make all possible glyphs
3244 display only a single character."
3245
3246   ;; We start from the standard display table, if any.
3247   (let ((table (or (copy-sequence standard-display-table)
3248                    (make-display-table)))
3249         (i 32))
3250     ;; Nix out all the control chars...
3251     (while (>= (setq i (1- i)) 0)
3252       (put-display-table i [??] table))
3253    ;; ... but not newline and cr, of course.  (cr is necessary for the
3254     ;; selective display).
3255     (put-display-table ?\n nil table)
3256     (put-display-table ?\r nil table)
3257     ;; We keep TAB as well.
3258     (put-display-table ?\t nil table)
3259     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3260     ;; Emacs 23 (unicode), that are not set already.
3261     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3262                  160
3263                256)))
3264       (while (>= (setq i (1- i)) 127)
3265         ;; Only modify if the entry is nil.
3266         (unless (get-display-table i table)
3267           (put-display-table i [??] table))))
3268     (setq buffer-display-table table)))
3269
3270 (defun gnus-summary-set-article-display-arrow (pos)
3271   "Update the overlay arrow to point to line at position POS."
3272   (when (and gnus-summary-display-arrow
3273              (boundp 'overlay-arrow-position)
3274              (boundp 'overlay-arrow-string))
3275     (save-excursion
3276       (goto-char pos)
3277       (beginning-of-line)
3278       (unless overlay-arrow-position
3279         (setq overlay-arrow-position (make-marker)))
3280       (setq overlay-arrow-string "=>"
3281             overlay-arrow-position (set-marker overlay-arrow-position
3282                                                (point)
3283                                                (current-buffer))))))
3284
3285 (defun gnus-summary-setup-buffer (group)
3286   "Initialize summary buffer."
3287   (let ((buffer (gnus-summary-buffer-name group))
3288         (dead-name (concat "*Dead Summary "
3289                            (gnus-group-decoded-name group) "*")))
3290     ;; If a dead summary buffer exists, we kill it.
3291     (when (gnus-buffer-live-p dead-name)
3292       (gnus-kill-buffer dead-name))
3293     (if (get-buffer buffer)
3294         (progn
3295           (set-buffer buffer)
3296           (setq gnus-summary-buffer (current-buffer))
3297           (not gnus-newsgroup-prepared))
3298       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3299       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3300       (gnus-summary-mode group)
3301       (when gnus-carpal
3302         (gnus-carpal-setup-buffer 'summary))
3303       (unless gnus-single-article-buffer
3304         (make-local-variable 'gnus-article-buffer)
3305         (make-local-variable 'gnus-article-current)
3306         (make-local-variable 'gnus-original-article-buffer))
3307       (setq gnus-newsgroup-name group)
3308       ;; Set any local variables in the group parameters.
3309       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3310       t)))
3311
3312 (defun gnus-set-global-variables ()
3313   "Set the global equivalents of the buffer-local variables.
3314 They are set to the latest values they had.  These reflect the summary
3315 buffer that was in action when the last article was fetched."
3316   (when (eq major-mode 'gnus-summary-mode)
3317     (setq gnus-summary-buffer (current-buffer))
3318     (let ((name gnus-newsgroup-name)
3319           (marked gnus-newsgroup-marked)
3320           (spam gnus-newsgroup-spam-marked)
3321           (unread gnus-newsgroup-unreads)
3322           (headers gnus-current-headers)
3323           (data gnus-newsgroup-data)
3324           (summary gnus-summary-buffer)
3325           (article-buffer gnus-article-buffer)
3326           (original gnus-original-article-buffer)
3327           (gac gnus-article-current)
3328           (reffed gnus-reffed-article-number)
3329           (score-file gnus-current-score-file)
3330           (default-charset gnus-newsgroup-charset)
3331           vlist)
3332       (let ((locals gnus-newsgroup-variables))
3333         (while locals
3334           (if (consp (car locals))
3335               (push (eval (caar locals)) vlist)
3336             (push (eval (car locals)) vlist))
3337           (setq locals (cdr locals)))
3338         (setq vlist (nreverse vlist)))
3339       (save-excursion
3340         (set-buffer gnus-group-buffer)
3341         (setq gnus-newsgroup-name name
3342               gnus-newsgroup-marked marked
3343               gnus-newsgroup-spam-marked spam
3344               gnus-newsgroup-unreads unread
3345               gnus-current-headers headers
3346               gnus-newsgroup-data data
3347               gnus-article-current gac
3348               gnus-summary-buffer summary
3349               gnus-article-buffer article-buffer
3350               gnus-original-article-buffer original
3351               gnus-reffed-article-number reffed
3352               gnus-current-score-file score-file
3353               gnus-newsgroup-charset default-charset)
3354         (let ((locals gnus-newsgroup-variables))
3355           (while locals
3356             (if (consp (car locals))
3357                 (set (caar locals) (pop vlist))
3358               (set (car locals) (pop vlist)))
3359             (setq locals (cdr locals))))
3360         ;; The article buffer also has local variables.
3361         (when (gnus-buffer-live-p gnus-article-buffer)
3362           (set-buffer gnus-article-buffer)
3363           (setq gnus-summary-buffer summary))))))
3364
3365 (defun gnus-summary-article-unread-p (article)
3366   "Say whether ARTICLE is unread or not."
3367   (memq article gnus-newsgroup-unreads))
3368
3369 (defun gnus-summary-first-article-p (&optional article)
3370   "Return whether ARTICLE is the first article in the buffer."
3371   (if (not (setq article (or article (gnus-summary-article-number))))
3372       nil
3373     (eq article (caar gnus-newsgroup-data))))
3374
3375 (defun gnus-summary-last-article-p (&optional article)
3376   "Return whether ARTICLE is the last article in the buffer."
3377   (if (not (setq article (or article (gnus-summary-article-number))))
3378       ;; All non-existent numbers are the last article.  :-)
3379       t
3380     (not (cdr (gnus-data-find-list article)))))
3381
3382 (defun gnus-make-thread-indent-array (&optional n)
3383   (when (or n
3384             (progn (setq n 200) nil)
3385             (null gnus-thread-indent-array)
3386             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3387     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3388           gnus-thread-indent-array-level gnus-thread-indent-level)
3389     (while (>= n 0)
3390       (aset gnus-thread-indent-array n
3391             (make-string (* n gnus-thread-indent-level) ? ))
3392       (setq n (1- n)))))
3393
3394 (defun gnus-update-summary-mark-positions ()
3395   "Compute where the summary marks are to go."
3396   (save-excursion
3397     (when (gnus-buffer-exists-p gnus-summary-buffer)
3398       (set-buffer gnus-summary-buffer))
3399     (let ((spec gnus-summary-line-format-spec)
3400           pos)
3401       (save-excursion
3402         (gnus-set-work-buffer)
3403         (let ((gnus-tmp-unread ?Z)
3404               (gnus-replied-mark ?Z)
3405               (gnus-score-below-mark ?Z)
3406               (gnus-score-over-mark ?Z)
3407               (gnus-undownloaded-mark ?Z)
3408               (gnus-summary-line-format-spec spec)
3409               (gnus-newsgroup-downloadable '(0))
3410               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3411               case-fold-search ignores)
3412           ;; Here, all marks are bound to Z.
3413           (gnus-summary-insert-line header
3414                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3415           (goto-char (point-min))
3416           ;; Memorize the positions of the same characters as dummy marks.
3417           (while (re-search-forward "[A-D]" nil t)
3418             (push (point) ignores))
3419           (erase-buffer)
3420           ;; We use A-D as dummy marks in order to know column positions
3421           ;; where marks should be inserted.
3422           (setq gnus-tmp-unread ?A
3423                 gnus-replied-mark ?B
3424                 gnus-score-below-mark ?C
3425                 gnus-score-over-mark ?C
3426                 gnus-undownloaded-mark ?D)
3427           (gnus-summary-insert-line header
3428                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3429           ;; Ignore characters which aren't dummy marks.
3430           (dolist (p ignores)
3431             (delete-region (goto-char (1- p)) p)
3432             (insert ?Z))
3433           (goto-char (point-min))
3434           (setq pos (list (cons 'unread
3435                                 (and (search-forward "A" nil t)
3436                                      (- (point) (point-min) 1)))))
3437           (goto-char (point-min))
3438           (push (cons 'replied (and (search-forward "B" nil t)
3439                                     (- (point) (point-min) 1)))
3440                 pos)
3441           (goto-char (point-min))
3442           (push (cons 'score (and (search-forward "C" nil t)
3443                                   (- (point) (point-min) 1)))
3444                 pos)
3445           (goto-char (point-min))
3446           (push (cons 'download (and (search-forward "D" nil t)
3447                                      (- (point) (point-min) 1)))
3448                 pos)))
3449       (setq gnus-summary-mark-positions pos))))
3450
3451 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3452   "Insert a dummy root in the summary buffer."
3453   (beginning-of-line)
3454   (gnus-add-text-properties
3455    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3456    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3457
3458 (defun gnus-summary-extract-address-component (from)
3459   (or (car (funcall gnus-extract-address-components from))
3460       from))
3461
3462 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3463   (let ((mail-parse-charset gnus-newsgroup-charset)
3464         ; Is it really necessary to do this next part for each summary line?
3465         ; Luckily, doesn't seem to slow things down much.
3466         (mail-parse-ignored-charsets
3467          (save-excursion (set-buffer gnus-summary-buffer)
3468                          gnus-newsgroup-ignored-charsets)))
3469     (or
3470      (and gnus-ignored-from-addresses
3471           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3472           (let ((extra-headers (mail-header-extra header))
3473                 to
3474                 newsgroups)
3475             (cond
3476              ((setq to (cdr (assq 'To extra-headers)))
3477               (concat "-> "
3478                       (inline
3479                         (gnus-summary-extract-address-component
3480                          (funcall gnus-decode-encoded-address-function to)))))
3481              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3482               (concat "=> " newsgroups)))))
3483      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3484
3485 (defun gnus-summary-insert-line (gnus-tmp-header
3486                                  gnus-tmp-level gnus-tmp-current
3487                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3488                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3489                                  &optional gnus-tmp-dummy gnus-tmp-score
3490                                  gnus-tmp-process)
3491   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3492       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3493                                           gnus-tmp-level)))
3494   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3495          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3496          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3497          (gnus-tmp-score-char
3498           (if (or (null gnus-summary-default-score)
3499                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3500                       gnus-summary-zcore-fuzz))
3501               ?                         ;Whitespace
3502             (if (< gnus-tmp-score gnus-summary-default-score)
3503                 gnus-score-below-mark gnus-score-over-mark)))
3504          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3505          (gnus-tmp-replied
3506           (cond (gnus-tmp-process gnus-process-mark)
3507                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3508                  gnus-cached-mark)
3509                 (gnus-tmp-replied gnus-replied-mark)
3510                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3511                  gnus-forwarded-mark)
3512                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3513                  gnus-saved-mark)
3514                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3515                  gnus-recent-mark)
3516                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3517                  gnus-unseen-mark)
3518                 (t gnus-no-mark)))
3519          (gnus-tmp-downloaded
3520           (cond (undownloaded
3521                  gnus-undownloaded-mark)
3522                 (gnus-newsgroup-agentized
3523                  gnus-downloaded-mark)
3524                 (t
3525                  gnus-no-mark)))
3526          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3527          (gnus-tmp-name
3528           (cond
3529            ((string-match "<[^>]+> *$" gnus-tmp-from)
3530             (let ((beg (match-beginning 0)))
3531               (or (and (string-match "^\".+\"" gnus-tmp-from)
3532                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3533                   (substring gnus-tmp-from 0 beg))))
3534            ((string-match "(.+)" gnus-tmp-from)
3535             (substring gnus-tmp-from
3536                        (1+ (match-beginning 0)) (1- (match-end 0))))
3537            (t gnus-tmp-from)))
3538          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3539          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3540          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3541          (buffer-read-only nil))
3542     (when (string= gnus-tmp-name "")
3543       (setq gnus-tmp-name gnus-tmp-from))
3544     (unless (numberp gnus-tmp-lines)
3545       (setq gnus-tmp-lines -1))
3546     (if (= gnus-tmp-lines -1)
3547         (setq gnus-tmp-lines "?")
3548       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3549       (gnus-put-text-property
3550      (point)
3551      (progn (eval gnus-summary-line-format-spec) (point))
3552        'gnus-number gnus-tmp-number)
3553     (when (gnus-visual-p 'summary-highlight 'highlight)
3554       (forward-line -1)
3555       (gnus-run-hooks 'gnus-summary-update-hook)
3556       (forward-line 1))))
3557
3558 (defun gnus-summary-update-line (&optional dont-update)
3559   "Update summary line after change."
3560   (when (and gnus-summary-default-score
3561              (not gnus-summary-inhibit-highlight))
3562     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3563            (article (gnus-summary-article-number))
3564            (score (gnus-summary-article-score article)))
3565       (unless dont-update
3566         (if (and gnus-summary-mark-below
3567                  (< (gnus-summary-article-score)
3568                     gnus-summary-mark-below))
3569             ;; This article has a low score, so we mark it as read.
3570             (when (memq article gnus-newsgroup-unreads)
3571               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3572           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3573             ;; This article was previously marked as read on account
3574             ;; of a low score, but now it has risen, so we mark it as
3575             ;; unread.
3576             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3577         (gnus-summary-update-mark
3578          (if (or (null gnus-summary-default-score)
3579                  (<= (abs (- score gnus-summary-default-score))
3580                      gnus-summary-zcore-fuzz))
3581              ?                          ;Whitespace
3582            (if (< score gnus-summary-default-score)
3583                gnus-score-below-mark gnus-score-over-mark))
3584          'score))
3585       ;; Do visual highlighting.
3586       (when (gnus-visual-p 'summary-highlight 'highlight)
3587         (gnus-run-hooks 'gnus-summary-update-hook)))))
3588
3589 (defvar gnus-tmp-new-adopts nil)
3590
3591 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3592   "Return the number of articles in THREAD.
3593 This may be 0 in some cases -- if none of the articles in
3594 the thread are to be displayed."
3595   (let* ((number
3596          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3597           (cond
3598            ((not (listp thread))
3599             1)
3600            ((and (consp thread) (cdr thread))
3601             (apply
3602              '+ 1 (mapcar
3603                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3604            ((null thread)
3605             1)
3606            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3607             1)
3608            (t 0))))
3609     (when (and level (zerop level) gnus-tmp-new-adopts)
3610       (incf number
3611             (apply '+ (mapcar
3612                        'gnus-summary-number-of-articles-in-thread
3613                        gnus-tmp-new-adopts))))
3614     (if char
3615         (if (> number 1) gnus-not-empty-thread-mark
3616           gnus-empty-thread-mark)
3617       number)))
3618
3619 (defsubst gnus-summary-line-message-size (head)
3620   "Return pretty-printed version of message size.
3621 This function is intended to be used in
3622 `gnus-summary-line-format-alist'."
3623   (let ((c (or (mail-header-chars head) -1)))
3624     (cond ((< c 0) "n/a")               ; chars not available
3625           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3626           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3627           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3628           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3629
3630
3631 (defun gnus-summary-set-local-parameters (group)
3632   "Go through the local params of GROUP and set all variable specs in that list."
3633   (let ((params (gnus-group-find-parameter group))
3634         (vars '(quit-config))           ; Ignore quit-config.
3635         elem)
3636     (while params
3637       (setq elem (car params)
3638             params (cdr params))
3639       (and (consp elem)                 ; Has to be a cons.
3640            (consp (cdr elem))           ; The cdr has to be a list.
3641            (symbolp (car elem))         ; Has to be a symbol in there.
3642            (not (memq (car elem) vars))
3643            (ignore-errors               ; So we set it.
3644              (push (car elem) vars)
3645              (make-local-variable (car elem))
3646              (set (car elem) (eval (nth 1 elem))))))))
3647
3648 (defun gnus-summary-read-group (group &optional show-all no-article
3649                                       kill-buffer no-display backward
3650                                       select-articles)
3651   "Start reading news in newsgroup GROUP.
3652 If SHOW-ALL is non-nil, already read articles are also listed.
3653 If NO-ARTICLE is non-nil, no article is selected initially.
3654 If NO-DISPLAY, don't generate a summary buffer."
3655   (let (result)
3656     (while (and group
3657                 (null (setq result
3658                             (let ((gnus-auto-select-next nil))
3659                               (or (gnus-summary-read-group-1
3660                                    group show-all no-article
3661                                    kill-buffer no-display
3662                                    select-articles)
3663                                   (setq show-all nil
3664                                         select-articles nil)))))
3665                 (eq gnus-auto-select-next 'quietly))
3666       (set-buffer gnus-group-buffer)
3667       ;; The entry function called above goes to the next
3668       ;; group automatically, so we go two groups back
3669       ;; if we are searching for the previous group.
3670       (when backward
3671         (gnus-group-prev-unread-group 2))
3672       (if (not (equal group (gnus-group-group-name)))
3673           (setq group (gnus-group-group-name))
3674         (setq group nil)))
3675     result))
3676
3677 (defun gnus-summary-read-group-1 (group show-all no-article
3678                                         kill-buffer no-display
3679                                         &optional select-articles)
3680   ;; Killed foreign groups can't be entered.
3681   ;;  (when (and (not (gnus-group-native-p group))
3682   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3683   ;;    (error "Dead non-native groups can't be entered"))
3684   (gnus-message 5 "Retrieving newsgroup: %s..."
3685                 (gnus-group-decoded-name group))
3686   (let* ((new-group (gnus-summary-setup-buffer group))
3687          (quit-config (gnus-group-quit-config group))
3688          (did-select (and new-group (gnus-select-newsgroup
3689                                      group show-all select-articles))))
3690     (cond
3691      ;; This summary buffer exists already, so we just select it.
3692      ((not new-group)
3693       (gnus-set-global-variables)
3694       (when kill-buffer
3695         (gnus-kill-or-deaden-summary kill-buffer))
3696       (gnus-configure-windows 'summary 'force)
3697       (gnus-set-mode-line 'summary)
3698       (gnus-summary-position-point)
3699       (message "")
3700       t)
3701      ;; We couldn't select this group.
3702      ((null did-select)
3703       (when (and (eq major-mode 'gnus-summary-mode)
3704                  (not (equal (current-buffer) kill-buffer)))
3705         (kill-buffer (current-buffer))
3706         (if (not quit-config)
3707             (progn
3708               ;; Update the info -- marks might need to be removed,
3709               ;; for instance.
3710               (gnus-summary-update-info)
3711               (set-buffer gnus-group-buffer)
3712               (gnus-group-jump-to-group group)
3713               (gnus-group-next-unread-group 1))
3714           (gnus-handle-ephemeral-exit quit-config)))
3715       (let ((grpinfo (gnus-get-info group)))
3716         (if (null (gnus-info-read grpinfo))
3717             (gnus-message 3 "Group %s contains no messages"
3718                           (gnus-group-decoded-name group))
3719           (gnus-message 3 "Can't select group")))
3720       nil)
3721      ;; The user did a `C-g' while prompting for number of articles,
3722      ;; so we exit this group.
3723      ((eq did-select 'quit)
3724       (and (eq major-mode 'gnus-summary-mode)
3725            (not (equal (current-buffer) kill-buffer))
3726            (kill-buffer (current-buffer)))
3727       (when kill-buffer
3728         (gnus-kill-or-deaden-summary kill-buffer))
3729       (if (not quit-config)
3730           (progn
3731             (set-buffer gnus-group-buffer)
3732             (gnus-group-jump-to-group group)
3733             (gnus-group-next-unread-group 1)
3734             (gnus-configure-windows 'group 'force))
3735         (gnus-handle-ephemeral-exit quit-config))
3736       ;; Finally signal the quit.
3737       (signal 'quit nil))
3738      ;; The group was successfully selected.
3739      (t
3740       (gnus-set-global-variables)
3741       ;; Save the active value in effect when the group was entered.
3742       (setq gnus-newsgroup-active
3743             (gnus-copy-sequence
3744              (gnus-active gnus-newsgroup-name)))
3745       ;; You can change the summary buffer in some way with this hook.
3746       (gnus-run-hooks 'gnus-select-group-hook)
3747       (when (memq 'summary (gnus-update-format-specifications
3748                             nil 'summary 'summary-mode 'summary-dummy))
3749         ;; The format specification for the summary line was updated,
3750         ;; so we need to update the mark positions as well.
3751         (gnus-update-summary-mark-positions))
3752       ;; Do score processing.
3753       (when gnus-use-scoring
3754         (gnus-possibly-score-headers))
3755       ;; Check whether to fill in the gaps in the threads.
3756       (when gnus-build-sparse-threads
3757         (gnus-build-sparse-threads))
3758       ;; Find the initial limit.
3759       (if show-all
3760           (let ((gnus-newsgroup-dormant nil))
3761             (gnus-summary-initial-limit show-all))
3762         (gnus-summary-initial-limit show-all))
3763       ;; Generate the summary buffer.
3764       (unless no-display
3765         (gnus-summary-prepare))
3766       (when gnus-use-trees
3767         (gnus-tree-open group)
3768         (setq gnus-summary-highlight-line-function
3769               'gnus-tree-highlight-article))
3770       ;; If the summary buffer is empty, but there are some low-scored
3771       ;; articles or some excluded dormants, we include these in the
3772       ;; buffer.
3773       (when (and (zerop (buffer-size))
3774                  (not no-display))
3775         (cond (gnus-newsgroup-dormant
3776                (gnus-summary-limit-include-dormant))
3777               ((and gnus-newsgroup-scored show-all)
3778                (gnus-summary-limit-include-expunged t))))
3779       ;; Function `gnus-apply-kill-file' must be called in this hook.
3780       (gnus-run-hooks 'gnus-apply-kill-hook)
3781       (if (and (zerop (buffer-size))
3782                (not no-display))
3783           (progn
3784             ;; This newsgroup is empty.
3785             (gnus-summary-catchup-and-exit nil t)
3786             (gnus-message 6 "No unread news")
3787             (when kill-buffer
3788               (gnus-kill-or-deaden-summary kill-buffer))
3789             ;; Return nil from this function.
3790             nil)
3791         ;; Hide conversation thread subtrees.  We cannot do this in
3792         ;; gnus-summary-prepare-hook since kill processing may not
3793         ;; work with hidden articles.
3794         (gnus-summary-maybe-hide-threads)
3795         (when kill-buffer
3796           (gnus-kill-or-deaden-summary kill-buffer))
3797         (gnus-summary-auto-select-subject)
3798         ;; Show first unread article if requested.
3799         (if (and (not no-article)
3800                  (not no-display)
3801                  gnus-newsgroup-unreads
3802                  gnus-auto-select-first)
3803             (progn
3804               (gnus-configure-windows 'summary)
3805               (let ((art (gnus-summary-article-number)))
3806                 (unless (and (not gnus-plugged)
3807                              (or (memq art gnus-newsgroup-undownloaded)
3808                                  (memq art gnus-newsgroup-downloadable)))
3809                   (gnus-summary-goto-article art))))
3810           ;; Don't select any articles.
3811           (gnus-summary-position-point)
3812           (gnus-configure-windows 'summary 'force)
3813           (gnus-set-mode-line 'summary))
3814         (when (and gnus-auto-center-group
3815                    (get-buffer-window gnus-group-buffer t))
3816           ;; Gotta use windows, because recenter does weird stuff if
3817           ;; the current buffer ain't the displayed window.
3818           (let ((owin (selected-window)))
3819             (select-window (get-buffer-window gnus-group-buffer t))
3820             (when (gnus-group-goto-group group)
3821               (recenter))
3822             (select-window owin)))
3823         ;; Mark this buffer as "prepared".
3824         (setq gnus-newsgroup-prepared t)
3825         (gnus-run-hooks 'gnus-summary-prepared-hook)
3826         (unless (gnus-ephemeral-group-p group)
3827           (gnus-group-update-group group))
3828         t)))))
3829
3830 (defun gnus-summary-auto-select-subject ()
3831   "Select the subject line on initial group entry."
3832   (goto-char (point-min))
3833   (cond
3834    ((eq gnus-auto-select-subject 'best)
3835     (gnus-summary-best-unread-subject))
3836    ((eq gnus-auto-select-subject 'unread)
3837     (gnus-summary-first-unread-subject))
3838    ((eq gnus-auto-select-subject 'unseen)
3839     (gnus-summary-first-unseen-subject))
3840    ((eq gnus-auto-select-subject 'unseen-or-unread)
3841     (gnus-summary-first-unseen-or-unread-subject))
3842    ((eq gnus-auto-select-subject 'first)
3843     ;; Do nothing.
3844     )
3845    ((functionp gnus-auto-select-subject)
3846     (funcall gnus-auto-select-subject))))
3847
3848 (defun gnus-summary-prepare ()
3849   "Generate the summary buffer."
3850   (interactive)
3851   (let ((buffer-read-only nil))
3852     (erase-buffer)
3853     (setq gnus-newsgroup-data nil
3854           gnus-newsgroup-data-reverse nil)
3855     (gnus-run-hooks 'gnus-summary-generate-hook)
3856     ;; Generate the buffer, either with threads or without.
3857     (when gnus-newsgroup-headers
3858       (gnus-summary-prepare-threads
3859        (if gnus-show-threads
3860            (gnus-sort-gathered-threads
3861             (funcall gnus-summary-thread-gathering-function
3862                      (gnus-sort-threads
3863                       (gnus-cut-threads (gnus-make-threads)))))
3864          ;; Unthreaded display.
3865          (gnus-sort-articles gnus-newsgroup-headers))))
3866     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3867     ;; Call hooks for modifying summary buffer.
3868     (goto-char (point-min))
3869     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3870
3871 (defsubst gnus-general-simplify-subject (subject)
3872   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3873   (setq subject
3874         (cond
3875          ;; Truncate the subject.
3876          (gnus-simplify-subject-functions
3877           (gnus-map-function gnus-simplify-subject-functions subject))
3878          ((numberp gnus-summary-gather-subject-limit)
3879           (setq subject (gnus-simplify-subject-re subject))
3880           (if (> (length subject) gnus-summary-gather-subject-limit)
3881               (substring subject 0 gnus-summary-gather-subject-limit)
3882             subject))
3883          ;; Fuzzily simplify it.
3884          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3885           (gnus-simplify-subject-fuzzy subject))
3886          ;; Just remove the leading "Re:".
3887          (t
3888           (gnus-simplify-subject-re subject))))
3889
3890   (if (and gnus-summary-gather-exclude-subject
3891            (string-match gnus-summary-gather-exclude-subject subject))
3892       nil                         ; This article shouldn't be gathered
3893     subject))
3894
3895 (defun gnus-summary-simplify-subject-query ()
3896   "Query where the respool algorithm would put this article."
3897   (interactive)
3898   (gnus-summary-select-article)
3899   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3900
3901 (defun gnus-gather-threads-by-subject (threads)
3902   "Gather threads by looking at Subject headers."
3903   (if (not gnus-summary-make-false-root)
3904       threads
3905     (let ((hashtb (gnus-make-hashtable 1024))
3906           (prev threads)
3907           (result threads)
3908           subject hthread whole-subject)
3909       (while threads
3910         (setq subject (gnus-general-simplify-subject
3911                        (setq whole-subject (mail-header-subject
3912                                             (caar threads)))))
3913         (when subject
3914           (if (setq hthread (gnus-gethash subject hashtb))
3915               (progn
3916                 ;; We enter a dummy root into the thread, if we
3917                 ;; haven't done that already.
3918                 (unless (stringp (caar hthread))
3919                   (setcar hthread (list whole-subject (car hthread))))
3920                 ;; We add this new gathered thread to this gathered
3921                 ;; thread.
3922                 (setcdr (car hthread)
3923                         (nconc (cdar hthread) (list (car threads))))
3924                 ;; Remove it from the list of threads.
3925                 (setcdr prev (cdr threads))
3926                 (setq threads prev))
3927             ;; Enter this thread into the hash table.
3928             (gnus-sethash subject
3929                           (if gnus-summary-make-false-root-always
3930                               (progn
3931                                 ;; If you want a dummy root above all
3932                                 ;; threads...
3933                                 (setcar threads (list whole-subject
3934                                                       (car threads)))
3935                                 threads)
3936                             threads)
3937                           hashtb)))
3938         (setq prev threads)
3939         (setq threads (cdr threads)))
3940       result)))
3941
3942 (defun gnus-gather-threads-by-references (threads)
3943   "Gather threads by looking at References headers."
3944   (let ((idhashtb (gnus-make-hashtable 1024))
3945         (thhashtb (gnus-make-hashtable 1024))
3946         (prev threads)
3947         (result threads)
3948         ids references id gthread gid entered ref)
3949     (while threads
3950       (when (setq references (mail-header-references (caar threads)))
3951         (setq id (mail-header-id (caar threads))
3952               ids (inline (gnus-split-references references))
3953               entered nil)
3954         (while (setq ref (pop ids))
3955           (setq ids (delete ref ids))
3956           (if (not (setq gid (gnus-gethash ref idhashtb)))
3957               (progn
3958                 (gnus-sethash ref id idhashtb)
3959                 (gnus-sethash id threads thhashtb))
3960             (setq gthread (gnus-gethash gid thhashtb))
3961             (unless entered
3962               ;; We enter a dummy root into the thread, if we
3963               ;; haven't done that already.
3964               (unless (stringp (caar gthread))
3965                 (setcar gthread (list (mail-header-subject (caar gthread))
3966                                       (car gthread))))
3967               ;; We add this new gathered thread to this gathered
3968               ;; thread.
3969               (setcdr (car gthread)
3970                       (nconc (cdar gthread) (list (car threads)))))
3971             ;; Add it into the thread hash table.
3972             (gnus-sethash id gthread thhashtb)
3973             (setq entered t)
3974             ;; Remove it from the list of threads.
3975             (setcdr prev (cdr threads))
3976             (setq threads prev))))
3977       (setq prev threads)
3978       (setq threads (cdr threads)))
3979     result))
3980
3981 (defun gnus-sort-gathered-threads (threads)
3982   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3983   (let ((result threads))
3984     (while threads
3985       (when (stringp (caar threads))
3986         (setcdr (car threads)
3987                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3988       (setq threads (cdr threads)))
3989     result))
3990
3991 (defun gnus-thread-loop-p (root thread)
3992   "Say whether ROOT is in THREAD."
3993   (let ((stack (list thread))
3994         (infloop 0)
3995         th)
3996     (while (setq thread (pop stack))
3997       (setq th (cdr thread))
3998       (while (and th
3999                   (not (eq (caar th) root)))
4000         (pop th))
4001       (if th
4002           ;; We have found a loop.
4003           (let (ref-dep)
4004             (setcdr thread (delq (car th) (cdr thread)))
4005             (if (boundp (setq ref-dep (intern "none"
4006                                               gnus-newsgroup-dependencies)))
4007                 (setcdr (symbol-value ref-dep)
4008                         (nconc (cdr (symbol-value ref-dep))
4009                                (list (car th))))
4010               (set ref-dep (list nil (car th))))
4011             (setq infloop 1
4012                   stack nil))
4013         ;; Push all the subthreads onto the stack.
4014         (push (cdr thread) stack)))
4015     infloop))
4016
4017 (defun gnus-make-threads ()
4018   "Go through the dependency hashtb and find the roots.  Return all threads."
4019   (let (threads)
4020     (while (catch 'infloop
4021              (mapatoms
4022               (lambda (refs)
4023                 ;; Deal with self-referencing References loops.
4024                 (when (and (car (symbol-value refs))
4025                            (not (zerop
4026                                  (apply
4027                                   '+
4028                                   (mapcar
4029                                    (lambda (thread)
4030                                      (gnus-thread-loop-p
4031                                       (car (symbol-value refs)) thread))
4032                                    (cdr (symbol-value refs)))))))
4033                   (setq threads nil)
4034                   (throw 'infloop t))
4035                 (unless (car (symbol-value refs))
4036                   ;; These threads do not refer back to any other
4037                   ;; articles, so they're roots.
4038                   (setq threads (append (cdr (symbol-value refs)) threads))))
4039               gnus-newsgroup-dependencies)))
4040     threads))
4041
4042 ;; Build the thread tree.
4043 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4044   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4045
4046 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4047 if it was already present.
4048
4049 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4050 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4051 Message-IDs will be renamed to a unique Message-ID before being
4052 entered.
4053
4054 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4055   (let* ((id (mail-header-id header))
4056          (id-dep (and id (intern id dependencies)))
4057          parent-id ref ref-dep ref-header replaced)
4058     ;; Enter this `header' in the `dependencies' table.
4059     (cond
4060      ((not id-dep)
4061       (setq header nil))
4062      ;; The first two cases do the normal part: enter a new `header'
4063      ;; in the `dependencies' table.
4064      ((not (boundp id-dep))
4065       (set id-dep (list header)))
4066      ((null (car (symbol-value id-dep)))
4067       (setcar (symbol-value id-dep) header))
4068
4069      ;; From here the `header' was already present in the
4070      ;; `dependencies' table.
4071      (force-new
4072       ;; Overrides an existing entry;
4073       ;; just set the header part of the entry.
4074       (setcar (symbol-value id-dep) header)
4075       (setq replaced t))
4076
4077      ;; Renames the existing `header' to a unique Message-ID.
4078      ((not gnus-summary-ignore-duplicates)
4079       ;; An article with this Message-ID has already been seen.
4080       ;; We rename the Message-ID.
4081       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4082            (list header))
4083       (mail-header-set-id header id))
4084
4085      ;; The last case ignores an existing entry, except it adds any
4086      ;; additional Xrefs (in case the two articles came from different
4087      ;; servers.
4088      ;; Also sets `header' to `nil' meaning that the `dependencies'
4089      ;; table was *not* modified.
4090      (t
4091       (mail-header-set-xref
4092        (car (symbol-value id-dep))
4093        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4094                    "")
4095                (or (mail-header-xref header) "")))
4096       (setq header nil)))
4097
4098     (when (and header (not replaced))
4099       ;; First check that we are not creating a References loop.
4100       (setq parent-id (gnus-parent-id (mail-header-references header)))
4101       (setq ref parent-id)
4102       (while (and ref
4103                   (setq ref-dep (intern-soft ref dependencies))
4104                   (boundp ref-dep)
4105                   (setq ref-header (car (symbol-value ref-dep))))
4106         (if (string= id ref)
4107             ;; Yuk!  This is a reference loop.  Make the article be a
4108             ;; root article.
4109             (progn
4110               (mail-header-set-references (car (symbol-value id-dep)) "none")
4111               (setq ref nil)
4112               (setq parent-id nil))
4113           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4114       (setq ref-dep (intern (or parent-id "none") dependencies))
4115       (if (boundp ref-dep)
4116           (setcdr (symbol-value ref-dep)
4117                   (nconc (cdr (symbol-value ref-dep))
4118                          (list (symbol-value id-dep))))
4119         (set ref-dep (list nil (symbol-value id-dep)))))
4120     header))
4121
4122 (defun gnus-extract-message-id-from-in-reply-to (string)
4123   (if (string-match "<[^>]+>" string)
4124       (substring string (match-beginning 0) (match-end 0))
4125     nil))
4126
4127 (defun gnus-build-sparse-threads ()
4128   (let ((headers gnus-newsgroup-headers)
4129         (mail-parse-charset gnus-newsgroup-charset)
4130         (gnus-summary-ignore-duplicates t)
4131         header references generation relations
4132         subject child end new-child date)
4133     ;; First we create an alist of generations/relations, where
4134     ;; generations is how much we trust the relation, and the relation
4135     ;; is parent/child.
4136     (gnus-message 7 "Making sparse threads...")
4137     (save-excursion
4138       (nnheader-set-temp-buffer " *gnus sparse threads*")
4139       (while (setq header (pop headers))
4140         (when (and (setq references (mail-header-references header))
4141                    (not (string= references "")))
4142           (insert references)
4143           (setq child (mail-header-id header)
4144                 subject (mail-header-subject header)
4145                 date (mail-header-date header)
4146                 generation 0)
4147           (while (search-backward ">" nil t)
4148             (setq end (1+ (point)))
4149             (when (search-backward "<" nil t)
4150               (setq new-child (buffer-substring (point) end))
4151               (push (list (incf generation)
4152                           child (setq child new-child)
4153                           subject date)
4154                     relations)))
4155           (when child
4156             (push (list (1+ generation) child nil subject) relations))
4157           (erase-buffer)))
4158       (kill-buffer (current-buffer)))
4159     ;; Sort over trustworthiness.
4160     (mapcar
4161      (lambda (relation)
4162        (when (gnus-dependencies-add-header
4163               (make-full-mail-header
4164                gnus-reffed-article-number
4165                (nth 3 relation) "" (or (nth 4 relation) "")
4166                (nth 1 relation)
4167                (or (nth 2 relation) "") 0 0 "")
4168               gnus-newsgroup-dependencies nil)
4169          (push gnus-reffed-article-number gnus-newsgroup-limit)
4170          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4171          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4172                gnus-newsgroup-reads)
4173          (decf gnus-reffed-article-number)))
4174      (sort relations 'car-less-than-car))
4175     (gnus-message 7 "Making sparse threads...done")))
4176
4177 (defun gnus-build-old-threads ()
4178   ;; Look at all the articles that refer back to old articles, and
4179   ;; fetch the headers for the articles that aren't there.  This will
4180   ;; build complete threads - if the roots haven't been expired by the
4181   ;; server, that is.
4182   (let ((mail-parse-charset gnus-newsgroup-charset)
4183         id heads)
4184     (mapatoms
4185      (lambda (refs)
4186        (when (not (car (symbol-value refs)))
4187          (setq heads (cdr (symbol-value refs)))
4188          (while heads
4189            (if (memq (mail-header-number (caar heads))
4190                      gnus-newsgroup-dormant)
4191                (setq heads (cdr heads))
4192              (setq id (symbol-name refs))
4193              (while (and (setq id (gnus-build-get-header id))
4194                          (not (car (gnus-id-to-thread id)))))
4195              (setq heads nil)))))
4196      gnus-newsgroup-dependencies)))
4197
4198 (defsubst gnus-remove-odd-characters (string)
4199   "Translate STRING into something that doesn't contain weird characters."
4200   (mm-subst-char-in-string
4201    ?\r ?\-
4202    (mm-subst-char-in-string
4203     ?\n ?\- string)))
4204
4205 ;; This function has to be called with point after the article number
4206 ;; on the beginning of the line.
4207 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4208   (let ((eol (gnus-point-at-eol))
4209         (buffer (current-buffer))
4210         header references in-reply-to)
4211
4212     ;; overview: [num subject from date id refs chars lines misc]
4213     (unwind-protect
4214         (let (x)
4215           (narrow-to-region (point) eol)
4216           (unless (eobp)
4217             (forward-char))
4218
4219           (setq header
4220                 (make-full-mail-header
4221                  number                 ; number
4222                  (condition-case ()     ; subject
4223                      (gnus-remove-odd-characters
4224                       (funcall gnus-decode-encoded-word-function
4225                                (setq x (nnheader-nov-field))))
4226                    (error x))
4227                  (condition-case ()     ; from
4228                      (gnus-remove-odd-characters
4229                       (funcall gnus-decode-encoded-address-function
4230                                (setq x (nnheader-nov-field))))
4231                    (error x))
4232                  (nnheader-nov-field)   ; date
4233                  (nnheader-nov-read-message-id) ; id
4234                  (setq references (nnheader-nov-field)) ; refs
4235                  (nnheader-nov-read-integer) ; chars
4236                  (nnheader-nov-read-integer) ; lines
4237                  (unless (eobp)
4238                    (if (looking-at "Xref: ")
4239                        (goto-char (match-end 0)))
4240                    (nnheader-nov-field)) ; Xref
4241                  (nnheader-nov-parse-extra)))) ; extra
4242
4243       (widen))
4244
4245     (when (and (string= references "")
4246                (setq in-reply-to (mail-header-extra header))
4247                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4248       (mail-header-set-references
4249        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4250
4251     (when gnus-alter-header-function
4252       (funcall gnus-alter-header-function header))
4253     (gnus-dependencies-add-header header dependencies force-new)))
4254
4255 (defun gnus-build-get-header (id)
4256   "Look through the buffer of NOV lines and find the header to ID.
4257 Enter this line into the dependencies hash table, and return
4258 the id of the parent article (if any)."
4259   (let ((deps gnus-newsgroup-dependencies)
4260         found header)
4261     (prog1
4262         (save-excursion
4263           (set-buffer nntp-server-buffer)
4264           (let ((case-fold-search nil))
4265             (goto-char (point-min))
4266             (while (and (not found)
4267                         (search-forward id nil t))
4268               (beginning-of-line)
4269               (setq found (looking-at
4270                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4271                                    (regexp-quote id))))
4272               (or found (beginning-of-line 2)))
4273             (when found
4274               (beginning-of-line)
4275               (and
4276                (setq header (gnus-nov-parse-line
4277                              (read (current-buffer)) deps))
4278                (gnus-parent-id (mail-header-references header))))))
4279       (when header
4280         (let ((number (mail-header-number header)))
4281           (push number gnus-newsgroup-limit)
4282           (push header gnus-newsgroup-headers)
4283           (if (memq number gnus-newsgroup-unselected)
4284               (progn
4285                 (setq gnus-newsgroup-unreads
4286                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4287                                                number))
4288                 (setq gnus-newsgroup-unselected
4289                       (delq number gnus-newsgroup-unselected)))
4290             (push number gnus-newsgroup-ancient)))))))
4291
4292 (defun gnus-build-all-threads ()
4293   "Read all the headers."
4294   (let ((gnus-summary-ignore-duplicates t)
4295         (mail-parse-charset gnus-newsgroup-charset)
4296         (dependencies gnus-newsgroup-dependencies)
4297         header article)
4298     (save-excursion
4299       (set-buffer nntp-server-buffer)
4300       (let ((case-fold-search nil))
4301         (goto-char (point-min))
4302         (while (not (eobp))
4303           (ignore-errors
4304             (setq article (read (current-buffer))
4305                   header (gnus-nov-parse-line article dependencies)))
4306           (when header
4307             (save-excursion
4308               (set-buffer gnus-summary-buffer)
4309               (push header gnus-newsgroup-headers)
4310               (if (memq (setq article (mail-header-number header))
4311                         gnus-newsgroup-unselected)
4312                   (progn
4313                     (setq gnus-newsgroup-unreads
4314                           (gnus-add-to-sorted-list
4315                            gnus-newsgroup-unreads article))
4316                     (setq gnus-newsgroup-unselected
4317                           (delq article gnus-newsgroup-unselected)))
4318                 (push article gnus-newsgroup-ancient)))
4319             (forward-line 1)))))))
4320
4321 (defun gnus-summary-update-article-line (article header)
4322   "Update the line for ARTICLE using HEADER."
4323   (let* ((id (mail-header-id header))
4324          (thread (gnus-id-to-thread id)))
4325     (unless thread
4326       (error "Article in no thread"))
4327     ;; Update the thread.
4328     (setcar thread header)
4329     (gnus-summary-goto-subject article)
4330     (let* ((datal (gnus-data-find-list article))
4331            (data (car datal))
4332            (buffer-read-only nil)
4333            (level (gnus-summary-thread-level)))
4334       (gnus-delete-line)
4335       (let ((inserted (- (point)
4336                          (progn
4337                            (gnus-summary-insert-line
4338                             header level nil
4339                             (memq article gnus-newsgroup-undownloaded)
4340                             (gnus-article-mark article)
4341                             (memq article gnus-newsgroup-replied)
4342                             (memq article gnus-newsgroup-expirable)
4343                             ;; Only insert the Subject string when it's different
4344                             ;; from the previous Subject string.
4345                             (if (and
4346                                  gnus-show-threads
4347                                  (gnus-subject-equal
4348                                   (condition-case ()
4349                                       (mail-header-subject
4350                                        (gnus-data-header
4351                                         (cadr
4352                                          (gnus-data-find-list
4353                                           article
4354                                           (gnus-data-list t)))))
4355                                     ;; Error on the side of excessive subjects.
4356                                     (error ""))
4357                                   (mail-header-subject header)))
4358                                 ""
4359                               (mail-header-subject header))
4360                             nil (cdr (assq article gnus-newsgroup-scored))
4361                             (memq article gnus-newsgroup-processable))
4362                            (point)))))
4363         (when (cdr datal)
4364           (gnus-data-update-list
4365            (cdr datal)
4366            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4367
4368 (defun gnus-summary-update-article (article &optional iheader)
4369   "Update ARTICLE in the summary buffer."
4370   (set-buffer gnus-summary-buffer)
4371   (let* ((header (gnus-summary-article-header article))
4372          (id (mail-header-id header))
4373          (data (gnus-data-find article))
4374          (thread (gnus-id-to-thread id))
4375          (references (mail-header-references header))
4376          (parent
4377           (gnus-id-to-thread
4378            (or (gnus-parent-id
4379                 (when (and references
4380                            (not (equal "" references)))
4381                   references))
4382                "none")))
4383          (buffer-read-only nil)
4384          (old (car thread)))
4385     (when thread
4386       (unless iheader
4387         (setcar thread nil)
4388         (when parent
4389           (delq thread parent)))
4390       (if (gnus-summary-insert-subject id header)
4391           ;; Set the (possibly) new article number in the data structure.
4392           (gnus-data-set-number data (gnus-id-to-article id))
4393         (setcar thread old)
4394         nil))))
4395
4396 (defun gnus-rebuild-thread (id &optional line)
4397   "Rebuild the thread containing ID.
4398 If LINE, insert the rebuilt thread starting on line LINE."
4399   (let ((buffer-read-only nil)
4400         old-pos current thread data)
4401     (if (not gnus-show-threads)
4402         (setq thread (list (car (gnus-id-to-thread id))))
4403       ;; Get the thread this article is part of.
4404       (setq thread (gnus-remove-thread id)))
4405     (setq old-pos (gnus-point-at-bol))
4406     (setq current (save-excursion
4407                     (and (re-search-backward "[\r\n]" nil t)
4408                          (gnus-summary-article-number))))
4409     ;; If this is a gathered thread, we have to go some re-gathering.
4410     (when (stringp (car thread))
4411       (let ((subject (car thread))
4412             roots thr)
4413         (setq thread (cdr thread))
4414         (while thread
4415           (unless (memq (setq thr (gnus-id-to-thread
4416                                    (gnus-root-id
4417                                     (mail-header-id (caar thread)))))
4418                         roots)
4419             (push thr roots))
4420           (setq thread (cdr thread)))
4421         ;; We now have all (unique) roots.
4422         (if (= (length roots) 1)
4423             ;; All the loose roots are now one solid root.
4424             (setq thread (car roots))
4425           (setq thread (cons subject (gnus-sort-threads roots))))))
4426     (let (threads)
4427       ;; We then insert this thread into the summary buffer.
4428       (when line
4429         (goto-char (point-min))
4430         (forward-line (1- line)))
4431       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4432         (if gnus-show-threads
4433             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4434           (gnus-summary-prepare-unthreaded thread))
4435         (setq data (nreverse gnus-newsgroup-data))
4436         (setq threads gnus-newsgroup-threads))
4437       ;; We splice the new data into the data structure.
4438       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4439       ;;!!! then we want to insert at the beginning of the buffer.
4440       ;;!!! That happens to be true with Gnus now, but that may
4441       ;;!!! change in the future.  Perhaps.
4442       (gnus-data-enter-list
4443        (if line nil current) data (- (point) old-pos))
4444       (setq gnus-newsgroup-threads
4445             (nconc threads gnus-newsgroup-threads))
4446       (gnus-data-compute-positions))))
4447
4448 (defun gnus-number-to-header (number)
4449   "Return the header for article NUMBER."
4450   (let ((headers gnus-newsgroup-headers))
4451     (while (and headers
4452                 (not (= number (mail-header-number (car headers)))))
4453       (pop headers))
4454     (when headers
4455       (car headers))))
4456
4457 (defun gnus-parent-headers (in-headers &optional generation)
4458   "Return the headers of the GENERATIONeth parent of HEADERS."
4459   (unless generation
4460     (setq generation 1))
4461   (let ((parent t)
4462         (headers in-headers)
4463         references)
4464     (while (and parent
4465                 (not (zerop generation))
4466                 (setq references (mail-header-references headers)))
4467       (setq headers (if (and references
4468                              (setq parent (gnus-parent-id references)))
4469                         (car (gnus-id-to-thread parent))
4470                       nil))
4471       (decf generation))
4472     (and (not (eq headers in-headers))
4473          headers)))
4474
4475 (defun gnus-id-to-thread (id)
4476   "Return the (sub-)thread where ID appears."
4477   (gnus-gethash id gnus-newsgroup-dependencies))
4478
4479 (defun gnus-id-to-article (id)
4480   "Return the article number of ID."
4481   (let ((thread (gnus-id-to-thread id)))
4482     (when (and thread
4483                (car thread))
4484       (mail-header-number (car thread)))))
4485
4486 (defun gnus-id-to-header (id)
4487   "Return the article headers of ID."
4488   (car (gnus-id-to-thread id)))
4489
4490 (defun gnus-article-displayed-root-p (article)
4491   "Say whether ARTICLE is a root(ish) article."
4492   (let ((level (gnus-summary-thread-level article))
4493         (refs (mail-header-references  (gnus-summary-article-header article)))
4494         particle)
4495     (cond
4496      ((null level) nil)
4497      ((zerop level) t)
4498      ((null refs) t)
4499      ((null (gnus-parent-id refs)) t)
4500      ((and (= 1 level)
4501            (null (setq particle (gnus-id-to-article
4502                                  (gnus-parent-id refs))))
4503            (null (gnus-summary-thread-level particle)))))))
4504
4505 (defun gnus-root-id (id)
4506   "Return the id of the root of the thread where ID appears."
4507   (let (last-id prev)
4508     (while (and id (setq prev (car (gnus-id-to-thread id))))
4509       (setq last-id id
4510             id (gnus-parent-id (mail-header-references prev))))
4511     last-id))
4512
4513 (defun gnus-articles-in-thread (thread)
4514   "Return the list of articles in THREAD."
4515   (cons (mail-header-number (car thread))
4516         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4517
4518 (defun gnus-remove-thread (id &optional dont-remove)
4519   "Remove the thread that has ID in it."
4520   (let (headers thread last-id)
4521     ;; First go up in this thread until we find the root.
4522     (setq last-id (gnus-root-id id)
4523           headers (message-flatten-list (gnus-id-to-thread last-id)))
4524     ;; We have now found the real root of this thread.  It might have
4525     ;; been gathered into some loose thread, so we have to search
4526     ;; through the threads to find the thread we wanted.
4527     (let ((threads gnus-newsgroup-threads)
4528           sub)
4529       (while threads
4530         (setq sub (car threads))
4531         (if (stringp (car sub))
4532             ;; This is a gathered thread, so we look at the roots
4533             ;; below it to find whether this article is in this
4534             ;; gathered root.
4535             (progn
4536               (setq sub (cdr sub))
4537               (while sub
4538                 (when (member (caar sub) headers)
4539                   (setq thread (car threads)
4540                         threads nil
4541                         sub nil))
4542                 (setq sub (cdr sub))))
4543           ;; It's an ordinary thread, so we check it.
4544           (when (eq (car sub) (car headers))
4545             (setq thread sub
4546                   threads nil)))
4547         (setq threads (cdr threads)))
4548       ;; If this article is in no thread, then it's a root.
4549       (if thread
4550           (unless dont-remove
4551             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4552         (setq thread (gnus-id-to-thread last-id)))
4553       (when thread
4554         (prog1
4555             thread                      ; We return this thread.
4556           (unless dont-remove
4557             (if (stringp (car thread))
4558                 (progn
4559                   ;; If we use dummy roots, then we have to remove the
4560                   ;; dummy root as well.
4561                   (when (eq gnus-summary-make-false-root 'dummy)
4562                     ;; We go to the dummy root by going to
4563                     ;; the first sub-"thread", and then one line up.
4564                     (gnus-summary-goto-article
4565                      (mail-header-number (caadr thread)))
4566                     (forward-line -1)
4567                     (gnus-delete-line)
4568                     (gnus-data-compute-positions))
4569                   (setq thread (cdr thread))
4570                   (while thread
4571                     (gnus-remove-thread-1 (car thread))
4572                     (setq thread (cdr thread))))
4573               (gnus-remove-thread-1 thread))))))))
4574
4575 (defun gnus-remove-thread-1 (thread)
4576   "Remove the thread THREAD recursively."
4577   (let ((number (mail-header-number (pop thread)))
4578         d)
4579     (setq thread (reverse thread))
4580     (while thread
4581       (gnus-remove-thread-1 (pop thread)))
4582     (when (setq d (gnus-data-find number))
4583       (goto-char (gnus-data-pos d))
4584       (gnus-summary-show-thread)
4585       (gnus-data-remove
4586        number
4587        (- (gnus-point-at-bol)
4588           (prog1
4589               (1+ (gnus-point-at-eol))
4590             (gnus-delete-line)))))))
4591
4592 (defun gnus-sort-threads-recursive (threads func)
4593   (sort (mapcar (lambda (thread)
4594                   (cons (car thread)
4595                         (and (cdr thread)
4596                              (gnus-sort-threads-recursive (cdr thread) func))))
4597                 threads) func))
4598
4599 (defun gnus-sort-threads-loop (threads func)
4600   (let* ((superthread (cons nil threads))
4601          (stack (list (cons superthread threads)))
4602          remaining-threads thread)
4603     (while stack
4604       (setq remaining-threads (cdr (car stack)))
4605       (if remaining-threads
4606           (progn (setq thread (car remaining-threads))
4607                  (setcdr (car stack) (cdr remaining-threads))
4608                  (if (cdr thread)
4609                      (push (cons thread (cdr thread)) stack)))
4610         (setq thread (caar stack))
4611         (setcdr thread (sort (cdr thread) func))
4612         (pop stack)))
4613     (cdr superthread)))
4614
4615 (defun gnus-sort-threads (threads)
4616   "Sort THREADS."
4617   (if (not gnus-thread-sort-functions)
4618       threads
4619     (gnus-message 8 "Sorting threads...")
4620     (prog1
4621         (condition-case nil
4622             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4623               (gnus-sort-threads-recursive
4624                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4625           ;; Even after binding max-lisp-eval-depth, the recursive
4626           ;; sorter might fail for very long threads.  In that case,
4627           ;; try using a (less well-tested) non-recursive sorter.
4628           (error (gnus-sort-threads-loop
4629                   threads (gnus-make-sort-function
4630                            gnus-thread-sort-functions))))
4631       (gnus-message 8 "Sorting threads...done"))))
4632
4633 (defun gnus-sort-articles (articles)
4634   "Sort ARTICLES."
4635   (when gnus-article-sort-functions
4636     (gnus-message 7 "Sorting articles...")
4637     (prog1
4638         (setq gnus-newsgroup-headers
4639               (sort articles (gnus-make-sort-function
4640                               gnus-article-sort-functions)))
4641       (gnus-message 7 "Sorting articles...done"))))
4642
4643 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4644 (defmacro gnus-thread-header (thread)
4645   "Return header of first article in THREAD.
4646 Note that THREAD must never, ever be anything else than a variable -
4647 using some other form will lead to serious barfage."
4648   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4649   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4650   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4651         (vector thread) 2))
4652
4653 (defsubst gnus-article-sort-by-number (h1 h2)
4654   "Sort articles by article number."
4655   (< (mail-header-number h1)
4656      (mail-header-number h2)))
4657
4658 (defun gnus-thread-sort-by-number (h1 h2)
4659   "Sort threads by root article number."
4660   (gnus-article-sort-by-number
4661    (gnus-thread-header h1) (gnus-thread-header h2)))
4662
4663 (defsubst gnus-article-sort-by-random (h1 h2)
4664   "Sort articles randomly."
4665   (zerop (random 2)))
4666
4667 (defun gnus-thread-sort-by-random (h1 h2)
4668   "Sort threads randomly."
4669   (gnus-article-sort-by-random
4670    (gnus-thread-header h1) (gnus-thread-header h2)))
4671
4672 (defsubst gnus-article-sort-by-lines (h1 h2)
4673   "Sort articles by article Lines header."
4674   (< (mail-header-lines h1)
4675      (mail-header-lines h2)))
4676
4677 (defun gnus-thread-sort-by-lines (h1 h2)
4678   "Sort threads by root article Lines header."
4679   (gnus-article-sort-by-lines
4680    (gnus-thread-header h1) (gnus-thread-header h2)))
4681
4682 (defsubst gnus-article-sort-by-chars (h1 h2)
4683   "Sort articles by octet length."
4684   (< (mail-header-chars h1)
4685      (mail-header-chars h2)))
4686
4687 (defun gnus-thread-sort-by-chars (h1 h2)
4688   "Sort threads by root article octet length."
4689   (gnus-article-sort-by-chars
4690    (gnus-thread-header h1) (gnus-thread-header h2)))
4691
4692 (defsubst gnus-article-sort-by-author (h1 h2)
4693   "Sort articles by root author."
4694   (gnus-string<
4695    (let ((extract (funcall
4696                    gnus-extract-address-components
4697                    (mail-header-from h1))))
4698      (or (car extract) (cadr extract) ""))
4699    (let ((extract (funcall
4700                    gnus-extract-address-components
4701                    (mail-header-from h2))))
4702      (or (car extract) (cadr extract) ""))))
4703
4704 (defun gnus-thread-sort-by-author (h1 h2)
4705   "Sort threads by root author."
4706   (gnus-article-sort-by-author
4707    (gnus-thread-header h1)  (gnus-thread-header h2)))
4708
4709 (defsubst gnus-article-sort-by-subject (h1 h2)
4710   "Sort articles by root subject."
4711   (gnus-string<
4712    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4713    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4714
4715 (defun gnus-thread-sort-by-subject (h1 h2)
4716   "Sort threads by root subject."
4717   (gnus-article-sort-by-subject
4718    (gnus-thread-header h1) (gnus-thread-header h2)))
4719
4720 (defsubst gnus-article-sort-by-date (h1 h2)
4721   "Sort articles by root article date."
4722   (time-less-p
4723    (gnus-date-get-time (mail-header-date h1))
4724    (gnus-date-get-time (mail-header-date h2))))
4725
4726 (defun gnus-thread-sort-by-date (h1 h2)
4727   "Sort threads by root article date."
4728   (gnus-article-sort-by-date
4729    (gnus-thread-header h1) (gnus-thread-header h2)))
4730
4731 (defsubst gnus-article-sort-by-score (h1 h2)
4732   "Sort articles by root article score.
4733 Unscored articles will be counted as having a score of zero."
4734   (> (or (cdr (assq (mail-header-number h1)
4735                     gnus-newsgroup-scored))
4736          gnus-summary-default-score 0)
4737      (or (cdr (assq (mail-header-number h2)
4738                     gnus-newsgroup-scored))
4739          gnus-summary-default-score 0)))
4740
4741 (defun gnus-thread-sort-by-score (h1 h2)
4742   "Sort threads by root article score."
4743   (gnus-article-sort-by-score
4744    (gnus-thread-header h1) (gnus-thread-header h2)))
4745
4746 (defun gnus-thread-sort-by-total-score (h1 h2)
4747   "Sort threads by the sum of all scores in the thread.
4748 Unscored articles will be counted as having a score of zero."
4749   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4750
4751 (defun gnus-thread-total-score (thread)
4752   ;; This function find the total score of THREAD.
4753   (cond
4754    ((null thread)
4755     0)
4756    ((consp thread)
4757     (if (stringp (car thread))
4758         (apply gnus-thread-score-function 0
4759                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4760       (gnus-thread-total-score-1 thread)))
4761    (t
4762     (gnus-thread-total-score-1 (list thread)))))
4763
4764 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4765   "Sort threads such that the thread with the most recently arrived article comes first."
4766   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4767
4768 (defun gnus-thread-highest-number (thread)
4769   "Return the highest article number in THREAD."
4770   (apply 'max (mapcar (lambda (header)
4771                         (mail-header-number header))
4772                       (message-flatten-list thread))))
4773
4774 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4775   "Sort threads such that the thread with the most recently dated article comes first."
4776   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4777
4778 (defun gnus-thread-latest-date (thread)
4779   "Return the highest article date in THREAD."
4780   (let ((previous-time 0))
4781     (apply 'max
4782            (mapcar
4783             (lambda (header)
4784               (setq previous-time
4785                     (condition-case ()
4786                         (time-to-seconds (mail-header-parse-date
4787                                           (mail-header-date header)))
4788                       (error previous-time))))
4789             (sort
4790              (message-flatten-list thread)
4791              (lambda (h1 h2)
4792                (< (mail-header-number h1)
4793                   (mail-header-number h2))))))))
4794
4795 (defun gnus-thread-total-score-1 (root)
4796   ;; This function find the total score of the thread below ROOT.
4797   (setq root (car root))
4798   (apply gnus-thread-score-function
4799          (or (append
4800               (mapcar 'gnus-thread-total-score
4801                       (cdr (gnus-id-to-thread (mail-header-id root))))
4802               (when (> (mail-header-number root) 0)
4803                 (list (or (cdr (assq (mail-header-number root)
4804                                      gnus-newsgroup-scored))
4805                           gnus-summary-default-score 0))))
4806              (list gnus-summary-default-score)
4807              '(0))))
4808
4809 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4810 (defvar gnus-tmp-prev-subject nil)
4811 (defvar gnus-tmp-false-parent nil)
4812 (defvar gnus-tmp-root-expunged nil)
4813 (defvar gnus-tmp-dummy-line nil)
4814
4815 (eval-when-compile (defvar gnus-tmp-header))
4816 (defun gnus-extra-header (type &optional header)
4817   "Return the extra header of TYPE."
4818   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4819       ""))
4820
4821 (defvar gnus-tmp-thread-tree-header-string "")
4822
4823 (defcustom gnus-sum-thread-tree-root "> "
4824   "With %B spec, used for the root of a thread.
4825 If nil, use subject instead."
4826   :version "22.1"
4827   :type '(radio (const :format "%v  " nil) string)
4828   :group 'gnus-thread)
4829 (defcustom gnus-sum-thread-tree-false-root "> "
4830   "With %B spec, used for a false root of a thread.
4831 If nil, use subject instead."
4832   :version "22.1"
4833   :type '(radio (const :format "%v  " nil) string)
4834   :group 'gnus-thread)
4835 (defcustom gnus-sum-thread-tree-single-indent ""
4836   "With %B spec, used for a thread with just one message.
4837 If nil, use subject instead."
4838   :version "22.1"
4839   :type '(radio (const :format "%v  " nil) string)
4840   :group 'gnus-thread)
4841 (defcustom gnus-sum-thread-tree-vertical "| "
4842   "With %B spec, used for drawing a vertical line."
4843   :version "22.1"
4844   :type 'string
4845   :group 'gnus-thread)
4846 (defcustom gnus-sum-thread-tree-indent "  "
4847   "With %B spec, used for indenting."
4848   :version "22.1"
4849   :type 'string
4850   :group 'gnus-thread)
4851 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4852   "With %B spec, used for a leaf with brothers."
4853   :version "22.1"
4854   :type 'string
4855   :group 'gnus-thread)
4856 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4857   "With %B spec, used for a leaf without brothers."
4858   :version "22.1"
4859   :type 'string
4860   :group 'gnus-thread)
4861
4862 (defun gnus-summary-prepare-threads (threads)
4863   "Prepare summary buffer from THREADS and indentation LEVEL.
4864 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4865 or a straight list of headers."
4866   (gnus-message 7 "Generating summary...")
4867
4868   (setq gnus-newsgroup-threads threads)
4869   (beginning-of-line)
4870
4871   (let ((gnus-tmp-level 0)
4872         (default-score (or gnus-summary-default-score 0))
4873         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4874         (building-line-count gnus-summary-display-while-building)
4875         (building-count (integerp gnus-summary-display-while-building))
4876         thread number subject stack state gnus-tmp-gathered beg-match
4877         new-roots gnus-tmp-new-adopts thread-end simp-subject
4878         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4879         gnus-tmp-replied gnus-tmp-subject-or-nil
4880         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4881         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4882         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4883         tree-stack)
4884
4885     (setq gnus-tmp-prev-subject nil
4886           gnus-tmp-thread-tree-header-string "")
4887
4888     (if (vectorp (car threads))
4889         ;; If this is a straight (sic) list of headers, then a
4890         ;; threaded summary display isn't required, so we just create
4891         ;; an unthreaded one.
4892         (gnus-summary-prepare-unthreaded threads)
4893
4894       ;; Do the threaded display.
4895
4896       (if gnus-summary-display-while-building
4897           (switch-to-buffer (buffer-name)))
4898       (while (or threads stack gnus-tmp-new-adopts new-roots)
4899
4900         (if (and (= gnus-tmp-level 0)
4901                  (or (not stack)
4902                      (= (caar stack) 0))
4903                  (not gnus-tmp-false-parent)
4904                  (or gnus-tmp-new-adopts new-roots))
4905             (if gnus-tmp-new-adopts
4906                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4907                       thread (list (car gnus-tmp-new-adopts))
4908                       gnus-tmp-header (caar thread)
4909                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4910               (when new-roots
4911                 (setq thread (list (car new-roots))
4912                       gnus-tmp-header (caar thread)
4913                       new-roots (cdr new-roots))))
4914
4915           (if threads
4916               ;; If there are some threads, we do them before the
4917               ;; threads on the stack.
4918               (setq thread threads
4919                     gnus-tmp-header (caar thread))
4920             ;; There were no current threads, so we pop something off
4921             ;; the stack.
4922             (setq state (car stack)
4923                   gnus-tmp-level (car state)
4924                   tree-stack (cadr state)
4925                   thread (caddr state)
4926                   stack (cdr stack)
4927                   gnus-tmp-header (caar thread))))
4928
4929         (setq gnus-tmp-false-parent nil)
4930         (setq gnus-tmp-root-expunged nil)
4931         (setq thread-end nil)
4932
4933         (if (stringp gnus-tmp-header)
4934             ;; The header is a dummy root.
4935             (cond
4936              ((eq gnus-summary-make-false-root 'adopt)
4937               ;; We let the first article adopt the rest.
4938               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4939                                                (cddar thread)))
4940               (setq gnus-tmp-gathered
4941                     (nconc (mapcar
4942                             (lambda (h) (mail-header-number (car h)))
4943                             (cddar thread))
4944                            gnus-tmp-gathered))
4945               (setq thread (cons (list (caar thread)
4946                                        (cadar thread))
4947                                  (cdr thread)))
4948               (setq gnus-tmp-level -1
4949                     gnus-tmp-false-parent t))
4950              ((eq gnus-summary-make-false-root 'empty)
4951               ;; We print adopted articles with empty subject fields.
4952               (setq gnus-tmp-gathered
4953                     (nconc (mapcar
4954                             (lambda (h) (mail-header-number (car h)))
4955                             (cddar thread))
4956                            gnus-tmp-gathered))
4957               (setq gnus-tmp-level -1))
4958              ((eq gnus-summary-make-false-root 'dummy)
4959               ;; We remember that we probably want to output a dummy
4960               ;; root.
4961               (setq gnus-tmp-dummy-line gnus-tmp-header)
4962               (setq gnus-tmp-prev-subject gnus-tmp-header))
4963              (t
4964               ;; We do not make a root for the gathered
4965               ;; sub-threads at all.
4966               (setq gnus-tmp-level -1)))
4967
4968           (setq number (mail-header-number gnus-tmp-header)
4969                 subject (mail-header-subject gnus-tmp-header)
4970                 simp-subject (gnus-simplify-subject-fully subject))
4971
4972           (cond
4973            ;; If the thread has changed subject, we might want to make
4974            ;; this subthread into a root.
4975            ((and (null gnus-thread-ignore-subject)
4976                  (not (zerop gnus-tmp-level))
4977                  gnus-tmp-prev-subject
4978                  (not (string= gnus-tmp-prev-subject simp-subject)))
4979             (setq new-roots (nconc new-roots (list (car thread)))
4980                   thread-end t
4981                   gnus-tmp-header nil))
4982            ;; If the article lies outside the current limit,
4983            ;; then we do not display it.
4984            ((not (memq number gnus-newsgroup-limit))
4985             (setq gnus-tmp-gathered
4986                   (nconc (mapcar
4987                           (lambda (h) (mail-header-number (car h)))
4988                           (cdar thread))
4989                          gnus-tmp-gathered))
4990             (setq gnus-tmp-new-adopts (if (cdar thread)
4991                                           (append gnus-tmp-new-adopts
4992                                                   (cdar thread))
4993                                         gnus-tmp-new-adopts)
4994                   thread-end t
4995                   gnus-tmp-header nil)
4996             (when (zerop gnus-tmp-level)
4997               (setq gnus-tmp-root-expunged t)))
4998            ;; Perhaps this article is to be marked as read?
4999            ((and gnus-summary-mark-below
5000                  (< (or (cdr (assq number gnus-newsgroup-scored))
5001                         default-score)
5002                     gnus-summary-mark-below)
5003                  ;; Don't touch sparse articles.
5004                  (not (gnus-summary-article-sparse-p number))
5005                  (not (gnus-summary-article-ancient-p number)))
5006             (setq gnus-newsgroup-unreads
5007                   (delq number gnus-newsgroup-unreads))
5008             (if gnus-newsgroup-auto-expire
5009                 (setq gnus-newsgroup-expirable
5010                       (gnus-add-to-sorted-list
5011                        gnus-newsgroup-expirable number))
5012               (push (cons number gnus-low-score-mark)
5013                     gnus-newsgroup-reads))))
5014
5015           (when gnus-tmp-header
5016             ;; We may have an old dummy line to output before this
5017             ;; article.
5018             (when (and gnus-tmp-dummy-line
5019                        (gnus-subject-equal
5020                         gnus-tmp-dummy-line
5021                         (mail-header-subject gnus-tmp-header)))
5022               (gnus-summary-insert-dummy-line
5023                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5024               (setq gnus-tmp-dummy-line nil))
5025
5026             ;; Compute the mark.
5027             (setq gnus-tmp-unread (gnus-article-mark number))
5028
5029             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5030                                   gnus-tmp-header gnus-tmp-level)
5031                   gnus-newsgroup-data)
5032
5033             ;; Actually insert the line.
5034             (setq
5035              gnus-tmp-subject-or-nil
5036              (cond
5037               ((and gnus-thread-ignore-subject
5038                     gnus-tmp-prev-subject
5039                     (not (string= gnus-tmp-prev-subject simp-subject)))
5040                subject)
5041               ((zerop gnus-tmp-level)
5042                (if (and (eq gnus-summary-make-false-root 'empty)
5043                         (memq number gnus-tmp-gathered)
5044                         gnus-tmp-prev-subject
5045                         (string= gnus-tmp-prev-subject simp-subject))
5046                    gnus-summary-same-subject
5047                  subject))
5048               (t gnus-summary-same-subject)))
5049             (if (and (eq gnus-summary-make-false-root 'adopt)
5050                      (= gnus-tmp-level 1)
5051                      (memq number gnus-tmp-gathered))
5052                 (setq gnus-tmp-opening-bracket ?\<
5053                       gnus-tmp-closing-bracket ?\>)
5054               (setq gnus-tmp-opening-bracket ?\[
5055                     gnus-tmp-closing-bracket ?\]))
5056             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5057                 (gnus-make-thread-indent-array
5058                  (max (* 2 (length gnus-thread-indent-array))
5059                       gnus-tmp-level)))
5060             (setq
5061              gnus-tmp-indentation
5062              (aref gnus-thread-indent-array gnus-tmp-level)
5063              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5064              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5065                                 gnus-summary-default-score 0)
5066              gnus-tmp-score-char
5067              (if (or (null gnus-summary-default-score)
5068                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5069                          gnus-summary-zcore-fuzz))
5070                  ?                      ;Whitespace
5071                (if (< gnus-tmp-score gnus-summary-default-score)
5072                    gnus-score-below-mark gnus-score-over-mark))
5073              gnus-tmp-replied
5074              (cond ((memq number gnus-newsgroup-processable)
5075                     gnus-process-mark)
5076                    ((memq number gnus-newsgroup-cached)
5077                     gnus-cached-mark)
5078                    ((memq number gnus-newsgroup-replied)
5079                     gnus-replied-mark)
5080                    ((memq number gnus-newsgroup-forwarded)
5081                     gnus-forwarded-mark)
5082                    ((memq number gnus-newsgroup-saved)
5083                     gnus-saved-mark)
5084                    ((memq number gnus-newsgroup-recent)
5085                     gnus-recent-mark)
5086                    ((memq number gnus-newsgroup-unseen)
5087                     gnus-unseen-mark)
5088                    (t gnus-no-mark))
5089              gnus-tmp-downloaded
5090              (cond ((memq number gnus-newsgroup-undownloaded)
5091                     gnus-undownloaded-mark)
5092                    (gnus-newsgroup-agentized
5093                     gnus-downloaded-mark)
5094                    (t
5095                     gnus-no-mark))
5096              gnus-tmp-from (mail-header-from gnus-tmp-header)
5097              gnus-tmp-name
5098              (cond
5099               ((string-match "<[^>]+> *$" gnus-tmp-from)
5100                (setq beg-match (match-beginning 0))
5101                (or (and (string-match "^\".+\"" gnus-tmp-from)
5102                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5103                    (substring gnus-tmp-from 0 beg-match)))
5104               ((string-match "(.+)" gnus-tmp-from)
5105                (substring gnus-tmp-from
5106                           (1+ (match-beginning 0)) (1- (match-end 0))))
5107               (t gnus-tmp-from))
5108
5109              ;; Do the %B string
5110              gnus-tmp-thread-tree-header-string
5111              (cond
5112               ((not gnus-show-threads) "")
5113               ((zerop gnus-tmp-level)
5114                (cond ((cdar thread)
5115                       (or gnus-sum-thread-tree-root subject))
5116                      (gnus-tmp-new-adopts
5117                       (or gnus-sum-thread-tree-false-root subject))
5118                      (t
5119                       (or gnus-sum-thread-tree-single-indent subject))))
5120               (t
5121                (concat (apply 'concat
5122                               (mapcar (lambda (item)
5123                                         (if (= item 1)
5124                                             gnus-sum-thread-tree-vertical
5125                                           gnus-sum-thread-tree-indent))
5126                                       (cdr (reverse tree-stack))))
5127                        (if (nth 1 thread)
5128                            gnus-sum-thread-tree-leaf-with-other
5129                          gnus-sum-thread-tree-single-leaf)))))
5130             (when (string= gnus-tmp-name "")
5131               (setq gnus-tmp-name gnus-tmp-from))
5132             (unless (numberp gnus-tmp-lines)
5133               (setq gnus-tmp-lines -1))
5134             (if (= gnus-tmp-lines -1)
5135                 (setq gnus-tmp-lines "?")
5136               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5137               (gnus-put-text-property
5138              (point)
5139              (progn (eval gnus-summary-line-format-spec) (point))
5140                'gnus-number number)
5141             (when gnus-visual-p
5142               (forward-line -1)
5143               (gnus-run-hooks 'gnus-summary-update-hook)
5144               (forward-line 1))
5145
5146             (setq gnus-tmp-prev-subject simp-subject)))
5147
5148         (when (nth 1 thread)
5149           (push (list (max 0 gnus-tmp-level)
5150                       (copy-sequence tree-stack)
5151                       (nthcdr 1 thread))
5152                 stack))
5153         (push (if (nth 1 thread) 1 0) tree-stack)
5154         (incf gnus-tmp-level)
5155         (setq threads (if thread-end nil (cdar thread)))
5156         (if gnus-summary-display-while-building
5157             (if building-count
5158                 (progn
5159                   ;; use a set frequency
5160                   (setq building-line-count (1- building-line-count))
5161                   (when (= building-line-count 0)
5162                     (sit-for 0)
5163                     (setq building-line-count
5164                           gnus-summary-display-while-building)))
5165               ;; always
5166               (sit-for 0)))
5167         (unless threads
5168           (setq gnus-tmp-level 0)))))
5169   (gnus-message 7 "Generating summary...done"))
5170
5171 (defun gnus-summary-prepare-unthreaded (headers)
5172   "Generate an unthreaded summary buffer based on HEADERS."
5173   (let (header number mark)
5174
5175     (beginning-of-line)
5176
5177     (while headers
5178       ;; We may have to root out some bad articles...
5179       (when (memq (setq number (mail-header-number
5180                                 (setq header (pop headers))))
5181                   gnus-newsgroup-limit)
5182         ;; Mark article as read when it has a low score.
5183         (when (and gnus-summary-mark-below
5184                    (< (or (cdr (assq number gnus-newsgroup-scored))
5185                           gnus-summary-default-score 0)
5186                       gnus-summary-mark-below)
5187                    (not (gnus-summary-article-ancient-p number)))
5188           (setq gnus-newsgroup-unreads
5189                 (delq number gnus-newsgroup-unreads))
5190           (if gnus-newsgroup-auto-expire
5191               (push number gnus-newsgroup-expirable)
5192             (push (cons number gnus-low-score-mark)
5193                   gnus-newsgroup-reads)))
5194
5195         (setq mark (gnus-article-mark number))
5196         (push (gnus-data-make number mark (1+ (point)) header 0)
5197               gnus-newsgroup-data)
5198         (gnus-summary-insert-line
5199          header 0 number
5200          (memq number gnus-newsgroup-undownloaded)
5201          mark (memq number gnus-newsgroup-replied)
5202          (memq number gnus-newsgroup-expirable)
5203          (mail-header-subject header) nil
5204          (cdr (assq number gnus-newsgroup-scored))
5205          (memq number gnus-newsgroup-processable))))))
5206
5207 (defun gnus-summary-remove-list-identifiers ()
5208   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5209   (let ((regexp (if (consp gnus-list-identifiers)
5210                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5211                   gnus-list-identifiers))
5212         changed subject)
5213     (when regexp
5214       (dolist (header gnus-newsgroup-headers)
5215         (setq subject (mail-header-subject header)
5216               changed nil)
5217         (while (string-match
5218                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
5219                 subject)
5220           (setq subject
5221                 (concat (substring subject 0 (match-beginning 2))
5222                         (substring subject (match-end 0)))
5223                 changed t))
5224         (when (and changed
5225                    (string-match
5226                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
5227           (setq subject
5228                 (concat (substring subject 0 (match-beginning 1))
5229                         (substring subject (match-end 1)))))
5230         (when changed
5231           (mail-header-set-subject header subject))))))
5232
5233 (defun gnus-fetch-headers (articles)
5234   "Fetch headers of ARTICLES."
5235   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5236     (gnus-message 5 "Fetching headers for %s..." name)
5237     (prog1
5238         (if (eq 'nov
5239                 (setq gnus-headers-retrieved-by
5240                       (gnus-retrieve-headers
5241                        articles gnus-newsgroup-name
5242                        ;; We might want to fetch old headers, but
5243                        ;; not if there is only 1 article.
5244                        (and (or (and
5245                                  (not (eq gnus-fetch-old-headers 'some))
5246                                  (not (numberp gnus-fetch-old-headers)))
5247                                 (> (length articles) 1))
5248                             gnus-fetch-old-headers))))
5249             (gnus-get-newsgroup-headers-xover
5250              articles nil nil gnus-newsgroup-name t)
5251           (gnus-get-newsgroup-headers))
5252       (gnus-message 5 "Fetching headers for %s...done" name))))
5253
5254 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5255   "Select newsgroup GROUP.
5256 If READ-ALL is non-nil, all articles in the group are selected.
5257 If SELECT-ARTICLES, only select those articles from GROUP."
5258   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5259          ;;!!! Dirty hack; should be removed.
5260          (gnus-summary-ignore-duplicates
5261           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5262               t
5263             gnus-summary-ignore-duplicates))
5264          (info (nth 2 entry))
5265          articles fetched-articles cached)
5266
5267     (unless (gnus-check-server
5268              (set (make-local-variable 'gnus-current-select-method)
5269                   (gnus-find-method-for-group group)))
5270       (error "Couldn't open server"))
5271
5272     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5273         (gnus-activate-group group)     ; Or we can activate it...
5274         (progn                          ; Or we bug out.
5275           (when (equal major-mode 'gnus-summary-mode)
5276             (gnus-kill-buffer (current-buffer)))
5277           (error "Couldn't activate group %s: %s"
5278                  (gnus-group-decoded-name group) (gnus-status-message group))))
5279
5280     (unless (gnus-request-group group t)
5281       (when (equal major-mode 'gnus-summary-mode)
5282         (gnus-kill-buffer (current-buffer)))
5283       (error "Couldn't request group %s: %s"
5284              (gnus-group-decoded-name group) (gnus-status-message group)))
5285
5286     (when gnus-agent
5287       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5288
5289       (setq gnus-summary-use-undownloaded-faces
5290             (gnus-agent-find-parameter
5291              group
5292              'agent-enable-undownloaded-faces)))
5293
5294     (setq gnus-newsgroup-name group
5295           gnus-newsgroup-unselected nil
5296           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5297
5298     (let ((display (gnus-group-find-parameter group 'display)))
5299       (setq gnus-newsgroup-display
5300             (cond
5301              ((not (zerop (or (car-safe read-all) 0)))
5302               ;; The user entered the group with C-u SPC/RET, let's show
5303               ;; all articles.
5304               'gnus-not-ignore)
5305              ((eq display 'all)
5306               'gnus-not-ignore)
5307              ((arrayp display)
5308               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5309              ((numberp display)
5310               ;; The following is probably the "correct" solution, but
5311               ;; it makes Gnus fetch all headers and then limit the
5312               ;; articles (which is slow), so instead we hack the
5313               ;; select-articles parameter instead. -- Simon Josefsson
5314               ;; <jas@kth.se>
5315               ;;
5316               ;; (gnus-byte-compile
5317               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5318               ;;                         display)))))
5319               (setq select-articles
5320                     (gnus-uncompress-range
5321                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5322                              (if (> tmp 0)
5323                                  tmp
5324                                1))
5325                            (cdr (gnus-active group)))))
5326               nil)
5327              (t
5328               nil))))
5329
5330     (gnus-summary-setup-default-charset)
5331
5332     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5333     (when (gnus-virtual-group-p group)
5334       (setq cached gnus-newsgroup-cached))
5335
5336     (setq gnus-newsgroup-unreads
5337           (gnus-sorted-ndifference
5338            (gnus-sorted-ndifference gnus-newsgroup-unreads
5339                                     gnus-newsgroup-marked)
5340            gnus-newsgroup-dormant))
5341
5342     (setq gnus-newsgroup-processable nil)
5343
5344     (gnus-update-read-articles group gnus-newsgroup-unreads)
5345
5346     ;; Adjust and set lists of article marks.
5347     (when info
5348       (gnus-adjust-marked-articles info))
5349     (if (setq articles select-articles)
5350         (setq gnus-newsgroup-unselected
5351               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5352       (setq articles (gnus-articles-to-read group read-all)))
5353
5354     (cond
5355      ((null articles)
5356       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5357       'quit)
5358      ((eq articles 0) nil)
5359      (t
5360       ;; Init the dependencies hash table.
5361       (setq gnus-newsgroup-dependencies
5362             (gnus-make-hashtable (length articles)))
5363       (gnus-set-global-variables)
5364       ;; Retrieve the headers and read them in.
5365
5366       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5367
5368       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5369       (when cached
5370         (setq gnus-newsgroup-cached cached))
5371
5372       ;; Suppress duplicates?
5373       (when gnus-suppress-duplicates
5374         (gnus-dup-suppress-articles))
5375
5376       ;; Set the initial limit.
5377       (setq gnus-newsgroup-limit (copy-sequence articles))
5378       ;; Remove canceled articles from the list of unread articles.
5379       (setq fetched-articles
5380             (mapcar (lambda (headers) (mail-header-number headers))
5381                     gnus-newsgroup-headers))
5382       (setq gnus-newsgroup-articles fetched-articles)
5383       (setq gnus-newsgroup-unreads
5384             (gnus-sorted-nintersection
5385              gnus-newsgroup-unreads fetched-articles))
5386       (gnus-compute-unseen-list)
5387
5388       ;; Removed marked articles that do not exist.
5389       (gnus-update-missing-marks
5390        (gnus-sorted-difference articles fetched-articles))
5391       ;; We might want to build some more threads first.
5392       (when (and gnus-fetch-old-headers
5393                  (eq gnus-headers-retrieved-by 'nov))
5394         (if (eq gnus-fetch-old-headers 'invisible)
5395             (gnus-build-all-threads)
5396           (gnus-build-old-threads)))
5397       ;; Let the Gnus agent mark articles as read.
5398       (when gnus-agent
5399         (gnus-agent-get-undownloaded-list))
5400       ;; Remove list identifiers from subject
5401       (when gnus-list-identifiers
5402         (gnus-summary-remove-list-identifiers))
5403       ;; Check whether auto-expire is to be done in this group.
5404       (setq gnus-newsgroup-auto-expire
5405             (gnus-group-auto-expirable-p group))
5406       ;; Set up the article buffer now, if necessary.
5407       (unless gnus-single-article-buffer
5408         (gnus-article-setup-buffer))
5409       ;; First and last article in this newsgroup.
5410       (when gnus-newsgroup-headers
5411         (setq gnus-newsgroup-begin
5412               (mail-header-number (car gnus-newsgroup-headers))
5413               gnus-newsgroup-end
5414               (mail-header-number
5415                (gnus-last-element gnus-newsgroup-headers))))
5416       ;; GROUP is successfully selected.
5417       (or gnus-newsgroup-headers t)))))
5418
5419 (defun gnus-compute-unseen-list ()
5420   ;; The `seen' marks are treated specially.
5421   (if (not gnus-newsgroup-seen)
5422       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5423     (setq gnus-newsgroup-unseen
5424           (gnus-inverse-list-range-intersection
5425            gnus-newsgroup-articles gnus-newsgroup-seen))))
5426
5427 (defun gnus-summary-display-make-predicate (display)
5428   (require 'gnus-agent)
5429   (when (= (length display) 1)
5430     (setq display (car display)))
5431   (unless gnus-summary-display-cache
5432     (dolist (elem (append '((unread . unread)
5433                             (read . read)
5434                             (unseen . unseen))
5435                           gnus-article-mark-lists))
5436       (push (cons (cdr elem)
5437                   (gnus-byte-compile
5438                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5439             gnus-summary-display-cache)))
5440   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5441         (gnus-category-predicate-cache gnus-summary-display-cache))
5442     (gnus-get-predicate display)))
5443
5444 ;; Uses the dynamically bound `number' variable.
5445 (eval-when-compile
5446   (defvar number))
5447 (defun gnus-article-marked-p (type &optional article)
5448   (let ((article (or article number)))
5449     (cond
5450      ((eq type 'tick)
5451       (memq article gnus-newsgroup-marked))
5452      ((eq type 'spam)
5453       (memq article gnus-newsgroup-spam-marked))
5454      ((eq type 'unsend)
5455       (memq article gnus-newsgroup-unsendable))
5456      ((eq type 'undownload)
5457       (memq article gnus-newsgroup-undownloaded))
5458      ((eq type 'download)
5459       (memq article gnus-newsgroup-downloadable))
5460      ((eq type 'unread)
5461       (memq article gnus-newsgroup-unreads))
5462      ((eq type 'read)
5463       (memq article gnus-newsgroup-reads))
5464      ((eq type 'dormant)
5465       (memq article gnus-newsgroup-dormant) )
5466      ((eq type 'expire)
5467       (memq article gnus-newsgroup-expirable))
5468      ((eq type 'reply)
5469       (memq article gnus-newsgroup-replied))
5470      ((eq type 'killed)
5471       (memq article gnus-newsgroup-killed))
5472      ((eq type 'bookmark)
5473       (assq article gnus-newsgroup-bookmarks))
5474      ((eq type 'score)
5475       (assq article gnus-newsgroup-scored))
5476      ((eq type 'save)
5477       (memq article gnus-newsgroup-saved))
5478      ((eq type 'cache)
5479       (memq article gnus-newsgroup-cached))
5480      ((eq type 'forward)
5481       (memq article gnus-newsgroup-forwarded))
5482      ((eq type 'seen)
5483       (not (memq article gnus-newsgroup-unseen)))
5484      ((eq type 'recent)
5485       (memq article gnus-newsgroup-recent))
5486      (t t))))
5487
5488 (defun gnus-articles-to-read (group &optional read-all)
5489   "Find out what articles the user wants to read."
5490   (let* ((articles
5491           ;; Select all articles if `read-all' is non-nil, or if there
5492           ;; are no unread articles.
5493           (if (or read-all
5494                   (and (zerop (length gnus-newsgroup-marked))
5495                        (zerop (length gnus-newsgroup-unreads)))
5496                   ;; Fetch all if the predicate is non-nil.
5497                   gnus-newsgroup-display)
5498               ;; We want to select the headers for all the articles in
5499               ;; the group, so we select either all the active
5500               ;; articles in the group, or (if that's nil), the
5501               ;; articles in the cache.
5502               (or
5503                (if gnus-newsgroup-maximum-articles
5504                    (let ((active (gnus-active group)))
5505                      (gnus-uncompress-range
5506                       (cons (max (car active)
5507                                  (- (cdr active)
5508                                     gnus-newsgroup-maximum-articles
5509                                     -1))
5510                             (cdr active))))
5511                  (gnus-uncompress-range (gnus-active group)))
5512                (gnus-cache-articles-in-group group))
5513             ;; Select only the "normal" subset of articles.
5514             (gnus-sorted-nunion
5515              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5516              gnus-newsgroup-unreads)))
5517          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5518          (scored (length scored-list))
5519          (number (length articles))
5520          (marked (+ (length gnus-newsgroup-marked)
5521                     (length gnus-newsgroup-dormant)))
5522          (select
5523           (cond
5524            ((numberp read-all)
5525             read-all)
5526            ((numberp gnus-newsgroup-display)
5527             gnus-newsgroup-display)
5528            (t
5529             (condition-case ()
5530                 (cond
5531                  ((and (or (<= scored marked) (= scored number))
5532                        (numberp gnus-large-newsgroup)
5533                        (> number gnus-large-newsgroup))
5534                   (let* ((cursor-in-echo-area nil)
5535                          (initial (gnus-parameter-large-newsgroup-initial
5536                                    gnus-newsgroup-name))
5537                          (input
5538                           (read-string
5539                            (format
5540                             "How many articles from %s (%s %d): "
5541                             (gnus-limit-string
5542                              (gnus-group-decoded-name gnus-newsgroup-name)
5543                              35)
5544                             (if initial "max" "default")
5545                             number)
5546                            (if initial
5547                                (cons (number-to-string initial)
5548                                      0)))))
5549                     (if (string-match "^[ \t]*$" input) number input)))
5550                  ((and (> scored marked) (< scored number)
5551                        (> (- scored number) 20))
5552                   (let ((input
5553                          (read-string
5554                           (format "%s %s (%d scored, %d total): "
5555                                   "How many articles from"
5556                                   (gnus-group-decoded-name group)
5557                                   scored number))))
5558                     (if (string-match "^[ \t]*$" input)
5559                         number input)))
5560                  (t number))
5561               (quit
5562                (message "Quit getting the articles to read")
5563                nil))))))
5564     (setq select (if (stringp select) (string-to-number select) select))
5565     (if (or (null select) (zerop select))
5566         select
5567       (if (and (not (zerop scored)) (<= (abs select) scored))
5568           (progn
5569             (setq articles (sort scored-list '<))
5570             (setq number (length articles)))
5571         (setq articles (copy-sequence articles)))
5572
5573       (when (< (abs select) number)
5574         (if (< select 0)
5575             ;; Select the N oldest articles.
5576             (setcdr (nthcdr (1- (abs select)) articles) nil)
5577           ;; Select the N most recent articles.
5578           (setq articles (nthcdr (- number select) articles))))
5579       (setq gnus-newsgroup-unselected
5580             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5581       (when gnus-alter-articles-to-read-function
5582         (setq articles
5583               (sort
5584                (funcall gnus-alter-articles-to-read-function
5585                         gnus-newsgroup-name articles)
5586                '<)))
5587       articles)))
5588
5589 (defun gnus-killed-articles (killed articles)
5590   (let (out)
5591     (while articles
5592       (when (inline (gnus-member-of-range (car articles) killed))
5593         (push (car articles) out))
5594       (setq articles (cdr articles)))
5595     out))
5596
5597 (defun gnus-uncompress-marks (marks)
5598   "Uncompress the mark ranges in MARKS."
5599   (let ((uncompressed '(score bookmark))
5600         out)
5601     (while marks
5602       (if (memq (caar marks) uncompressed)
5603           (push (car marks) out)
5604         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5605       (setq marks (cdr marks)))
5606     out))
5607
5608 (defun gnus-article-mark-to-type (mark)
5609   "Return the type of MARK."
5610   (or (cadr (assq mark gnus-article-special-mark-lists))
5611       'list))
5612
5613 (defun gnus-article-unpropagatable-p (mark)
5614   "Return whether MARK should be propagated to back end."
5615   (memq mark gnus-article-unpropagated-mark-lists))
5616
5617 (defun gnus-adjust-marked-articles (info)
5618   "Set all article lists and remove all marks that are no longer valid."
5619   (let* ((marked-lists (gnus-info-marks info))
5620          (active (gnus-active (gnus-info-group info)))
5621          (min (car active))
5622          (max (cdr active))
5623          (types gnus-article-mark-lists)
5624          marks var articles article mark mark-type
5625          bgn end)
5626
5627     (dolist (marks marked-lists)
5628       (setq mark (car marks)
5629             mark-type (gnus-article-mark-to-type mark)
5630             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5631
5632       ;; We set the variable according to the type of the marks list,
5633       ;; and then adjust the marks to a subset of the active articles.
5634       (cond
5635        ;; Adjust "simple" lists - compressed yet unsorted
5636        ((eq mark-type 'list)
5637         ;; Simultaneously uncompress and clip to active range
5638         ;; See gnus-uncompress-range for a description of possible marks
5639         (let (l lh)
5640           (if (not (cadr marks))
5641               (set var nil)
5642             (setq articles (if (numberp (cddr marks))
5643                                (list (cdr marks))
5644                              (cdr marks))
5645                   lh (cons nil nil)
5646                   l lh)
5647
5648             (while (setq article (pop articles))
5649               (cond ((consp article)
5650                      (setq bgn (max (car article) min)
5651                            end (min (cdr article) max))
5652                      (while (<= bgn end)
5653                        (setq l (setcdr l (cons bgn nil))
5654                              bgn (1+ bgn))))
5655                     ((and (<= min article)
5656                           (>= max article))
5657                      (setq l (setcdr l (cons article nil))))))
5658             (set var (cdr lh)))))
5659        ;; Adjust assocs.
5660        ((eq mark-type 'tuple)
5661         (set var (setq articles (cdr marks)))
5662         (when (not (listp (cdr (symbol-value var))))
5663           (set var (list (symbol-value var))))
5664         (when (not (listp (cdr articles)))
5665           (setq articles (list articles)))
5666         (while articles
5667           (when (or (not (consp (setq article (pop articles))))
5668                     (< (car article) min)
5669                     (> (car article) max))
5670             (set var (delq article (symbol-value var))))))
5671        ;; Adjust ranges (sloppily).
5672        ((eq mark-type 'range)
5673         (cond
5674          ((eq mark 'seen)
5675           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5676           ;; It should be (seen (NUM1 . NUM2)).
5677           (when (numberp (cddr marks))
5678             (setcdr marks (list (cdr marks))))
5679           (setq articles (cdr marks))
5680           (while (and articles
5681                       (or (and (consp (car articles))
5682                                (> min (cdar articles)))
5683                           (and (numberp (car articles))
5684                                (> min (car articles)))))
5685             (pop articles))
5686           (set var articles))))))))
5687
5688 (defun gnus-update-missing-marks (missing)
5689   "Go through the list of MISSING articles and remove them from the mark lists."
5690   (when missing
5691     (let (var m)
5692       ;; Go through all types.
5693       (dolist (elem gnus-article-mark-lists)
5694         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5695           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5696           (when (symbol-value var)
5697             ;; This list has articles.  So we delete all missing
5698             ;; articles from it.
5699             (setq m missing)
5700             (while m
5701               (set var (delq (pop m) (symbol-value var))))))))))
5702
5703 (defun gnus-update-marks ()
5704   "Enter the various lists of marked articles into the newsgroup info list."
5705   (let ((types gnus-article-mark-lists)
5706         (info (gnus-get-info gnus-newsgroup-name))
5707         type list newmarked symbol delta-marks)
5708     (when info
5709       ;; Add all marks lists to the list of marks lists.
5710       (while (setq type (pop types))
5711         (setq list (symbol-value
5712                     (setq symbol
5713                           (intern (format "gnus-newsgroup-%s" (car type))))))
5714
5715         (when list
5716           ;; Get rid of the entries of the articles that have the
5717           ;; default score.
5718           (when (and (eq (cdr type) 'score)
5719                      gnus-save-score
5720                      list)
5721             (let* ((arts list)
5722                    (prev (cons nil list))
5723                    (all prev))
5724               (while arts
5725                 (if (or (not (consp (car arts)))
5726                         (= (cdar arts) gnus-summary-default-score))
5727                     (setcdr prev (cdr arts))
5728                   (setq prev arts))
5729                 (setq arts (cdr arts)))
5730               (setq list (cdr all)))))
5731
5732         (when (eq (cdr type) 'seen)
5733           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5734
5735         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5736           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5737
5738         (when (and (gnus-check-backend-function
5739                     'request-set-mark gnus-newsgroup-name)
5740                    (not (gnus-article-unpropagatable-p (cdr type))))
5741           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5742                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5743                  (add (gnus-remove-from-range
5744                        (gnus-copy-sequence list) old)))
5745             (when add
5746               (push (list add 'add (list (cdr type))) delta-marks))
5747             (when del
5748               (push (list del 'del (list (cdr type))) delta-marks))))
5749
5750         (when list
5751           (push (cons (cdr type) list) newmarked)))
5752
5753       (when delta-marks
5754         (unless (gnus-check-group gnus-newsgroup-name)
5755           (error "Can't open server for %s" gnus-newsgroup-name))
5756         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5757
5758       ;; Enter these new marks into the info of the group.
5759       (if (nthcdr 3 info)
5760           (setcar (nthcdr 3 info) newmarked)
5761         ;; Add the marks lists to the end of the info.
5762         (when newmarked
5763           (setcdr (nthcdr 2 info) (list newmarked))))
5764
5765       ;; Cut off the end of the info if there's nothing else there.
5766       (let ((i 5))
5767         (while (and (> i 2)
5768                     (not (nth i info)))
5769           (when (nthcdr (decf i) info)
5770             (setcdr (nthcdr i info) nil)))))))
5771
5772 (defun gnus-set-mode-line (where)
5773   "Set the mode line of the article or summary buffers.
5774 If WHERE is `summary', the summary mode line format will be used."
5775   ;; Is this mode line one we keep updated?
5776   (when (and (memq where gnus-updated-mode-lines)
5777              (symbol-value
5778               (intern (format "gnus-%s-mode-line-format-spec" where))))
5779     (let (mode-string)
5780       (save-excursion
5781         ;; We evaluate this in the summary buffer since these
5782         ;; variables are buffer-local to that buffer.
5783         (set-buffer gnus-summary-buffer)
5784        ;; We bind all these variables that are used in the `eval' form
5785         ;; below.
5786         (let* ((mformat (symbol-value
5787                          (intern
5788                           (format "gnus-%s-mode-line-format-spec" where))))
5789                (gnus-tmp-group-name (gnus-mode-string-quote
5790                                      (gnus-group-decoded-name
5791                                       gnus-newsgroup-name)))
5792                (gnus-tmp-article-number (or gnus-current-article 0))
5793                (gnus-tmp-unread gnus-newsgroup-unreads)
5794                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5795                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5796                (gnus-tmp-unread-and-unselected
5797                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5798                             (zerop gnus-tmp-unselected))
5799                        "")
5800                       ((zerop gnus-tmp-unselected)
5801                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5802                       (t (format "{%d(+%d) more}"
5803                                  gnus-tmp-unread-and-unticked
5804                                  gnus-tmp-unselected))))
5805                (gnus-tmp-subject
5806                 (if (and gnus-current-headers
5807                          (vectorp gnus-current-headers))
5808                     (gnus-mode-string-quote
5809                      (mail-header-subject gnus-current-headers))
5810                   ""))
5811                bufname-length max-len
5812                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5813           (setq mode-string (eval mformat))
5814           (setq bufname-length (if (string-match "%b" mode-string)
5815                                    (- (length
5816                                        (buffer-name
5817                                         (if (eq where 'summary)
5818                                             nil
5819                                           (get-buffer gnus-article-buffer))))
5820                                       2)
5821                                  0))
5822           (setq max-len (max 4 (if gnus-mode-non-string-length
5823                                    (- (window-width)
5824                                       gnus-mode-non-string-length
5825                                       bufname-length)
5826                                  (length mode-string))))
5827           ;; We might have to chop a bit of the string off...
5828           (when (> (length mode-string) max-len)
5829             (setq mode-string
5830                   (concat (truncate-string-to-width mode-string (- max-len 3))
5831                           "...")))
5832           ;; Pad the mode string a bit.
5833           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5834       ;; Update the mode line.
5835       (setq mode-line-buffer-identification
5836             (gnus-mode-line-buffer-identification (list mode-string)))
5837       (set-buffer-modified-p t))))
5838
5839 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5840   "Go through the HEADERS list and add all Xrefs to a hash table.
5841 The resulting hash table is returned, or nil if no Xrefs were found."
5842   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5843          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5844          (xref-hashtb (gnus-make-hashtable))
5845          start group entry number xrefs header)
5846     (while headers
5847       (setq header (pop headers))
5848       (when (and (setq xrefs (mail-header-xref header))
5849                  (not (memq (setq number (mail-header-number header))
5850                             unreads)))
5851         (setq start 0)
5852         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5853           (setq start (match-end 0))
5854           (setq group (if prefix
5855                           (concat prefix (substring xrefs (match-beginning 1)
5856                                                     (match-end 1)))
5857                         (substring xrefs (match-beginning 1) (match-end 1))))
5858           (setq number
5859                 (string-to-number (substring xrefs (match-beginning 2)
5860                                           (match-end 2))))
5861           (if (setq entry (gnus-gethash group xref-hashtb))
5862               (setcdr entry (cons number (cdr entry)))
5863             (gnus-sethash group (cons number nil) xref-hashtb)))))
5864     (and start xref-hashtb)))
5865
5866 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5867   "Look through all the headers and mark the Xrefs as read."
5868   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5869         name entry info xref-hashtb idlist method nth4)
5870     (save-excursion
5871       (set-buffer gnus-group-buffer)
5872       (when (setq xref-hashtb
5873                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5874         (mapatoms
5875          (lambda (group)
5876            (unless (string= from-newsgroup (setq name (symbol-name group)))
5877              (setq idlist (symbol-value group))
5878              ;; Dead groups are not updated.
5879              (and (prog1
5880                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5881                             info (nth 2 entry))
5882                     (when (stringp (setq nth4 (gnus-info-method info)))
5883                       (setq nth4 (gnus-server-to-method nth4))))
5884                   ;; Only do the xrefs if the group has the same
5885                   ;; select method as the group we have just read.
5886                   (or (gnus-methods-equal-p
5887                        nth4 (gnus-find-method-for-group from-newsgroup))
5888                       virtual
5889                       (equal nth4 (setq method (gnus-find-method-for-group
5890                                                 from-newsgroup)))
5891                       (and (equal (car nth4) (car method))
5892                            (equal (nth 1 nth4) (nth 1 method))))
5893                   gnus-use-cross-reference
5894                   (or (not (eq gnus-use-cross-reference t))
5895                       virtual
5896                       ;; Only do cross-references on subscribed
5897                       ;; groups, if that is what is wanted.
5898                       (<= (gnus-info-level info) gnus-level-subscribed))
5899                   (gnus-group-make-articles-read name idlist))))
5900          xref-hashtb)))))
5901
5902 (defun gnus-compute-read-articles (group articles)
5903   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5904          (info (nth 2 entry))
5905          (active (gnus-active group))
5906          ninfo)
5907     (when entry
5908       ;; First peel off all invalid article numbers.
5909       (when active
5910         (let ((ids articles)
5911               id first)
5912           (while (setq id (pop ids))
5913             (when (and first (> id (cdr active)))
5914               ;; We'll end up in this situation in one particular
5915               ;; obscure situation.  If you re-scan a group and get
5916               ;; a new article that is cross-posted to a different
5917               ;; group that has not been re-scanned, you might get
5918               ;; crossposted article that has a higher number than
5919               ;; Gnus believes possible.  So we re-activate this
5920               ;; group as well.  This might mean doing the
5921               ;; crossposting thingy will *increase* the number
5922               ;; of articles in some groups.  Tsk, tsk.
5923               (setq active (or (gnus-activate-group group) active)))
5924             (when (or (> id (cdr active))
5925                       (< id (car active)))
5926               (setq articles (delq id articles))))))
5927       ;; If the read list is nil, we init it.
5928       (if (and active
5929                (null (gnus-info-read info))
5930                (> (car active) 1))
5931           (setq ninfo (cons 1 (1- (car active))))
5932         (setq ninfo (gnus-info-read info)))
5933       ;; Then we add the read articles to the range.
5934       (gnus-add-to-range
5935        ninfo (setq articles (sort articles '<))))))
5936
5937 (defun gnus-group-make-articles-read (group articles)
5938   "Update the info of GROUP to say that ARTICLES are read."
5939   (let* ((num 0)
5940          (entry (gnus-gethash group gnus-newsrc-hashtb))
5941          (info (nth 2 entry))
5942          (active (gnus-active group))
5943          range)
5944     (when entry
5945       (setq range (gnus-compute-read-articles group articles))
5946       (save-excursion
5947         (set-buffer gnus-group-buffer)
5948         (gnus-undo-register
5949           `(progn
5950              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5951              (gnus-info-set-read ',info ',(gnus-info-read info))
5952              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5953              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5954              (gnus-group-update-group ,group t))))
5955       ;; Add the read articles to the range.
5956       (gnus-info-set-read info range)
5957       (gnus-request-set-mark group (list (list range 'add '(read))))
5958       ;; Then we have to re-compute how many unread
5959       ;; articles there are in this group.
5960       (when active
5961         (cond
5962          ((not range)
5963           (setq num (- (1+ (cdr active)) (car active))))
5964          ((not (listp (cdr range)))
5965           (setq num (- (cdr active) (- (1+ (cdr range))
5966                                        (car range)))))
5967          (t
5968           (while range
5969             (if (numberp (car range))
5970                 (setq num (1+ num))
5971               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5972             (setq range (cdr range)))
5973           (setq num (- (cdr active) num))))
5974         ;; Update the number of unread articles.
5975         (setcar entry num)
5976         ;; Update the group buffer.
5977         (unless (gnus-ephemeral-group-p group)
5978           (gnus-group-update-group group t))))))
5979
5980 (defvar gnus-newsgroup-none-id 0)
5981
5982 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5983   (let ((cur nntp-server-buffer)
5984         (dependencies
5985          (or dependencies
5986              (save-excursion (set-buffer gnus-summary-buffer)
5987                              gnus-newsgroup-dependencies)))
5988         headers id end ref
5989         (mail-parse-charset gnus-newsgroup-charset)
5990         (mail-parse-ignored-charsets
5991          (save-excursion (condition-case nil
5992                              (set-buffer gnus-summary-buffer)
5993                            (error))
5994                          gnus-newsgroup-ignored-charsets)))
5995     (save-excursion
5996       (set-buffer nntp-server-buffer)
5997       ;; Translate all TAB characters into SPACE characters.
5998       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5999       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6000       (ietf-drums-unfold-fws)
6001       (gnus-run-hooks 'gnus-parse-headers-hook)
6002       (let ((case-fold-search t)
6003             in-reply-to header p lines chars)
6004         (goto-char (point-min))
6005         ;; Search to the beginning of the next header.  Error messages
6006         ;; do not begin with 2 or 3.
6007         (while (re-search-forward "^[23][0-9]+ " nil t)
6008           (setq id nil
6009                 ref nil)
6010           ;; This implementation of this function, with nine
6011           ;; search-forwards instead of the one re-search-forward and
6012           ;; a case (which basically was the old function) is actually
6013           ;; about twice as fast, even though it looks messier.  You
6014           ;; can't have everything, I guess.  Speed and elegance
6015           ;; doesn't always go hand in hand.
6016           (setq
6017            header
6018            (vector
6019             ;; Number.
6020             (prog1
6021                 (read cur)
6022               (end-of-line)
6023               (setq p (point))
6024               (narrow-to-region (point)
6025                                 (or (and (search-forward "\n.\n" nil t)
6026                                          (- (point) 2))
6027                                     (point))))
6028             ;; Subject.
6029             (progn
6030               (goto-char p)
6031               (if (search-forward "\nsubject:" nil t)
6032                   (funcall gnus-decode-encoded-word-function
6033                            (nnheader-header-value))
6034                 "(none)"))
6035             ;; From.
6036             (progn
6037               (goto-char p)
6038               (if (search-forward "\nfrom:" nil t)
6039                   (funcall gnus-decode-encoded-address-function
6040                            (nnheader-header-value))
6041                 "(nobody)"))
6042             ;; Date.
6043             (progn
6044               (goto-char p)
6045               (if (search-forward "\ndate:" nil t)
6046                   (nnheader-header-value) ""))
6047             ;; Message-ID.
6048             (progn
6049               (goto-char p)
6050               (setq id (if (re-search-forward
6051                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6052                            ;; We do it this way to make sure the Message-ID
6053                            ;; is (somewhat) syntactically valid.
6054                            (buffer-substring (match-beginning 1)
6055                                              (match-end 1))
6056                          ;; If there was no message-id, we just fake one
6057                          ;; to make subsequent routines simpler.
6058                          (nnheader-generate-fake-message-id))))
6059             ;; References.
6060             (progn
6061               (goto-char p)
6062               (if (search-forward "\nreferences:" nil t)
6063                   (progn
6064                     (setq end (point))
6065                     (prog1
6066                         (nnheader-header-value)
6067                       (setq ref
6068                             (buffer-substring
6069                              (progn
6070                                (end-of-line)
6071                                (search-backward ">" end t)
6072                                (1+ (point)))
6073                              (progn
6074                                (search-backward "<" end t)
6075                                (point))))))
6076                 ;; Get the references from the in-reply-to header if there
6077                 ;; were no references and the in-reply-to header looks
6078                 ;; promising.
6079                 (if (and (search-forward "\nin-reply-to:" nil t)
6080                          (setq in-reply-to (nnheader-header-value))
6081                          (string-match "<[^>]+>" in-reply-to))
6082                     (let (ref2)
6083                       (setq ref (substring in-reply-to (match-beginning 0)
6084                                            (match-end 0)))
6085                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6086                         (setq ref2 (substring in-reply-to (match-beginning 0)
6087                                               (match-end 0)))
6088                         (when (> (length ref2) (length ref))
6089                           (setq ref ref2)))
6090                       ref)
6091                   (setq ref nil))))
6092             ;; Chars.
6093             (progn
6094               (goto-char p)
6095               (if (search-forward "\nchars: " nil t)
6096                   (if (numberp (setq chars (ignore-errors (read cur))))
6097                       chars -1)
6098                 -1))
6099             ;; Lines.
6100             (progn
6101               (goto-char p)
6102               (if (search-forward "\nlines: " nil t)
6103                   (if (numberp (setq lines (ignore-errors (read cur))))
6104                       lines -1)
6105                 -1))
6106             ;; Xref.
6107             (progn
6108               (goto-char p)
6109               (and (search-forward "\nxref:" nil t)
6110                    (nnheader-header-value)))
6111             ;; Extra.
6112             (when gnus-extra-headers
6113               (let ((extra gnus-extra-headers)
6114                     out)
6115                 (while extra
6116                   (goto-char p)
6117                   (when (search-forward
6118                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6119                     (push (cons (car extra) (nnheader-header-value))
6120                           out))
6121                   (pop extra))
6122                 out))))
6123           (when (equal id ref)
6124             (setq ref nil))
6125
6126           (when gnus-alter-header-function
6127             (funcall gnus-alter-header-function header)
6128             (setq id (mail-header-id header)
6129                   ref (gnus-parent-id (mail-header-references header))))
6130
6131           (when (setq header
6132                       (gnus-dependencies-add-header
6133                        header dependencies force-new))
6134             (push header headers))
6135           (goto-char (point-max))
6136           (widen))
6137         (nreverse headers)))))
6138
6139 ;; Goes through the xover lines and returns a list of vectors
6140 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6141                                                   force-new dependencies
6142                                                   group also-fetch-heads)
6143   "Parse the news overview data in the server buffer.
6144 Return a list of headers that match SEQUENCE (see
6145 `nntp-retrieve-headers')."
6146   ;; Get the Xref when the users reads the articles since most/some
6147   ;; NNTP servers do not include Xrefs when using XOVER.
6148   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6149   (let ((mail-parse-charset gnus-newsgroup-charset)
6150         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6151         (cur nntp-server-buffer)
6152         (dependencies (or dependencies gnus-newsgroup-dependencies))
6153         (allp (cond
6154                ((eq gnus-read-all-available-headers t)
6155                 t)
6156                ((and (stringp gnus-read-all-available-headers)
6157                      group)
6158                 (string-match gnus-read-all-available-headers group))
6159                (t
6160                 nil)))
6161         number headers header)
6162     (save-excursion
6163       (set-buffer nntp-server-buffer)
6164       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6165       ;; Allow the user to mangle the headers before parsing them.
6166       (gnus-run-hooks 'gnus-parse-headers-hook)
6167       (goto-char (point-min))
6168       (gnus-parse-without-error
6169         (while (and (or sequence allp)
6170                     (not (eobp)))
6171           (setq number (read cur))
6172           (when (not allp)
6173             (while (and sequence
6174                         (< (car sequence) number))
6175               (setq sequence (cdr sequence))))
6176           (when (and (or allp
6177                          (and sequence
6178                               (eq number (car sequence))))
6179                      (progn
6180                        (setq sequence (cdr sequence))
6181                        (setq header (inline
6182                                       (gnus-nov-parse-line
6183                                        number dependencies force-new)))))
6184             (push header headers))
6185           (forward-line 1)))
6186       ;; A common bug in inn is that if you have posted an article and
6187       ;; then retrieves the active file, it will answer correctly --
6188       ;; the new article is included.  However, a NOV entry for the
6189       ;; article may not have been generated yet, so this may fail.
6190       ;; We work around this problem by retrieving the last few
6191       ;; headers using HEAD.
6192       (if (or (not also-fetch-heads)
6193               (not sequence))
6194           ;; We (probably) got all the headers.
6195           (nreverse headers)
6196         (let ((gnus-nov-is-evil t))
6197           (nconc
6198            (nreverse headers)
6199            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6200              (gnus-get-newsgroup-headers))))))))
6201
6202 (defun gnus-article-get-xrefs ()
6203   "Fill in the Xref value in `gnus-current-headers', if necessary.
6204 This is meant to be called in `gnus-article-internal-prepare-hook'."
6205   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
6206                                  gnus-current-headers)))
6207     (or (not gnus-use-cross-reference)
6208         (not headers)
6209         (and (mail-header-xref headers)
6210              (not (string= (mail-header-xref headers) "")))
6211         (let ((case-fold-search t)
6212               xref)
6213           (save-restriction
6214             (nnheader-narrow-to-headers)
6215             (goto-char (point-min))
6216             (when (or (and (not (eobp))
6217                            (eq (downcase (char-after)) ?x)
6218                            (looking-at "Xref:"))
6219                       (search-forward "\nXref:" nil t))
6220               (goto-char (1+ (match-end 0)))
6221               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
6222               (mail-header-set-xref headers xref)))))))
6223
6224 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6225   "Find article ID and insert the summary line for that article.
6226 OLD-HEADER can either be a header or a line number to insert
6227 the subject line on."
6228   (let* ((line (and (numberp old-header) old-header))
6229          (old-header (and (vectorp old-header) old-header))
6230          (header (cond ((and old-header use-old-header)
6231                         old-header)
6232                        ((and (numberp id)
6233                              (gnus-number-to-header id))
6234                         (gnus-number-to-header id))
6235                        (t
6236                         (gnus-read-header id))))
6237          (number (and (numberp id) id))
6238          d)
6239     (when header
6240       ;; Rebuild the thread that this article is part of and go to the
6241       ;; article we have fetched.
6242       (when (and (not gnus-show-threads)
6243                  old-header)
6244         (when (and number
6245                    (setq d (gnus-data-find (mail-header-number old-header))))
6246           (goto-char (gnus-data-pos d))
6247           (gnus-data-remove
6248            number
6249            (- (gnus-point-at-bol)
6250               (prog1
6251                   (1+ (gnus-point-at-eol))
6252                 (gnus-delete-line))))))
6253       ;; Remove list identifiers from subject.
6254       (when gnus-list-identifiers
6255         (let ((gnus-newsgroup-headers (list header)))
6256           (gnus-summary-remove-list-identifiers)))
6257       (when old-header
6258         (mail-header-set-number header (mail-header-number old-header)))
6259       (setq gnus-newsgroup-sparse
6260             (delq (setq number (mail-header-number header))
6261                   gnus-newsgroup-sparse))
6262       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6263       (push number gnus-newsgroup-limit)
6264       (gnus-rebuild-thread (mail-header-id header) line)
6265       (gnus-summary-goto-subject number nil t))
6266     (when (and (numberp number)
6267                (> number 0))
6268       ;; We have to update the boundaries even if we can't fetch the
6269       ;; article if ID is a number -- so that the next `P' or `N'
6270       ;; command will fetch the previous (or next) article even
6271       ;; if the one we tried to fetch this time has been canceled.
6272       (when (> number gnus-newsgroup-end)
6273         (setq gnus-newsgroup-end number))
6274       (when (< number gnus-newsgroup-begin)
6275         (setq gnus-newsgroup-begin number))
6276       (setq gnus-newsgroup-unselected
6277             (delq number gnus-newsgroup-unselected)))
6278     ;; Report back a success?
6279     (and header (mail-header-number header))))
6280
6281 ;;; Process/prefix in the summary buffer
6282
6283 (defun gnus-summary-work-articles (n)
6284   "Return a list of articles to be worked upon.
6285 The prefix argument, the list of process marked articles, and the
6286 current article will be taken into consideration."
6287   (save-excursion
6288     (set-buffer gnus-summary-buffer)
6289     (cond
6290      (n
6291       ;; A numerical prefix has been given.
6292       (setq n (prefix-numeric-value n))
6293       (let ((backward (< n 0))
6294             (n (abs (prefix-numeric-value n)))
6295             articles article)
6296         (save-excursion
6297           (while
6298               (and (> n 0)
6299                    (push (setq article (gnus-summary-article-number))
6300                          articles)
6301                    (if backward
6302                        (gnus-summary-find-prev nil article)
6303                      (gnus-summary-find-next nil article)))
6304             (decf n)))
6305         (nreverse articles)))
6306      ((and (gnus-region-active-p) (mark))
6307       (message "region active")
6308       ;; Work on the region between point and mark.
6309       (let ((max (max (point) (mark)))
6310             articles article)
6311         (save-excursion
6312           (goto-char (min (point) (mark)))
6313           (while
6314               (and
6315                (push (setq article (gnus-summary-article-number)) articles)
6316                (gnus-summary-find-next nil article)
6317                (< (point) max)))
6318           (nreverse articles))))
6319      (gnus-newsgroup-processable
6320       ;; There are process-marked articles present.
6321       ;; Save current state.
6322       (gnus-summary-save-process-mark)
6323       ;; Return the list.
6324       (reverse gnus-newsgroup-processable))
6325      (t
6326       ;; Just return the current article.
6327       (list (gnus-summary-article-number))))))
6328
6329 (defmacro gnus-summary-iterate (arg &rest forms)
6330   "Iterate over the process/prefixed articles and do FORMS.
6331 ARG is the interactive prefix given to the command.  FORMS will be
6332 executed with point over the summary line of the articles."
6333   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6334     `(let ((,articles (gnus-summary-work-articles ,arg)))
6335        (while ,articles
6336          (gnus-summary-goto-subject (car ,articles))
6337          ,@forms
6338          (pop ,articles)))))
6339
6340 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6341 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6342
6343 (defun gnus-summary-save-process-mark ()
6344   "Push the current set of process marked articles on the stack."
6345   (interactive)
6346   (push (copy-sequence gnus-newsgroup-processable)
6347         gnus-newsgroup-process-stack))
6348
6349 (defun gnus-summary-kill-process-mark ()
6350   "Push the current set of process marked articles on the stack and unmark."
6351   (interactive)
6352   (gnus-summary-save-process-mark)
6353   (gnus-summary-unmark-all-processable))
6354
6355 (defun gnus-summary-yank-process-mark ()
6356   "Pop the last process mark state off the stack and restore it."
6357   (interactive)
6358   (unless gnus-newsgroup-process-stack
6359     (error "Empty mark stack"))
6360   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6361
6362 (defun gnus-summary-process-mark-set (set)
6363   "Make SET into the current process marked articles."
6364   (gnus-summary-unmark-all-processable)
6365   (while set
6366     (gnus-summary-set-process-mark (pop set))))
6367
6368 ;;; Searching and stuff
6369
6370 (defun gnus-summary-search-group (&optional backward use-level)
6371   "Search for next unread newsgroup.
6372 If optional argument BACKWARD is non-nil, search backward instead."
6373   (save-excursion
6374     (set-buffer gnus-group-buffer)
6375     (when (gnus-group-search-forward
6376            backward nil (if use-level (gnus-group-group-level) nil))
6377       (gnus-group-group-name))))
6378
6379 (defun gnus-summary-best-group (&optional exclude-group)
6380   "Find the name of the best unread group.
6381 If EXCLUDE-GROUP, do not go to this group."
6382   (save-excursion
6383     (set-buffer gnus-group-buffer)
6384     (save-excursion
6385       (gnus-group-best-unread-group exclude-group))))
6386
6387 (defun gnus-summary-find-next (&optional unread article backward)
6388   (if backward
6389       (gnus-summary-find-prev unread article)
6390     (let* ((dummy (gnus-summary-article-intangible-p))
6391            (article (or article (gnus-summary-article-number)))
6392            (data (gnus-data-find-list article))
6393            result)
6394       (when (and (not dummy)
6395                  (or (not gnus-summary-check-current)
6396                      (not unread)
6397                      (not (gnus-data-unread-p (car data)))))
6398         (setq data (cdr data)))
6399       (when (setq result
6400                   (if unread
6401                       (progn
6402                         (while data
6403                           (unless (memq (gnus-data-number (car data))
6404                                         (cond
6405                                          ((eq gnus-auto-goto-ignores
6406                                               'always-undownloaded)
6407                                           gnus-newsgroup-undownloaded)
6408                                          (gnus-plugged
6409                                           nil)
6410                                          ((eq gnus-auto-goto-ignores
6411                                               'unfetched)
6412                                           gnus-newsgroup-unfetched)
6413                                          ((eq gnus-auto-goto-ignores
6414                                               'undownloaded)
6415                                           gnus-newsgroup-undownloaded)))
6416                             (when (gnus-data-unread-p (car data))
6417                               (setq result (car data)
6418                                     data nil)))
6419                           (setq data (cdr data)))
6420                         result)
6421                     (car data)))
6422         (goto-char (gnus-data-pos result))
6423         (gnus-data-number result)))))
6424
6425 (defun gnus-summary-find-prev (&optional unread article)
6426   (let* ((eobp (eobp))
6427          (article (or article (gnus-summary-article-number)))
6428          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6429          result)
6430     (when (and (not eobp)
6431                (or (not gnus-summary-check-current)
6432                    (not unread)
6433                    (not (gnus-data-unread-p (car data)))))
6434       (setq data (cdr data)))
6435     (when (setq result
6436                 (if unread
6437                     (progn
6438                       (while data
6439                         (unless (memq (gnus-data-number (car data))
6440                                       (cond
6441                                        ((eq gnus-auto-goto-ignores
6442                                             'always-undownloaded)
6443                                         gnus-newsgroup-undownloaded)
6444                                        (gnus-plugged
6445                                         nil)
6446                                        ((eq gnus-auto-goto-ignores
6447                                             'unfetched)
6448                                         gnus-newsgroup-unfetched)
6449                                        ((eq gnus-auto-goto-ignores
6450                                             'undownloaded)
6451                                         gnus-newsgroup-undownloaded)))
6452                           (when (gnus-data-unread-p (car data))
6453                             (setq result (car data)
6454                                   data nil)))
6455                         (setq data (cdr data)))
6456                       result)
6457                   (car data)))
6458       (goto-char (gnus-data-pos result))
6459       (gnus-data-number result))))
6460
6461 (defun gnus-summary-find-subject (subject &optional unread backward article)
6462   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6463          (article (or article (gnus-summary-article-number)))
6464          (articles (gnus-data-list backward))
6465          (arts (gnus-data-find-list article articles))
6466          result)
6467     (when (or (not gnus-summary-check-current)
6468               (not unread)
6469               (not (gnus-data-unread-p (car arts))))
6470       (setq arts (cdr arts)))
6471     (while arts
6472       (and (or (not unread)
6473                (gnus-data-unread-p (car arts)))
6474            (vectorp (gnus-data-header (car arts)))
6475            (gnus-subject-equal
6476             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6477            (setq result (car arts)
6478                  arts nil))
6479       (setq arts (cdr arts)))
6480     (and result
6481          (goto-char (gnus-data-pos result))
6482          (gnus-data-number result))))
6483
6484 (defun gnus-summary-search-forward (&optional unread subject backward)
6485   "Search forward for an article.
6486 If UNREAD, look for unread articles.  If SUBJECT, look for
6487 articles with that subject.  If BACKWARD, search backward instead."
6488   (cond (subject (gnus-summary-find-subject subject unread backward))
6489         (backward (gnus-summary-find-prev unread))
6490         (t (gnus-summary-find-next unread))))
6491
6492 (defun gnus-recenter (&optional n)
6493   "Center point in window and redisplay frame.
6494 Also do horizontal recentering."
6495   (interactive "P")
6496   (when (and gnus-auto-center-summary
6497              (not (eq gnus-auto-center-summary 'vertical)))
6498     (gnus-horizontal-recenter))
6499   (recenter n))
6500
6501 (defun gnus-summary-recenter ()
6502   "Center point in the summary window.
6503 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6504 displayed, no centering will be performed."
6505   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6506   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6507   (interactive)
6508   ;; The user has to want it.
6509   (when gnus-auto-center-summary
6510     (let* ((top (cond ((< (window-height) 4) 0)
6511                       ((< (window-height) 7) 1)
6512                       (t (if (numberp gnus-auto-center-summary)
6513                              gnus-auto-center-summary
6514                            2))))
6515            (height (1- (window-height)))
6516            (bottom (save-excursion (goto-char (point-max))
6517                                    (forward-line (- height))
6518                                    (point)))
6519            (window (get-buffer-window (current-buffer))))
6520       (when (get-buffer-window gnus-article-buffer)
6521         ;; Only do recentering when the article buffer is displayed,
6522         ;; Set the window start to either `bottom', which is the biggest
6523         ;; possible valid number, or the second line from the top,
6524         ;; whichever is the least.
6525         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6526           (if (> bottom top-pos)
6527               ;; Keep the second line from the top visible
6528               (set-window-start window top-pos t)
6529             ;; Try to keep the bottom line visible; if it's partially
6530             ;; obscured, either scroll one more line to make it fully
6531             ;; visible, or revert to using TOP-POS.
6532             (save-excursion
6533               (goto-char (point-max))
6534               (forward-line -1)
6535               (let ((last-line-start (point)))
6536                 (goto-char bottom)
6537                 (set-window-start window (point) t)
6538                 (when (not (pos-visible-in-window-p last-line-start window))
6539                   (forward-line 1)
6540                   (set-window-start window (min (point) top-pos) t)))))))
6541       ;; Do horizontal recentering while we're at it.
6542       (when (and (get-buffer-window (current-buffer) t)
6543                  (not (eq gnus-auto-center-summary 'vertical)))
6544         (let ((selected (selected-window)))
6545           (select-window (get-buffer-window (current-buffer) t))
6546           (gnus-summary-position-point)
6547           (gnus-horizontal-recenter)
6548           (select-window selected))))))
6549
6550 (defun gnus-summary-jump-to-group (newsgroup)
6551   "Move point to NEWSGROUP in group mode buffer."
6552   ;; Keep update point of group mode buffer if visible.
6553   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6554       (save-window-excursion
6555         ;; Take care of tree window mode.
6556         (when (get-buffer-window gnus-group-buffer)
6557           (pop-to-buffer gnus-group-buffer))
6558         (gnus-group-jump-to-group newsgroup))
6559     (save-excursion
6560       ;; Take care of tree window mode.
6561       (if (get-buffer-window gnus-group-buffer)
6562           (pop-to-buffer gnus-group-buffer)
6563         (set-buffer gnus-group-buffer))
6564       (gnus-group-jump-to-group newsgroup))))
6565
6566 ;; This function returns a list of article numbers based on the
6567 ;; difference between the ranges of read articles in this group and
6568 ;; the range of active articles.
6569 (defun gnus-list-of-unread-articles (group)
6570   (let* ((read (gnus-info-read (gnus-get-info group)))
6571          (active (or (gnus-active group) (gnus-activate-group group)))
6572          (last (cdr active))
6573          (bottom (if gnus-newsgroup-maximum-articles
6574                      (max (car active)
6575                           (- last gnus-newsgroup-maximum-articles -1))
6576                    (car active)))
6577          first nlast unread)
6578     ;; If none are read, then all are unread.
6579     (if (not read)
6580         (setq first bottom)
6581       ;; If the range of read articles is a single range, then the
6582       ;; first unread article is the article after the last read
6583       ;; article.  Sounds logical, doesn't it?
6584       (if (and (not (listp (cdr read)))
6585                (or (< (car read) bottom)
6586                    (progn (setq read (list read))
6587                           nil)))
6588           (setq first (max bottom (1+ (cdr read))))
6589         ;; `read' is a list of ranges.
6590         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6591                                   (caar read)))
6592                   1)
6593           (setq first bottom))
6594         (while read
6595           (when first
6596             (while (< first nlast)
6597               (setq unread (cons first unread)
6598                     first (1+ first))))
6599           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6600           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6601           (setq read (cdr read)))))
6602     ;; And add the last unread articles.
6603     (while (<= first last)
6604       (setq unread (cons first unread)
6605             first (1+ first)))
6606     ;; Return the list of unread articles.
6607     (delq 0 (nreverse unread))))
6608
6609 (defun gnus-list-of-read-articles (group)
6610   "Return a list of unread, unticked and non-dormant articles."
6611   (let* ((info (gnus-get-info group))
6612          (marked (gnus-info-marks info))
6613          (active (gnus-active group)))
6614     (and info active
6615          (gnus-list-range-difference
6616           (gnus-list-range-difference
6617            (gnus-sorted-complement
6618             (gnus-uncompress-range
6619              (if gnus-newsgroup-maximum-articles
6620                  (cons (max (car active)
6621                             (- (cdr active)
6622                                gnus-newsgroup-maximum-articles
6623                                -1))
6624                        (cdr active))
6625                active))
6626             (gnus-list-of-unread-articles group))
6627            (cdr (assq 'dormant marked)))
6628           (cdr (assq 'tick marked))))))
6629
6630 ;; This function returns a sequence of article numbers based on the
6631 ;; difference between the ranges of read articles in this group and
6632 ;; the range of active articles.
6633 (defun gnus-sequence-of-unread-articles (group)
6634   (let* ((read (gnus-info-read (gnus-get-info group)))
6635          (active (or (gnus-active group) (gnus-activate-group group)))
6636          (last (cdr active))
6637          (bottom (if gnus-newsgroup-maximum-articles
6638                      (max (car active)
6639                           (- last gnus-newsgroup-maximum-articles -1))
6640                    (car active)))
6641          first nlast unread)
6642     ;; If none are read, then all are unread.
6643     (if (not read)
6644         (setq first bottom)
6645       ;; If the range of read articles is a single range, then the
6646       ;; first unread article is the article after the last read
6647       ;; article.  Sounds logical, doesn't it?
6648       (if (and (not (listp (cdr read)))
6649                (or (< (car read) bottom)
6650                    (progn (setq read (list read))
6651                           nil)))
6652           (setq first (max bottom (1+ (cdr read))))
6653         ;; `read' is a list of ranges.
6654         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6655                                   (caar read)))
6656                   1)
6657           (setq first bottom))
6658         (while read
6659           (when first
6660             (push (cons first nlast) unread))
6661           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6662           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6663           (setq read (cdr read)))))
6664     ;; And add the last unread articles.
6665     (cond ((not (and first last))
6666            nil)
6667           ((< first last)
6668            (push (cons first last) unread))
6669           ((= first last)
6670            (push first unread)))
6671     ;; Return the sequence of unread articles.
6672     (delq 0 (nreverse unread))))
6673
6674 ;; Various summary commands
6675
6676 (defun gnus-summary-select-article-buffer ()
6677   "Reconfigure windows to show article buffer."
6678   (interactive)
6679   (if (not (gnus-buffer-live-p gnus-article-buffer))
6680       (error "There is no article buffer for this summary buffer")
6681     (gnus-configure-windows 'article)
6682     (select-window (get-buffer-window gnus-article-buffer))))
6683
6684 (defun gnus-summary-universal-argument (arg)
6685   "Perform any operation on all articles that are process/prefixed."
6686   (interactive "P")
6687   (let ((articles (gnus-summary-work-articles arg))
6688         func article)
6689     (if (eq
6690          (setq
6691           func
6692           (key-binding
6693            (read-key-sequence
6694             (substitute-command-keys
6695              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6696          'undefined)
6697         (gnus-error 1 "Undefined key")
6698       (save-excursion
6699         (while articles
6700           (gnus-summary-goto-subject (setq article (pop articles)))
6701           (let (gnus-newsgroup-processable)
6702             (command-execute func))
6703           (gnus-summary-remove-process-mark article)))))
6704   (gnus-summary-position-point))
6705
6706 (defun gnus-summary-toggle-truncation (&optional arg)
6707   "Toggle truncation of summary lines.
6708 With ARG, turn line truncation on if ARG is positive."
6709   (interactive "P")
6710   (setq truncate-lines
6711         (if (null arg) (not truncate-lines)
6712           (> (prefix-numeric-value arg) 0)))
6713   (redraw-display))
6714
6715 (defun gnus-summary-find-for-reselect ()
6716   "Return the number of an article to stay on across a reselect.
6717 The current article is considered, then following articles, then previous
6718 articles.  An article is sought which is not cancelled and isn't a temporary
6719 insertion from another group.  If there's no such then return a dummy 0."
6720   (let (found)
6721     (dolist (rev '(nil t))
6722       (unless found      ; don't demand the reverse list if we don't need it
6723         (let ((data (gnus-data-find-list
6724                      (gnus-summary-article-number) (gnus-data-list rev))))
6725           (while (and data (not found))
6726             (if (and (< 0 (gnus-data-number (car data)))
6727                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6728                 (setq found (gnus-data-number (car data))))
6729             (setq data (cdr data))))))
6730     (or found 0)))
6731
6732 (defun gnus-summary-reselect-current-group (&optional all rescan)
6733   "Exit and then reselect the current newsgroup.
6734 The prefix argument ALL means to select all articles."
6735   (interactive "P")
6736   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6737     (error "Ephemeral groups can't be reselected"))
6738   (let ((current-subject (gnus-summary-find-for-reselect))
6739         (group gnus-newsgroup-name))
6740     (setq gnus-newsgroup-begin nil)
6741     (gnus-summary-exit nil 'leave-hidden)
6742     ;; We have to adjust the point of group mode buffer because
6743     ;; point was moved to the next unread newsgroup by exiting.
6744     (gnus-summary-jump-to-group group)
6745     (when rescan
6746       (save-excursion
6747         (gnus-group-get-new-news-this-group 1)))
6748     (gnus-group-read-group all t)
6749     (gnus-summary-goto-subject current-subject nil t)))
6750
6751 (defun gnus-summary-rescan-group (&optional all)
6752   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6753   (interactive "P")
6754   (gnus-summary-reselect-current-group all t))
6755
6756 (defun gnus-summary-update-info (&optional non-destructive)
6757   (save-excursion
6758     (let ((group gnus-newsgroup-name))
6759       (when group
6760         (when gnus-newsgroup-kill-headers
6761           (setq gnus-newsgroup-killed
6762                 (gnus-compress-sequence
6763                  (gnus-sorted-union
6764                   (gnus-list-range-intersection
6765                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6766                   gnus-newsgroup-unreads)
6767                  t)))
6768         (unless (listp (cdr gnus-newsgroup-killed))
6769           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6770         (let ((headers gnus-newsgroup-headers))
6771           ;; Set the new ranges of read articles.
6772           (save-excursion
6773             (set-buffer gnus-group-buffer)
6774             (gnus-undo-force-boundary))
6775           (gnus-update-read-articles
6776            group (gnus-sorted-union
6777                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6778           ;; Set the current article marks.
6779           (let ((gnus-newsgroup-scored
6780                  (if (and (not gnus-save-score)
6781                           (not non-destructive))
6782                      nil
6783                    gnus-newsgroup-scored)))
6784             (save-excursion
6785               (gnus-update-marks)))
6786           ;; Do the cross-ref thing.
6787           (when gnus-use-cross-reference
6788             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6789           ;; Do not switch windows but change the buffer to work.
6790           (set-buffer gnus-group-buffer)
6791           (unless (gnus-ephemeral-group-p group)
6792             (gnus-group-update-group group)))))))
6793
6794 (defun gnus-summary-save-newsrc (&optional force)
6795   "Save the current number of read/marked articles in the dribble buffer.
6796 The dribble buffer will then be saved.
6797 If FORCE (the prefix), also save the .newsrc file(s)."
6798   (interactive "P")
6799   (gnus-summary-update-info t)
6800   (if force
6801       (gnus-save-newsrc-file)
6802     (gnus-dribble-save)))
6803
6804 (defun gnus-summary-exit (&optional temporary leave-hidden)
6805   "Exit reading current newsgroup, and then return to group selection mode.
6806 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6807   (interactive)
6808   (gnus-set-global-variables)
6809   (when (gnus-buffer-live-p gnus-article-buffer)
6810     (save-excursion
6811       (set-buffer gnus-article-buffer)
6812       (mm-destroy-parts gnus-article-mime-handles)
6813       ;; Set it to nil for safety reason.
6814       (setq gnus-article-mime-handle-alist nil)
6815       (setq gnus-article-mime-handles nil)))
6816   (gnus-kill-save-kill-buffer)
6817   (gnus-async-halt-prefetch)
6818   (let* ((group gnus-newsgroup-name)
6819          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6820          (gnus-group-is-exiting-p t)
6821          (mode major-mode)
6822          (group-point nil)
6823          (buf (current-buffer)))
6824     (unless quit-config
6825       ;; Do adaptive scoring, and possibly save score files.
6826       (when gnus-newsgroup-adaptive
6827         (gnus-score-adaptive))
6828       (when gnus-use-scoring
6829         (gnus-score-save)))
6830     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6831     ;; If we have several article buffers, we kill them at exit.
6832     (unless gnus-single-article-buffer
6833       (gnus-kill-buffer gnus-original-article-buffer)
6834       (setq gnus-article-current nil))
6835     (when gnus-use-cache
6836       (gnus-cache-possibly-remove-articles)
6837       (gnus-cache-save-buffers))
6838     (gnus-async-prefetch-remove-group group)
6839     (when gnus-suppress-duplicates
6840       (gnus-dup-enter-articles))
6841     (when gnus-use-trees
6842       (gnus-tree-close group))
6843     (when gnus-use-cache
6844       (gnus-cache-write-active))
6845     ;; Remove entries for this group.
6846     (nnmail-purge-split-history (gnus-group-real-name group))
6847     ;; Make all changes in this group permanent.
6848     (unless quit-config
6849       (gnus-run-hooks 'gnus-exit-group-hook)
6850       (gnus-summary-update-info))
6851     (gnus-close-group group)
6852     ;; Make sure where we were, and go to next newsgroup.
6853     (set-buffer gnus-group-buffer)
6854     (unless quit-config
6855       (gnus-group-jump-to-group group))
6856     (gnus-run-hooks 'gnus-summary-exit-hook)
6857     (unless (or quit-config
6858                 ;; If this group has disappeared from the summary
6859                 ;; buffer, don't skip forwards.
6860                 (not (string= group (gnus-group-group-name))))
6861       (gnus-group-next-unread-group 1))
6862     (setq group-point (point))
6863     (if temporary
6864         nil                             ;Nothing to do.
6865       ;; If we have several article buffers, we kill them at exit.
6866       (unless gnus-single-article-buffer
6867         (gnus-kill-buffer gnus-article-buffer)
6868         (gnus-kill-buffer gnus-original-article-buffer)
6869         (setq gnus-article-current nil))
6870       (set-buffer buf)
6871       (if (not gnus-kill-summary-on-exit)
6872           (progn
6873             (gnus-deaden-summary)
6874             (setq mode nil))
6875         ;; We set all buffer-local variables to nil.  It is unclear why
6876         ;; this is needed, but if we don't, buffer-local variables are
6877         ;; not garbage-collected, it seems.  This would the lead to en
6878         ;; ever-growing Emacs.
6879         (gnus-summary-clear-local-variables)
6880         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6881           (gnus-summary-clear-local-variables))
6882         (when (get-buffer gnus-article-buffer)
6883           (bury-buffer gnus-article-buffer))
6884         ;; We clear the global counterparts of the buffer-local
6885         ;; variables as well, just to be on the safe side.
6886         (set-buffer gnus-group-buffer)
6887         (gnus-summary-clear-local-variables)
6888         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6889           (gnus-summary-clear-local-variables))
6890         ;; Return to group mode buffer.
6891         (when (eq mode 'gnus-summary-mode)
6892           (gnus-kill-buffer buf)))
6893       (setq gnus-current-select-method gnus-select-method)
6894       (set-buffer gnus-group-buffer)
6895       (if quit-config
6896           (gnus-handle-ephemeral-exit quit-config)
6897         (goto-char group-point)
6898         ;; If gnus-group-buffer is already displayed, make sure we also move
6899         ;; the cursor in the window that displays it.
6900         (let ((win (get-buffer-window (current-buffer) 0)))
6901           (if win (set-window-point win (point))))
6902         (unless leave-hidden
6903           (gnus-configure-windows 'group 'force)))
6904       ;; Clear the current group name.
6905       (unless quit-config
6906         (setq gnus-newsgroup-name nil)))))
6907
6908 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6909 (defun gnus-summary-exit-no-update (&optional no-questions)
6910   "Quit reading current newsgroup without updating read article info."
6911   (interactive)
6912   (let* ((group gnus-newsgroup-name)
6913          (gnus-group-is-exiting-p t)
6914          (gnus-group-is-exiting-without-update-p t)
6915          (quit-config (gnus-group-quit-config group)))
6916     (when (or no-questions
6917               gnus-expert-user
6918               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6919       (gnus-async-halt-prefetch)
6920       (run-hooks 'gnus-summary-prepare-exit-hook)
6921       (when (gnus-buffer-live-p gnus-article-buffer)
6922         (save-excursion
6923           (set-buffer gnus-article-buffer)
6924           (mm-destroy-parts gnus-article-mime-handles)
6925           ;; Set it to nil for safety reason.
6926           (setq gnus-article-mime-handle-alist nil)
6927           (setq gnus-article-mime-handles nil)))
6928       ;; If we have several article buffers, we kill them at exit.
6929       (unless gnus-single-article-buffer
6930         (gnus-kill-buffer gnus-article-buffer)
6931         (gnus-kill-buffer gnus-original-article-buffer)
6932         (setq gnus-article-current nil))
6933       (if (not gnus-kill-summary-on-exit)
6934           (gnus-deaden-summary)
6935         (gnus-close-group group)
6936         (gnus-summary-clear-local-variables)
6937         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6938           (gnus-summary-clear-local-variables))
6939         (set-buffer gnus-group-buffer)
6940         (gnus-summary-clear-local-variables)
6941         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6942           (gnus-summary-clear-local-variables))
6943         (gnus-kill-buffer gnus-summary-buffer))
6944       (unless gnus-single-article-buffer
6945         (setq gnus-article-current nil))
6946       (when gnus-use-trees
6947         (gnus-tree-close group))
6948       (gnus-async-prefetch-remove-group group)
6949       (when (get-buffer gnus-article-buffer)
6950         (bury-buffer gnus-article-buffer))
6951       ;; Return to the group buffer.
6952       (gnus-configure-windows 'group 'force)
6953       ;; Clear the current group name.
6954       (setq gnus-newsgroup-name nil)
6955       (unless (gnus-ephemeral-group-p group)
6956         (gnus-group-update-group group))
6957       (when (equal (gnus-group-group-name) group)
6958         (gnus-group-next-unread-group 1))
6959       (when quit-config
6960         (gnus-handle-ephemeral-exit quit-config)))))
6961
6962 (defun gnus-handle-ephemeral-exit (quit-config)
6963   "Handle movement when leaving an ephemeral group.
6964 The state which existed when entering the ephemeral is reset."
6965   (if (not (buffer-name (car quit-config)))
6966       (gnus-configure-windows 'group 'force)
6967     (set-buffer (car quit-config))
6968     (cond ((eq major-mode 'gnus-summary-mode)
6969            (gnus-set-global-variables))
6970           ((eq major-mode 'gnus-article-mode)
6971            (save-excursion
6972              ;; The `gnus-summary-buffer' variable may point
6973              ;; to the old summary buffer when using a single
6974              ;; article buffer.
6975              (unless (gnus-buffer-live-p gnus-summary-buffer)
6976                (set-buffer gnus-group-buffer))
6977              (set-buffer gnus-summary-buffer)
6978              (gnus-set-global-variables))))
6979     (if (or (eq (cdr quit-config) 'article)
6980             (eq (cdr quit-config) 'pick))
6981         (progn
6982           ;; The current article may be from the ephemeral group
6983           ;; thus it is best that we reload this article
6984           ;;
6985           ;; If we're exiting from a large digest, this can be
6986           ;; extremely slow.  So, it's better not to reload it. -- jh.
6987           ;;(gnus-summary-show-article)
6988           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6989               (gnus-configure-windows 'pick 'force)
6990             (gnus-configure-windows (cdr quit-config) 'force)))
6991       (gnus-configure-windows (cdr quit-config) 'force))
6992     (when (eq major-mode 'gnus-summary-mode)
6993       (gnus-summary-next-subject 1 nil t)
6994       (gnus-summary-recenter)
6995       (gnus-summary-position-point))))
6996
6997 ;;; Dead summaries.
6998
6999 (defvar gnus-dead-summary-mode-map nil)
7000
7001 (unless gnus-dead-summary-mode-map
7002   (setq gnus-dead-summary-mode-map (make-keymap))
7003   (suppress-keymap gnus-dead-summary-mode-map)
7004   (substitute-key-definition
7005    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7006   (dolist (key '("\C-d" "\r" "\177" [delete]))
7007     (define-key gnus-dead-summary-mode-map
7008       key 'gnus-summary-wake-up-the-dead))
7009   (dolist (key '("q" "Q"))
7010     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7011
7012 (defvar gnus-dead-summary-mode nil
7013   "Minor mode for Gnus summary buffers.")
7014
7015 (defun gnus-dead-summary-mode (&optional arg)
7016   "Minor mode for Gnus summary buffers."
7017   (interactive "P")
7018   (when (eq major-mode 'gnus-summary-mode)
7019     (make-local-variable 'gnus-dead-summary-mode)
7020     (setq gnus-dead-summary-mode
7021           (if (null arg) (not gnus-dead-summary-mode)
7022             (> (prefix-numeric-value arg) 0)))
7023     (when gnus-dead-summary-mode
7024       (gnus-add-minor-mode
7025        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7026
7027 (defun gnus-deaden-summary ()
7028   "Make the current summary buffer into a dead summary buffer."
7029   ;; Kill any previous dead summary buffer.
7030   (when (and gnus-dead-summary
7031              (buffer-name gnus-dead-summary))
7032     (save-excursion
7033       (set-buffer gnus-dead-summary)
7034       (when gnus-dead-summary-mode
7035         (kill-buffer (current-buffer)))))
7036   ;; Make this the current dead summary.
7037   (setq gnus-dead-summary (current-buffer))
7038   (gnus-dead-summary-mode 1)
7039   (let ((name (buffer-name)))
7040     (when (string-match "Summary" name)
7041       (rename-buffer
7042        (concat (substring name 0 (match-beginning 0)) "Dead "
7043                (substring name (match-beginning 0)))
7044        t)
7045       (bury-buffer))))
7046
7047 (defun gnus-kill-or-deaden-summary (buffer)
7048   "Kill or deaden the summary BUFFER."
7049   (save-excursion
7050     (when (and (buffer-name buffer)
7051                (not gnus-single-article-buffer))
7052       (save-excursion
7053         (set-buffer buffer)
7054         (gnus-kill-buffer gnus-article-buffer)
7055         (gnus-kill-buffer gnus-original-article-buffer)))
7056     (cond
7057      ;; Kill the buffer.
7058      (gnus-kill-summary-on-exit
7059       (when (and gnus-use-trees
7060                  (gnus-buffer-exists-p buffer))
7061         (save-excursion
7062           (set-buffer buffer)
7063           (gnus-tree-close gnus-newsgroup-name)))
7064       (gnus-kill-buffer buffer))
7065      ;; Deaden the buffer.
7066      ((gnus-buffer-exists-p buffer)
7067       (save-excursion
7068         (set-buffer buffer)
7069         (gnus-deaden-summary))))))
7070
7071 (defun gnus-summary-wake-up-the-dead (&rest args)
7072   "Wake up the dead summary buffer."
7073   (interactive)
7074   (gnus-dead-summary-mode -1)
7075   (let ((name (buffer-name)))
7076     (when (string-match "Dead " name)
7077       (rename-buffer
7078        (concat (substring name 0 (match-beginning 0))
7079                (substring name (match-end 0)))
7080        t)))
7081   (gnus-message 3 "This dead summary is now alive again"))
7082
7083 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7084 (defun gnus-summary-fetch-faq (&optional faq-dir)
7085   "Fetch the FAQ for the current group.
7086 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7087 in."
7088   (interactive
7089    (list
7090     (when current-prefix-arg
7091       (completing-read
7092        "FAQ dir: " (and (listp gnus-group-faq-directory)
7093                         (mapcar (lambda (file) (list file))
7094                                 gnus-group-faq-directory))))))
7095   (let (gnus-faq-buffer)
7096     (when (setq gnus-faq-buffer
7097                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7098       (gnus-configure-windows 'summary-faq))))
7099
7100 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7101 (defun gnus-summary-describe-group (&optional force)
7102   "Describe the current newsgroup."
7103   (interactive "P")
7104   (gnus-group-describe-group force gnus-newsgroup-name))
7105
7106 (defun gnus-summary-describe-briefly ()
7107   "Describe summary mode commands briefly."
7108   (interactive)
7109   (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")))
7110
7111 ;; Walking around group mode buffer from summary mode.
7112
7113 (defun gnus-summary-next-group (&optional no-article target-group backward)
7114   "Exit current newsgroup and then select next unread newsgroup.
7115 If prefix argument NO-ARTICLE is non-nil, no article is selected
7116 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7117 previous group instead."
7118   (interactive "P")
7119   ;; Stop pre-fetching.
7120   (gnus-async-halt-prefetch)
7121   (let ((current-group gnus-newsgroup-name)
7122         (current-buffer (current-buffer))
7123         entered)
7124     ;; First we semi-exit this group to update Xrefs and all variables.
7125     ;; We can't do a real exit, because the window conf must remain
7126     ;; the same in case the user is prompted for info, and we don't
7127     ;; want the window conf to change before that...
7128     (gnus-summary-exit t)
7129     (while (not entered)
7130       ;; Then we find what group we are supposed to enter.
7131       (set-buffer gnus-group-buffer)
7132       (gnus-group-jump-to-group current-group)
7133       (setq target-group
7134             (or target-group
7135                 (if (eq gnus-keep-same-level 'best)
7136                     (gnus-summary-best-group gnus-newsgroup-name)
7137                   (gnus-summary-search-group backward gnus-keep-same-level))))
7138       (if (not target-group)
7139           ;; There are no further groups, so we return to the group
7140           ;; buffer.
7141           (progn
7142             (gnus-message 5 "Returning to the group buffer")
7143             (setq entered t)
7144             (when (gnus-buffer-live-p current-buffer)
7145               (set-buffer current-buffer)
7146               (gnus-summary-exit))
7147             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7148         ;; We try to enter the target group.
7149         (gnus-group-jump-to-group target-group)
7150         (let ((unreads (gnus-group-group-unread)))
7151           (if (and (or (eq t unreads)
7152                        (and unreads (not (zerop unreads))))
7153                    (gnus-summary-read-group
7154                     target-group nil no-article
7155                     (and (buffer-name current-buffer) current-buffer)
7156                     nil backward))
7157               (setq entered t)
7158             (setq current-group target-group
7159                   target-group nil)))))))
7160
7161 (defun gnus-summary-prev-group (&optional no-article)
7162   "Exit current newsgroup and then select previous unread newsgroup.
7163 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7164   (interactive "P")
7165   (gnus-summary-next-group no-article nil t))
7166
7167 ;; Walking around summary lines.
7168
7169 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7170   "Go to the first subject satisfying any non-nil constraint.
7171 If UNREAD is non-nil, the article should be unread.
7172 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7173 If UNSEEN is non-nil, the article should be unseen.
7174 Returns the article selected or nil if there are no matching articles."
7175   (interactive "P")
7176   (cond
7177    ;; Empty summary.
7178    ((null gnus-newsgroup-data)
7179     (gnus-message 3 "No articles in the group")
7180     nil)
7181    ;; Pick the first article.
7182    ((not (or unread undownloaded unseen))
7183     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7184     (gnus-data-number (car gnus-newsgroup-data)))
7185    ;; Find the first unread article.
7186    (t
7187     (let ((data gnus-newsgroup-data))
7188       (while (and data
7189                   (let ((num (gnus-data-number (car data))))
7190                     (or (memq num gnus-newsgroup-unfetched)
7191                         (not (or (and unread
7192                                       (memq num gnus-newsgroup-unreads))
7193                                  (and undownloaded
7194                                       (memq num gnus-newsgroup-undownloaded))
7195                                  (and unseen
7196                                       (memq num gnus-newsgroup-unseen)))))))
7197         (setq data (cdr data)))
7198       (prog1
7199           (if data
7200               (progn
7201                 (goto-char (gnus-data-pos (car data)))
7202                 (gnus-data-number (car data)))
7203             (gnus-message 3 "No more%s articles"
7204                           (let* ((r (when unread " unread"))
7205                                  (d (when undownloaded " undownloaded"))
7206                                  (s (when unseen " unseen"))
7207                                  (l (delq nil (list r d s))))
7208                             (cond ((= 3 (length l))
7209                                    (concat r "," d ", or" s))
7210                                   ((= 2 (length l))
7211                                    (concat (car l) ", or" (cadr l)))
7212                                   ((= 1 (length l))
7213                                    (car l))
7214                                   (t
7215                                    ""))))
7216             nil
7217             )
7218         (gnus-summary-position-point))))))
7219
7220 (defun gnus-summary-next-subject (n &optional unread dont-display)
7221   "Go to next N'th summary line.
7222 If N is negative, go to the previous N'th subject line.
7223 If UNREAD is non-nil, only unread articles are selected.
7224 The difference between N and the actual number of steps taken is
7225 returned."
7226   (interactive "p")
7227   (let ((backward (< n 0))
7228         (n (abs n)))
7229     (while (and (> n 0)
7230                 (if backward
7231                     (gnus-summary-find-prev unread)
7232                   (gnus-summary-find-next unread)))
7233       (unless (zerop (setq n (1- n)))
7234         (gnus-summary-show-thread)))
7235     (when (/= 0 n)
7236       (gnus-message 7 "No more%s articles"
7237                     (if unread " unread" "")))
7238     (unless dont-display
7239       (gnus-summary-recenter)
7240       (gnus-summary-position-point))
7241     n))
7242
7243 (defun gnus-summary-next-unread-subject (n)
7244   "Go to next N'th unread summary line."
7245   (interactive "p")
7246   (gnus-summary-next-subject n t))
7247
7248 (defun gnus-summary-prev-subject (n &optional unread)
7249   "Go to previous N'th summary line.
7250 If optional argument UNREAD is non-nil, only unread article is selected."
7251   (interactive "p")
7252   (gnus-summary-next-subject (- n) unread))
7253
7254 (defun gnus-summary-prev-unread-subject (n)
7255   "Go to previous N'th unread summary line."
7256   (interactive "p")
7257   (gnus-summary-next-subject (- n) t))
7258
7259 (defun gnus-summary-goto-subjects (articles)
7260   "Insert the subject header for ARTICLES in the current buffer."
7261   (save-excursion
7262     (dolist (article articles)
7263       (gnus-summary-goto-subject article t)))
7264   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7265   (gnus-summary-position-point))
7266
7267 (defun gnus-summary-goto-subject (article &optional force silent)
7268   "Go the subject line of ARTICLE.
7269 If FORCE, also allow jumping to articles not currently shown."
7270   (interactive "nArticle number: ")
7271   (unless (numberp article)
7272     (error "Article %s is not a number" article))
7273   (let ((b (point))
7274         (data (gnus-data-find article)))
7275     ;; We read in the article if we have to.
7276     (and (not data)
7277          force
7278          (gnus-summary-insert-subject
7279           article
7280           (if (or (numberp force) (vectorp force)) force)
7281           t)
7282          (setq data (gnus-data-find article)))
7283     (goto-char b)
7284     (if (not data)
7285         (progn
7286           (unless silent
7287             (gnus-message 3 "Can't find article %d" article))
7288           nil)
7289       (let ((pt (gnus-data-pos data)))
7290         (goto-char pt)
7291         (gnus-summary-set-article-display-arrow pt))
7292       (gnus-summary-position-point)
7293       article)))
7294
7295 ;; Walking around summary lines with displaying articles.
7296
7297 (defun gnus-summary-expand-window (&optional arg)
7298   "Make the summary buffer take up the entire Emacs frame.
7299 Given a prefix, will force an `article' buffer configuration."
7300   (interactive "P")
7301   (if arg
7302       (gnus-configure-windows 'article 'force)
7303     (gnus-configure-windows 'summary 'force)))
7304
7305 (defun gnus-summary-display-article (article &optional all-header)
7306   "Display ARTICLE in article buffer."
7307   (when (gnus-buffer-live-p gnus-article-buffer)
7308     (with-current-buffer gnus-article-buffer
7309       (mm-enable-multibyte)))
7310   (gnus-set-global-variables)
7311   (when (gnus-buffer-live-p gnus-article-buffer)
7312     (with-current-buffer gnus-article-buffer
7313       (setq gnus-article-charset gnus-newsgroup-charset)
7314       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7315       (mm-enable-multibyte)))
7316   (if (null article)
7317       nil
7318     (prog1
7319         (if gnus-summary-display-article-function
7320             (funcall gnus-summary-display-article-function article all-header)
7321           (gnus-article-prepare article all-header))
7322       (gnus-run-hooks 'gnus-select-article-hook)
7323       (when (and gnus-current-article
7324                  (not (zerop gnus-current-article)))
7325         (gnus-summary-goto-subject gnus-current-article))
7326       (gnus-summary-recenter)
7327       (when (and gnus-use-trees gnus-show-threads)
7328         (gnus-possibly-generate-tree article)
7329         (gnus-highlight-selected-tree article))
7330       ;; Successfully display article.
7331       (gnus-article-set-window-start
7332        (cdr (assq article gnus-newsgroup-bookmarks))))))
7333
7334 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7335   "Select the current article.
7336 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7337 non-nil, the article will be re-fetched even if it already present in
7338 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7339 be displayed."
7340   ;; Make sure we are in the summary buffer to work around bbdb bug.
7341   (unless (eq major-mode 'gnus-summary-mode)
7342     (set-buffer gnus-summary-buffer))
7343   (let ((article (or article (gnus-summary-article-number)))
7344         (all-headers (not (not all-headers))) ;Must be t or nil.
7345         gnus-summary-display-article-function)
7346     (and (not pseudo)
7347          (gnus-summary-article-pseudo-p article)
7348          (error "This is a pseudo-article"))
7349     (save-excursion
7350       (set-buffer gnus-summary-buffer)
7351       (if (or (and gnus-single-article-buffer
7352                    (or (null gnus-current-article)
7353                        (null gnus-article-current)
7354                        (null (get-buffer gnus-article-buffer))
7355                        (not (eq article (cdr gnus-article-current)))
7356                        (not (equal (car gnus-article-current)
7357                                    gnus-newsgroup-name))))
7358               (and (not gnus-single-article-buffer)
7359                    (or (null gnus-current-article)
7360                        (not (eq gnus-current-article article))))
7361               force)
7362           ;; The requested article is different from the current article.
7363           (progn
7364             (gnus-summary-display-article article all-headers)
7365             (when (gnus-buffer-live-p gnus-article-buffer)
7366               (with-current-buffer gnus-article-buffer
7367                 (if (not gnus-article-decoded-p) ;; a local variable
7368                     (mm-disable-multibyte))))
7369             (gnus-article-set-window-start
7370              (cdr (assq article gnus-newsgroup-bookmarks)))
7371             article)
7372         'old))))
7373
7374 (defun gnus-summary-force-verify-and-decrypt ()
7375   "Display buttons for signed/encrypted parts and verify/decrypt them."
7376   (interactive)
7377   (let ((mm-verify-option 'known)
7378         (mm-decrypt-option 'known)
7379         (gnus-article-emulate-mime t)
7380         (gnus-buttonized-mime-types (append (list "multipart/signed"
7381                                                   "multipart/encrypted")
7382                                             gnus-buttonized-mime-types)))
7383     (gnus-summary-select-article nil 'force)))
7384
7385 (defun gnus-summary-set-current-mark (&optional current-mark)
7386   "Obsolete function."
7387   nil)
7388
7389 (defun gnus-summary-next-article (&optional unread subject backward push)
7390   "Select the next article.
7391 If UNREAD, only unread articles are selected.
7392 If SUBJECT, only articles with SUBJECT are selected.
7393 If BACKWARD, the previous article is selected instead of the next."
7394   (interactive "P")
7395   ;; Make sure we are in the summary buffer.
7396   (unless (eq major-mode 'gnus-summary-mode)
7397     (set-buffer gnus-summary-buffer))
7398   (cond
7399    ;; Is there such an article?
7400    ((and (gnus-summary-search-forward unread subject backward)
7401          (or (gnus-summary-display-article (gnus-summary-article-number))
7402              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7403     (gnus-summary-position-point))
7404    ;; If not, we try the first unread, if that is wanted.
7405    ((and subject
7406          gnus-auto-select-same
7407          (gnus-summary-first-unread-article))
7408     (gnus-summary-position-point)
7409     (gnus-message 6 "Wrapped"))
7410    ;; Try to get next/previous article not displayed in this group.
7411    ((and gnus-auto-extend-newsgroup
7412          (not unread) (not subject))
7413     (gnus-summary-goto-article
7414      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7415      nil (count-lines (point-min) (point))))
7416    ;; Go to next/previous group.
7417    (t
7418     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7419       (gnus-summary-jump-to-group gnus-newsgroup-name))
7420     (let ((cmd last-command-char)
7421           (point
7422            (save-excursion
7423              (set-buffer gnus-group-buffer)
7424              (point)))
7425           (group
7426            (if (eq gnus-keep-same-level 'best)
7427                (gnus-summary-best-group gnus-newsgroup-name)
7428              (gnus-summary-search-group backward gnus-keep-same-level))))
7429       ;; For some reason, the group window gets selected.  We change
7430       ;; it back.
7431       (select-window (get-buffer-window (current-buffer)))
7432       ;; Select next unread newsgroup automagically.
7433       (cond
7434        ((or (not gnus-auto-select-next)
7435             (not cmd))
7436         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7437        ((or (eq gnus-auto-select-next 'quietly)
7438             (and (eq gnus-auto-select-next 'slightly-quietly)
7439                  push)
7440             (and (eq gnus-auto-select-next 'almost-quietly)
7441                  (gnus-summary-last-article-p)))
7442         ;; Select quietly.
7443         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7444             (gnus-summary-exit)
7445           (gnus-message 7 "No more%s articles (%s)..."
7446                         (if unread " unread" "")
7447                         (if group (concat "selecting " group)
7448                           "exiting"))
7449           (gnus-summary-next-group nil group backward)))
7450        (t
7451         (when (gnus-key-press-event-p last-input-event)
7452           (gnus-summary-walk-group-buffer
7453            gnus-newsgroup-name cmd unread backward point))))))))
7454
7455 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7456   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7457                       (?\C-p (gnus-group-prev-unread-group 1))))
7458         (cursor-in-echo-area t)
7459         keve key group ended prompt)
7460     (save-excursion
7461       (set-buffer gnus-group-buffer)
7462       (goto-char start)
7463       (setq group
7464             (if (eq gnus-keep-same-level 'best)
7465                 (gnus-summary-best-group gnus-newsgroup-name)
7466               (gnus-summary-search-group backward gnus-keep-same-level))))
7467     (while (not ended)
7468       (setq prompt
7469             (format
7470              "No more%s articles%s " (if unread " unread" "")
7471              (if (and group
7472                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7473                  (format " (Type %s for %s [%s])"
7474                          (single-key-description cmd)
7475                          (gnus-group-decoded-name group)
7476                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7477                (format " (Type %s to exit %s)"
7478                        (single-key-description cmd)
7479                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7480       ;; Confirm auto selection.
7481       (setq key (car (setq keve (gnus-read-event-char prompt)))
7482             ended t)
7483       (cond
7484        ((assq key keystrokes)
7485         (let ((obuf (current-buffer)))
7486           (switch-to-buffer gnus-group-buffer)
7487           (when group
7488             (gnus-group-jump-to-group group))
7489           (eval (cadr (assq key keystrokes)))
7490           (setq group (gnus-group-group-name))
7491           (switch-to-buffer obuf))
7492         (setq ended nil))
7493        ((equal key cmd)
7494         (if (or (not group)
7495                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7496             (gnus-summary-exit)
7497           (gnus-summary-next-group nil group backward)))
7498        (t
7499         (push (cdr keve) unread-command-events))))))
7500
7501 (defun gnus-summary-next-unread-article ()
7502   "Select unread article after current one."
7503   (interactive)
7504   (gnus-summary-next-article
7505    (or (not (eq gnus-summary-goto-unread 'never))
7506        (gnus-summary-last-article-p (gnus-summary-article-number)))
7507    (and gnus-auto-select-same
7508         (gnus-summary-article-subject))))
7509
7510 (defun gnus-summary-prev-article (&optional unread subject)
7511   "Select the article before the current one.
7512 If UNREAD is non-nil, only unread articles are selected."
7513   (interactive "P")
7514   (gnus-summary-next-article unread subject t))
7515
7516 (defun gnus-summary-prev-unread-article ()
7517   "Select unread article before current one."
7518   (interactive)
7519   (gnus-summary-prev-article
7520    (or (not (eq gnus-summary-goto-unread 'never))
7521        (gnus-summary-first-article-p (gnus-summary-article-number)))
7522    (and gnus-auto-select-same
7523         (gnus-summary-article-subject))))
7524
7525 (defun gnus-summary-next-page (&optional lines circular stop)
7526   "Show next page of the selected article.
7527 If at the end of the current article, select the next article.
7528 LINES says how many lines should be scrolled up.
7529
7530 If CIRCULAR is non-nil, go to the start of the article instead of
7531 selecting the next article when reaching the end of the current
7532 article.
7533
7534 If STOP is non-nil, just stop when reaching the end of the message.
7535
7536 Also see the variable `gnus-article-skip-boring'."
7537   (interactive "P")
7538   (setq gnus-summary-buffer (current-buffer))
7539   (gnus-set-global-variables)
7540   (let ((article (gnus-summary-article-number))
7541         (article-window (get-buffer-window gnus-article-buffer t))
7542         endp)
7543     ;; If the buffer is empty, we have no article.
7544     (unless article
7545       (error "No article to select"))
7546     (gnus-configure-windows 'article)
7547     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7548         (if (and (eq gnus-summary-goto-unread 'never)
7549                  (not (gnus-summary-last-article-p article)))
7550             (gnus-summary-next-article)
7551           (gnus-summary-next-unread-article))
7552       (if (or (null gnus-current-article)
7553               (null gnus-article-current)
7554               (/= article (cdr gnus-article-current))
7555               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7556           ;; Selected subject is different from current article's.
7557           (gnus-summary-display-article article)
7558         (when article-window
7559           (gnus-eval-in-buffer-window gnus-article-buffer
7560             (setq endp (or (gnus-article-next-page lines)
7561                            (gnus-article-only-boring-p))))
7562           (when endp
7563             (cond (stop
7564                    (gnus-message 3 "End of message"))
7565                   (circular
7566                    (gnus-summary-beginning-of-article))
7567                   (lines
7568                    (gnus-message 3 "End of message"))
7569                   ((null lines)
7570                    (if (and (eq gnus-summary-goto-unread 'never)
7571                             (not (gnus-summary-last-article-p article)))
7572                        (gnus-summary-next-article)
7573                      (gnus-summary-next-unread-article))))))))
7574     (gnus-summary-recenter)
7575     (gnus-summary-position-point)))
7576
7577 (defun gnus-summary-prev-page (&optional lines move)
7578   "Show previous page of selected article.
7579 Argument LINES specifies lines to be scrolled down.
7580 If MOVE, move to the previous unread article if point is at
7581 the beginning of the buffer."
7582   (interactive "P")
7583   (let ((article (gnus-summary-article-number))
7584         (article-window (get-buffer-window gnus-article-buffer t))
7585         endp)
7586     (gnus-configure-windows 'article)
7587     (if (or (null gnus-current-article)
7588             (null gnus-article-current)
7589             (/= article (cdr gnus-article-current))
7590             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7591         ;; Selected subject is different from current article's.
7592         (gnus-summary-display-article article)
7593       (gnus-summary-recenter)
7594       (when article-window
7595         (gnus-eval-in-buffer-window gnus-article-buffer
7596           (setq endp (gnus-article-prev-page lines)))
7597         (when (and move endp)
7598           (cond (lines
7599                  (gnus-message 3 "Beginning of message"))
7600                 ((null lines)
7601                  (if (and (eq gnus-summary-goto-unread 'never)
7602                           (not (gnus-summary-first-article-p article)))
7603                      (gnus-summary-prev-article)
7604                    (gnus-summary-prev-unread-article))))))))
7605   (gnus-summary-position-point))
7606
7607 (defun gnus-summary-prev-page-or-article (&optional lines)
7608   "Show previous page of selected article.
7609 Argument LINES specifies lines to be scrolled down.
7610 If at the beginning of the article, go to the next article."
7611   (interactive "P")
7612   (gnus-summary-prev-page lines t))
7613
7614 (defun gnus-summary-scroll-up (lines)
7615   "Scroll up (or down) one line current article.
7616 Argument LINES specifies lines to be scrolled up (or down if negative)."
7617   (interactive "p")
7618   (gnus-configure-windows 'article)
7619   (gnus-summary-show-thread)
7620   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7621     (gnus-eval-in-buffer-window gnus-article-buffer
7622       (cond ((> lines 0)
7623              (when (gnus-article-next-page lines)
7624                (gnus-message 3 "End of message")))
7625             ((< lines 0)
7626              (gnus-article-prev-page (- lines))))))
7627   (gnus-summary-recenter)
7628   (gnus-summary-position-point))
7629
7630 (defun gnus-summary-scroll-down (lines)
7631   "Scroll down (or up) one line current article.
7632 Argument LINES specifies lines to be scrolled down (or up if negative)."
7633   (interactive "p")
7634   (gnus-summary-scroll-up (- lines)))
7635
7636 (defun gnus-summary-next-same-subject ()
7637   "Select next article which has the same subject as current one."
7638   (interactive)
7639   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7640
7641 (defun gnus-summary-prev-same-subject ()
7642   "Select previous article which has the same subject as current one."
7643   (interactive)
7644   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7645
7646 (defun gnus-summary-next-unread-same-subject ()
7647   "Select next unread article which has the same subject as current one."
7648   (interactive)
7649   (gnus-summary-next-article t (gnus-summary-article-subject)))
7650
7651 (defun gnus-summary-prev-unread-same-subject ()
7652   "Select previous unread article which has the same subject as current one."
7653   (interactive)
7654   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7655
7656 (defun gnus-summary-first-unread-article ()
7657   "Select the first unread article.
7658 Return nil if there are no unread articles."
7659   (interactive)
7660   (prog1
7661       (when (gnus-summary-first-subject t)
7662         (gnus-summary-show-thread)
7663         (gnus-summary-first-subject t)
7664         (gnus-summary-display-article (gnus-summary-article-number)))
7665     (gnus-summary-position-point)))
7666
7667 (defun gnus-summary-first-unread-subject ()
7668   "Place the point on the subject line of the first unread article.
7669 Return nil if there are no unread articles."
7670   (interactive)
7671   (prog1
7672       (when (gnus-summary-first-subject t)
7673         (gnus-summary-show-thread)
7674         (gnus-summary-first-subject t))
7675     (gnus-summary-position-point)))
7676
7677 (defun gnus-summary-first-unseen-subject ()
7678   "Place the point on the subject line of the first unseen article.
7679 Return nil if there are no unseen articles."
7680   (interactive)
7681   (prog1
7682       (when (gnus-summary-first-subject nil nil t)
7683         (gnus-summary-show-thread)
7684         (gnus-summary-first-subject nil nil t))
7685     (gnus-summary-position-point)))
7686
7687 (defun gnus-summary-first-unseen-or-unread-subject ()
7688   "Place the point on the subject line of the first unseen article or,
7689 if all article have been seen, on the subject line of the first unread
7690 article."
7691   (interactive)
7692   (prog1
7693       (unless (when (gnus-summary-first-subject nil nil t)
7694                 (gnus-summary-show-thread)
7695                 (gnus-summary-first-subject nil nil t))
7696         (when (gnus-summary-first-subject t)
7697           (gnus-summary-show-thread)
7698           (gnus-summary-first-subject t)))
7699     (gnus-summary-position-point)))
7700
7701 (defun gnus-summary-first-article ()
7702   "Select the first article.
7703 Return nil if there are no articles."
7704   (interactive)
7705   (prog1
7706       (when (gnus-summary-first-subject)
7707         (gnus-summary-show-thread)
7708         (gnus-summary-first-subject)
7709         (gnus-summary-display-article (gnus-summary-article-number)))
7710     (gnus-summary-position-point)))
7711
7712 (defun gnus-summary-best-unread-article (&optional arg)
7713   "Select the unread article with the highest score.
7714 If given a prefix argument, select the next unread article that has a
7715 score higher than the default score."
7716   (interactive "P")
7717   (let ((article (if arg
7718                      (gnus-summary-better-unread-subject)
7719                    (gnus-summary-best-unread-subject))))
7720     (if article
7721         (gnus-summary-goto-article article)
7722       (error "No unread articles"))))
7723
7724 (defun gnus-summary-best-unread-subject ()
7725   "Select the unread subject with the highest score."
7726   (interactive)
7727   (let ((best -1000000)
7728         (data gnus-newsgroup-data)
7729         article score)
7730     (while data
7731       (and (gnus-data-unread-p (car data))
7732            (> (setq score
7733                     (gnus-summary-article-score (gnus-data-number (car data))))
7734               best)
7735            (setq best score
7736                  article (gnus-data-number (car data))))
7737       (setq data (cdr data)))
7738     (when article
7739       (gnus-summary-goto-subject article))
7740     (gnus-summary-position-point)
7741     article))
7742
7743 (defun gnus-summary-better-unread-subject ()
7744   "Select the first unread subject that has a score over the default score."
7745   (interactive)
7746   (let ((data gnus-newsgroup-data)
7747         article score)
7748     (while (and (setq article (gnus-data-number (car data)))
7749                 (or (gnus-data-read-p (car data))
7750                     (not (> (gnus-summary-article-score article)
7751                             gnus-summary-default-score))))
7752       (setq data (cdr data)))
7753     (when article
7754       (gnus-summary-goto-subject article))
7755     (gnus-summary-position-point)
7756     article))
7757
7758 (defun gnus-summary-last-subject ()
7759   "Go to the last displayed subject line in the group."
7760   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7761     (when article
7762       (gnus-summary-goto-subject article))))
7763
7764 (defun gnus-summary-goto-article (article &optional all-headers force)
7765   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7766 If ALL-HEADERS is non-nil, no header lines are hidden.
7767 If FORCE, go to the article even if it isn't displayed.  If FORCE
7768 is a number, it is the line the article is to be displayed on."
7769   (interactive
7770    (list
7771     (completing-read
7772      "Article number or Message-ID: "
7773      (mapcar (lambda (number) (list (int-to-string number)))
7774              gnus-newsgroup-limit))
7775     current-prefix-arg
7776     t))
7777   (prog1
7778       (if (and (stringp article)
7779                (string-match "@\\|%40" article))
7780           (gnus-summary-refer-article article)
7781         (when (stringp article)
7782           (setq article (string-to-number article)))
7783         (if (gnus-summary-goto-subject article force)
7784             (gnus-summary-display-article article all-headers)
7785           (gnus-message 4 "Couldn't go to article %s" article) nil))
7786     (gnus-summary-position-point)))
7787
7788 (defun gnus-summary-goto-last-article ()
7789   "Go to the previously read article."
7790   (interactive)
7791   (prog1
7792       (when gnus-last-article
7793         (gnus-summary-goto-article gnus-last-article nil t))
7794     (gnus-summary-position-point)))
7795
7796 (defun gnus-summary-pop-article (number)
7797   "Pop one article off the history and go to the previous.
7798 NUMBER articles will be popped off."
7799   (interactive "p")
7800   (let (to)
7801     (setq gnus-newsgroup-history
7802           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7803     (if to
7804         (gnus-summary-goto-article (car to) nil t)
7805       (error "Article history empty")))
7806   (gnus-summary-position-point))
7807
7808 ;; Summary commands and functions for limiting the summary buffer.
7809
7810 (defun gnus-summary-limit-to-articles (n)
7811   "Limit the summary buffer to the next N articles.
7812 If not given a prefix, use the process marked articles instead."
7813   (interactive "P")
7814   (prog1
7815       (let ((articles (gnus-summary-work-articles n)))
7816         (setq gnus-newsgroup-processable nil)
7817         (gnus-summary-limit articles))
7818     (gnus-summary-position-point)))
7819
7820 (defun gnus-summary-pop-limit (&optional total)
7821   "Restore the previous limit.
7822 If given a prefix, remove all limits."
7823   (interactive "P")
7824   (when total
7825     (setq gnus-newsgroup-limits
7826           (list (mapcar (lambda (h) (mail-header-number h))
7827                         gnus-newsgroup-headers))))
7828   (unless gnus-newsgroup-limits
7829     (error "No limit to pop"))
7830   (prog1
7831       (gnus-summary-limit nil 'pop)
7832     (gnus-summary-position-point)))
7833
7834 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7835   "Limit the summary buffer to articles that have subjects that match a regexp.
7836 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7837   (interactive
7838    (list (read-string (if current-prefix-arg
7839                           "Exclude subject (regexp): "
7840                         "Limit to subject (regexp): "))
7841          nil current-prefix-arg))
7842   (unless header
7843     (setq header "subject"))
7844   (when (not (equal "" subject))
7845     (prog1
7846         (let ((articles (gnus-summary-find-matching
7847                          (or header "subject") subject 'all nil nil
7848                          not-matching)))
7849           (unless articles
7850             (error "Found no matches for \"%s\"" subject))
7851           (gnus-summary-limit articles))
7852       (gnus-summary-position-point))))
7853
7854 (defun gnus-summary-limit-to-author (from &optional not-matching)
7855   "Limit the summary buffer to articles that have authors that match a regexp.
7856 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7857   (interactive
7858    (list (read-string (if current-prefix-arg
7859                           "Exclude author (regexp): "
7860                         "Limit to author (regexp): "))
7861          current-prefix-arg))
7862   (gnus-summary-limit-to-subject from "from" not-matching))
7863
7864 (defun gnus-summary-limit-to-age (age &optional younger-p)
7865   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7866 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7867 articles that are younger than AGE days."
7868   (interactive
7869    (let ((younger current-prefix-arg)
7870          (days-got nil)
7871          days)
7872      (while (not days-got)
7873        (setq days (if younger
7874                       (read-string "Limit to articles younger than (in days, older when negative): ")
7875                     (read-string
7876                      "Limit to articles older than (in days, younger when negative): ")))
7877        (when (> (length days) 0)
7878          (setq days (read days)))
7879        (if (numberp days)
7880            (progn
7881              (setq days-got t)
7882              (if (< days 0)
7883                  (progn
7884                    (setq younger (not younger))
7885                    (setq days (* days -1)))))
7886          (message "Please enter a number.")
7887          (sleep-for 1)))
7888      (list days younger)))
7889   (prog1
7890       (let ((data gnus-newsgroup-data)
7891             (cutoff (days-to-time age))
7892             articles d date is-younger)
7893         (while (setq d (pop data))
7894           (when (and (vectorp (gnus-data-header d))
7895                      (setq date (mail-header-date (gnus-data-header d))))
7896             (setq is-younger (time-less-p
7897                               (time-since (condition-case ()
7898                                               (date-to-time date)
7899                                             (error '(0 0))))
7900                               cutoff))
7901             (when (if younger-p
7902                       is-younger
7903                     (not is-younger))
7904               (push (gnus-data-number d) articles))))
7905         (gnus-summary-limit (nreverse articles)))
7906     (gnus-summary-position-point)))
7907
7908 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7909   "Limit the summary buffer to articles that match an 'extra' header."
7910   (interactive
7911    (let ((header
7912           (intern
7913            (gnus-completing-read-with-default
7914             (symbol-name (car gnus-extra-headers))
7915             (if current-prefix-arg
7916                 "Exclude extra header"
7917               "Limit extra header")
7918             (mapcar (lambda (x)
7919                       (cons (symbol-name x) x))
7920                     gnus-extra-headers)
7921             nil
7922             t))))
7923      (list header
7924            (read-string (format "%s header %s (regexp): "
7925                                 (if current-prefix-arg "Exclude" "Limit to")
7926                                 header))
7927            current-prefix-arg)))
7928   (when (not (equal "" regexp))
7929     (prog1
7930         (let ((articles (gnus-summary-find-matching
7931                          (cons 'extra header) regexp 'all nil nil
7932                          not-matching)))
7933           (unless articles
7934             (error "Found no matches for \"%s\"" regexp))
7935           (gnus-summary-limit articles))
7936       (gnus-summary-position-point))))
7937
7938 (defun gnus-summary-limit-to-display-predicate ()
7939   "Limit the summary buffer to the predicated in the `display' group parameter."
7940   (interactive)
7941   (unless gnus-newsgroup-display
7942     (error "There is no `display' group parameter"))
7943   (let (articles)
7944     (dolist (number gnus-newsgroup-articles)
7945       (when (funcall gnus-newsgroup-display)
7946         (push number articles)))
7947     (gnus-summary-limit articles))
7948   (gnus-summary-position-point))
7949
7950 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7951 (make-obsolete
7952  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7953
7954 (defun gnus-summary-limit-to-unread (&optional all)
7955   "Limit the summary buffer to articles that are not marked as read.
7956 If ALL is non-nil, limit strictly to unread articles."
7957   (interactive "P")
7958   (if all
7959       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7960     (gnus-summary-limit-to-marks
7961      ;; Concat all the marks that say that an article is read and have
7962      ;; those removed.
7963      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7964            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7965            gnus-low-score-mark gnus-expirable-mark
7966            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7967            gnus-duplicate-mark gnus-souped-mark)
7968      'reverse)))
7969
7970 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7971 (make-obsolete 'gnus-summary-delete-marked-with
7972                'gnus-summary-limit-exclude-marks)
7973
7974 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7975   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7976 If REVERSE, limit the summary buffer to articles that are marked
7977 with MARKS.  MARKS can either be a string of marks or a list of marks.
7978 Returns how many articles were removed."
7979   (interactive "sMarks: ")
7980   (gnus-summary-limit-to-marks marks t))
7981
7982 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7983   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7984 If REVERSE (the prefix), limit the summary buffer to articles that are
7985 not marked with MARKS.  MARKS can either be a string of marks or a
7986 list of marks.
7987 Returns how many articles were removed."
7988   (interactive "sMarks: \nP")
7989   (prog1
7990       (let ((data gnus-newsgroup-data)
7991             (marks (if (listp marks) marks
7992                      (append marks nil))) ; Transform to list.
7993             articles)
7994         (while data
7995           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7996                   (memq (gnus-data-mark (car data)) marks))
7997             (push (gnus-data-number (car data)) articles))
7998           (setq data (cdr data)))
7999         (gnus-summary-limit articles))
8000     (gnus-summary-position-point)))
8001
8002 (defun gnus-summary-limit-to-score (score)
8003   "Limit to articles with score at or above SCORE."
8004   (interactive "NLimit to articles with score of at least: ")
8005   (let ((data gnus-newsgroup-data)
8006         articles)
8007     (while data
8008       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8009                 score)
8010         (push (gnus-data-number (car data)) articles))
8011       (setq data (cdr data)))
8012     (prog1
8013         (gnus-summary-limit articles)
8014       (gnus-summary-position-point))))
8015
8016 (defun gnus-summary-limit-to-unseen ()
8017   "Limit to unseen articles."
8018   (interactive)
8019   (prog1
8020       (gnus-summary-limit gnus-newsgroup-unseen)
8021     (gnus-summary-position-point)))
8022
8023 (defun gnus-summary-limit-include-thread (id)
8024   "Display all the hidden articles that is in the thread with ID in it.
8025 When called interactively, ID is the Message-ID of the current
8026 article."
8027   (interactive (list (mail-header-id (gnus-summary-article-header))))
8028   (let ((articles (gnus-articles-in-thread
8029                    (gnus-id-to-thread (gnus-root-id id)))))
8030     (prog1
8031         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8032       (gnus-summary-limit-include-matching-articles
8033        "subject"
8034        (regexp-quote (gnus-simplify-subject-re
8035                       (mail-header-subject (gnus-id-to-header id)))))
8036       (gnus-summary-position-point))))
8037
8038 (defun gnus-summary-limit-include-matching-articles (header regexp)
8039   "Display all the hidden articles that have HEADERs that match REGEXP."
8040   (interactive (list (read-string "Match on header: ")
8041                      (read-string "Regexp: ")))
8042   (let ((articles (gnus-find-matching-articles header regexp)))
8043     (prog1
8044         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8045       (gnus-summary-position-point))))
8046
8047 (defun gnus-summary-insert-dormant-articles ()
8048   "Insert all the dormant articles for this group into the current buffer."
8049   (interactive)
8050   (let ((gnus-verbose (max 6 gnus-verbose)))
8051     (if (not gnus-newsgroup-dormant)
8052         (gnus-message 3 "No dormant articles for this group")
8053       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8054
8055 (defun gnus-summary-limit-include-dormant ()
8056   "Display all the hidden articles that are marked as dormant.
8057 Note that this command only works on a subset of the articles currently
8058 fetched for this group."
8059   (interactive)
8060   (unless gnus-newsgroup-dormant
8061     (error "There are no dormant articles in this group"))
8062   (prog1
8063       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8064     (gnus-summary-position-point)))
8065
8066 (defun gnus-summary-limit-exclude-dormant ()
8067   "Hide all dormant articles."
8068   (interactive)
8069   (prog1
8070       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8071     (gnus-summary-position-point)))
8072
8073 (defun gnus-summary-limit-exclude-childless-dormant ()
8074   "Hide all dormant articles that have no children."
8075   (interactive)
8076   (let ((data (gnus-data-list t))
8077         articles d children)
8078     ;; Find all articles that are either not dormant or have
8079     ;; children.
8080     (while (setq d (pop data))
8081       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8082                 (and (setq children
8083                            (gnus-article-children (gnus-data-number d)))
8084                      (let (found)
8085                        (while children
8086                          (when (memq (car children) articles)
8087                            (setq children nil
8088                                  found t))
8089                          (pop children))
8090                        found)))
8091         (push (gnus-data-number d) articles)))
8092     ;; Do the limiting.
8093     (prog1
8094         (gnus-summary-limit articles)
8095       (gnus-summary-position-point))))
8096
8097 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8098   "Mark all unread excluded articles as read.
8099 If ALL, mark even excluded ticked and dormants as read."
8100   (interactive "P")
8101   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8102   (let ((articles (gnus-sorted-ndifference
8103                    (sort
8104                     (mapcar (lambda (h) (mail-header-number h))
8105                             gnus-newsgroup-headers)
8106                     '<)
8107                    gnus-newsgroup-limit))
8108         article)
8109     (setq gnus-newsgroup-unreads
8110           (gnus-sorted-intersection gnus-newsgroup-unreads
8111                                     gnus-newsgroup-limit))
8112     (if all
8113         (setq gnus-newsgroup-dormant nil
8114               gnus-newsgroup-marked nil
8115               gnus-newsgroup-reads
8116               (nconc
8117                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8118                gnus-newsgroup-reads))
8119       (while (setq article (pop articles))
8120         (unless (or (memq article gnus-newsgroup-dormant)
8121                     (memq article gnus-newsgroup-marked))
8122           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8123
8124 (defun gnus-summary-limit (articles &optional pop)
8125   (if pop
8126       ;; We pop the previous limit off the stack and use that.
8127       (setq articles (car gnus-newsgroup-limits)
8128             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8129     ;; We use the new limit, so we push the old limit on the stack.
8130     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8131   ;; Set the limit.
8132   (setq gnus-newsgroup-limit articles)
8133   (let ((total (length gnus-newsgroup-data))
8134         (data (gnus-data-find-list (gnus-summary-article-number)))
8135         (gnus-summary-mark-below nil)   ; Inhibit this.
8136         found)
8137     ;; This will do all the work of generating the new summary buffer
8138     ;; according to the new limit.
8139     (gnus-summary-prepare)
8140     ;; Hide any threads, possibly.
8141     (gnus-summary-maybe-hide-threads)
8142     ;; Try to return to the article you were at, or one in the
8143     ;; neighborhood.
8144     (when data
8145       ;; We try to find some article after the current one.
8146       (while data
8147         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8148           (setq data nil
8149                 found t))
8150         (setq data (cdr data))))
8151     (unless found
8152       ;; If there is no data, that means that we were after the last
8153       ;; article.  The same goes when we can't find any articles
8154       ;; after the current one.
8155       (goto-char (point-max))
8156       (gnus-summary-find-prev))
8157     (gnus-set-mode-line 'summary)
8158     ;; We return how many articles were removed from the summary
8159     ;; buffer as a result of the new limit.
8160     (- total (length gnus-newsgroup-data))))
8161
8162 (defsubst gnus-invisible-cut-children (threads)
8163   (let ((num 0))
8164     (while threads
8165       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8166         (incf num))
8167       (pop threads))
8168     (< num 2)))
8169
8170 (defsubst gnus-cut-thread (thread)
8171   "Go forwards in the thread until we find an article that we want to display."
8172   (when (or (eq gnus-fetch-old-headers 'some)
8173             (eq gnus-fetch-old-headers 'invisible)
8174             (numberp gnus-fetch-old-headers)
8175             (eq gnus-build-sparse-threads 'some)
8176             (eq gnus-build-sparse-threads 'more))
8177     ;; Deal with old-fetched headers and sparse threads.
8178     (while (and
8179             thread
8180             (or
8181              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8182              (gnus-summary-article-ancient-p
8183               (mail-header-number (car thread))))
8184             (if (or (<= (length (cdr thread)) 1)
8185                     (eq gnus-fetch-old-headers 'invisible))
8186                 (setq gnus-newsgroup-limit
8187                       (delq (mail-header-number (car thread))
8188                             gnus-newsgroup-limit)
8189                       thread (cadr thread))
8190               (when (gnus-invisible-cut-children (cdr thread))
8191                 (let ((th (cdr thread)))
8192                   (while th
8193                     (if (memq (mail-header-number (caar th))
8194                               gnus-newsgroup-limit)
8195                         (setq thread (car th)
8196                               th nil)
8197                       (setq th (cdr th))))))))))
8198   thread)
8199
8200 (defun gnus-cut-threads (threads)
8201   "Cut off all uninteresting articles from the beginning of THREADS."
8202   (when (or (eq gnus-fetch-old-headers 'some)
8203             (eq gnus-fetch-old-headers 'invisible)
8204             (numberp gnus-fetch-old-headers)
8205             (eq gnus-build-sparse-threads 'some)
8206             (eq gnus-build-sparse-threads 'more))
8207     (let ((th threads))
8208       (while th
8209         (setcar th (gnus-cut-thread (car th)))
8210         (setq th (cdr th)))))
8211   ;; Remove nixed out threads.
8212   (delq nil threads))
8213
8214 (defun gnus-summary-initial-limit (&optional show-if-empty)
8215   "Figure out what the initial limit is supposed to be on group entry.
8216 This entails weeding out unwanted dormants, low-scored articles,
8217 fetch-old-headers verbiage, and so on."
8218   ;; Most groups have nothing to remove.
8219   (if (or gnus-inhibit-limiting
8220           (and (null gnus-newsgroup-dormant)
8221                (eq gnus-newsgroup-display 'gnus-not-ignore)
8222                (not (eq gnus-fetch-old-headers 'some))
8223                (not (numberp gnus-fetch-old-headers))
8224                (not (eq gnus-fetch-old-headers 'invisible))
8225                (null gnus-summary-expunge-below)
8226                (not (eq gnus-build-sparse-threads 'some))
8227                (not (eq gnus-build-sparse-threads 'more))
8228                (null gnus-thread-expunge-below)
8229                (not gnus-use-nocem)))
8230       ()                                ; Do nothing.
8231     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8232     (setq gnus-newsgroup-limit nil)
8233     (mapatoms
8234      (lambda (node)
8235        (unless (car (symbol-value node))
8236          ;; These threads have no parents -- they are roots.
8237          (let ((nodes (cdr (symbol-value node)))
8238                thread)
8239            (while nodes
8240              (if (and gnus-thread-expunge-below
8241                       (< (gnus-thread-total-score (car nodes))
8242                          gnus-thread-expunge-below))
8243                  (gnus-expunge-thread (pop nodes))
8244                (setq thread (pop nodes))
8245                (gnus-summary-limit-children thread))))))
8246      gnus-newsgroup-dependencies)
8247     ;; If this limitation resulted in an empty group, we might
8248     ;; pop the previous limit and use it instead.
8249     (when (and (not gnus-newsgroup-limit)
8250                show-if-empty)
8251       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8252     gnus-newsgroup-limit))
8253
8254 (defun gnus-summary-limit-children (thread)
8255   "Return 1 if this subthread is visible and 0 if it is not."
8256   ;; First we get the number of visible children to this thread.  This
8257   ;; is done by recursing down the thread using this function, so this
8258   ;; will really go down to a leaf article first, before slowly
8259   ;; working its way up towards the root.
8260   (when thread
8261     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8262            (children
8263            (if (cdr thread)
8264                (apply '+ (mapcar 'gnus-summary-limit-children
8265                                  (cdr thread)))
8266              0))
8267           (number (mail-header-number (car thread)))
8268           score)
8269       (if (and
8270            (not (memq number gnus-newsgroup-marked))
8271            (or
8272             ;; If this article is dormant and has absolutely no visible
8273             ;; children, then this article isn't visible.
8274             (and (memq number gnus-newsgroup-dormant)
8275                  (zerop children))
8276             ;; If this is "fetch-old-headered" and there is no
8277             ;; visible children, then we don't want this article.
8278             (and (or (eq gnus-fetch-old-headers 'some)
8279                      (numberp gnus-fetch-old-headers))
8280                  (gnus-summary-article-ancient-p number)
8281                  (zerop children))
8282             ;; If this is "fetch-old-headered" and `invisible', then
8283             ;; we don't want this article.
8284             (and (eq gnus-fetch-old-headers 'invisible)
8285                  (gnus-summary-article-ancient-p number))
8286             ;; If this is a sparsely inserted article with no children,
8287             ;; we don't want it.
8288             (and (eq gnus-build-sparse-threads 'some)
8289                  (gnus-summary-article-sparse-p number)
8290                  (zerop children))
8291             ;; If we use expunging, and this article is really
8292             ;; low-scored, then we don't want this article.
8293             (when (and gnus-summary-expunge-below
8294                        (< (setq score
8295                                 (or (cdr (assq number gnus-newsgroup-scored))
8296                                     gnus-summary-default-score))
8297                           gnus-summary-expunge-below))
8298               ;; We increase the expunge-tally here, but that has
8299               ;; nothing to do with the limits, really.
8300               (incf gnus-newsgroup-expunged-tally)
8301               ;; We also mark as read here, if that's wanted.
8302               (when (and gnus-summary-mark-below
8303                          (< score gnus-summary-mark-below))
8304                 (setq gnus-newsgroup-unreads
8305                       (delq number gnus-newsgroup-unreads))
8306                 (if gnus-newsgroup-auto-expire
8307                     (push number gnus-newsgroup-expirable)
8308                   (push (cons number gnus-low-score-mark)
8309                         gnus-newsgroup-reads)))
8310               t)
8311             ;; Do the `display' group parameter.
8312             (and gnus-newsgroup-display
8313                  (not (funcall gnus-newsgroup-display)))
8314             ;; Check NoCeM things.
8315             (if (and gnus-use-nocem
8316                      (gnus-nocem-unwanted-article-p
8317                       (mail-header-id (car thread))))
8318                 (progn
8319                   (setq gnus-newsgroup-unreads
8320                         (delq number gnus-newsgroup-unreads))
8321                   t))))
8322           ;; Nope, invisible article.
8323           0
8324         ;; Ok, this article is to be visible, so we add it to the limit
8325         ;; and return 1.
8326         (push number gnus-newsgroup-limit)
8327         1))))
8328
8329 (defun gnus-expunge-thread (thread)
8330   "Mark all articles in THREAD as read."
8331   (let* ((number (mail-header-number (car thread))))
8332     (incf gnus-newsgroup-expunged-tally)
8333     ;; We also mark as read here, if that's wanted.
8334     (setq gnus-newsgroup-unreads
8335           (delq number gnus-newsgroup-unreads))
8336     (if gnus-newsgroup-auto-expire
8337         (push number gnus-newsgroup-expirable)
8338       (push (cons number gnus-low-score-mark)
8339             gnus-newsgroup-reads)))
8340   ;; Go recursively through all subthreads.
8341   (mapcar 'gnus-expunge-thread (cdr thread)))
8342
8343 ;; Summary article oriented commands
8344
8345 (defun gnus-summary-refer-parent-article (n)
8346   "Refer parent article N times.
8347 If N is negative, go to ancestor -N instead.
8348 The difference between N and the number of articles fetched is returned."
8349   (interactive "p")
8350   (let ((skip 1)
8351         error header ref)
8352     (when (not (natnump n))
8353       (setq skip (abs n)
8354             n 1))
8355     (while (and (> n 0)
8356                 (not error))
8357       (setq header (gnus-summary-article-header))
8358       (if (and (eq (mail-header-number header)
8359                    (cdr gnus-article-current))
8360                (equal gnus-newsgroup-name
8361                       (car gnus-article-current)))
8362           ;; If we try to find the parent of the currently
8363           ;; displayed article, then we take a look at the actual
8364           ;; References header, since this is slightly more
8365           ;; reliable than the References field we got from the
8366           ;; server.
8367           (save-excursion
8368             (set-buffer gnus-original-article-buffer)
8369             (nnheader-narrow-to-headers)
8370             (unless (setq ref (message-fetch-field "references"))
8371               (when (setq ref (message-fetch-field "in-reply-to"))
8372                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8373             (widen))
8374         (setq ref
8375               ;; It's not the current article, so we take a bet on
8376               ;; the value we got from the server.
8377               (mail-header-references header)))
8378       (if (and ref
8379                (not (equal ref "")))
8380           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8381             (gnus-message 1 "Couldn't find parent"))
8382         (gnus-message 1 "No references in article %d"
8383                       (gnus-summary-article-number))
8384         (setq error t))
8385       (decf n))
8386     (gnus-summary-position-point)
8387     n))
8388
8389 (defun gnus-summary-refer-references ()
8390   "Fetch all articles mentioned in the References header.
8391 Return the number of articles fetched."
8392   (interactive)
8393   (let ((ref (mail-header-references (gnus-summary-article-header)))
8394         (current (gnus-summary-article-number))
8395         (n 0))
8396     (if (or (not ref)
8397             (equal ref ""))
8398         (error "No References in the current article")
8399       ;; For each Message-ID in the References header...
8400       (while (string-match "<[^>]*>" ref)
8401         (incf n)
8402         ;; ... fetch that article.
8403         (gnus-summary-refer-article
8404          (prog1 (match-string 0 ref)
8405            (setq ref (substring ref (match-end 0))))))
8406       (gnus-summary-goto-subject current)
8407       (gnus-summary-position-point)
8408       n)))
8409
8410 (defun gnus-summary-refer-thread (&optional limit)
8411   "Fetch all articles in the current thread.
8412 If LIMIT (the numerical prefix), fetch that many old headers instead
8413 of what's specified by the `gnus-refer-thread-limit' variable."
8414   (interactive "P")
8415   (let ((id (mail-header-id (gnus-summary-article-header)))
8416         (limit (if limit (prefix-numeric-value limit)
8417                  gnus-refer-thread-limit)))
8418     (unless (eq gnus-fetch-old-headers 'invisible)
8419       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8420       ;; Retrieve the headers and read them in.
8421       (if (eq (if (numberp limit)
8422                   (gnus-retrieve-headers
8423                    (list (min
8424                           (+ (mail-header-number
8425                               (gnus-summary-article-header))
8426                              limit)
8427                           gnus-newsgroup-end))
8428                    gnus-newsgroup-name (* limit 2))
8429                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8430                 ;; headers.
8431                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8432                                        gnus-newsgroup-name limit))
8433               'nov)
8434           (gnus-build-all-threads)
8435         (error "Can't fetch thread from back ends that don't support NOV"))
8436       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8437     (gnus-summary-limit-include-thread id)))
8438
8439 (defun gnus-summary-refer-article (message-id)
8440   "Fetch an article specified by MESSAGE-ID."
8441   (interactive "sMessage-ID: ")
8442   (when (and (stringp message-id)
8443              (not (zerop (length message-id))))
8444     (setq message-id (gnus-replace-in-string message-id " " ""))
8445     ;; Construct the correct Message-ID if necessary.
8446     ;; Suggested by tale@pawl.rpi.edu.
8447     (unless (string-match "^<" message-id)
8448       (setq message-id (concat "<" message-id)))
8449     (unless (string-match ">$" message-id)
8450       (setq message-id (concat message-id ">")))
8451     ;; People often post MIDs from URLs, so unhex it:
8452     (unless (string-match "@" message-id)
8453       (setq message-id (gnus-url-unhex-string message-id)))
8454     (let* ((header (gnus-id-to-header message-id))
8455            (sparse (and header
8456                         (gnus-summary-article-sparse-p
8457                          (mail-header-number header))
8458                         (memq (mail-header-number header)
8459                               gnus-newsgroup-limit)))
8460            number)
8461       (cond
8462        ;; If the article is present in the buffer we just go to it.
8463        ((and header
8464              (or (not (gnus-summary-article-sparse-p
8465                        (mail-header-number header)))
8466                  sparse))
8467         (prog1
8468             (gnus-summary-goto-article
8469              (mail-header-number header) nil t)
8470           (when sparse
8471             (gnus-summary-update-article (mail-header-number header)))))
8472        (t
8473         ;; We fetch the article.
8474         (catch 'found
8475           (dolist (gnus-override-method (gnus-refer-article-methods))
8476             (when (and (gnus-check-server gnus-override-method)
8477                        ;; Fetch the header,
8478                        (setq number (gnus-summary-insert-subject message-id)))
8479               ;; and display the article.
8480               (gnus-summary-select-article nil nil nil number)
8481               (throw 'found t)))
8482           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8483
8484 (defun gnus-refer-article-methods ()
8485   "Return a list of referable methods."
8486   (cond
8487    ;; No method, so we default to current and native.
8488    ((null gnus-refer-article-method)
8489     (list gnus-current-select-method gnus-select-method))
8490    ;; Current.
8491    ((eq 'current gnus-refer-article-method)
8492     (list gnus-current-select-method))
8493    ;; List of select methods.
8494    ((not (and (symbolp (car gnus-refer-article-method))
8495               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8496     (let (out)
8497       (dolist (method gnus-refer-article-method)
8498         (push (if (eq 'current method)
8499                   gnus-current-select-method
8500                 method)
8501               out))
8502       (nreverse out)))
8503    ;; One single select method.
8504    (t
8505     (list gnus-refer-article-method))))
8506
8507 (defun gnus-summary-edit-parameters ()
8508   "Edit the group parameters of the current group."
8509   (interactive)
8510   (gnus-group-edit-group gnus-newsgroup-name 'params))
8511
8512 (defun gnus-summary-customize-parameters ()
8513   "Customize the group parameters of the current group."
8514   (interactive)
8515   (gnus-group-customize gnus-newsgroup-name))
8516
8517 (defun gnus-summary-enter-digest-group (&optional force)
8518   "Enter an nndoc group based on the current article.
8519 If FORCE, force a digest interpretation.  If not, try
8520 to guess what the document format is."
8521   (interactive "P")
8522   (let ((conf gnus-current-window-configuration))
8523     (save-window-excursion
8524       (save-excursion
8525         (let (gnus-article-prepare-hook
8526               gnus-display-mime-function
8527               gnus-break-pages)
8528           (gnus-summary-select-article))))
8529     (setq gnus-current-window-configuration conf)
8530     (let* ((name (format "%s-%d"
8531                          (gnus-group-prefixed-name
8532                           gnus-newsgroup-name (list 'nndoc ""))
8533                          (save-excursion
8534                            (set-buffer gnus-summary-buffer)
8535                            gnus-current-article)))
8536            (ogroup gnus-newsgroup-name)
8537            (params (append (gnus-info-params (gnus-get-info ogroup))
8538                            (list (cons 'to-group ogroup))
8539                            (list (cons 'parent-group ogroup))
8540                            (list (cons 'save-article-group ogroup))))
8541            (case-fold-search t)
8542            (buf (current-buffer))
8543            dig to-address)
8544       (save-excursion
8545         (set-buffer gnus-original-article-buffer)
8546         ;; Have the digest group inherit the main mail address of
8547         ;; the parent article.
8548         (when (setq to-address (or (gnus-fetch-field "reply-to")
8549                                    (gnus-fetch-field "from")))
8550           (setq params
8551                 (append
8552                  (list (cons 'to-address
8553                              (funcall gnus-decode-encoded-address-function
8554                                       to-address))))))
8555         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8556         (insert-buffer-substring gnus-original-article-buffer)
8557         ;; Remove lines that may lead nndoc to misinterpret the
8558         ;; document type.
8559         (narrow-to-region
8560          (goto-char (point-min))
8561          (or (search-forward "\n\n" nil t) (point)))
8562         (goto-char (point-min))
8563         (delete-matching-lines "^Path:\\|^From ")
8564         (widen))
8565       (unwind-protect
8566           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8567                     (gnus-newsgroup-ephemeral-ignored-charsets
8568                      gnus-newsgroup-ignored-charsets))
8569                 (gnus-group-read-ephemeral-group
8570                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8571                               (nndoc-article-type
8572                                ,(if force 'mbox 'guess)))
8573                  t nil nil nil
8574                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8575                                                         "ADAPT")))))
8576               ;; Make all postings to this group go to the parent group.
8577               (nconc (gnus-info-params (gnus-get-info name))
8578                      params)
8579             ;; Couldn't select this doc group.
8580             (switch-to-buffer buf)
8581             (gnus-set-global-variables)
8582             (gnus-configure-windows 'summary)
8583             (gnus-message 3 "Article couldn't be entered?"))
8584         (kill-buffer dig)))))
8585
8586 (defun gnus-summary-read-document (n)
8587   "Open a new group based on the current article(s).
8588 This will allow you to read digests and other similar
8589 documents as newsgroups.
8590 Obeys the standard process/prefix convention."
8591   (interactive "P")
8592   (let* ((articles (gnus-summary-work-articles n))
8593          (ogroup gnus-newsgroup-name)
8594          (params (append (gnus-info-params (gnus-get-info ogroup))
8595                          (list (cons 'to-group ogroup))))
8596          article group egroup groups vgroup)
8597     (while (setq article (pop articles))
8598       (setq group (format "%s-%d" gnus-newsgroup-name article))
8599       (gnus-summary-remove-process-mark article)
8600       (when (gnus-summary-display-article article)
8601         (save-excursion
8602           (with-temp-buffer
8603             (insert-buffer-substring gnus-original-article-buffer)
8604             ;; Remove some headers that may lead nndoc to make
8605             ;; the wrong guess.
8606             (message-narrow-to-head)
8607             (goto-char (point-min))
8608             (delete-matching-lines "^\\(Path\\):\\|^From ")
8609             (widen)
8610             (if (setq egroup
8611                       (gnus-group-read-ephemeral-group
8612                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8613                                      (nndoc-article-type guess))
8614                        t nil t))
8615                 (progn
8616             ;; Make all postings to this group go to the parent group.
8617                   (nconc (gnus-info-params (gnus-get-info egroup))
8618                          params)
8619                   (push egroup groups))
8620               ;; Couldn't select this doc group.
8621               (gnus-error 3 "Article couldn't be entered"))))))
8622     ;; Now we have selected all the documents.
8623     (cond
8624      ((not groups)
8625       (error "None of the articles could be interpreted as documents"))
8626      ((gnus-group-read-ephemeral-group
8627        (setq vgroup (format
8628                      "nnvirtual:%s-%s" gnus-newsgroup-name
8629                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8630        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8631        t
8632        (cons (current-buffer) 'summary)))
8633      (t
8634       (error "Couldn't select virtual nndoc group")))))
8635
8636 (defun gnus-summary-isearch-article (&optional regexp-p)
8637   "Do incremental search forward on the current article.
8638 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8639   (interactive "P")
8640   (gnus-summary-select-article)
8641   (gnus-configure-windows 'article)
8642   (gnus-eval-in-buffer-window gnus-article-buffer
8643     (save-restriction
8644       (widen)
8645       (isearch-forward regexp-p))))
8646
8647 (defun gnus-summary-search-article-forward (regexp &optional backward)
8648   "Search for an article containing REGEXP forward.
8649 If BACKWARD, search backward instead."
8650   (interactive
8651    (list (read-string
8652           (format "Search article %s (regexp%s): "
8653                   (if current-prefix-arg "backward" "forward")
8654                   (if gnus-last-search-regexp
8655                       (concat ", default " gnus-last-search-regexp)
8656                     "")))
8657          current-prefix-arg))
8658   (if (string-equal regexp "")
8659       (setq regexp (or gnus-last-search-regexp ""))
8660     (setq gnus-last-search-regexp regexp)
8661     (setq gnus-article-before-search gnus-current-article))
8662   ;; Intentionally set gnus-last-article.
8663   (setq gnus-last-article gnus-article-before-search)
8664   (let ((gnus-last-article gnus-last-article))
8665     (if (gnus-summary-search-article regexp backward)
8666         (gnus-summary-show-thread)
8667       (signal 'search-failed (list regexp)))))
8668
8669 (defun gnus-summary-search-article-backward (regexp)
8670   "Search for an article containing REGEXP backward."
8671   (interactive
8672    (list (read-string
8673           (format "Search article backward (regexp%s): "
8674                   (if gnus-last-search-regexp
8675                       (concat ", default " gnus-last-search-regexp)
8676                     "")))))
8677   (gnus-summary-search-article-forward regexp 'backward))
8678
8679 (defun gnus-summary-search-article (regexp &optional backward)
8680   "Search for an article containing REGEXP.
8681 Optional argument BACKWARD means do search for backward.
8682 `gnus-select-article-hook' is not called during the search."
8683   ;; We have to require this here to make sure that the following
8684   ;; dynamic binding isn't shadowed by autoloading.
8685   (require 'gnus-async)
8686   (require 'gnus-art)
8687   (let ((gnus-select-article-hook nil)  ;Disable hook.
8688         (gnus-article-prepare-hook nil)
8689         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8690         (gnus-use-article-prefetch nil)
8691         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8692         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8693         (gnus-visual nil)
8694         (gnus-keep-backlog nil)
8695         (gnus-break-pages nil)
8696         (gnus-summary-display-arrow nil)
8697         (gnus-updated-mode-lines nil)
8698         (gnus-auto-center-summary nil)
8699         (sum (current-buffer))
8700         (gnus-display-mime-function nil)
8701         (found nil)
8702         point)
8703     (gnus-save-hidden-threads
8704       (gnus-summary-select-article)
8705       (set-buffer gnus-article-buffer)
8706       (goto-char (window-point (get-buffer-window (current-buffer))))
8707       (when backward
8708         (forward-line -1))
8709       (while (not found)
8710         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8711         (if (if backward
8712                 (re-search-backward regexp nil t)
8713               (re-search-forward regexp nil t))
8714             ;; We found the regexp.
8715             (progn
8716               (setq found 'found)
8717               (beginning-of-line)
8718               (set-window-start
8719                (get-buffer-window (current-buffer))
8720                (point))
8721               (forward-line 1)
8722               (set-window-point
8723                (get-buffer-window (current-buffer))
8724                (point))
8725               (set-buffer sum)
8726               (setq point (point)))
8727           ;; We didn't find it, so we go to the next article.
8728           (set-buffer sum)
8729           (setq found 'not)
8730           (while (eq found 'not)
8731             (if (not (if backward (gnus-summary-find-prev)
8732                        (gnus-summary-find-next)))
8733                 ;; No more articles.
8734                 (setq found t)
8735               ;; Select the next article and adjust point.
8736               (unless (gnus-summary-article-sparse-p
8737                        (gnus-summary-article-number))
8738                 (setq found nil)
8739                 (gnus-summary-select-article)
8740                 (set-buffer gnus-article-buffer)
8741                 (widen)
8742                 (goto-char (if backward (point-max) (point-min))))))))
8743       (gnus-message 7 ""))
8744     ;; Return whether we found the regexp.
8745     (when (eq found 'found)
8746       (goto-char point)
8747       (gnus-summary-show-thread)
8748       (gnus-summary-goto-subject gnus-current-article)
8749       (gnus-summary-position-point)
8750       t)))
8751
8752 (defun gnus-find-matching-articles (header regexp)
8753   "Return a list of all articles that match REGEXP on HEADER.
8754 This search includes all articles in the current group that Gnus has
8755 fetched headers for, whether they are displayed or not."
8756   (let ((articles nil)
8757         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8758         (case-fold-search t))
8759     (dolist (header gnus-newsgroup-headers)
8760       (when (string-match regexp (funcall func header))
8761         (push (mail-header-number header) articles)))
8762     (nreverse articles)))
8763
8764 (defun gnus-summary-find-matching (header regexp &optional backward unread
8765                                           not-case-fold not-matching)
8766   "Return a list of all articles that match REGEXP on HEADER.
8767 The search stars on the current article and goes forwards unless
8768 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8769 If UNREAD is non-nil, only unread articles will
8770 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8771 in the comparisons. If NOT-MATCHING, return a list of all articles that
8772 not match REGEXP on HEADER."
8773   (let ((case-fold-search (not not-case-fold))
8774         articles d func)
8775     (if (consp header)
8776         (if (eq (car header) 'extra)
8777             (setq func
8778                   `(lambda (h)
8779                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8780                          "")))
8781           (error "%s is an invalid header" header))
8782       (unless (fboundp (intern (concat "mail-header-" header)))
8783         (error "%s is not a valid header" header))
8784       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8785     (dolist (d (if (eq backward 'all)
8786                    gnus-newsgroup-data
8787                  (gnus-data-find-list
8788                   (gnus-summary-article-number)
8789                   (gnus-data-list backward))))
8790       (when (and (or (not unread)       ; We want all articles...
8791                      (gnus-data-unread-p d)) ; Or just unreads.
8792                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8793                  (if not-matching
8794                      (not (string-match
8795                            regexp
8796                            (funcall func (gnus-data-header d))))
8797                    (string-match regexp
8798                                  (funcall func (gnus-data-header d)))))
8799         (push (gnus-data-number d) articles))) ; Success!
8800     (nreverse articles)))
8801
8802 (defun gnus-summary-execute-command (header regexp command &optional backward)
8803   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8804 If HEADER is an empty string (or nil), the match is done on the entire
8805 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8806   (interactive
8807    (list (let ((completion-ignore-case t))
8808            (completing-read
8809             "Header name: "
8810             (mapcar (lambda (header) (list (format "%s" header)))
8811                     (append
8812                      '("Number" "Subject" "From" "Lines" "Date"
8813                        "Message-ID" "Xref" "References" "Body")
8814                      gnus-extra-headers))
8815             nil 'require-match))
8816          (read-string "Regexp: ")
8817          (read-key-sequence "Command: ")
8818          current-prefix-arg))
8819   (when (equal header "Body")
8820     (setq header ""))
8821   ;; Hidden thread subtrees must be searched as well.
8822   (gnus-summary-show-all-threads)
8823   ;; We don't want to change current point nor window configuration.
8824   (save-excursion
8825     (save-window-excursion
8826       (let (gnus-visual
8827             gnus-treat-strip-trailing-blank-lines
8828             gnus-treat-strip-leading-blank-lines
8829             gnus-treat-strip-multiple-blank-lines
8830             gnus-treat-hide-boring-headers
8831             gnus-treat-fold-newsgroups
8832             gnus-article-prepare-hook)
8833         (gnus-message 6 "Executing %s..." (key-description command))
8834         ;; We'd like to execute COMMAND interactively so as to give arguments.
8835         (gnus-execute header regexp
8836                       `(call-interactively ',(key-binding command))
8837                       backward)
8838         (gnus-message 6 "Executing %s...done" (key-description command))))))
8839
8840 (defun gnus-summary-beginning-of-article ()
8841   "Scroll the article back to the beginning."
8842   (interactive)
8843   (gnus-summary-select-article)
8844   (gnus-configure-windows 'article)
8845   (gnus-eval-in-buffer-window gnus-article-buffer
8846     (widen)
8847     (goto-char (point-min))
8848     (when gnus-break-pages
8849       (gnus-narrow-to-page))))
8850
8851 (defun gnus-summary-end-of-article ()
8852   "Scroll to the end of the article."
8853   (interactive)
8854   (gnus-summary-select-article)
8855   (gnus-configure-windows 'article)
8856   (gnus-eval-in-buffer-window gnus-article-buffer
8857     (widen)
8858     (goto-char (point-max))
8859     (recenter -3)
8860     (when gnus-break-pages
8861       (gnus-narrow-to-page))))
8862
8863 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8864   "Truncate to LEN and quote all \"(\"'s in STRING."
8865   (gnus-replace-in-string (if (and len (> (length string) len))
8866                               (substring string 0 len)
8867                             string)
8868                           "[()]" "\\\\\\&"))
8869
8870 (defun gnus-summary-print-article (&optional filename n)
8871   "Generate and print a PostScript image of the process-marked (mail) articles.
8872
8873 If used interactively, print the current article if none are
8874 process-marked.  With prefix arg, prompt the user for the name of the
8875 file to save in.
8876
8877 When used from Lisp, accept two optional args FILENAME and N.  N means
8878 to print the next N articles.  If N is negative, print the N previous
8879 articles.  If N is nil and articles have been marked with the process
8880 mark, print these instead.
8881
8882 If the optional first argument FILENAME is nil, send the image to the
8883 printer.  If FILENAME is a string, save the PostScript image in a file with
8884 that name.  If FILENAME is a number, prompt the user for the name of the file
8885 to save in."
8886   (interactive (list (ps-print-preprint current-prefix-arg)))
8887   (dolist (article (gnus-summary-work-articles n))
8888     (gnus-summary-select-article nil nil 'pseudo article)
8889     (gnus-eval-in-buffer-window gnus-article-buffer
8890       (gnus-print-buffer))
8891     (gnus-summary-remove-process-mark article))
8892   (ps-despool filename))
8893
8894 (defun gnus-print-buffer ()
8895   (let ((buffer (generate-new-buffer " *print*")))
8896     (unwind-protect
8897         (progn
8898           (copy-to-buffer buffer (point-min) (point-max))
8899           (set-buffer buffer)
8900           (gnus-remove-text-with-property 'gnus-decoration)
8901           (when (gnus-visual-p 'article-highlight 'highlight)
8902             ;; Copy-to-buffer doesn't copy overlay.  So redo
8903             ;; highlight.
8904             (let ((gnus-article-buffer buffer))
8905               (gnus-article-highlight-citation t)
8906               (gnus-article-highlight-signature)
8907               (gnus-article-emphasize)
8908               (gnus-article-delete-invisible-text)))
8909           (let ((ps-left-header
8910                  (list
8911                   (concat "("
8912                           (gnus-summary-print-truncate-and-quote
8913                            (mail-header-subject gnus-current-headers)
8914                            66) ")")
8915                   (concat "("
8916                           (gnus-summary-print-truncate-and-quote
8917                            (mail-header-from gnus-current-headers)
8918                            45) ")")))
8919                 (ps-right-header
8920                  (list
8921                   "/pagenumberstring load"
8922                   (concat "("
8923                           (mail-header-date gnus-current-headers) ")"))))
8924             (gnus-run-hooks 'gnus-ps-print-hook)
8925             (save-excursion
8926               (if ps-print-color-p
8927                   (ps-spool-buffer-with-faces)
8928                 (ps-spool-buffer)))))
8929       (kill-buffer buffer))))
8930
8931 (defun gnus-summary-show-article (&optional arg)
8932   "Force redisplaying of the current article.
8933 If ARG (the prefix) is a number, show the article with the charset
8934 defined in `gnus-summary-show-article-charset-alist', or the charset
8935 input.
8936 If ARG (the prefix) is non-nil and not a number, show the raw article
8937 without any article massaging functions being run.  Normally, the key
8938 strokes are `C-u g'."
8939   (interactive "P")
8940   (cond
8941    ((numberp arg)
8942     (gnus-summary-show-article t)
8943     (let ((gnus-newsgroup-charset
8944            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8945                (mm-read-coding-system
8946                 "View as charset: " ;; actually it is coding system.
8947                 (save-excursion
8948                   (set-buffer gnus-article-buffer)
8949                   (mm-detect-coding-region (point) (point-max))))))
8950           (gnus-newsgroup-ignored-charsets 'gnus-all))
8951       (gnus-summary-select-article nil 'force)
8952       (let ((deps gnus-newsgroup-dependencies)
8953             head header lines)
8954         (save-excursion
8955           (set-buffer gnus-original-article-buffer)
8956           (save-restriction
8957             (message-narrow-to-head)
8958             (setq head (buffer-string))
8959             (goto-char (point-min))
8960             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8961               (goto-char (point-max))
8962               (widen)
8963               (setq lines (1- (count-lines (point) (point-max))))))
8964           (with-temp-buffer
8965             (insert (format "211 %d Article retrieved.\n"
8966                             (cdr gnus-article-current)))
8967             (insert head)
8968             (if lines (insert (format "Lines: %d\n" lines)))
8969             (insert ".\n")
8970             (let ((nntp-server-buffer (current-buffer)))
8971               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8972         (gnus-data-set-header
8973          (gnus-data-find (cdr gnus-article-current))
8974          header)
8975         (gnus-summary-update-article-line
8976          (cdr gnus-article-current) header)
8977         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8978           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8979    ((not arg)
8980     ;; Select the article the normal way.
8981     (gnus-summary-select-article nil 'force))
8982    (t
8983     ;; We have to require this here to make sure that the following
8984     ;; dynamic binding isn't shadowed by autoloading.
8985     (require 'gnus-async)
8986     (require 'gnus-art)
8987     ;; Bind the article treatment functions to nil.
8988     (let ((gnus-have-all-headers t)
8989           gnus-article-prepare-hook
8990           gnus-article-decode-hook
8991           gnus-display-mime-function
8992           gnus-break-pages)
8993       ;; Destroy any MIME parts.
8994       (when (gnus-buffer-live-p gnus-article-buffer)
8995         (save-excursion
8996           (set-buffer gnus-article-buffer)
8997           (mm-destroy-parts gnus-article-mime-handles)
8998           ;; Set it to nil for safety reason.
8999           (setq gnus-article-mime-handle-alist nil)
9000           (setq gnus-article-mime-handles nil)))
9001       (gnus-summary-select-article nil 'force))))
9002   (gnus-summary-goto-subject gnus-current-article)
9003   (gnus-summary-position-point))
9004
9005 (defun gnus-summary-show-raw-article ()
9006   "Show the raw article without any article massaging functions being run."
9007   (interactive)
9008   (gnus-summary-show-article t))
9009
9010 (defun gnus-summary-verbose-headers (&optional arg)
9011   "Toggle permanent full header display.
9012 If ARG is a positive number, turn header display on.
9013 If ARG is a negative number, turn header display off."
9014   (interactive "P")
9015   (setq gnus-show-all-headers
9016         (cond ((or (not (numberp arg))
9017                    (zerop arg))
9018                (not gnus-show-all-headers))
9019               ((natnump arg)
9020                t)))
9021   (gnus-summary-show-article))
9022
9023 (defun gnus-summary-toggle-header (&optional arg)
9024   "Show the headers if they are hidden, or hide them if they are shown.
9025 If ARG is a positive number, show the entire header.
9026 If ARG is a negative number, hide the unwanted header lines."
9027   (interactive "P")
9028   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9029                      (get-buffer-window gnus-article-buffer t))))
9030     (with-current-buffer gnus-article-buffer
9031       (widen)
9032       (article-narrow-to-head)
9033       (let* ((buffer-read-only nil)
9034              (inhibit-point-motion-hooks t)
9035              (hidden (if (numberp arg)
9036                          (>= arg 0)
9037                        (or (not (looking-at "[^ \t\n]+:"))
9038                            (gnus-article-hidden-text-p 'headers))))
9039              s e)
9040         (delete-region (point-min) (point-max))
9041         (with-current-buffer gnus-original-article-buffer
9042           (goto-char (setq s (point-min)))
9043           (setq e (if (search-forward "\n\n" nil t)
9044                       (1- (point))
9045                     (point-max))))
9046         (insert-buffer-substring gnus-original-article-buffer s e)
9047         (run-hooks 'gnus-article-decode-hook)
9048         (if hidden
9049             (let ((gnus-treat-hide-headers nil)
9050                   (gnus-treat-hide-boring-headers nil))
9051               (gnus-delete-wash-type 'headers)
9052               (gnus-treat-article 'head))
9053           (gnus-treat-article 'head))
9054         (widen)
9055         (if window
9056             (set-window-start window (goto-char (point-min))))
9057         (if gnus-break-pages
9058             (gnus-narrow-to-page)
9059           (when (gnus-visual-p 'page-marker)
9060             (let ((buffer-read-only nil))
9061               (gnus-remove-text-with-property 'gnus-prev)
9062               (gnus-remove-text-with-property 'gnus-next))))
9063         (gnus-set-mode-line 'article)))))
9064
9065 (defun gnus-summary-show-all-headers ()
9066   "Make all header lines visible."
9067   (interactive)
9068   (gnus-summary-toggle-header 1))
9069
9070 (defun gnus-summary-caesar-message (&optional arg)
9071   "Caesar rotate the current article by 13.
9072 The numerical prefix specifies how many places to rotate each letter
9073 forward."
9074   (interactive "P")
9075   (gnus-summary-select-article)
9076   (let ((mail-header-separator ""))
9077     (gnus-eval-in-buffer-window gnus-article-buffer
9078       (save-restriction
9079         (widen)
9080         (let ((start (window-start))
9081               buffer-read-only)
9082           (message-caesar-buffer-body arg)
9083           (set-window-start (get-buffer-window (current-buffer)) start)))))
9084   ;; Create buttons and stuff...
9085   (gnus-treat-article nil))
9086
9087 (autoload 'unmorse-region "morse"
9088   "Convert morse coded text in region to ordinary ASCII text."
9089   t)
9090
9091 (defun gnus-summary-morse-message (&optional arg)
9092   "Morse decode the current article."
9093   (interactive "P")
9094   (gnus-summary-select-article)
9095   (let ((mail-header-separator ""))
9096     (gnus-eval-in-buffer-window gnus-article-buffer
9097       (save-excursion
9098         (save-restriction
9099           (widen)
9100           (let ((pos (window-start))
9101                 buffer-read-only)
9102             (goto-char (point-min))
9103             (when (message-goto-body)
9104               (gnus-narrow-to-body))
9105             (goto-char (point-min))
9106             (while (re-search-forward "·" (point-max) t)
9107               (replace-match "."))
9108             (unmorse-region (point-min) (point-max))
9109             (widen)
9110             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9111
9112 (defun gnus-summary-stop-page-breaking ()
9113   "Stop page breaking in the current article."
9114   (interactive)
9115   (gnus-summary-select-article)
9116   (gnus-eval-in-buffer-window gnus-article-buffer
9117     (widen)
9118     (when (gnus-visual-p 'page-marker)
9119       (let ((buffer-read-only nil))
9120         (gnus-remove-text-with-property 'gnus-prev)
9121         (gnus-remove-text-with-property 'gnus-next))
9122       (setq gnus-page-broken nil))))
9123
9124 (defun gnus-summary-move-article (&optional n to-newsgroup
9125                                             select-method action)
9126   "Move the current article to a different newsgroup.
9127 If N is a positive number, move the N next articles.
9128 If N is a negative number, move the N previous articles.
9129 If N is nil and any articles have been marked with the process mark,
9130 move those articles instead.
9131 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9132 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9133 re-spool using this method.
9134
9135 When called interactively with TO-NEWSGROUP being nil, the value of
9136 the variable `gnus-move-split-methods' is used for finding a default
9137 for the target newsgroup.
9138
9139 For this function to work, both the current newsgroup and the
9140 newsgroup that you want to move to have to support the `request-move'
9141 and `request-accept' functions.
9142
9143 ACTION can be either `move' (the default), `crosspost' or `copy'."
9144   (interactive "P")
9145   (unless action
9146     (setq action 'move))
9147   ;; Check whether the source group supports the required functions.
9148   (cond ((and (eq action 'move)
9149               (not (gnus-check-backend-function
9150                     'request-move-article gnus-newsgroup-name)))
9151          (error "The current group does not support article moving"))
9152         ((and (eq action 'crosspost)
9153               (not (gnus-check-backend-function
9154                     'request-replace-article gnus-newsgroup-name)))
9155          (error "The current group does not support article editing")))
9156   (let ((articles (gnus-summary-work-articles n))
9157         (prefix (if (gnus-check-backend-function
9158                      'request-move-article gnus-newsgroup-name)
9159                     (gnus-group-real-prefix gnus-newsgroup-name)
9160                   ""))
9161         (names '((move "Move" "Moving")
9162                  (copy "Copy" "Copying")
9163                  (crosspost "Crosspost" "Crossposting")))
9164         (copy-buf (save-excursion
9165                     (nnheader-set-temp-buffer " *copy article*")))
9166         art-group to-method new-xref article to-groups)
9167     (unless (assq action names)
9168       (error "Unknown action %s" action))
9169     ;; Read the newsgroup name.
9170     (when (and (not to-newsgroup)
9171                (not select-method))
9172       (if (and gnus-move-split-methods
9173                (not
9174                 (and (memq gnus-current-article articles)
9175                      (gnus-buffer-live-p gnus-original-article-buffer))))
9176           ;; When `gnus-move-split-methods' is non-nil, we have to
9177           ;; select an article to give `gnus-read-move-group-name' an
9178           ;; opportunity to suggest an appropriate default.  However,
9179           ;; we needn't render or mark the article.
9180           (let ((gnus-display-mime-function nil)
9181                 (gnus-article-prepare-hook nil)
9182                 (gnus-mark-article-hook nil))
9183             (gnus-summary-select-article nil nil nil (car articles))))
9184       (setq to-newsgroup
9185             (gnus-read-move-group-name
9186              (cadr (assq action names))
9187              (symbol-value (intern (format "gnus-current-%s-group" action)))
9188              articles prefix))
9189       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9190     (setq to-method (or select-method
9191                         (gnus-server-to-method
9192                          (gnus-group-method to-newsgroup))))
9193     ;; Check the method we are to move this article to...
9194     (unless (gnus-check-backend-function
9195              'request-accept-article (car to-method))
9196       (error "%s does not support article copying" (car to-method)))
9197     (unless (gnus-check-server to-method)
9198       (error "Can't open server %s" (car to-method)))
9199     (gnus-message 6 "%s to %s: %s..."
9200                   (caddr (assq action names))
9201                   (or (car select-method) to-newsgroup) articles)
9202     (while articles
9203       (setq article (pop articles))
9204       (setq
9205        art-group
9206        (cond
9207         ;; Move the article.
9208         ((eq action 'move)
9209          ;; Remove this article from future suppression.
9210          (gnus-dup-unsuppress-article article)
9211          (gnus-request-move-article
9212           article                       ; Article to move
9213           gnus-newsgroup-name           ; From newsgroup
9214           (nth 1 (gnus-find-method-for-group
9215                   gnus-newsgroup-name)) ; Server
9216           (list 'gnus-request-accept-article
9217                 to-newsgroup (list 'quote select-method)
9218                 (not articles) t)       ; Accept form
9219           (not articles)))              ; Only save nov last time
9220         ;; Copy the article.
9221         ((eq action 'copy)
9222          (save-excursion
9223            (set-buffer copy-buf)
9224            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9225              (gnus-request-accept-article
9226               to-newsgroup select-method (not articles) t))))
9227         ;; Crosspost the article.
9228         ((eq action 'crosspost)
9229          (let ((xref (message-tokenize-header
9230                       (mail-header-xref (gnus-summary-article-header article))
9231                       " ")))
9232            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9233                                   ":" (number-to-string article)))
9234            (unless xref
9235              (setq xref (list (system-name))))
9236            (setq new-xref
9237                  (concat
9238                   (mapconcat 'identity
9239                              (delete "Xref:" (delete new-xref xref))
9240                              " ")
9241                   " " new-xref))
9242            (save-excursion
9243              (set-buffer copy-buf)
9244              ;; First put the article in the destination group.
9245              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9246              (when (consp (setq art-group
9247                                 (gnus-request-accept-article
9248                                  to-newsgroup select-method (not articles) t)))
9249                (setq new-xref (concat new-xref " " (car art-group)
9250                                       ":"
9251                                       (number-to-string (cdr art-group))))
9252                ;; Now we have the new Xrefs header, so we insert
9253                ;; it and replace the new article.
9254                (nnheader-replace-header "Xref" new-xref)
9255                (gnus-request-replace-article
9256                 (cdr art-group) to-newsgroup (current-buffer) t)
9257                art-group))))))
9258       (cond
9259        ((not art-group)
9260         (gnus-message 1 "Couldn't %s article %s: %s"
9261                       (cadr (assq action names)) article
9262                       (nnheader-get-report (car to-method))))
9263        ((eq art-group 'junk)
9264         (when (eq action 'move)
9265           (gnus-summary-mark-article article gnus-canceled-mark)
9266           (gnus-message 4 "Deleted article %s" article)
9267           ;; run the delete hook
9268           (run-hook-with-args 'gnus-summary-article-delete-hook
9269                               action
9270                               (gnus-data-header
9271                                (assoc article (gnus-data-list nil)))
9272                               gnus-newsgroup-name nil
9273                               select-method)))
9274        (t
9275         (let* ((pto-group (gnus-group-prefixed-name
9276                            (car art-group) to-method))
9277                (entry
9278                 (gnus-gethash pto-group gnus-newsrc-hashtb))
9279                (info (nth 2 entry))
9280                (to-group (gnus-info-group info))
9281                to-marks)
9282           ;; Update the group that has been moved to.
9283           (when (and info
9284                      (memq action '(move copy)))
9285             (unless (member to-group to-groups)
9286               (push to-group to-groups))
9287
9288             (unless (memq article gnus-newsgroup-unreads)
9289               (push 'read to-marks)
9290               (gnus-info-set-read
9291                info (gnus-add-to-range (gnus-info-read info)
9292                                        (list (cdr art-group)))))
9293
9294             ;; See whether the article is to be put in the cache.
9295             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9296                              gnus-article-mark-lists
9297                            (delete '(expirable . expire)
9298                                    (copy-sequence gnus-article-mark-lists))))
9299                   (to-article (cdr art-group)))
9300
9301               ;; Enter the article into the cache in the new group,
9302               ;; if that is required.
9303               (when gnus-use-cache
9304                 (gnus-cache-possibly-enter-article
9305                  to-group to-article
9306                  (memq article gnus-newsgroup-marked)
9307                  (memq article gnus-newsgroup-dormant)
9308                  (memq article gnus-newsgroup-unreads)))
9309
9310               (when gnus-preserve-marks
9311                 ;; Copy any marks over to the new group.
9312                 (when (and (equal to-group gnus-newsgroup-name)
9313                            (not (memq article gnus-newsgroup-unreads)))
9314                   ;; Mark this article as read in this group.
9315                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9316                   (setcdr (gnus-active to-group) to-article)
9317                   (setcdr gnus-newsgroup-active to-article))
9318
9319                 (while marks
9320                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9321                     (when (memq article (symbol-value
9322                                          (intern (format "gnus-newsgroup-%s"
9323                                                          (caar marks)))))
9324                       (push (cdar marks) to-marks)
9325                       ;; If the other group is the same as this group,
9326                       ;; then we have to add the mark to the list.
9327                       (when (equal to-group gnus-newsgroup-name)
9328                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9329                              (cons to-article
9330                                    (symbol-value
9331                                     (intern (format "gnus-newsgroup-%s"
9332                                                     (caar marks)))))))
9333                       ;; Copy the marks to other group.
9334                       (gnus-add-marked-articles
9335                        to-group (cdar marks) (list to-article) info)))
9336                   (setq marks (cdr marks)))
9337
9338                 (gnus-request-set-mark
9339                  to-group (list (list (list to-article) 'add to-marks))))
9340
9341               (gnus-dribble-enter
9342                (concat "(gnus-group-set-info '"
9343                        (gnus-prin1-to-string (gnus-get-info to-group))
9344                        ")"))))
9345
9346           ;; Update the Xref header in this article to point to
9347           ;; the new crossposted article we have just created.
9348           (when (eq action 'crosspost)
9349             (save-excursion
9350               (set-buffer copy-buf)
9351               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9352               (nnheader-replace-header "Xref" new-xref)
9353               (gnus-request-replace-article
9354                article gnus-newsgroup-name (current-buffer) t)))
9355
9356           ;; run the move/copy/crosspost/respool hook
9357           (run-hook-with-args 'gnus-summary-article-move-hook
9358                               action
9359                               (gnus-data-header
9360                                (assoc article (gnus-data-list nil)))
9361                               gnus-newsgroup-name
9362                               to-newsgroup
9363                               select-method))
9364
9365         ;;;!!!Why is this necessary?
9366         (set-buffer gnus-summary-buffer)
9367
9368         (gnus-summary-goto-subject article)
9369         (when (eq action 'move)
9370           (gnus-summary-mark-article article gnus-canceled-mark))))
9371       (gnus-summary-remove-process-mark article))
9372     ;; Re-activate all groups that have been moved to.
9373     (save-excursion
9374       (set-buffer gnus-group-buffer)
9375       (let ((gnus-group-marked to-groups))
9376         (gnus-group-get-new-news-this-group nil t)))
9377
9378     (gnus-kill-buffer copy-buf)
9379     (gnus-summary-position-point)
9380     (gnus-set-mode-line 'summary)))
9381
9382 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9383   "Copy the current article to some other group.
9384 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9385 When called interactively, if TO-NEWSGROUP is nil, use the value of
9386 the variable `gnus-move-split-methods' for finding a default target
9387 newsgroup.
9388 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9389 re-spool using this method."
9390   (interactive "P")
9391   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9392
9393 (defun gnus-summary-crosspost-article (&optional n)
9394   "Crosspost the current article to some other group."
9395   (interactive "P")
9396   (gnus-summary-move-article n nil nil 'crosspost))
9397
9398 (defcustom gnus-summary-respool-default-method nil
9399   "Default method type for respooling an article.
9400 If nil, use to the current newsgroup method."
9401   :type 'symbol
9402   :group 'gnus-summary-mail)
9403
9404 (defcustom gnus-summary-display-while-building nil
9405   "If non-nil, show and update the summary buffer as it's being built.
9406 If the value is t, update the buffer after every line is inserted.  If
9407 the value is an integer (N), update the display every N lines."
9408   :version "22.1"
9409   :group 'gnus-thread
9410   :type '(choice (const :tag "off" nil)
9411                  number
9412                  (const :tag "frequently" t)))
9413
9414 (defun gnus-summary-respool-article (&optional n method)
9415   "Respool the current article.
9416 The article will be squeezed through the mail spooling process again,
9417 which means that it will be put in some mail newsgroup or other
9418 depending on `nnmail-split-methods'.
9419 If N is a positive number, respool the N next articles.
9420 If N is a negative number, respool the N previous articles.
9421 If N is nil and any articles have been marked with the process mark,
9422 respool those articles instead.
9423
9424 Respooling can be done both from mail groups and \"real\" newsgroups.
9425 In the former case, the articles in question will be moved from the
9426 current group into whatever groups they are destined to.  In the
9427 latter case, they will be copied into the relevant groups."
9428   (interactive
9429    (list current-prefix-arg
9430          (let* ((methods (gnus-methods-using 'respool))
9431                 (methname
9432                  (symbol-name (or gnus-summary-respool-default-method
9433                                   (car (gnus-find-method-for-group
9434                                         gnus-newsgroup-name)))))
9435                 (method
9436                  (gnus-completing-read-with-default
9437                   methname "Backend to use when respooling"
9438                   methods nil t nil 'gnus-mail-method-history))
9439                 ms)
9440            (cond
9441             ((zerop (length (setq ms (gnus-servers-using-backend
9442                                       (intern method)))))
9443              (list (intern method) ""))
9444             ((= 1 (length ms))
9445              (car ms))
9446             (t
9447              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9448                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9449                            ms-alist))))))))
9450   (unless method
9451     (error "No method given for respooling"))
9452   (if (assoc (symbol-name
9453               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9454              (gnus-methods-using 'respool))
9455       (gnus-summary-move-article n nil method)
9456     (gnus-summary-copy-article n nil method)))
9457
9458 (defun gnus-summary-import-article (file &optional edit)
9459   "Import an arbitrary file into a mail newsgroup."
9460   (interactive "fImport file: \nP")
9461   (let ((group gnus-newsgroup-name)
9462         (now (current-time))
9463         atts lines group-art)
9464     (unless (gnus-check-backend-function 'request-accept-article group)
9465       (error "%s does not support article importing" group))
9466     (or (file-readable-p file)
9467         (not (file-regular-p file))
9468         (error "Can't read %s" file))
9469     (save-excursion
9470       (set-buffer (gnus-get-buffer-create " *import file*"))
9471       (erase-buffer)
9472       (nnheader-insert-file-contents file)
9473       (goto-char (point-min))
9474       (if (nnheader-article-p)
9475           (save-restriction
9476             (goto-char (point-min))
9477             (search-forward "\n\n" nil t)
9478             (narrow-to-region (point-min) (1- (point)))
9479             (goto-char (point-min))
9480             (unless (re-search-forward "^date:" nil t)
9481               (goto-char (point-max))
9482               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9483        ;; This doesn't look like an article, so we fudge some headers.
9484         (setq atts (file-attributes file)
9485               lines (count-lines (point-min) (point-max)))
9486         (insert "From: " (read-string "From: ") "\n"
9487                 "Subject: " (read-string "Subject: ") "\n"
9488                 "Date: " (message-make-date (nth 5 atts)) "\n"
9489                 "Message-ID: " (message-make-message-id) "\n"
9490                 "Lines: " (int-to-string lines) "\n"
9491                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9492       (setq group-art (gnus-request-accept-article group nil t))
9493       (kill-buffer (current-buffer)))
9494     (setq gnus-newsgroup-active (gnus-activate-group group))
9495     (forward-line 1)
9496     (gnus-summary-goto-article (cdr group-art) nil t)
9497     (when edit
9498       (gnus-summary-edit-article))))
9499
9500 (defun gnus-summary-create-article ()
9501   "Create an article in a mail newsgroup."
9502   (interactive)
9503   (let ((group gnus-newsgroup-name)
9504         (now (current-time))
9505         group-art)
9506     (unless (gnus-check-backend-function 'request-accept-article group)
9507       (error "%s does not support article importing" group))
9508     (save-excursion
9509       (set-buffer (gnus-get-buffer-create " *import file*"))
9510       (erase-buffer)
9511       (goto-char (point-min))
9512       ;; This doesn't look like an article, so we fudge some headers.
9513       (insert "From: " (read-string "From: ") "\n"
9514               "Subject: " (read-string "Subject: ") "\n"
9515               "Date: " (message-make-date now) "\n"
9516               "Message-ID: " (message-make-message-id) "\n")
9517       (setq group-art (gnus-request-accept-article group nil t))
9518       (kill-buffer (current-buffer)))
9519     (setq gnus-newsgroup-active (gnus-activate-group group))
9520     (forward-line 1)
9521     (gnus-summary-goto-article (cdr group-art) nil t)
9522     (gnus-summary-edit-article)))
9523
9524 (defun gnus-summary-article-posted-p ()
9525   "Say whether the current (mail) article is available from news as well.
9526 This will be the case if the article has both been mailed and posted."
9527   (interactive)
9528   (let ((id (mail-header-references (gnus-summary-article-header)))
9529         (gnus-override-method (car (gnus-refer-article-methods))))
9530     (if (gnus-request-head id "")
9531         (gnus-message 2 "The current message was found on %s"
9532                       gnus-override-method)
9533       (gnus-message 2 "The current message couldn't be found on %s"
9534                     gnus-override-method)
9535       nil)))
9536
9537 (defun gnus-summary-expire-articles (&optional now)
9538   "Expire all articles that are marked as expirable in the current group."
9539   (interactive)
9540   (when (and (not gnus-group-is-exiting-without-update-p)
9541              (gnus-check-backend-function
9542               'request-expire-articles gnus-newsgroup-name))
9543     ;; This backend supports expiry.
9544     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9545            (expirable (if total
9546                           (progn
9547                             ;; We need to update the info for
9548                             ;; this group for `gnus-list-of-read-articles'
9549                             ;; to give us the right answer.
9550                             (gnus-run-hooks 'gnus-exit-group-hook)
9551                             (gnus-summary-update-info)
9552                             (gnus-list-of-read-articles gnus-newsgroup-name))
9553                         (setq gnus-newsgroup-expirable
9554                               (sort gnus-newsgroup-expirable '<))))
9555            (expiry-wait (if now 'immediate
9556                           (gnus-group-find-parameter
9557                            gnus-newsgroup-name 'expiry-wait)))
9558            (nnmail-expiry-target
9559             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9560                 nnmail-expiry-target))
9561            es)
9562       (when expirable
9563         ;; There are expirable articles in this group, so we run them
9564         ;; through the expiry process.
9565         (gnus-message 6 "Expiring articles...")
9566         (unless (gnus-check-group gnus-newsgroup-name)
9567           (error "Can't open server for %s" gnus-newsgroup-name))
9568         ;; The list of articles that weren't expired is returned.
9569         (save-excursion
9570           (if expiry-wait
9571               (let ((nnmail-expiry-wait-function nil)
9572                     (nnmail-expiry-wait expiry-wait))
9573                 (setq es (gnus-request-expire-articles
9574                           expirable gnus-newsgroup-name)))
9575             (setq es (gnus-request-expire-articles
9576                       expirable gnus-newsgroup-name)))
9577           (unless total
9578             (setq gnus-newsgroup-expirable es))
9579           ;; We go through the old list of expirable, and mark all
9580           ;; really expired articles as nonexistent.
9581           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9582             (let ((gnus-use-cache nil))
9583               (dolist (article expirable)
9584                 (when (and (not (memq article es))
9585                            (gnus-data-find article))
9586                   (gnus-summary-mark-article article gnus-canceled-mark)
9587                   (run-hook-with-args 'gnus-summary-article-expire-hook
9588                                       'delete
9589                                       (gnus-data-header
9590                                        (assoc article (gnus-data-list nil)))
9591                                       gnus-newsgroup-name
9592                                       nil
9593                                       nil))))))
9594         (gnus-message 6 "Expiring articles...done")))))
9595
9596 (defun gnus-summary-expire-articles-now ()
9597   "Expunge all expirable articles in the current group.
9598 This means that *all* articles that are marked as expirable will be
9599 deleted forever, right now."
9600   (interactive)
9601   (or gnus-expert-user
9602       (gnus-yes-or-no-p
9603        "Are you really, really sure you want to delete all expirable messages? ")
9604       (error "Phew!"))
9605   (gnus-summary-expire-articles t))
9606
9607 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9608 (defun gnus-summary-delete-article (&optional n)
9609   "Delete the N next (mail) articles.
9610 This command actually deletes articles.  This is not a marking
9611 command.  The article will disappear forever from your life, never to
9612 return.
9613
9614 If N is negative, delete backwards.
9615 If N is nil and articles have been marked with the process mark,
9616 delete these instead.
9617
9618 If `gnus-novice-user' is non-nil you will be asked for
9619 confirmation before the articles are deleted."
9620   (interactive "P")
9621   (unless (gnus-check-backend-function 'request-expire-articles
9622                                        gnus-newsgroup-name)
9623     (error "The current newsgroup does not support article deletion"))
9624   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9625     (error "Couldn't open server"))
9626   ;; Compute the list of articles to delete.
9627   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9628         (nnmail-expiry-target 'delete)
9629         not-deleted)
9630     (if (and gnus-novice-user
9631              (not (gnus-yes-or-no-p
9632                    (format "Do you really want to delete %s forever? "
9633                            (if (> (length articles) 1)
9634                                (format "these %s articles" (length articles))
9635                              "this article")))))
9636         ()
9637       ;; Delete the articles.
9638       (setq not-deleted (gnus-request-expire-articles
9639                          articles gnus-newsgroup-name 'force))
9640       (while articles
9641         (gnus-summary-remove-process-mark (car articles))
9642         ;; The backend might not have been able to delete the article
9643         ;; after all.
9644         (unless (memq (car articles) not-deleted)
9645           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9646         (let* ((article (car articles))
9647                (id (mail-header-id (gnus-data-header
9648                                     (assoc article (gnus-data-list nil))))))
9649           (run-hook-with-args 'gnus-summary-article-delete-hook
9650                               'delete id gnus-newsgroup-name nil
9651                               nil))
9652         (setq articles (cdr articles)))
9653       (when not-deleted
9654         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9655     (gnus-summary-position-point)
9656     (gnus-set-mode-line 'summary)
9657     not-deleted))
9658
9659 (defun gnus-summary-edit-article (&optional arg)
9660   "Edit the current article.
9661 This will have permanent effect only in mail groups.
9662 If ARG is nil, edit the decoded articles.
9663 If ARG is 1, edit the raw articles.
9664 If ARG is 2, edit the raw articles even in read-only groups.
9665 If ARG is 3, edit the articles with the current handles.
9666 Otherwise, allow editing of articles even in read-only
9667 groups."
9668   (interactive "P")
9669   (let (force raw current-handles)
9670     (cond
9671      ((null arg))
9672      ((eq arg 1)
9673       (setq raw t))
9674      ((eq arg 2)
9675       (setq raw t
9676             force t))
9677      ((eq arg 3)
9678       (setq current-handles
9679             (and (gnus-buffer-live-p gnus-article-buffer)
9680                  (with-current-buffer gnus-article-buffer
9681                    (prog1
9682                        gnus-article-mime-handles
9683                      (setq gnus-article-mime-handles nil))))))
9684      (t
9685       (setq force t)))
9686     (when (and raw (not force)
9687                (member gnus-newsgroup-name '("nndraft:delayed"
9688                                              "nndraft:drafts"
9689                                              "nndraft:queue")))
9690       (error "Can't edit the raw article in group %s"
9691              gnus-newsgroup-name))
9692     (save-excursion
9693       (set-buffer gnus-summary-buffer)
9694       (let ((mail-parse-charset gnus-newsgroup-charset)
9695             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9696         (gnus-set-global-variables)
9697         (when (and (not force)
9698                    (gnus-group-read-only-p))
9699           (error "The current newsgroup does not support article editing"))
9700         (gnus-summary-show-article t)
9701         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9702           (with-current-buffer gnus-article-buffer
9703             (mm-enable-multibyte)))
9704         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9705             (setq raw t))
9706         (gnus-article-edit-article
9707          (if raw 'ignore
9708            `(lambda ()
9709               (let ((mbl mml-buffer-list))
9710                 (setq mml-buffer-list nil)
9711                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9712                   (mime-to-mml ,'current-handles))
9713                 (let ((mbl1 mml-buffer-list))
9714                   (setq mml-buffer-list mbl)
9715                   (set (make-local-variable 'mml-buffer-list) mbl1))
9716                 (gnus-make-local-hook 'kill-buffer-hook)
9717                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9718          `(lambda (no-highlight)
9719             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9720                   (message-options message-options)
9721                   (message-options-set-recipient)
9722                   (mail-parse-ignored-charsets
9723                    ',gnus-newsgroup-ignored-charsets))
9724               ,(if (not raw) '(progn
9725                                 (mml-to-mime)
9726                                 (mml-destroy-buffers)
9727                                 (remove-hook 'kill-buffer-hook
9728                                              'mml-destroy-buffers t)
9729                                 (kill-local-variable 'mml-buffer-list)))
9730               (gnus-summary-edit-article-done
9731                ,(or (mail-header-references gnus-current-headers) "")
9732                ,(gnus-group-read-only-p)
9733                ,gnus-summary-buffer no-highlight))))))))
9734
9735 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9736
9737 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9738                                                  no-highlight)
9739   "Make edits to the current article permanent."
9740   (interactive)
9741   (save-excursion
9742    ;; The buffer restriction contains the entire article if it exists.
9743     (when (article-goto-body)
9744       (let ((lines (count-lines (point) (point-max)))
9745             (length (- (point-max) (point)))
9746             (case-fold-search t)
9747             (body (copy-marker (point))))
9748         (goto-char (point-min))
9749         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9750           (delete-region (match-beginning 1) (match-end 1))
9751           (insert (number-to-string length)))
9752         (goto-char (point-min))
9753         (when (re-search-forward
9754                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9755           (delete-region (match-beginning 1) (match-end 1))
9756           (insert (number-to-string length)))
9757         (goto-char (point-min))
9758         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9759           (delete-region (match-beginning 1) (match-end 1))
9760           (insert (number-to-string lines))))))
9761   ;; Replace the article.
9762   (let ((buf (current-buffer)))
9763     (with-temp-buffer
9764       (insert-buffer-substring buf)
9765
9766       (if (and (not read-only)
9767                (not (gnus-request-replace-article
9768                      (cdr gnus-article-current) (car gnus-article-current)
9769                      (current-buffer) t)))
9770           (error "Couldn't replace article")
9771         ;; Update the summary buffer.
9772         (if (and references
9773                  (equal (message-tokenize-header references " ")
9774                         (message-tokenize-header
9775                          (or (message-fetch-field "references") "") " ")))
9776             ;; We only have to update this line.
9777             (save-excursion
9778               (save-restriction
9779                 (message-narrow-to-head)
9780                 (let ((head (buffer-substring-no-properties
9781                              (point-min) (point-max)))
9782                       header)
9783                   (with-temp-buffer
9784                     (insert (format "211 %d Article retrieved.\n"
9785                                     (cdr gnus-article-current)))
9786                     (insert head)
9787                     (insert ".\n")
9788                     (let ((nntp-server-buffer (current-buffer)))
9789                       (setq header (car (gnus-get-newsgroup-headers
9790                                          nil t))))
9791                     (save-excursion
9792                       (set-buffer gnus-summary-buffer)
9793                       (gnus-data-set-header
9794                        (gnus-data-find (cdr gnus-article-current))
9795                        header)
9796                       (gnus-summary-update-article-line
9797                        (cdr gnus-article-current) header)
9798                       (if (gnus-summary-goto-subject
9799                            (cdr gnus-article-current) nil t)
9800                           (gnus-summary-update-secondary-mark
9801                            (cdr gnus-article-current))))))))
9802           ;; Update threads.
9803           (set-buffer (or buffer gnus-summary-buffer))
9804           (gnus-summary-update-article (cdr gnus-article-current))
9805           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9806               (gnus-summary-update-secondary-mark
9807                (cdr gnus-article-current))))
9808         ;; Prettify the article buffer again.
9809         (unless no-highlight
9810           (save-excursion
9811             (set-buffer gnus-article-buffer)
9812             ;;;!!! Fix this -- article should be rehighlighted.
9813             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9814             (set-buffer gnus-original-article-buffer)
9815             (gnus-request-article
9816              (cdr gnus-article-current)
9817              (car gnus-article-current) (current-buffer))))
9818         ;; Prettify the summary buffer line.
9819         (when (gnus-visual-p 'summary-highlight 'highlight)
9820           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9821
9822 (defun gnus-summary-edit-wash (key)
9823   "Perform editing command KEY in the article buffer."
9824   (interactive
9825    (list
9826     (progn
9827       (message "%s" (concat (this-command-keys) "- "))
9828       (read-char))))
9829   (message "")
9830   (gnus-summary-edit-article)
9831   (execute-kbd-macro (concat (this-command-keys) key))
9832   (gnus-article-edit-done))
9833
9834 ;;; Respooling
9835
9836 (defun gnus-summary-respool-query (&optional silent trace)
9837   "Query where the respool algorithm would put this article."
9838   (interactive)
9839   (let (gnus-mark-article-hook)
9840     (gnus-summary-select-article)
9841     (save-excursion
9842       (set-buffer gnus-original-article-buffer)
9843       (let ((groups (nnmail-article-group 'identity trace)))
9844         (unless silent
9845           (if groups
9846               (message "This message would go to %s"
9847                        (mapconcat 'car groups ", "))
9848             (message "This message would go to no groups"))
9849           groups)))))
9850
9851 (defun gnus-summary-respool-trace ()
9852   "Trace where the respool algorithm would put this article.
9853 Display a buffer showing all fancy splitting patterns which matched."
9854   (interactive)
9855   (gnus-summary-respool-query nil t))
9856
9857 ;; Summary marking commands.
9858
9859 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9860   "Mark articles which has the same subject as read, and then select the next.
9861 If UNMARK is positive, remove any kind of mark.
9862 If UNMARK is negative, tick articles."
9863   (interactive "P")
9864   (when unmark
9865     (setq unmark (prefix-numeric-value unmark)))
9866   (let ((count
9867          (gnus-summary-mark-same-subject
9868           (gnus-summary-article-subject) unmark)))
9869     ;; Select next unread article.  If auto-select-same mode, should
9870     ;; select the first unread article.
9871     (gnus-summary-next-article t (and gnus-auto-select-same
9872                                       (gnus-summary-article-subject)))
9873     (gnus-message 7 "%d article%s marked as %s"
9874                   count (if (= count 1) " is" "s are")
9875                   (if unmark "unread" "read"))))
9876
9877 (defun gnus-summary-kill-same-subject (&optional unmark)
9878   "Mark articles which has the same subject as read.
9879 If UNMARK is positive, remove any kind of mark.
9880 If UNMARK is negative, tick articles."
9881   (interactive "P")
9882   (when unmark
9883     (setq unmark (prefix-numeric-value unmark)))
9884   (let ((count
9885          (gnus-summary-mark-same-subject
9886           (gnus-summary-article-subject) unmark)))
9887     ;; If marked as read, go to next unread subject.
9888     (when (null unmark)
9889       ;; Go to next unread subject.
9890       (gnus-summary-next-subject 1 t))
9891     (gnus-message 7 "%d articles are marked as %s"
9892                   count (if unmark "unread" "read"))))
9893
9894 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9895   "Mark articles with same SUBJECT as read, and return marked number.
9896 If optional argument UNMARK is positive, remove any kinds of marks.
9897 If optional argument UNMARK is negative, mark articles as unread instead."
9898   (let ((count 1))
9899     (save-excursion
9900       (cond
9901        ((null unmark)                   ; Mark as read.
9902         (while (and
9903                 (progn
9904                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9905                   (gnus-summary-show-thread) t)
9906                 (gnus-summary-find-subject subject))
9907           (setq count (1+ count))))
9908        ((> unmark 0)                    ; Tick.
9909         (while (and
9910                 (progn
9911                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9912                   (gnus-summary-show-thread) t)
9913                 (gnus-summary-find-subject subject))
9914           (setq count (1+ count))))
9915        (t                               ; Mark as unread.
9916         (while (and
9917                 (progn
9918                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9919                   (gnus-summary-show-thread) t)
9920                 (gnus-summary-find-subject subject))
9921           (setq count (1+ count)))))
9922       (gnus-set-mode-line 'summary)
9923       ;; Return the number of marked articles.
9924       count)))
9925
9926 (defun gnus-summary-mark-as-processable (n &optional unmark)
9927   "Set the process mark on the next N articles.
9928 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9929 the process mark instead.  The difference between N and the actual
9930 number of articles marked is returned."
9931   (interactive "P")
9932   (if (and (null n) (gnus-region-active-p))
9933       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9934     (setq n (prefix-numeric-value n))
9935     (let ((backward (< n 0))
9936           (n (abs n)))
9937       (while (and
9938               (> n 0)
9939               (if unmark
9940                   (gnus-summary-remove-process-mark
9941                    (gnus-summary-article-number))
9942                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9943               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9944         (setq n (1- n)))
9945       (when (/= 0 n)
9946         (gnus-message 7 "No more articles"))
9947       (gnus-summary-recenter)
9948       (gnus-summary-position-point)
9949       n)))
9950
9951 (defun gnus-summary-unmark-as-processable (n)
9952   "Remove the process mark from the next N articles.
9953 If N is negative, unmark backward instead.  The difference between N and
9954 the actual number of articles unmarked is returned."
9955   (interactive "P")
9956   (gnus-summary-mark-as-processable n t))
9957
9958 (defun gnus-summary-unmark-all-processable ()
9959   "Remove the process mark from all articles."
9960   (interactive)
9961   (save-excursion
9962     (while gnus-newsgroup-processable
9963       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9964   (gnus-summary-position-point))
9965
9966 (defun gnus-summary-add-mark (article type)
9967   "Mark ARTICLE with a mark of TYPE."
9968   (let ((vtype (car (assq type gnus-article-mark-lists)))
9969         var)
9970     (if (not vtype)
9971         (error "No such mark type: %s" type)
9972       (setq var (intern (format "gnus-newsgroup-%s" type)))
9973       (set var (cons article (symbol-value var)))
9974       (if (memq type '(processable cached replied forwarded recent saved))
9975           (gnus-summary-update-secondary-mark article)
9976         ;;; !!! This is bogus.  We should find out what primary
9977         ;;; !!! mark we want to set.
9978         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9979
9980 (defun gnus-summary-mark-as-expirable (n)
9981   "Mark N articles forward as expirable.
9982 If N is negative, mark backward instead.  The difference between N and
9983 the actual number of articles marked is returned."
9984   (interactive "p")
9985   (gnus-summary-mark-forward n gnus-expirable-mark))
9986
9987 (defun gnus-summary-mark-as-spam (n)
9988   "Mark N articles forward as spam.
9989 If N is negative, mark backward instead.  The difference between N and
9990 the actual number of articles marked is returned."
9991   (interactive "p")
9992   (gnus-summary-mark-forward n gnus-spam-mark))
9993
9994 (defun gnus-summary-mark-article-as-replied (article)
9995   "Mark ARTICLE as replied to and update the summary line.
9996 ARTICLE can also be a list of articles."
9997   (interactive (list (gnus-summary-article-number)))
9998   (let ((articles (if (listp article) article (list article))))
9999     (dolist (article articles)
10000       (unless (numberp article)
10001         (error "%s is not a number" article))
10002       (push article gnus-newsgroup-replied)
10003       (let ((buffer-read-only nil))
10004         (when (gnus-summary-goto-subject article nil t)
10005           (gnus-summary-update-secondary-mark article))))))
10006
10007 (defun gnus-summary-mark-article-as-forwarded (article)
10008   "Mark ARTICLE as forwarded and update the summary line.
10009 ARTICLE can also be a list of articles."
10010   (let ((articles (if (listp article) article (list article))))
10011     (dolist (article articles)
10012       (push article gnus-newsgroup-forwarded)
10013       (let ((buffer-read-only nil))
10014         (when (gnus-summary-goto-subject article nil t)
10015           (gnus-summary-update-secondary-mark article))))))
10016
10017 (defun gnus-summary-set-bookmark (article)
10018   "Set a bookmark in current article."
10019   (interactive (list (gnus-summary-article-number)))
10020   (when (or (not (get-buffer gnus-article-buffer))
10021             (not gnus-current-article)
10022             (not gnus-article-current)
10023             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10024     (error "No current article selected"))
10025   ;; Remove old bookmark, if one exists.
10026   (gnus-pull article gnus-newsgroup-bookmarks)
10027   ;; Set the new bookmark, which is on the form
10028   ;; (article-number . line-number-in-body).
10029   (push
10030    (cons article
10031          (save-excursion
10032            (set-buffer gnus-article-buffer)
10033            (count-lines
10034             (min (point)
10035                  (save-excursion
10036                    (article-goto-body)
10037                    (point)))
10038             (point))))
10039    gnus-newsgroup-bookmarks)
10040   (gnus-message 6 "A bookmark has been added to the current article."))
10041
10042 (defun gnus-summary-remove-bookmark (article)
10043   "Remove the bookmark from the current article."
10044   (interactive (list (gnus-summary-article-number)))
10045   ;; Remove old bookmark, if one exists.
10046   (if (not (assq article gnus-newsgroup-bookmarks))
10047       (gnus-message 6 "No bookmark in current article.")
10048     (gnus-pull article gnus-newsgroup-bookmarks)
10049     (gnus-message 6 "Removed bookmark.")))
10050
10051 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10052 (defun gnus-summary-mark-as-dormant (n)
10053   "Mark N articles forward as dormant.
10054 If N is negative, mark backward instead.  The difference between N and
10055 the actual number of articles marked is returned."
10056   (interactive "p")
10057   (gnus-summary-mark-forward n gnus-dormant-mark))
10058
10059 (defun gnus-summary-set-process-mark (article)
10060   "Set the process mark on ARTICLE and update the summary line."
10061   (setq gnus-newsgroup-processable
10062         (cons article
10063               (delq article gnus-newsgroup-processable)))
10064   (when (gnus-summary-goto-subject article)
10065     (gnus-summary-show-thread)
10066     (gnus-summary-goto-subject article)
10067     (gnus-summary-update-secondary-mark article)))
10068
10069 (defun gnus-summary-remove-process-mark (article)
10070   "Remove the process mark from ARTICLE and update the summary line."
10071   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10072   (when (gnus-summary-goto-subject article)
10073     (gnus-summary-show-thread)
10074     (gnus-summary-goto-subject article)
10075     (gnus-summary-update-secondary-mark article)))
10076
10077 (defun gnus-summary-set-saved-mark (article)
10078   "Set the process mark on ARTICLE and update the summary line."
10079   (push article gnus-newsgroup-saved)
10080   (when (gnus-summary-goto-subject article)
10081     (gnus-summary-update-secondary-mark article)))
10082
10083 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10084   "Mark N articles as read forwards.
10085 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10086 The difference between N and the actual number of articles marked is
10087 returned.
10088 If NO-EXPIRE, auto-expiry will be inhibited."
10089   (interactive "p")
10090   (gnus-summary-show-thread)
10091   (let ((backward (< n 0))
10092         (gnus-summary-goto-unread
10093          (and gnus-summary-goto-unread
10094               (not (eq gnus-summary-goto-unread 'never))
10095               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10096                                     gnus-ticked-mark gnus-dormant-mark)))))
10097         (n (abs n))
10098         (mark (or mark gnus-del-mark)))
10099     (while (and (> n 0)
10100                 (gnus-summary-mark-article nil mark no-expire)
10101                 (zerop (gnus-summary-next-subject
10102                         (if backward -1 1)
10103                         (and gnus-summary-goto-unread
10104                              (not (eq gnus-summary-goto-unread 'never)))
10105                         t)))
10106       (setq n (1- n)))
10107     (when (/= 0 n)
10108       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10109     (gnus-summary-recenter)
10110     (gnus-summary-position-point)
10111     (gnus-set-mode-line 'summary)
10112     n))
10113
10114 (defun gnus-summary-mark-article-as-read (mark)
10115   "Mark the current article quickly as read with MARK."
10116   (let ((article (gnus-summary-article-number)))
10117     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10118     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10119     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10120     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10121     (push (cons article mark) gnus-newsgroup-reads)
10122     ;; Possibly remove from cache, if that is used.
10123     (when gnus-use-cache
10124       (gnus-cache-enter-remove-article article))
10125     ;; Allow the backend to change the mark.
10126     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10127     ;; Check for auto-expiry.
10128     (when (and gnus-newsgroup-auto-expire
10129                (memq mark gnus-auto-expirable-marks))
10130       (setq mark gnus-expirable-mark)
10131       ;; Let the backend know about the mark change.
10132       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10133       (push article gnus-newsgroup-expirable))
10134     ;; Set the mark in the buffer.
10135     (gnus-summary-update-mark mark 'unread)
10136     t))
10137
10138 (defun gnus-summary-mark-article-as-unread (mark)
10139   "Mark the current article quickly as unread with MARK."
10140   (let* ((article (gnus-summary-article-number))
10141          (old-mark (gnus-summary-article-mark article)))
10142     ;; Allow the backend to change the mark.
10143     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10144     (if (eq mark old-mark)
10145         t
10146       (if (<= article 0)
10147           (progn
10148             (gnus-error 1 "Can't mark negative article numbers")
10149             nil)
10150         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10151         (setq gnus-newsgroup-spam-marked
10152               (delq article gnus-newsgroup-spam-marked))
10153         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10154         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10155         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10156         (cond ((= mark gnus-ticked-mark)
10157                (setq gnus-newsgroup-marked
10158                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10159                                               article)))
10160               ((= mark gnus-spam-mark)
10161                (setq gnus-newsgroup-spam-marked
10162                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10163                                               article)))
10164               ((= mark gnus-dormant-mark)
10165                (setq gnus-newsgroup-dormant
10166                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10167                                               article)))
10168               (t
10169                (setq gnus-newsgroup-unreads
10170                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10171                                               article))))
10172         (gnus-pull article gnus-newsgroup-reads)
10173
10174         ;; See whether the article is to be put in the cache.
10175         (and gnus-use-cache
10176              (vectorp (gnus-summary-article-header article))
10177              (save-excursion
10178                (gnus-cache-possibly-enter-article
10179                 gnus-newsgroup-name article
10180                 (= mark gnus-ticked-mark)
10181                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10182
10183         ;; Fix the mark.
10184         (gnus-summary-update-mark mark 'unread)
10185         t))))
10186
10187 (defun gnus-summary-mark-article (&optional article mark no-expire)
10188   "Mark ARTICLE with MARK.  MARK can be any character.
10189 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10190 `??' (dormant) and `?E' (expirable).
10191 If MARK is nil, then the default character `?r' is used.
10192 If ARTICLE is nil, then the article on the current line will be
10193 marked.
10194 If NO-EXPIRE, auto-expiry will be inhibited."
10195   ;; The mark might be a string.
10196   (when (stringp mark)
10197     (setq mark (aref mark 0)))
10198   ;; If no mark is given, then we check auto-expiring.
10199   (when (null mark)
10200     (setq mark gnus-del-mark))
10201   (when (and (not no-expire)
10202              gnus-newsgroup-auto-expire
10203              (memq mark gnus-auto-expirable-marks))
10204     (setq mark gnus-expirable-mark))
10205   (let ((article (or article (gnus-summary-article-number)))
10206         (old-mark (gnus-summary-article-mark article)))
10207     ;; Allow the backend to change the mark.
10208     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10209     (if (eq mark old-mark)
10210         t
10211       (unless article
10212         (error "No article on current line"))
10213       (if (not (if (or (= mark gnus-unread-mark)
10214                        (= mark gnus-ticked-mark)
10215                        (= mark gnus-spam-mark)
10216                        (= mark gnus-dormant-mark))
10217                    (gnus-mark-article-as-unread article mark)
10218                  (gnus-mark-article-as-read article mark)))
10219           t
10220         ;; See whether the article is to be put in the cache.
10221         (and gnus-use-cache
10222              (not (= mark gnus-canceled-mark))
10223              (vectorp (gnus-summary-article-header article))
10224              (save-excursion
10225                (gnus-cache-possibly-enter-article
10226                 gnus-newsgroup-name article
10227                 (= mark gnus-ticked-mark)
10228                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10229
10230         (when (gnus-summary-goto-subject article nil t)
10231           (let ((buffer-read-only nil))
10232             (gnus-summary-show-thread)
10233             ;; Fix the mark.
10234             (gnus-summary-update-mark mark 'unread)
10235             t))))))
10236
10237 (defun gnus-summary-update-secondary-mark (article)
10238   "Update the secondary (read, process, cache) mark."
10239   (gnus-summary-update-mark
10240    (cond ((memq article gnus-newsgroup-processable)
10241           gnus-process-mark)
10242          ((memq article gnus-newsgroup-cached)
10243           gnus-cached-mark)
10244          ((memq article gnus-newsgroup-replied)
10245           gnus-replied-mark)
10246          ((memq article gnus-newsgroup-forwarded)
10247           gnus-forwarded-mark)
10248          ((memq article gnus-newsgroup-saved)
10249           gnus-saved-mark)
10250          ((memq article gnus-newsgroup-recent)
10251           gnus-recent-mark)
10252          ((memq article gnus-newsgroup-unseen)
10253           gnus-unseen-mark)
10254          (t gnus-no-mark))
10255    'replied)
10256   (when (gnus-visual-p 'summary-highlight 'highlight)
10257     (gnus-run-hooks 'gnus-summary-update-hook))
10258   t)
10259
10260 (defun gnus-summary-update-download-mark (article)
10261   "Update the download mark."
10262   (gnus-summary-update-mark
10263    (cond ((memq article gnus-newsgroup-undownloaded)
10264           gnus-undownloaded-mark)
10265          (gnus-newsgroup-agentized
10266           gnus-downloaded-mark)
10267          (t
10268           gnus-no-mark))
10269    'download)
10270   (gnus-summary-update-line t)
10271   t)
10272
10273 (defun gnus-summary-update-mark (mark type)
10274   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10275         (buffer-read-only nil))
10276     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
10277     (when forward
10278       (when (looking-at "\r")
10279         (incf forward))
10280       (when (<= (+ forward (point)) (point-max))
10281         ;; Go to the right position on the line.
10282         (goto-char (+ forward (point)))
10283         ;; Replace the old mark with the new mark.
10284         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10285         ;; Optionally update the marks by some user rule.
10286         (when (eq type 'unread)
10287           (gnus-data-set-mark
10288            (gnus-data-find (gnus-summary-article-number)) mark)
10289           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10290
10291 (defun gnus-mark-article-as-read (article &optional mark)
10292   "Enter ARTICLE in the pertinent lists and remove it from others."
10293   ;; Make the article expirable.
10294   (let ((mark (or mark gnus-del-mark)))
10295     (setq gnus-newsgroup-expirable
10296           (if (= mark gnus-expirable-mark)
10297               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10298             (delq article gnus-newsgroup-expirable)))
10299     ;; Remove from unread and marked lists.
10300     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10301     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10302     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10303     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10304     (push (cons article mark) gnus-newsgroup-reads)
10305     ;; Possibly remove from cache, if that is used.
10306     (when gnus-use-cache
10307       (gnus-cache-enter-remove-article article))
10308     t))
10309
10310 (defun gnus-mark-article-as-unread (article &optional mark)
10311   "Enter ARTICLE in the pertinent lists and remove it from others."
10312   (let ((mark (or mark gnus-ticked-mark)))
10313     (if (<= article 0)
10314         (progn
10315           (gnus-error 1 "Can't mark negative article numbers")
10316           nil)
10317       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10318             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10319             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10320             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10321             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10322
10323       ;; Unsuppress duplicates?
10324       (when gnus-suppress-duplicates
10325         (gnus-dup-unsuppress-article article))
10326
10327       (cond ((= mark gnus-ticked-mark)
10328              (setq gnus-newsgroup-marked
10329                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10330             ((= mark gnus-spam-mark)
10331              (setq gnus-newsgroup-spam-marked
10332                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10333                                             article)))
10334             ((= mark gnus-dormant-mark)
10335              (setq gnus-newsgroup-dormant
10336                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10337             (t
10338              (setq gnus-newsgroup-unreads
10339                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10340       (gnus-pull article gnus-newsgroup-reads)
10341       t)))
10342
10343 (defalias 'gnus-summary-mark-as-unread-forward
10344   'gnus-summary-tick-article-forward)
10345 (make-obsolete 'gnus-summary-mark-as-unread-forward
10346                'gnus-summary-tick-article-forward)
10347 (defun gnus-summary-tick-article-forward (n)
10348   "Tick N articles forwards.
10349 If N is negative, tick backwards instead.
10350 The difference between N and the number of articles ticked is returned."
10351   (interactive "p")
10352   (gnus-summary-mark-forward n gnus-ticked-mark))
10353
10354 (defalias 'gnus-summary-mark-as-unread-backward
10355   'gnus-summary-tick-article-backward)
10356 (make-obsolete 'gnus-summary-mark-as-unread-backward
10357                'gnus-summary-tick-article-backward)
10358 (defun gnus-summary-tick-article-backward (n)
10359   "Tick N articles backwards.
10360 The difference between N and the number of articles ticked is returned."
10361   (interactive "p")
10362   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10363
10364 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10365 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10366 (defun gnus-summary-tick-article (&optional article clear-mark)
10367   "Mark current article as unread.
10368 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10369 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10370   (interactive)
10371   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10372                                        gnus-ticked-mark)))
10373
10374 (defun gnus-summary-mark-as-read-forward (n)
10375   "Mark N articles as read forwards.
10376 If N is negative, mark backwards instead.
10377 The difference between N and the actual number of articles marked is
10378 returned."
10379   (interactive "p")
10380   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10381
10382 (defun gnus-summary-mark-as-read-backward (n)
10383   "Mark the N articles as read backwards.
10384 The difference between N and the actual number of articles marked is
10385 returned."
10386   (interactive "p")
10387   (gnus-summary-mark-forward
10388    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10389
10390 (defun gnus-summary-mark-as-read (&optional article mark)
10391   "Mark current article as read.
10392 ARTICLE specifies the article to be marked as read.
10393 MARK specifies a string to be inserted at the beginning of the line."
10394   (gnus-summary-mark-article article mark))
10395
10396 (defun gnus-summary-clear-mark-forward (n)
10397   "Clear marks from N articles forward.
10398 If N is negative, clear backward instead.
10399 The difference between N and the number of marks cleared is returned."
10400   (interactive "p")
10401   (gnus-summary-mark-forward n gnus-unread-mark))
10402
10403 (defun gnus-summary-clear-mark-backward (n)
10404   "Clear marks from N articles backward.
10405 The difference between N and the number of marks cleared is returned."
10406   (interactive "p")
10407   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10408
10409 (defun gnus-summary-mark-unread-as-read ()
10410   "Intended to be used by `gnus-mark-article-hook'."
10411   (when (memq gnus-current-article gnus-newsgroup-unreads)
10412     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10413
10414 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10415   "Intended to be used by `gnus-mark-article-hook'."
10416   (let ((mark (gnus-summary-article-mark)))
10417     (when (or (gnus-unread-mark-p mark)
10418               (gnus-read-mark-p mark))
10419       (gnus-summary-mark-article gnus-current-article
10420                                  (or new-mark gnus-read-mark)))))
10421
10422 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10423   "Intended to be used by `gnus-mark-article-hook'."
10424   (let ((mark (gnus-summary-article-mark)))
10425     (when (or (gnus-unread-mark-p mark)
10426               (gnus-read-mark-p mark))
10427       (gnus-summary-mark-article (gnus-summary-article-number)
10428                                  (or new-mark gnus-read-mark)))))
10429
10430 (defun gnus-summary-mark-unread-as-ticked ()
10431   "Intended to be used by `gnus-mark-article-hook'."
10432   (when (memq gnus-current-article gnus-newsgroup-unreads)
10433     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10434
10435 (defun gnus-summary-mark-region-as-read (point mark all)
10436   "Mark all unread articles between point and mark as read.
10437 If given a prefix, mark all articles between point and mark as read,
10438 even ticked and dormant ones."
10439   (interactive "r\nP")
10440   (save-excursion
10441     (let (article)
10442       (goto-char point)
10443       (beginning-of-line)
10444       (while (and
10445               (< (point) mark)
10446               (progn
10447                 (when (or all
10448                           (memq (setq article (gnus-summary-article-number))
10449                                 gnus-newsgroup-unreads))
10450                   (gnus-summary-mark-article article gnus-del-mark))
10451                 t)
10452               (gnus-summary-find-next))))))
10453
10454 (defun gnus-summary-mark-below (score mark)
10455   "Mark articles with score less than SCORE with MARK."
10456   (interactive "P\ncMark: ")
10457   (setq score (if score
10458                   (prefix-numeric-value score)
10459                 (or gnus-summary-default-score 0)))
10460   (save-excursion
10461     (set-buffer gnus-summary-buffer)
10462     (goto-char (point-min))
10463     (while
10464         (progn
10465           (and (< (gnus-summary-article-score) score)
10466                (gnus-summary-mark-article nil mark))
10467           (gnus-summary-find-next)))))
10468
10469 (defun gnus-summary-kill-below (&optional score)
10470   "Mark articles with score below SCORE as read."
10471   (interactive "P")
10472   (gnus-summary-mark-below score gnus-killed-mark))
10473
10474 (defun gnus-summary-clear-above (&optional score)
10475   "Clear all marks from articles with score above SCORE."
10476   (interactive "P")
10477   (gnus-summary-mark-above score gnus-unread-mark))
10478
10479 (defun gnus-summary-tick-above (&optional score)
10480   "Tick all articles with score above SCORE."
10481   (interactive "P")
10482   (gnus-summary-mark-above score gnus-ticked-mark))
10483
10484 (defun gnus-summary-mark-above (score mark)
10485   "Mark articles with score over SCORE with MARK."
10486   (interactive "P\ncMark: ")
10487   (setq score (if score
10488                   (prefix-numeric-value score)
10489                 (or gnus-summary-default-score 0)))
10490   (save-excursion
10491     (set-buffer gnus-summary-buffer)
10492     (goto-char (point-min))
10493     (while (and (progn
10494                   (when (> (gnus-summary-article-score) score)
10495                     (gnus-summary-mark-article nil mark))
10496                   t)
10497                 (gnus-summary-find-next)))))
10498
10499 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10500 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10501 (defun gnus-summary-limit-include-expunged (&optional no-error)
10502   "Display all the hidden articles that were expunged for low scores."
10503   (interactive)
10504   (let ((buffer-read-only nil))
10505     (let ((scored gnus-newsgroup-scored)
10506           headers h)
10507       (while scored
10508         (unless (gnus-summary-article-header (caar scored))
10509           (and (setq h (gnus-number-to-header (caar scored)))
10510                (< (cdar scored) gnus-summary-expunge-below)
10511                (push h headers)))
10512         (setq scored (cdr scored)))
10513       (if (not headers)
10514           (when (not no-error)
10515             (error "No expunged articles hidden"))
10516         (goto-char (point-min))
10517         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10518         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10519         (mapcar (lambda (x) (push (mail-header-number x)
10520                                   gnus-newsgroup-limit))
10521                 headers)
10522         (gnus-summary-prepare-unthreaded (nreverse headers))
10523         (goto-char (point-min))
10524         (gnus-summary-position-point)
10525         t))))
10526
10527 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10528   "Mark all unread articles in this newsgroup as read.
10529 If prefix argument ALL is non-nil, ticked and dormant articles will
10530 also be marked as read.
10531 If QUIETLY is non-nil, no questions will be asked.
10532
10533 If TO-HERE is non-nil, it should be a point in the buffer.  All
10534 articles before (after, if REVERSE is set) this point will be marked
10535 as read.
10536
10537 Note that this function will only catch up the unread article
10538 in the current summary buffer limitation.
10539
10540 The number of articles marked as read is returned."
10541   (interactive "P")
10542   (prog1
10543       (save-excursion
10544         (when (or quietly
10545                   (not gnus-interactive-catchup) ;Without confirmation?
10546                   gnus-expert-user
10547                   (gnus-y-or-n-p
10548                    (if all
10549                        "Mark absolutely all articles as read? "
10550                      "Mark all unread articles as read? ")))
10551           (if (and not-mark
10552                    (not gnus-newsgroup-adaptive)
10553                    (not gnus-newsgroup-auto-expire)
10554                    (not gnus-suppress-duplicates)
10555                    (or (not gnus-use-cache)
10556                        (eq gnus-use-cache 'passive)))
10557               (progn
10558                 (when all
10559                   (setq gnus-newsgroup-marked nil
10560                         gnus-newsgroup-spam-marked nil
10561                         gnus-newsgroup-dormant nil))
10562                 (setq gnus-newsgroup-unreads
10563                       (gnus-sorted-nunion
10564                        (gnus-sorted-intersection gnus-newsgroup-unreads
10565                                                  gnus-newsgroup-downloadable)
10566                        (gnus-sorted-difference gnus-newsgroup-unfetched
10567                                                gnus-newsgroup-cached))))
10568             ;; We actually mark all articles as canceled, which we
10569             ;; have to do when using auto-expiry or adaptive scoring.
10570             (gnus-summary-show-all-threads)
10571             (if (and to-here reverse)
10572                 (progn
10573                   (goto-char to-here)
10574                   (gnus-summary-mark-current-read-and-unread-as-read
10575                    gnus-catchup-mark)
10576                   (while (gnus-summary-find-next (not all))
10577                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10578               (when (gnus-summary-first-subject (not all))
10579                 (while (and
10580                         (if to-here (< (point) to-here) t)
10581                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10582                         (gnus-summary-find-next (not all))))))
10583             (gnus-set-mode-line 'summary))
10584           t))
10585     (gnus-summary-position-point)))
10586
10587 (defun gnus-summary-catchup-to-here (&optional all)
10588   "Mark all unticked articles before the current one as read.
10589 If ALL is non-nil, also mark ticked and dormant articles as read."
10590   (interactive "P")
10591   (save-excursion
10592     (gnus-save-hidden-threads
10593       (let ((beg (point)))
10594         ;; We check that there are unread articles.
10595         (when (or all (gnus-summary-find-prev))
10596           (gnus-summary-catchup all t beg)))))
10597   (gnus-summary-position-point))
10598
10599 (defun gnus-summary-catchup-from-here (&optional all)
10600   "Mark all unticked articles after (and including) the current one as read.
10601 If ALL is non-nil, also mark ticked and dormant articles as read."
10602   (interactive "P")
10603   (save-excursion
10604     (gnus-save-hidden-threads
10605       (let ((beg (point)))
10606         ;; We check that there are unread articles.
10607         (when (or all (gnus-summary-find-next))
10608           (gnus-summary-catchup all t beg nil t)))))
10609   (gnus-summary-position-point))
10610
10611 (defun gnus-summary-catchup-all (&optional quietly)
10612   "Mark all articles in this newsgroup as read.
10613 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10614 instead, which marks only unread articles as read."
10615   (interactive "P")
10616   (gnus-summary-catchup t quietly))
10617
10618 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10619   "Mark all unread articles in this group as read, then exit.
10620 If prefix argument ALL is non-nil, all articles are marked as read.
10621 If QUIETLY is non-nil, no questions will be asked."
10622   (interactive "P")
10623   (when (gnus-summary-catchup all quietly nil 'fast)
10624     ;; Select next newsgroup or exit.
10625     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10626              (eq gnus-auto-select-next 'quietly))
10627         (gnus-summary-next-group nil)
10628       (gnus-summary-exit))))
10629
10630 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10631   "Mark all articles in this newsgroup as read, and then exit.
10632 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10633 instead, which marks only unread articles as read."
10634   (interactive "P")
10635   (gnus-summary-catchup-and-exit t quietly))
10636
10637 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10638   "Mark all articles in this group as read and select the next group.
10639 If given a prefix, mark all articles, unread as well as ticked, as
10640 read."
10641   (interactive "P")
10642   (save-excursion
10643     (gnus-summary-catchup all))
10644   (gnus-summary-next-group))
10645
10646 ;;;
10647 ;;; with article
10648 ;;;
10649
10650 (defmacro gnus-with-article (article &rest forms)
10651   "Select ARTICLE and perform FORMS in the original article buffer.
10652 Then replace the article with the result."
10653   `(progn
10654      ;; We don't want the article to be marked as read.
10655      (let (gnus-mark-article-hook)
10656        (gnus-summary-select-article t t nil ,article))
10657      (set-buffer gnus-original-article-buffer)
10658      ,@forms
10659      (if (not (gnus-check-backend-function
10660                'request-replace-article (car gnus-article-current)))
10661          (gnus-message 5 "Read-only group; not replacing")
10662        (unless (gnus-request-replace-article
10663                 ,article (car gnus-article-current)
10664                 (current-buffer) t)
10665          (error "Couldn't replace article")))
10666      ;; The cache and backlog have to be flushed somewhat.
10667      (when gnus-keep-backlog
10668        (gnus-backlog-remove-article
10669         (car gnus-article-current) (cdr gnus-article-current)))
10670      (when gnus-use-cache
10671        (gnus-cache-update-article
10672         (car gnus-article-current) (cdr gnus-article-current)))))
10673
10674 (put 'gnus-with-article 'lisp-indent-function 1)
10675 (put 'gnus-with-article 'edebug-form-spec '(form body))
10676
10677 ;; Thread-based commands.
10678
10679 (defun gnus-summary-articles-in-thread (&optional article)
10680   "Return a list of all articles in the current thread.
10681 If ARTICLE is non-nil, return all articles in the thread that starts
10682 with that article."
10683   (let* ((article (or article (gnus-summary-article-number)))
10684          (data (gnus-data-find-list article))
10685          (top-level (gnus-data-level (car data)))
10686          (top-subject
10687           (cond ((null gnus-thread-operation-ignore-subject)
10688                  (gnus-simplify-subject-re
10689                   (mail-header-subject (gnus-data-header (car data)))))
10690                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10691                  (gnus-simplify-subject-fuzzy
10692                   (mail-header-subject (gnus-data-header (car data)))))
10693                 (t nil)))
10694          (end-point (save-excursion
10695                       (if (gnus-summary-go-to-next-thread)
10696                           (point) (point-max))))
10697          articles)
10698     (while (and data
10699                 (< (gnus-data-pos (car data)) end-point))
10700       (when (or (not top-subject)
10701                 (string= top-subject
10702                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10703                              (gnus-simplify-subject-fuzzy
10704                               (mail-header-subject
10705                                (gnus-data-header (car data))))
10706                            (gnus-simplify-subject-re
10707                             (mail-header-subject
10708                              (gnus-data-header (car data)))))))
10709         (push (gnus-data-number (car data)) articles))
10710       (unless (and (setq data (cdr data))
10711                    (> (gnus-data-level (car data)) top-level))
10712         (setq data nil)))
10713     ;; Return the list of articles.
10714     (nreverse articles)))
10715
10716 (defun gnus-summary-rethread-current ()
10717   "Rethread the thread the current article is part of."
10718   (interactive)
10719   (let* ((gnus-show-threads t)
10720          (article (gnus-summary-article-number))
10721          (id (mail-header-id (gnus-summary-article-header)))
10722          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10723     (unless id
10724       (error "No article on the current line"))
10725     (gnus-rebuild-thread id)
10726     (gnus-summary-goto-subject article)))
10727
10728 (defun gnus-summary-reparent-thread ()
10729   "Make the current article child of the marked (or previous) article.
10730
10731 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10732 is non-nil or the Subject: of both articles are the same."
10733   (interactive)
10734   (unless (not (gnus-group-read-only-p))
10735     (error "The current newsgroup does not support article editing"))
10736   (unless (<= (length gnus-newsgroup-processable) 1)
10737     (error "No more than one article may be marked"))
10738   (save-window-excursion
10739     (let ((gnus-article-buffer " *reparent*")
10740           (current-article (gnus-summary-article-number))
10741           ;; First grab the marked article, otherwise one line up.
10742           (parent-article (if (not (null gnus-newsgroup-processable))
10743                               (car gnus-newsgroup-processable)
10744                             (save-excursion
10745                               (if (eq (forward-line -1) 0)
10746                                   (gnus-summary-article-number)
10747                                 (error "Beginning of summary buffer"))))))
10748       (unless (not (eq current-article parent-article))
10749         (error "An article may not be self-referential"))
10750       (let ((message-id (mail-header-id
10751                          (gnus-summary-article-header parent-article))))
10752         (unless (and message-id (not (equal message-id "")))
10753           (error "No message-id in desired parent"))
10754         (gnus-with-article current-article
10755           (save-restriction
10756             (goto-char (point-min))
10757             (message-narrow-to-head)
10758             (if (re-search-forward "^References: " nil t)
10759                 (progn
10760                   (re-search-forward "^[^ \t]" nil t)
10761                   (forward-line -1)
10762                   (end-of-line)
10763                   (insert " " message-id))
10764               (insert "References: " message-id "\n"))))
10765         (set-buffer gnus-summary-buffer)
10766         (gnus-summary-unmark-all-processable)
10767         (gnus-summary-update-article current-article)
10768         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10769             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10770         (gnus-summary-rethread-current)
10771         (gnus-message 3 "Article %d is now the child of article %d"
10772                       current-article parent-article)))))
10773
10774 (defun gnus-summary-toggle-threads (&optional arg)
10775   "Toggle showing conversation threads.
10776 If ARG is positive number, turn showing conversation threads on."
10777   (interactive "P")
10778   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10779     (setq gnus-show-threads
10780           (if (null arg) (not gnus-show-threads)
10781             (> (prefix-numeric-value arg) 0)))
10782     (gnus-summary-prepare)
10783     (gnus-summary-goto-subject current)
10784     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10785     (gnus-summary-position-point)))
10786
10787 (defun gnus-summary-show-all-threads ()
10788   "Show all threads."
10789   (interactive)
10790   (save-excursion
10791     (let ((buffer-read-only nil))
10792       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10793   (gnus-summary-position-point))
10794
10795 (defun gnus-summary-show-thread ()
10796   "Show thread subtrees.
10797 Returns nil if no thread was there to be shown."
10798   (interactive)
10799   (let ((buffer-read-only nil)
10800         (orig (point))
10801         (end (gnus-point-at-eol))
10802         ;; Leave point at bol
10803         (beg (progn (beginning-of-line) (point))))
10804     (prog1
10805         ;; Any hidden lines here?
10806         (search-forward "\r" end t)
10807       (subst-char-in-region beg end ?\^M ?\n t)
10808       (goto-char orig)
10809       (gnus-summary-position-point))))
10810
10811 (defun gnus-summary-maybe-hide-threads ()
10812   "If requested, hide the threads that should be hidden."
10813   (when (and gnus-show-threads
10814              gnus-thread-hide-subtree)
10815     (gnus-summary-hide-all-threads
10816      (if (or (consp gnus-thread-hide-subtree)
10817              (functionp gnus-thread-hide-subtree))
10818          (gnus-make-predicate gnus-thread-hide-subtree)
10819        nil))))
10820
10821 ;;; Hiding predicates.
10822
10823 (defun gnus-article-unread-p (header)
10824   (memq (mail-header-number header) gnus-newsgroup-unreads))
10825
10826 (defun gnus-article-unseen-p (header)
10827   (memq (mail-header-number header) gnus-newsgroup-unseen))
10828
10829 (defun gnus-map-articles (predicate articles)
10830   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10831   (apply 'gnus-or (mapcar predicate
10832                           (mapcar (lambda (number)
10833                                     (gnus-summary-article-header number))
10834                                   articles))))
10835
10836 (defun gnus-summary-hide-all-threads (&optional predicate)
10837   "Hide all thread subtrees.
10838 If PREDICATE is supplied, threads that satisfy this predicate
10839 will not be hidden."
10840   (interactive)
10841   (save-excursion
10842     (goto-char (point-min))
10843     (let ((end nil))
10844       (while (not end)
10845         (when (or (not predicate)
10846                   (gnus-map-articles
10847                    predicate (gnus-summary-article-children)))
10848             (gnus-summary-hide-thread))
10849         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10850   (gnus-summary-position-point))
10851
10852 (defun gnus-summary-hide-thread ()
10853   "Hide thread subtrees.
10854 If PREDICATE is supplied, threads that satisfy this predicate
10855 will not be hidden.
10856 Returns nil if no threads were there to be hidden."
10857   (interactive)
10858   (let ((buffer-read-only nil)
10859         (start (point))
10860         (article (gnus-summary-article-number)))
10861     (goto-char start)
10862     ;; Go forward until either the buffer ends or the subthread
10863     ;; ends.
10864     (when (and (not (eobp))
10865                (or (zerop (gnus-summary-next-thread 1 t))
10866                    (goto-char (point-max))))
10867       (prog1
10868           (if (and (> (point) start)
10869                    (search-backward "\n" start t))
10870               (progn
10871                 (subst-char-in-region start (point) ?\n ?\^M)
10872                 (gnus-summary-goto-subject article))
10873             (goto-char start)
10874             nil)))))
10875
10876 (defun gnus-summary-go-to-next-thread (&optional previous)
10877   "Go to the same level (or less) next thread.
10878 If PREVIOUS is non-nil, go to previous thread instead.
10879 Return the article number moved to, or nil if moving was impossible."
10880   (let ((level (gnus-summary-thread-level))
10881         (way (if previous -1 1))
10882         (beg (point)))
10883     (forward-line way)
10884     (while (and (not (eobp))
10885                 (< level (gnus-summary-thread-level)))
10886       (forward-line way))
10887     (if (eobp)
10888         (progn
10889           (goto-char beg)
10890           nil)
10891       (setq beg (point))
10892       (prog1
10893           (gnus-summary-article-number)
10894         (goto-char beg)))))
10895
10896 (defun gnus-summary-next-thread (n &optional silent)
10897   "Go to the same level next N'th thread.
10898 If N is negative, search backward instead.
10899 Returns the difference between N and the number of skips actually
10900 done.
10901
10902 If SILENT, don't output messages."
10903   (interactive "p")
10904   (let ((backward (< n 0))
10905         (n (abs n)))
10906     (while (and (> n 0)
10907                 (gnus-summary-go-to-next-thread backward))
10908       (decf n))
10909     (unless silent
10910       (gnus-summary-position-point))
10911     (when (and (not silent) (/= 0 n))
10912       (gnus-message 7 "No more threads"))
10913     n))
10914
10915 (defun gnus-summary-prev-thread (n)
10916   "Go to the same level previous N'th thread.
10917 Returns the difference between N and the number of skips actually
10918 done."
10919   (interactive "p")
10920   (gnus-summary-next-thread (- n)))
10921
10922 (defun gnus-summary-go-down-thread ()
10923   "Go down one level in the current thread."
10924   (let ((children (gnus-summary-article-children)))
10925     (when children
10926       (gnus-summary-goto-subject (car children)))))
10927
10928 (defun gnus-summary-go-up-thread ()
10929   "Go up one level in the current thread."
10930   (let ((parent (gnus-summary-article-parent)))
10931     (when parent
10932       (gnus-summary-goto-subject parent))))
10933
10934 (defun gnus-summary-down-thread (n)
10935   "Go down thread N steps.
10936 If N is negative, go up instead.
10937 Returns the difference between N and how many steps down that were
10938 taken."
10939   (interactive "p")
10940   (let ((up (< n 0))
10941         (n (abs n)))
10942     (while (and (> n 0)
10943                 (if up (gnus-summary-go-up-thread)
10944                   (gnus-summary-go-down-thread)))
10945       (setq n (1- n)))
10946     (gnus-summary-position-point)
10947     (when (/= 0 n)
10948       (gnus-message 7 "Can't go further"))
10949     n))
10950
10951 (defun gnus-summary-up-thread (n)
10952   "Go up thread N steps.
10953 If N is negative, go down instead.
10954 Returns the difference between N and how many steps down that were
10955 taken."
10956   (interactive "p")
10957   (gnus-summary-down-thread (- n)))
10958
10959 (defun gnus-summary-top-thread ()
10960   "Go to the top of the thread."
10961   (interactive)
10962   (while (gnus-summary-go-up-thread))
10963   (gnus-summary-article-number))
10964
10965 (defun gnus-summary-kill-thread (&optional unmark)
10966   "Mark articles under current thread as read.
10967 If the prefix argument is positive, remove any kinds of marks.
10968 If the prefix argument is negative, tick articles instead."
10969   (interactive "P")
10970   (when unmark
10971     (setq unmark (prefix-numeric-value unmark)))
10972   (let ((articles (gnus-summary-articles-in-thread)))
10973     (save-excursion
10974       ;; Expand the thread.
10975       (gnus-summary-show-thread)
10976       ;; Mark all the articles.
10977       (while articles
10978         (gnus-summary-goto-subject (car articles))
10979         (cond ((null unmark)
10980                (gnus-summary-mark-article-as-read gnus-killed-mark))
10981               ((> unmark 0)
10982                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10983               (t
10984                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10985         (setq articles (cdr articles))))
10986     ;; Hide killed subtrees.
10987     (and (null unmark)
10988          gnus-thread-hide-killed
10989          (gnus-summary-hide-thread))
10990     ;; If marked as read, go to next unread subject.
10991     (when (null unmark)
10992       ;; Go to next unread subject.
10993       (gnus-summary-next-subject 1 t)))
10994   (gnus-set-mode-line 'summary))
10995
10996 ;; Summary sorting commands
10997
10998 (defun gnus-summary-sort-by-number (&optional reverse)
10999   "Sort the summary buffer by article number.
11000 Argument REVERSE means reverse order."
11001   (interactive "P")
11002   (gnus-summary-sort 'number reverse))
11003
11004 (defun gnus-summary-sort-by-random (&optional reverse)
11005   "Randomize the order in the summary buffer.
11006 Argument REVERSE means to randomize in reverse order."
11007   (interactive "P")
11008   (gnus-summary-sort 'random reverse))
11009
11010 (defun gnus-summary-sort-by-author (&optional reverse)
11011   "Sort the summary buffer by author name alphabetically.
11012 If `case-fold-search' is non-nil, case of letters is ignored.
11013 Argument REVERSE means reverse order."
11014   (interactive "P")
11015   (gnus-summary-sort 'author reverse))
11016
11017 (defun gnus-summary-sort-by-subject (&optional reverse)
11018   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11019 If `case-fold-search' is non-nil, case of letters is ignored.
11020 Argument REVERSE means reverse order."
11021   (interactive "P")
11022   (gnus-summary-sort 'subject reverse))
11023
11024 (defun gnus-summary-sort-by-date (&optional reverse)
11025   "Sort the summary buffer by date.
11026 Argument REVERSE means reverse order."
11027   (interactive "P")
11028   (gnus-summary-sort 'date reverse))
11029
11030 (defun gnus-summary-sort-by-score (&optional reverse)
11031   "Sort the summary buffer by score.
11032 Argument REVERSE means reverse order."
11033   (interactive "P")
11034   (gnus-summary-sort 'score reverse))
11035
11036 (defun gnus-summary-sort-by-lines (&optional reverse)
11037   "Sort the summary buffer by the number of lines.
11038 Argument REVERSE means reverse order."
11039   (interactive "P")
11040   (gnus-summary-sort 'lines reverse))
11041
11042 (defun gnus-summary-sort-by-chars (&optional reverse)
11043   "Sort the summary buffer by article length.
11044 Argument REVERSE means reverse order."
11045   (interactive "P")
11046   (gnus-summary-sort 'chars reverse))
11047
11048 (defun gnus-summary-sort-by-original (&optional reverse)
11049   "Sort the summary buffer using the default sorting method.
11050 Argument REVERSE means reverse order."
11051   (interactive "P")
11052   (let* ((buffer-read-only)
11053          (gnus-summary-prepare-hook nil))
11054     ;; We do the sorting by regenerating the threads.
11055     (gnus-summary-prepare)
11056     ;; Hide subthreads if needed.
11057     (gnus-summary-maybe-hide-threads)))
11058
11059 (defun gnus-summary-sort (predicate reverse)
11060   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11061   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11062          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11063          (gnus-thread-sort-functions
11064           (if (not reverse)
11065               thread
11066             `(lambda (t1 t2)
11067                (,thread t2 t1))))
11068          (gnus-sort-gathered-threads-function
11069           gnus-thread-sort-functions)
11070          (gnus-article-sort-functions
11071           (if (not reverse)
11072               article
11073             `(lambda (t1 t2)
11074                (,article t2 t1))))
11075          (buffer-read-only)
11076          (gnus-summary-prepare-hook nil))
11077     ;; We do the sorting by regenerating the threads.
11078     (gnus-summary-prepare)
11079     ;; Hide subthreads if needed.
11080     (gnus-summary-maybe-hide-threads)))
11081
11082 ;; Summary saving commands.
11083
11084 (defun gnus-summary-save-article (&optional n not-saved)
11085   "Save the current article using the default saver function.
11086 If N is a positive number, save the N next articles.
11087 If N is a negative number, save the N previous articles.
11088 If N is nil and any articles have been marked with the process mark,
11089 save those articles instead.
11090 The variable `gnus-default-article-saver' specifies the saver function.
11091
11092 If the optional second argument NOT-SAVED is non-nil, articles saved
11093 will not be marked as saved."
11094   (interactive "P")
11095   (require 'gnus-art)
11096   (let* ((articles (gnus-summary-work-articles n))
11097          (save-buffer (save-excursion
11098                         (nnheader-set-temp-buffer " *Gnus Save*")))
11099          (num (length articles))
11100          ;; Whether to save decoded articles or raw articles.
11101          (decode (when gnus-article-save-coding-system
11102                    (get gnus-default-article-saver :decode)))
11103          ;; When saving many articles in a single file, use the other
11104          ;; function to save articles other than the first one.
11105          (saver2 (get gnus-default-article-saver :function))
11106          (gnus-prompt-before-saving (if saver2
11107                                         t
11108                                       gnus-prompt-before-saving))
11109          (gnus-default-article-saver gnus-default-article-saver)
11110          header file)
11111     (dolist (article articles)
11112       (setq header (gnus-summary-article-header article))
11113       (if (not (vectorp header))
11114           ;; This is a pseudo-article.
11115           (if (assq 'name header)
11116               (gnus-copy-file (cdr (assq 'name header)))
11117             (gnus-message 1 "Article %d is unsaveable" article))
11118         ;; This is a real article.
11119         (save-window-excursion
11120           (let ((gnus-display-mime-function (when decode
11121                                               gnus-display-mime-function))
11122                 (gnus-article-prepare-hook (when decode
11123                                              gnus-article-prepare-hook)))
11124             (gnus-summary-select-article t nil nil article)
11125             (gnus-summary-goto-subject article)))
11126         (save-excursion
11127           (set-buffer save-buffer)
11128           (erase-buffer)
11129           (insert-buffer-substring (if decode
11130                                        gnus-article-buffer
11131                                      gnus-original-article-buffer)))
11132         (setq file (gnus-article-save save-buffer file num))
11133         (gnus-summary-remove-process-mark article)
11134         (unless not-saved
11135           (gnus-summary-set-saved-mark article)))
11136       (when saver2
11137         (setq gnus-default-article-saver saver2
11138               saver2 nil)))
11139     (gnus-kill-buffer save-buffer)
11140     (gnus-summary-position-point)
11141     (gnus-set-mode-line 'summary)
11142     n))
11143
11144 (defun gnus-summary-pipe-output (&optional arg headers)
11145   "Pipe the current article to a subprocess.
11146 If N is a positive number, pipe the N next articles.
11147 If N is a negative number, pipe the N previous articles.
11148 If N is nil and any articles have been marked with the process mark,
11149 pipe those articles instead.
11150 If HEADERS (the symbolic prefix), include the headers, too."
11151   (interactive (gnus-interactive "P\ny"))
11152   (require 'gnus-art)
11153   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11154         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11155     (gnus-summary-save-article arg t))
11156   (let ((buffer (get-buffer "*Shell Command Output*")))
11157     (when (and buffer
11158                (not (zerop (buffer-size buffer))))
11159       (gnus-configure-windows 'pipe))))
11160
11161 (defun gnus-summary-save-article-mail (&optional arg)
11162   "Append the current article to a Unix mail box file.
11163 If N is a positive number, save the N next articles.
11164 If N is a negative number, save the N previous articles.
11165 If N is nil and any articles have been marked with the process mark,
11166 save those articles instead."
11167   (interactive "P")
11168   (require 'gnus-art)
11169   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11170     (gnus-summary-save-article arg)))
11171
11172 (defun gnus-summary-save-article-rmail (&optional arg)
11173   "Append the current article to an rmail file.
11174 If N is a positive number, save the N next articles.
11175 If N is a negative number, save the N previous articles.
11176 If N is nil and any articles have been marked with the process mark,
11177 save those articles instead."
11178   (interactive "P")
11179   (require 'gnus-art)
11180   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11181     (gnus-summary-save-article arg)))
11182
11183 (defun gnus-summary-save-article-file (&optional arg)
11184   "Append the current article to a file.
11185 If N is a positive number, save the N next articles.
11186 If N is a negative number, save the N previous articles.
11187 If N is nil and any articles have been marked with the process mark,
11188 save those articles instead."
11189   (interactive "P")
11190   (require 'gnus-art)
11191   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11192     (gnus-summary-save-article arg)))
11193
11194 (defun gnus-summary-write-article-file (&optional arg)
11195   "Write the current article to a file, deleting the previous file.
11196 If N is a positive number, save the N next articles.
11197 If N is a negative number, save the N previous articles.
11198 If N is nil and any articles have been marked with the process mark,
11199 save those articles instead."
11200   (interactive "P")
11201   (require 'gnus-art)
11202   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11203     (gnus-summary-save-article arg)))
11204
11205 (defun gnus-summary-save-article-body-file (&optional arg)
11206   "Append the current article body to a file.
11207 If N is a positive number, save the N next articles.
11208 If N is a negative number, save the N previous articles.
11209 If N is nil and any articles have been marked with the process mark,
11210 save those articles instead."
11211   (interactive "P")
11212   (require 'gnus-art)
11213   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11214     (gnus-summary-save-article arg)))
11215
11216 (defun gnus-summary-write-article-body-file (&optional arg)
11217   "Write the current article body to a file, deleting the previous file.
11218 If N is a positive number, save the N next articles.
11219 If N is a negative number, save the N previous articles.
11220 If N is nil and any articles have been marked with the process mark,
11221 save those articles instead."
11222   (interactive "P")
11223   (require 'gnus-art)
11224   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11225     (gnus-summary-save-article arg)))
11226
11227 (defun gnus-summary-muttprint (&optional arg)
11228   "Print the current article using Muttprint.
11229 If N is a positive number, save the N next articles.
11230 If N is a negative number, save the N previous articles.
11231 If N is nil and any articles have been marked with the process mark,
11232 save those articles instead."
11233   (interactive "P")
11234   (require 'gnus-art)
11235   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11236     (gnus-summary-save-article arg t)))
11237
11238 (defun gnus-summary-pipe-message (program)
11239   "Pipe the current article through PROGRAM."
11240   (interactive "sProgram: ")
11241   (gnus-summary-select-article)
11242   (let ((mail-header-separator ""))
11243     (gnus-eval-in-buffer-window gnus-article-buffer
11244       (save-restriction
11245         (widen)
11246         (let ((start (window-start))
11247               buffer-read-only)
11248           (message-pipe-buffer-body program)
11249           (set-window-start (get-buffer-window (current-buffer)) start))))))
11250
11251 (defun gnus-get-split-value (methods)
11252   "Return a value based on the split METHODS."
11253   (let (split-name method result match)
11254     (when methods
11255       (save-excursion
11256         (set-buffer gnus-original-article-buffer)
11257         (save-restriction
11258           (nnheader-narrow-to-headers)
11259           (while (and methods (not split-name))
11260             (goto-char (point-min))
11261             (setq method (pop methods))
11262             (setq match (car method))
11263             (when (cond
11264                    ((stringp match)
11265                     ;; Regular expression.
11266                     (ignore-errors
11267                       (re-search-forward match nil t)))
11268                    ((functionp match)
11269                     ;; Function.
11270                     (save-restriction
11271                       (widen)
11272                       (setq result (funcall match gnus-newsgroup-name))))
11273                    ((consp match)
11274                     ;; Form.
11275                     (save-restriction
11276                       (widen)
11277                       (setq result (eval match)))))
11278               (setq split-name (cdr method))
11279               (cond ((stringp result)
11280                      (push (expand-file-name
11281                             result gnus-article-save-directory)
11282                            split-name))
11283                     ((consp result)
11284                      (setq split-name (append result split-name)))))))))
11285     (nreverse split-name)))
11286
11287 (defun gnus-valid-move-group-p (group)
11288   (and (boundp group)
11289        (symbol-name group)
11290        (symbol-value group)
11291        (gnus-get-function (gnus-find-method-for-group
11292                            (symbol-name group)) 'request-accept-article t)))
11293
11294 (defun gnus-read-move-group-name (prompt default articles prefix)
11295   "Read a group name."
11296   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11297          (minibuffer-confirm-incomplete nil) ; XEmacs
11298          (prom
11299           (format "%s %s to"
11300                   prompt
11301                   (if (> (length articles) 1)
11302                       (format "these %d articles" (length articles))
11303                     "this article")))
11304          (to-newsgroup
11305           (cond
11306            ((null split-name)
11307             (gnus-completing-read-with-default
11308              default prom
11309              gnus-active-hashtb
11310              'gnus-valid-move-group-p
11311              nil prefix
11312              'gnus-group-history))
11313            ((= 1 (length split-name))
11314             (gnus-completing-read-with-default
11315              (car split-name) prom
11316              gnus-active-hashtb
11317              'gnus-valid-move-group-p
11318              nil nil
11319              'gnus-group-history))
11320            (t
11321             (gnus-completing-read-with-default
11322              nil prom
11323              (mapcar (lambda (el) (list el))
11324                      (nreverse split-name))
11325              nil nil nil
11326              'gnus-group-history))))
11327          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11328     (when to-newsgroup
11329       (if (or (string= to-newsgroup "")
11330               (string= to-newsgroup prefix))
11331           (setq to-newsgroup default))
11332       (unless to-newsgroup
11333         (error "No group name entered"))
11334       (or (gnus-active to-newsgroup)
11335           (gnus-activate-group to-newsgroup nil nil to-method)
11336           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11337                                      to-newsgroup))
11338               (or (and (gnus-request-create-group to-newsgroup to-method)
11339                        (gnus-activate-group
11340                         to-newsgroup nil nil to-method)
11341                        (gnus-subscribe-group to-newsgroup))
11342                   (error "Couldn't create group %s" to-newsgroup)))
11343           (error "No such group: %s" to-newsgroup)))
11344     to-newsgroup))
11345
11346 (defun gnus-summary-save-parts (type dir n &optional reverse)
11347   "Save parts matching TYPE to DIR.
11348 If REVERSE, save parts that do not match TYPE."
11349   (interactive
11350    (list (read-string "Save parts of type: "
11351                       (or (car gnus-summary-save-parts-type-history)
11352                           gnus-summary-save-parts-default-mime)
11353                       'gnus-summary-save-parts-type-history)
11354          (setq gnus-summary-save-parts-last-directory
11355                (read-file-name "Save to directory: "
11356                                gnus-summary-save-parts-last-directory
11357                                nil t))
11358          current-prefix-arg))
11359   (gnus-summary-iterate n
11360     (let ((gnus-display-mime-function nil)
11361           (gnus-inhibit-treatment t))
11362       (gnus-summary-select-article))
11363     (save-excursion
11364       (set-buffer gnus-article-buffer)
11365       (let ((handles (or gnus-article-mime-handles
11366                          (mm-dissect-buffer nil gnus-article-loose-mime)
11367                          (and gnus-article-emulate-mime
11368                               (mm-uu-dissect)))))
11369         (when handles
11370           (gnus-summary-save-parts-1 type dir handles reverse)
11371           (unless gnus-article-mime-handles ;; Don't destroy this case.
11372             (mm-destroy-parts handles)))))))
11373
11374 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11375   (if (stringp (car handle))
11376       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11377               (cdr handle))
11378     (when (if reverse
11379               (not (string-match type (mm-handle-media-type handle)))
11380             (string-match type (mm-handle-media-type handle)))
11381       (let ((file (expand-file-name
11382                    (gnus-map-function
11383                     mm-file-name-rewrite-functions
11384                     (file-name-nondirectory
11385                      (or
11386                       (mail-content-type-get
11387                        (mm-handle-disposition handle) 'filename)
11388                       (mail-content-type-get
11389                        (mm-handle-type handle) 'name)
11390                       (concat gnus-newsgroup-name
11391                               "." (number-to-string
11392                                    (cdr gnus-article-current))))))
11393                    dir)))
11394         (unless (file-exists-p file)
11395           (mm-save-part-to-file handle file))))))
11396
11397 ;; Summary extract commands
11398
11399 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11400   (let ((buffer-read-only nil)
11401         (article (gnus-summary-article-number))
11402         after-article b e)
11403     (unless (gnus-summary-goto-subject article)
11404       (error "No such article: %d" article))
11405     (gnus-summary-position-point)
11406     ;; If all commands are to be bunched up on one line, we collect
11407     ;; them here.
11408     (unless gnus-view-pseudos-separately
11409       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11410             files action)
11411         (while ps
11412           (setq action (cdr (assq 'action (car ps))))
11413           (setq files (list (cdr (assq 'name (car ps)))))
11414           (while (and ps (cdr ps)
11415                       (string= (or action "1")
11416                                (or (cdr (assq 'action (cadr ps))) "2")))
11417             (push (cdr (assq 'name (cadr ps))) files)
11418             (setcdr ps (cddr ps)))
11419           (when files
11420             (when (not (string-match "%s" action))
11421               (push " " files))
11422             (push " " files)
11423             (when (assq 'execute (car ps))
11424               (setcdr (assq 'execute (car ps))
11425                       (funcall (if (string-match "%s" action)
11426                                    'format 'concat)
11427                                action
11428                                (mapconcat
11429                                 (lambda (f)
11430                                   (if (equal f " ")
11431                                       f
11432                                     (mm-quote-arg f)))
11433                                 files " ")))))
11434           (setq ps (cdr ps)))))
11435     (if (and gnus-view-pseudos (not not-view))
11436         (while pslist
11437           (when (assq 'execute (car pslist))
11438             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11439                                   (eq gnus-view-pseudos 'not-confirm)))
11440           (setq pslist (cdr pslist)))
11441       (save-excursion
11442         (while pslist
11443           (setq after-article (or (cdr (assq 'article (car pslist)))
11444                                   (gnus-summary-article-number)))
11445           (gnus-summary-goto-subject after-article)
11446           (forward-line 1)
11447           (setq b (point))
11448           (insert "    " (file-name-nondirectory
11449                           (cdr (assq 'name (car pslist))))
11450                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11451           (setq e (point))
11452           (forward-line -1)             ; back to `b'
11453           (gnus-add-text-properties
11454            b (1- e) (list 'gnus-number gnus-reffed-article-number
11455                           gnus-mouse-face-prop gnus-mouse-face))
11456           (gnus-data-enter
11457            after-article gnus-reffed-article-number
11458            gnus-unread-mark b (car pslist) 0 (- e b))
11459           (setq gnus-newsgroup-unreads
11460                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11461                                          gnus-reffed-article-number))
11462           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11463           (setq pslist (cdr pslist)))))))
11464
11465 (defun gnus-pseudos< (p1 p2)
11466   (let ((c1 (cdr (assq 'action p1)))
11467         (c2 (cdr (assq 'action p2))))
11468     (and c1 c2 (string< c1 c2))))
11469
11470 (defun gnus-request-pseudo-article (props)
11471   (cond ((assq 'execute props)
11472          (gnus-execute-command (cdr (assq 'execute props)))))
11473   (let ((gnus-current-article (gnus-summary-article-number)))
11474     (gnus-run-hooks 'gnus-mark-article-hook)))
11475
11476 (defun gnus-execute-command (command &optional automatic)
11477   (save-excursion
11478     (gnus-article-setup-buffer)
11479     (set-buffer gnus-article-buffer)
11480     (setq buffer-read-only nil)
11481     (let ((command (if automatic command
11482                      (read-string "Command: " (cons command 0)))))
11483       (erase-buffer)
11484       (insert "$ " command "\n\n")
11485       (if gnus-view-pseudo-asynchronously
11486           (start-process "gnus-execute" (current-buffer) shell-file-name
11487                          shell-command-switch command)
11488         (call-process shell-file-name nil t nil
11489                       shell-command-switch command)))))
11490
11491 ;; Summary kill commands.
11492
11493 (defun gnus-summary-edit-global-kill (article)
11494   "Edit the \"global\" kill file."
11495   (interactive (list (gnus-summary-article-number)))
11496   (gnus-group-edit-global-kill article))
11497
11498 (defun gnus-summary-edit-local-kill ()
11499   "Edit a local kill file applied to the current newsgroup."
11500   (interactive)
11501   (setq gnus-current-headers (gnus-summary-article-header))
11502   (gnus-group-edit-local-kill
11503    (gnus-summary-article-number) gnus-newsgroup-name))
11504
11505 ;;; Header reading.
11506
11507 (defun gnus-read-header (id &optional header)
11508   "Read the headers of article ID and enter them into the Gnus system."
11509   (let ((group gnus-newsgroup-name)
11510         (gnus-override-method
11511          (or
11512           gnus-override-method
11513           (and (gnus-news-group-p gnus-newsgroup-name)
11514                (car (gnus-refer-article-methods)))))
11515         where)
11516     ;; First we check to see whether the header in question is already
11517     ;; fetched.
11518     (if (stringp id)
11519         ;; This is a Message-ID.
11520         (setq header (or header (gnus-id-to-header id)))
11521       ;; This is an article number.
11522       (setq header (or header (gnus-summary-article-header id))))
11523     (if (and header
11524              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11525         ;; We have found the header.
11526         header
11527       ;; We have to really fetch the header to this article.
11528       (save-excursion
11529         (set-buffer nntp-server-buffer)
11530         (when (setq where (gnus-request-head id group))
11531           (nnheader-fold-continuation-lines)
11532           (goto-char (point-max))
11533           (insert ".\n")
11534           (goto-char (point-min))
11535           (insert "211 ")
11536           (princ (cond
11537                   ((numberp id) id)
11538                   ((cdr where) (cdr where))
11539                   (header (mail-header-number header))
11540                   (t gnus-reffed-article-number))
11541                  (current-buffer))
11542           (insert " Article retrieved.\n"))
11543         (if (or (not where)
11544                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11545             ()                          ; Malformed head.
11546           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11547             (when (and (stringp id)
11548                        (not (string= (gnus-group-real-name group)
11549                                      (car where))))
11550               ;; If we fetched by Message-ID and the article came
11551               ;; from a different group, we fudge some bogus article
11552               ;; numbers for this article.
11553               (mail-header-set-number header gnus-reffed-article-number))
11554             (save-excursion
11555               (set-buffer gnus-summary-buffer)
11556               (decf gnus-reffed-article-number)
11557               (gnus-remove-header (mail-header-number header))
11558               (push header gnus-newsgroup-headers)
11559               (setq gnus-current-headers header)
11560               (push (mail-header-number header) gnus-newsgroup-limit)))
11561           header)))))
11562
11563 (defun gnus-remove-header (number)
11564   "Remove header NUMBER from `gnus-newsgroup-headers'."
11565   (if (and gnus-newsgroup-headers
11566            (= number (mail-header-number (car gnus-newsgroup-headers))))
11567       (pop gnus-newsgroup-headers)
11568     (let ((headers gnus-newsgroup-headers))
11569       (while (and (cdr headers)
11570                   (not (= number (mail-header-number (cadr headers)))))
11571         (pop headers))
11572       (when (cdr headers)
11573         (setcdr headers (cddr headers))))))
11574
11575 ;;;
11576 ;;; summary highlights
11577 ;;;
11578
11579 (defun gnus-highlight-selected-summary ()
11580   "Highlight selected article in summary buffer."
11581   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11582   (when gnus-summary-selected-face
11583     (save-excursion
11584       (let* ((beg (gnus-point-at-bol))
11585              (end (gnus-point-at-eol))
11586              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11587              (from (if (get-text-property beg gnus-mouse-face-prop)
11588                        beg
11589                      (or (next-single-property-change
11590                           beg gnus-mouse-face-prop nil end)
11591                          beg)))
11592              (to
11593               (if (= from end)
11594                   (- from 2)
11595                 (or (next-single-property-change
11596                      from gnus-mouse-face-prop nil end)
11597                     end))))
11598         ;; If no mouse-face prop on line we will have to = from = end,
11599         ;; so we highlight the entire line instead.
11600         (when (= (+ to 2) from)
11601           (setq from beg)
11602           (setq to end))
11603         (if gnus-newsgroup-selected-overlay
11604             ;; Move old overlay.
11605             (gnus-move-overlay
11606              gnus-newsgroup-selected-overlay from to (current-buffer))
11607           ;; Create new overlay.
11608           (gnus-overlay-put
11609            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11610            'face gnus-summary-selected-face))))))
11611
11612 (defvar gnus-summary-highlight-line-cached nil)
11613 (defvar gnus-summary-highlight-line-trigger nil)
11614
11615 (defun gnus-summary-highlight-line-0 ()
11616   (if (and (eq gnus-summary-highlight-line-trigger
11617                gnus-summary-highlight)
11618            gnus-summary-highlight-line-cached)
11619       gnus-summary-highlight-line-cached
11620     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11621           gnus-summary-highlight-line-cached
11622           (let* ((cond (list 'cond))
11623                  (c cond)
11624                  (list gnus-summary-highlight))
11625             (while list
11626               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11627                               nil))
11628               (setq c (cdr c)
11629                     list (cdr list)))
11630             (gnus-byte-compile (list 'lambda nil cond))))))
11631
11632 (defun gnus-summary-highlight-line ()
11633   "Highlight current line according to `gnus-summary-highlight'."
11634   (let* ((beg (gnus-point-at-bol))
11635          (article (or (gnus-summary-article-number) gnus-current-article))
11636          (score (or (cdr (assq article
11637                                gnus-newsgroup-scored))
11638                     gnus-summary-default-score 0))
11639          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11640          (inhibit-read-only t)
11641          (default gnus-summary-default-score)
11642          (default-high gnus-summary-default-high-score)
11643          (default-low gnus-summary-default-low-score)
11644          (uncached (and gnus-summary-use-undownloaded-faces
11645                         (memq article gnus-newsgroup-undownloaded)
11646                         (not (memq article gnus-newsgroup-cached)))))
11647     (let ((face (funcall (gnus-summary-highlight-line-0))))
11648       (unless (eq face (get-text-property beg 'face))
11649         (gnus-put-text-property-excluding-characters-with-faces
11650          beg (gnus-point-at-eol) 'face
11651          (setq face (if (boundp face) (symbol-value face) face)))
11652         (when gnus-summary-highlight-line-function
11653           (funcall gnus-summary-highlight-line-function article face))))))
11654
11655 (defun gnus-update-read-articles (group unread &optional compute)
11656   "Update the list of read articles in GROUP.
11657 UNREAD is a sorted list."
11658   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11659          (entry (gnus-gethash group gnus-newsrc-hashtb))
11660          (info (nth 2 entry))
11661          (prev 1)
11662          read)
11663     (if (or (not info) (not active))
11664         ;; There is no info on this group if it was, in fact,
11665         ;; killed.  Gnus stores no information on killed groups, so
11666         ;; there's nothing to be done.
11667         ;; One could store the information somewhere temporarily,
11668         ;; perhaps...  Hmmm...
11669         ()
11670       ;; Remove any negative articles numbers.
11671       (while (and unread (< (car unread) 0))
11672         (setq unread (cdr unread)))
11673       ;; Remove any expired article numbers
11674       (while (and unread (< (car unread) (car active)))
11675         (setq unread (cdr unread)))
11676       ;; Compute the ranges of read articles by looking at the list of
11677       ;; unread articles.
11678       (while unread
11679         (when (/= (car unread) prev)
11680           (push (if (= prev (1- (car unread))) prev
11681                   (cons prev (1- (car unread))))
11682                 read))
11683         (setq prev (1+ (car unread)))
11684         (setq unread (cdr unread)))
11685       (when (<= prev (cdr active))
11686         (push (cons prev (cdr active)) read))
11687       (setq read (if (> (length read) 1) (nreverse read) read))
11688       (if compute
11689           read
11690         (save-excursion
11691           (let (setmarkundo)
11692             ;; Propagate the read marks to the backend.
11693             (when (gnus-check-backend-function 'request-set-mark group)
11694               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11695                     (add (gnus-remove-from-range read (gnus-info-read info))))
11696                 (when (or add del)
11697                   (unless (gnus-check-group group)
11698                     (error "Can't open server for %s" group))
11699                   (gnus-request-set-mark
11700                    group (delq nil (list (if add (list add 'add '(read)))
11701                                          (if del (list del 'del '(read))))))
11702                   (setq setmarkundo
11703                         `(gnus-request-set-mark
11704                           ,group
11705                           ',(delq nil (list
11706                                        (if del (list del 'add '(read)))
11707                                        (if add (list add 'del '(read))))))))))
11708             (set-buffer gnus-group-buffer)
11709             (gnus-undo-register
11710               `(progn
11711                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11712                  (gnus-info-set-read ',info ',(gnus-info-read info))
11713                  (gnus-get-unread-articles-in-group ',info
11714                                                     (gnus-active ,group))
11715                  (gnus-group-update-group ,group t)
11716                  ,setmarkundo))))
11717         ;; Enter this list into the group info.
11718         (gnus-info-set-read info read)
11719         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11720         (gnus-get-unread-articles-in-group info (gnus-active group))
11721         t))))
11722
11723 (defun gnus-offer-save-summaries ()
11724   "Offer to save all active summary buffers."
11725   (let (buffers)
11726     ;; Go through all buffers and find all summaries.
11727     (dolist (buffer (buffer-list))
11728       (when (and (setq buffer (buffer-name buffer))
11729                  (string-match "Summary" buffer)
11730                  (save-excursion
11731                    (set-buffer buffer)
11732                    ;; We check that this is, indeed, a summary buffer.
11733                    (and (eq major-mode 'gnus-summary-mode)
11734                         ;; Also make sure this isn't bogus.
11735                         gnus-newsgroup-prepared
11736                         ;; Also make sure that this isn't a
11737                         ;; dead summary buffer.
11738                         (not gnus-dead-summary-mode))))
11739         (push buffer buffers)))
11740     ;; Go through all these summary buffers and offer to save them.
11741     (when buffers
11742       (save-excursion
11743         (map-y-or-n-p
11744          "Update summary buffer %s? "
11745          (lambda (buf)
11746            (switch-to-buffer buf)
11747            (gnus-summary-exit))
11748          buffers)))))
11749
11750 (defun gnus-summary-setup-default-charset ()
11751   "Setup newsgroup default charset."
11752   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11753       (setq gnus-newsgroup-charset nil)
11754     (let* ((ignored-charsets
11755             (or gnus-newsgroup-ephemeral-ignored-charsets
11756                 (append
11757                  (and gnus-newsgroup-name
11758                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11759                  gnus-newsgroup-ignored-charsets))))
11760       (setq gnus-newsgroup-charset
11761             (or gnus-newsgroup-ephemeral-charset
11762                 (and gnus-newsgroup-name
11763                      (gnus-parameter-charset gnus-newsgroup-name))
11764                 gnus-default-charset))
11765       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11766            ignored-charsets))))
11767
11768 ;;;
11769 ;;; Mime Commands
11770 ;;;
11771
11772 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11773   "Display the current article buffer fully MIME-buttonized.
11774 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11775 treated as multipart/mixed."
11776   (interactive "P")
11777   (require 'gnus-art)
11778   (let ((gnus-unbuttonized-mime-types nil)
11779         (gnus-mime-display-multipart-as-mixed show-all-parts))
11780     (gnus-summary-show-article)))
11781
11782 (defun gnus-summary-repair-multipart (article)
11783   "Add a Content-Type header to a multipart article without one."
11784   (interactive (list (gnus-summary-article-number)))
11785   (gnus-with-article article
11786     (message-narrow-to-head)
11787     (message-remove-header "Mime-Version")
11788     (goto-char (point-max))
11789     (insert "Mime-Version: 1.0\n")
11790     (widen)
11791     (when (search-forward "\n--" nil t)
11792       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11793         (message-narrow-to-head)
11794         (message-remove-header "Content-Type")
11795         (goto-char (point-max))
11796         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11797                         separator))
11798         (widen))))
11799   (let (gnus-mark-article-hook)
11800     (gnus-summary-select-article t t nil article)))
11801
11802 (defun gnus-summary-toggle-display-buttonized ()
11803   "Toggle the buttonizing of the article buffer."
11804   (interactive)
11805   (require 'gnus-art)
11806   (if (setq gnus-inhibit-mime-unbuttonizing
11807             (not gnus-inhibit-mime-unbuttonizing))
11808       (let ((gnus-unbuttonized-mime-types nil))
11809         (gnus-summary-show-article))
11810     (gnus-summary-show-article)))
11811
11812 ;;;
11813 ;;; Generic summary marking commands
11814 ;;;
11815
11816 (defvar gnus-summary-marking-alist
11817   '((read gnus-del-mark "d")
11818     (unread gnus-unread-mark "u")
11819     (ticked gnus-ticked-mark "!")
11820     (dormant gnus-dormant-mark "?")
11821     (expirable gnus-expirable-mark "e"))
11822   "An alist of names/marks/keystrokes.")
11823
11824 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11825 (defvar gnus-summary-mark-map)
11826
11827 (defun gnus-summary-make-all-marking-commands ()
11828   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11829   (dolist (elem gnus-summary-marking-alist)
11830     (apply 'gnus-summary-make-marking-command elem)))
11831
11832 (defun gnus-summary-make-marking-command (name mark keystroke)
11833   (let ((map (make-sparse-keymap)))
11834     (define-key gnus-summary-generic-mark-map keystroke map)
11835     (dolist (lway `((next "next" next nil "n")
11836                     (next-unread "next unread" next t "N")
11837                     (prev "previous" prev nil "p")
11838                     (prev-unread "previous unread" prev t "P")
11839                     (nomove "" nil nil ,keystroke)))
11840       (let ((func (gnus-summary-make-marking-command-1
11841                    mark (car lway) lway name)))
11842         (setq func (eval func))
11843         (define-key map (nth 4 lway) func)))))
11844
11845 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11846   `(defun ,(intern
11847             (format "gnus-summary-put-mark-as-%s%s"
11848                     name (if (eq way 'nomove)
11849                              ""
11850                            (concat "-" (symbol-name way)))))
11851      (n)
11852      ,(format
11853        "Mark the current article as %s%s.
11854 If N, the prefix, then repeat N times.
11855 If N is negative, move in reverse order.
11856 The difference between N and the actual number of articles marked is
11857 returned."
11858        name (cadr lway))
11859      (interactive "p")
11860      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11861
11862 (defun gnus-summary-generic-mark (n mark move unread)
11863   "Mark N articles with MARK."
11864   (unless (eq major-mode 'gnus-summary-mode)
11865     (error "This command can only be used in the summary buffer"))
11866   (gnus-summary-show-thread)
11867   (let ((nummove
11868          (cond
11869           ((eq move 'next) 1)
11870           ((eq move 'prev) -1)
11871           (t 0))))
11872     (if (zerop nummove)
11873         (setq n 1)
11874       (when (< n 0)
11875         (setq n (abs n)
11876               nummove (* -1 nummove))))
11877     (while (and (> n 0)
11878                 (gnus-summary-mark-article nil mark)
11879                 (zerop (gnus-summary-next-subject nummove unread t)))
11880       (setq n (1- n)))
11881     (when (/= 0 n)
11882       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11883     (gnus-summary-recenter)
11884     (gnus-summary-position-point)
11885     (gnus-set-mode-line 'summary)
11886     n))
11887
11888 (defun gnus-summary-insert-articles (articles)
11889   (when (setq articles
11890               (gnus-sorted-difference articles
11891                                       (mapcar (lambda (h)
11892                                                 (mail-header-number h))
11893                                               gnus-newsgroup-headers)))
11894     (setq gnus-newsgroup-headers
11895           (gnus-merge 'list
11896                       gnus-newsgroup-headers
11897                       (gnus-fetch-headers articles)
11898                       'gnus-article-sort-by-number))
11899     ;; Suppress duplicates?
11900     (when gnus-suppress-duplicates
11901       (gnus-dup-suppress-articles))
11902
11903     ;; We might want to build some more threads first.
11904     (when (and gnus-fetch-old-headers
11905                (eq gnus-headers-retrieved-by 'nov))
11906       (if (eq gnus-fetch-old-headers 'invisible)
11907           (gnus-build-all-threads)
11908         (gnus-build-old-threads)))
11909     ;; Let the Gnus agent mark articles as read.
11910     (when gnus-agent
11911       (gnus-agent-get-undownloaded-list))
11912     ;; Remove list identifiers from subject
11913     (when gnus-list-identifiers
11914       (gnus-summary-remove-list-identifiers))
11915     ;; First and last article in this newsgroup.
11916     (when gnus-newsgroup-headers
11917       (setq gnus-newsgroup-begin
11918             (mail-header-number (car gnus-newsgroup-headers))
11919             gnus-newsgroup-end
11920             (mail-header-number
11921              (gnus-last-element gnus-newsgroup-headers))))
11922     (when gnus-use-scoring
11923       (gnus-possibly-score-headers))))
11924
11925 (defun gnus-summary-insert-old-articles (&optional all)
11926   "Insert all old articles in this group.
11927 If ALL is non-nil, already read articles become readable.
11928 If ALL is a number, fetch this number of articles."
11929   (interactive "P")
11930   (prog1
11931       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11932             older len)
11933         (setq older
11934               ;; Some nntp servers lie about their active range.  When
11935               ;; this happens, the active range can be in the millions.
11936               ;; Use a compressed range to avoid creating a huge list.
11937               (gnus-range-difference (list gnus-newsgroup-active) old))
11938         (setq len (gnus-range-length older))
11939         (cond
11940          ((null older) nil)
11941          ((numberp all)
11942           (if (< all len)
11943               (let ((older-range (nreverse older)))
11944                 (setq older nil)
11945
11946                 (while (> all 0)
11947                   (let* ((r (pop older-range))
11948                          (min (if (numberp r) r (car r)))
11949                          (max (if (numberp r) r (cdr r))))
11950                     (while (and (<= min max)
11951                                 (> all 0))
11952                       (push max older)
11953                       (setq all (1- all)
11954                             max (1- max))))))
11955             (setq older (gnus-uncompress-range older))))
11956          (all
11957           (setq older (gnus-uncompress-range older)))
11958          (t
11959           (when (and (numberp gnus-large-newsgroup)
11960                    (> len gnus-large-newsgroup))
11961               (let* ((cursor-in-echo-area nil)
11962                      (initial (gnus-parameter-large-newsgroup-initial
11963                                gnus-newsgroup-name))
11964                      (input
11965                       (read-string
11966                        (format
11967                         "How many articles from %s (%s %d): "
11968                         (gnus-limit-string
11969                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11970                         (if initial "max" "default")
11971                         len)
11972                        (if initial
11973                            (cons (number-to-string initial)
11974                                  0)))))
11975                 (unless (string-match "^[ \t]*$" input)
11976                   (setq all (string-to-number input))
11977                   (if (< all len)
11978                       (let ((older-range (nreverse older)))
11979                         (setq older nil)
11980
11981                         (while (> all 0)
11982                           (let* ((r (pop older-range))
11983                                  (min (if (numberp r) r (car r)))
11984                                  (max (if (numberp r) r (cdr r))))
11985                             (while (and (<= min max)
11986                                         (> all 0))
11987                               (push max older)
11988                               (setq all (1- all)
11989                                     max (1- max))))))))))
11990           (setq older (gnus-uncompress-range older))))
11991         (if (not older)
11992             (message "No old news.")
11993           (gnus-summary-insert-articles older)
11994           (gnus-summary-limit (gnus-sorted-nunion old older))))
11995     (gnus-summary-position-point)))
11996
11997 (defun gnus-summary-insert-new-articles ()
11998   "Insert all new articles in this group."
11999   (interactive)
12000   (prog1
12001       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12002             (old-active gnus-newsgroup-active)
12003             (nnmail-fetched-sources (list t))
12004             i new)
12005         (setq gnus-newsgroup-active
12006               (gnus-activate-group gnus-newsgroup-name 'scan))
12007         (setq i (cdr gnus-newsgroup-active))
12008         (while (> i (cdr old-active))
12009           (push i new)
12010           (decf i))
12011         (if (not new)
12012             (message "No gnus is bad news.")
12013           (gnus-summary-insert-articles new)
12014           (setq gnus-newsgroup-unreads
12015                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12016           (gnus-summary-limit (gnus-sorted-nunion old new))))
12017     (gnus-summary-position-point)))
12018
12019 (gnus-summary-make-all-marking-commands)
12020
12021 (gnus-ems-redefine)
12022
12023 (provide 'gnus-sum)
12024
12025 (run-hooks 'gnus-sum-load-hook)
12026
12027 ;; Local Variables:
12028 ;; coding: iso-8859-1
12029 ;; End:
12030
12031 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12032 ;;; gnus-sum.el ends here